use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method doTestMultiReleaseBundleManifest.
private void doTestMultiReleaseBundleManifest(int rv) throws Exception {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
String expectedCap;
String expectedPkg;
if (rv < 9) {
expectedCap = "capbase";
expectedPkg = "pkgbase";
} else {
expectedCap = "cap" + rv;
expectedPkg = "pkg" + 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();
List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
assertEquals("Wrong number of capability wires.", 1, capWires.size());
List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of package requiremens.", 1, pkgReqs.size());
String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
assertTrue("Wrong package filter: " + filter, filter.contains(expectedPkg));
} 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 testMultiReleaseBundleManifestChangeRuntime.
public void testMultiReleaseBundleManifestChangeRuntime() throws Exception {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, String> configMap = Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath() + " with space");
Equinox equinox = new Equinox(configMap);
String location;
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
location = mrBundle.getLocation();
mrBundle.start();
} finally {
equinox.stop();
equinox.waitForStop(1000);
}
for (int rv = 8; rv <= 11; rv++) {
doTestMultiReleaseBundleManifestChangeRuntime(rv, configMap, location);
}
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle toUninstall = systemContext.getBundle(location);
toUninstall.uninstall();
Bundle mrBundle = systemContext.installBundle("reference:" + mrJarBundle.toURI().toString());
location = mrBundle.getLocation();
mrBundle.start();
} finally {
equinox.stop();
equinox.waitForStop(1000);
}
for (int rv = 8; rv <= 11; rv++) {
doTestMultiReleaseBundleManifestChangeRuntime(rv, configMap, location);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method doTestMultiReleaseGetResource.
private void doTestMultiReleaseGetResource(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", readResource("multi/release/test/testResourceBase.txt", mrBundle));
assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/testResource8.txt", mrBundle));
assertEquals("Wrong resource.", RNF, readResource("multi/release/test/testResourceAdd8.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResource("multi/release/test/testResource9.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResource("multi/release/test/testResourceAdd9.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResource("multi/release/test/testResource10.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResource("multi/release/test/testResourceAdd10.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResource("multi/release/test/testResource11.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("multi/release/test/testResourceAdd11.txt", mrBundle));
assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub/testResourceBase.txt", mrBundle));
assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub/testResource8.txt", mrBundle));
assertEquals("Wrong resource.", RNF, readResource("multi/release/test/testResourceAdd8.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResource("multi/release/test/sub/testResource9.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResource("multi/release/test/sub/testResourceAdd9.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResource("multi/release/test/sub/testResource10.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResource("multi/release/test/sub/testResourceAdd10.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResource("multi/release/test/sub/testResource11.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("multi/release/test/sub/testResourceAdd11.txt", mrBundle));
assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub2/testResourceBase.txt", mrBundle));
assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub2/testResource8.txt", mrBundle));
assertEquals("Wrong resource.", RNF, readResource("multi/release/test/testResourceAdd8.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResource("multi/release/test/sub2/testResource9.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResource("multi/release/test/sub2/testResourceAdd9.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResource("multi/release/test/sub2/testResource10.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResource("multi/release/test/sub2/testResourceAdd10.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResource("multi/release/test/sub2/testResource11.txt", mrBundle));
assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("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 testMultiReleasePreventMetaInfResourceURLs.
public void testMultiReleasePreventMetaInfResourceURLs() 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();
URL existingResource = mrBundle.getResource("multi/release/test/testResourceAdd9.txt");
assertNotNull("Did not find Java 9 added resource.", existingResource);
URL metaInfResource = new URL(existingResource, "/META-INF/addedFor9.txt");
try {
metaInfResource.openStream().close();
fail("Expected error opening versioned META-INF resource.");
} catch (IOException e) {
// expected
}
} finally {
equinox.stop();
equinox.waitForStop(1000);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class MultiReleaseJarTests method doTestMultiReleaseBundleManifestChangeRuntime.
private void doTestMultiReleaseBundleManifestChangeRuntime(int rv, Map<String, String> configMap, String location) throws BundleException {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
String expectedCap;
String expectedPkg;
if (rv < 9) {
expectedCap = "capbase";
expectedPkg = "pkgbase";
} else {
expectedCap = "cap" + rv;
expectedPkg = "pkg" + rv;
}
Equinox equinox = new Equinox(configMap);
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Bundle mrBundle = systemContext.getBundle(location);
assertNotNull("No mrBundle found: " + rv, mrBundle);
assertEquals("Wrong state of mrBundle: " + rv, Bundle.ACTIVE, mrBundle.getState());
List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
assertEquals("Wrong number of capability wires: " + rv, 1, capWires.size());
List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of package requiremens: " + rv, 1, pkgReqs.size());
String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
assertTrue("Wrong package filter: " + rv + " " + filter, filter.contains(expectedPkg));
} finally {
try {
equinox.stop();
equinox.waitForStop(10000);
} catch (Exception e) {
// ignore;
}
}
}
Aggregations