incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r890897 - in /sling/trunk/installer/osgi/installer/src: main/java/org/apache/sling/osgi/installer/impl/ main/java/org/apache/sling/osgi/installer/impl/tasks/ test/java/org/apache/sling/osgi/installer/impl/
Date Tue, 15 Dec 2009 17:33:08 GMT
Author: bdelacretaz
Date: Tue Dec 15 17:33:07 2009
New Revision: 890897

URL: http://svn.apache.org/viewvc?rev=890897&view=rev
Log:
SLING-1241 - RegisteredResourceImpl stores file number instead of full path

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/BundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/LocalFileRegisteredResource.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceTest.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=890897&r1=890896&r2=890897&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 Dec 15 17:33:07 2009
@@ -371,7 +371,7 @@
             }
             for(RegisteredResource r : toDelete) {
                 group.remove(r);
-                r.cleanup();
+                r.cleanup(ctx.getBundleContext());
                 if(ctx.getLogService() != null) {
                     ctx.getLogService().log(LogService.LOG_DEBUG,
                             "Removing RegisteredResource from list, not installable and has
been processed: " + r);

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=890897&r1=890896&r2=890897&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 Dec 15 17:33:07 2009
@@ -23,6 +23,8 @@
 import java.util.Dictionary;
 import java.util.Map;
 
+import org.osgi.framework.BundleContext;
+
 /** A resource that's been registered in the OSGi controller.
  * 	Data can be either an InputStream or a Dictionary, and we store
  *  it locally to avoid holding up to classes or data from our 
@@ -40,9 +42,9 @@
 	public static final String ENTITY_BUNDLE_PREFIX = "bundle:";
 	public static final String ENTITY_CONFIG_PREFIX = "config:";
 	
-	void cleanup();
+	void cleanup(BundleContext bc);
 	String getURL();
-	InputStream getInputStream() throws IOException;
+	InputStream getInputStream(BundleContext bc) throws IOException;
 	Dictionary<String, Object> getDictionary();
 	String getDigest();
 	String getUrl();

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=890897&r1=890896&r2=890897&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 Dec 15 17:33:07 2009
@@ -51,16 +51,15 @@
  *  clients, in case those disappear while we're installing stuff. 
  */
 public class RegisteredResourceImpl implements RegisteredResource, Serializable { 
-    private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 2L;
 	private final String url;
 	private final String urlScheme;
 	private final String digest;
-	private final File dataFile;
 	private final String entity;
 	private final Dictionary<String, Object> dictionary;
 	private final Map<String, Object> attributes = new HashMap<String, Object>();
-	private static long fileNumber;
 	private boolean installable = true;
+	private final boolean hasDataFile;
 	private final int priority;
     private final long serialNumber;
     private static long serialNumberCounter = System.currentTimeMillis();
@@ -98,10 +97,10 @@
                     throw new IllegalArgumentException("InputStream is required for BUNDLE
resource type: " + input);
                 }
                 dictionary = null;
-                dataFile = getDataFile(ctx);
-                copyToLocalStorage(input.getInputStream(), dataFile);
+                copyToLocalStorage(input.getInputStream(), getDataFile(ctx));
+                hasDataFile = true;
                 digest = input.getDigest();
-                setAttributesFromManifest();
+                setAttributesFromManifest(ctx);
                 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
@@ -110,7 +109,7 @@
                     entity = ENTITY_BUNDLE_PREFIX + name;
                 }
     		} else {
-                dataFile = null;
+                hasDataFile = false;
                 final ConfigurationPid pid = new ConfigurationPid(input.getUrl());
                 entity = ENTITY_CONFIG_PREFIX + pid.getCompositePid();
                 attributes.put(CONFIG_PID_ATTRIBUTE, pid);
@@ -140,16 +139,14 @@
 	    return getClass().getSimpleName() + " " + url + ", digest=" + digest + ", serialNumber="
+ serialNumber;
 	}
 	
-	protected File getDataFile(BundleContext ctx) throws IOException {
-		String filename = null;
-		synchronized (getClass()) {
-			filename = getClass().getSimpleName() + "." + fileNumber++;
-		}
+	protected File getDataFile(BundleContext ctx) {
+		final String filename = getClass().getSimpleName() + "." + serialNumber;
 		return ctx.getDataFile(filename);
 	}
 	
-	public void cleanup() {
-		if(dataFile != null && dataFile.exists()) {
+	public void cleanup(BundleContext bc) {
+	    final File dataFile = getDataFile(bc);
+		if(dataFile.exists()) {
 			dataFile.delete();
 		}
 	}
@@ -158,11 +155,14 @@
 		return url;
 	}
 	
-	public InputStream getInputStream() throws IOException {
-		if(dataFile == null) {
-			return null;
-		}
-		return new BufferedInputStream(new FileInputStream(dataFile));
+	public InputStream getInputStream(BundleContext bc) throws IOException {
+	    if(hasDataFile) {
+	        final File dataFile = getDataFile(bc);
+	        if(dataFile.exists()) {
+	            return new BufferedInputStream(new FileInputStream(dataFile));
+	        }
+	    }
+        return  null;
 	}
 	
 	public Dictionary<String, Object> getDictionary() {
@@ -286,8 +286,8 @@
         return result;
     }
     
-    private void setAttributesFromManifest() throws IOException {
-    	final Manifest m = getManifest(getInputStream());
+    private void setAttributesFromManifest(BundleContext bc) throws IOException {
+    	final Manifest m = getManifest(getInputStream(bc));
     	if(m == null) {
             throw new IOException("Cannot get manifest of bundle resource");
     	}

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=890897&r1=890896&r2=890897&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 Dec 15 17:33:07 2009
@@ -42,7 +42,7 @@
     }
     
     public void execute(OsgiInstallerContext ctx) throws Exception {
-        final Bundle b = ctx.getBundleContext().installBundle(resource.getUrl(), resource.getInputStream());
+        final Bundle b = ctx.getBundleContext().installBundle(resource.getUrl(), resource.getInputStream(ctx.getBundleContext()));
         final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
         ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
         logExecution(ctx);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java?rev=890897&r1=890896&r2=890897&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
Tue Dec 15 17:33:07 2009
@@ -92,7 +92,7 @@
             ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
         }
         b.stop();
-        b.update(resource.getInputStream());
+        b.update(resource.getInputStream(ctx.getBundleContext()));
         ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
         ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask());
         if(ctx.getLogService() != null) {

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/LocalFileRegisteredResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/LocalFileRegisteredResource.java?rev=890897&r1=890896&r2=890897&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/LocalFileRegisteredResource.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/LocalFileRegisteredResource.java
Tue Dec 15 17:33:07 2009
@@ -33,9 +33,13 @@
 	}
 	
 	@Override
-	protected File getDataFile(BundleContext ctx) throws IOException {
+	protected File getDataFile(BundleContext ctx) {
 		if(storage == null) {
-			storage = File.createTempFile(getClass().getName(), "test");
+	        try {
+	            storage = File.createTempFile(getClass().getName(), "test");
+	        } catch(IOException ioe) {
+	            throw new Error("IOException on file creation", ioe);
+	        }
 			storage.deleteOnExit();
 		}
 		return storage;

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=890897&r1=890896&r2=890897&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 Dec 15 17:33:07 2009
@@ -26,6 +26,7 @@
 import java.util.Map;
 
 import org.apache.sling.osgi.installer.InstallableResource;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 
 /** Mock RegisteredResource that simulates a bundle */
@@ -75,7 +76,7 @@
         ;
 	}
 	
-	public void cleanup() {
+	public void cleanup(BundleContext ctx) {
 	}
 
 	public Map<String, Object> getAttributes() {
@@ -94,7 +95,7 @@
 		return null;
 	}
 
-	public InputStream getInputStream() throws IOException {
+	public InputStream getInputStream(BundleContext ctx) throws IOException {
 		return null;
 	}
 

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=890897&r1=890896&r2=890897&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
Tue Dec 15 17:33:07 2009
@@ -77,7 +77,7 @@
             final RegisteredResource r = new LocalFileRegisteredResource(new InstallableResource("test:1.jar",
s, "some digest"));
             assertEquals(".jar URL creates a BUNDLE resource", 
                     RegisteredResource.ResourceType.BUNDLE, r.getResourceType());
-            final InputStream rs = r.getInputStream();
+            final InputStream rs = r.getInputStream(null);
             assertNotNull("BUNDLE resource provides an InputStream", rs);
             rs.close();
             assertNull("BUNDLE resource does not provide a Dictionary", r.getDictionary());
@@ -89,7 +89,7 @@
             final RegisteredResource r = new LocalFileRegisteredResource(new InstallableResource("test:1.properties",
s, "digest1"));
             assertEquals(".properties URL creates a CONFIG resource", 
                     RegisteredResource.ResourceType.CONFIG, r.getResourceType());
-            final InputStream rs = r.getInputStream();
+            final InputStream rs = r.getInputStream(null);
             assertNull("CONFIG resource does not provide an InputStream", rs);
             final Dictionary<String, Object> d = r.getDictionary();
             assertNotNull("CONFIG resource provides a Dictionary", d);
@@ -104,7 +104,7 @@
             final RegisteredResource r = new LocalFileRegisteredResource(new InstallableResource("test:1",
data));
             assertEquals("No-extension URL with Dictionary creates a CONFIG resource", 
                     RegisteredResource.ResourceType.CONFIG, r.getResourceType());
-            final InputStream rs = r.getInputStream();
+            final InputStream rs = r.getInputStream(null);
             assertNull("CONFIG resource does not provide an InputStream", rs);
             final Dictionary<String, Object> d = r.getDictionary();
             assertNotNull("CONFIG resource provides a Dictionary", d);



Mime
View raw message