Search in sources :

Example 1 with EnvironmentInfo

use of org.eclipse.osgi.service.environment.EnvironmentInfo in project rt.equinox.framework by eclipse.

the class EclipseStarter method startup.

/**
 * Starts the platform and sets it up to run a single application. The application is either identified
 * in the given arguments (e.g., -application &lt;app id&gt;) or in the <code>eclipse.application</code>
 * System property.  The platform must not be running already.
 * <p>
 * The given runnable (if not <code>null</code>) is used to tear down the splash screen if required.
 * </p>
 * @param args the arguments passed to the application
 * @return BundleContext the context of the system bundle
 * @throws Exception if anything goes wrong
 */
public static BundleContext startup(String[] args, Runnable endSplashHandler) throws Exception {
    if (running)
        throw new IllegalStateException(Msg.ECLIPSE_STARTUP_ALREADY_RUNNING);
    processCommandLine(args);
    framework = new Equinox(getConfiguration());
    framework.init();
    context = framework.getBundleContext();
    ServiceReference<FrameworkLog> logRef = context.getServiceReference(FrameworkLog.class);
    log = context.getService(logRef);
    ServiceReference<EnvironmentInfo> configRef = context.getServiceReference(EnvironmentInfo.class);
    equinoxConfig = (EquinoxConfiguration) context.getService(configRef);
    equinoxConfig.setAllArgs(allArgs);
    equinoxConfig.setFrameworkArgs(frameworkArgs);
    equinoxConfig.setAppArgs(appArgs);
    registerFrameworkShutdownHandlers();
    publishSplashScreen(endSplashHandler);
    consoleMgr = ConsoleManager.startConsole(context, equinoxConfig);
    Bundle[] startBundles = loadBasicBundles();
    if (startBundles == null || ("true".equals(getProperty(PROP_REFRESH_BUNDLES)) && refreshPackages(getCurrentBundles(false)))) {
        // $NON-NLS-1$
        waitForShutdown();
        // cannot continue; loadBasicBundles caused refreshPackages to shutdown the framework
        return context;
    }
    framework.start();
    if (isForcedRestart()) {
        return context;
    }
    // set the framework start level to the ultimate value.  This will actually start things
    // running if they are persistently active.
    setStartLevel(getStartLevel());
    // they should all be active by this time
    ensureBundlesActive(startBundles);
    // in the case where the built-in console is disabled we should try to start the console bundle
    try {
        consoleMgr.checkForConsoleBundle();
    } catch (BundleException e) {
        FrameworkLogEntry entry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, e.getMessage(), 0, e, null);
        log.log(entry);
    }
    // TODO should log unresolved bundles if in debug or dev mode
    running = true;
    return context;
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) FrameworkLog(org.eclipse.osgi.framework.log.FrameworkLog) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 2 with EnvironmentInfo

use of org.eclipse.osgi.service.environment.EnvironmentInfo in project rt.equinox.framework by eclipse.

the class BundleResourceTests method testBug395274.

public void testBug395274() throws Exception {
    ServiceReference<EnvironmentInfo> infoRef = OSGiTestsActivator.getContext().getServiceReference(EnvironmentInfo.class);
    EnvironmentInfo info = OSGiTestsActivator.getContext().getService(infoRef);
    String original = info.setProperty("osgi.strictBundleEntryPath", "true");
    try {
        // $NON-NLS-1$
        Bundle bundle = installer.installBundle("test");
        URL path = bundle.getEntry("META-INF./MANIFEST.MF");
        assertNull("found resource!", path);
        path = bundle.getEntry("META-INF/MANIFEST.MF");
        assertNotNull("Did not find resource!", path);
        path = bundle.getEntry("folder/file1.TXT");
        assertNull("found resource!", path);
        path = bundle.getEntry("folder/file1.txt");
        assertNotNull("Did not find resource!", path);
        checkEntries(bundle, "/./file1.txt", 1);
        checkEntries(bundle, "//file1.txt", 1);
        checkEntries(bundle, "/", 1);
        checkEntries(bundle, "/.", 1);
    } finally {
        info.setProperty("osgi.strictBundleEntryPath", original);
        OSGiTestsActivator.getContext().ungetService(infoRef);
    }
}
Also used : EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) URL(java.net.URL)

Example 3 with EnvironmentInfo

use of org.eclipse.osgi.service.environment.EnvironmentInfo in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testBackedBySystemReplaceSystemProperties.

public void testBackedBySystemReplaceSystemProperties() throws BundleException {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put("osgi.framework.useSystemProperties", "true");
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class);
    EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef);
    // replace the system properties with a copy
    Properties copy = new Properties();
    copy.putAll(System.getProperties());
    System.setProperties(copy);
    // set a system prop for this test after replacement of the properties object
    String systemKey = getName() + ".system";
    System.setProperty(systemKey, getName());
    // make sure context properties reflect the new test prop
    assertEquals("Wrong context value", getName(), equinox.getBundleContext().getProperty(systemKey));
    // also test EnvironmentInfo properties
    assertEquals("Wrong context value", getName(), envInfo.getProperty(systemKey));
    assertEquals("Wrong EquinoxConfiguration config value", getName(), ((EquinoxConfiguration) envInfo).getConfiguration(systemKey));
    // set environment info prop
    String envKey = getName() + ".env";
    envInfo.setProperty(envKey, getName());
    // make sure the system properties reflect the new test prop
    assertEquals("Wrong system value", getName(), System.getProperty(envKey));
    equinox.stop();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) Properties(java.util.Properties) File(java.io.File)

Example 4 with EnvironmentInfo

use of org.eclipse.osgi.service.environment.EnvironmentInfo in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testNullConfigurationValueSystemProperties.

public void testNullConfigurationValueSystemProperties() throws BundleException {
    System.setProperty(nullTest, "system");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put("osgi.framework.useSystemProperties", "true");
    configuration.put(nullTest, null);
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    String nullValue = equinox.getBundleContext().getProperty(nullTest);
    assertNull(nullTest + " is not null: " + nullValue, nullValue);
    assertNull("Did not get null system value.", System.getProperties().get(nullTest));
    // also test EnvironmentInfo effects on system properties
    ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class);
    EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef);
    envInfo.setProperty(getName(), getName());
    assertEquals("Got wrong value from system properties.", System.getProperty(getName()), getName());
    envInfo.setProperty(getName(), null);
    assertNull("Did not get null system value.", System.getProperties().get(getName()));
    equinox.stop();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) File(java.io.File)

Example 5 with EnvironmentInfo

use of org.eclipse.osgi.service.environment.EnvironmentInfo in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testLocalConfigReplaceSystemProperties.

public void testLocalConfigReplaceSystemProperties() throws BundleException {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class);
    EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef);
    // replace the system properties with a copy
    Properties copy = new Properties();
    copy.putAll(System.getProperties());
    System.setProperties(copy);
    // set a system prop for this test after replacement of the properties object
    String systemKey = getName() + ".system";
    System.setProperty(systemKey, getName());
    // make sure context properties reflect the new system test prop.
    // remember context properties are backed by system properties
    assertEquals("Wrong context value", getName(), equinox.getBundleContext().getProperty(systemKey));
    // also test EnvironmentInfo properties.
    // remember the getProperty method is backed by system properties
    assertEquals("Wrong context value", getName(), envInfo.getProperty(systemKey));
    // config options are not backed by system properties when framework is not using system properties for configuration
    assertNull("Wrong EquinoxConfiguration config value", ((EquinoxConfiguration) envInfo).getConfiguration(systemKey));
    // set environment info prop
    String envKey = getName() + ".env";
    envInfo.setProperty(envKey, getName());
    // make sure the system properties does NOT reflect the new test prop
    assertNull("Wrong system value", System.getProperty(envKey));
    equinox.stop();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) Properties(java.util.Properties) File(java.io.File)

Aggregations

EnvironmentInfo (org.eclipse.osgi.service.environment.EnvironmentInfo)5 Equinox (org.eclipse.osgi.launch.Equinox)4 File (java.io.File)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Properties (java.util.Properties)2 URL (java.net.URL)1 FrameworkLog (org.eclipse.osgi.framework.log.FrameworkLog)1 FrameworkLogEntry (org.eclipse.osgi.framework.log.FrameworkLogEntry)1