Search in sources :

Example 16 with Equinox

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

the class MultiReleaseJarTests method doTestMultiReleaseGetResources.

private void doTestMultiReleaseGetResources(int rv) throws Exception {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    // $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();
        assertEquals("Wrong resource.", "RESOURCE XX", readResources("multi/release/test/testResourceBase.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResources("multi/release/test/testResource8.txt", mrBundle));
        assertEquals("Wrong resource.", RNF, readResources("multi/release/test/testResourceAdd8.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResources("multi/release/test/testResource9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResources("multi/release/test/testResourceAdd9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResources("multi/release/test/testResource10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResources("multi/release/test/testResourceAdd10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResources("multi/release/test/testResource11.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResources("multi/release/test/testResourceAdd11.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResources("multi/release/test/sub/testResourceBase.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResources("multi/release/test/sub/testResource8.txt", mrBundle));
        assertEquals("Wrong resource.", RNF, readResources("multi/release/test/testResourceAdd8.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResources("multi/release/test/sub/testResource9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResources("multi/release/test/sub/testResourceAdd9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResources("multi/release/test/sub/testResource10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResources("multi/release/test/sub/testResourceAdd10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResources("multi/release/test/sub/testResource11.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResources("multi/release/test/sub/testResourceAdd11.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResources("multi/release/test/sub2/testResourceBase.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResources("multi/release/test/sub2/testResource8.txt", mrBundle));
        assertEquals("Wrong resource.", RNF, readResources("multi/release/test/testResourceAdd8.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResources("multi/release/test/sub2/testResource9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResources("multi/release/test/sub2/testResourceAdd9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResources("multi/release/test/sub2/testResource10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResources("multi/release/test/sub2/testResourceAdd10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResources("multi/release/test/sub2/testResource11.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResources("multi/release/test/sub2/testResourceAdd11.txt", mrBundle));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) File(java.io.File) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BundleContext(org.osgi.framework.BundleContext)

Example 17 with Equinox

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

the class MultiReleaseJarTests method testMultiReleaseBundleDeletedRestart.

public void testMultiReleaseBundleDeletedRestart() throws Exception {
    File copyMrJarBundle = OSGiTestsActivator.getContext().getDataFile("copy-" + mrJarBundle.getName());
    StorageUtil.readFile(new FileInputStream(mrJarBundle), copyMrJarBundle);
    System.setProperty("java.specification.version", "9");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> configMap = Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configMap);
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle("reference:" + copyMrJarBundle.toURI().toString());
        mrBundle.start();
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
    copyMrJarBundle.delete();
    System.setProperty("java.specification.version", "10");
    equinox = new Equinox(configMap);
    try {
        equinox.start();
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) File(java.io.File) FileInputStream(java.io.FileInputStream) BundleContext(org.osgi.framework.BundleContext)

Example 18 with Equinox

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

the class MultiReleaseJarTests method testMultiReleasePreventMetaInfVersionListing.

public void testMultiReleasePreventMetaInfVersionListing() throws Exception {
    System.setProperty("java.specification.version", "9");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> configMap = Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configMap);
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle("reference:" + mrJarBundle.toURI().toString());
        mrBundle.start();
        Collection<String> list = mrBundle.adapt(BundleWiring.class).listResources("/META-INF/", "*.txt", 0);
        assertTrue("Found versioned META-INF resources: " + list, list.isEmpty());
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 19 with Equinox

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

the class MultiReleaseJarTests method testMultiReleasePreventMetaInfServiceVersions.

public void testMultiReleasePreventMetaInfServiceVersions() throws Exception {
    System.setProperty("java.specification.version", "9");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> configMap = Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configMap);
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle("reference:" + mrJarBundle.toURI().toString());
        mrBundle.start();
        Class<?> testServiceClass = mrBundle.loadClass("multi.release.test.TestService");
        ServiceLoader<?> loader = ServiceLoader.load(testServiceClass, mrBundle.adapt(BundleWiring.class).getClassLoader());
        Object testService = loader.iterator().next();
        assertEquals("Wrong service found.", "SERVICE_BASE", testService.toString());
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 20 with Equinox

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

the class SystemBundleTests method doTestJavaProfile.

private void doTestJavaProfile(String javaSpecVersion, String expectedEEName, String releaseName) throws FileNotFoundException, IOException {
    if (releaseName != null) {
        File release = getContext().getDataFile("jre/release");
        release.getParentFile().mkdirs();
        Properties props = new Properties();
        props.put("JAVA_PROFILE", releaseName);
        FileOutputStream propStream = new FileOutputStream(release);
        try {
            props.store(propStream, null);
        } finally {
            propStream.close();
        }
        System.setProperty("java.home", release.getParentFile().getAbsolutePath());
    }
    System.setProperty("java.specification.version", javaSpecVersion);
    // create/stop/ test
    File config = OSGiTestsActivator.getContext().getDataFile(getName() + javaSpecVersion);
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    @SuppressWarnings("deprecation") String osgiEE = equinox.getBundleContext().getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
    // don't do anything; just put the framework back to the RESOLVED state
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected error stopping framework", e);
    }
    try {
        equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
    assertTrue("Wrong osgi EE: expected: " + expectedEEName + " but was: " + osgiEE, osgiEE.endsWith(expectedEEName));
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) BundleException(org.osgi.framework.BundleException) Properties(java.util.Properties) File(java.io.File)

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