Author: cziegeler
Date: Tue Aug 17 08:21:49 2010
New Revision: 986235

URL: http://svn.apache.org/viewvc?rev=986235&view=rev
Log:
Minor code cleanup

Modified:
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
    
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=986235&r1=986234&r2=986235&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
 Tue Aug 17 08:21:49 2010
@@ -252,14 +252,14 @@ public class OsgiInstallerThread
                for(String scheme : newResourcesSchemes) {
                    Logger.logDebug("Processing set of new resources with 
scheme " + scheme);
                 for(RegisteredResource r : newResources) {
-                    if(r.getUrlScheme().equals(scheme)) {
+                    if(r.getScheme().equals(scheme)) {
                         r.setInstallable(false);
                         Logger.logDebug("New resource set to non-installable: 
" + r);
                     }
                  }
                 for(SortedSet<RegisteredResource> ss : 
registeredResources.values()) {
                     for(RegisteredResource r : ss) {
-                        if(r.getUrlScheme().equals(scheme)) {
+                        if(r.getScheme().equals(scheme)) {
                             r.setInstallable(false);
                             Logger.logDebug("Existing resource set to 
non-installable: " + r);
                         }
@@ -269,7 +269,7 @@ public class OsgiInstallerThread
             for(SortedSet<RegisteredResource> s : newResourcesSets) {
                 newResources.addAll(s);
                 Logger.logDebug("Added set of " + s.size() + " new resources 
with scheme "
-                            + s.first().getUrlScheme() + ": " + s);
+                            + s.first().getScheme() + ": " + s);
             }
             newResourcesSets.clear();
             newResourcesSchemes.clear();

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java?rev=986235&r1=986234&r2=986235&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResource.java
 Tue Aug 17 08:21:49 2010
@@ -33,11 +33,6 @@ import org.apache.sling.osgi.installer.O
  */
 public interface RegisteredResource extends Serializable, 
Comparable<RegisteredResource> {
 
-       String DIGEST_TYPE = "MD5";
-    String ENTITY_JAR_PREFIX = "jar:";
-       String ENTITY_BUNDLE_PREFIX = "bundle:";
-       String ENTITY_CONFIG_PREFIX = "config:";
-
     /** Attribute key: configuration pid */
     String CONFIG_PID_ATTRIBUTE = "config.pid";
 
@@ -90,7 +85,8 @@ public interface RegisteredResource exte
 
        boolean isInstallable();
        void setInstallable(boolean installable);
-       String getUrlScheme();
+
+       String getScheme();
 
        /** Attributes include the bundle symbolic name, bundle version, etc. */
        Map<String, Object> getAttributes();

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java?rev=986235&r1=986234&r2=986235&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
 Tue Aug 17 08:21:49 2010
@@ -27,13 +27,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.List;
 import java.util.Map;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
@@ -50,9 +47,11 @@ import org.osgi.framework.Version;
 public class RegisteredResourceImpl
     implements RegisteredResource, Serializable {
 
+    private static final String ENTITY_BUNDLE_PREFIX = "bundle:";
+    private static final String ENTITY_CONFIG_PREFIX = "config:";
+
     private static final long serialVersionUID = 3L;
     private final String id;
-       private final String url;
        private final String urlScheme;
        private final String digest;
        private final String entity;
@@ -77,7 +76,6 @@ public class RegisteredResourceImpl
                final String scheme) throws IOException {
         this.id = input.getId();
         this.urlScheme = scheme;
-               this.url = scheme + ':' + input.getId();
                this.resourceType = input.getType();
                this.priority = input.getPriority();
         this.dictionary = copy(input.getDictionary());
@@ -92,18 +90,17 @@ public class RegisteredResourceImpl
                 copyToLocalStorage(input.getInputStream());
                 setAttributesFromManifest();
                 final String name = 
(String)attributes.get(Constants.BUNDLE_SYMBOLICNAME);
-                if(name == null) {
-                    // not a bundle - use "jar" entity to make it easier to 
find out
-                    entity = ENTITY_JAR_PREFIX + url;
-                } else {
-                    entity = ENTITY_BUNDLE_PREFIX + name;
+                if (name == null) {
+                    // not a bundle
+                    throw new IOException("Bundle resource does not contain a 
bundle " + this.urlScheme + ":" + this.id);
                 }
+                entity = ENTITY_BUNDLE_PREFIX + name;
             } finally {
                 is.close();
             }
                } else if ( 
resourceType.equals(InstallableResource.TYPE_CONFIG)) {
             this.dataFile = null;
-            final ConfigurationPid pid = new ConfigurationPid(url);
+            final ConfigurationPid pid = new ConfigurationPid(this.getURL());
             entity = ENTITY_CONFIG_PREFIX + pid.getCompositePid();
             attributes.put(CONFIG_PID_ATTRIBUTE, pid);
                } else {
@@ -119,7 +116,7 @@ public class RegisteredResourceImpl
 
        @Override
        public String toString() {
-           return getClass().getSimpleName() + " " + url + ", digest=" + 
digest + ", serialNumber=" + serialNumber;
+           return getClass().getSimpleName() + " " + this.getURL() + ", 
digest=" + this.getDigest() + ", serialNumber=" + this.getSerialNumber();
        }
 
        protected File getDataFile(final BundleContext bundleContext) {
@@ -127,6 +124,9 @@ public class RegisteredResourceImpl
                return bundleContext.getDataFile(filename);
        }
 
+       /**
+        * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#cleanup()
+        */
        public void cleanup() {
            if ( this.dataFile != null && this.dataFile.exists() ) {
                    Logger.logDebug("Deleting local storage file "
@@ -135,10 +135,16 @@ public class RegisteredResourceImpl
                }
        }
 
+       /**
+        * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getURL()
+        */
        public String getURL() {
-               return url;
+               return this.getScheme() + ':' + this.getId();
        }
 
+       /**
+        * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getInputStream()
+        */
        public InputStream getInputStream() throws IOException {
            if (this.dataFile != null && this.dataFile.exists() ) {
                return new BufferedInputStream(new 
FileInputStream(this.dataFile));
@@ -146,10 +152,16 @@ public class RegisteredResourceImpl
         return  null;
        }
 
+       /**
+        * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getDictionary()
+        */
        public Dictionary<String, Object> getDictionary() {
                return dictionary;
        }
 
+       /**
+        * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getDigest()
+        */
        public String getDigest() {
                return digest;
        }
@@ -176,54 +188,64 @@ public class RegisteredResourceImpl
                }
        }
 
-       /** Copy given Dictionary, sorting keys */
-       static Dictionary<String, Object> copy(final Dictionary<String, Object> 
d) {
+       /** Copy given Dictionary */
+       private Dictionary<String, Object> copy(final Dictionary<String, 
Object> d) {
            if ( d == null ) {
                return null;
            }
            final Dictionary<String, Object> result = new Hashtable<String, 
Object>();
-           final List<String> keys = new ArrayList<String>();
            final Enumeration<String> e = d.keys();
            while(e.hasMoreElements()) {
-               keys.add(e.nextElement());
-           }
-           Collections.sort(keys);
-           for(String key : keys) {
-               result.put(key, d.get(key));
+               final String key = e.nextElement();
+            result.put(key, d.get(key));
            }
            return result;
        }
 
+       /**
+        * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getId()
+        */
        public String getId() {
            return id;
        }
 
+    /**
+     * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getType()
+     */
     public String getType() {
         return resourceType;
     }
 
-    /** Return the identifier of the OSGi "entity" that this resource
-     *  represents, for example "bundle:SID" where SID is the bundle's
-     *  symbolic ID, or "config:PID" where PID is config's PID.
+    /**
+     * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getEntityId()
      */
     public String getEntityId() {
         return entity;
     }
 
+    /**
+     * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getAttributes()
+     */
     public Map<String, Object> getAttributes() {
                return attributes;
        }
 
+       /**
+        * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#isInstallable()
+        */
        public boolean isInstallable() {
         return installable;
        }
 
+    /**
+     * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#setInstallable(boolean)
+     */
     public void setInstallable(boolean installable) {
         this.installable = installable;
     }
 
     /** Read the manifest from supplied input stream, which is closed before 
return */
-    static Manifest getManifest(InputStream ins) throws IOException {
+    private Manifest getManifest(InputStream ins) throws IOException {
         Manifest result = null;
 
         JarInputStream jis = null;
@@ -272,10 +294,16 @@ public class RegisteredResourceImpl
         attributes.put(Constants.BUNDLE_VERSION, v.toString());
     }
 
-    public String getUrlScheme() {
+    /**
+     * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getScheme()
+     */
+    public String getScheme() {
         return urlScheme;
     }
 
+    /**
+     * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getPriority()
+     */
     public int getPriority() {
         return priority;
     }

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java?rev=986235&r1=986234&r2=986235&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
 Tue Aug 17 08:21:49 2010
@@ -68,10 +68,12 @@ public class BundleInstallTask extends O
         try {
             final Bundle b = 
this.creator.getBundleContext().installBundle(resource.getURL(), 
resource.getInputStream());
             // optionally set the start level
-            if (startLevelService != null && startLevel > 0) {
-                startLevelService.setBundleStartLevel(b, startLevel);
-            } else {
-                Logger.logWarn("Ignoring start level " + startLevel + " for 
bundle " + b + " - start level service not available.");
+            if ( startLevel > 0 ) {
+                if (startLevelService != null) {
+                    startLevelService.setBundleStartLevel(b, startLevel);
+                } else {
+                    Logger.logWarn("Ignoring start level " + startLevel + " 
for bundle " + b + " - start level service not available.");
+                }
             }
             final Version newVersion = new 
Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
             this.creator.saveInstalledBundleInfo(b.getSymbolicName(), 
resource.getDigest(), newVersion.toString());

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=986235&r1=986234&r2=986235&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
 Tue Aug 17 08:21:49 2010
@@ -63,7 +63,7 @@ public class BundleStartTask extends Osg
         * @see 
org.apache.sling.osgi.installer.impl.OsgiInstallerTask#execute(org.apache.sling.osgi.installer.impl.OsgiInstallerContext)
         */
        public Result execute(final OsgiInstallerContext ctx) {
-           // TODO : if bundle id is zero we should have created this task in 
the first place!
+           // this is just a sanity check which should never be reached
         if (bundleId == 0) {
             Logger.logDebug("Bundle 0 is the framework bundle, ignoring 
request to start it");
             return Result.NOTHING;
@@ -85,30 +85,29 @@ public class BundleStartTask extends Osg
 
         if (b.getState() == Bundle.ACTIVE) {
             Logger.logDebug("Bundle already started, no action taken:" + 
bundleId + "/" + b.getSymbolicName());
-        } else {
-            // Try to start bundle, and if that doesn't work we'll need to 
retry
-            logExecution();
-            try {
-                b.start();
-                Logger.logInfo("Bundle started (retry count=" + retryCount + 
", bundle ID=" + bundleId + ") " + b.getSymbolicName());
-            } catch(BundleException e) {
-                Logger.logInfo("Could not start bundle (retry count=" + 
retryCount + ", " + e
-                            + "), will retry: " + bundleId + "/" + 
b.getSymbolicName());
-
-                // Do the first retry immediately (in case "something" 
happenened right now
-                // that warrants a retry), but for the next ones wait for at 
least one bundle
-                // event or framework event
-                if (retryCount == 0) {
-                    eventsCountForRetrying = 
OsgiInstallerThread.getTotalEventsCount();
-                } else {
-                    eventsCountForRetrying = 
OsgiInstallerThread.getTotalEventsCount() + 1;
-                }
-
-                ctx.addTaskToNextCycle(this);
+            return Result.SUCCESS;
+        }
+        // Try to start bundle, and if that doesn't work we'll need to retry
+        logExecution();
+        try {
+            b.start();
+            Logger.logInfo("Bundle started (retry count=" + retryCount + ", 
bundle ID=" + bundleId + ") " + b.getSymbolicName());
+        } catch(BundleException e) {
+            Logger.logInfo("Could not start bundle (retry count=" + retryCount 
+ ", " + e
+                        + "), will retry: " + bundleId + "/" + 
b.getSymbolicName());
+
+            // Do the first retry immediately (in case "something" happenened 
right now
+            // that warrants a retry), but for the next ones wait for at least 
one bundle
+            // event or framework event
+            if (retryCount == 0) {
+                eventsCountForRetrying = 
OsgiInstallerThread.getTotalEventsCount();
+            } else {
+                eventsCountForRetrying = 
OsgiInstallerThread.getTotalEventsCount() + 1;
             }
-
+            retryCount++;
+            ctx.addTaskToNextCycle(this);
         }
-               retryCount++;
+
         return Result.SUCCESS;
        }
 }

Modified: 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java?rev=986235&r1=986234&r2=986235&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
 Tue Aug 17 08:21:49 2010
@@ -138,9 +138,9 @@ public class MockBundleResource implemen
        }
 
     /**
-     * @see 
org.apache.sling.osgi.installer.impl.RegisteredResource#getUrlScheme()
+     * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getScheme()
      */
-    public String getUrlScheme() {
+    public String getScheme() {
         return null;
     }
 


Reply via email to