Author: bdelacretaz
Date: Fri Aug 14 16:22:45 2009
New Revision: 804280

URL: http://svn.apache.org/viewvc?rev=804280&view=rev
Log:
SLING-1078 - entity IDs and RegisteredResourceList added

Added:
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java
      - copied, changed from r804107, 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
   (with props)
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
   (with props)
Removed:
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
Modified:
    sling/trunk/installer/osgi/installer/pom.xml
    
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/tasks/BundleInstallRemoveTask.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/TaskUtilities.java
    
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
    
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java

Modified: sling/trunk/installer/osgi/installer/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/pom.xml?rev=804280&r1=804279&r2=804280&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/pom.xml (original)
+++ sling/trunk/installer/osgi/installer/pom.xml Fri Aug 14 16:22:45 2009
@@ -42,27 +42,68 @@
     
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/installer/osgi/installer</developerConnection>
     <url>http://svn.apache.org/viewvc/sling/installer/osgi/installer</url>
   </scm>
-  
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
-        <configuration>
-            <instructions>
-                <Bundle-Activator>
-                    org.apache.sling.osgi.installer.impl.Activator
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-Activator>
+                                                       
org.apache.sling.osgi.installer.impl.Activator
                 </Bundle-Activator>
-                <Export-Package>
-                    org.apache.sling.osgi.installer
+                                               <Export-Package>
+                                                       
org.apache.sling.osgi.installer
                 </Export-Package>
-                
<Private-Package>org.apache.sling.osgi.installer.impl.*</Private-Package>
-            </instructions>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+                                               
<Private-Package>org.apache.sling.osgi.installer.impl.*</Private-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-surefire-plugin</artifactId>
+                               <configuration>
+                                       <systemProperties>
+                                               <property>
+                                                       
<name>osgi.installer.base.dir</name>
+                                                       
<value>${project.build.directory}</value>
+                                               </property>
+                        <property>
+                            <name>osgi.installer.pom.version</name>
+                            <value>${pom.version}</value>
+                        </property>
+                                       </systemProperties>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <!-- Create dummy test bundles -->
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-jar-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>testbundle-1.0</id>
+                                               <phase>compile</phase>
+                                               <goals>
+                                                       <goal>jar</goal>
+                                               </goals>
+                                               <configuration>
+                                                       
<classifier>testbundle-1.0</classifier>
+                                                       <archive>
+                                                               
<manifestEntries>
+                                                                       
<Manifest-Version>2</Manifest-Version>
+                                                                       
<Bundle-Name>OSGi installer test bundle</Bundle-Name>
+                                                                       
<Bundle-SymbolicName>osgi-installer-testbundle</Bundle-SymbolicName>
+                                                                       
<Bundle-Version>1.0.4</Bundle-Version>
+                                                               
</manifestEntries>
+                                                       </archive>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
   
   <dependencies>
     <dependency>

Copied: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java
 (from r804107, 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java)
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java?p2=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java&p1=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java&r1=804107&r2=804280&rev=804280&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java
 Fri Aug 14 16:22:45 2009
@@ -16,13 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.osgi.installer.impl.tasks;
+package org.apache.sling.osgi.installer.impl;
+
+import org.apache.sling.osgi.installer.impl.tasks.ConfigInstallRemoveTask;
 
 /** Builds configration PIDs out of filenames, examples:
  *      o.a.s.foo.bar.cfg -> pid = o.a.s.foo.bar
  *      o.a.s.foo.bar-a.cfg -> pid = o.a.s.foo.bar, factory pid = a 
  */
-class ConfigurationPid {
+public class ConfigurationPid {
     private final String configPid;
     private final String factoryPid;
 
@@ -68,4 +70,8 @@
     public String getFactoryPid() {
         return factoryPid;
     }
+    
+    public String getCompositePid() {
+        return (factoryPid == null ? "" : factoryPid + ".") + configPid;
+    }
 }

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=804280&r1=804279&r2=804280&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
 Fri Aug 14 16:22:45 2009
@@ -22,7 +22,6 @@
 import java.util.List;
 import java.util.TreeSet;
 
-import org.apache.sling.osgi.installer.impl.tasks.BundleInstallTask;
 import org.osgi.service.log.LogService;
 
 /** Worker thread where all OSGi tasks are executed.
@@ -36,8 +35,8 @@
 class OsgiInstallerThread extends Thread {
     
     private final OsgiInstallerContext ctx;
+    private final RegisteredResourceList registeredResources = new 
RegisteredResourceList();
     private final List<RegisteredResource> newResources = new 
LinkedList<RegisteredResource>();
-    private final List<RegisteredResource> registeredResources = new 
LinkedList<RegisteredResource>();
     private final TreeSet<OsgiInstallerTask> tasks = new 
TreeSet<OsgiInstallerTask>();
     
     OsgiInstallerThread(OsgiInstallerContext ctx) {
@@ -50,9 +49,21 @@
         while(true) {
             // TODO do nothing if nothing to process!
             try {
-                mergeNewResources();
-                computeListOfTasks();
+                // Add new resources to the list
+                synchronized (newResources) {
+                    for(RegisteredResource r : newResources) {
+                        registeredResources.add(r);
+                    }
+                    newResources.clear();
+                }
+                
+                // Compute OSGi tasks based on the list of resources
+                tasks.addAll(registeredResources.getTasks());
+                
+                // Execute all tasks
                 executeTasks();
+                
+                // Wait a bit before next cycle
                 Thread.sleep(250);
             } catch(Exception e) {
                 if(ctx.getLogService() != null) {
@@ -66,21 +77,6 @@
         }
     }
     
-    private void mergeNewResources() {
-        synchronized (newResources) {
-            registeredResources.addAll(newResources);
-            newResources.clear();
-        }
-    }
-    
-    private void computeListOfTasks() {
-        for(RegisteredResource r : registeredResources) {
-            if(r.getResourceType() == RegisteredResource.ResourceType.BUNDLE) {
-                tasks.add(new BundleInstallTask(r));
-            }
-        }
-    }
-    
     void addTaskToCurrentCycle(OsgiInstallerTask t) {
         if(ctx.getLogService() != null) {
             ctx.getLogService().log(LogService.LOG_DEBUG, "adding task to 
current cycle:" + t);

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=804280&r1=804279&r2=804280&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
 Fri Aug 14 16:22:45 2009
@@ -39,11 +39,14 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
 
 import org.apache.sling.osgi.installer.InstallableResource;
 import 
org.apache.sling.osgi.installer.impl.propertyconverter.PropertyConverter;
 import org.apache.sling.osgi.installer.impl.propertyconverter.PropertyValue;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 
 /** A resource that's been registered in the OSGi controller.
  *     Data can be either an InputStream or a Dictionary, and we store
@@ -54,7 +57,9 @@
        private final String url;
        private final String digest;
        private final File dataFile;
+       private final String entity;
        private final Dictionary<String, Object> dictionary;
+       private final Manifest manifest;
        private static long fileNumber;
        
        static enum State {
@@ -75,6 +80,9 @@
     private final ResourceType resourceType;
        
        public static final String DIGEST_TYPE = "MD5";
+    public static final String ENTITY_JAR_PREFIX = "jar:";
+       public static final String ENTITY_BUNDLE_PREFIX = "bundle:";
+       public static final String ENTITY_CONFIG_PREFIX = "config:";
        
        /** Create a RegisteredResource from given data. If the data's extension
         *  maps to a configuration and the data provides an input stream, it is
@@ -98,8 +106,21 @@
                     throw new IllegalArgumentException(
                             "Digest must be supplied for BUNDLE resource type: 
" + input);
                 }
+                manifest = getManifest(getInputStream());
+                String name = null;
+                if(manifest != null) {
+                    name = 
manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+                }
+                if(name == null) {
+                    // not a bundle - use "jar" entity to make it easier to 
find out
+                    entity = ENTITY_JAR_PREFIX + input.getUrl();
+                } else {
+                    entity = ENTITY_BUNDLE_PREFIX + name;
+                }
                } else {
                 dataFile = null;
+                manifest = null;
+                entity = ENTITY_CONFIG_PREFIX + new 
ConfigurationPid(input.getUrl()).getCompositePid();
                 if(input.getInputStream() == null) {
                     // config provided as a Dictionary
                     dictionary = copy(input.getDictionary());
@@ -241,6 +262,10 @@
         return resourceType;
     }
     
+    public Manifest getManifest() {
+        return manifest;
+    }
+    
     static ResourceType computeResourceType(String extension) {
         if(extension.equals("jar")) {
             return ResourceType.BUNDLE;
@@ -248,4 +273,42 @@
             return ResourceType.CONFIG;
         }
     }
+    
+    /** 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. 
+     */
+    public String getEntityId() {
+        return entity;
+    }
+    
+    /** Read the manifest from supplied input stream, which is closed before 
return */
+    static Manifest getManifest(InputStream ins) throws IOException {
+        Manifest result = null;
+
+        JarInputStream jis = null;
+        try {
+            jis = new JarInputStream(ins);
+            result= jis.getManifest();
+
+        } finally {
+
+            // close the jar stream or the inputstream, if the jar
+            // stream is set, we don't need to close the input stream
+            // since closing the jar stream closes the input stream
+            if (jis != null) {
+                try {
+                    jis.close();
+                } catch (IOException ignore) {
+                }
+            } else {
+                try {
+                    ins.close();
+                } catch (IOException ignore) {
+                }
+            }
+        }
+
+        return result;
+    }
 }

Added: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java?rev=804280&view=auto
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
 (added)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
 Fri Aug 14 16:22:45 2009
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.osgi.installer.impl;
+
+import java.util.Comparator;
+
+/** Comparator that defines priorities between RegisteredResources */
+class RegisteredResourceComparator implements Comparator<RegisteredResource >{
+
+    public int compare(RegisteredResource a, RegisteredResource b) {
+        // TODO 
+        return 0;
+    }
+    
+}

Propchange: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java?rev=804280&view=auto
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
 (added)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
 Fri Aug 14 16:22:45 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.osgi.installer.impl;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+
+import org.apache.sling.osgi.installer.impl.tasks.BundleInstallTask;
+
+/** Used by the installer to hold the complete list of RegisteredResources,
+ *  this class is key in defining priorities between resources, making sure
+ *  the latest version of a bundle is installed if several are available, etc.
+ *  
+ *  The storage structure is not really a list, but a Map of sorted lists of
+ *  RegisteredResource. The Map key is the "OSGi entity" that the resources
+ *  represent, for example a given bundle (keyed by symbolic name) or 
+ *  a given config (keyed by pid).
+ *  
+ *  Before it starts executing OSGi tasks, the installer calls the 
+ *  getTasks() method which walks the data structure and uses priority rules
+ *  and the RegisteredResource's desired and actual states to define the set
+ *  of OSGi tasks to execute.
+ *  
+ *  This class is *not* threadsafe, clients must care about that.
+ */
+class RegisteredResourceList {
+    private final Map<String, TreeSet<RegisteredResource>> list = new 
HashMap<String, TreeSet<RegisteredResource>>();
+    
+    /** Add the given resource to this list, at the correct position based
+     *  on the resource's entity ID */
+    void add(RegisteredResource r) {
+        TreeSet<RegisteredResource> t = list.get(r.getEntityId());
+        if(t == null) {
+            t = new TreeSet<RegisteredResource>(new 
RegisteredResourceComparator());
+            list.put(r.getEntityId(), t);
+        }
+        t.add(r);
+    }
+    
+    List<OsgiInstallerTask> getTasks() {
+        final List<OsgiInstallerTask> result = new 
LinkedList<OsgiInstallerTask>();
+        
+        // Walk the list of entities, and create appropriate OSGi tasks for 
each group
+        for(TreeSet<RegisteredResource> group : list.values()) {
+            for(RegisteredResource r : group) {
+                // TODO tasks must be created based on priorities + 
desired/actual states
+                
if(r.getResourceType().equals(RegisteredResource.ResourceType.BUNDLE)) {
+                    result.add(new BundleInstallTask(r));
+                }
+            }
+        }
+        
+        return result;
+    }
+}

Propchange: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java?rev=804280&r1=804279&r2=804280&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallRemoveTask.java
 Fri Aug 14 16:22:45 2009
@@ -87,7 +87,7 @@
                throw new IOException("RegisteredResource does not adapt to an 
InputStream: " + uri);
        }
 
-               final Manifest m = TaskUtilities.getManifest(data);
+               final Manifest m = data.getManifest();
                if(m == null) {
                        throw new IOException("Manifest not found for 
RegisteredResource " + uri);
                }

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java?rev=804280&r1=804279&r2=804280&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
 Fri Aug 14 16:22:45 2009
@@ -21,6 +21,7 @@
 import java.util.Dictionary;
 import java.util.Map;
 
+import org.apache.sling.osgi.installer.impl.ConfigurationPid;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.service.cm.Configuration;
@@ -31,7 +32,7 @@
 
     static final String ALIAS_KEY = "_alias_factory_pid";
     static final String CONFIG_PATH_KEY = "_jcr_config_path";
-    static final String [] CONFIG_EXTENSIONS = { ".cfg", ".properties" };
+    public static final String [] CONFIG_EXTENSIONS = { ".cfg", ".properties" 
};
     
        public ConfigInstallRemoveTask(String uri, RegisteredResource data, 
OsgiInstallerContext ocs) {
                super(uri, data, ocs);

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/TaskUtilities.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/TaskUtilities.java?rev=804280&r1=804279&r2=804280&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/TaskUtilities.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/TaskUtilities.java
 Fri Aug 14 16:22:45 2009
@@ -5,6 +5,7 @@
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
+import org.apache.sling.osgi.installer.impl.ConfigurationPid;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.framework.Bundle;
@@ -51,41 +52,6 @@
        return null;
     }
 
-    /** Read the manifest from the RegisteredResource */
-    static Manifest getManifest(RegisteredResource data) throws IOException {
-       Manifest result = null;
-        InputStream ins = data.getInputStream();
-        if (ins == null) {
-               return null;
-               }
-
-        JarInputStream jis = null;
-        try {
-            jis = new JarInputStream(ins);
-            result= jis.getManifest();
-
-        } finally {
-
-            // close the jar stream or the inputstream, if the jar
-            // stream is set, we don't need to close the input stream
-            // since closing the jar stream closes the input stream
-            if (jis != null) {
-                try {
-                    jis.close();
-                } catch (IOException ignore) {
-                }
-            } else {
-                // ins is never null here
-                try {
-                    ins.close();
-                } catch (IOException ignore) {
-                }
-            }
-        }
-
-        return result;
-    }
-    
     /** Get or create configuration */
     static Configuration getConfiguration(ConfigurationPid cp, boolean 
createIfNeeded, OsgiInstallerContext ocs)
     throws IOException, InvalidSyntaxException

Modified: 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java?rev=804280&r1=804279&r2=804280&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.java
 Fri Aug 14 16:22:45 2009
@@ -25,6 +25,8 @@
 import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -35,6 +37,11 @@
 
 public class RegisteredResourceTest {
        
+    static File getTestBundle(String name) {
+        return new File(System.getProperty("osgi.installer.base.dir"),
+                "org.apache.sling.osgi.installer-" + 
System.getProperty("osgi.installer.pom.version") + "-" + name);
+    }
+    
        @org.junit.Test public void testStreamIsClosed() throws Exception {
                final String data = "some data";
                
@@ -70,6 +77,7 @@
             assertNotNull("BUNDLE resource provides an InputStream", rs);
             rs.close();
             assertNull("BUNDLE resource does not provide a Dictionary", 
r.getDictionary());
+            assertEquals("RegisteredResource entity ID must match", 
"jar:1.jar", r.getEntityId());
         }
         
         {
@@ -162,4 +170,19 @@
                 r2.getDigest()
         );
     }
+    
+    @org.junit.Test public void testBundleManifest() throws Exception {
+        final File f = getTestBundle("testbundle-1.0.jar");
+        final InstallableResource i = new 
InstallableResource(f.getAbsolutePath(), new FileInputStream(f), f.getName());
+        final RegisteredResource r = new LocalFileRegisteredResource(i);
+        assertNotNull("RegisteredResource must have manifest", 
r.getManifest());
+        assertEquals("RegisteredResource entity ID must match", 
"bundle:osgi-installer-testbundle", r.getEntityId());
+    }
+    
+    @org.junit.Test public void testConfigEntity() throws Exception {
+        final InstallableResource i = new 
InstallableResource("/foo/someconfig", new Hashtable<String, Object>());
+        final RegisteredResource r = new LocalFileRegisteredResource(i);
+        assertNull("RegisteredResource must not have manifest", 
r.getManifest());
+        assertEquals("RegisteredResource entity ID must match", 
"config:someconfig", r.getEntityId());
+    }
 }
\ No newline at end of file

Modified: 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java?rev=804280&r1=804279&r2=804280&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
 Fri Aug 14 16:22:45 2009
@@ -20,6 +20,8 @@
 
 import static org.junit.Assert.assertEquals;
 
+import org.apache.sling.osgi.installer.impl.ConfigurationPid;
+
 public class ConfigurationPidTest {
 
     private void assertPid(String path, String expectedPid, String 
expectedFactoryPid) {


Reply via email to