Applied code formatting and some minor cleanups to improve readability of the code.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1589641 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
index 6581dc0..1d3ec68 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
@@ -43,7 +43,7 @@
* how the deployment package data is obtained, this should be handled by
* extending classes.
*/
-public abstract class AbstractDeploymentPackage implements DeploymentPackage {
+public abstract class AbstractDeploymentPackage implements DeploymentPackage, Constants {
/**
* Represents an empty deployment package.
*/
@@ -52,40 +52,70 @@
private static final ResourceInfoImpl[] RESOURCE_INFO_IMPLS = new ResourceInfoImpl[] {};
private static final BundleInfoImpl[] BUNDLE_INFO_IMPLS = new BundleInfoImpl[] {};
- public String getHeader(String header) {
- if (Constants.DEPLOYMENTPACKAGE_SYMBOLICMAME.equals(header)) {
- return "";
- } else if (Constants.DEPLOYMENTPACKAGE_VERSION.equals(header)) {
- return Version.emptyVersion.toString();
- } else {
- return null;
- }
- }
-
public Bundle getBundle(String symbolicName) {
return null;
}
- public BundleInfo[] getBundleInfos() {
- return BUNDLE_INFO_IMPLS;
- }
-
public BundleInfoImpl[] getBundleInfoImpls() {
return BUNDLE_INFO_IMPLS;
}
- public ResourceInfoImpl[] getResourceInfos() {
- return RESOURCE_INFO_IMPLS;
+ public BundleInfo[] getBundleInfos() {
+ return BUNDLE_INFO_IMPLS;
+ }
+
+ public InputStream getBundleStream(String symbolicName) throws IOException {
+ return null;
+ }
+
+ public InputStream getCurrentEntryStream() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getDisplayName() {
+ return "";
+ }
+
+ public String getHeader(String header) {
+ if (DEPLOYMENTPACKAGE_SYMBOLICMAME.equals(header)) {
+ return "";
+ }
+ else if (DEPLOYMENTPACKAGE_VERSION.equals(header)) {
+ return Version.emptyVersion.toString();
+ }
+ else {
+ return null;
+ }
+ }
+
+ public URL getIcon() {
+ return null;
}
public String getName() {
return "";
}
+ public AbstractInfo getNextEntry() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ public BundleInfoImpl[] getOrderedBundleInfos() {
+ return BUNDLE_INFO_IMPLS;
+ }
+
+ public ResourceInfoImpl[] getOrderedResourceInfos() {
+ return RESOURCE_INFO_IMPLS;
+ }
+
public String getResourceHeader(String resource, String header) {
return null;
}
+ public ResourceInfoImpl[] getResourceInfos() {
+ return RESOURCE_INFO_IMPLS;
+ }
+
public ServiceReference getResourceProcessor(String resource) {
return null;
}
@@ -109,34 +139,6 @@
public boolean uninstallForced() throws DeploymentException {
throw new IllegalStateException("Can not uninstall stale DeploymentPackage");
}
-
- public InputStream getBundleStream(String symbolicName) throws IOException {
- return null;
- }
-
- public BundleInfoImpl[] getOrderedBundleInfos() {
- return BUNDLE_INFO_IMPLS;
- }
-
- public ResourceInfoImpl[] getOrderedResourceInfos() {
- return RESOURCE_INFO_IMPLS;
- }
-
- public InputStream getCurrentEntryStream() {
- throw new UnsupportedOperationException();
- }
-
- public AbstractInfo getNextEntry() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- public String getDisplayName() {
- return "";
- }
-
- public URL getIcon() {
- return null;
- }
}
protected static final AbstractDeploymentPackage EMPTY_PACKAGE = new EmptyDeploymentPackage();
@@ -152,17 +154,6 @@
private final boolean m_isFixPackage;
private boolean m_isStale;
- /* Constructor only for use by the emptyPackage static variable */
- private AbstractDeploymentPackage() {
- m_bundleContext = null;
- m_manifest = null;
- m_bundleInfos = null;
- m_resourceInfos = null;
- m_resourcePaths = null;
- m_isFixPackage = false;
- m_deploymentAdmin = null;
- }
-
/**
* Creates an instance of this class.
*
@@ -184,13 +175,13 @@
String bsn = m_bundleInfos[i].getSymbolicName();
if (m_nameToBundleInfo.put(bsn, m_bundleInfos[i]) != null) {
// FELIX-4463: make sure that the DP is consistent...
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Duplicate bundle present in deployment package: " + bsn);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Duplicate bundle present in deployment package: " + bsn);
}
String path = m_bundleInfos[i].getPath();
if (m_pathToEntry.put(path, m_bundleInfos[i]) != null) {
// FELIX-4463: make sure that the DP is consistent...
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
}
}
@@ -201,12 +192,23 @@
String path = m_resourceInfos[i].getPath();
if (m_pathToEntry.put(path, m_resourceInfos[i]) != null) {
// FELIX-4463: make sure that the DP is consistent...
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
}
}
m_resourcePaths = (String[]) m_pathToEntry.keySet().toArray(new String[m_pathToEntry.size()]);
}
+ /* Constructor only for use by the emptyPackage static variable */
+ private AbstractDeploymentPackage() {
+ m_bundleContext = null;
+ m_manifest = null;
+ m_bundleInfos = null;
+ m_resourceInfos = null;
+ m_resourcePaths = null;
+ m_isFixPackage = false;
+ m_deploymentAdmin = null;
+ }
+
public Bundle getBundle(String symbolicName) {
if (isStale()) {
throw new IllegalStateException("Can not get bundle from stale deployment package.");
@@ -226,8 +228,32 @@
return null;
}
- public BundleInfo[] getBundleInfos() {
- return (BundleInfo[]) m_bundleInfos.clone();
+ /**
+ * Determines the info about a bundle resource based on the bundle symbolic
+ * name.
+ *
+ * @param symbolicName String containing a bundle symbolic name
+ * @return <code>BundleInfoImpl</code> for the bundle identified by the
+ * specified symbolic name or null if the symbolic name is unknown
+ */
+ public BundleInfoImpl getBundleInfoByName(String symbolicName) {
+ return (BundleInfoImpl) m_nameToBundleInfo.get(symbolicName);
+ }
+
+ /**
+ * Determines the info about a bundle based on it's path/resource-id.
+ *
+ * @param path String containing a bundle path
+ * @return <code>BundleInfoImpl</code> for the bundle resource identified by
+ * the specified path or null if the path is unknown or does not
+ * describe a bundle resource
+ */
+ public BundleInfoImpl getBundleInfoByPath(String path) {
+ AbstractInfo info = (AbstractInfo) m_pathToEntry.get(path);
+ if (info instanceof BundleInfoImpl) {
+ return (BundleInfoImpl) info;
+ }
+ return null;
}
/**
@@ -241,6 +267,117 @@
return (BundleInfoImpl[]) m_bundleInfos.clone();
}
+ public BundleInfo[] getBundleInfos() {
+ return (BundleInfo[]) m_bundleInfos.clone();
+ }
+
+ /**
+ * Determines the data stream of a bundle resource based on the bundle
+ * symbolic name
+ *
+ * @param symbolicName Bundle symbolic name
+ * @return Stream to the bundle identified by the specified symbolic name or
+ * null if no such bundle exists in this deployment package.
+ * @throws IOException If the bundle can not be properly offered as an
+ * inputstream
+ */
+ public abstract InputStream getBundleStream(String symbolicName) throws IOException;
+
+ /**
+ * Determines the data stream to the current entry of this deployment
+ * package, use this together with the <code>getNextEntry</code> method.
+ *
+ * @return Stream to the current resource in the deployment package (as
+ * determined by the order in which the deployment package was
+ * received originally) or null if there is no entry
+ */
+ public abstract InputStream getCurrentEntryStream();
+
+ public String getDisplayName() {
+ return getHeader(DEPLOYMENTPACKAGE_NAME);
+ }
+
+ public String getHeader(String header) {
+ return m_manifest.getHeader(header);
+ }
+
+ public URL getIcon() {
+ String icon = getHeader(DEPLOYMENTPACKAGE_ICON);
+ if (icon == null) {
+ return null;
+ }
+ else {
+ try {
+ // TODO spec states this must be a local resource, but we don't make sure of that yet
+ return new URL(icon);
+ }
+ catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ }
+
+ public String getName() {
+ return m_manifest.getSymbolicName();
+ }
+
+ /**
+ * Determines the next resource entry in this deployment package based on
+ * the order in which the resources appeared when the package was originally
+ * received.
+ *
+ * @return <code>AbstractInfo</code> describing the next resource entry (as
+ * determined by the order in which the deployment package was
+ * received originally) or null if there is no next entry
+ * @throws IOException if the next entry can not be properly determined
+ */
+ public abstract AbstractInfo getNextEntry() throws IOException;
+
+ /**
+ * Determines the bundles of this deployment package in the order in which
+ * they were originally received.
+ *
+ * @return Array containing <code>BundleInfoImpl</code> objects of the
+ * bundles in this deployment package, ordered in the way they
+ * appeared when the deployment package was first received.
+ */
+ public abstract BundleInfoImpl[] getOrderedBundleInfos();
+
+ /**
+ * Determines the resources of this deployment package in the order in which
+ * they were originally received.
+ *
+ * @return Array containing <code>ResourceInfoImpl</code> objects of all
+ * processed resources in this deployment package, ordered in the
+ * way they appeared when the deployment package was first received
+ */
+ public abstract ResourceInfoImpl[] getOrderedResourceInfos();
+
+ public String getResourceHeader(String resource, String header) {
+ AbstractInfo info = (AbstractInfo) m_pathToEntry.get(resource);
+ if (info != null) {
+ return info.getHeader(header);
+ }
+ return null;
+ }
+
+ /**
+ * Determines the info about a processed resource based on it's
+ * path/resource-id.
+ *
+ * @param path String containing a (processed) resource path
+ * @return <code>ResourceInfoImpl</code> for the resource identified by the
+ * specified path or null if the path is unknown or does not
+ * describe a processed resource
+ */
+ public ResourceInfoImpl getResourceInfoByPath(String path) {
+ AbstractInfo info = (AbstractInfo) m_pathToEntry.get(path);
+ if (info instanceof ResourceInfoImpl) {
+ return (ResourceInfoImpl) info;
+ }
+ return null;
+ }
+
/**
* Returns the processed resources of this deployment package as an array of
* <code>ResourceInfoImpl</code> objects.
@@ -252,51 +389,6 @@
return (ResourceInfoImpl[]) m_resourceInfos.clone();
}
- /**
- * Determines whether this deployment package is a fix package.
- *
- * @return True if this deployment package is a fix package, false
- * otherwise.
- */
- public boolean isFixPackage() {
- return m_isFixPackage;
- }
-
- public String getHeader(String header) {
- return m_manifest.getHeader(header);
- }
-
- public String getName() {
- return m_manifest.getSymbolicName();
- }
-
- public String getDisplayName() {
- return getHeader("DeploymentPackage-Name");
- }
-
- public URL getIcon() {
- String icon = getHeader("DeploymentPackage-Icon");
- if (icon == null) {
- return null;
- } else {
- try {
- // TODO spec states this must be a local resource, but we don't make sure of that yet
- return new URL(icon);
- }
- catch (MalformedURLException e) {
- return null;
- }
- }
- }
-
- public String getResourceHeader(String resource, String header) {
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(resource);
- if (info != null) {
- return info.getHeader(header);
- }
- return null;
- }
-
public ServiceReference getResourceProcessor(String resource) {
if (isStale()) {
throw new IllegalStateException("Can not get bundle from stale deployment package.");
@@ -306,10 +398,11 @@
String processor = ((ResourceInfoImpl) info).getResourceProcessor();
if (processor != null) {
try {
- ServiceReference[] services = m_bundleContext.getServiceReferences(ResourceProcessor.class.getName(), "(" + org.osgi.framework.Constants.SERVICE_PID + "=" + processor + ")");
+ ServiceReference[] services = m_bundleContext.getServiceReferences(ResourceProcessor.class.getName(), "(" + SERVICE_PID + "=" + processor + ")");
if (services != null && services.length > 0) {
return services[0];
- } else {
+ }
+ else {
return null;
}
}
@@ -341,8 +434,14 @@
return m_manifest.getFixPackage();
}
- public boolean isStale() {
- return m_isStale;
+ /**
+ * Determines whether this deployment package is a fix package.
+ *
+ * @return True if this deployment package is a fix package, false
+ * otherwise.
+ */
+ public boolean isFixPackage() {
+ return m_isFixPackage;
}
/**
@@ -354,6 +453,10 @@
return this == EMPTY_PACKAGE;
}
+ public boolean isStale() {
+ return m_isStale;
+ }
+
public void setStale(boolean isStale) {
m_isStale = isStale;
}
@@ -384,43 +487,6 @@
}
/**
- * Determines the bundles of this deployment package in the order in which
- * they were originally received.
- *
- * @return Array containing <code>BundleInfoImpl</code> objects of the
- * bundles in this deployment package, ordered in the way they
- * appeared when the deployment package was first received.
- */
- public abstract BundleInfoImpl[] getOrderedBundleInfos();
-
- /**
- * Determines the resources of this deployment package in the order in which
- * they were originally received.
- *
- * @return Array containing <code>ResourceInfoImpl</code> objects of all
- * processed resources in this deployment package, ordered in the
- * way they appeared when the deployment package was first received
- */
- public abstract ResourceInfoImpl[] getOrderedResourceInfos();
-
- /**
- * Determines the info about a processed resource based on it's
- * path/resource-id.
- *
- * @param path String containing a (processed) resource path
- * @return <code>ResourceInfoImpl</code> for the resource identified by the
- * specified path or null if the path is unknown or does not
- * describe a processed resource
- */
- public ResourceInfoImpl getResourceInfoByPath(String path) {
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(path);
- if (info instanceof ResourceInfoImpl) {
- return (ResourceInfoImpl) info;
- }
- return null;
- }
-
- /**
* Determines the info about either a bundle or processed resource based on
* it's path/resource-id.
*
@@ -433,66 +499,4 @@
return (AbstractInfo) m_pathToEntry.get(path);
}
- /**
- * Determines the info about a bundle based on it's path/resource-id.
- *
- * @param path String containing a bundle path
- * @return <code>BundleInfoImpl</code> for the bundle resource identified by
- * the specified path or null if the path is unknown or does not
- * describe a bundle resource
- */
- public BundleInfoImpl getBundleInfoByPath(String path) {
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(path);
- if (info instanceof BundleInfoImpl) {
- return (BundleInfoImpl) info;
- }
- return null;
- }
-
- /**
- * Determines the info about a bundle resource based on the bundle symbolic
- * name.
- *
- * @param symbolicName String containing a bundle symbolic name
- * @return <code>BundleInfoImpl</code> for the bundle identified by the
- * specified symbolic name or null if the symbolic name is unknown
- */
- public BundleInfoImpl getBundleInfoByName(String symbolicName) {
- return (BundleInfoImpl) m_nameToBundleInfo.get(symbolicName);
- }
-
- /**
- * Determines the data stream of a bundle resource based on the bundle
- * symbolic name
- *
- * @param symbolicName Bundle symbolic name
- * @return Stream to the bundle identified by the specified symbolic name or
- * null if no such bundle exists in this deployment package.
- * @throws IOException If the bundle can not be properly offered as an
- * inputstream
- */
- public abstract InputStream getBundleStream(String symbolicName) throws IOException;
-
- /**
- * Determines the next resource entry in this deployment package based on
- * the order in which the resources appeared when the package was originally
- * received.
- *
- * @return <code>AbstractInfo</code> describing the next resource entry (as
- * determined by the order in which the deployment package was
- * received originally) or null if there is no next entry
- * @throws IOException if the next entry can not be properly determined
- */
- public abstract AbstractInfo getNextEntry() throws IOException;
-
- /**
- * Determines the data stream to the current entry of this deployment
- * package, use this together with the <code>getNextEntry</code> method.
- *
- * @return Stream to the current resource in the deployment package (as
- * determined by the order in which the deployment package was
- * received originally) or null if there is no entry
- */
- public abstract InputStream getCurrentEntryStream();
-
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java
index e950bb7..f0b2af1 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java
@@ -27,28 +27,24 @@
* Objects of this class represent the meta data for a resource from a deployment package, this
* can be either bundle resources or processed resources.
*/
-public class AbstractInfo {
+public class AbstractInfo implements Constants {
private static final BitSet VALID_RESOURCE_PATH_CHARS;
- static
- {
+ static {
VALID_RESOURCE_PATH_CHARS = new BitSet();
- for ( int i = 'a'; i <= 'z'; i++ )
- {
- VALID_RESOURCE_PATH_CHARS.set( i );
+ for (int i = 'a'; i <= 'z'; i++) {
+ VALID_RESOURCE_PATH_CHARS.set(i);
}
- for ( int i = 'A'; i <= 'Z'; i++ )
- {
- VALID_RESOURCE_PATH_CHARS.set( i );
+ for (int i = 'A'; i <= 'Z'; i++) {
+ VALID_RESOURCE_PATH_CHARS.set(i);
}
- for ( int i = '0'; i <= '9'; i++ )
- {
- VALID_RESOURCE_PATH_CHARS.set( i );
+ for (int i = '0'; i <= '9'; i++) {
+ VALID_RESOURCE_PATH_CHARS.set(i);
}
- VALID_RESOURCE_PATH_CHARS.set( '.' );
- VALID_RESOURCE_PATH_CHARS.set( '-' );
- VALID_RESOURCE_PATH_CHARS.set( '_' );
- VALID_RESOURCE_PATH_CHARS.set( '/' );
+ VALID_RESOURCE_PATH_CHARS.set('.');
+ VALID_RESOURCE_PATH_CHARS.set('-');
+ VALID_RESOURCE_PATH_CHARS.set('_');
+ VALID_RESOURCE_PATH_CHARS.set('/');
}
private final String m_path;
@@ -66,7 +62,7 @@
verifyEntryName(path);
m_path = path;
m_attributes = attributes;
- m_missing = parseBooleanHeader(attributes, Constants.DEPLOYMENTPACKAGE_MISSING);
+ m_missing = parseBooleanHeader(attributes, DEPLOYMENTPACKAGE_MISSING);
}
/**
@@ -78,6 +74,7 @@
/**
* Return the value of a header for this resource
+ *
* @param header Name of the header
* @return Value of the header specified by the given header name
*/
@@ -88,17 +85,19 @@
private void verifyEntryName(String name) throws DeploymentException {
byte[] bytes = name.getBytes();
boolean delimiterSeen = false;
- for(int j = 0; j < bytes.length; j++) {
- if(!VALID_RESOURCE_PATH_CHARS.get(bytes[j])) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Resource ID '" + name +"' contains invalid character(s)");
+ for (int j = 0; j < bytes.length; j++) {
+ if (!VALID_RESOURCE_PATH_CHARS.get(bytes[j])) {
+ throw new DeploymentException(CODE_BAD_HEADER, "Resource ID '" + name + "' contains invalid character(s)");
}
if (bytes[j] == '/') {
if (delimiterSeen) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Resource ID '" + name +"' contains multiple consequetive path seperators");
- } else {
+ throw new DeploymentException(CODE_BAD_HEADER, "Resource ID '" + name + "' contains multiple consequetive path seperators");
+ }
+ else {
delimiterSeen = true;
}
- } else {
+ }
+ else {
delimiterSeen = false;
}
}
@@ -106,6 +105,7 @@
/**
* Determine if a resource is missing or not
+ *
* @return True if the actual data for this resource is not present, false otherwise
*/
public boolean isMissing() {
@@ -125,11 +125,12 @@
if (value != null) {
if ("true".equals(value)) {
return true;
- } else if ("false".equals(value)){
+ }
+ else if ("false".equals(value)) {
return false;
- } else {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Invalid '" + header + "' header for manifest " +
- "entry '" + getPath() + "' header, should be either 'true' or 'false' or not present");
+ }
+ else {
+ throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + header + "' header for manifest " + "entry '" + getPath() + "' header, should be either 'true' or 'false' or not present");
}
}
return false;
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
index 217a84a..e6089d5 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
@@ -39,10 +39,10 @@
public void init(BundleContext context, DependencyManager manager) throws Exception {
String[] ifaces = { DeploymentAdmin.class.getName(), ManagedService.class.getName() };
-
+
Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, DeploymentAdminImpl.PID);
-
+
manager.add(createComponent()
.setInterface(ifaces, props)
.setImplementation(DeploymentAdminImpl.class)
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java
index bdbe25b..bdfa8c1 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java
@@ -44,28 +44,31 @@
public BundleInfoImpl(String path, Attributes attributes) throws DeploymentException {
super(path, attributes);
- String bundleSymbolicName = attributes.getValue(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);
+ String bundleSymbolicName = attributes.getValue(BUNDLE_SYMBOLICNAME);
if (bundleSymbolicName == null) {
- throw new DeploymentException(DeploymentException.CODE_MISSING_HEADER, "Missing '" + org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
- } else if (bundleSymbolicName.trim().equals("")) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Invalid '" + org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
- } else {
+ throw new DeploymentException(CODE_MISSING_HEADER, "Missing '" + BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
+ }
+ else if (bundleSymbolicName.trim().equals("")) {
+ throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
+ }
+ else {
m_symbolicName = parseSymbolicName(bundleSymbolicName);
}
- String version = attributes.getValue(org.osgi.framework.Constants.BUNDLE_VERSION);
+ String version = attributes.getValue(BUNDLE_VERSION);
if (version == null || version == "") {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Invalid '" + org.osgi.framework.Constants.BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
+ throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
}
try {
m_version = Version.parseVersion(version);
- } catch (IllegalArgumentException e) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Invalid '" + org.osgi.framework.Constants.BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
+ }
+ catch (IllegalArgumentException e) {
+ throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
}
- m_customizer = parseBooleanHeader(attributes, Constants.DEPLOYMENTPACKAGE_CUSTOMIZER);
+ m_customizer = parseBooleanHeader(attributes, DEPLOYMENTPACKAGE_CUSTOMIZER);
}
-
+
/**
* Strips parameters from the bundle symbolic name such as "foo;singleton:=true".
*
@@ -103,7 +106,7 @@
* @return true if the attributes describe a bundle resource, false otherwise
*/
public static boolean isBundleResource(Attributes attributes) {
- return (attributes.getValue(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME) != null);
+ return (attributes.getValue(BUNDLE_SYMBOLICNAME) != null);
}
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java
index 0bdf653..7a524b3 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java
@@ -18,31 +18,58 @@
*/
package org.apache.felix.deploymentadmin;
+import org.osgi.service.deploymentadmin.DeploymentException;
import org.osgi.service.deploymentadmin.DeploymentPackage;
public interface Constants extends org.osgi.framework.Constants {
// manifest main attribute header constants
- public static final String DEPLOYMENTPACKAGE_SYMBOLICMAME = "DeploymentPackage-SymbolicName";
- public static final String DEPLOYMENTPACKAGE_VERSION = "DeploymentPackage-Version";
- public static final String DEPLOYMENTPACKAGE_FIXPACK = "DeploymentPackage-FixPack";
+ String DEPLOYMENTPACKAGE_SYMBOLICMAME = "DeploymentPackage-SymbolicName";
+ String DEPLOYMENTPACKAGE_VERSION = "DeploymentPackage-Version";
+ String DEPLOYMENTPACKAGE_FIXPACK = "DeploymentPackage-FixPack";
+ String DEPLOYMENTPACKAGE_NAME = "DeploymentPackage-Name";
+ String DEPLOYMENTPACKAGE_ICON = "DeploymentPackage-Icon";
// manifest 'name' section header constants
- public static final String RESOURCE_PROCESSOR = "Resource-Processor";
- public static final String DEPLOYMENTPACKAGE_MISSING = "DeploymentPackage-Missing";
- public static final String DEPLOYMENTPACKAGE_CUSTOMIZER = "DeploymentPackage-Customizer";
+ String RESOURCE_PROCESSOR = "Resource-Processor";
+ String DEPLOYMENTPACKAGE_MISSING = "DeploymentPackage-Missing";
+ String DEPLOYMENTPACKAGE_CUSTOMIZER = "DeploymentPackage-Customizer";
// event topics and properties
- public static final String EVENTTOPIC_INSTALL = "org/osgi/service/deployment/INSTALL";
- public static final String EVENTTOPIC_UNINSTALL = "org/osgi/service/deployment/UNINSTALL";
- public static final String EVENTTOPIC_COMPLETE = "org/osgi/service/deployment/COMPLETE";
-
- public static final String EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_NAME;
- public static final String EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_READABLENAME;
- public static final String EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_CURRENTVERSION;
- public static final String EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_NEXTVERSION;
- public static final String EVENTPROPERTY_SUCCESSFUL = "successful";
+ String EVENTTOPIC_INSTALL = "org/osgi/service/deployment/INSTALL";
+ String EVENTTOPIC_UNINSTALL = "org/osgi/service/deployment/UNINSTALL";
+ String EVENTTOPIC_COMPLETE = "org/osgi/service/deployment/COMPLETE";
+
+ String EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_NAME;
+ String EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_READABLENAME;
+ String EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_CURRENTVERSION;
+ String EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_NEXTVERSION;
+ String EVENTPROPERTY_SUCCESSFUL = "successful";
// miscellaneous constants
- public static final String BUNDLE_LOCATION_PREFIX = "osgi-dp:";
+ String BUNDLE_LOCATION_PREFIX = "osgi-dp:";
+
+ // inlined constants for convenience & readability
+ int CODE_CANCELLED = DeploymentException.CODE_CANCELLED;
+ int CODE_NOT_A_JAR = DeploymentException.CODE_NOT_A_JAR;
+ int CODE_ORDER_ERROR = DeploymentException.CODE_ORDER_ERROR;
+ int CODE_MISSING_HEADER = DeploymentException.CODE_MISSING_HEADER;
+ int CODE_BAD_HEADER = DeploymentException.CODE_BAD_HEADER;
+ int CODE_MISSING_FIXPACK_TARGET = DeploymentException.CODE_MISSING_FIXPACK_TARGET;
+ int CODE_MISSING_BUNDLE = DeploymentException.CODE_MISSING_BUNDLE;
+ int CODE_MISSING_RESOURCE = DeploymentException.CODE_MISSING_RESOURCE;
+ int CODE_SIGNING_ERROR = DeploymentException.CODE_SIGNING_ERROR;
+ int CODE_BUNDLE_NAME_ERROR = DeploymentException.CODE_BUNDLE_NAME_ERROR;
+ int CODE_FOREIGN_CUSTOMIZER = DeploymentException.CODE_FOREIGN_CUSTOMIZER;
+ int CODE_BUNDLE_SHARING_VIOLATION = DeploymentException.CODE_BUNDLE_SHARING_VIOLATION;
+ int CODE_RESOURCE_SHARING_VIOLATION = DeploymentException.CODE_RESOURCE_SHARING_VIOLATION;
+ int CODE_COMMIT_ERROR = DeploymentException.CODE_COMMIT_ERROR;
+ int CODE_OTHER_ERROR = DeploymentException.CODE_OTHER_ERROR;
+ int CODE_PROCESSOR_NOT_FOUND = DeploymentException.CODE_PROCESSOR_NOT_FOUND;
+ int CODE_TIMEOUT = DeploymentException.CODE_TIMEOUT;
+
+ String BUNDLE_SYMBOLICNAME = org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+ String BUNDLE_VERSION = org.osgi.framework.Constants.BUNDLE_VERSION;
+ String SERVICE_PID = org.osgi.framework.Constants.SERVICE_PID;
+
}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java
index bbaec0e..8f9a689 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java
@@ -33,19 +33,17 @@
import java.util.zip.ZipEntry;
/**
- * Provides a custom {@link JarInputStream} that copies all entries read from the original
- * {@link InputStream} to a given directory and index file. It does this by tracking the
- * common usage of the {@link JarInputStream} API. For each entry that is read it streams
- * all read bytes to a separate file compressing it on the fly. The caller does not notice
- * anything, although it might be that the {@link #read(byte[], int, int)} is blocked for
- * a little while during the writing of the file contents.
+ * Provides a custom {@link JarInputStream} that copies all entries read from the original {@link InputStream} to a
+ * given directory and index file. It does this by tracking thecommon usage of the {@link JarInputStream} API. For each
+ * entry that is read it streams all read bytes to a separate file compressing it on the fly. The caller does not notice
+ * anything, although it might be that the {@link #read(byte[], int, int)} is blocked for a little while during the
+ * writing of the file contents.
* <p>
* This implementation replaces the old <tt>ExplodingOutputtingInputStream</tt> that used
* at least two threads and was difficult to understand and maintain. See FELIX-4486.
* </p>
*/
-class ContentCopyingJarInputStream extends JarInputStream
-{
+class ContentCopyingJarInputStream extends JarInputStream {
private static final String MANIFEST_FILE = JarFile.MANIFEST_NAME;
private final File m_contentDir;
@@ -54,8 +52,7 @@
/** Used to copy the contents of the *next* entry. */
private OutputStream m_entryOS;
- public ContentCopyingJarInputStream(InputStream in, File indexFile, File contentDir) throws IOException
- {
+ public ContentCopyingJarInputStream(InputStream in, File indexFile, File contentDir) throws IOException {
super(in);
m_contentDir = contentDir;
@@ -65,35 +62,29 @@
// the manifest of the JAR is already read by JarInputStream, so we need to write this one as well...
Manifest manifest = getManifest();
- if (manifest != null)
- {
+ if (manifest != null) {
copyManifest(manifest);
}
}
- public void close() throws IOException
- {
+ public void close() throws IOException {
closeCopy();
closeIndex();
super.close();
}
- public void closeEntry() throws IOException
- {
+ public void closeEntry() throws IOException {
closeCopy();
super.closeEntry();
}
- public ZipEntry getNextEntry() throws IOException
- {
+ public ZipEntry getNextEntry() throws IOException {
closeCopy();
ZipEntry entry = super.getNextEntry();
- if (entry != null)
- {
+ if (entry != null) {
File current = new File(m_contentDir, entry.getName());
- if (!entry.isDirectory())
- {
+ if (!entry.isDirectory()) {
addToIndex(entry.getName());
m_entryOS = createOutputStream(current);
@@ -103,52 +94,41 @@
return entry;
}
- public int read(byte[] b, int off, int len) throws IOException
- {
+ public int read(byte[] b, int off, int len) throws IOException {
int r = super.read(b, off, len);
- if (m_entryOS != null)
- {
- if (r > 0)
- {
+ if (m_entryOS != null) {
+ if (r > 0) {
m_entryOS.write(b, off, r);
}
- else
- {
+ else {
closeCopy();
}
}
return r;
}
- private void addToIndex(String name) throws IOException
- {
+ private void addToIndex(String name) throws IOException {
m_indexFileWriter.println(name);
m_indexFileWriter.flush();
}
- private void closeCopy()
- {
+ private void closeCopy() {
closeSilently(m_entryOS);
m_entryOS = null;
}
- private void closeIndex()
- {
+ private void closeIndex() {
closeSilently(m_indexFileWriter);
m_indexFileWriter = null;
}
- private void closeSilently(Closeable resource)
- {
- try
- {
- if (resource != null)
- {
+ private void closeSilently(Closeable resource) {
+ try {
+ if (resource != null) {
resource.close();
}
}
- catch (IOException e)
- {
+ catch (IOException e) {
// Ignore, not much we can do about this...
}
}
@@ -156,30 +136,24 @@
/**
* Creates a verbatim copy of the manifest, when it is read from the original JAR.
*/
- private void copyManifest(Manifest manifest) throws IOException
- {
+ private void copyManifest(Manifest manifest) throws IOException {
addToIndex(MANIFEST_FILE);
OutputStream os = createOutputStream(new File(m_contentDir, MANIFEST_FILE));
- try
- {
+ try {
manifest.write(os);
}
- finally
- {
+ finally {
closeSilently(os);
}
}
- private OutputStream createOutputStream(File file) throws IOException
- {
+ private OutputStream createOutputStream(File file) throws IOException {
File parent = file.getParentFile();
- if (parent != null)
- {
+ if (parent != null) {
parent.mkdirs();
}
- if (!file.createNewFile())
- {
+ if (!file.createNewFile()) {
throw new IOException("Attempt to overwrite file: " + file);
}
return new GZIPOutputStream(new FileOutputStream(file));
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
index 2266d46..70f9a3d 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
@@ -58,7 +58,7 @@
import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.PackageAdmin;
-public class DeploymentAdminImpl implements DeploymentAdmin, ManagedService {
+public class DeploymentAdminImpl implements DeploymentAdmin, ManagedService, Constants {
/** Configuration PID used to dynamically configure DA at runtime. */
public static final String PID = "org.apache.felix.deploymentadmin";
@@ -71,14 +71,14 @@
private static final long TIMEOUT = 10000;
- private volatile BundleContext m_context; /* will be injected by dependencymanager */
- private volatile PackageAdmin m_packageAdmin; /* will be injected by dependencymanager */
- private volatile EventAdmin m_eventAdmin; /* will be injected by dependencymanager */
- private volatile LogService m_log; /* will be injected by dependencymanager */
+ private volatile BundleContext m_context; /* will be injected by dependencymanager */
+ private volatile PackageAdmin m_packageAdmin; /* will be injected by dependencymanager */
+ private volatile EventAdmin m_eventAdmin; /* will be injected by dependencymanager */
+ private volatile LogService m_log; /* will be injected by dependencymanager */
private volatile DeploymentSessionImpl m_session;
private volatile DeploymentAdminConfig m_config;
-
- private final Map m_packages = new HashMap();
+
+ private final Map /* BSN -> DeploymentPackage */m_packages = new HashMap();
private final Semaphore m_semaphore = new Semaphore();
/**
@@ -87,7 +87,7 @@
public DeploymentAdminImpl() {
// Nop
}
-
+
/**
* Creates a new {@link DeploymentAdminImpl} instance.
*/
@@ -152,18 +152,18 @@
return m_packageAdmin;
}
- public DeploymentPackage installDeploymentPackage(InputStream sourceInput) throws DeploymentException {
+ public DeploymentPackage installDeploymentPackage(InputStream sourceInput) throws DeploymentException {
if (sourceInput == null) {
throw new IllegalArgumentException("Inputstream may not be null");
}
try {
if (!m_semaphore.tryAcquire(TIMEOUT)) {
- throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Timeout exceeded while waiting to install deployment package (" + TIMEOUT + " ms)");
+ throw new DeploymentException(CODE_TIMEOUT, "Timeout exceeded while waiting to install deployment package (" + TIMEOUT + " ms)");
}
}
catch (InterruptedException ie) {
- throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Thread interrupted");
+ throw new DeploymentException(CODE_TIMEOUT, "Thread interrupted");
}
File tempPackage = null;
@@ -187,42 +187,43 @@
}
catch (IOException e) {
m_log.log(LogService.LOG_ERROR, "Error writing package to disk", e);
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Error writing package to disk", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Error writing package to disk", e);
}
try {
jarInput = new ContentCopyingJarInputStream(sourceInput, tempIndex, tempContents);
-
+
if (jarInput.getManifest() == null) {
m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid deployment package: missing manifest!");
- throw new DeploymentException(DeploymentException.CODE_MISSING_HEADER, "No manifest present in deployment package!");
+ throw new DeploymentException(CODE_MISSING_HEADER, "No manifest present in deployment package!");
}
}
catch (IOException e) {
m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid Jar", e);
- throw new DeploymentException(DeploymentException.CODE_NOT_A_JAR, "Stream does not contain a valid Jar", e);
+ throw new DeploymentException(CODE_NOT_A_JAR, "Stream does not contain a valid Jar", e);
}
source = new StreamDeploymentPackage(jarInput, m_context, this);
String dpSymbolicName = source.getName();
-
+
target = getExistingOrEmptyDeploymentPackage(dpSymbolicName);
-
- // Fire an event that we're about to install a new package
+
+ // Fire an event that we're about to install a new package
sendStartedEvent(source, target);
// Assert that:
- // the source has no bundles that exists in other packages than the target.
+ // the source has no bundles that exists in other packages than the target.
verifyNoResourcesShared(source, target);
-
+
if (source.isFixPackage()) {
// Assert that:
- // a. the version of the target matches the required fix-package range;
- // b. all missing source bundles are present in the target.
+ // a. the version of the target matches the required fix-package range;
+ // b. all missing source bundles are present in the target.
verifyFixPackage(source, target);
- } else {
+ }
+ else {
// Assert that:
- // no missing resources or bundles are declared.
+ // no missing resources or bundles are declared.
verifySourcePackage(source);
}
@@ -245,17 +246,17 @@
}
catch (IOException e) {
m_log.log(LogService.LOG_ERROR, "Could not merge source fix package with target deployment package", e);
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not merge source fix package with target deployment package", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not merge source fix package with target deployment package", e);
}
}
else {
File targetPackage = m_context.getDataFile(dpInstallBaseDirectory);
targetPackage.mkdirs();
if (!Utils.replace(targetPackage, tempPackage)) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not replace " + targetPackage + " with " + tempPackage);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not replace " + targetPackage + " with " + tempPackage);
}
}
-
+
FileDeploymentPackage fileDeploymentPackage = null;
try {
fileDeploymentPackage = new FileDeploymentPackage(targetIndex, targetContents, m_context, this);
@@ -263,7 +264,7 @@
}
catch (IOException e) {
m_log.log(LogService.LOG_ERROR, "Could not create installed deployment package from disk", e);
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not create installed deployment package from disk", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not create installed deployment package from disk", e);
}
// Since we're here, it means everything went OK, so we might as well raise our success flag...
@@ -274,12 +275,12 @@
finally {
if (tempPackage != null) {
if (!Utils.delete(tempPackage, true)) {
- m_log.log(LogService.LOG_ERROR, "Could not delete temporary deployment package from disk");
- succeeded = false;
+ m_log.log(LogService.LOG_ERROR, "Could not delete temporary deployment package from disk");
+ succeeded = false;
}
}
- sendCompleteEvent(source, target, succeeded);
+ sendCompleteEvent(source, target, succeeded);
m_semaphore.release();
}
}
@@ -295,24 +296,27 @@
public void start() throws DeploymentException {
// Create a default configuration...
m_config = new DeploymentAdminConfig(m_context);
-
+
File packageDir = m_context.getDataFile(PACKAGE_DIR);
if (packageDir == null) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not create directories needed for deployment package persistence");
- } else {
- packageDir.mkdirs();
- File[] packages = packageDir.listFiles();
- for(int i = 0; i < packages.length; i++) {
- if (packages[i].isDirectory()) {
- try {
- File index = new File(packages[i], PACKAGEINDEX_FILE);
- File contents = new File(packages[i], PACKAGECONTENTS_DIR);
- FileDeploymentPackage dp = new FileDeploymentPackage(index, contents, m_context, this);
- m_packages.put(dp.getName(), dp);
- }
- catch (IOException e) {
- m_log.log(LogService.LOG_WARNING, "Could not read deployment package from disk, skipping: '" + packages[i].getAbsolutePath() + "'");
- }
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not create directories needed for deployment package persistence");
+ }
+ else if (packageDir.isDirectory()) {
+ File[] dpPackages = packageDir.listFiles();
+ for (int i = 0; i < dpPackages.length; i++) {
+ File dpPackageDir = dpPackages[i];
+ if (!dpPackageDir.isDirectory()) {
+ continue;
+ }
+
+ try {
+ File index = new File(dpPackageDir, PACKAGEINDEX_FILE);
+ File contents = new File(dpPackageDir, PACKAGECONTENTS_DIR);
+ FileDeploymentPackage dp = new FileDeploymentPackage(index, contents, m_context, this);
+ m_packages.put(dp.getName(), dp);
+ }
+ catch (IOException e) {
+ m_log.log(LogService.LOG_WARNING, "Could not read deployment package from disk, skipping: '" + dpPackageDir.getAbsolutePath() + "'");
}
}
}
@@ -322,11 +326,11 @@
* Called by dependency manager when stopping this component.
*/
public void stop() {
- cancel();
+ cancel();
- m_config = null;
+ m_config = null;
}
-
+
/**
* Uninstalls the given deployment package from the system.
*
@@ -337,13 +341,13 @@
public void uninstallDeploymentPackage(DeploymentPackage dp, boolean forced) throws DeploymentException {
try {
if (!m_semaphore.tryAcquire(TIMEOUT)) {
- throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Timeout exceeded while waiting to uninstall deployment package (" + TIMEOUT + " ms)");
+ throw new DeploymentException(CODE_TIMEOUT, "Timeout exceeded while waiting to uninstall deployment package (" + TIMEOUT + " ms)");
}
}
catch (InterruptedException ie) {
- throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Thread interrupted");
+ throw new DeploymentException(CODE_TIMEOUT, "Thread interrupted");
}
-
+
boolean succeeded = false;
AbstractDeploymentPackage source = AbstractDeploymentPackage.EMPTY_PACKAGE;
AbstractDeploymentPackage target = (AbstractDeploymentPackage) dp;
@@ -362,10 +366,10 @@
File targetPackage = m_context.getDataFile(PACKAGE_DIR + File.separator + source.getName());
if (!Utils.delete(targetPackage, true)) {
- m_log.log(LogService.LOG_ERROR, "Could not delete deployment package from disk");
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not delete deployment package from disk");
+ m_log.log(LogService.LOG_ERROR, "Could not delete deployment package from disk");
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not delete deployment package from disk");
}
-
+
m_packages.remove(dp.getName());
succeeded = true;
@@ -375,7 +379,7 @@
m_semaphore.release();
}
}
-
+
public void updated(Dictionary properties) throws ConfigurationException {
m_config = new DeploymentAdminConfig(m_context, properties);
}
@@ -395,18 +399,18 @@
displayName = source.getName();
}
- props.put(Constants.EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME, source.getName());
- props.put(Constants.EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME, displayName);
+ props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME, source.getName());
+ props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME, displayName);
if (!source.isNew()) {
- props.put(Constants.EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION, source.getVersion());
+ props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION, source.getVersion());
}
}
if ((target != null) && !target.isNew()) {
- props.put(Constants.EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION, target.getVersion());
+ props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION, target.getVersion());
}
return props;
}
-
+
private List createInstallCommandChain() {
List commandChain = new ArrayList();
@@ -422,7 +426,7 @@
commandChain.add(new DropBundleCommand());
commandChain.add(commitCommand);
commandChain.add(new StartBundleCommand());
-
+
return commandChain;
}
@@ -438,19 +442,19 @@
commandChain.add(new DropAllResourcesCommand(commitCommand));
commandChain.add(commitCommand);
commandChain.add(new DropAllBundlesCommand());
-
+
return commandChain;
}
-
+
/**
* Searches for a deployment package that contains a bundle with the given symbolic name.
*
* @param symbolicName the symbolic name of the <em>bundle</em> to return the containing deployment package for, cannot be <code>null</code>.
* @return the deployment package containing the given bundle, or <code>null</code> if no deployment package contained such bundle.
*/
- private DeploymentPackage getDeploymentPackageContainingBundleWithSymbolicName(String symbolicName) {
+ private AbstractDeploymentPackage getDeploymentPackageContainingBundleWithSymbolicName(String symbolicName) {
for (Iterator i = m_packages.values().iterator(); i.hasNext();) {
- DeploymentPackage dp = (DeploymentPackage) i.next();
+ AbstractDeploymentPackage dp = (AbstractDeploymentPackage) i.next();
if (dp.getBundle(symbolicName) != null) {
return dp;
}
@@ -465,7 +469,7 @@
* @return a deployment package, never <code>null</code>.
*/
private AbstractDeploymentPackage getExistingOrEmptyDeploymentPackage(String symbolicName) {
- AbstractDeploymentPackage result = (AbstractDeploymentPackage) getDeploymentPackage(symbolicName);
+ AbstractDeploymentPackage result = (AbstractDeploymentPackage) m_packages.get(symbolicName);
if (result == null) {
result = AbstractDeploymentPackage.EMPTY_PACKAGE;
}
@@ -473,18 +477,18 @@
}
/**
- * Returns all bundles that are not present in any deployment package. Ultimately, this should only
+ * Returns all bundles that are not present in any deployment package. Ultimately, this should only
* be one bundle, the system bundle, but this is not enforced in any way by the specification.
*
* @return an array of non-deployment packaged bundles, never <code>null</code>.
*/
private Bundle[] getNonDeploymentPackagedBundles() {
List result = new ArrayList(Arrays.asList(m_context.getBundles()));
-
+
Iterator iter = result.iterator();
while (iter.hasNext()) {
Bundle suspect = (Bundle) iter.next();
- if (suspect.getLocation().startsWith(Constants.BUNDLE_LOCATION_PREFIX)) {
+ if (suspect.getLocation().startsWith(BUNDLE_LOCATION_PREFIX)) {
iter.remove();
}
}
@@ -493,7 +497,7 @@
}
/**
- * Sends out an event that the {@link #installDeploymentPackage(InputStream)} is
+ * Sends out an event that the {@link #installDeploymentPackage(InputStream)} is
* completed its installation of a deployment package.
*
* @param source the source package being installed;
@@ -502,13 +506,13 @@
*/
private void sendCompleteEvent(AbstractDeploymentPackage source, AbstractDeploymentPackage target, boolean success) {
Dictionary props = createEventProperties(source, target);
- props.put(Constants.EVENTPROPERTY_SUCCESSFUL, Boolean.valueOf(success));
-
- m_eventAdmin.postEvent(new Event(Constants.EVENTTOPIC_COMPLETE, props));
+ props.put(EVENTPROPERTY_SUCCESSFUL, Boolean.valueOf(success));
+
+ m_eventAdmin.postEvent(new Event(EVENTTOPIC_COMPLETE, props));
}
/**
- * Sends out an event that the {@link #installDeploymentPackage(InputStream)} is about
+ * Sends out an event that the {@link #installDeploymentPackage(InputStream)} is about
* to install a new deployment package.
*
* @param source the source package being installed;
@@ -517,11 +521,11 @@
private void sendStartedEvent(AbstractDeploymentPackage source, AbstractDeploymentPackage target) {
Dictionary props = createEventProperties(source, target);
- m_eventAdmin.postEvent(new Event(Constants.EVENTTOPIC_INSTALL, props));
+ m_eventAdmin.postEvent(new Event(EVENTTOPIC_INSTALL, props));
}
/**
- * Sends out an event that the {@link #uninstallDeploymentPackage(DeploymentPackage)} is about
+ * Sends out an event that the {@link #uninstallDeploymentPackage(DeploymentPackage)} is about
* to uninstall a deployment package.
*
* @param source the source package being uninstalled;
@@ -530,11 +534,11 @@
private void sendUninstallEvent(AbstractDeploymentPackage source, AbstractDeploymentPackage target) {
Dictionary props = createEventProperties(source, target);
- m_eventAdmin.postEvent(new Event(Constants.EVENTTOPIC_UNINSTALL, props));
+ m_eventAdmin.postEvent(new Event(EVENTTOPIC_UNINSTALL, props));
}
/**
- * Verifies that the version of the target matches the required source version range, and
+ * Verifies that the version of the target matches the required source version range, and
* whether all missing source resources are available in the target.
*
* @param source the fix-package source to verify;
@@ -547,7 +551,7 @@
// Verify whether the target package exists, and if so, falls in the requested fix-package range...
if (newPackage || (!source.getVersionRange().isInRange(target.getVersion()))) {
m_log.log(LogService.LOG_ERROR, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
- throw new DeploymentException(DeploymentException.CODE_MISSING_FIXPACK_TARGET, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
+ throw new DeploymentException(CODE_MISSING_FIXPACK_TARGET, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
}
// Verify whether all missing bundles are available in the target package...
@@ -558,7 +562,7 @@
BundleInfoImpl targetBundleInfo = target.getBundleInfoByPath(bundleInfos[i].getPath());
if (targetBundleInfo == null) {
m_log.log(LogService.LOG_ERROR, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
- throw new DeploymentException(DeploymentException.CODE_MISSING_BUNDLE, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
+ throw new DeploymentException(CODE_MISSING_BUNDLE, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
}
}
}
@@ -571,14 +575,14 @@
ResourceInfoImpl targetResourceInfo = target.getResourceInfoByPath(resourceInfos[i].getPath());
if (targetResourceInfo == null) {
m_log.log(LogService.LOG_ERROR, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
- throw new DeploymentException(DeploymentException.CODE_MISSING_RESOURCE, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
+ throw new DeploymentException(CODE_MISSING_RESOURCE, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
}
}
}
}
/**
- * Verifies whether none of the mentioned resources in the source package are present in
+ * Verifies whether none of the mentioned resources in the source package are present in
* deployment packages other than the given target.
*
* @param source the source package to verify;
@@ -587,7 +591,7 @@
*/
private void verifyNoResourcesShared(AbstractDeploymentPackage source, AbstractDeploymentPackage target) throws DeploymentException {
Bundle[] foreignBundles = getNonDeploymentPackagedBundles();
-
+
// Verify whether all source bundles are available in the target package or absent...
BundleInfoImpl[] bundleInfos = source.getBundleInfoImpls();
for (int i = 0; i < bundleInfos.length; i++) {
@@ -598,26 +602,26 @@
// If found, it should match the given target DP; not found is also ok...
if ((targetPackage != null) && !targetPackage.equals(target)) {
m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
- throw new DeploymentException(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
+ throw new DeploymentException(CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
}
-
+
if (targetPackage == null) {
// Maybe the bundle is installed without deployment admin...
for (int j = 0; j < foreignBundles.length; j++) {
if (symbolicName.equals(foreignBundles[j].getSymbolicName()) && version.equals(foreignBundles[j].getVersion())) {
m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present!");
- throw new DeploymentException(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present!");
+ throw new DeploymentException(CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present!");
}
}
}
}
-
+
// TODO verify other resources as well...
}
private void verifySourcePackage(AbstractDeploymentPackage source) throws DeploymentException {
// TODO this method should do a X-ref check between DP-manifest and JAR-entries...
-// m_log.log(LogService.LOG_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
-// throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() + " is not part of target package!");
+// m_log.log(LogService.LOG_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
+// throw new DeploymentException(CODE_OTHER_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() + " is not part of target package!");
}
}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java
index f450b94..ed1189c 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java
@@ -32,7 +32,7 @@
* This class represents a manifest file used to describe the contents of a deployment package. It can verify the correctness of a
* deployment package manifest and can interpret the various manifest entries and headers the OSGi specification defines.
*/
-public class DeploymentPackageManifest {
+public class DeploymentPackageManifest implements Constants {
private final Manifest m_manifest;
private final Version m_version;
@@ -50,36 +50,38 @@
*/
public DeploymentPackageManifest(Manifest manifest) throws DeploymentException {
if ((manifest == null) || (manifest.getMainAttributes() == null)) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER);
+ throw new DeploymentException(CODE_BAD_HEADER);
}
m_manifest = manifest;
Attributes mainAttributes = m_manifest.getMainAttributes();
// TODO: verify symbolic name and entry-names for valid format/chars
- m_symbolicName = getNonNullHeader(mainAttributes.getValue(Constants.DEPLOYMENTPACKAGE_SYMBOLICMAME));
+ m_symbolicName = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_SYMBOLICMAME));
- String version = getNonNullHeader(mainAttributes.getValue(Constants.DEPLOYMENTPACKAGE_VERSION));
+ String version = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_VERSION));
try {
m_version = new Version(version);
- } catch (IllegalArgumentException e) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER);
+ }
+ catch (IllegalArgumentException e) {
+ throw new DeploymentException(CODE_BAD_HEADER);
}
- String fixPackage = mainAttributes.getValue(Constants.DEPLOYMENTPACKAGE_FIXPACK);
+ String fixPackage = mainAttributes.getValue(DEPLOYMENTPACKAGE_FIXPACK);
if (fixPackage != null) {
try {
m_fixPackage = VersionRange.parse(fixPackage);
}
catch (IllegalArgumentException iae) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Invalid version range for header: " + Constants.DEPLOYMENTPACKAGE_FIXPACK);
+ throw new DeploymentException(CODE_BAD_HEADER, "Invalid version range for header: " + DEPLOYMENTPACKAGE_FIXPACK);
}
- } else {
+ }
+ else {
m_fixPackage = null;
}
Map entries = m_manifest.getEntries();
- for(Iterator i = entries.keySet().iterator(); i.hasNext(); ) {
+ for (Iterator i = entries.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
processEntry(key, (Attributes) entries.get(key), (m_fixPackage != null));
}
@@ -115,6 +117,7 @@
/**
* Determines the version of the deployment package.
+ *
* @return Version of the deployment package.
*/
public Version getVersion() {
@@ -143,20 +146,22 @@
if (BundleInfoImpl.isBundleResource(attributes)) {
BundleInfoImpl bundleInfo = new BundleInfoImpl(key, attributes);
if (bundleInfo.isMissing() && !isFixPack) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Header '" + Constants.DEPLOYMENTPACKAGE_MISSING + "' for manifest " +
- "entry '" + key + "' may only be 'true' if " + Constants.DEPLOYMENTPACKAGE_FIXPACK + " manifest header is 'true'");
+ throw new DeploymentException(CODE_BAD_HEADER, "Header '" + DEPLOYMENTPACKAGE_MISSING + "' for manifest entry '" + key + "' may only be 'true' if " + DEPLOYMENTPACKAGE_FIXPACK
+ + " manifest header is 'true'");
}
m_bundleInfos.add(bundleInfo);
- } else {
+ }
+ else {
m_resourceInfos.add(new ResourceInfoImpl(key, attributes));
}
}
private String getNonNullHeader(String header) throws DeploymentException {
if (header == null) {
- throw new DeploymentException(DeploymentException.CODE_MISSING_HEADER);
- } else if(header.trim().equals("")) {
- throw new DeploymentException(DeploymentException.CODE_BAD_HEADER);
+ throw new DeploymentException(CODE_MISSING_HEADER);
+ }
+ else if ("".equals(header.trim())) {
+ throw new DeploymentException(CODE_BAD_HEADER);
}
return header;
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java
index 94aa1a1..f2a0454 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java
@@ -56,17 +56,6 @@
m_contentsDir = packageDir;
}
- public BundleInfoImpl[] getOrderedBundleInfos() {
- List result = new ArrayList();
- for(Iterator i = m_index.iterator(); i.hasNext();) {
- AbstractInfo bundleInfo = getBundleInfoByPath((String) i.next());
- if (bundleInfo != null) {
- result.add(bundleInfo);
- }
- }
- return (BundleInfoImpl[]) result.toArray(new BundleInfoImpl[result.size()]);
- }
-
public InputStream getBundleStream(String symbolicName) throws IOException {
BundleInfoImpl bundleInfo = getBundleInfoByName(symbolicName);
if (bundleInfo != null) {
@@ -75,17 +64,6 @@
return null;
}
- public ResourceInfoImpl[] getOrderedResourceInfos() {
- List result = new ArrayList();
- for(Iterator i = m_index.iterator(); i.hasNext();) {
- AbstractInfo resourceInfo = getResourceInfoByPath((String) i.next());
- if (resourceInfo != null) {
- result.add(resourceInfo);
- }
- }
- return (ResourceInfoImpl[]) result.toArray(new ResourceInfoImpl[result.size()]);
- }
-
public InputStream getCurrentEntryStream() {
throw new UnsupportedOperationException("Not implemented for file-based deployment package");
}
@@ -93,4 +71,26 @@
public AbstractInfo getNextEntry() throws IOException {
throw new UnsupportedOperationException("Not implemented for file-based deployment package");
}
+
+ public BundleInfoImpl[] getOrderedBundleInfos() {
+ List result = new ArrayList();
+ for (Iterator i = m_index.iterator(); i.hasNext();) {
+ AbstractInfo bundleInfo = getBundleInfoByPath((String) i.next());
+ if (bundleInfo != null) {
+ result.add(bundleInfo);
+ }
+ }
+ return (BundleInfoImpl[]) result.toArray(new BundleInfoImpl[result.size()]);
+ }
+
+ public ResourceInfoImpl[] getOrderedResourceInfos() {
+ List result = new ArrayList();
+ for (Iterator i = m_index.iterator(); i.hasNext();) {
+ AbstractInfo resourceInfo = getResourceInfoByPath((String) i.next());
+ if (resourceInfo != null) {
+ result.add(resourceInfo);
+ }
+ }
+ return (ResourceInfoImpl[]) result.toArray(new ResourceInfoImpl[result.size()]);
+ }
}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java
index c4ae67c..795192b 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java
@@ -29,77 +29,74 @@
*/
public class NonCloseableStream extends InputStream {
- private final InputStream m_input;
- private boolean m_closed;
+ private final InputStream m_input;
+ private boolean m_closed;
- public NonCloseableStream(InputStream m_input) {
- this.m_input = m_input;
- }
+ public NonCloseableStream(InputStream m_input) {
+ this.m_input = m_input;
+ }
-
- // stream should not be actually closed, subsequent calls to read methods will throw an exception though
-
- public void close() throws IOException {
- if (m_closed) {
- throw new IOException("Unable to read, stream is closed.");
- }
- m_closed = true;
- }
-
- public int read() throws IOException {
- return m_input.read();
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- if (m_closed) {
- throw new IOException("Unable to read, stream is closed.");
- }
- return m_input.read(b, off, len);
- }
+ // stream should not be actually closed, subsequent calls to read methods will throw an exception though
- public int read(byte[] b) throws IOException {
- if (m_closed) {
- throw new IOException("Unable to read, stream is closed.");
- }
- return m_input.read(b);
- }
+ public void close() throws IOException {
+ if (m_closed) {
+ throw new IOException("Unable to read, stream is closed.");
+ }
+ m_closed = true;
+ }
-
- // No mark & reset support
-
- public boolean markSupported() {
- return false;
- }
+ public int read() throws IOException {
+ return m_input.read();
+ }
- public void mark(int readlimit) {
- // do nothing
- }
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (m_closed) {
+ throw new IOException("Unable to read, stream is closed.");
+ }
+ return m_input.read(b, off, len);
+ }
- public void reset() throws IOException {
- throw new IOException("Mark and reset are not available on this type of stream.");
- }
+ public int read(byte[] b) throws IOException {
+ if (m_closed) {
+ throw new IOException("Unable to read, stream is closed.");
+ }
+ return m_input.read(b);
+ }
+ // No mark & reset support
- // Unaffected methods
+ public boolean markSupported() {
+ return false;
+ }
- public int available() throws IOException {
- return m_input.available();
- }
+ public void mark(int readlimit) {
+ // do nothing
+ }
- public int hashCode() {
- return m_input.hashCode();
- }
+ public void reset() throws IOException {
+ throw new IOException("Mark and reset are not available on this type of stream.");
+ }
- public long skip(long n) throws IOException {
- return m_input.skip(n);
- }
+ // Unaffected methods
- public boolean equals(Object obj) {
- return m_input.equals(obj);
- }
+ public int available() throws IOException {
+ return m_input.available();
+ }
- public String toString() {
- return m_input.toString();
- }
+ public int hashCode() {
+ return m_input.hashCode();
+ }
+
+ public long skip(long n) throws IOException {
+ return m_input.skip(n);
+ }
+
+ public boolean equals(Object obj) {
+ return m_input.equals(obj);
+ }
+
+ public String toString() {
+ return m_input.toString();
+ }
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
index be796a8..07ee847 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
@@ -38,7 +38,7 @@
*/
public ResourceInfoImpl(String path, Attributes attributes) throws DeploymentException {
super(path, attributes);
- m_resourceProcessor = attributes.getValue(Constants.RESOURCE_PROCESSOR);
+ m_resourceProcessor = attributes.getValue(RESOURCE_PROCESSOR);
}
/**
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java
index b27bb47..a9f20e2 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java
@@ -70,7 +70,7 @@
*
* @param timeout the number of milliseconds to wait
* @return <code>true</code> if the semaphore was acquired, <code>false</code> if it was
- * not after waiting for the specified amount of time
+ * not after waiting for the specified amount of time
* @throws InterruptedException when the thread is interrupted
*/
public boolean tryAcquire(long timeout) throws InterruptedException {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java
index 887628b..8279739 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java
@@ -52,31 +52,8 @@
throw new UnsupportedOperationException("Not applicable for stream-based deployment package");
}
- // This only works for those resources that have been read from the stream already, no guarantees for remainder of stream
- public BundleInfoImpl[] getOrderedBundleInfos() {
- List result = new ArrayList();
-
- // add all bundle resources ordered by location in stream
- for(Iterator i = m_names.iterator(); i.hasNext();) {
- String indexEntry = (String) i.next();
- AbstractInfo bundleInfo = getBundleInfoByPath(indexEntry);
- if (bundleInfo != null) {
- result.add(bundleInfo);
- }
- }
-
- // add bundle resources marked missing to the end of the result
- BundleInfoImpl[] bundleInfoImpls = getBundleInfoImpls();
- for (int i = 0; i < bundleInfoImpls.length; i++) {
- if(bundleInfoImpls[i].isMissing()) {
- result.add(bundleInfoImpls[i]);
- }
- }
- return (BundleInfoImpl[]) result.toArray(new BundleInfoImpl[result.size()]);
- }
-
- public ResourceInfoImpl[] getOrderedResourceInfos() {
- throw new UnsupportedOperationException("Not applicable for stream-based deployment package");
+ public InputStream getCurrentEntryStream() {
+ return new NonCloseableStream(m_input);
}
public AbstractInfo getNextEntry() throws IOException {
@@ -90,7 +67,30 @@
return abstractInfoByPath;
}
- public InputStream getCurrentEntryStream() {
- return new NonCloseableStream(m_input);
+ // This only works for those resources that have been read from the stream already, no guarantees for remainder of stream
+ public BundleInfoImpl[] getOrderedBundleInfos() {
+ List result = new ArrayList();
+
+ // add all bundle resources ordered by location in stream
+ for (Iterator i = m_names.iterator(); i.hasNext();) {
+ String indexEntry = (String) i.next();
+ AbstractInfo bundleInfo = getBundleInfoByPath(indexEntry);
+ if (bundleInfo != null) {
+ result.add(bundleInfo);
+ }
+ }
+
+ // add bundle resources marked missing to the end of the result
+ BundleInfoImpl[] bundleInfoImpls = getBundleInfoImpls();
+ for (int i = 0; i < bundleInfoImpls.length; i++) {
+ if (bundleInfoImpls[i].isMissing()) {
+ result.add(bundleInfoImpls[i]);
+ }
+ }
+ return (BundleInfoImpl[]) result.toArray(new BundleInfoImpl[result.size()]);
+ }
+
+ public ResourceInfoImpl[] getOrderedResourceInfos() {
+ throw new UnsupportedOperationException("Not applicable for stream-based deployment package");
}
}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java
index 9279b50..daebd3e 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java
@@ -90,10 +90,10 @@
return false;
}
finally {
- if (!closeSilently(output)) {
+ if (!closeSilently(output)) {
result = false;
}
- if (!closeSilently(input)) {
+ if (!closeSilently(input)) {
result = false;
}
}
@@ -166,7 +166,7 @@
result.add(path);
}
if (!rename(from, to)) {
- throw new IOException("Could not rename " + from + " to " + to);
+ throw new IOException("Could not rename " + from + " to " + to);
}
}
@@ -191,7 +191,8 @@
GZIPOutputStream outputStream = new GZIPOutputStream(new FileOutputStream(new File(target, MANIFEST_NAME)));
try {
resultManifest.write(outputStream);
- } finally {
+ }
+ finally {
outputStream.close();
}
writeIndex(targetIndex, result);
@@ -211,7 +212,7 @@
closeSilently(reader);
}
}
-
+
static boolean closeSilently(Closeable closeable) {
if (closeable != null) {
try {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java
index c9298d9..44d1c94 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.felix.deploymentadmin.spi;
/**
@@ -26,8 +25,7 @@
*/
abstract class AbstractAction implements Runnable {
/**
- * Runs this action by calling {@link #doRun()} and in case of failure,
- * {@link #onFailure(Exception)}.
+ * Runs this action by calling {@link #doRun()} and in case of failure, {@link #onFailure(Exception)}.
*/
public final void run() {
try {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
index 312d66c..4529de0 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
@@ -34,7 +34,7 @@
* and a command that is currently in progress can be signaled to stop it's
* activities by canceling it.
*/
-public abstract class Command {
+public abstract class Command implements Constants {
private final List m_rollback = new ArrayList();
private final List m_commit = new ArrayList();
@@ -58,7 +58,7 @@
if (e instanceof DeploymentException) {
throw (DeploymentException) e;
}
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Command failed!", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Command failed!", e);
}
}
@@ -169,10 +169,10 @@
* bundle, <code>false</code> otherwise.
*/
static final boolean isFragmentBundle(Bundle bundle) {
- Object fragmentHost = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
+ Object fragmentHost = bundle.getHeaders().get(FRAGMENT_HOST);
return fragmentHost != null;
}
-
+
static final void closeSilently(Closeable resource) {
if (resource != null) {
try {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
index 94de905..171337a 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
@@ -46,13 +46,13 @@
session.getLog().log(LogService.LOG_ERROR, "Preparing commit for resource processor failed", e);
// Check what error code we got...
if (e.getCode() == ResourceProcessorException.CODE_PREPARE) {
- throw new DeploymentException(DeploymentException.CODE_COMMIT_ERROR, "Preparing commit for resource processor failed!", e);
+ throw new DeploymentException(CODE_COMMIT_ERROR, "Preparing commit for resource processor failed!", e);
}
throw new DeploymentException(e.getCode(), "Preparing commit for resource processor failed!", e);
}
catch (Exception e) {
session.getLog().log(LogService.LOG_ERROR, "Preparing commit for resource processor failed", e);
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Preparing commit for resource processor failed", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Preparing commit for resource processor failed", e);
}
}
for (ListIterator i = m_processors.listIterator(m_processors.size()); i.hasPrevious();) {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
index f83bc86..68d0fb0 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
@@ -25,6 +25,7 @@
import java.util.ListIterator;
import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
+import org.apache.felix.deploymentadmin.Constants;
import org.apache.felix.deploymentadmin.DeploymentAdminConfig;
import org.apache.felix.deploymentadmin.DeploymentAdminImpl;
import org.osgi.framework.Bundle;
@@ -38,7 +39,7 @@
/**
* Represents a running deployment session.
*/
-public class DeploymentSessionImpl implements DeploymentSession {
+public class DeploymentSessionImpl implements DeploymentSession, Constants {
private final AbstractDeploymentPackage m_target;
private final AbstractDeploymentPackage m_source;
@@ -49,8 +50,7 @@
private volatile Command m_currentCommand = null;
private volatile boolean m_cancelled;
- public DeploymentSessionImpl(AbstractDeploymentPackage source, AbstractDeploymentPackage target, List commands,
- DeploymentAdminImpl admin) {
+ public DeploymentSessionImpl(AbstractDeploymentPackage source, AbstractDeploymentPackage target, List commands, DeploymentAdminImpl admin) {
m_source = source;
m_target = target;
m_commands = commands;
@@ -73,7 +73,7 @@
if (m_cancelled) {
// previous command did not pick up on cancel
rollback(executedCommands);
- throw new DeploymentException(DeploymentException.CODE_CANCELLED);
+ throw new DeploymentException(CODE_CANCELLED);
}
m_currentCommand = (Command) i.next();
try {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java
index bfe8a89..48ca3ff 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java
@@ -69,7 +69,8 @@
is = m_target.getBundleStream(m_bundle.getSymbolicName());
if (is != null) {
m_bundle.update(is);
- } else {
+ }
+ else {
throw new RuntimeException("Unable to get inputstream for bundle '" + m_bundle.getSymbolicName() + "'");
}
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
index b918953..95e9273 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
@@ -76,13 +76,13 @@
ServiceReference ref = target.getResourceProcessor(path);
if (ref == null) {
log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
- throw new DeploymentException(DeploymentException.CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
+ throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
}
ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
if (resourceProcessor == null) {
log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
- throw new DeploymentException(DeploymentException.CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
+ throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
}
try {
@@ -93,7 +93,7 @@
}
catch (Exception e) {
log.log(LogService.LOG_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
}
}
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java
index ee018d0..7ad59c2 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java
@@ -71,7 +71,8 @@
is = m_target.getBundleStream(m_bundle.getSymbolicName());
if (is != null) {
m_bundle.update(is);
- } else {
+ }
+ else {
throw new RuntimeException("Unable to get Inputstream for bundle '" + m_bundle.getSymbolicName() + "'");
}
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java
index bc0093b..d75c619 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java
@@ -41,7 +41,7 @@
BundleInfo[] infos = target.getBundleInfos();
for (int i = 0; i < infos.length; i++) {
if (isCancelled()) {
- throw new DeploymentException(DeploymentException.CODE_CANCELLED);
+ throw new DeploymentException(CODE_CANCELLED);
}
Bundle bundle = target.getBundle(infos[i].getSymbolicName());
if (bundle != null) {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
index cfa6d84..7b89635 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
@@ -75,27 +75,27 @@
while (!expectedResources.isEmpty()) {
AbstractInfo jarEntry = source.getNextEntry();
if (jarEntry == null) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Expected more resources in the stream: " + expectedResources.keySet());
+ throw new DeploymentException(CODE_OTHER_ERROR, "Expected more resources in the stream: " + expectedResources.keySet());
}
String name = jarEntry.getPath();
ResourceInfoImpl resourceInfo = (ResourceInfoImpl) expectedResources.remove(name);
if (resourceInfo == null) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
+ throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
}
ServiceReference ref = source.getResourceProcessor(name);
if (ref == null) {
- throw new DeploymentException(DeploymentException.CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
+ throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
}
if (!isValidCustomizer(session, ref)) {
- throw new DeploymentException(DeploymentException.CODE_FOREIGN_CUSTOMIZER, "Resource processor for resource '" + name + "' belongs to foreign deployment package");
+ throw new DeploymentException(CODE_FOREIGN_CUSTOMIZER, "Resource processor for resource '" + name + "' belongs to foreign deployment package");
}
ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
if (resourceProcessor == null) {
- throw new DeploymentException(DeploymentException.CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
+ throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
}
try {
@@ -106,18 +106,19 @@
}
catch (ResourceProcessorException rpe) {
if (rpe.getCode() == ResourceProcessorException.CODE_RESOURCE_SHARING_VIOLATION) {
- throw new DeploymentException(DeploymentException.CODE_RESOURCE_SHARING_VIOLATION, "Sharing violation while processing resource '" + name + "'", rpe);
- } else {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Error while processing resource '" + name + "'", rpe);
+ throw new DeploymentException(CODE_RESOURCE_SHARING_VIOLATION, "Sharing violation while processing resource '" + name + "'", rpe);
+ }
+ else {
+ throw new DeploymentException(CODE_OTHER_ERROR, "Error while processing resource '" + name + "'", rpe);
}
}
}
}
catch (IOException e) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Problem while reading stream", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
}
}
-
+
private boolean isValidCustomizer(DeploymentSessionImpl session, ServiceReference ref) {
if (session.getConfiguration().isAllowForeignCustomizers()) {
// If foreign customizers are allowed, any non-null customizer will do...
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
index 1b6f589..7b25160 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
@@ -52,7 +52,7 @@
Map storageAreas = m_getStorageAreaCommand.getStorageAreas();
for (int i = 0; i < infos.length; i++) {
if (isCancelled()) {
- throw new DeploymentException(DeploymentException.CODE_CANCELLED);
+ throw new DeploymentException(CODE_CANCELLED);
}
String symbolicName = infos[i].getSymbolicName();
@@ -73,7 +73,8 @@
session.getLog().log(LogService.LOG_WARNING, "Could not access storage area of bundle '" + symbolicName + "'!", e);
snapshot.delete();
}
- } else {
+ }
+ else {
session.getLog().log(LogService.LOG_WARNING, "Could not retrieve storage area of bundle '" + symbolicName + "', skipping it.");
}
}
@@ -102,7 +103,8 @@
for (int i = 0; i < childs.length; i++) {
storeRecursive(childs[i], new File(path, childs[i].getName()), output);
}
- } else {
+ }
+ else {
InputStream input = null;
try {
input = new FileInputStream(current);
@@ -181,7 +183,8 @@
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory()) {
(new File(target, entry.getName())).mkdirs();
- } else {
+ }
+ else {
OutputStream output = null;
try {
output = new FileOutputStream(target);
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
index ea9d4ae..edb4502 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
@@ -55,7 +55,8 @@
if (bundle != null) {
if (isFragmentBundle(bundle)) {
log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
- } else {
+ }
+ else {
try {
bundle.start();
}
@@ -63,7 +64,8 @@
log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "'", be);
}
}
- } else {
+ }
+ else {
log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "' because it is not present in the framework");
}
}
@@ -105,12 +107,12 @@
try {
wait(REFRESH_TIMEOUT);
}
- catch (InterruptedException ie) {
- }
+ catch (InterruptedException ie) {}
finally {
m_alreadyNotified = false;
}
- } else {
+ }
+ else {
// just reset the misted notification variable, this Monitor
// object might be reused.
m_alreadyNotified = false;
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
index cf1e9ea..610e9ab 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
@@ -70,7 +70,7 @@
bundle.start();
}
catch (Exception be) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not start customizer bundle '" + bundle.getSymbolicName() + "'", be);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not start customizer bundle '" + bundle.getSymbolicName() + "'", be);
}
addRollback(new StopCustomizerRunnable(session, bundle));
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
index f7e4d03..13bfeda 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
@@ -47,8 +47,9 @@
BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
for (int i = 0; i < bundleInfos.length; i++) {
if (isCancelled()) {
- throw new DeploymentException(DeploymentException.CODE_CANCELLED);
+ throw new DeploymentException(CODE_CANCELLED);
}
+
String symbolicName = bundleInfos[i].getSymbolicName();
Bundle bundle = target.getBundle(symbolicName);
if (bundle != null) {
@@ -57,7 +58,8 @@
}
if (isFragmentBundle(bundle)) {
log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
- } else {
+ }
+ else {
addRollback(new StartBundleRunnable(session, bundle));
try {
bundle.stop();
@@ -66,7 +68,8 @@
log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "'", e);
}
}
- } else {
+ }
+ else {
log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not present in the framework");
}
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
index 2fca3bc..4e96879 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
@@ -26,7 +26,6 @@
import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
import org.apache.felix.deploymentadmin.AbstractInfo;
import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.apache.felix.deploymentadmin.Constants;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
@@ -60,13 +59,13 @@
while (!expectedBundles.isEmpty()) {
AbstractInfo entry = source.getNextEntry();
if (entry == null) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Expected more bundles in the stream: " + expectedBundles.keySet());
+ throw new DeploymentException(CODE_OTHER_ERROR, "Expected more bundles in the stream: " + expectedBundles.keySet());
}
String name = entry.getPath();
BundleInfoImpl bundleInfo = (BundleInfoImpl) expectedBundles.remove(name);
if (bundleInfo == null) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
+ throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
}
String bsn = bundleInfo.getSymbolicName();
@@ -76,9 +75,10 @@
try {
if (bundle == null) {
// new bundle, install it
- bundle = context.installBundle(Constants.BUNDLE_LOCATION_PREFIX + bsn, new BundleInputStream(source.getCurrentEntryStream()));
+ bundle = context.installBundle(BUNDLE_LOCATION_PREFIX + bsn, new BundleInputStream(source.getCurrentEntryStream()));
addRollback(new UninstallBundleRunnable(bundle, log));
- } else {
+ }
+ else {
// existing bundle, update it
Version currentVersion = getVersion(bundle);
if (!sourceVersion.equals(currentVersion)) {
@@ -91,26 +91,27 @@
if (isCancelled()) {
return;
}
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not install new bundle '" + name + "' (" + bsn + ")", be);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Could not install new bundle '" + name + "' (" + bsn + ")", be);
}
if (!bundle.getSymbolicName().equals(bsn)) {
- throw new DeploymentException(DeploymentException.CODE_BUNDLE_NAME_ERROR, "Installed/updated bundle symbolicname (" + bundle.getSymbolicName() + ") do not match what was installed/updated: " + bsn);
+ throw new DeploymentException(CODE_BUNDLE_NAME_ERROR, "Installed/updated bundle symbolicname (" + bundle.getSymbolicName() + ") do not match what was installed/updated: " + bsn);
}
Version targetVersion = getVersion(bundle);
if (!sourceVersion.equals(targetVersion)) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Installed/updated bundle version (" + targetVersion + ") do not match what was installed/updated: " + sourceVersion + ", offending bundle = " + bsn);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Installed/updated bundle version (" + targetVersion + ") do not match what was installed/updated: " + sourceVersion
+ + ", offending bundle = " + bsn);
}
}
}
catch (IOException e) {
- throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Problem while reading stream", e);
+ throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
}
}
private Version getVersion(Bundle bundle) {
- return Version.parseVersion((String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION));
+ return Version.parseVersion((String) bundle.getHeaders().get(BUNDLE_VERSION));
}
private static class UninstallBundleRunnable extends AbstractAction {
@@ -148,7 +149,8 @@
is = m_targetPackage.getBundleStream(m_bundle.getSymbolicName());
if (is != null) {
m_bundle.update(is);
- } else {
+ }
+ else {
throw new RuntimeException("Unable to get inputstream for bundle " + m_bundle.getSymbolicName());
}
}