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;
}
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
Aggregations