use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class SubsystemResource method computeDependencies.
void computeDependencies(DeploymentManifest manifest, Coordination coordination) {
if (manifest == null) {
computeDependencies(getSubsystemManifest(), coordination);
} else {
ProvisionResourceHeader header = manifest.getProvisionResourceHeader();
if (header == null)
return;
for (ProvisionResourceHeader.Clause clause : header.getClauses()) {
Resource resource = findDependency(clause);
if (resource == null)
throw new SubsystemException("A required dependency could not be found. This means the resource was either missing or not recognized as a supported resource format due to, for example, an invalid bundle manifest or blueprint XML file. Turn on debug logging for more information. The resource was: " + resource);
addDependency(resource);
}
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class WovenClassListener method modified.
@Override
public void modified(WovenClass wovenClass) {
if (wovenClass.getState() != WovenClass.TRANSFORMED) {
// the defined state is reached.
return;
}
List<String> dynamicImports = wovenClass.getDynamicImports();
if (dynamicImports.isEmpty()) {
// Nothing to do if there are no dynamic imports.
return;
}
BundleWiring wiring = wovenClass.getBundleWiring();
Bundle bundle = wiring.getBundle();
BundleRevision revision = bundle.adapt(BundleRevision.class);
BundleConstituent constituent = new BundleConstituent(null, revision);
Collection<BasicSubsystem> basicSubsystems = subsystems.getSubsystemsByConstituent(constituent);
BasicSubsystem subsystem = basicSubsystems.iterator().next();
// Find the scoped subsystem in the region.
subsystem = scopedSubsystem(subsystem);
if (subsystem.getSubsystemId() == 0) {
// The root subsystem needs no sharing policy.
return;
}
if (EnumSet.of(Subsystem.State.INSTALLING, Subsystem.State.INSTALLED).contains(subsystem.getState())) {
// The scoped subsystem must be resolved before adding dynamic
// package imports to the sharing policy in order to minimize
// unpredictable wirings. Resolving the scoped subsystem will also
// resolve all of the unscoped subsystems in the region.
AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.RESOLVE_ONLY));
}
Bundle systemBundle = context.getBundle(org.osgi.framework.Constants.SYSTEM_BUNDLE_LOCATION);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
// The following map tracks all of the necessary updates as each dynamic
// import is processed. The key is the tail region of the connection
// whose filter needs updating.
Map<Region, RegionUpdaterInfo> updates = new HashMap<Region, RegionUpdaterInfo>();
for (String dynamicImport : dynamicImports) {
// For each dynamic import, collect the necessary update information.
DynamicImportPackageHeader header = new DynamicImportPackageHeader(dynamicImport);
List<DynamicImportPackageRequirement> requirements = header.toRequirements(revision);
for (DynamicImportPackageRequirement requirement : requirements) {
Collection<BundleCapability> providers = frameworkWiring.findProviders(requirement);
if (providers.isEmpty()) {
// import, no updates are made.
continue;
}
addSharingPolicyUpdates(requirement, subsystem, providers, updates);
}
}
// Now update each sharing policy only once.
for (RegionUpdaterInfo update : updates.values()) {
RegionUpdater updater = new RegionUpdater(update.tail(), update.head());
try {
updater.addRequirements(update.requirements());
} catch (IllegalStateException e) {
// Something outside of the subsystems implementation has
// deleted the edge between the parent and child subsystems.
// Assume the dynamic import sharing policy is being handled
// elsewhere. See ARIES-1429.
} catch (Exception e) {
throw new SubsystemException(e);
}
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class InstallTest method testLocationAsEmptyString.
@Test
public void testLocationAsEmptyString() throws Exception {
try {
Subsystem a = installSubsystemFromFile(getRootSubsystem(), new File(APPLICATION_A), "");
try {
BasicSubsystem basic = (BasicSubsystem) a;
String location = basic.getLocation();
assertEquals("Location value should be an empty string", "", location);
} finally {
uninstallSubsystemSilently(a);
}
} catch (SubsystemException e) {
e.printStackTrace();
fail("Subsystem should have installed");
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class ResolutionTest method testMissingNativeCodeRequirement.
@Test
public void testMissingNativeCodeRequirement() throws Exception {
Subsystem applicationE = null;
try {
applicationE = installSubsystemFromFile(APPLICATION_E);
// TODO this should fail to intsall
} catch (SubsystemException e) {
e.printStackTrace();
fail("Installation should succeed for Bundle-NativeCode");
}
try {
applicationE.start();
fail("Expected to fail to install");
} catch (Exception e) {
// expected
} finally {
uninstallSubsystemSilently(applicationE);
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class ResolutionTest method testContentWithNonConstituentDependencyWithNonConstituentDependency.
/*
* Test that the right regions are used when validating capabilities.
*
* Application A contains a content bundle requiring capability A. Bundle B
* provides capability A and is available as an installable resource from a
* repository service. Bundle B also requires capability B. Bundle C is an
* already installed resource in the root subsystem providing capability B.
* When validating capability A, the subsystem should use the root region as
* the from region, and its own region as the to region. When validating
* capability B, the subsystem should use the root region as the from region
* as well as for the to region.
*/
@Test
public void testContentWithNonConstituentDependencyWithNonConstituentDependency() throws Exception {
// Register a repository service containing bundle B requiring
// capability B and providing capability A.
registerRepositoryService(BUNDLE_B);
Subsystem root = getRootSubsystem();
// Install unmanaged bundle C providing capability B as a constituent
// of the root subsystem.
Bundle bundleC = installBundleFromFile(BUNDLE_C, root);
try {
// Install application A with content bundle A requiring
// capability A.
Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
// Make sure the Require-Capability exists for capability a...
assertHeaderExists(applicationA, Constants.REQUIRE_CAPABILITY);
// ...but not for capability b.
RequireCapabilityHeader header = new RequireCapabilityHeader(applicationA.getSubsystemHeaders(null).get(Constants.REQUIRE_CAPABILITY));
assertEquals("Wrong number of clauses", 1, header.getClauses().size());
Clause clause = header.getClauses().iterator().next();
assertEquals("Wrong path", "a", clause.getPath());
assertEquals("Wrong resolution directive", Constants.RESOLUTION_MANDATORY, clause.getDirective(Constants.RESOLUTION_DIRECTIVE).getValue());
assertEquals("Wrong effective directive", Constants.EFFECTIVE_RESOLVE, clause.getDirective(Constants.EFFECTIVE_DIRECTIVE).getValue());
try {
// Make sure the runtime resolution works as well.
applicationA.start();
} catch (SubsystemException e) {
fail("Application A should have started");
} finally {
stopAndUninstallSubsystemSilently(applicationA);
}
} catch (SubsystemException e) {
fail("Application A should have installed." + e.getMessage());
} finally {
uninstallSilently(bundleC);
}
}
Aggregations