Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 22112 invoked from network); 19 Jan 2010 13:01:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Jan 2010 13:01:11 -0000 Received: (qmail 5182 invoked by uid 500); 19 Jan 2010 13:01:11 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 5125 invoked by uid 500); 19 Jan 2010 13:01:11 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 5116 invoked by uid 99); 19 Jan 2010 13:01:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2010 13:01:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2010 13:01:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 971EE2388A16; Tue, 19 Jan 2010 13:00:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r900757 - in /sling/trunk/installer: jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ osgi/installer/src/main/java/org/apache/sling/osgi/installer/ osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ osgi/in... Date: Tue, 19 Jan 2010 13:00:38 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100119130038.971EE2388A16@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Tue Jan 19 13:00:37 2010 New Revision: 900757 URL: http://svn.apache.org/viewvc?rev=900757&view=rev Log: Clean up code - no functional changes. Modified: sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilterTest.java sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MiscUtil.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/InstallableResourceTest.java Modified: sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilterTest.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilterTest.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilterTest.java (original) +++ sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilterTest.java Tue Jan 19 13:00:37 2010 @@ -18,10 +18,11 @@ */ package org.apache.sling.jcr.jcrinstall.impl; -import org.junit.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; public class FolderNameFilterTest { public static final String DEFAULT_REGEXP = ".*/install$"; @@ -55,14 +56,14 @@ assertEquals(200, f.getRootPriority("/b/foo")); } } - + @Test public void testNoRunMode() { final FolderNameFilter f = new FolderNameFilter(ROOTS, DEFAULT_REGEXP, new MockRunMode(new String[0])); assertTrue("Test 1", f.getPriority("/libs/install") > 0); assertFalse("Test 2", f.getPriority("/libs/install.bar") > 0); } - + @Test public void testSingleMode() { final String [] m = { "dev" }; @@ -75,7 +76,7 @@ assertFalse("Test 6", f.getPriority("/libs/install.dev.bar") > 0); assertFalse("Test 7", f.getPriority("/libs/install.bar.dev") > 0); } - + @Test public void testThreeModes() { final String [] m = { "dev", "web", "staging" }; @@ -94,36 +95,36 @@ assertFalse("Test 12",f.getPriority("/libs/install.dev.bar") > 0); assertFalse("Test 13",f.getPriority("/libs/install.bar.dev") > 0); } - + @Test public void testRootPriorities() { final String [] m = { "dev" }; final FolderNameFilter f = new FolderNameFilter(ROOTS, DEFAULT_REGEXP, new MockRunMode(m)); - assertEquals("/libs root", new Integer(100), f.getPriority("/libs/install")); - assertEquals("/apps root", new Integer(200), f.getPriority("/apps/install")); + assertEquals("/libs root", new Integer(100), (Integer)f.getPriority("/libs/install")); + assertEquals("/apps root", new Integer(200), (Integer)f.getPriority("/apps/install")); } - + @Test public void testRunModePriorities() { final String [] m = { "dev", "prod", "staging" }; final FolderNameFilter f = new FolderNameFilter(ROOTS, DEFAULT_REGEXP, new MockRunMode(m)); - assertEquals("Matches no runmode", new Integer(100), f.getPriority("/libs/install")); - assertEquals("Matches dev runmode", new Integer(201), f.getPriority("/apps/install.dev")); - assertEquals("Matches staging runmode", new Integer(201), f.getPriority("/apps/install.staging")); - assertEquals("Matches three runmodes (A)", new Integer(203), f.getPriority("/apps/install.dev.staging.prod")); - assertEquals("Matches three runmodes (B)", new Integer(203), f.getPriority("/apps/install.dev.prod.staging")); - assertEquals("Matches three runmodes (C)", new Integer(103), f.getPriority("/libs/install.dev.prod.staging")); + assertEquals("Matches no runmode", new Integer(100), (Integer)f.getPriority("/libs/install")); + assertEquals("Matches dev runmode", new Integer(201), (Integer)f.getPriority("/apps/install.dev")); + assertEquals("Matches staging runmode", new Integer(201), (Integer)f.getPriority("/apps/install.staging")); + assertEquals("Matches three runmodes (A)", new Integer(203), (Integer)f.getPriority("/apps/install.dev.staging.prod")); + assertEquals("Matches three runmodes (B)", new Integer(203), (Integer)f.getPriority("/apps/install.dev.prod.staging")); + assertEquals("Matches three runmodes (C)", new Integer(103), (Integer)f.getPriority("/libs/install.dev.prod.staging")); } - + @Test public void testDotsInPath() { final String [] m = { "dev", "prod", "staging" }; final FolderNameFilter f = new FolderNameFilter(ROOTS, DEFAULT_REGEXP, new MockRunMode(m)); - assertEquals("Matches no runmode", new Integer(100), f.getPriority("/libs/foo.bar/install")); - assertEquals("Matches dev runmode", new Integer(201), f.getPriority("/apps/foo.bar/install.dev")); - assertEquals("Matches staging runmode", new Integer(201), f.getPriority("/apps/foo.bar/install.staging")); - assertEquals("Matches three runmodes (A)", new Integer(203), f.getPriority("/apps/foo.bar/install.dev.staging.prod")); - assertEquals("Matches three runmodes (B)", new Integer(203), f.getPriority("/apps/foo.bar/install.dev.prod.staging")); - assertEquals("Matches three runmodes (C)", new Integer(103), f.getPriority("/libs/foo.bar/install.dev.prod.staging")); + assertEquals("Matches no runmode", new Integer(100), (Integer)f.getPriority("/libs/foo.bar/install")); + assertEquals("Matches dev runmode", new Integer(201), (Integer)f.getPriority("/apps/foo.bar/install.dev")); + assertEquals("Matches staging runmode", new Integer(201), (Integer)f.getPriority("/apps/foo.bar/install.staging")); + assertEquals("Matches three runmodes (A)", new Integer(203), (Integer)f.getPriority("/apps/foo.bar/install.dev.staging.prod")); + assertEquals("Matches three runmodes (B)", new Integer(203), (Integer)f.getPriority("/apps/foo.bar/install.dev.prod.staging")); + assertEquals("Matches three runmodes (C)", new Integer(103), (Integer)f.getPriority("/libs/foo.bar/install.dev.prod.staging")); } } Modified: sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MiscUtil.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MiscUtil.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MiscUtil.java (original) +++ sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MiscUtil.java Tue Jan 19 13:00:37 2010 @@ -40,10 +40,10 @@ class MiscUtil { static final Mockery mockery = new Mockery(); - + public static String SEARCH_PATHS [] = { "/libs/", "/apps/" }; public static String RUN_MODES [] = { "dev", "staging" }; - + static class MockResourceResolver implements ResourceResolver { public Iterator findResources(String arg0, String arg1) { @@ -70,6 +70,16 @@ return null; } + public String map(HttpServletRequest request, String resourcePath) { + // TODO Auto-generated method stub + return null; + } + + public Resource resolve(HttpServletRequest request, String absPath) { + // TODO Auto-generated method stub + return null; + } + public Iterator> queryResources(String arg0, String arg1) { return null; @@ -87,15 +97,15 @@ return null; } } - + /** Set a non-public Field */ static void setField(Object target, String fieldName, Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Field f = target.getClass().getDeclaredField(fieldName); f.setAccessible(true); f.set(target, value); } - - /** Return a JcrInstaller setup for testing */ + + /** Return a JcrInstaller setup for testing */ static JcrInstaller getJcrInstaller(SlingRepository repository, OsgiInstaller osgiInstaller) throws Exception { final JcrInstaller installer = new JcrInstaller(); setField(installer, "repository", repository); @@ -105,12 +115,12 @@ installer.activate(getMockComponentContext()); return installer; } - + static ComponentContext getMockComponentContext() { // Setup fake ComponentContext to allow JcrInstaller to start final ComponentContext cc = mockery.mock(ComponentContext.class); final BundleContext bc = mockery.mock(BundleContext.class); - + final Dictionary emptyDict = new Hashtable(); mockery.checking(new Expectations() {{ allowing(cc).getProperties(); @@ -122,7 +132,7 @@ }}); return cc; } - + static private void waitForCycles(JcrInstaller installer, long initialCycleCount, int expectedCycles, long timeoutMsec) throws Exception { final long endTime = System.currentTimeMillis() + timeoutMsec; long cycles = 0; @@ -132,9 +142,9 @@ return; } } - throw new Exception("did not get " + expectedCycles + " installer cycles in " + timeoutMsec + " msec, got " + cycles); + throw new Exception("did not get " + expectedCycles + " installer cycles in " + timeoutMsec + " msec, got " + cycles); } - + /** Get the WatchedFolders of supplied JcrInstaller */ @SuppressWarnings({ "unchecked"}) static Collection getWatchedFolders(JcrInstaller installer) throws Exception { @@ -142,11 +152,11 @@ f.setAccessible(true); return (Collection)f.get(installer); } - - /** Wait long enough for all changes in content to be processed by JcrInstaller */ + + /** Wait long enough for all changes in content to be processed by JcrInstaller */ static void waitAfterContentChanges(EventHelper eventHelper, JcrInstaller installer) throws Exception { final long startCycles = installer.getCounters()[JcrInstaller.RUN_LOOP_COUNTER]; - + // First wait for all JCR events to be delivered eventHelper.waitForEvents(5000L); // RescanTimer causes a SCAN_DELAY_MSEC wait after JCR events are received @@ -154,7 +164,7 @@ // And wait for a few JcrInstaller run cycles MiscUtil.waitForCycles(installer, startCycles, 2, 10000L); } - + /** Wait until installer thread exits */ static void waitForInstallerThread(JcrInstaller installer, long timeoutMsec) throws Exception { final long endTime = System.currentTimeMillis() + timeoutMsec; @@ -163,6 +173,6 @@ return; } } - throw new Exception("JcrInstaller thread did not signal its end (timeout=" + timeoutMsec + " msec)"); + throw new Exception("JcrInstaller thread did not signal its end (timeout=" + timeoutMsec + " msec)"); } } \ No newline at end of file Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java Tue Jan 19 13:00:37 2010 @@ -33,7 +33,7 @@ /** A piece of data that can be installed by the OSGi controller. * Wraps either a Dictionary or an InputStream. - * Extension is used to decide which type of data (bundle, config, etc.). + * Extension is used to decide which type of data (bundle, config, etc.). */ public class InstallableResource { private final String url; @@ -44,10 +44,10 @@ private int priority; private final boolean empty; public static final String DIGEST_TYPE = "MD5"; - + /** Default resource priority */ public static final int DEFAULT_PRIORITY = 100; - + /** Create an empty data object, used when removing resources */ public InstallableResource(String url) { this.url = url; @@ -58,15 +58,15 @@ this.priority = DEFAULT_PRIORITY; this.empty = true; } - - /** Create a data object that wraps an InputStream - * @param url unique URL of the supplied data, must start with the scheme used + + /** Create a data object that wraps an InputStream + * @param url unique URL of the supplied data, must start with the scheme used * {@link OsgiInstaller#registerResources} call * @param is the resource contents * @param digest must be supplied by client. Does not need to be an actual digest * of the contents, but must change if the contents change. Having this supplied * by the client avoids having to compute real digests to find out if a resource - * has changed, which can be expensive. + * has changed, which can be expensive. */ public InstallableResource(String url, InputStream is, String digest) { this.url = url; @@ -77,15 +77,14 @@ this.priority = DEFAULT_PRIORITY; this.empty = false; } - + /** Create a data object that wraps a Dictionary. Digest will be computed - * by the installer in this case, as configuration dictionaries are + * by the installer in this case, as configuration dictionaries are * usually small so computing a real digest to find out if they changed * is ok. - * - * @param url unique URL of the supplied data, must start with the scheme used + * + * @param url unique URL of the supplied data, must start with the scheme used * {@link OsgiInstaller#registerResources} call - * @param is the resource contents */ public InstallableResource(String url, Dictionary d) { this.url = url; @@ -105,15 +104,15 @@ public String toString() { return getClass().getSimpleName() + ", priority=" + priority + ", url=" + url; } - - /** Compute the extension */ + + /** Compute the extension */ private static String getExtension(String url) { final int pos = url.lastIndexOf('.'); return (pos < 0 ? "" : url.substring(pos+1)); } - + /** Return this data's URL. It is opaque for the {@link OsgiInstaller} - * but the scheme must be the one used in the + * but the scheme must be the one used in the * {@link OsgiInstaller#registerResources} call. */ public String getUrl() { @@ -138,13 +137,13 @@ } /** Return this resource's digest. Not necessarily an actual md5 or other digest of the - * data, can be any string that changes if the data changes. + * data, can be any string that changes if the data changes. */ public String getDigest() { return digest; } - /** Return the priority of this resource. Priorities are used to decide which + /** Return the priority of this resource. Priorities are used to decide which * resource to install when several are registered for the same OSGi entity * (bundle, config, etc.) */ @@ -156,7 +155,7 @@ public void setPriority(int priority) { this.priority = priority; } - + /** convert digest to readable string (http://www.javalobby.org/java/forums/t84420.html) */ public static String digestToString(MessageDigest d) { final BigInteger bigInt = new BigInteger(1, d.digest()); @@ -167,13 +166,13 @@ public static String computeDigest(Dictionary data) throws IOException, NoSuchAlgorithmException { return computeDigest(data, null); } - + /** Digest is needed to detect changes in data, and must not depend on dictionary ordering */ public static String computeDigest(Dictionary data, Set keysToIgnore) throws IOException, NoSuchAlgorithmException { final MessageDigest d = MessageDigest.getInstance(DIGEST_TYPE); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(bos); - + final SortedSet sortedKeys = new TreeSet(); if(data != null) { for(Enumeration e = data.keys(); e.hasMoreElements(); ) { @@ -187,12 +186,12 @@ oos.writeObject(key); oos.writeObject(data.get(key)); } - + bos.flush(); d.update(bos.toByteArray()); return digestToString(d); } - + public boolean isEmpty() { return empty; } Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java Tue Jan 19 13:00:37 2010 @@ -18,69 +18,68 @@ */ package org.apache.sling.osgi.installer; -import java.io.IOException; import java.util.Collection; /** OSGi Service that installs/updates/removes InstallableData - * in the OSGi framework. - * - * The client can register a number of such resources, and the - * installer decides based on the resource weights, bundle version + * in the OSGi framework. + * + * The client can register a number of such resources, and the + * installer decides based on the resource weights, bundle version * numbers, etc. which ones are actually installed. * - * An InstallableResource can be a bundle, a configuration, and later - * we might support deployment packages as well. + * An InstallableResource can be a bundle, a configuration, and later + * we might support deployment packages as well. */ public interface OsgiInstaller { - + /** Provide the installer with the complete list of installable * resources for a given client. - * - * Client must call this at startup and/or when the installer + * + * Client must call this at startup and/or when the installer * service becomes available. The installer stores the list of * previously registered/added resources, compares with the new * list and removes resources that have disappeared. - * + * * Invalid resources are ignored. - * + * * @param data the list of available resources * @param urlScheme identifies the client. All URLs of the supplied data * must use this scheme */ void registerResources(Collection data, String urlScheme); - + /** Inform the installer that a resource is available for installation. * also called if the resource has been modified since it was registered. * Invalid resources are ignored. */ void addResource(InstallableResource r); - - /** Inform the installer that a resource is no longer available + + /** Inform the installer that a resource is no longer available * @param r an empty InstallableResource, isEmpty() must return true */ void removeResource(InstallableResource r); - + /** Return counters used for statistics, console display, testing, etc. */ long [] getCounters(); - + /** Counter index: number of OSGi tasks executed */ int OSGI_TASKS_COUNTER = 0; - + /** Counter index: number of installer cycles */ int INSTALLER_CYCLES_COUNTER = 1; - + /** Counter index: number of currently registered resources */ int REGISTERED_RESOURCES_COUNTER = 2; - - /** Counter index: number of currently registered resource groups + + /** Counter index: number of currently registered resource groups * of resources having the same OSGi entity ID */ int REGISTERED_GROUPS_COUNTER = 3; - + /** Counter index: is worker thread idle? (not really a counter: 1 means true) */ int WORKER_THREAD_IS_IDLE_COUNTER = 4; - + /** Counter index: how many times did worker thread become idle */ int WORKER_THREAD_BECOMES_IDLE_COUNTER = 5; - + /** Size of the counters array */ int COUNTERS_SIZE = 6; } \ No newline at end of file Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java Tue Jan 19 13:00:37 2010 @@ -39,39 +39,39 @@ * for snapshot bundles */ private final Map digests = new HashMap(); - + /** Holds the bundle info that we need, makes it easier to test - * without an OSGi framework */ + * without an OSGi framework */ static class BundleInfo { final String symbolicName; final Version version; final int state; - + BundleInfo(String symbolicName, Version version, int state) { this.symbolicName = symbolicName; this.version = version; this.state = state; } - + BundleInfo(Bundle b) { this.symbolicName = b.getSymbolicName(); this.version = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION)); this.state = b.getState(); } } - + /** Create tasks for a set of RegisteredResource that all represent the same bundle. * Selects the bundle with the highest priority (i.e. the first one in the group that * has desired state == active, and generates the appropriate OSGi tasks to - * reach this state. + * reach this state. */ public void createTasks(OsgiInstallerContext ctx, SortedSet resources, SortedSet tasks) throws IOException { - + // Find the bundle that must be active: the resources collection is ordered according // to priorities, so we just need to find the first one that is installable RegisteredResource toActivate = null; for(RegisteredResource r : resources) { - if(toActivate == null && r.isInstallable()) { + if (r.isInstallable()) { toActivate = r; break; } @@ -79,25 +79,25 @@ RegisteredResource toUpdate = null; String digestToSave = null; - final RegisteredResource firstResource = resources.first(); - final String symbolicName = firstResource == null ? null : + final RegisteredResource firstResource = resources.first(); + final String symbolicName = firstResource == null ? null : (String)firstResource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); - + if(toActivate == null) { // None of our resources are installable, remove corresponding bundle if present // and if we installed it if(getBundleInfo(ctx, resources.first()) != null) { if(ctx.getInstalledBundleVersion(symbolicName) == null) { if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_INFO, - "Bundle " + symbolicName + ctx.getLogService().log(LogService.LOG_INFO, + "Bundle " + symbolicName + " was not installed by this module, not removed"); } } else { tasks.add(new BundleRemoveTask(resources.first())); } } - + } else { final BundleInfo info = getBundleInfo(ctx, toActivate); final Version newVersion = new Version((String)toActivate.getAttributes().get(Constants.BUNDLE_VERSION)); @@ -107,7 +107,7 @@ tasks.add(new BundleInstallTask(toActivate)); digestToSave = toActivate.getDigest(); } else { - final int compare = info.version.compareTo(newVersion); + final int compare = info.version.compareTo(newVersion); if(compare < 0) { // installed version is lower -> update toUpdate = toActivate; @@ -118,14 +118,14 @@ if(info.version.toString().equals(installedVersion)) { toUpdate = toActivate; if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_INFO, - "Bundle " + info.symbolicName + " " + installedVersion + ctx.getLogService().log(LogService.LOG_INFO, + "Bundle " + info.symbolicName + " " + installedVersion + " was installed by this module, downgrading to " + newVersion); } } else { if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_INFO, - "Bundle " + info.symbolicName + " " + installedVersion + ctx.getLogService().log(LogService.LOG_INFO, + "Bundle " + info.symbolicName + " " + installedVersion + " was not installed by this module, not downgraded"); } } @@ -141,20 +141,20 @@ final String previousDigest = digests.get(symbolicName); if(toUpdate.getDigest().equals(previousDigest)) { if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_DEBUG, + ctx.getLogService().log(LogService.LOG_DEBUG, "Ignoring update of " + toUpdate + ", digest didn't change"); } digestToSave = previousDigest; } else { if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_DEBUG, + ctx.getLogService().log(LogService.LOG_DEBUG, "Scheduling update of " + toUpdate + ", digest has changed"); } tasks.add(new BundleUpdateTask(toUpdate)); digestToSave = toUpdate.getDigest(); } } - + if(digestToSave == null) { if(symbolicName != null) { digests.remove(symbolicName); Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java Tue Jan 19 13:00:37 2010 @@ -31,21 +31,21 @@ /** Store digests of the installed configs, keyed by config pid */ private final Map digests = new HashMap(); - + /** Create tasks for a set of RegisteredResource that all represent the same config PID. */ public void createTasks(OsgiInstallerContext ctx, SortedSet resources, SortedSet tasks) { - + // Find the config that must be active: the resources collection is ordered according // to priorities, so we just need to find the first one that is installable RegisteredResource toActivate = null; for(RegisteredResource r : resources) { - if(toActivate == null && r.isInstallable()) { + if (r.isInstallable()) { toActivate = r; break; } } - + if(toActivate == null) { // None of our resources are installable, remove corresponding config // (task simply does nothing if config does not exist) @@ -57,19 +57,19 @@ final String previousDigest = digests.get(key); if(toActivate.getDigest().equals(previousDigest)) { if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_DEBUG, "Configuration (" + key+ ") already installed, ignored: " + toActivate); + ctx.getLogService().log(LogService.LOG_DEBUG, "Configuration (" + key+ ") already installed, ignored: " + toActivate); } } else { tasks.add(new ConfigInstallTask(toActivate)); digests.put(key, toActivate.getDigest()); if(ctx.getLogService() != null) { - ctx.getLogService().log(LogService.LOG_DEBUG, + ctx.getLogService().log(LogService.LOG_DEBUG, "Scheduling update/install of config " + toActivate + ", digest has changed or was absent"); } } } } - + private String getDigestKey(RegisteredResource r) { final ConfigurationPid cp = (ConfigurationPid)r.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE); if(cp == null) { Modified: 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=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java Tue Jan 19 13:00:37 2010 @@ -36,7 +36,7 @@ public int compare(RegisteredResource a, RegisteredResource b) { final boolean aBundle = a.getResourceType() == RegisteredResource.ResourceType.BUNDLE; final boolean bBundle = b.getResourceType() == RegisteredResource.ResourceType.BUNDLE; - + if(aBundle && bBundle) { return compareBundles(a, b); } else if(!aBundle && !bBundle){ @@ -47,30 +47,28 @@ return -1; } } - + int compareBundles(RegisteredResource a, RegisteredResource b) { boolean isSnapshot = false; int result = 0; - + // Order first by symbolic name final String nameA = (String)a.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); final String nameB = (String)b.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); if(nameA != null && nameB != null) { result = nameA.compareTo(nameB); } - + // Then by version if(result == 0) { final Version va = new Version((String)a.getAttributes().get(Constants.BUNDLE_VERSION)); final Version vb = new Version((String)b.getAttributes().get(Constants.BUNDLE_VERSION)); - isSnapshot = va!= null && va.toString().contains(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER); - if(va != null && vb != null) { - // higher version has more priority, must come first so invert comparison - result = vb.compareTo(va); - } + isSnapshot = va.toString().contains(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER); + // higher version has more priority, must come first so invert comparison + result = vb.compareTo(va); } - + // Then by priority, higher values first if(result == 0) { if(a.getPriority() < b.getPriority()) { @@ -79,7 +77,7 @@ result = -1; } } - + if(result == 0 && isSnapshot) { // For snapshots, compare serial numbers so that snapshots registered // later get priority @@ -89,20 +87,20 @@ result = -1; } } - + return result; } - + int compareConfig(RegisteredResource a, RegisteredResource b) { int result = 0; - + // First compare by pid final ConfigurationPid pA = (ConfigurationPid)a.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE); final ConfigurationPid pB = (ConfigurationPid)b.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE); if(pA != null && pA.getCompositePid() != null && pB != null && pB.getCompositePid() != null) { result = pA.getCompositePid().compareTo(pB.getCompositePid()); } - + // Then by priority, higher values first if(result == 0) { if(a.getPriority() < b.getPriority()) { @@ -111,7 +109,7 @@ result = -1; } } - + return result; } } 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=900757&r1=900756&r2=900757&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 Jan 19 13:00:37 2010 @@ -47,10 +47,10 @@ /** 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 - * clients, in case those disappear while we're installing stuff. + * it locally to avoid holding up to classes or data from our + * clients, in case those disappear while we're installing stuff. */ -public class RegisteredResourceImpl implements RegisteredResource, Serializable { +public class RegisteredResourceImpl implements RegisteredResource, Serializable { private static final long serialVersionUID = 2L; private final String url; private final String urlScheme; @@ -63,35 +63,35 @@ private final int priority; private final long serialNumber; private static long serialNumberCounter = System.currentTimeMillis(); - + static enum ResourceType { BUNDLE, CONFIG } - + private final RegisteredResource.ResourceType resourceType; - + 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 - * converted to a Dictionary + * converted to a Dictionary */ public RegisteredResourceImpl(BundleContext ctx, InstallableResource input) throws IOException { - + try { url = input.getUrl(); urlScheme = getUrlScheme(url); resourceType = computeResourceType(input.getExtension()); priority = input.getPriority(); serialNumber = getNextSerialNumber(); - + if(input.getDigest() == null || input.getDigest().length() == 0) { throw new IllegalArgumentException("Missing digest: " + input); } - + if(resourceType == RegisteredResource.ResourceType.BUNDLE) { if(input.getInputStream() == null) { throw new IllegalArgumentException("InputStream is required for BUNDLE resource type: " + input); @@ -101,7 +101,7 @@ hasDataFile = true; digest = input.getDigest(); setAttributesFromManifest(ctx); - final String name = (String)attributes.get(Constants.BUNDLE_SYMBOLICNAME); + 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 + input.getUrl(); @@ -117,7 +117,7 @@ // config provided as a Dictionary dictionary = copy(input.getDictionary()); } else { - dictionary = readDictionary(input.getInputStream()); + dictionary = readDictionary(input.getInputStream()); } digest = input.getDigest(); } @@ -127,10 +127,10 @@ } } } - + private static long getNextSerialNumber() { synchronized (RegisteredResourceImpl.class) { - return serialNumberCounter++; + return serialNumberCounter++; } } @@ -138,23 +138,23 @@ public String toString() { return getClass().getSimpleName() + " " + url + ", digest=" + digest + ", serialNumber=" + serialNumber; } - + protected File getDataFile(BundleContext ctx) { final String filename = getClass().getSimpleName() + "." + serialNumber; return ctx.getDataFile(filename); } - + public void cleanup(BundleContext bc) { final File dataFile = getDataFile(bc); if(dataFile.exists()) { dataFile.delete(); } } - + public String getURL() { return url; } - + public InputStream getInputStream(BundleContext bc) throws IOException { if(hasDataFile) { final File dataFile = getDataFile(bc); @@ -164,15 +164,15 @@ } return null; } - + public Dictionary getDictionary() { return dictionary; } - + public String getDigest() { return digest; } - + /** Copy data to local storage */ private void copyToLocalStorage(InputStream data, File f) throws IOException { final OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); @@ -184,14 +184,12 @@ } os.flush(); } finally { - if(os != null) { - os.close(); - } + os.close(); } } - + /** Convert InputStream to Dictionary using our extended properties format, - * which supports multi-value properties + * which supports multi-value properties */ static Dictionary readDictionary(InputStream is) throws IOException { final Dictionary result = new Hashtable(); @@ -204,7 +202,7 @@ } return result; } - + /** Copy given Dictionary, sorting keys */ static Dictionary copy(Dictionary d) { final Dictionary result = new Hashtable(); @@ -219,7 +217,7 @@ } return result; } - + public String getUrl() { return url; } @@ -227,27 +225,26 @@ public RegisteredResource.ResourceType getResourceType() { return resourceType; } - + static RegisteredResource.ResourceType computeResourceType(String extension) { if(extension.equals("jar")) { return RegisteredResource.ResourceType.BUNDLE; - } else { - return RegisteredResource.ResourceType.CONFIG; } + return RegisteredResource.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. + * symbolic ID, or "config:PID" where PID is config's PID. */ public String getEntityId() { return entity; } - + public Map getAttributes() { return attributes; } - + public boolean isInstallable() { return installable; } @@ -285,29 +282,27 @@ return result; } - + 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"); } - + final String sn = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); if(sn == null) { throw new IOException("Manifest does not supply " + Constants.BUNDLE_SYMBOLICNAME); } - + final String v = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION); if(v == null) { throw new IOException("Manifest does not supply " + Constants.BUNDLE_VERSION); } - - if(m != null) { - attributes.put(Constants.BUNDLE_SYMBOLICNAME, sn); - attributes.put(Constants.BUNDLE_VERSION, v.toString()); - } + + attributes.put(Constants.BUNDLE_SYMBOLICNAME, sn); + attributes.put(Constants.BUNDLE_VERSION, v.toString()); } - + static String getUrlScheme(String url) { final int pos = url.indexOf(':'); if(pos <= 0) { @@ -315,15 +310,15 @@ } return url.substring(0, pos); } - + public String getUrlScheme() { return urlScheme; } - + public int getPriority() { return priority; } - + public long getSerialNumber() { return serialNumber; } Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/InstallableResourceTest.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/InstallableResourceTest.java?rev=900757&r1=900756&r2=900757&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/InstallableResourceTest.java (original) +++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/InstallableResourceTest.java Tue Jan 19 13:00:37 2010 @@ -18,29 +18,28 @@ */ package org.apache.sling.osgi.installer.impl; -import java.io.ByteArrayInputStream; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.Dictionary; import java.util.Hashtable; import org.apache.sling.osgi.installer.InstallableResource; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - public class InstallableResourceTest { - - @Test + + @Test public void testDictionaryDigest() { final Dictionary d = new Hashtable(); final InstallableResource r = new InstallableResource("x:url", d); assertNotNull("Expected InstallableResource to compute its own digest", r.getDigest()); } - + @org.junit.Test public void testDictionaryDigestFromDictionaries() throws Exception { final Hashtable d1 = new Hashtable(); final Hashtable d2 = new Hashtable(); - + final String [] keys = { "foo", "bar", "something" }; for(int i=0 ; i < keys.length; i++) { d1.put(keys[i], keys[i] + "." + keys[i]); @@ -48,12 +47,12 @@ for(int i=keys.length - 1 ; i >= 0; i--) { d2.put(keys[i], keys[i] + "." + keys[i]); } - + final InstallableResource r1 = new InstallableResource("test:url1", d1); final InstallableResource r2 = new InstallableResource("test:url1", d2); - + assertEquals( - "Two InstallableResource (Dictionary) with same values but different key orderings must have the same key", + "Two InstallableResource (Dictionary) with same values but different key orderings must have the same key", r1.getDigest(), r2.getDigest() );