You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2012/02/13 13:52:51 UTC
svn commit: r1243492 - in /aries/trunk/subsystem:
subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/
subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/
subsystem-core/src/main/java/org/apache/aries/subsystem/core/...
Author: jwross
Date: Mon Feb 13 12:52:50 2012
New Revision: 1243492
URL: http://svn.apache.org/viewvc?rev=1243492&view=rev
Log:
ARIES-825: Update subsystems to latest Subsystem, Resolver, and Repository APIs.
(1) fixed issue with duplicate constituents
(2) fixed issue with default values for subsystem manifest not being inserted
(3) refactored persistence to use custom headers in deployment manifest
(4) added autostart setting
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemManifest.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemVersionHeader.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/VersionHeader.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemDirectoryResource.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java Mon Feb 13 12:52:50 2012
@@ -1,160 +1,212 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
package org.apache.aries.subsystem.core.archive;
-import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
-import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
-
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
import org.apache.aries.subsystem.core.internal.Activator;
-import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;
import org.apache.aries.subsystem.core.internal.OsgiIdentityRequirement;
import org.apache.aries.subsystem.core.obr.SubsystemEnvironment;
-import org.osgi.framework.Version;
-import org.osgi.framework.resource.Capability;
-import org.osgi.framework.resource.Requirement;
+import org.apache.aries.util.manifest.ManifestProcessor;
+import org.osgi.framework.Constants;
import org.osgi.framework.resource.Resource;
-import org.osgi.framework.resource.ResourceConstants;
import org.osgi.framework.resource.Wire;
import org.osgi.service.resolver.Resolver;
+import org.osgi.service.subsystem.SubsystemConstants;
import org.osgi.service.subsystem.SubsystemException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class DeploymentManifest extends Manifest implements Resource {
- public static final String IDENTITY_TYPE = "org.apache.aries.subsystem.manifest.deployment";
-
- private static final Logger logger = LoggerFactory.getLogger(DeploymentManifest.class);
+public class DeploymentManifest {
+ public static final String DEPLOYED_CONTENT = SubsystemConstants.DEPLOYED_CONTENT;
+ public static final String DEPLOYED_EXPORTSERVICE = "Deployed-ExportService"; // TODO Needs constant on SubsystemConstants.
+ public static final String DEPLOYED_IMPORTSERVICE = "Deployed-ImportService"; // TODO Needs constant on SubsystemConstants.
+ public static final String DEPLOYMENT_MANIFESTVERSION = "Deployment-ManifestVersion"; // TODO Needs constant on SubsystemConstants.
+ public static final String EXPORT_PACKAGE = Constants.EXPORT_PACKAGE;
+ public static final String IMPORT_PACKAGE = Constants.IMPORT_PACKAGE;
+ public static final String PROVISION_RESOURCE = SubsystemConstants.PROVISION_RESOURCE;
+ public static final String REQUIRE_BUNDLE = Constants.REQUIRE_BUNDLE;
+ public static final String SUBSYSTEM_SYMBOLICNAME = SubsystemConstants.SUBSYSTEM_SYMBOLICNAME;
+ public static final String SUBSYSTEM_VERSION = SubsystemConstants.SUBSYSTEM_VERSION;
+
+ public static final String ARIESSUBSYSTEM_AUTOSTART = "AriesSubsystem-Autostart";
+ public static final String ARIESSUBSYSTEM_ID = "AriesSubsystem-Id";
+ public static final String ARIESSUBSYSTEM_LASTID = "AriesSubsystem-LastId";
+ public static final String ARIESSUBSYSTEM_LOCATION = "AriesSubsystem-Location";
+
+ private final Map<String, Header<?>> headers;
+
+ public DeploymentManifest(File file) throws FileNotFoundException, IOException {
+ Manifest manifest = ManifestProcessor.parseManifest(new FileInputStream(file));
+ Attributes attributes = manifest.getMainAttributes();
+ Map<String, Header<?>> headers = new HashMap<String, Header<?>>(attributes.size() + 4); // Plus the # of potentially derived headers.
+ for (Entry<Object, Object> entry : attributes.entrySet()) {
+ String key = String.valueOf(entry.getKey());
+ headers.put(key, HeaderFactory.createHeader(key, String.valueOf(entry.getValue())));
+ }
+ this.headers = Collections.unmodifiableMap(headers);
+ }
- public static DeploymentManifest newInstance(SubsystemManifest manifest, SubsystemEnvironment environment) {
- if (logger.isDebugEnabled())
- logger.debug(LOG_ENTRY, "newInstance", new Object[]{manifest, environment});
- DeploymentManifest result = new DeploymentManifest();
- result.headers.put(ManifestVersionHeader.NAME, manifest.getManifestVersion());
- Collection<Resource> resources = new HashSet<Resource>();
- SubsystemContentHeader contentHeader = manifest.getSubsystemContent();
- if (contentHeader != null) {
- for (SubsystemContentHeader.Content content : contentHeader.getContents()) {
- OsgiIdentityRequirement requirement = new OsgiIdentityRequirement(content.getName(), content.getVersionRange(), content.getType(), false);
- Resource resource = environment.findResource(requirement);
- // If the resource is null, can't continue.
- // TODO Actually, can continue if resource is optional.
- if (resource == null)
- throw new SubsystemException("Resource does not exist: " + requirement);
- resources.add(resource);
+// public DeploymentManifest(DeploymentManifest manifest, boolean autostart, long id, long lastId, String location) {
+// Map<String, Header<?>> headers = new HashMap<String, Header<?>>(manifest.getHeaders());
+// headers.put(ARIESSUBSYSTEM_AUTOSTART, new GenericHeader(ARIESSUBSYSTEM_AUTOSTART, Boolean.toString(autostart)));
+// headers.put(ARIESSUBSYSTEM_ID, new GenericHeader(ARIESSUBSYSTEM_ID, Long.toString(id)));
+// headers.put(ARIESSUBSYSTEM_LOCATION, new GenericHeader(ARIESSUBSYSTEM_LOCATION, location));
+// headers.put(ARIESSUBSYSTEM_LASTID, new GenericHeader(ARIESSUBSYSTEM_LASTID, Long.toString(lastId)));
+// this.headers = Collections.unmodifiableMap(headers);
+// }
+//
+// public DeploymentManifest(SubsystemManifest manifest, SubsystemEnvironment environment) {
+// this(null, manifest, environment);
+// }
+
+ public DeploymentManifest(
+ DeploymentManifest deploymentManifest,
+ SubsystemManifest subsystemManifest,
+ SubsystemEnvironment environment,
+ boolean autostart,
+ long id,
+ long lastId,
+ String location,
+ boolean overwrite) {
+ Map<String, Header<?>> headers;
+ if (deploymentManifest == null // We're generating a new deployment manifest.
+ || (deploymentManifest != null && overwrite)) { // A deployment manifest already exists but overwriting it with subsystem manifest content is desired.
+ headers = new HashMap<String, Header<?>>();
+ Collection<Resource> resources = new HashSet<Resource>();
+ SubsystemContentHeader contentHeader = subsystemManifest.getSubsystemContentHeader();
+ if (contentHeader != null) {
+ for (SubsystemContentHeader.Content content : contentHeader.getContents()) {
+ OsgiIdentityRequirement requirement = new OsgiIdentityRequirement(content.getName(), content.getVersionRange(), content.getType(), false);
+ Resource resource = environment.findResource(requirement);
+ // If the resource is null, can't continue.
+ // TODO Actually, can continue if resource is optional.
+ if (resource == null)
+ throw new SubsystemException("Resource does not exist: " + requirement);
+ resources.add(resource);
+ }
+ // TODO This does not validate that all content bundles were found.
+ Map<Resource, List<Wire>> resolution = Activator.getInstance().getServiceProvider().getService(Resolver.class).resolve(environment, new ArrayList<Resource>(resources), Collections.EMPTY_LIST);
+ // TODO Once we have a resolver that actually returns lists of wires, we can use them to compute other manifest headers such as Import-Package.
+ Collection<Resource> deployedContent = new HashSet<Resource>();
+ Collection<Resource> provisionResource = new HashSet<Resource>();
+ for (Resource resource : resolution.keySet()) {
+ if (contentHeader.contains(resource))
+ deployedContent.add(resource);
+ else
+ provisionResource.add(resource);
+ }
+ // Make sure any already resolved content resources are added back in.
+ deployedContent.addAll(resources);
+ headers.put(DEPLOYED_CONTENT, DeployedContentHeader.newInstance(deployedContent));
+ if (!provisionResource.isEmpty())
+ headers.put(PROVISION_RESOURCE, ProvisionResourceHeader.newInstance(provisionResource));
}
- // TODO This does not validate that all content bundles were found.
- Map<Resource, List<Wire>> resolution = Activator.getInstance().getServiceProvider().getService(Resolver.class).resolve(environment, new ArrayList<Resource>(resources), Collections.EMPTY_LIST);
- // TODO Once we have a resolver that actually returns lists of wires, we can use them to compute other manifest headers such as Import-Package.
- Collection<Resource> deployedContent = new HashSet<Resource>();
- Collection<Resource> provisionResource = new HashSet<Resource>();
- for (Resource resource : resolution.keySet()) {
- if (contentHeader.contains(resource))
- deployedContent.add(resource);
- else
- provisionResource.add(resource);
+ headers.put(SUBSYSTEM_SYMBOLICNAME, subsystemManifest.getSubsystemSymbolicNameHeader());
+ headers.put(SUBSYSTEM_VERSION, subsystemManifest.getSubsystemVersionHeader());
+ SubsystemTypeHeader typeHeader = subsystemManifest.getSubsystemTypeHeader();
+ // TODO Add to constants.
+ if ("osgi.application".equals(typeHeader.getValue())) {
+ // TODO Compute additional headers for an application.
}
- // Make sure any already resolved content resources are added back in.
- deployedContent.addAll(resources);
- result.headers.put(DeployedContentHeader.NAME, DeployedContentHeader.newInstance(deployedContent));
- if (!provisionResource.isEmpty())
- result.headers.put(ProvisionResourceHeader.NAME, ProvisionResourceHeader.newInstance(provisionResource));
- }
- result.headers.put(SubsystemSymbolicNameHeader.NAME, manifest.getSubsystemSymbolicName());
- result.headers.put(SubsystemVersionHeader.NAME, manifest.getSubsystemVersion());
- SubsystemTypeHeader typeHeader = manifest.getSubsystemType();
- result.headers.put(SubsystemTypeHeader.NAME, typeHeader);
- // TODO Add to constants.
- if ("osgi.application".equals(typeHeader.getValue())) {
- // TODO Compute additional headers for an application.
+ // TODO Add to constants.
+ else if ("osgi.composite".equals(typeHeader.getValue())) {
+ // TODO Compute additional headers for a composite.
+ }
+ // Features require no additional headers.
}
- // TODO Add to constants.
- else if ("osgi.composite".equals(typeHeader.getValue())) {
- // TODO Compute additional headers for a composite.
+ else {
+ headers = new HashMap<String, Header<?>>(deploymentManifest.getHeaders());
}
- // Features require no additional headers.
- logger.debug(LOG_EXIT, "newInstance", result);
- return result;
- }
-
- public DeploymentManifest(File manifestFile) throws IOException {
- super(manifestFile);
- }
-
- public DeploymentManifest(InputStream in) throws IOException {
- super(in);
- }
-
- private DeploymentManifest() {}
-
- public DeploymentManifest(Collection<Resource> deployedContent, Collection<Resource> provisionResource) {
- headers.put(ManifestVersionHeader.NAME, new ManifestVersionHeader("1.0"));
- headers.put(DeployedContentHeader.NAME, DeployedContentHeader.newInstance(deployedContent));
- if (!provisionResource.isEmpty())
- headers.put(ProvisionResourceHeader.NAME, ProvisionResourceHeader.newInstance(provisionResource));
- }
-
- @Override
- public List<Capability> getCapabilities(String namespace) {
- List<Capability> result = new ArrayList<Capability>(1);
- if (namespace == null || namespace.equals(ResourceConstants.IDENTITY_NAMESPACE)) {
- OsgiIdentityCapability capability = new OsgiIdentityCapability(
- this,
- // TODO Reusing IDENTITY_TYPE for the symbolic name here.
- // Since there's only one subsystem manifest per subsystem,
- // this shouldn't cause any technical issues. However, it
- // might be best to use the subsystem's symbolic name here.
- // But there are issues with that as well since type is not
- // part of the unique identity.
- IDENTITY_TYPE,
- Version.emptyVersion,
- IDENTITY_TYPE);
- result.add(capability);
+ // TODO DEPLOYMENT_MANIFESTVERSION
+ headers.put(ARIESSUBSYSTEM_AUTOSTART, new GenericHeader(ARIESSUBSYSTEM_AUTOSTART, Boolean.toString(autostart)));
+ headers.put(ARIESSUBSYSTEM_ID, new GenericHeader(ARIESSUBSYSTEM_ID, Long.toString(id)));
+ headers.put(ARIESSUBSYSTEM_LOCATION, new GenericHeader(ARIESSUBSYSTEM_LOCATION, location));
+ headers.put(ARIESSUBSYSTEM_LASTID, new GenericHeader(ARIESSUBSYSTEM_LASTID, Long.toString(lastId)));
+ this.headers = Collections.unmodifiableMap(headers);
+ }
+
+// public DeploymentManifest(DeploymentManifest deploymentManifest, SubsystemManifest subsystemManifest, SubsystemEnvironment environment) {
+// Map<String, Header<?>> headers;
+// if (deploymentManifest == null)
+// headers = new HashMap<String, Header<?>>();
+// else
+// headers = new HashMap<String, Header<?>>(deploymentManifest.getHeaders());
+// // TODO DEPLOYMENT_MANIFESTVERSION
+// Collection<Resource> resources = new HashSet<Resource>();
+// SubsystemContentHeader contentHeader = subsystemManifest.getSubsystemContentHeader();
+// if (contentHeader != null) {
+// for (SubsystemContentHeader.Content content : contentHeader.getContents()) {
+// OsgiIdentityRequirement requirement = new OsgiIdentityRequirement(content.getName(), content.getVersionRange(), content.getType(), false);
+// Resource resource = environment.findResource(requirement);
+// // If the resource is null, can't continue.
+// // TODO Actually, can continue if resource is optional.
+// if (resource == null)
+// throw new SubsystemException("Resource does not exist: " + requirement);
+// resources.add(resource);
+// }
+// // TODO This does not validate that all content bundles were found.
+// Map<Resource, List<Wire>> resolution = Activator.getInstance().getServiceProvider().getService(Resolver.class).resolve(environment, new ArrayList<Resource>(resources), Collections.EMPTY_LIST);
+// // TODO Once we have a resolver that actually returns lists of wires, we can use them to compute other manifest headers such as Import-Package.
+// Collection<Resource> deployedContent = new HashSet<Resource>();
+// Collection<Resource> provisionResource = new HashSet<Resource>();
+// for (Resource resource : resolution.keySet()) {
+// if (contentHeader.contains(resource))
+// deployedContent.add(resource);
+// else
+// provisionResource.add(resource);
+// }
+// // Make sure any already resolved content resources are added back in.
+// deployedContent.addAll(resources);
+// headers.put(DEPLOYED_CONTENT, DeployedContentHeader.newInstance(deployedContent));
+// if (!provisionResource.isEmpty())
+// headers.put(PROVISION_RESOURCE, ProvisionResourceHeader.newInstance(provisionResource));
+// }
+// headers.put(SUBSYSTEM_SYMBOLICNAME, subsystemManifest.getSubsystemSymbolicNameHeader());
+// headers.put(SUBSYSTEM_VERSION, subsystemManifest.getSubsystemVersionHeader());
+// SubsystemTypeHeader typeHeader = subsystemManifest.getSubsystemTypeHeader();
+// // TODO Add to constants.
+// if ("osgi.application".equals(typeHeader.getValue())) {
+// // TODO Compute additional headers for an application.
+// }
+// // TODO Add to constants.
+// else if ("osgi.composite".equals(typeHeader.getValue())) {
+// // TODO Compute additional headers for a composite.
+// }
+// // Features require no additional headers.
+// this.headers = Collections.unmodifiableMap(headers);
+// }
+
+ public DeployedContentHeader getDeployedContentHeader() {
+ return (DeployedContentHeader)getHeaders().get(DEPLOYED_CONTENT);
+ }
+
+ public Map<String, Header<?>> getHeaders() {
+ return headers;
+ }
+
+ public ProvisionResourceHeader getProvisionResourceHeader() {
+ return (ProvisionResourceHeader)getHeaders().get(PROVISION_RESOURCE);
+ }
+
+ public void write(OutputStream out) throws IOException {
+ Manifest manifest = new Manifest();
+ Attributes attributes = manifest.getMainAttributes();
+ // The manifest won't write anything unless the following header is present.
+ attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ for (Entry<String, Header<?>> entry : headers.entrySet()) {
+ attributes.putValue(entry.getKey(), entry.getValue().getValue());
}
- return result;
- }
-
- public DeployedContentHeader getDeployedContent() {
- return (DeployedContentHeader)getHeader(DeployedContentHeader.NAME);
- }
-
- public ProvisionResourceHeader getProvisionResource() {
- return (ProvisionResourceHeader)getHeader(ProvisionResourceHeader.NAME);
- }
-
- @Override
- public List<Requirement> getRequirements(String namespace) {
- return Collections.emptyList();
- }
-
- public SubsystemSymbolicNameHeader getSubsystemSymbolicName() {
- return (SubsystemSymbolicNameHeader)getHeader(SubsystemSymbolicNameHeader.NAME);
- }
-
- public SubsystemVersionHeader getSubsystemVersion() {
- SubsystemVersionHeader result = (SubsystemVersionHeader)getHeader(SubsystemVersionHeader.NAME);
- if (result == null)
- return SubsystemVersionHeader.DEFAULT;
- return result;
+ manifest.write(out);
}
}
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java Mon Feb 13 12:52:50 2012
@@ -3,59 +3,56 @@ package org.apache.aries.subsystem.core.
import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
import org.apache.aries.subsystem.core.ResourceHelper;
import org.apache.aries.subsystem.core.internal.DataFile;
-import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;
import org.apache.aries.subsystem.core.internal.StaticDataFile;
-import org.apache.aries.subsystem.core.resource.AbstractRequirement;
import org.apache.aries.subsystem.core.resource.BundleResource;
+import org.apache.aries.subsystem.core.resource.SubsystemDirectoryResource;
import org.apache.aries.subsystem.core.resource.SubsystemFileResource;
-import org.osgi.framework.Constants;
import org.osgi.framework.resource.Capability;
import org.osgi.framework.resource.Requirement;
import org.osgi.framework.resource.Resource;
-import org.osgi.framework.resource.ResourceConstants;
import org.osgi.service.repository.Repository;
-import org.osgi.service.repository.RepositoryContent;
-import org.osgi.service.subsystem.SubsystemConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SubsystemArchive implements Repository, RepositoryContent, Resource {
+public class SubsystemArchive implements Repository {
private static final Logger logger = LoggerFactory.getLogger(SubsystemArchive.class);
private final File directory;
private final Map<Resource, URL> resources = new HashMap<Resource, URL>();
+ private DeploymentManifest deploymentManifest;
+ private SubsystemManifest subsystemManifest;
+
public SubsystemArchive(File content) throws Exception {
logger.debug(LOG_ENTRY, "init", content);
- if (!content.exists())
- throw new IllegalArgumentException(content.getName());
- if (content.isDirectory()) {
- directory = content;
- processDirectory(content);
- }
- else { // It's a file.
- directory = content.getParentFile();
- processFile(content);
+ if (!content.isDirectory())
+ throw new IllegalArgumentException("Not a directory: " + content.getAbsolutePath());
+ directory = content;
+ for (File file : content.listFiles()) {
+ if (file.isDirectory() && "OSGI-INF".equals(file.getName())) {
+ for (File f : file.listFiles()) {
+ if (f.getName().equals("SUBSYSTEM.MF")) {
+ subsystemManifest = new SubsystemManifest(f);
+ }
+ else if (f.getName().equals("DEPLOYMENT.MF")) {
+ deploymentManifest = new DeploymentManifest(f);
+ }
+ }
+ }
+ else
+ processResource(file);
}
logger.debug(LOG_EXIT, "init");
}
@@ -86,344 +83,66 @@ public class SubsystemArchive implements
return result;
}
- @Override
- public List<Capability> getCapabilities(String namespace) {
- if (namespace == null || namespace.equals(ResourceConstants.IDENTITY_NAMESPACE)) {
- List<Capability> result = new ArrayList<Capability>(1);
- OsgiIdentityCapability capability = new OsgiIdentityCapability(
- this,
- getSubsystemManifest().getSubsystemSymbolicName().getSymbolicName(),
- getSubsystemManifest().getSubsystemVersion().getVersion(),
- SubsystemConstants.IDENTITY_TYPE_SUBSYSTEM);
- result.add(capability);
- return result;
- }
- return Collections.emptyList();
- }
-
- @Override
- public synchronized InputStream getContent() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ZipOutputStream zos = new ZipOutputStream(baos);
- for (Resource resource : getResources()) {
- ZipEntry ze = new ZipEntry(
- new StringBuilder(ResourceHelper.getSymbolicNameAttribute(resource))
- .append(';')
- .append(ResourceHelper.getVersionAttribute(resource))
- .append(';')
- .append(ResourceHelper.getTypeAttribute(resource))
- .toString());
- try {
- zos.putNextEntry(ze);
- InputStream is = ((RepositoryContent) resource).getContent();
- byte[] bytes = new byte[2048];
- int read;
- while ((read = is.read(bytes)) != -1)
- zos.write(bytes, 0, read);
- zos.closeEntry();
- }
- finally {
- try {
- zos.close();
- }
- catch (IOException e) {
- logger.debug("Unable to close the stream: ", e);
- }
- }
- }
- return new ByteArrayInputStream(baos.toByteArray());
- }
-
- public synchronized DataFile getDataFile() {
- Collection<Capability> capabilities = findProviders(new AbstractRequirement() {
- @Override
- public Map<String, Object> getAttributes() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<String, String> getDirectives() {
- Map<String, String> directives = new HashMap<String, String>(1);
- directives.put(
- Constants.FILTER_DIRECTIVE,
- new StringBuilder()
- .append('(')
- .append(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE)
- .append('=')
- .append(DataFile.IDENTITY_TYPE)
- .append(')')
- .toString());
- return Collections.unmodifiableMap(directives);
- }
-
- @Override
- public String getNamespace() {
- return ResourceConstants.IDENTITY_NAMESPACE;
- }
-
- @Override
- public Resource getResource() {
- return null;
- }
- });
- if (capabilities.isEmpty())
- return null;
- return (DataFile)capabilities.iterator().next().getResource();
- }
-
public synchronized DeploymentManifest getDeploymentManifest() {
- Collection<Capability> capabilities = findProviders(new AbstractRequirement() {
- @Override
- public Map<String, Object> getAttributes() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<String, String> getDirectives() {
- Map<String, String> directives = new HashMap<String, String>(1);
- directives.put(
- Constants.FILTER_DIRECTIVE,
- new StringBuilder()
- .append('(')
- .append(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE)
- .append('=')
- .append(DeploymentManifest.IDENTITY_TYPE)
- .append(')')
- .toString());
- return Collections.unmodifiableMap(directives);
- }
-
- @Override
- public String getNamespace() {
- return ResourceConstants.IDENTITY_NAMESPACE;
- }
-
- @Override
- public Resource getResource() {
- return null;
- }
- });
- if (capabilities.isEmpty())
- return null;
- return (DeploymentManifest)capabilities.iterator().next().getResource();
- }
-
- @Override
- public List<Requirement> getRequirements(String namespace) {
- return Collections.emptyList();
- }
-
- public synchronized Collection<Resource> getResources() {
- Collection<Capability> capabilities = findProviders(new AbstractRequirement() {
- @Override
- public Map<String, Object> getAttributes() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<String, String> getDirectives() {
- Map<String, String> directives = new HashMap<String, String>(1);
- directives.put(
- Constants.FILTER_DIRECTIVE,
- new StringBuilder("(")
- .append(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE)
- .append("=osgi.*)")
- .toString());
- return Collections.unmodifiableMap(directives);
- }
-
- @Override
- public String getNamespace() {
- return ResourceConstants.IDENTITY_NAMESPACE;
- }
-
- @Override
- public Resource getResource() {
- return null;
- }
- });
- if (capabilities.isEmpty())
- return Collections.emptyList();
- Collection<Resource> resources = new HashSet<Resource>(capabilities.size());
- for (Capability capability : capabilities) {
- resources.add(capability.getResource());
- }
- return resources;
+ return deploymentManifest;
}
- public synchronized StaticDataFile getStaticDataFile() {
- Collection<Capability> capabilities = findProviders(new AbstractRequirement() {
- @Override
- public Map<String, Object> getAttributes() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<String, String> getDirectives() {
- Map<String, String> directives = new HashMap<String, String>(1);
- directives.put(
- Constants.FILTER_DIRECTIVE,
- new StringBuilder()
- .append('(')
- .append(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE)
- .append('=')
- .append(StaticDataFile.IDENTITY_TYPE)
- .append(')')
- .toString());
- return Collections.unmodifiableMap(directives);
- }
-
- @Override
- public String getNamespace() {
- return ResourceConstants.IDENTITY_NAMESPACE;
- }
-
- @Override
- public Resource getResource() {
- return null;
- }
- });
- if (capabilities.isEmpty())
- return null;
- return (StaticDataFile)capabilities.iterator().next().getResource();
+ public Collection<Resource> getResources() {
+ return resources.keySet();
}
public synchronized SubsystemManifest getSubsystemManifest() {
- logger.debug(LOG_ENTRY, "getSubsystemManifest");
- Collection<Capability> capabilities = findProviders(new AbstractRequirement() {
- @Override
- public Map<String, Object> getAttributes() {
- return Collections.emptyMap();
- }
-
- @Override
- public Map<String, String> getDirectives() {
- Map<String, String> directives = new HashMap<String, String>(1);
- directives.put(
- Constants.FILTER_DIRECTIVE,
- new StringBuilder()
- .append('(')
- .append(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE)
- .append('=')
- .append(SubsystemManifest.IDENTITY_TYPE)
- .append(')')
- .toString());
- return Collections.unmodifiableMap(directives);
- }
-
- @Override
- public String getNamespace() {
- return ResourceConstants.IDENTITY_NAMESPACE;
- }
-
- @Override
- public Resource getResource() {
- return null;
- }
- });
- SubsystemManifest result = null;
- if (!capabilities.isEmpty())
- result = (SubsystemManifest)capabilities.iterator().next().getResource();
- logger.debug(LOG_EXIT, "getSubsystemManifest", result);
- return result;
- }
-
- public synchronized void setDataFile(DataFile dataFile) throws IOException {
- DataFile old = getDataFile();
- // TODO Add to constants.
- File file = new File(directory, DataFile.IDENTITY_TYPE);
- OutputStream out = new FileOutputStream(file);
- try {
- dataFile.write(out);
- if (old != null)
- resources.remove(old);
- resources.put(dataFile, file.toURI().toURL());
- } finally {
- out.close();
- }
+ return subsystemManifest;
}
public synchronized void setDeploymentManifest(DeploymentManifest manifest) throws IOException {
logger.debug(LOG_ENTRY, "setDeploymentManifest", manifest);
- DeploymentManifest old = getDeploymentManifest();
- // TODO Add to constants.
File file = new File(directory, "OSGI-INF");
- if (!file.exists() && !file.mkdir())
- throw new IOException("Unable to make directory for "
- + file.getCanonicalPath());
+ if (!file.exists() && !file.mkdirs())
+ throw new IOException("Unable to make directory for " + file.getCanonicalPath());
file = new File(file, "DEPLOYMENT.MF");
OutputStream out = new FileOutputStream(file);
try {
manifest.write(out);
- if (old != null)
- resources.remove(old);
- resources.put(manifest, file.toURI().toURL());
} finally {
out.close();
}
+
+ deploymentManifest = manifest;
logger.debug(LOG_EXIT, "setDeploymentManifest");
}
public synchronized void setSubsystemManifest(SubsystemManifest manifest) throws IOException {
logger.debug(LOG_ENTRY, "setSubsystemManifest", manifest);
- SubsystemManifest old = getSubsystemManifest();
- // TODO Add to constants.
File file = new File(directory, "OSGI-INF");
- if (!file.exists() && !file.mkdir())
+ if (!file.exists() && !file.mkdirs())
throw new IOException("Unable to make directory for " + file.getCanonicalPath());
file = new File(file, "SUBSYSTEM.MF");
OutputStream out = new FileOutputStream(file);
try {
manifest.write(out);
- if (old != null)
- resources.remove(old);
- resources.put(manifest, file.toURI().toURL());
}
finally {
out.close();
}
+ // TODO What if the provided deployment manifest's file is out of sync?
+ subsystemManifest = manifest;
logger.debug(LOG_EXIT, "setSubsystemManifest");
}
- private Resource createResource(File file) throws Exception {
- if (file.isDirectory() && file.getName().startsWith("subsystem"))
- return new SubsystemArchive(file);
- if (file.getName().endsWith(".jar"))
- return BundleResource.newInstance(file.toURI().toURL());
- if (!file.getName().startsWith("subsystem") && file.getName().endsWith(".ssa"))
- return new SubsystemFileResource(file);
- if (file.getName().endsWith("SUBSYSTEM.MF"))
- return new SubsystemManifest(file);
- if (file.getName().endsWith("DEPLOYMENT.MF"))
- return new DeploymentManifest(file);
- if (file.getName().endsWith(DataFile.IDENTITY_TYPE))
- return new DataFile(file);
- if (file.getName().endsWith(StaticDataFile.IDENTITY_TYPE))
- return new StaticDataFile(file);
- logger.warn("Ignoring unsupported resource type: " + file.getAbsolutePath());
- return null;
- }
-
- private void processDirectory(File content) throws Exception {
- logger.debug(LOG_ENTRY, "processDirectory", content);
- for (File file : content.listFiles()) {
- logger.debug("Processing file {}", file);
- processFile(file);
- }
- logger.debug(LOG_EXIT, "processDirectory");
- }
-
- private void processFile(File content) throws Exception {
- logger.debug(LOG_ENTRY, "processFile", content);
- if (content.isDirectory() && "OSGI-INF".equals(content.getName())) {
- processDirectory(content);
- }
- else {
- Resource resource = createResource(content);
- if (resource != null) {
- resources.put(resource, content.toURI().toURL());
- }
- }
- logger.debug(LOG_EXIT, "processFile");
+ private void processResource(File file) throws Exception {
+ String name = file.getName();
+ if (file.isDirectory() && name.startsWith("subsystem"))
+ resources.put(new SubsystemDirectoryResource(file), file.toURI().toURL());
+ else if (name.endsWith(".jar")) {
+ URL url = file.toURI().toURL();
+ resources.put(BundleResource.newInstance(url), url);
+ }
+ else if (name.endsWith(".ssa") && !name.startsWith("subsystem"))
+ resources.put(new SubsystemFileResource(file), file.toURI().toURL());
+ else if (name.endsWith(DataFile.IDENTITY_TYPE))
+ resources.put(new DataFile(file), file.toURI().toURL());
+ else if (name.endsWith(StaticDataFile.IDENTITY_TYPE))
+ resources.put(new StaticDataFile(file), file.toURI().toURL());
}
}
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemManifest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemManifest.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemManifest.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemManifest.java Mon Feb 13 12:52:50 2012
@@ -1,130 +1,139 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
package org.apache.aries.subsystem.core.archive;
-import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
-import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
-
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
+import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
-import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;
+import org.apache.aries.util.manifest.ManifestProcessor;
+import org.osgi.framework.Constants;
import org.osgi.framework.Version;
import org.osgi.framework.resource.Capability;
-import org.osgi.framework.resource.Requirement;
import org.osgi.framework.resource.Resource;
import org.osgi.framework.resource.ResourceConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.osgi.service.subsystem.SubsystemConstants;
-public class SubsystemManifest extends Manifest implements Resource {
- public static final String IDENTITY_TYPE = "org.apache.aries.subsystem.manifest";
-
- private static final Logger logger = LoggerFactory.getLogger(SubsystemManifest.class);
-
- public static SubsystemManifest newInstance(String symbolicName, Version version, Collection<Resource> resources) {
- if (logger.isDebugEnabled())
- logger.debug(LOG_ENTRY, "newInstance", new Object[]{symbolicName, version, resources});
- SubsystemManifest manifest = new SubsystemManifest();
- manifest.headers.put(SubsystemTypeHeader.NAME, new SubsystemTypeHeader());
- manifest.headers.put(ManifestVersionHeader.NAME, new ManifestVersionHeader());
- manifest.headers.put(SubsystemManifestVersionHeader.NAME, new SubsystemManifestVersionHeader());
- manifest.headers.put(ManifestVersionHeader.NAME, new ManifestVersionHeader());
- manifest.headers.put(SubsystemSymbolicNameHeader.NAME, new SubsystemSymbolicNameHeader(symbolicName));
- manifest.headers.put(SubsystemVersionHeader.NAME, new SubsystemVersionHeader(version.toString()));
- // TODO Leaving out Subsystem-Name and Subsystem-Description.
- // TODO Better way than using StringBuilder? Would require a more robust SubsystemContentHeader in order to fulfill the Header contract.
- StringBuilder content = new StringBuilder();
- for (Resource resource : resources) {
- Capability osgiIdentity = resource.getCapabilities(ResourceConstants.IDENTITY_NAMESPACE).get(0);
- String resourceSymbolicName = (String)osgiIdentity.getAttributes().get(ResourceConstants.IDENTITY_NAMESPACE);
- Version resourceVersion = (Version)osgiIdentity.getAttributes().get(ResourceConstants.IDENTITY_VERSION_ATTRIBUTE);
- String type = (String)osgiIdentity.getAttributes().get(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE);
- content.append(resourceSymbolicName).append(';')
- // TODO Add to constants.
- .append("version").append('=').append(resourceVersion).append(';')
- // TODO Add to constants.
- .append("type").append('=').append(type).append(',');
- }
- if (content.length() != 0) {
- // Remove the trailing comma.
- content.deleteCharAt(content.length() - 1);
- manifest.headers.put(SubsystemContentHeader.NAME, new SubsystemContentHeader(content.toString()));
+public class SubsystemManifest {
+ public static final String EXPORT_PACKAGE = Constants.EXPORT_PACKAGE;
+ public static final String IMPORT_PACKAGE = Constants.IMPORT_PACKAGE;
+ public static final String PREFERRED_PROVIDER = SubsystemConstants.PREFERRED_PROVIDER;
+ public static final String PROVIDE_CAPABILITY = Constants.PROVIDE_CAPABILITY;
+ public static final String REQUIRE_BUNDLE = Constants.REQUIRE_BUNDLE;
+ public static final String REQUIRE_CAPABILITY = Constants.REQUIRE_CAPABILITY;
+ public static final String SUBSYSTEM_CONTENT = SubsystemConstants.SUBSYSTEM_CONTENT;
+ public static final String SUBSYSTEM_DESCRIPTION = SubsystemConstants.SUBSYSTEM_DESCRIPTION;
+ public static final String SUBSYSTEM_EXPORTSERVICE = SubsystemConstants.SUBSYSTEM_EXPORTSERVICE;
+ public static final String SUBSYSTEM_IMPORTSERVICE = SubsystemConstants.SUBSYSTEM_IMPORTSERVICE;
+ public static final String SUBSYSTEM_MANIFESTVERSION = SubsystemConstants.SUBSYSTEM_MANIFESTVERSION;
+ public static final String SUBSYSTEM_NAME = SubsystemConstants.SUBSYSTEM_NAME;
+ public static final String SUBSYSTEM_SYMBOLICNAME = SubsystemConstants.SUBSYSTEM_SYMBOLICNAME;
+ public static final String SUBSYSTEM_TYPE = SubsystemConstants.SUBSYSTEM_TYPE;
+ public static final String SUBSYSTEM_VERSION = SubsystemConstants.SUBSYSTEM_VERSION;
+
+ private final Map<String, Header<?>> headers;
+
+ public SubsystemManifest(File file) throws FileNotFoundException, IOException {
+ Manifest manifest = ManifestProcessor.parseManifest(new FileInputStream(file));
+ Attributes attributes = manifest.getMainAttributes();
+ Map<String, Header<?>> headers = new HashMap<String, Header<?>>(attributes.size() + 4); // Plus the # of potentially derived headers.
+ for (Entry<Object, Object> entry : attributes.entrySet()) {
+ String key = String.valueOf(entry.getKey());
+ headers.put(key, HeaderFactory.createHeader(key, String.valueOf(entry.getValue())));
}
- logger.debug(LOG_EXIT, "newInstance", manifest);
- return manifest;
- }
-
- public SubsystemManifest(InputStream in) throws IOException {
- super(in);
+ Header<?> header = headers.get(SUBSYSTEM_VERSION);
+ if (header == null) {
+ headers.put(SUBSYSTEM_VERSION, SubsystemVersionHeader.DEFAULT);
+ }
+ header = headers.get(SUBSYSTEM_TYPE);
+ if (header == null)
+ headers.put(SUBSYSTEM_TYPE, SubsystemTypeHeader.DEFAULT);
+ this.headers = Collections.unmodifiableMap(headers);
}
-
- public SubsystemManifest(File file) throws IOException {
- super(file);
+
+ public SubsystemManifest(String symbolicName, Version version, Collection<Resource> content) {
+ this(null, symbolicName, version, content);
}
-
- private SubsystemManifest() {}
- @Override
- public List<Capability> getCapabilities(String namespace) {
- List<Capability> result = new ArrayList<Capability>(1);
- if (namespace == null || namespace.equals(ResourceConstants.IDENTITY_NAMESPACE)) {
- OsgiIdentityCapability capability = new OsgiIdentityCapability(
- this,
- // TODO Reusing IDENTITY_TYPE for the symbolic name here.
- // Since there's only one subsystem manifest per subsystem,
- // this shouldn't cause any technical issues. However, it
- // might be best to use the subsystem's symbolic name here.
- // But there are issues with that as well since type is not
- // part of the unique identity.
- IDENTITY_TYPE,
- Version.emptyVersion,
- IDENTITY_TYPE);
- result.add(capability);
+ public SubsystemManifest(SubsystemManifest manifest, String symbolicName, Version version, Collection<Resource> content) {
+ Map<String, Header<?>> headers;
+ if (manifest == null) {
+ headers = new HashMap<String, Header<?>>(4);
+ }
+ else {
+ headers = new HashMap<String, Header<?>>(manifest.headers);
+ }
+ Header<?> header = headers.get(SUBSYSTEM_SYMBOLICNAME);
+ if (header == null)
+ headers.put(SUBSYSTEM_SYMBOLICNAME, new SubsystemSymbolicNameHeader(symbolicName));
+ header = headers.get(SUBSYSTEM_VERSION);
+ if (header == null) {
+ if (version == null)
+ headers.put(SUBSYSTEM_VERSION, SubsystemVersionHeader.DEFAULT);
+ else
+ headers.put(SUBSYSTEM_VERSION, new SubsystemVersionHeader(version));
+ }
+ header = headers.get(SUBSYSTEM_CONTENT);
+ if (header == null && content != null && !content.isEmpty()) {
+ // TODO Better way than using StringBuilder? Would require a more robust SubsystemContentHeader in order to fulfill the Header contract.
+ StringBuilder sb = new StringBuilder();
+ for (Resource resource : content) {
+ Capability c = resource.getCapabilities(ResourceConstants.IDENTITY_NAMESPACE).get(0);
+ Map<String, Object> a = c.getAttributes();
+ String s = (String)a.get(ResourceConstants.IDENTITY_NAMESPACE);
+ Version v = (Version)a.get(ResourceConstants.IDENTITY_VERSION_ATTRIBUTE);
+ String t = (String)a.get(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE);
+ sb.append(s).append(';')
+ .append(ResourceConstants.IDENTITY_VERSION_ATTRIBUTE).append('=').append(v).append(';')
+ .append(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE).append('=').append(t).append(',');
+ }
+ if (sb.length() != 0) {
+ // Remove the trailing comma.
+ sb.deleteCharAt(sb.length() - 1);
+ headers.put(SubsystemContentHeader.NAME, new SubsystemContentHeader(sb.toString()));
+ }
}
- return result;
+ header = headers.get(SUBSYSTEM_TYPE);
+ if (header == null)
+ headers.put(SUBSYSTEM_TYPE, SubsystemTypeHeader.DEFAULT);
+ this.headers = Collections.unmodifiableMap(headers);
}
- @Override
- public List<Requirement> getRequirements(String namespace) {
- return Collections.emptyList();
+ public Map<String, Header<?>> getHeaders() {
+ return headers;
}
- public SubsystemContentHeader getSubsystemContent() {
- return (SubsystemContentHeader)getHeader(SubsystemContentHeader.NAME);
+ public SubsystemContentHeader getSubsystemContentHeader() {
+ return (SubsystemContentHeader)getHeaders().get(SUBSYSTEM_CONTENT);
}
- public SubsystemSymbolicNameHeader getSubsystemSymbolicName() {
- return (SubsystemSymbolicNameHeader)getHeader(SubsystemSymbolicNameHeader.NAME);
+ public SubsystemSymbolicNameHeader getSubsystemSymbolicNameHeader() {
+ return (SubsystemSymbolicNameHeader)getHeaders().get(SUBSYSTEM_SYMBOLICNAME);
}
- public SubsystemTypeHeader getSubsystemType() {
- SubsystemTypeHeader result = (SubsystemTypeHeader)getHeader(SubsystemTypeHeader.NAME);
- if (result == null)
- return SubsystemTypeHeader.DEFAULT;
- return result;
+ public SubsystemTypeHeader getSubsystemTypeHeader() {
+ return (SubsystemTypeHeader)getHeaders().get(SUBSYSTEM_TYPE);
}
- public SubsystemVersionHeader getSubsystemVersion() {
- SubsystemVersionHeader result = (SubsystemVersionHeader)getHeader(SubsystemVersionHeader.NAME);
- if (result == null)
- return SubsystemVersionHeader.DEFAULT;
- return result;
+ public SubsystemVersionHeader getSubsystemVersionHeader() {
+ return (SubsystemVersionHeader)getHeaders().get(SUBSYSTEM_VERSION);
+ }
+
+ public void write(OutputStream out) throws IOException {
+ Manifest manifest = new Manifest();
+ Attributes attributes = manifest.getMainAttributes();
+ // The manifest won't write anything unless the following header is present.
+ attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ for (Entry<String, Header<?>> entry : headers.entrySet()) {
+ attributes.putValue(entry.getKey(), entry.getValue().getValue());
+ }
+ manifest.write(out);
}
}
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemVersionHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemVersionHeader.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemVersionHeader.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemVersionHeader.java Mon Feb 13 12:52:50 2012
@@ -29,4 +29,8 @@ public class SubsystemVersionHeader exte
public SubsystemVersionHeader(String value) {
super(NAME, value);
}
+
+ public SubsystemVersionHeader(Version value) {
+ super(NAME, value);
+ }
}
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/VersionHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/VersionHeader.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/VersionHeader.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/VersionHeader.java Mon Feb 13 12:52:50 2012
@@ -19,8 +19,12 @@ public abstract class VersionHeader exte
private final Version version;
public VersionHeader(String name, String value) {
- super(name, value);
- version = Version.parseVersion(getClauses().get(0).getPath());
+ this(name, Version.parseVersion(value));
+ }
+
+ public VersionHeader(String name, Version value) {
+ super(name, value.toString());
+ version = value;
}
public Version getVersion() {
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java Mon Feb 13 12:52:50 2012
@@ -36,6 +36,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -49,8 +50,8 @@ import org.apache.aries.subsystem.core.a
import org.apache.aries.subsystem.core.archive.ProvisionResourceHeader.ProvisionedResource;
import org.apache.aries.subsystem.core.archive.SubsystemArchive;
import org.apache.aries.subsystem.core.archive.SubsystemManifest;
-import org.apache.aries.subsystem.core.archive.SubsystemSymbolicNameHeader;
import org.apache.aries.subsystem.core.obr.SubsystemEnvironment;
+import org.apache.aries.subsystem.core.resource.SubsystemDirectoryResource;
import org.apache.aries.subsystem.core.resource.SubsystemFileResource;
import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
@@ -211,6 +212,7 @@ public class AriesSubsystem implements S
private final ArrayList<AriesSubsystem> parents = new ArrayList<AriesSubsystem>();
private final Region region;
+ private boolean autostart;
private Subsystem.State state = State.INSTALLING;
public AriesSubsystem() throws Exception {
@@ -220,39 +222,42 @@ public class AriesSubsystem implements S
// by any embedded child subsystems during archive initialization. See the constructors.
directory = Activator.getInstance().getBundleContext().getDataFile("");
archive = new SubsystemArchive(directory);
- DataFile data = archive.getDataFile();
- if (data == null) {
- id = 0;
- location = ROOT_LOCATION;
- region = createRegion(null);
+ DeploymentManifest deploymentManifest = archive.getDeploymentManifest();
+ if (deploymentManifest != null) {
+ autostart = Boolean.parseBoolean(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_AUTOSTART).getValue());
+ id = Long.parseLong(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_ID).getValue());
+ lastId = Long.parseLong(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LASTID).getValue());
+ location = deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LOCATION).getValue();
}
else {
- id = data.getSubsystemId();
- location = data.getLocation();
- region = createRegion(data.getRegionName());
- state = data.getState();
+ autostart = true;
+ id = 0;
+ location = ROOT_LOCATION;
}
+ region = createRegion(null);
// TODO The creation of the subsystem manifest is in two places. See other constructor.
- SubsystemManifest manifest = archive.getSubsystemManifest();
- if (manifest == null) {
+ SubsystemManifest subsystemManifest = archive.getSubsystemManifest();
+ if (subsystemManifest == null) {
// This is the first time the root subsystem has been initialized in this framework or
// a framework clean start was requested.
SubsystemUri uri = new SubsystemUri(ROOT_LOCATION);
- manifest = SubsystemManifest.newInstance(uri.getSymbolicName(), uri.getVersion(), archive.getResources());
- archive.setSubsystemManifest(manifest);
+ subsystemManifest = new SubsystemManifest(uri.getSymbolicName(), uri.getVersion(), archive.getResources());
+ archive.setSubsystemManifest(subsystemManifest);
}
else
// Need to generate a new subsystem manifest in order to generated a new deployment manifest based
// on any persisted resources.
- manifest = SubsystemManifest.newInstance(getSymbolicName(), getVersion(), archive.getResources());
+ subsystemManifest = new SubsystemManifest(getSymbolicName(), getVersion(), archive.getResources());
environment = new SubsystemEnvironment(this);
- archive.setDeploymentManifest(DeploymentManifest.newInstance(manifest, environment));
- StaticDataFile sdf = archive.getStaticDataFile();
- LOGGER.debug("Data file: {}", sdf);
- if (sdf != null) {
- lastId = sdf.getLastSubsystemId();
- }
- LOGGER.debug("Last ID will start at {}", lastId);
+ archive.setDeploymentManifest(new DeploymentManifest(
+ deploymentManifest,
+ subsystemManifest,
+ environment,
+ autostart,
+ id,
+ lastId,
+ location,
+ true));
// TODO Begin proof of concept.
// This is a proof of concept for initializing the relationships between the root subsystem and bundles
// that already existed in its region. Not sure this will be the final resting place. Plus, there are issues
@@ -312,27 +317,28 @@ public class AriesSubsystem implements S
// better to create the URI in a try/catch block and throw an
// exception with a message indicating we received a subsystem
// with no manifest and no subsystem URI.
- archive.setSubsystemManifest(SubsystemManifest.newInstance(
+ archive.setSubsystemManifest(new SubsystemManifest(
uri.getSymbolicName(),
uri.getVersion(),
archive.getResources()));
- // TODO If the subsystem manifest is not null, need to provide default headers if subsystem URI was used.
}
- region = createRegion(getSymbolicName() + ';' + getVersion());
+ region = createRegion(getSymbolicName() + ';' + getVersion() + ';' + getType() + ';' + getSubsystemId());
}
public AriesSubsystem(SubsystemArchive archive, AriesSubsystem parent) throws Exception {
this.archive = archive;
- DataFile data = archive.getDataFile();
- if (data == null)
- throw new IllegalArgumentException("Missing data file");
- this.location = data.getLocation();
- this.parents.add(parent);
- id = data.getSubsystemId();
+
+ DeploymentManifest manifest = archive.getDeploymentManifest();
+ if (manifest == null)
+ throw new IllegalStateException("Missing deployment manifest");
+ autostart = Boolean.parseBoolean(manifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_AUTOSTART).getValue());
+ id = Long.parseLong(manifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_ID).getValue());
+ location = manifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LOCATION).getValue();
String directoryName = "subsystem" + id;
directory = new File(parent.directory, directoryName);
environment = new SubsystemEnvironment(this);
- region = createRegion(data.getRegionName());
+ parents.add(parent);
+ region = createRegion(getSymbolicName() + ';' + getVersion() + ';' + getType() + ';' + getSubsystemId());
}
public SubsystemArchive getArchive() {
@@ -360,7 +366,7 @@ public class AriesSubsystem implements S
@Override
public synchronized Collection<Resource> getConstituents() {
- Collection<Resource> resources = new ArrayList<Resource>();
+ Collection<Resource> resources = new HashSet<Resource>();
if (isRoot() || isApplication() || isComposite()) {
Set<Long> bundleIds = region.getBundleIds();
BundleContext context = getBundleContext();
@@ -393,11 +399,11 @@ public class AriesSubsystem implements S
@Override
public Map<String, String> getSubsystemHeaders(Locale locale) {
- Collection<Header> headers = archive.getSubsystemManifest().getHeaders();
+ Map<String, Header<?>> headers = archive.getSubsystemManifest().getHeaders();
Map<String, String> result = new HashMap<String, String>(headers.size());
- for (Header header : headers) {
- String value = header.getValue();
- result.put(header.getName(), value);
+ for (Entry<String, Header<?>> entry: headers.entrySet()) {
+ Header<?> value = entry.getValue();
+ result.put(entry.getKey(), value.getValue());
}
return result;
}
@@ -409,9 +415,7 @@ public class AriesSubsystem implements S
@Override
public String getSymbolicName() {
- if (isRoot())
- return ROOT_SYMBOLIC_NAME;
- return ((SubsystemSymbolicNameHeader)archive.getSubsystemManifest().getSubsystemSymbolicName()).getSymbolicName();
+ return archive.getSubsystemManifest().getHeaders().get(SubsystemManifest.SUBSYSTEM_SYMBOLICNAME).getValue();
}
@Override
@@ -470,18 +474,24 @@ public class AriesSubsystem implements S
}
public boolean isApplication() {
- // TODO Add to constants.
- return !isRoot() && "osgi.application".equals(archive.getSubsystemManifest().getSubsystemType().getValue());
+ return !isRoot()
+ && SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION.equals(archive
+ .getSubsystemManifest().getHeaders()
+ .get(SubsystemManifest.SUBSYSTEM_TYPE).getValue());
}
public boolean isComposite() {
- // TODO Add to constants.
- return !isRoot() && "osgi.composite".equals(archive.getSubsystemManifest().getSubsystemType().getValue());
+ return !isRoot()
+ && SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(archive
+ .getSubsystemManifest().getHeaders()
+ .get(SubsystemManifest.SUBSYSTEM_TYPE).getValue());
}
public boolean isFeature() {
- // TODO Add to constants.
- return !isRoot() && "osgi.feature".equals(archive.getSubsystemManifest().getSubsystemType().getValue());
+ return !isRoot()
+ && SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(archive
+ .getSubsystemManifest().getHeaders()
+ .get(SubsystemManifest.SUBSYSTEM_TYPE).getValue());
}
/* INSTALLING Wait, Start
@@ -515,6 +525,7 @@ public class AriesSubsystem implements S
resolve();
}
setState(State.STARTING);
+ autostart = true;
// TODO Need to hold a lock here to guarantee that another start
// operation can't occur when the state goes to RESOLVED.
// Start the subsystem.
@@ -559,6 +570,7 @@ public class AriesSubsystem implements S
public synchronized void stop() throws SubsystemException {
// The root subsystem may not be stopped.
checkRoot();
+ autostart = false;
stop0();
}
@@ -643,7 +655,7 @@ public class AriesSubsystem implements S
List<Resource> contentResources = new ArrayList<Resource>();
List<Resource> transitiveDependencies = new ArrayList<Resource>();
DeploymentManifest manifest = getDeploymentManifest();
- DeployedContentHeader contentHeader = manifest.getDeployedContent();
+ DeployedContentHeader contentHeader = manifest.getDeployedContentHeader();
if (contentHeader != null) {
for (DeployedContent content : contentHeader.getDeployedContents()) {
Collection<Capability> capabilities = environment.findProviders(
@@ -654,7 +666,7 @@ public class AriesSubsystem implements S
contentResources.add(resource);
}
}
- ProvisionResourceHeader resourceHeader = manifest.getProvisionResource();
+ ProvisionResourceHeader resourceHeader = manifest.getProvisionResourceHeader();
if (resourceHeader != null) {
for (ProvisionedResource content : resourceHeader.getProvisionedResources()) {
Collection<Capability> capabilities = environment.findProviders(
@@ -688,8 +700,9 @@ public class AriesSubsystem implements S
coordination.end();
}
}
- if (getState().equals(State.INSTALLING))
- setState(State.INSTALLED);
+ setState(State.INSTALLED);
+ if (autostart)
+ start();
}
void stop0() {
@@ -715,6 +728,21 @@ public class AriesSubsystem implements S
}
// TODO Can we automatically assume it actually is resolved?
setState(State.RESOLVED);
+ DeploymentManifest manifest = new DeploymentManifest(
+ archive.getDeploymentManifest(),
+ null,
+ null,
+ autostart,
+ id,
+ lastId,
+ location,
+ false);
+ try {
+ archive.setDeploymentManifest(manifest);
+ }
+ catch (IOException e) {
+ throw new SubsystemException(e);
+ }
}
protected boolean contains(Resource resource) {
@@ -733,19 +761,6 @@ public class AriesSubsystem implements S
protected synchronized void setState(Subsystem.State state) {
this.state = state;
- // The archive will be null if this is the root subsystem.
- if (archive != null) {
- // If necessary, update this subsystem's data file to honor start and stop requests.
- if (EnumSet.of(State.INSTALLED, State.RESOLVED, State.ACTIVE).contains(state)) {
- DataFile data = new DataFile(location, region.getName(), state, id);
- try {
- archive.setDataFile(data);
- }
- catch (IOException e) {
- throw new SubsystemException(e);
- }
- }
- }
Activator.getInstance().getSubsystemServiceRegistrar().update(this);
notifyAll();
}
@@ -766,11 +781,13 @@ public class AriesSubsystem implements S
}
private Region createRegion(String name) throws BundleException {
+ Activator activator = Activator.getInstance();
+ RegionDigraph digraph = activator.getServiceProvider().getService(RegionDigraph.class);
if (name == null)
- return Activator.getInstance().getServiceProvider().getService(RegionDigraph.class).getRegion(Activator.getInstance().getBundleContext().getBundle());
- Region region = Activator.getInstance().getServiceProvider().getService(RegionDigraph.class).getRegion(name);
+ return digraph.getRegion(activator.getBundleContext().getBundle());
+ Region region = digraph.getRegion(name);
if (region == null)
- return Activator.getInstance().getServiceProvider().getService(RegionDigraph.class).createRegion(name);
+ return digraph.createRegion(name);
return region;
}
@@ -784,7 +801,15 @@ public class AriesSubsystem implements S
private DeploymentManifest getDeploymentManifest() throws IOException {
if (archive.getDeploymentManifest() == null) {
- archive.setDeploymentManifest(DeploymentManifest.newInstance(archive.getSubsystemManifest(), environment));
+ archive.setDeploymentManifest(new DeploymentManifest(
+ null,
+ archive.getSubsystemManifest(),
+ environment,
+ autostart,
+ id,
+ lastId,
+ location,
+ true));
}
return archive.getDeploymentManifest();
}
@@ -871,8 +896,8 @@ public class AriesSubsystem implements S
return;
}
else {
- SubsystemArchive archive = (SubsystemArchive)resource;
- subsystem = new AriesSubsystem(archive, this);
+ SubsystemDirectoryResource sdr = (SubsystemDirectoryResource)resource;
+ subsystem = new AriesSubsystem(sdr.getArchive(), this);
locationToSubsystem.put(subsystem.getLocation(), subsystem);
}
Set<AriesSubsystem> subsystems = new HashSet<AriesSubsystem>();
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityCapability.java Mon Feb 13 12:52:50 2012
@@ -54,8 +54,8 @@ public class OsgiIdentityCapability exte
public OsgiIdentityCapability(Resource resource, SubsystemManifest manifest) {
this(
resource,
- manifest.getSubsystemSymbolicName().getSymbolicName(),
- manifest.getSubsystemVersion().getVersion(),
+ manifest.getSubsystemSymbolicNameHeader().getSymbolicName(),
+ manifest.getSubsystemVersionHeader().getVersion(),
// TODO Add to constants.
"osgi.subsystem");
}
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemDirectoryResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemDirectoryResource.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemDirectoryResource.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemDirectoryResource.java Mon Feb 13 12:52:50 2012
@@ -1,52 +1,39 @@
package org.apache.aries.subsystem.core.resource;
import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.jar.Manifest;
-import org.apache.aries.subsystem.core.archive.SubsystemSymbolicNameHeader;
+import org.apache.aries.subsystem.core.archive.SubsystemArchive;
+import org.apache.aries.subsystem.core.archive.SubsystemManifest;
import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;
-import org.apache.aries.util.filesystem.FileSystem;
-import org.apache.aries.util.filesystem.IDirectory;
-import org.apache.aries.util.manifest.ManifestProcessor;
-import org.osgi.framework.Version;
import org.osgi.framework.resource.Capability;
import org.osgi.framework.resource.Requirement;
import org.osgi.framework.resource.Resource;
import org.osgi.framework.resource.ResourceConstants;
-import org.osgi.service.repository.RepositoryContent;
import org.osgi.service.subsystem.SubsystemConstants;
-public class SubsystemDirectoryResource implements Resource, RepositoryContent {
+public class SubsystemDirectoryResource implements Resource {
+ private final SubsystemArchive archive;
private final List<Capability> capabilities;
- private final IDirectory directory;
- public SubsystemDirectoryResource(File content) throws IOException {
- this(FileSystem.getFSRoot(content));
- }
-
- public SubsystemDirectoryResource(IDirectory content) throws IOException {
- if (!content.isDirectory())
- throw new IllegalArgumentException("The content must represent a directory: " + content);
- this.directory = content;
- Manifest manifest = ManifestProcessor.obtainManifestFromAppDir(content, "OSGI-INF/DEPLOYMENT.MF");
- if (manifest == null)
- manifest = ManifestProcessor.obtainManifestFromAppDir(content, "OSGI-INF/SUBSYSTEM.MF");
- String symbolicName = new SubsystemSymbolicNameHeader(manifest
- .getMainAttributes().getValue(
- SubsystemConstants.SUBSYSTEM_SYMBOLICNAME))
- .getSymbolicName();
- Version version = Version.parseVersion(manifest.getMainAttributes()
- .getValue(SubsystemConstants.SUBSYSTEM_VERSION));
+ public SubsystemDirectoryResource(File content) throws Exception {
+ archive = new SubsystemArchive(content);
+ SubsystemManifest manifest = archive.getSubsystemManifest();
List<Capability> capabilities = new ArrayList<Capability>(1);
- capabilities.add(new OsgiIdentityCapability(this, symbolicName, version, SubsystemConstants.IDENTITY_TYPE_SUBSYSTEM));
+ capabilities.add(new OsgiIdentityCapability(
+ this,
+ manifest.getSubsystemSymbolicNameHeader().getSymbolicName(),
+ manifest.getSubsystemVersionHeader().getVersion(),
+ SubsystemConstants.IDENTITY_TYPE_SUBSYSTEM));
this.capabilities = Collections.unmodifiableList(capabilities);
}
+ public SubsystemArchive getArchive() {
+ return archive;
+ }
+
@Override
public List<Capability> getCapabilities(String namespace) {
if (namespace == null || ResourceConstants.IDENTITY_NAMESPACE.equals(namespace))
@@ -55,11 +42,6 @@ public class SubsystemDirectoryResource
}
@Override
- public InputStream getContent() throws IOException {
- return directory.open();
- }
-
- @Override
public List<Requirement> getRequirements(String namespace) {
return Collections.emptyList();
}
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java Mon Feb 13 12:52:50 2012
@@ -7,7 +7,6 @@ import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceEvent;
import org.osgi.framework.Version;
import org.osgi.service.subsystem.Subsystem;
@@ -34,40 +33,23 @@ public class RootSubsystemTest extends S
}
@Test
- public void testServiceEventsFresh() throws Exception {
+ public void testServiceEvents() throws Exception {
Subsystem root = getRootSubsystem();
Bundle core = getSubsystemCoreBundle();
core.stop();
- assertEvent(root, Subsystem.State.STOPPING, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000));
- // Don't forget about the unregistering event, which will have the same state as before.
- assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000), ServiceEvent.UNREGISTERING);
+ assertServiceEventsStop(root);
core.uninstall();
core = installBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.core");
core.start();
- // When starting for the very first time, the root subsystem should transition through all states.
- assertEvent(root, Subsystem.State.INSTALLING, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.INSTALLED, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.RESOLVING, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.STARTING, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.ACTIVE, subsystemEvents.poll(root.getSubsystemId(), 5000));
- }
-
- @Test
- public void testServiceEventsPersisted() throws Exception {
- Subsystem root = getRootSubsystem();
- Bundle core = getSubsystemCoreBundle();
+ assertServiceEventsInstall(root);
+ assertServiceEventsResolve(root);
+ assertServiceEventsStart(root);
core.stop();
- assertEvent(root, Subsystem.State.STOPPING, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000));
- // Don't forget about the unregistering event, which will have the same state as before.
- assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000), ServiceEvent.UNREGISTERING);
+ assertServiceEventsStop(root);
core.start();
- // On subsequent, post-installation starts, the root subsystem should start in the resolved state.
- assertEvent(root, Subsystem.State.RESOLVED, subsystemEvents.poll(root.getSubsystemId(), 5000), ServiceEvent.REGISTERED);
- assertEvent(root, Subsystem.State.STARTING, subsystemEvents.poll(root.getSubsystemId(), 5000));
- assertEvent(root, Subsystem.State.ACTIVE, subsystemEvents.poll(root.getSubsystemId(), 5000));
+ assertServiceEventsInstall(root);
+ assertServiceEventsResolve(root);
+ assertServiceEventsStart(root);
}
@Test
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1243492&r1=1243491&r2=1243492&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java Mon Feb 13 12:52:50 2012
@@ -327,6 +327,28 @@ public abstract class SubsystemTest exte
assertConstituent(s, "org.osgi.service.subsystem.region.context." + s.getSubsystemId(), Version.parseVersion("1.0.0"), ResourceConstants.IDENTITY_TYPE_BUNDLE);
}
+ protected void assertServiceEventsInstall(Subsystem subsystem) throws InterruptedException {
+ assertEvent(subsystem, Subsystem.State.INSTALLING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ assertEvent(subsystem, Subsystem.State.INSTALLED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ }
+
+ protected void assertServiceEventsResolve(Subsystem subsystem) throws InterruptedException {
+ assertEvent(subsystem, Subsystem.State.RESOLVING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ }
+
+ protected void assertServiceEventsStart(Subsystem subsystem) throws InterruptedException {
+ assertEvent(subsystem, Subsystem.State.STARTING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ assertEvent(subsystem, Subsystem.State.ACTIVE, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ }
+
+ protected void assertServiceEventsStop(Subsystem subsystem) throws InterruptedException {
+ assertEvent(subsystem, Subsystem.State.STOPPING, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000));
+ // Don't forget about the unregistering event, which will have the same state as before.
+ assertEvent(subsystem, Subsystem.State.RESOLVED, subsystemEvents.poll(subsystem.getSubsystemId(), 5000), ServiceEvent.UNREGISTERING);
+ }
+
protected void assertState(State expected, State actual) {
assertState(EnumSet.of(expected), actual);
}