Search in sources :

Example 11 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class BasicLocationTests method testNoDefault.

public void testNoDefault() throws Exception {
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@noDefault");
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "@noDefault");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        Location userLocation = locations.get(Location.USER_FILTER);
        Location instanceLocation = locations.get(Location.INSTANCE_FILTER);
        assertNull("User locatoin is not null.", userLocation.getURL());
        assertNull("Instance location is not null.", instanceLocation.getURL());
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Example 12 with Equinox

use of org.eclipse.osgi.launch.Equinox 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 13 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class ImportJavaSEPackagesTests method testImportPackageCanContainJavaPackages.

public void testImportPackageCanContainJavaPackages() throws Exception {
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    headers.put(Constants.BUNDLE_SYMBOLICNAME, getName());
    headers.put(Constants.IMPORT_PACKAGE, JAVA_LANG);
    config.mkdirs();
    File bundle = SystemBundleTests.createBundle(config, getName(), headers);
    Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle testBundle = systemContext.installBundle(bundle.toURI().toString());
        testBundle.start();
        Dictionary<String, String> testHeaders = testBundle.getHeaders();
        assertTrue(Constants.IMPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.IMPORT_PACKAGE).contains(JAVA_LANG));
        List<BundleWire> pkgWires = testBundle.adapt(BundleWiring.class).getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
        assertEquals("Wrong number of package requiremens: ", 1, pkgWires.size());
        assertEquals("Wrong package found: " + pkgWires.get(0), JAVA_LANG, pkgWires.get(0).getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    } catch (BundleException e) {
        fail("Failed to test Import-Package header");
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // do nothing
        }
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire) BundleException(org.osgi.framework.BundleException) Equinox(org.eclipse.osgi.launch.Equinox) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 14 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class ImportJavaSEPackagesTests method testExportPackageCannotContainJavaPackages.

public void testExportPackageCannotContainJavaPackages() throws Exception {
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    headers.put(Constants.BUNDLE_SYMBOLICNAME, getName());
    headers.put(Constants.EXPORT_PACKAGE, JAVA_LANG);
    config.mkdirs();
    File bundle = SystemBundleTests.createBundle(config, getName(), headers);
    Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle testBundle = systemContext.installBundle(bundle.toURI().toString());
        testBundle.start();
        fail("Failed to test Export-Package header");
    } catch (BundleException e) {
        assertEquals("It should throw a bundle exception of type manifest error", BundleException.MANIFEST_ERROR, e.getType());
        assertTrue("It should throw a Bundle Exception stating Invalid manifest header Export-Package", e.getMessage().contains("Cannot specify java.* packages in Export headers"));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // do nothing
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleException(org.osgi.framework.BundleException) BundleContext(org.osgi.framework.BundleContext)

Example 15 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class MultiReleaseJarTests method doTestMultiReleaseListResources.

private void doTestMultiReleaseListResources(int rv) throws Exception {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    Collection<String> expected = new ArrayList<String>();
    Collection<String> expectedRecurse = new ArrayList<String>();
    expected.add("multi/release/test/testResourceBase.txt");
    expected.add("multi/release/test/testResource8.txt");
    expected.add("multi/release/test/testResource9.txt");
    expected.add("multi/release/test/testResource10.txt");
    expected.add("multi/release/test/testResource11.txt");
    if (rv >= 9) {
        expected.add("multi/release/test/testResourceAdd9.txt");
    }
    if (rv >= 10) {
        expected.add("multi/release/test/testResourceAdd10.txt");
    }
    if (rv >= 11) {
        expected.add("multi/release/test/testResourceAdd11.txt");
    }
    expectedRecurse.addAll(expected);
    expectedRecurse.add("multi/release/test/sub/testResourceBase.txt");
    expectedRecurse.add("multi/release/test/sub/testResource8.txt");
    expectedRecurse.add("multi/release/test/sub/testResource9.txt");
    expectedRecurse.add("multi/release/test/sub/testResource10.txt");
    expectedRecurse.add("multi/release/test/sub/testResource11.txt");
    expectedRecurse.add("multi/release/test/sub2/testResourceBase.txt");
    expectedRecurse.add("multi/release/test/sub2/testResource8.txt");
    expectedRecurse.add("multi/release/test/sub2/testResource9.txt");
    expectedRecurse.add("multi/release/test/sub2/testResource10.txt");
    expectedRecurse.add("multi/release/test/sub2/testResource11.txt");
    if (rv >= 9) {
        expectedRecurse.add("multi/release/test/sub/testResourceAdd9.txt");
        expectedRecurse.add("multi/release/test/sub2/testResourceAdd9.txt");
    }
    if (rv >= 10) {
        expectedRecurse.add("multi/release/test/sub/testResourceAdd10.txt");
        expectedRecurse.add("multi/release/test/sub2/testResourceAdd10.txt");
    }
    if (rv >= 11) {
        expectedRecurse.add("multi/release/test/sub/testResourceAdd11.txt");
        expectedRecurse.add("multi/release/test/sub2/testResourceAdd11.txt");
    }
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
        mrBundle.start();
        listResources("multi/release/test", expected, mrBundle, 0);
        listResources("multi/release/test", expectedRecurse, mrBundle, BundleWiring.LISTRESOURCES_RECURSE);
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) File(java.io.File) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Equinox (org.eclipse.osgi.launch.Equinox)105 File (java.io.File)88 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)58 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)58 BundleException (org.osgi.framework.BundleException)52 BundleContext (org.osgi.framework.BundleContext)51 Bundle (org.osgi.framework.Bundle)43 IOException (java.io.IOException)18 FileNotFoundException (java.io.FileNotFoundException)11 URL (java.net.URL)10 Location (org.eclipse.osgi.service.datalocation.Location)10 Properties (java.util.Properties)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 FrameworkEvent (org.osgi.framework.FrameworkEvent)8 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)8 BundleWiring (org.osgi.framework.wiring.BundleWiring)8 ArrayList (java.util.ArrayList)7 ExecutionException (java.util.concurrent.ExecutionException)6 FileOutputStream (java.io.FileOutputStream)5