Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java Wed Jan 7 19:37:42 2015 @@ -35,9 +35,10 @@ public class Location { final String toString; final String scheme; LocationType(String toString, String scheme) {this.toString = toString; this.scheme = scheme;} + @Override public String toString() {return toString;} }; - + private final LocationType type; private final String value; private final URI uri; @@ -51,8 +52,20 @@ public class Location { */ public Location(String location) throws MalformedURLException, URISyntaxException { value = location; - URI locationUri = new URI(location); - if (locationUri.isAbsolute()) { // i.e. looks like scheme:something + URI locationUri = null; + try { + locationUri = new URI(location); + } catch ( URISyntaxException urise ) { + // ignore + } + if (locationUri == null) { + type = LocationType.UNKNOWN; + url = null; + uri = null; + subsystemUri = null; + subsystemUriException = null; + + } else if (locationUri.isAbsolute()) { // i.e. looks like scheme:something String scheme = locationUri.getScheme(); if (LocationType.SUBSYSTEM.scheme.equals(scheme)) { type = LocationType.SUBSYSTEM; @@ -81,10 +94,16 @@ public class Location { url = null; uri = locationUri; } else { // otherwise will only accept a url, (a url - type = LocationType.URL; // always has a scheme, so fine to have + type = LocationType.URL; // always has a scheme, so fine to have subsystemUri = null; // this inside the 'if isAbsolute' block). subsystemUriException = null; - url = locationUri.toURL(); + URL localUrl = null; + try { + localUrl = locationUri.toURL(); + } catch ( final MalformedURLException mue) { + // ignore + } + url = localUrl; uri = locationUri; } } else { @@ -95,18 +114,18 @@ public class Location { subsystemUriException = null; } } - + public String getValue() { return value; } - + public String getSymbolicName() { if (subsystemUriException != null) { throw subsystemUriException; } return (subsystemUri!=null) ? subsystemUri.getSymbolicName() : null; } - + public Version getVersion() { if (subsystemUriException != null) { throw subsystemUriException; @@ -130,14 +149,14 @@ public class Location { // method will never be called. return FileSystem.getFSRoot(new URL(value).openStream()); default : // should never get here as switch should cover all types - throw new UnsupportedOperationException("cannot open location of type " + type); + throw new UnsupportedOperationException("cannot open location of type " + type); } } - + /* - * Although the uri should contain information about the directory finder + * Although the uri should contain information about the directory finder * service to use to retrieve the directory, there are not expected to be - * many such services in use (typically one), so a simple list of all + * many such services in use (typically one), so a simple list of all * directory finders is maintained by the activator and we loop over them in * turn until the desired directory is retrieved or there are no more finders * left to call. @@ -151,7 +170,7 @@ public class Location { } throw new IOException("cannot find IDirectory corresponding to id " + uri); } - + @Override public String toString() { return value;
Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java Wed Jan 7 19:37:42 2015 @@ -27,31 +27,36 @@ import org.osgi.framework.namespace.Iden import org.osgi.resource.Resource; public class OsgiIdentityCapability extends AbstractCapability { - private final Map<String, Object> attributes = new HashMap<String, Object>(); + private final Map<String, Object> attributes; private final Resource resource; - + public OsgiIdentityCapability(Resource resource, String symbolicName) { this(resource, symbolicName, Version.emptyVersion); } - + public OsgiIdentityCapability(Resource resource, String symbolicName, Version version) { this(resource, symbolicName, version, IdentityNamespace.TYPE_BUNDLE); } - + public OsgiIdentityCapability(Resource resource, String symbolicName, Version version, String identityType) { + this(resource, symbolicName, version, identityType, new HashMap<String, Object>()); + } + + public OsgiIdentityCapability(Resource resource, String symbolicName, Version version, String identityType, Map<String, Object> attrs) { this.resource = resource; + attributes = attrs; attributes.put( - IdentityNamespace.IDENTITY_NAMESPACE, + IdentityNamespace.IDENTITY_NAMESPACE, symbolicName); attributes.put( - IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, + IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version); attributes.put( - IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, + IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, identityType); // TODO Add directives, particularly "effective" and "singleton". } - + public OsgiIdentityCapability(Resource resource, SubsystemManifest manifest) { this( resource, @@ -59,7 +64,7 @@ public class OsgiIdentityCapability exte manifest.getSubsystemVersionHeader().getVersion(), manifest.getSubsystemTypeHeader().getType()); } - + public OsgiIdentityCapability(Resource resource, BundleManifest manifest) { this( resource, Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java Wed Jan 7 19:37:42 2015 @@ -31,12 +31,15 @@ import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.aries.subsystem.ContentHandler; +import org.apache.aries.subsystem.core.archive.Attribute; import org.apache.aries.subsystem.core.archive.DeploymentManifest; import org.apache.aries.subsystem.core.archive.Header; import org.apache.aries.subsystem.core.archive.ImportPackageHeader; import org.apache.aries.subsystem.core.archive.RequireBundleHeader; import org.apache.aries.subsystem.core.archive.RequireCapabilityHeader; import org.apache.aries.subsystem.core.archive.SubsystemContentHeader; +import org.apache.aries.subsystem.core.archive.SubsystemContentHeader.Clause; import org.apache.aries.subsystem.core.archive.SubsystemImportServiceHeader; import org.apache.aries.subsystem.core.archive.SubsystemLocalizationHeader; import org.apache.aries.subsystem.core.archive.SubsystemManifest; @@ -66,35 +69,35 @@ import org.slf4j.LoggerFactory; public class RawSubsystemResource implements Resource { private static final Logger logger = LoggerFactory.getLogger(RawSubsystemResource.class); - + private static final Pattern PATTERN = Pattern.compile("([^@/\\\\]+)(?:@(.+))?.esa"); private static final String APPLICATION_IMPORT_SERVICE_HEADER = "Application-ImportService"; - + private static SubsystemManifest computeExistingSubsystemManifest(IDirectory directory) throws IOException { Manifest manifest = ManifestProcessor.obtainManifestFromAppDir(directory, "OSGI-INF/SUBSYSTEM.MF"); if (manifest == null) return null; return new SubsystemManifest(manifest); } - + private static SubsystemManifest computeNewSubsystemManifest() { return new SubsystemManifest.Builder().build(); } - + private static SubsystemManifest computeSubsystemManifest(IDirectory directory) throws IOException { SubsystemManifest result = computeExistingSubsystemManifest(directory); if (result == null) result = computeNewSubsystemManifest(); return result; } - + private static String convertFileToLocation(IFile file) throws MalformedURLException { String result = convertFileNameToLocation(file.getName()); if (result == null) result = file.toURL().toString(); return result; } - + private static String convertFileNameToLocation(String fileName) { Matcher matcher = PATTERN.matcher(fileName); if (!matcher.matches()) @@ -103,26 +106,28 @@ public class RawSubsystemResource implem return new SubsystemUri(matcher.group(1), version == null ? null : Version.parseVersion(version), null).toString(); } - + private final List<Capability> capabilities; private final DeploymentManifest deploymentManifest; private final long id; private final org.apache.aries.subsystem.core.repository.Repository localRepository; private final Location location; + private final BasicSubsystem parentSubsystem; private final List<Requirement> requirements; private final Collection<Resource> resources; private final Resource fakeImportServiceResource; private final SubsystemManifest subsystemManifest; private final Collection<TranslationFile> translations; - - public RawSubsystemResource(String location, IDirectory content) throws URISyntaxException, IOException, ResolutionException { + + public RawSubsystemResource(String location, IDirectory content, BasicSubsystem parent) throws URISyntaxException, IOException, ResolutionException { id = SubsystemIdentifier.getNextId(); this.location = new Location(location); + this.parentSubsystem = parent; if (content == null) content = this.location.open(); try { - resources = computeResources(content); - SubsystemManifest manifest = computeSubsystemManifest(content); + SubsystemManifest manifest = computeSubsystemManifest(content); + resources = computeResources(content, manifest); fakeImportServiceResource = createFakeResource(manifest); localRepository = computeLocalRepository(); manifest = computeSubsystemManifestBeforeRequirements(manifest); @@ -136,12 +141,12 @@ public class RawSubsystemResource implem IOUtils.close(content.toCloseable()); } } - - public RawSubsystemResource(File file) throws IOException, URISyntaxException, ResolutionException { - this(FileSystem.getFSRoot(file)); + + public RawSubsystemResource(File file, BasicSubsystem parent) throws IOException, URISyntaxException, ResolutionException { + this(FileSystem.getFSRoot(file), parent); } - - public RawSubsystemResource(IDirectory idir) throws IOException, URISyntaxException, ResolutionException { + + public RawSubsystemResource(IDirectory idir, BasicSubsystem parent) throws IOException, URISyntaxException, ResolutionException { resources = Collections.emptyList(); fakeImportServiceResource = null; // not needed for persistent subsystems localRepository = computeLocalRepository(); @@ -151,6 +156,7 @@ public class RawSubsystemResource implem deploymentManifest = initializeDeploymentManifest(idir); id = Long.parseLong(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_ID).getValue()); location = new Location(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LOCATION).getValue()); + parentSubsystem = parent; translations = Collections.emptyList(); } @@ -222,19 +228,19 @@ public class RawSubsystemResource implem result.trimToSize(); return Collections.unmodifiableList(result); } - + public DeploymentManifest getDeploymentManifest() { return deploymentManifest; } - + public long getId() { return id; } - + public org.apache.aries.subsystem.core.repository.Repository getLocalRepository() { return localRepository; } - + public Location getLocation() { return location; } @@ -250,11 +256,11 @@ public class RawSubsystemResource implem result.trimToSize(); return Collections.unmodifiableList(result); } - + public SubsystemManifest getSubsystemManifest() { return subsystemManifest; } - + public Collection<TranslationFile> getTranslations() { return translations; } @@ -265,56 +271,56 @@ public class RawSubsystemResource implem result = 31 * result + getLocation().hashCode(); return result; } - + private void addHeader(SubsystemManifest.Builder builder, Header<?> header) { if (header == null) return; builder.header(header); } - + private void addImportPackageHeader(SubsystemManifest.Builder builder) { addHeader(builder, computeImportPackageHeader()); } - + private void addRequireBundleHeader(SubsystemManifest.Builder builder) { addHeader(builder, computeRequireBundleHeader()); } - + private void addRequireCapabilityHeader(SubsystemManifest.Builder builder) { addHeader(builder, computeRequireCapabilityHeader()); } - + private void addSubsystemContentHeader(SubsystemManifest.Builder builder, SubsystemManifest manifest) { addHeader(builder, computeSubsystemContentHeader(manifest)); } - + private void addSubsystemImportServiceHeader(SubsystemManifest.Builder builder) { addHeader(builder, computeSubsystemImportServiceHeader()); } - + private void addSubsystemSymbolicNameHeader(SubsystemManifest.Builder builder, SubsystemManifest manifest) { addHeader(builder, computeSubsystemSymbolicNameHeader(manifest)); } - + private void addSubsystemVersionHeader(SubsystemManifest.Builder builder, SubsystemManifest manifest) { addHeader(builder, computeSubsystemVersionHeader(manifest)); } - + private List<Capability> computeCapabilities() { return subsystemManifest.toCapabilities(this); } - + private DeploymentManifest computeDeploymentManifest(IDirectory directory) throws IOException { return computeExistingDeploymentManifest(directory); } - + private DeploymentManifest computeExistingDeploymentManifest(IDirectory directory) throws IOException { Manifest manifest = ManifestProcessor.obtainManifestFromAppDir(directory, "OSGI-INF/DEPLOYMENT.MF"); if (manifest == null) return null; return new DeploymentManifest(manifest); } - + private ImportPackageHeader computeImportPackageHeader() { if (requirements.isEmpty()) return null; @@ -329,7 +335,7 @@ public class RawSubsystemResource implem clauses.trimToSize(); return new ImportPackageHeader(clauses); } - + private org.apache.aries.subsystem.core.repository.Repository computeLocalRepository() { if (fakeImportServiceResource != null) { Collection<Resource> temp = new ArrayList<Resource>(resources); @@ -338,7 +344,7 @@ public class RawSubsystemResource implem } return new LocalRepository(resources); } - + private RequireBundleHeader computeRequireBundleHeader() { if (requirements.isEmpty()) return null; @@ -353,14 +359,14 @@ public class RawSubsystemResource implem clauses.trimToSize(); return new RequireBundleHeader(clauses); } - + private RequireCapabilityHeader computeRequireCapabilityHeader() { if (requirements.isEmpty()) return null; ArrayList<RequireCapabilityHeader.Clause> clauses = new ArrayList<RequireCapabilityHeader.Clause>(); for (Requirement requirement : requirements) { String namespace = requirement.getNamespace(); - if (namespace.startsWith("osgi.") && + if (namespace.startsWith("osgi.") && // Don't filter out the osgi.ee namespace. !namespace.equals(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE)) continue; @@ -371,7 +377,7 @@ public class RawSubsystemResource implem clauses.trimToSize(); return new RequireCapabilityHeader(clauses); } - + private List<Requirement> computeRequirements(SubsystemManifest manifest) throws ResolutionException { if (isComposite(manifest)) { // Composites determine their own requirements. @@ -403,58 +409,85 @@ public class RawSubsystemResource implem // dependencies not satisfied by the content resources themselves. return new DependencyCalculator(resources).calculateDependencies(); } - - private Collection<Resource> computeResources(IDirectory directory) throws IOException, URISyntaxException, ResolutionException { + + private Collection<Resource> computeResources(IDirectory directory, SubsystemManifest manifest) throws IOException, URISyntaxException, ResolutionException { List<IFile> files = directory.listFiles(); if (files.isEmpty()) return Collections.emptyList(); ArrayList<Resource> result = new ArrayList<Resource>(files.size()); for (IFile file : directory.listFiles()) { - String name = file.getName(); - if (file.isFile()) { - // Subsystem resources must end with ".esa". - if (name.endsWith(".esa")) - result.add(new RawSubsystemResource(convertFileToLocation(file), file.convertNested())); - else { - // Assume all other resources are bundles. - try { - result.add(new BundleResource(file)); - } - catch (Exception e) { - // Ignore if the resource is an invalid bundle or not a bundle at all. - if (logger.isDebugEnabled()) { - logger.debug("File \"" + file.getName() + "\" in subsystem with location \"" + location + "\" will be ignored because it is not recognized as a supported resource", e); - } - } - } - } - else { - if (name.endsWith(".esa")) - result.add(new RawSubsystemResource(convertFileToLocation(file), file.convert())); - else { - try { - result.add(new BundleResource(file)); - } - catch (Exception e) { - // Ignore - if (logger.isDebugEnabled()) { - logger.debug("File \"" + file.getName() + "\" in subsystem with location \"" + location + "\" will be ignored because it is not recognized as a supported resource", e); - } - } - } - } + if (file.isFile()) { + addResource(file, file.convertNested(), manifest, result); + } else { + addResource(file, file.convert(), manifest, result); + } } result.trimToSize(); return result; } - - private SubsystemContentHeader computeSubsystemContentHeader(SubsystemManifest manifest) { + + private void addResource(IFile file, IDirectory content, SubsystemManifest manifest, ArrayList<Resource> result) throws URISyntaxException, + IOException, ResolutionException, MalformedURLException { + String name = file.getName(); + if (name.endsWith(".esa")) { + result.add(new RawSubsystemResource(convertFileToLocation(file), content, parentSubsystem)); + } else if (name.endsWith(".jar")) { + result.add(new BundleResource(file)); + } else { + // This is a different type of file. Add a file resource for it if there is a custom content handler for it. + FileResource fr = new FileResource(file); + fr.setCapabilities(computeFileCapabilities(fr, file, manifest)); + List<Capability> idcaps = fr.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE); + if (idcaps.size() > 0) { + Capability idcap = idcaps.get(0); + Object type = idcap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE); + if (type instanceof String && parentSubsystem != null) { + if (CustomResources.getCustomContentHandler(parentSubsystem, (String) type) != null) { + // Yes, there is a custom content handler, add it. + result.add(fr); + return; + } + } + } + + // There is no custom handler for this resource, let's check if it turns out to be a bundle + try { + result.add(new BundleResource(file)); + } catch (Exception e) { + // Ignore if the resource is an invalid bundle or not a bundle at all. + if (logger.isDebugEnabled()) { + logger.debug("File \"" + file.getName() + "\" in subsystem with location \"" + location + "\" will be ignored because it is not recognized as a supported resource", e); + } + } + } + } + + private List<Capability> computeFileCapabilities(FileResource resource, IFile file, SubsystemManifest manifest) { + SubsystemContentHeader ssch = manifest.getSubsystemContentHeader(); + if (ssch == null) + return Collections.emptyList(); + + for (Clause c : ssch.getClauses()) { + Attribute er = c.getAttribute(ContentHandler.EMBEDDED_RESOURCE_ATTRIBUTE); + if (er != null) { + if (file.getName().equals(er.getValue())) { + Map<String, Object> attrs = new HashMap<String, Object>(); + attrs.put(ContentHandler.EMBEDDED_RESOURCE_ATTRIBUTE, er.getValue()); + return Collections.<Capability> singletonList( + new OsgiIdentityCapability(resource, c.getSymbolicName(), c.getVersionRange().getLeft(), c.getType(), attrs)); + } + } + } + return Collections.emptyList(); + } + + private SubsystemContentHeader computeSubsystemContentHeader(SubsystemManifest manifest) { SubsystemContentHeader header = manifest.getSubsystemContentHeader(); if (header == null && !resources.isEmpty()) header = SubsystemContentHeader.newInstance(resources); return header; } - + private SubsystemImportServiceHeader computeSubsystemImportServiceHeader() { if (requirements.isEmpty()) return null; @@ -469,7 +502,7 @@ public class RawSubsystemResource implem clauses.trimToSize(); return new SubsystemImportServiceHeader(clauses); } - + private SubsystemManifest computeSubsystemManifestAfterRequirements(SubsystemManifest manifest) { if (isComposite(manifest)) return manifest; @@ -480,7 +513,7 @@ public class RawSubsystemResource implem addSubsystemImportServiceHeader(builder); return builder.build(); } - + private SubsystemManifest computeSubsystemManifestBeforeRequirements(SubsystemManifest manifest) { SubsystemManifest.Builder builder = new SubsystemManifest.Builder().manifest(manifest); addSubsystemSymbolicNameHeader(builder, manifest); @@ -488,7 +521,7 @@ public class RawSubsystemResource implem addSubsystemContentHeader(builder, manifest); return builder.build(); } - + private SubsystemSymbolicNameHeader computeSubsystemSymbolicNameHeader(SubsystemManifest manifest) { SubsystemSymbolicNameHeader header = manifest.getSubsystemSymbolicNameHeader(); if (header != null) @@ -498,14 +531,14 @@ public class RawSubsystemResource implem symbolicName = "org.apache.aries.subsystem." + id; return new SubsystemSymbolicNameHeader(symbolicName); } - + private SubsystemVersionHeader computeSubsystemVersionHeader(SubsystemManifest manifest) { SubsystemVersionHeader header = manifest.getSubsystemVersionHeader(); if (header.getVersion().equals(Version.emptyVersion) && location.getVersion() != null) header = new SubsystemVersionHeader(location.getVersion()); return header; } - + private Collection<TranslationFile> computeTranslations(IDirectory directory) throws IOException { SubsystemManifest manifest = getSubsystemManifest(); SubsystemLocalizationHeader header = manifest.getSubsystemLocalizationHeader(); @@ -547,7 +580,7 @@ public class RawSubsystemResource implem .state(State.INSTALLING) .build(); } - + private SubsystemManifest initializeSubsystemManifest(IDirectory idir) throws IOException { Manifest manifest = ManifestProcessor.obtainManifestFromAppDir(idir, @@ -565,7 +598,7 @@ public class RawSubsystemResource implem + SubsystemTypeHeader.PROVISION_POLICY_ACCEPT_DEPENDENCIES) .build(); } - + private boolean isComposite(SubsystemManifest manifest) { return SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(manifest.getSubsystemTypeHeader().getType()); } Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java Wed Jan 7 19:37:42 2015 @@ -13,8 +13,10 @@ */ package org.apache.aries.subsystem.core.internal; +import org.apache.aries.subsystem.ContentHandler; import org.apache.aries.subsystem.core.archive.DeployedContentHeader; import org.apache.aries.subsystem.core.archive.DeploymentManifest; +import org.osgi.framework.ServiceReference; import org.osgi.framework.namespace.IdentityNamespace; import org.osgi.resource.Resource; import org.osgi.service.coordinator.Coordination; @@ -27,28 +29,32 @@ public abstract class ResourceInstaller String type = ResourceHelper.getTypeAttribute(resource); if (SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION.equals(type) || SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type) - || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) + || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) { return new SubsystemResourceInstaller(coordination, resource, subsystem); - else if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type)) + } else if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type)) { return new BundleResourceInstaller(coordination, resource, subsystem); - else if (Constants.ResourceTypeSynthesized.equals(type)) { + } else if (Constants.ResourceTypeSynthesized.equals(type)) { return new ResourceInstaller(coordination, resource, subsystem) { - @Override public Resource install() throws Exception { // do nothing; return resource; } }; + } else { + ServiceReference<ContentHandler> handlerRef = CustomResources.getCustomContentHandler(subsystem, type); + if (handlerRef != null) + return new CustomResourceInstaller(coordination, resource, type, subsystem, handlerRef); + } - throw new SubsystemException("No installer exists for resource type: " + type); + throw new SubsystemException("No installer exists for resource type: " + type); } - - protected final Coordination coordination; + + protected final Coordination coordination; protected final BasicSubsystem provisionTo; protected final Resource resource; protected final BasicSubsystem subsystem; - + public ResourceInstaller(Coordination coordination, Resource resource, BasicSubsystem subsystem) { this.coordination = coordination; this.resource = resource; @@ -62,9 +68,9 @@ public abstract class ResourceInstaller else provisionTo = subsystem; } - + public abstract Resource install() throws Exception; - + protected void addConstituent(final Resource resource) { // Don't let a resource become a constituent of itself. if (provisionTo == null || resource.equals(provisionTo)) @@ -82,7 +88,7 @@ public abstract class ResourceInstaller } }); } - + protected void addReference(final Resource resource) { // Don't let a resource reference itself. if (resource.equals(subsystem)) @@ -106,19 +112,19 @@ public abstract class ResourceInstaller }); } } - + protected String getLocation() { return provisionTo.getLocation() + "!/" + ResourceHelper.getLocation(resource); } - + protected boolean isContent() { return Utils.isContent(subsystem, resource); } - + protected boolean isDependency() { return Utils.isDependency(subsystem, resource); } - + protected boolean isReferencedProvisionTo() { DeploymentManifest manifest = subsystem.getDeploymentManifest(); if (manifest != null) { @@ -130,7 +136,7 @@ public abstract class ResourceInstaller return isReferencedSubsystem(); return false; } - + protected boolean isReferencedSubsystem() { DeploymentManifest manifest = subsystem.getDeploymentManifest(); if (manifest != null) { Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceUninstaller.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceUninstaller.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceUninstaller.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceUninstaller.java Wed Jan 7 19:37:42 2015 @@ -13,7 +13,9 @@ */ package org.apache.aries.subsystem.core.internal; +import org.apache.aries.subsystem.ContentHandler; import org.apache.aries.subsystem.core.archive.ProvisionResourceHeader; +import org.osgi.framework.ServiceReference; import org.osgi.framework.namespace.IdentityNamespace; import org.osgi.framework.wiring.BundleRevision; import org.osgi.resource.Resource; @@ -24,31 +26,37 @@ import org.slf4j.LoggerFactory; public abstract class ResourceUninstaller { private static final Logger logger = LoggerFactory.getLogger(ResourceUninstaller.class); - + public static ResourceUninstaller newInstance(Resource resource, BasicSubsystem subsystem) { String type = ResourceHelper.getTypeAttribute(resource); if (SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION.equals(type) || SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type) - || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) + || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) { return new SubsystemResourceUninstaller(resource, subsystem); - else if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type)) + } else if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type)) { return new BundleResourceUninstaller(resource, subsystem); - else - throw new SubsystemException("No uninstaller exists for resource type: " + type); + } else { + ServiceReference<ContentHandler> handlerRef = CustomResources.getCustomContentHandler(subsystem, type); + if (handlerRef != null) { + return new CustomResourceUninstaller(resource, type, subsystem, handlerRef); + } else { + throw new SubsystemException("No uninstaller exists for resource type: " + type); + } + } } - + protected static void removeConstituent(BasicSubsystem subsystem, Resource resource) { Activator.getInstance().getSubsystems().removeConstituent(subsystem, resource); } - + protected static void removeReference(BasicSubsystem subsystem, Resource resource) { Activator.getInstance().getSubsystems().removeReference(subsystem, resource); } - + protected final BasicSubsystem provisionTo; protected final Resource resource; protected final BasicSubsystem subsystem; - + public ResourceUninstaller(Resource resource, BasicSubsystem subsystem) { if (resource == null) throw new NullPointerException("Missing required parameter: resource"); @@ -61,9 +69,9 @@ public abstract class ResourceUninstalle else provisionTo = subsystem; } - + public abstract void uninstall(); - + protected boolean isExplicit() { // The operation is explicit if it was requested by a user, in which // case the resource and subsystem are the same. @@ -80,14 +88,14 @@ public abstract class ResourceUninstalle } return false; } - + protected boolean isTransitive() { ProvisionResourceHeader header = subsystem.getDeploymentManifest().getProvisionResourceHeader(); if (header == null) return false; return header.contains(resource); } - + protected boolean isResourceUninstallable() { int referenceCount = Activator.getInstance().getSubsystems().getSubsystemsReferencing(resource).size(); if (referenceCount == 0) @@ -98,11 +106,11 @@ public abstract class ResourceUninstalle } return false; } - + protected void removeConstituent() { removeConstituent(subsystem, resource); } - + protected void removeReference() { removeReference(subsystem, resource); } Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java Wed Jan 7 19:37:42 2015 @@ -22,6 +22,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Map.Entry; +import org.apache.aries.subsystem.ContentHandler; import org.apache.aries.subsystem.core.archive.ExportPackageCapability; import org.apache.aries.subsystem.core.archive.ExportPackageHeader; import org.apache.aries.subsystem.core.archive.ProvideCapabilityCapability; @@ -35,7 +36,10 @@ import org.eclipse.equinox.region.Region import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; import org.osgi.framework.namespace.IdentityNamespace; +import org.osgi.framework.startlevel.BundleStartLevel; +import org.osgi.framework.startlevel.FrameworkStartLevel; import org.osgi.framework.wiring.BundleRevision; import org.osgi.framework.wiring.FrameworkWiring; import org.osgi.resource.Resource; @@ -51,16 +55,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class StartAction extends AbstractAction { - private static final Logger logger = LoggerFactory.getLogger(BasicSubsystem.class); - + private static final Logger logger = LoggerFactory.getLogger(StartAction.class); + private final Coordination coordination; private final BasicSubsystem instigator; private final boolean resolveOnly; - + public StartAction(BasicSubsystem instigator, BasicSubsystem requestor, BasicSubsystem target) { this(instigator, requestor, target, false); } - + public StartAction(BasicSubsystem instigator, BasicSubsystem requestor, BasicSubsystem target, boolean resolveOnly) { this(instigator, requestor, target, null, resolveOnly); } @@ -75,7 +79,7 @@ public class StartAction extends Abstrac this.coordination = coordination; this.resolveOnly = resolveOnly; } - + @Override public Object run() { State state = target.getState(); @@ -129,7 +133,7 @@ public class StartAction extends Abstrac // region and transition to INSTALLED. } finally { try { - // Don't end the coordination if the subsystem being started + // Don't end the coordination if the subsystem being started // (i.e. the target) did not begin it. if (coordination.getName().equals(Utils.computeCoordinationName(target))) coordination.end(); @@ -143,7 +147,7 @@ public class StartAction extends Abstrac } return null; } - + private static Collection<Bundle> getBundles(BasicSubsystem subsystem) { Collection<Resource> constituents = Activator.getInstance().getSubsystems().getConstituents(subsystem); ArrayList<Bundle> result = new ArrayList<Bundle>(constituents.size()); @@ -154,7 +158,7 @@ public class StartAction extends Abstrac result.trimToSize(); return result; } - + private static void resolve(BasicSubsystem subsystem) { // Don't propagate a RESOLVING event if this is a persisted subsystem // that is already RESOLVED. @@ -168,16 +172,26 @@ public class StartAction extends Abstrac if (!subsystem.isRoot()) { for (Subsystem child : Activator.getInstance().getSubsystems().getChildren(subsystem)) resolve((BasicSubsystem)child); + + FrameworkWiring frameworkWiring = Activator.getInstance().getBundleContext().getBundle(0) + .adapt(FrameworkWiring.class); + // TODO I think this is insufficient. Do we need both // pre-install and post-install environments for the Resolver? Collection<Bundle> bundles = getBundles(subsystem); - if (!Activator.getInstance().getBundleContext().getBundle(0) - .adapt(FrameworkWiring.class).resolveBundles(bundles)) { + if (!frameworkWiring.resolveBundles(bundles)) { + //work out which bundles could not be resolved + Collection<Bundle> unresolved = new ArrayList<Bundle>(); + for(Bundle bundle:bundles){ + if((bundle.getState() & Bundle.RESOLVED) != Bundle.RESOLVED){ + unresolved.add(bundle); + } + } logger.error( "Unable to resolve bundles for subsystem/version/id {}/{}/{}: {}", new Object[] { subsystem.getSymbolicName(), subsystem.getVersion(), - subsystem.getSubsystemId(), bundles }); - throw new SubsystemException("Framework could not resolve the bundles"); + subsystem.getSubsystemId(), unresolved }); + throw new SubsystemException("Framework could not resolve the bundles: " + unresolved); } setExportIsolationPolicy(subsystem); } @@ -193,7 +207,7 @@ public class StartAction extends Abstrac throw new SubsystemException(t); } } - + private static void setExportIsolationPolicy(BasicSubsystem subsystem) throws InvalidSyntaxException, IOException, BundleException, URISyntaxException, ResolutionException { if (!subsystem.isComposite()) return; @@ -211,7 +225,7 @@ public class StartAction extends Abstrac + ", to=" + to + ", filter=" + regionFilter); from.connectRegion(to, regionFilter); } - + private static void setExportIsolationPolicy(RegionFilterBuilder builder, ExportPackageHeader header, BasicSubsystem subsystem) throws InvalidSyntaxException { if (header == null) return; @@ -226,7 +240,7 @@ public class StartAction extends Abstrac builder.allow(policy, filter.toString()); } } - + private static void setExportIsolationPolicy(RegionFilterBuilder builder, ProvideCapabilityHeader header, BasicSubsystem subsystem) throws InvalidSyntaxException { if (header == null) return; @@ -255,7 +269,7 @@ public class StartAction extends Abstrac builder.allow(policy, filter); } } - + private void startBundleResource(Resource resource, Coordination coordination) throws BundleException { if (target.isRoot()) // Starting the root subsystem should not affect bundles within the @@ -265,37 +279,73 @@ public class StartAction extends Abstrac // The region context bundle was persistently started elsewhere. return; final Bundle bundle = ((BundleRevision)resource).getBundle(); + if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0) return; + + if (logger.isDebugEnabled()) { + int bundleStartLevel = bundle.adapt(BundleStartLevel.class).getStartLevel(); + Bundle systemBundle=Activator.getInstance().getBundleContext().getBundle(0); + int fwStartLevel = systemBundle.adapt(FrameworkStartLevel.class).getStartLevel(); + logger.debug("StartAction: starting bundle " + bundle.getSymbolicName() + + " " + bundle.getVersion().toString() + + " bundleStartLevel=" + bundleStartLevel + + " frameworkStartLevel=" + fwStartLevel); + } + bundle.start(Bundle.START_TRANSIENT | Bundle.START_ACTIVATION_POLICY); + + if (logger.isDebugEnabled()) { + logger.debug("StartAction: bundle " + bundle.getSymbolicName() + + " " + bundle.getVersion().toString() + + " started correctly"); + } + if (coordination == null) return; coordination.addParticipant(new Participant() { public void ended(Coordination coordination) throws Exception { // noop } - + public void failed(Coordination coordination) throws Exception { bundle.stop(); } }); } - + private void startResource(Resource resource, Coordination coordination) throws BundleException, IOException { String type = ResourceHelper.getTypeAttribute(resource); if (SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION.equals(type) || SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type) - || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) + || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) { startSubsystemResource(resource, coordination); - else if (IdentityNamespace.TYPE_BUNDLE.equals(type)) + } else if (IdentityNamespace.TYPE_BUNDLE.equals(type)) { startBundleResource(resource, coordination); - else if (IdentityNamespace.TYPE_FRAGMENT.equals(type)) { + } else if (IdentityNamespace.TYPE_FRAGMENT.equals(type)) { // Fragments are not started. + } else { + if (!startCustomHandler(resource, type, coordination)) + throw new SubsystemException("Unsupported resource type: " + type); } - else - throw new SubsystemException("Unsupported resource type: " + type); } + private boolean startCustomHandler(Resource resource, String type, Coordination coordination) { + ServiceReference<ContentHandler> customHandlerRef = CustomResources.getCustomContentHandler(target, type); + if (customHandlerRef != null) { + ContentHandler customHandler = target.getBundleContext().getService(customHandlerRef); + if (customHandler != null) { + try { + customHandler.start(ResourceHelper.getSymbolicNameAttribute(resource), type, target, coordination); + return true; + } finally { + target.getBundleContext().ungetService(customHandlerRef); + } + } + } + return false; + } + private void startSubsystemResource(Resource resource, Coordination coordination) throws IOException { final BasicSubsystem subsystem = (BasicSubsystem)resource; // Subsystems that are content resources of another subsystem must have @@ -309,7 +359,7 @@ public class StartAction extends Abstrac public void ended(Coordination coordination) throws Exception { // noop } - + public void failed(Coordination coordination) throws Exception { new StopAction(target, subsystem, !subsystem.isRoot()).run(); } Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java Wed Jan 7 19:37:42 2015 @@ -19,9 +19,11 @@ import java.util.Collections; import java.util.EnumSet; import java.util.List; +import org.apache.aries.subsystem.ContentHandler; import org.apache.aries.subsystem.core.archive.DeploymentManifest; import org.apache.aries.subsystem.core.archive.SubsystemContentHeader; import org.osgi.framework.BundleException; +import org.osgi.framework.ServiceReference; import org.osgi.framework.namespace.IdentityNamespace; import org.osgi.framework.wiring.BundleRevision; import org.osgi.resource.Resource; @@ -33,11 +35,11 @@ import org.slf4j.LoggerFactory; public class StopAction extends AbstractAction { private static final Logger logger = LoggerFactory.getLogger(StopAction.class); - + public StopAction(BasicSubsystem requestor, BasicSubsystem target, boolean disableRootCheck) { super(requestor, target, disableRootCheck); } - + @Override public Object run() { checkRoot(); @@ -63,7 +65,7 @@ public class StopAction extends Abstract continue; try { stopResource(resource); - } + } catch (Exception e) { logger.error("An error occurred while stopping resource " + resource + " of subsystem " + target, e); } @@ -88,29 +90,47 @@ public class StopAction extends Abstract } return null; } - + private void stopBundleResource(Resource resource) throws BundleException { if (target.isRoot()) return; ((BundleRevision)resource).getBundle().stop(); } - + private void stopResource(Resource resource) throws BundleException, IOException { if (Utils.getActiveUseCount(resource) > 0) return; String type = ResourceHelper.getTypeAttribute(resource); if (SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION.equals(type) || SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type) - || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) + || SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type)) { stopSubsystemResource(resource); - else if (IdentityNamespace.TYPE_BUNDLE.equals(type)) + } else if (IdentityNamespace.TYPE_BUNDLE.equals(type)) { stopBundleResource(resource); - else if (IdentityNamespace.TYPE_FRAGMENT.equals(type)) + } else if (IdentityNamespace.TYPE_FRAGMENT.equals(type)) { return; - else - throw new SubsystemException("Unsupported resource type: " + type); + } else { + if (!stopCustomHandler(resource, type)) + throw new SubsystemException("Unsupported resource type: " + type); + } } - + + private boolean stopCustomHandler(Resource resource, String type) { + ServiceReference<ContentHandler> customHandlerRef = CustomResources.getCustomContentHandler(target, type); + if (customHandlerRef != null) { + ContentHandler customHandler = target.getBundleContext().getService(customHandlerRef); + if (customHandler != null) { + try { + customHandler.stop(ResourceHelper.getSymbolicNameAttribute(resource), type, target); + return true; + } finally { + target.getBundleContext().ungetService(customHandlerRef); + } + } + } + return false; + } + private void stopSubsystemResource(Resource resource) throws IOException { new StopAction(target, (BasicSubsystem)resource, !((BasicSubsystem)resource).isRoot()).run(); } Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java Wed Jan 7 19:37:42 2015 @@ -72,7 +72,7 @@ import org.osgi.service.subsystem.Subsys public class SubsystemResource implements Resource { private Region region; - + private final List<Capability> capabilities; private final DeploymentManifest deploymentManifest; private final Collection<Resource> installableContent = new HashSet<Resource>(); @@ -84,11 +84,11 @@ public class SubsystemResource implement private final RawSubsystemResource resource; private final Collection<Resource> sharedContent = new HashSet<Resource>(); private final Collection<Resource> sharedDependencies = new HashSet<Resource>(); - + public SubsystemResource(String location, IDirectory content, BasicSubsystem parent) throws URISyntaxException, IOException, ResolutionException, BundleException, InvalidSyntaxException { - this(new RawSubsystemResource(location, content), parent); + this(new RawSubsystemResource(location, content, parent), parent); } - + public SubsystemResource(RawSubsystemResource resource, BasicSubsystem parent) throws IOException, BundleException, InvalidSyntaxException, URISyntaxException { this.parent = parent; this.resource = resource; @@ -97,20 +97,20 @@ public class SubsystemResource implement computeDependencies(resource.getDeploymentManifest()); deploymentManifest = computeDeploymentManifest(); } - + public SubsystemResource(File file) throws IOException, URISyntaxException, ResolutionException, BundleException, InvalidSyntaxException { this(FileSystem.getFSRoot(file)); } - + public SubsystemResource(IDirectory directory) throws IOException, URISyntaxException, ResolutionException, BundleException, InvalidSyntaxException { parent = null; - resource = new RawSubsystemResource(directory); + resource = new RawSubsystemResource(directory, parent); deploymentManifest = resource.getDeploymentManifest(); computeContentResources(deploymentManifest); capabilities = computeCapabilities(); computeDependencies(deploymentManifest); } - + @Override public boolean equals(Object o) { if (o == this) @@ -125,7 +125,7 @@ public class SubsystemResource implement public List<Capability> getCapabilities(String namespace) { return Collections.unmodifiableList(capabilities); } - + private List<Capability> computeCapabilities() throws InvalidSyntaxException { List<Capability> capabilities = new ArrayList<Capability>(); if (isScoped()) @@ -134,18 +134,18 @@ public class SubsystemResource implement computeUnscopedCapabilities(capabilities); return capabilities; } - + private void computeUnscopedCapabilities(List<Capability> capabilities) { capabilities.addAll(resource.getCapabilities(null)); for (Resource r : getContentResources()) capabilities.addAll(r.getCapabilities(null)); } - + private void computeScopedCapabilities(List<Capability> capabilities) throws InvalidSyntaxException { capabilities.addAll(resource.getCapabilities(null)); computeOsgiServiceCapabilities(capabilities); } - + private void computeOsgiServiceCapabilities(List<Capability> capabilities) throws InvalidSyntaxException { SubsystemExportServiceHeader header = getSubsystemManifest().getSubsystemExportServiceHeader(); if (header == null) @@ -153,31 +153,31 @@ public class SubsystemResource implement for (Resource resource : getContentResources()) capabilities.addAll(header.toCapabilities(resource)); } - + public DeploymentManifest getDeploymentManifest() { return deploymentManifest; } - + public long getId() { return resource.getId(); } - + public Collection<Resource> getInstallableContent() { return installableContent; } - + public Collection<Resource> getInstallableDependencies() { return installableDependencies; } - + public org.apache.aries.subsystem.core.repository.Repository getLocalRepository() { return resource.getLocalRepository(); } - + public String getLocation() { return resource.getLocation().getValue(); } - + Collection<Resource> getMandatoryResources() { return mandatoryResources; } @@ -185,7 +185,7 @@ public class SubsystemResource implement public Collection<DeployedContentHeader.Clause> getMissingResources() { return missingResources; } - + Collection<Resource> getOptionalResources() { return optionalResources; } @@ -203,7 +203,7 @@ public class SubsystemResource implement } return Collections.singleton(parent); } - + public synchronized Region getRegion() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException { if (region == null) { region = createRegion(getId()); @@ -240,19 +240,19 @@ public class SubsystemResource implement return result; } } - + public Collection<Resource> getSharedContent() { return sharedContent; } - + public Collection<Resource> getSharedDependencies() { return sharedDependencies; } - + public SubsystemManifest getSubsystemManifest() { return resource.getSubsystemManifest(); } - + public Collection<TranslationFile> getTranslations() { return resource.getTranslations(); } @@ -263,7 +263,7 @@ public class SubsystemResource implement result = 31 * result + getLocation().hashCode(); return result; } - + private void addContentResource(Resource resource) { if (resource == null) return; @@ -276,7 +276,7 @@ public class SubsystemResource implement else sharedContent.add(resource); } - + private void addDependency(Resource resource) { if (resource == null) return; @@ -285,11 +285,11 @@ public class SubsystemResource implement else sharedDependencies.add(resource); } - + private void addMissingResource(DeployedContentHeader.Clause resource) { missingResources.add(resource); } - + private void addSubsystemServiceImportToSharingPolicy( RegionFilterBuilder builder) throws InvalidSyntaxException, BundleException, IOException, URISyntaxException { builder.allow( @@ -302,7 +302,7 @@ public class SubsystemResource implement .append('=').append(getRegion().getName()) .append("))").toString()); } - + private void addSubsystemServiceImportToSharingPolicy(RegionFilterBuilder builder, Region to) throws InvalidSyntaxException, BundleException, IOException, URISyntaxException { Region root = Activator.getInstance().getSubsystems().getRootSubsystem().getRegion(); @@ -316,7 +316,7 @@ public class SubsystemResource implement getRegion().connectRegion(to, regionFilter); } } - + private void computeContentResources(DeploymentManifest manifest) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException { if (manifest == null) computeContentResources(getSubsystemManifest()); @@ -333,7 +333,7 @@ public class SubsystemResource implement } } } - + private void computeContentResources(SubsystemManifest manifest) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException { SubsystemContentHeader contentHeader = manifest.getSubsystemContentHeader(); if (contentHeader == null) @@ -349,7 +349,7 @@ public class SubsystemResource implement addContentResource(resource); } } - + private void computeDependencies(DeploymentManifest manifest) { if (manifest == null) computeDependencies(getSubsystemManifest()); @@ -363,9 +363,9 @@ public class SubsystemResource implement 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); } - } + } } - + private void computeDependencies(SubsystemManifest manifest) { SubsystemContentHeader contentHeader = manifest.getSubsystemContentHeader(); try { @@ -397,14 +397,14 @@ public class SubsystemResource implement throw new SubsystemException(e); } } - + private DeployedContentHeader computeDeployedContentHeader() { Collection<Resource> content = getContentResources(); if (content.isEmpty()) return null; return DeployedContentHeader.newInstance(content); } - + private DeploymentManifest computeDeploymentManifest() throws IOException { DeploymentManifest result = computeExistingDeploymentManifest(); if (result != null) @@ -414,18 +414,18 @@ public class SubsystemResource implement .header(computeProvisionResourceHeader()).build(); return result; } - + private DeploymentManifest computeExistingDeploymentManifest() throws IOException { return resource.getDeploymentManifest(); } - + private ProvisionResourceHeader computeProvisionResourceHeader() { Collection<Resource> dependencies = getDepedencies(); if (dependencies.isEmpty()) return null; return ProvisionResourceHeader.newInstance(dependencies); } - + private Region createRegion(long id) throws BundleException { if (!isScoped()) return getParents().iterator().next().getRegion(); @@ -450,11 +450,11 @@ public class SubsystemResource implement return digraph.createRegion(name); return region; } - + private ResolveContext createResolveContext() { return new org.apache.aries.subsystem.core.internal.ResolveContext(this); } - + private Resource findContent(Requirement requirement) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException { Map<Requirement, Collection<Capability>> map; // TODO System repository for scoped subsystems should be searched in @@ -489,7 +489,7 @@ public class SubsystemResource implement return capabilities.iterator().next().getResource(); return null; } - + private Resource findContent(DeployedContentHeader.Clause clause) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException { Attribute attribute = clause.getAttribute(DeployedContentHeader.Clause.ATTRIBUTE_RESOURCEID); long resourceId = attribute == null ? -1 : Long.parseLong(String.valueOf(attribute.getValue())); @@ -506,7 +506,7 @@ public class SubsystemResource implement } return findContent(clause.toRequirement(this)); } - + private Resource findDependency(ProvisionResourceHeader.Clause clause) { Attribute attribute = clause.getAttribute(DeployedContentHeader.Clause.ATTRIBUTE_RESOURCEID); long resourceId = attribute == null ? -1 : Long.parseLong(String.valueOf(attribute.getValue())); @@ -525,26 +525,26 @@ public class SubsystemResource implement return null; return capabilities.get(0).getResource(); } - + private Collection<Resource> getContentResources() { Collection<Resource> result = new ArrayList<Resource>(installableContent.size() + sharedContent.size()); result.addAll(installableContent); result.addAll(sharedContent); return result; } - + private Collection<Resource> getDepedencies() { Collection<Resource> result = new ArrayList<Resource>(installableDependencies.size() + sharedDependencies.size()); result.addAll(installableDependencies); result.addAll(sharedDependencies); return result; } - + boolean isApplication() { String type = resource.getSubsystemManifest().getSubsystemTypeHeader().getType(); return SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION.equals(type); } - + boolean isComposite() { String type = resource.getSubsystemManifest().getSubsystemTypeHeader().getType(); return SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type); @@ -553,30 +553,30 @@ public class SubsystemResource implement private boolean isInstallable(Resource resource) { return !isShared(resource); } - + private boolean isMandatory(Resource resource) { SubsystemContentHeader header = this.resource.getSubsystemManifest().getSubsystemContentHeader(); if (header == null) return false; return header.isMandatory(resource); } - + boolean isRoot() { return BasicSubsystem.ROOT_LOCATION.equals(getLocation()); } - + private boolean isShared(Resource resource) { return Utils.isSharedResource(resource); } - + private boolean isScoped() { return isApplication() || isComposite(); } - + private boolean isUnscoped() { return !isScoped(); } - + private void setImportIsolationPolicy(Map<Resource, List<Wire>> resolution) throws Exception { if (!isApplication()) { return; @@ -623,14 +623,14 @@ public class SubsystemResource implement RegionFilter regionFilter = builder.build(); from.connectRegion(to, regionFilter); } - + private void setImportIsolationPolicy() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException { if (isRoot() || !isScoped()) return; Region region = getRegion(); Region from = region; RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder(); - Region to = ((BasicSubsystem)getParents().iterator().next()).getRegion(); + Region to = getParents().iterator().next().getRegion(); addSubsystemServiceImportToSharingPolicy(builder, to); // TODO Is this check really necessary? Looks like it was done at the beginning of this method. if (isScoped()) { @@ -654,7 +654,7 @@ public class SubsystemResource implement RegionFilter regionFilter = builder.build(); from.connectRegion(to, regionFilter); } - + private void setImportIsolationPolicy(RegionFilterBuilder builder, ImportPackageHeader header) throws InvalidSyntaxException { String policy = RegionFilter.VISIBLE_PACKAGE_NAMESPACE; if (header == null) @@ -676,7 +676,7 @@ public class SubsystemResource implement builder.allow(policy, filter); } } - + private void setImportIsolationPolicy(RegionFilterBuilder builder, RequireCapabilityHeader header) throws InvalidSyntaxException { if (header == null) return; Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java Wed Jan 7 19:37:42 2015 @@ -30,7 +30,7 @@ public class SubsystemResourceInstaller public SubsystemResourceInstaller(Coordination coordination, Resource resource, BasicSubsystem subsystem) { super(coordination, resource, subsystem); } - + public Resource install() throws Exception { if (resource instanceof BasicSubsystem) return installAriesSubsystem((BasicSubsystem)resource); @@ -42,7 +42,7 @@ public class SubsystemResourceInstaller return installRepositoryContent(resource); } } - + private void addChild(final BasicSubsystem child) { // provisionTo will be null if the resource is an already installed // dependency. @@ -64,7 +64,7 @@ public class SubsystemResourceInstaller } }); } - + private void addSubsystem(final BasicSubsystem subsystem) { Activator.getInstance().getSubsystems().addSubsystem(subsystem); coordination.addParticipant(new Participant() { @@ -72,14 +72,14 @@ public class SubsystemResourceInstaller public void ended(Coordination arg0) throws Exception { // Nothing } - + @Override public void failed(Coordination arg0) throws Exception { Activator.getInstance().getSubsystems().removeSubsystem(subsystem); } }); } - + private BasicSubsystem installAriesSubsystem(BasicSubsystem subsystem) throws Exception { addChild(subsystem); addReference(subsystem); @@ -124,12 +124,12 @@ public class SubsystemResourceInstaller Activator.getInstance().getSubsystemServiceRegistrar().register(subsystem, this.subsystem); return subsystem; } - + private BasicSubsystem installRawSubsystemResource(RawSubsystemResource resource) throws Exception { SubsystemResource subsystemResource = new SubsystemResource(resource, provisionTo); return installSubsystemResource(subsystemResource); } - + private void installRegionContextBundle(final BasicSubsystem subsystem) throws Exception { if (!subsystem.isScoped()) return; @@ -146,14 +146,14 @@ public class SubsystemResourceInstaller } }); } - + private BasicSubsystem installRepositoryContent(Resource resource) throws Exception { Method method = resource.getClass().getMethod("getContent"); InputStream is = (InputStream)method.invoke(resource); - RawSubsystemResource rawSubsystemResource = new RawSubsystemResource(getLocation(), FileSystem.getFSRoot(is)); + RawSubsystemResource rawSubsystemResource = new RawSubsystemResource(getLocation(), FileSystem.getFSRoot(is), subsystem); return installRawSubsystemResource(rawSubsystemResource); } - + private BasicSubsystem installSubsystemResource(SubsystemResource resource) throws Exception { BasicSubsystem subsystem = new BasicSubsystem(resource); installAriesSubsystem(subsystem); Modified: aries/branches/subsystemsR6/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java Wed Jan 7 19:37:42 2015 @@ -51,6 +51,12 @@ public class LocationTest { } @Test + public void testAnyURIScheme() throws Exception { + Location l = new Location("foo://bar"); + assertEquals("foo://bar", l.getValue()); + } + + @Test public void testSubsystemLocation() throws Exception { String locationString = "subsystem://?Subsystem-SymbolicName=org.osgi.service.subsystem.root&Subsystem-Version=1.2.3"; @@ -77,7 +83,7 @@ public class LocationTest { Version v = location.getVersion(); fail("Expecting an error: " + v); } catch (IllegalArgumentException e) { - // expected + // expected } } } Modified: aries/branches/subsystemsR6/subsystem/subsystem-itests/pom.xml URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-itests/pom.xml?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-itests/pom.xml (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-itests/pom.xml Wed Jan 7 19:37:42 2015 @@ -30,7 +30,7 @@ <groupId>org.apache.aries.subsystem</groupId> <artifactId>org.apache.aries.subsystem.itests</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>Apache Aries Subsystem iTests</name> <description> Integration tests using the subsystem api, core for the implementation @@ -141,7 +141,7 @@ <groupId>org.apache.aries.subsystem</groupId> <artifactId>org.apache.aries.subsystem.core</artifactId> <scope>test</scope> - <version>1.0.1-SNAPSHOT</version> + <version>1.2.0-SNAPSHOT</version> <exclusions> <exclusion> <groupId>org.osgi</groupId> @@ -181,7 +181,7 @@ <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.configadmin</artifactId> <scope>test</scope> - <version>1.2.8</version> + <version>1.8.0</version> <exclusions> <exclusion> <groupId>org.osgi</groupId> @@ -297,7 +297,7 @@ </exclusions> </dependency> <dependency> - <groupId>org.eclipse</groupId> + <groupId>org.eclipse.tycho</groupId> <artifactId>org.eclipse.osgi</artifactId> <version>3.10.0.v20140606-1445</version> </dependency> @@ -321,24 +321,6 @@ <version>2.3</version> <executions> <execution> - <id>core-fragment</id> - <goals> - <goal>jar</goal> - </goals> - <configuration> - <archive> - <manifestFile>src/test/bundles/core.fragment/META-INF/MANIFEST.MF</manifestFile> - </archive> - <excludes> - <exclude>**/*</exclude> - </excludes> - <classesDirectory>${project.build.directory}/test-classes</classesDirectory> - <outputDirectory>${project.build.directory}/test-classes/core.fragment</outputDirectory> - <finalName>core.fragment</finalName> - </configuration> - <phase>process-test-classes</phase> - </execution> - <execution> <id>tb1-application1</id> <goals> <goal>jar</goal> @@ -447,6 +429,24 @@ </configuration> <phase>process-test-classes</phase> </execution> + <execution> + <id>tb4-composite2</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifestFile>src/test/bundles/tb4/META-INF/MANIFEST.MF</manifestFile> + </archive> + <classesDirectory>${project.build.directory}/test-classes</classesDirectory> + <includes> + <include>org/apache/aries/subsystem/itests/tb4/**</include> + </includes> + <outputDirectory>${project.build.directory}/test-classes/composite2</outputDirectory> + <finalName>tb4</finalName> + </configuration> + <phase>process-test-classes</phase> + </execution> <!-- New pom for hello + related tests, part 1 --> @@ -470,46 +470,105 @@ </execution> <execution> - <id>dynamic-import-impl</id> + <id>cm-content-bundleZ</id> <goals> <goal>jar</goal> </goals> <configuration> <archive> - <manifestFile>src/test/bundles/dynamicImport/META-INF/MANIFEST.MF</manifestFile> + <manifestFile>src/test/bundles/cmContentBundleZ/META-INF/MANIFEST.MF</manifestFile> </archive> <classesDirectory>${project.build.directory}/test-classes</classesDirectory> <includes> - <include>org/apache/aries/subsystem/itests/dynamicImport/**</include> + <include>org/apache/aries/subsystem/itests/cmcontent/impl/**</include> </includes> - <outputDirectory>${project.build.directory}/test-classes/dynamicImport</outputDirectory> - <finalName>dynamicImport</finalName> + <outputDirectory>${project.build.directory}/test-classes/cmContent</outputDirectory> + <finalName>cmContentBundleZ</finalName> </configuration> <phase>process-test-classes</phase> </execution> - <!-- End of new pom for hello tests, part 1 --> + <execution> + <id>custom-content-bundleA</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifestFile>src/test/bundles/customContentBundleA/META-INF/MANIFEST.MF</manifestFile> + </archive> + <outputDirectory>${project.build.directory}/test-classes/customContent</outputDirectory> + <finalName>customContentBundleA</finalName> + </configuration> + <phase>process-test-classes</phase> + </execution> <execution> - <id>basic-blueprint-application</id> + <id>custom-content-bundleB</id> <goals> <goal>jar</goal> </goals> <configuration> <archive> - <manifestFile>src/test/bundles/blueprint/META-INF/MANIFEST.MF</manifestFile> + <manifestFile>src/test/bundles/customContentBundleB/META-INF/MANIFEST.MF</manifestFile> + </archive> + <outputDirectory>${project.build.directory}/test-classes/customContent1</outputDirectory> + <finalName>customContentBundleB</finalName> + </configuration> + <phase>process-test-classes</phase> + </execution> + + <execution> + <id>custom-content-bundleC</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifestFile>src/test/bundles/customContentBundleC/META-INF/MANIFEST.MF</manifestFile> + </archive> + <outputDirectory>${project.build.directory}/test-classes/customContent2</outputDirectory> + <finalName>customContentBundleC</finalName> + </configuration> + <phase>process-test-classes</phase> + </execution> + + <execution> + <id>custom-content-bundleD</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifestFile>src/test/bundles/customContentBundleD/META-INF/MANIFEST.MF</manifestFile> + </archive> + <outputDirectory>${project.build.directory}/test-classes/customContent3</outputDirectory> + <finalName>customContentBundleD</finalName> + </configuration> + <phase>process-test-classes</phase> + </execution> + + <execution> + <id>dynamic-import-impl</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifestFile>src/test/bundles/dynamicImport/META-INF/MANIFEST.MF</manifestFile> </archive> <classesDirectory>${project.build.directory}/test-classes</classesDirectory> <includes> - <include>org/apache/aries/subsystem/itests/blueprint/**</include> - <include>OSGI-INF/blueprint/blueprint.xml</include> + <include>org/apache/aries/subsystem/itests/dynamicImport/**</include> </includes> - <outputDirectory>${project.build.directory}/test-classes/blueprint</outputDirectory> - <finalName>blueprint</finalName> + <outputDirectory>${project.build.directory}/test-classes/dynamicImport</outputDirectory> + <finalName>dynamicImport</finalName> </configuration> <phase>process-test-classes</phase> </execution> + <!-- End of new pom for hello tests, part 1 --> + </executions> </plugin> <plugin> @@ -518,50 +577,50 @@ <version>1.5</version> <executions> <execution> - <id>core-fragment</id> + <id>add-source-tb1</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> - <source>src/test/bundles/core.fragment</source> + <source>src/test/bundles/tb1</source> </sources> </configuration> </execution> <execution> - <id>add-source-tb1</id> + <id>add-source-tb2</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> - <source>src/test/bundles/tb1</source> + <source>src/test/bundles/tb2</source> </sources> </configuration> </execution> <execution> - <id>add-source-tb2</id> + <id>add-source-tb3</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> - <source>src/test/bundles/tb2</source> + <source>src/test/bundles/tb3</source> </sources> </configuration> </execution> <execution> - <id>add-source-tb3</id> + <id>add-source-tb4</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> - <source>src/test/bundles/tb3</source> + <source>src/test/bundles/tb4</source> </sources> </configuration> </execution> @@ -582,33 +641,33 @@ </execution> <execution> - <id>add-source-dynamicImport</id> + <id>add-source-cmContentBundleZ</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> - <source>src/test/bundles/dynamicImport</source> + <source>src/test/bundles/cmContentBundleZ</source> </sources> </configuration> </execution> - <!-- End of new pom for hello tests, part 2 --> - <execution> - <id>add-source-blueprint</id> + <id>add-source-dynamicImport</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> - <source>src/test/bundles/blueprint</source> + <source>src/test/bundles/dynamicImport</source> </sources> </configuration> </execution> + <!-- End of new pom for hello tests, part 2 --> + <execution> <id>add-source-classes</id> <phase>generate-sources</phase> Modified: aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BasicTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BasicTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BasicTest.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BasicTest.java Wed Jan 7 19:37:42 2015 @@ -18,12 +18,7 @@ */ package org.apache.aries.subsystem.itests; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceReference; import org.osgi.framework.Version; import org.osgi.service.subsystem.Subsystem; import org.osgi.service.subsystem.SubsystemConstants; @@ -36,27 +31,6 @@ public class BasicTest extends Subsystem createApplication("emptySubsystem", new String[]{}); } - /* - * When the subsystems implementation bundle is installed, there should be - * a Subsystem service available. - */ - @Test - public void test1() throws Exception { - Bundle[] bundles = bundleContext.getBundles(); - boolean found = false; - for (Bundle bundle : bundles) { - if ("org.apache.aries.subsystem.core".equals(bundle.getSymbolicName())) { - found = true; - break; - } - } - assertTrue("Subsystems implementation bundle not found", found); - ServiceReference serviceReference = bundleContext.getServiceReference(Subsystem.class); - assertNotNull("Reference to subsystem service not found", serviceReference); - Subsystem subsystem = (Subsystem) bundleContext.getService(serviceReference); - assertNotNull("Subsystem service not found", subsystem); - } - @Test public void testEmptyFeature() throws Exception { Subsystem emptyFeature = installSubsystemFromFile("emptyFeature.esa"); Modified: aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BlueprintTest.java URL: http://svn.apache.org/viewvc/aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BlueprintTest.java?rev=1650143&r1=1650142&r2=1650143&view=diff ============================================================================== --- aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BlueprintTest.java (original) +++ aries/branches/subsystemsR6/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/BlueprintTest.java Wed Jan 7 19:37:42 2015 @@ -2,10 +2,15 @@ package org.apache.aries.subsystem.itest import static org.junit.Assert.assertEquals; +import java.io.InputStream; + import org.apache.aries.itest.RichBundleContext; +import org.apache.aries.subsystem.itests.bundles.blueprint.BPHelloImpl; import org.apache.aries.subsystem.itests.hello.api.Hello; import org.junit.Test; +import org.ops4j.pax.tinybundles.core.TinyBundles; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.service.subsystem.Subsystem; /* @@ -13,15 +18,16 @@ import org.osgi.service.subsystem.Subsys */ public class BlueprintTest extends SubsystemTest { - @Override - public void createApplications() throws Exception { - createApplication("blueprint", "blueprint.jar"); - } + private static final String BLUEPRINT_ESA = "target/blueprint.esa"; + + protected void init() throws Exception { + writeToFile(createBlueprintEsa(), BLUEPRINT_ESA); + } @Test public void checkBlueprint() throws Exception { - Subsystem subsystem = installSubsystemFromFile ("blueprint.esa"); + Subsystem subsystem = installSubsystemFromFile(BLUEPRINT_ESA); try { startSubsystem(subsystem); BundleContext bc = subsystem.getBundleContext(); @@ -33,5 +39,20 @@ public class BlueprintTest extends Subsy uninstallSubsystem(subsystem); } } + + private InputStream createBlueprintEsa() throws Exception { + return TinyBundles.bundle() + .add("OSGI-INF/SUBSYSTEM.MF", getResource("blueprint/OSGI-INF/SUBSYSTEM.MF")) + .add("blueprint.jar", createBlueprintTestBundle()) + .build(TinyBundles.withBnd()); + } + + private InputStream createBlueprintTestBundle() { + return TinyBundles.bundle() + .add(BPHelloImpl.class) + .add("OSGI-INF/blueprint/blueprint.xml", getResource("blueprint/OSGI-INF/blueprint/blueprint.xml")) + .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.subsystem.itests.blueprint") + .build(TinyBundles.withBnd()); + } }
