incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1140979 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl: DefaultTransformer.java Util.java
Date Wed, 29 Jun 2011 07:07:48 GMT
Author: cziegeler
Date: Wed Jun 29 07:07:48 2011
New Revision: 1140979

URL: http://svn.apache.org/viewvc?rev=1140979&view=rev
Log:
SLING-2115 : Reject bundle with illegal version information as early as possible

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Util.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java?rev=1140979&r1=1140978&r2=1140979&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
Wed Jun 29 07:07:48 2011
@@ -28,6 +28,9 @@ import org.apache.sling.installer.api.ta
 import org.apache.sling.installer.api.tasks.TransformationResult;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The default transformer transforms:
@@ -36,6 +39,9 @@ import org.osgi.framework.Constants;
 public class DefaultTransformer
     implements InternalService, ResourceTransformer {
 
+    /** Logger */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
     /**
      * @see org.apache.sling.installer.core.impl.InternalService#init(org.osgi.framework.BundleContext,
org.apache.sling.installer.api.ResourceChangeListener)
      */
@@ -74,21 +80,32 @@ public class DefaultTransformer
     private TransformationResult[] checkBundle(final RegisteredResource resource) {
         final Util.BundleHeaders headers = Util.readBundleHeaders(resource);
         if ( headers != null ) {
-            final Map<String, Object> attr = new HashMap<String, Object>();
-            attr.put(Constants.BUNDLE_SYMBOLICNAME, headers.symbolicName);
-            attr.put(Constants.BUNDLE_VERSION, headers.version);
-
-            // check for activation policy
-            if ( headers.activationPolicy != null ) {
-                attr.put(Constants.BUNDLE_ACTIVATIONPOLICY, headers.activationPolicy);
+            // check the version for validity
+            boolean validVersion = true;
+            try {
+                new Version(headers.version);
+            } catch (final IllegalArgumentException iae) {
+                logger.info("Rejecting bundle {} from {} due to invalid version information:
{}," +
+                		new Object[] {headers.symbolicName, resource, headers.version});
+                validVersion = false;
             }
+            if ( validVersion ) {
+                final Map<String, Object> attr = new HashMap<String, Object>();
+                attr.put(Constants.BUNDLE_SYMBOLICNAME, headers.symbolicName);
+                attr.put(Constants.BUNDLE_VERSION, headers.version);
+
+                // check for activation policy
+                if ( headers.activationPolicy != null ) {
+                    attr.put(Constants.BUNDLE_ACTIVATIONPOLICY, headers.activationPolicy);
+                }
+
+                final TransformationResult tr = new TransformationResult();
+                tr.setId(headers.symbolicName);
+                tr.setResourceType(InstallableResource.TYPE_BUNDLE);
+                tr.setAttributes(attr);
 
-            final TransformationResult tr = new TransformationResult();
-            tr.setId(headers.symbolicName);
-            tr.setResourceType(InstallableResource.TYPE_BUNDLE);
-            tr.setAttributes(attr);
-
-            return new TransformationResult[] {tr};
+                return new TransformationResult[] {tr};
+            }
         }
         return null;
     }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Util.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Util.java?rev=1140979&r1=1140978&r2=1140979&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Util.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Util.java
Wed Jun 29 07:07:48 2011
@@ -109,7 +109,7 @@ public class Util {
                         final String symbolicName = (paramPos == -1 ? sn : sn.substring(0,
paramPos));
                         final BundleHeaders headers = new BundleHeaders();
                         headers.symbolicName = symbolicName;
-                        headers.version = v.toString();
+                        headers.version = v;
 
                         // check for activation policy
                         final String actPolicy = m.getMainAttributes().getValue(Constants.BUNDLE_ACTIVATIONPOLICY);



Mime
View raw message