use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class BundleVisibilityTest method test2.
/**
* Install a bundle into a different scope than this one. Neither bundle
* should be able to see the other.
* @throws Exception
*/
@Test
public void test2() throws Exception {
Scope scope = getScope();
assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
ScopeUpdate child = scopeUpdate.newChild("tb4");
scopeUpdate.getChildren().add(child);
String location = getBundleLocation("tb-4.jar");
assertNull(bundleContext.getBundle(location));
URL url = new URL(location);
InstallInfo installInfo = new InstallInfo(location, url.openStream());
child.getBundlesToInstall().add(installInfo);
addPackageImportPolicy("org.osgi.framework", child);
addPackageImportPolicy("org.apache.aries.subsystem.scope", child);
addPackageImportPolicy("org.apache.aries.subsystem.scope.itests", child);
addServiceExportPolicy(BundleProvider.class, child);
scopeUpdate.commit();
Bundle bundle = bundleContext.getBundle(location);
assertNotNull(bundle);
Collection<Scope> childScopes = scope.getChildren();
assertEquals(1, childScopes.size());
assertTrue(childScopes.iterator().next().getBundles().contains(bundle));
bundle.start();
ServiceReference<BundleProvider> bundleProviderRef = bundleContext.getServiceReference(BundleProvider.class);
BundleProvider bundleProvider = bundleContext.getService(bundleProviderRef);
assertFalse(Arrays.asList(bundleContext.getBundles()).contains(bundle));
assertNull(bundleContext.getBundle(bundle.getBundleId()));
assertFalse(bundleProvider.getBundles().contains(bundleContext.getBundle()));
assertNull(bundleProvider.getBundle(bundleContext.getBundle().getBundleId()));
bundleContext.ungetService(bundleProviderRef);
bundle.uninstall();
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class AbstractTest method installBundles.
protected void installBundles(Scope scope, Collection<String> bundleNames) throws Exception {
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
for (String bundleName : bundleNames) {
URL url = AbstractTest.class.getClassLoader().getResource(bundleName);
InstallInfo installInfo = new InstallInfo(url.toExternalForm(), url.openStream());
scopeUpdate.getBundlesToInstall().add(installInfo);
}
scopeUpdate.commit();
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class ScopeSecurityTest method testScopeSecurityWithServiceShared.
//@Test
public void testScopeSecurityWithServiceShared() throws Exception {
SecurityManager security = System.getSecurityManager();
assertNotNull("Security manager should not be null", security);
Bundle[] bundles = bundleContext.getBundles();
for (Bundle b : bundles) {
// set up condition permission for scope
if (b.getSymbolicName().indexOf("subsystem.scope.impl") > -1) {
ServiceReference permRef = bundleContext.getServiceReference(ConditionalPermissionAdmin.class.getName());
ConditionalPermissionAdmin permAdmin = (ConditionalPermissionAdmin) bundleContext.getService(permRef);
ConditionalPermissionUpdate update = permAdmin.newConditionalPermissionUpdate();
List<ConditionalPermissionInfo> infos = update.getConditionalPermissionInfos();
//infos.clear();
// set up the conditionInfo
ConditionInfo[] conditionInfo = new ConditionInfo[] { new ConditionInfo("org.osgi.service.condpermadmin.BundleLocationCondition", new String[] { b.getLocation() }) };
// Set up permissions which are common to all applications
infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, adminAllowInfo, "allow"));
update.commit();
}
}
ScopeUpdate su = scope.newScopeUpdate();
ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
final Filter filter1 = FrameworkUtil.createFilter("(&" + "(osgi.package=org.apache.aries.subsystem.example.helloIsolation)" + ")");
final Filter filter2 = FrameworkUtil.createFilter("(&" + "(osgi.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" + ")");
List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
if (packagePolicies == null) {
packagePolicies = new ArrayList<SharePolicy>();
sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
}
packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
if (servicePolicies == null) {
servicePolicies = new ArrayList<SharePolicy>();
sharePolicies.put("scope.share.service", servicePolicies);
}
servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
// build up installInfo object for the scope
InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT"));
InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
bundlesToInstall.add(info1);
bundlesToInstall.add(info2);
// add bundles to be installed, based on subsystem content
su.commit();
// start all bundles in the scope scope_test1
Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
for (Bundle b : bundlesToStart) {
b.start();
}
try {
ServiceReference sr = bundleContext.getServiceReference("org.apache.aries.subsystem.example.helloIsolation.HelloIsolation");
fail("should not be able to get the sr for HelloIsolation service");
} catch (Exception ex) {
// expected
} catch (Error er) {
// expected
}
// test bundle find hooks
bundles = bundleContext.getBundles();
for (Bundle b : bundles) {
System.out.println("Bundle is " + b.getBundleId() + ": " + b.getSymbolicName());
if (b.getSymbolicName().indexOf("org.apache.aries.subsystem.example.helloIsolation") > -1) {
fail("bundles with name starts with org.apache.aries.subsystem.example.helloIsolation should be in a different scope");
}
}
// test bundle service find hook
//ServiceReference sr = bundleContext.getServiceReference(HelloIsolation.class.getName());
//assertNull("sr should be null", sr);
Collection<Scope> children = scope.getChildren();
assertEquals(1, children.size());
for (Scope child : children) {
if (child.getName().equals("scope_test1")) {
Collection<Bundle> buns = child.getBundles();
assertEquals(2, buns.size());
assertEquals(0, child.getChildren().size());
BundleContext childScopebundleContext = null;
for (Bundle b : buns) {
assertTrue(b.getSymbolicName().indexOf("org.apache.aries.subsystem.example.helloIsolation") > -1);
if (b.getSymbolicName().indexOf("org.apache.aries.subsystem.example.helloIsolationRef") > -1) {
childScopebundleContext = b.getBundleContext();
}
}
assertNotNull(childScopebundleContext);
ServiceReference sr = childScopebundleContext.getServiceReference("org.apache.aries.subsystem.example.helloIsolation.HelloIsolation");
assertNotNull("sr is not null", sr);
System.out.println("got the sr, go get service next");
HelloIsolation hi = (HelloIsolation) childScopebundleContext.getService(sr);
hi.hello();
Permission permission = new PackagePermission("*", PackagePermission.IMPORT);
hi.checkPermission(permission);
}
}
// install a test bundle in the root scope
URL url = new URL("mvn:org.apache.felix/org.apache.felix.fileinstall/2.0.8");
bundleContext.installBundle("org.apache.felix.fileinstall-rootScope", url.openStream());
// remove child scope
su = scope.newScopeUpdate();
Collection<ScopeUpdate> scopes = su.getChildren();
// obtain child scope admin from service registry
// String filter = "ScopeName=scope_test1";
Scope childScopeAdmin = childScopeUpdate.getScope();
assertEquals(scope, childScopeAdmin.getParent());
scopes.remove(childScopeUpdate);
su.commit();
assertFalse(scope.getChildren().contains(childScopeAdmin));
su = scope.newScopeUpdate();
assertFalse(su.getChildren().contains(childScopeUpdate));
// childScopeAdmin = null;
// try {
// childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
// } catch (Exception ex) {
// // ignore
// }
// assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class SharePolicyTest method test4.
/**
* Bundle tb5
* Bundle tb6
* tb5 imports package exported by tb6
* tb5 in child scope of root
* tb6 in different child scope of root
* tb6 scope exports tb6 package
* root scope exports tb6 package
* tb5 scope imports tb6 package
* tb5 should resolve
*
* @throws Exception
*/
@Test
public void test4() throws Exception {
Bundle tb5 = null;
Bundle tb6 = null;
try {
String tb5Location = getBundleLocation("tb-5.jar");
String tb6Location = getBundleLocation("tb-6.jar");
InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
ScopeUpdate rootUpdate = getScope().newScopeUpdate();
addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb6", rootUpdate);
ScopeUpdate tb5Update = rootUpdate.newChild("tb5");
rootUpdate.getChildren().add(tb5Update);
tb5Update.getBundlesToInstall().add(tb5Info);
addPackageImportPolicy("org.apache.aries.subsystem.scope.itests.tb6", tb5Update);
rootUpdate.commit();
tb5 = findBundle("org.apache.aries.subsystem.scope.itests.tb5", tb5Update.getScope());
assertNotNull(tb5);
FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5 })));
rootUpdate = getScope().newScopeUpdate();
ScopeUpdate tb6Update = rootUpdate.newChild("tb6");
rootUpdate.getChildren().add(tb6Update);
tb6Update.getBundlesToInstall().add(tb6Info);
addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb6", tb6Update);
rootUpdate.commit();
tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6Update.getScope());
assertNotNull(tb6);
assertTrue(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5, tb6 })));
} finally {
uninstallQuietly(tb6);
uninstallQuietly(tb5);
}
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class SharePolicyTest method test2.
/**
* Bundle tb5
* Bundle tb6
* tb5 imports package exported by tb6
* tb5 in root scope
* tb6 in child scope of root
* tb6 scope does not export tb6 package
* tb5 should not resolve
* @throws Exception
*/
@Test
public void test2() throws Exception {
Bundle tb5 = null;
Bundle tb6 = null;
try {
String tb5Location = getBundleLocation("tb-5.jar");
String tb6Location = getBundleLocation("tb-6.jar");
InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
ScopeUpdate scopeUpdate = getScope().newScopeUpdate();
scopeUpdate.getBundlesToInstall().add(tb5Info);
scopeUpdate.commit();
tb5 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb5");
assertNotNull(tb5);
FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5 })));
scopeUpdate = getScope().newScopeUpdate();
ScopeUpdate tb6ScopeUpdate = scopeUpdate.newChild("tb6");
scopeUpdate.getChildren().add(tb6ScopeUpdate);
tb6ScopeUpdate.getBundlesToInstall().add(tb6Info);
scopeUpdate.commit();
tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate.getScope());
assertNotNull(tb6);
assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[] { tb5, tb6 })));
} finally {
uninstallQuietly(tb6);
uninstallQuietly(tb5);
}
}
Aggregations