001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     gracinet
018 *
019 * $Id$
020 */
021
022package org.nuxeo.runtime.test;
023
024import java.net.URL;
025
026import org.apache.commons.logging.Log;
027import org.apache.commons.logging.LogFactory;
028
029import org.nuxeo.common.Environment;
030import org.nuxeo.runtime.api.Framework;
031import org.nuxeo.runtime.osgi.OSGiComponentLoader;
032import org.nuxeo.runtime.osgi.OSGiRuntimeActivator;
033import org.nuxeo.runtime.osgi.OSGiRuntimeService;
034
035import org.osgi.framework.BundleContext;
036
037/**
038 * @author gracinet
039 */
040public class OSGIRuntimeTestActivator extends OSGiRuntimeActivator {
041
042    private static final Log log = LogFactory.getLog(OSGIRuntimeTestActivator.class);
043
044    @Override
045    public void start(BundleContext context) {
046        log.info("Starting Runtime Activator");
047        // create the runtime
048        runtime = new OSGiRuntimeService(context);
049        String tempDir = Environment.getDefault().getTemp().getAbsolutePath();
050        System.setProperty("java.io.tmpdir", tempDir);
051        System.setProperty(Environment.NUXEO_TMP_DIR, tempDir);
052
053        // load main config file if any
054        URL config = context.getBundle().getResource("/OSGI-INF/nuxeo.properties");
055        if (config != null) {
056            System.setProperty(OSGiRuntimeService.PROP_CONFIG_DIR, config.toExternalForm());
057        }
058
059        initialize(runtime);
060        // start it
061        Framework.initialize(runtime);
062        // register bundle component loader
063        componentLoader = new OSGiComponentLoader(runtime);
064        // TODO register osgi services
065    }
066
067}