Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 29032 invoked from network); 12 Aug 2010 10:08:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Aug 2010 10:08:28 -0000 Received: (qmail 7007 invoked by uid 500); 12 Aug 2010 10:08:28 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 6942 invoked by uid 500); 12 Aug 2010 10:08:26 -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 6935 invoked by uid 99); 12 Aug 2010 10:08:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Aug 2010 10:08:25 +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; Thu, 12 Aug 2010 10:08:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B6CF72388A2C; Thu, 12 Aug 2010 10:07:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r984709 - 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: Thu, 12 Aug 2010 10:07:04 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100812100704.B6CF72388A2C@eris.apache.org> Author: cziegeler Date: Thu Aug 12 10:07:03 2010 New Revision: 984709 URL: http://svn.apache.org/viewvc?rev=984709&view=rev Log: SLING-1560 : Clean up installer context and installer impl Modified: 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/OsgiInstallerContext.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java 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/PersistentBundleInfo.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/RegisteredResourceComparator.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/BundleRemoveTask.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -22,7 +22,9 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.SortedSet; +import java.util.TreeSet; +import org.apache.sling.osgi.installer.OsgiInstaller; import org.apache.sling.osgi.installer.impl.tasks.BundleInstallTask; import org.apache.sling.osgi.installer.impl.tasks.BundleRemoveTask; import org.apache.sling.osgi.installer.impl.tasks.BundleUpdateTask; @@ -35,7 +37,7 @@ import org.osgi.service.startlevel.Start import org.osgi.util.tracker.ServiceTracker; /** TaskCreator that processes a list of bundle RegisteredResources */ -class BundleTaskCreator { +public class BundleTaskCreator { /** Interface of the package admin */ private static String PACKAGE_ADMIN_NAME = PackageAdmin.class.getName(); @@ -43,12 +45,23 @@ class BundleTaskCreator { /** Interface of the start level */ private static String START_LEVEL_NAME = StartLevel.class.getName(); + /** The filename for the digest storage. */ + private static final String FILE_DIGEST_STORAGE = "bundle-digests.properties"; + + private static final String MAVEN_SNAPSHOT_MARKER = "SNAPSHOT"; + /** Tracker for the package admin. */ private final ServiceTracker packageAdminTracker; /** Tracker for the start level service. */ private final ServiceTracker startLevelTracker; + /** The storage for the bundle info. */ + private final PersistentBundleInfo bundleDigestsStorage; + + /** The bundle context. */ + private final BundleContext bundleContext; + /** Store the digests of the bundles for which we create update tasks, * keyed by symbolic name, to avoid generating repated updates * for snapshot bundles @@ -56,16 +69,43 @@ class BundleTaskCreator { private final Map digests = new HashMap(); public BundleTaskCreator(final BundleContext bc) { + this.bundleContext = bc; // create and start tracker this.packageAdminTracker = new ServiceTracker(bc, PACKAGE_ADMIN_NAME, null); this.packageAdminTracker.open(); this.startLevelTracker = new ServiceTracker(bc, START_LEVEL_NAME, null); this.startLevelTracker.open(); + this.bundleDigestsStorage = new PersistentBundleInfo(bc.getDataFile(FILE_DIGEST_STORAGE)); } public void deactivate() { this.packageAdminTracker.close(); this.startLevelTracker.close(); + final TreeSet installedBundlesSymbolicNames = new TreeSet(); + // do we really want to iterate here? Over all bundles? TODO + for(Bundle b : bundleContext.getBundles()) { + final String name = b.getSymbolicName(); + if ( name != null ) { + installedBundlesSymbolicNames.add(b.getSymbolicName()); + } + } + try { + this.bundleDigestsStorage.purgeAndSave(installedBundlesSymbolicNames); + } catch (IOException e) { + Logger.logWarn(OsgiInstaller.class.getName() + " service failed to save state.", e); + } + } + + public BundleContext getBundleContext() { + return this.bundleContext; + } + + public StartLevel getStartLevel() { + return (StartLevel) this.startLevelTracker.getService(); + } + + public PackageAdmin getPackageAdmin() { + return (PackageAdmin)this.packageAdminTracker.getService(); } /** Holds the bundle info that we need, makes it easier to test @@ -110,15 +150,16 @@ class BundleTaskCreator { final String symbolicName = firstResource == null ? null : (String)firstResource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); - if(toActivate == null) { + 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 (getBundleInfo(ctx, resources.first()) != null) { + if (this.getInstalledBundleVersion(symbolicName) == null) { Logger.logInfo("Bundle " + symbolicName + " was not installed by this module, not removed"); } else { - tasks.add(new BundleRemoveTask(resources.first(), this.packageAdminTracker)); + tasks.add(new BundleRemoveTask(resources.first(), + this)); } } @@ -129,7 +170,8 @@ class BundleTaskCreator { if (info == null) { // bundle is not installed yet: install and save digest to avoid // unnecessary updates - tasks.add(new BundleInstallTask(toActivate, this.startLevelTracker)); + tasks.add(new BundleInstallTask(toActivate, + this)); digestToSave = toActivate.getDigest(); } else { final int compare = info.version.compareTo(newVersion); @@ -139,7 +181,7 @@ class BundleTaskCreator { } else if(compare > 0) { // installed version is higher -> downgrade only if // we installed that version - final String installedVersion = ctx.getInstalledBundleVersion(info.symbolicName); + final String installedVersion = this.getInstalledBundleVersion(info.symbolicName); if(info.version.toString().equals(installedVersion)) { toUpdate = toActivate; Logger.logInfo("Bundle " + info.symbolicName + " " + installedVersion @@ -148,7 +190,7 @@ class BundleTaskCreator { Logger.logInfo("Bundle " + info.symbolicName + " " + installedVersion + " was not installed by this module, not downgraded"); } - } else if(compare == 0 && ctx.isSnapshot(newVersion)){ + } else if(compare == 0 && this.isSnapshot(newVersion)){ // installed, same version but SNAPSHOT toUpdate = toActivate; } @@ -163,7 +205,8 @@ class BundleTaskCreator { digestToSave = previousDigest; } else { Logger.logDebug("Scheduling update of " + toUpdate + ", digest has changed"); - tasks.add(new BundleUpdateTask(toUpdate, this.packageAdminTracker)); + tasks.add(new BundleUpdateTask(toUpdate, + this)); digestToSave = toUpdate.getDigest(); } } @@ -180,10 +223,55 @@ class BundleTaskCreator { protected BundleInfo getBundleInfo(OsgiInstallerContext ctx, RegisteredResource bundle) { final String symbolicName = (String)bundle.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); - final Bundle b = ctx.getMatchingBundle(symbolicName); - if(b == null) { + final Bundle b = this.getMatchingBundle(symbolicName); + if (b == null) { return null; } return new BundleInfo(b); } + + /** + * Retrieve a bundle's digest that was stored by saveInstalledBundleInfo + * @return null if no digest was stored + */ + public String getInstalledBundleDigest(Bundle b) throws IOException { + return bundleDigestsStorage.getDigest(b.getSymbolicName()); + } + + /** + * Retrieve a bundle's version that was stored by saveInstalledBundleInfo + * @return null if no version was stored + */ + public String getInstalledBundleVersion(String symbolicName) throws IOException { + return bundleDigestsStorage.getInstalledVersion(symbolicName); + } + + /** + * Store a bundle's digest and installed version, keyed by symbolic ID + */ + public void saveInstalledBundleInfo(String symbolicName, String digest, String version) throws IOException { + bundleDigestsStorage.putInfo(symbolicName, digest, version); + } + + /** + * Finds the bundle with given symbolic name in our BundleContext. + */ + public Bundle getMatchingBundle(String bundleSymbolicName) { + if (bundleSymbolicName != null) { + Bundle[] bundles = bundleContext.getBundles(); + for (Bundle bundle : bundles) { + if (bundleSymbolicName.equals(bundle.getSymbolicName())) { + return bundle; + } + } + } + return null; + } + + /** + * Check if the version is a snapshot version + */ + public boolean isSnapshot(Version v) { + return v.toString().indexOf(MAVEN_SNAPSHOT_MARKER) >= 0; + } } Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java Thu Aug 12 10:07:03 2010 @@ -18,28 +18,13 @@ */ package org.apache.sling.osgi.installer.impl; -import java.io.IOException; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; /** - * Installer context, gives access to selected methods of the {@link OsgiInstallerImpl} + * Context for the installation tasks. + * Currently it allows to add a task to the current or the next cycle. */ public interface OsgiInstallerContext { - /** - * Return the bundle context. - */ - BundleContext getBundleContext(); - - /** - * Finds the bundle with given symbolic name in our BundleContext. - */ - Bundle getMatchingBundle(String bundleSymbolicName); - boolean isSnapshot(Version v); - /** Schedule a task for execution in the current OsgiController cycle */ void addTaskToCurrentCycle(OsgiInstallerTask t); @@ -47,17 +32,4 @@ public interface OsgiInstallerContext { * usually to indicate that a task must be retried */ void addTaskToNextCycle(OsgiInstallerTask t); - - /** Store a bundle's digest and installed version, keyed by symbolic ID */ - void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException; - - /** Retrieve a bundle's digest that was stored by saveInstalledBundleInfo - * @return null if no digest was stored - * */ - String getInstalledBundleDigest(Bundle b) throws IOException; - - /** Retrieve a bundle's version that was stored by saveInstalledBundleInfo - * @return null if no version was stored - * */ - String getInstalledBundleVersion(String symbolicName) throws IOException; } Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java Thu Aug 12 10:07:03 2010 @@ -20,19 +20,15 @@ package org.apache.sling.osgi.installer. import java.io.IOException; import java.util.Collection; -import java.util.TreeSet; import org.apache.sling.osgi.installer.InstallableResource; import org.apache.sling.osgi.installer.OsgiInstaller; import org.apache.sling.osgi.installer.OsgiInstallerStatistics; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; /** OsgiInstaller service implementation */ -public class OsgiInstallerImpl implements OsgiInstaller, OsgiInstallerStatistics, OsgiInstallerContext { - - public static final String MAVEN_SNAPSHOT_MARKER = "SNAPSHOT"; +public class OsgiInstallerImpl + implements OsgiInstaller, OsgiInstallerStatistics { /** The bundle context. */ private final BundleContext bundleContext; @@ -40,17 +36,14 @@ public class OsgiInstallerImpl implement /** The actual worker thread. */ private final OsgiInstallerThread installerThread; - private PersistentBundleInfo bundleDigestsStorage; - /** * Construct a new service */ public OsgiInstallerImpl(final BundleContext bc) throws IOException { this.bundleContext = bc; - bundleDigestsStorage = new PersistentBundleInfo(bc.getDataFile("bundle-digests.properties")); - installerThread = new OsgiInstallerThread(this); + installerThread = new OsgiInstallerThread(bc); installerThread.setDaemon(true); installerThread.start(); } @@ -61,20 +54,6 @@ public class OsgiInstallerImpl implement public void deactivate() { installerThread.deactivate(); - final TreeSet installedBundlesSymbolicNames = new TreeSet(); - // do we really want to iterate here? Over all bundles? TODO - for(Bundle b : bundleContext.getBundles()) { - final String name = b.getSymbolicName(); - if ( name != null ) { - installedBundlesSymbolicNames.add(b.getSymbolicName()); - } - } - try { - bundleDigestsStorage.purgeAndSave(installedBundlesSymbolicNames); - } catch (IOException e) { - Logger.logWarn(OsgiInstaller.class.getName() + " service failed to save state.", e); - } - Logger.logInfo("Waiting for installer thread to stop"); try { installerThread.join(); @@ -87,28 +66,6 @@ public class OsgiInstallerImpl implement } /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#addTaskToCurrentCycle(org.apache.sling.osgi.installer.impl.OsgiInstallerTask) - */ - public void addTaskToCurrentCycle(OsgiInstallerTask t) { - installerThread.addTaskToCurrentCycle(t); - } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#addTaskToNextCycle(org.apache.sling.osgi.installer.impl.OsgiInstallerTask) - */ - public void addTaskToNextCycle(OsgiInstallerTask t) { - Logger.logDebug("adding task to next cycle:" + t); - installerThread.addTaskToNextCycle(t); - } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#getBundleContext() - */ - public BundleContext getBundleContext() { - return bundleContext; - } - - /** * @see org.apache.sling.osgi.installer.OsgiInstaller#addResource(java.lang.String, org.apache.sling.osgi.installer.InstallableResource) */ public void addResource(final String scheme, final InstallableResource r) { @@ -135,53 +92,4 @@ public class OsgiInstallerImpl implement public long[] getCounters() { return this.installerThread.getCounters(); } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#getMatchingBundle(java.lang.String) - */ - public Bundle getMatchingBundle(String bundleSymbolicName) { - if (bundleSymbolicName != null) { - Bundle[] bundles = bundleContext.getBundles(); - for (Bundle bundle : bundles) { - if (bundleSymbolicName.equals(bundle.getSymbolicName())) { - return bundle; - } - } - } - return null; - } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#isSnapshot(org.osgi.framework.Version) - */ - public boolean isSnapshot(Version v) { - return v.toString().indexOf(MAVEN_SNAPSHOT_MARKER) >= 0; - } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#getInstalledBundleDigest(org.osgi.framework.Bundle) - */ - public String getInstalledBundleDigest(Bundle b) throws IOException { - if(bundleDigestsStorage == null) { - return null; - } - return bundleDigestsStorage.getDigest(b.getSymbolicName()); - } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#getInstalledBundleVersion(java.lang.String) - */ - public String getInstalledBundleVersion(String symbolicName) throws IOException { - if(bundleDigestsStorage == null) { - return null; - } - return bundleDigestsStorage.getInstalledVersion(symbolicName); - } - - /** - * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#saveInstalledBundleInfo(org.osgi.framework.Bundle, java.lang.String, java.lang.String) - */ - public void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException { - bundleDigestsStorage.putInfo(b.getSymbolicName(), digest, version); - } } \ No newline at end of file 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -46,9 +46,11 @@ import org.osgi.framework.BundleListener * that are updated or removed during a cycle, and merged with * the main list at the end of the cycle. */ -class OsgiInstallerThread extends Thread implements BundleListener, OsgiInstallerStatistics { +class OsgiInstallerThread + extends Thread + implements BundleListener, OsgiInstallerStatistics, OsgiInstallerContext { - private final OsgiInstallerContext ctx; + private final BundleContext ctx; private final List newResources = new LinkedList(); private final SortedSet tasks = new TreeSet(); private final SortedSet tasksForNextCycle = new TreeSet(); @@ -67,20 +69,20 @@ class OsgiInstallerThread extends Thread private long [] counters = new long[COUNTERS_SIZE]; - OsgiInstallerThread(final OsgiInstallerContext ctx) { - this.configTaskCreator = new ConfigTaskCreator(ctx.getBundleContext()); - this.bundleTaskCreator = new BundleTaskCreator(ctx.getBundleContext()); + OsgiInstallerThread(final BundleContext ctx) { + this.configTaskCreator = new ConfigTaskCreator(ctx); + this.bundleTaskCreator = new BundleTaskCreator(ctx); setName(getClass().getSimpleName()); this.ctx = ctx; - final File f = ctx.getBundleContext().getDataFile("RegisteredResourceList.ser"); - persistentList = new PersistentResourceList(ctx.getBundleContext(), f); + final File f = ctx.getDataFile("RegisteredResourceList.ser"); + persistentList = new PersistentResourceList(ctx, f); registeredResources = persistentList.getData(); } void deactivate() { this.configTaskCreator.deactivate(); this.bundleTaskCreator.deactivate(); - ctx.getBundleContext().removeBundleListener(this); + ctx.removeBundleListener(this); active = false; synchronized (newResources) { newResources.notify(); @@ -104,7 +106,7 @@ class OsgiInstallerThread extends Thread @Override public void run() { - ctx.getBundleContext().addBundleListener(this); + ctx.addBundleListener(this); while(active) { try { @@ -150,7 +152,10 @@ class OsgiInstallerThread extends Thread Logger.logInfo("Deactivated, exiting"); } - void addTaskToCurrentCycle(OsgiInstallerTask t) { + /** + * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#addTaskToCurrentCycle(org.apache.sling.osgi.installer.impl.OsgiInstallerTask) + */ + public void addTaskToCurrentCycle(OsgiInstallerTask t) { Logger.logDebug("adding task to current cycle:" + t); synchronized (tasks) { tasks.add(t); @@ -173,7 +178,7 @@ class OsgiInstallerThread extends Thread void addNewResource(final InstallableResource r, final String scheme) { RegisteredResource rr = null; try { - rr = new RegisteredResourceImpl(ctx.getBundleContext(), r, scheme); + rr = new RegisteredResourceImpl(ctx, r, scheme); } catch(IOException ioe) { Logger.logWarn("Cannot create RegisteredResource (resource will be ignored):" + r, ioe); return; @@ -194,7 +199,7 @@ class OsgiInstallerThread extends Thread for(InstallableResource r : data) { RegisteredResource rr = null; try { - rr = new RegisteredResourceImpl(ctx.getBundleContext(), r, urlScheme); + rr = new RegisteredResourceImpl(ctx, r, urlScheme); } catch(IOException ioe) { Logger.logWarn("Cannot create RegisteredResource (resource will be ignored):" + r, ioe); continue; @@ -284,7 +289,11 @@ class OsgiInstallerThread extends Thread } } - void addTaskToNextCycle(OsgiInstallerTask t) { + /** + * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#addTaskToNextCycle(org.apache.sling.osgi.installer.impl.OsgiInstallerTask) + */ + public void addTaskToNextCycle(OsgiInstallerTask t) { + Logger.logDebug("adding task to next cycle:" + t); synchronized (tasksForNextCycle) { tasksForNextCycle.add(t); } @@ -302,7 +311,7 @@ class OsgiInstallerThread extends Thread final List toKeep = new ArrayList(); synchronized (tasksForNextCycle) { for(OsgiInstallerTask t : tasksForNextCycle) { - if(t.isExecutable(ctx)) { + if(t.isExecutable(this)) { tasks.add(t); } else { toKeep.add(t); @@ -321,9 +330,9 @@ class OsgiInstallerThread extends Thread } final String rt = group.first().getType(); if ( InstallableResource.TYPE_BUNDLE.equals(rt) ) { - bundleTaskCreator.createTasks(ctx, group, tasks); + bundleTaskCreator.createTasks(this, group, tasks); } else if ( InstallableResource.TYPE_CONFIG.equals(rt) ) { - configTaskCreator.createTasks(ctx, group, tasks); + configTaskCreator.createTasks(this, group, tasks); } } } @@ -336,7 +345,7 @@ class OsgiInstallerThread extends Thread t = tasks.first(); tasks.remove(t); } - final OsgiInstallerTask.Result result = t.execute(ctx); + final OsgiInstallerTask.Result result = t.execute(this); switch (result) { case SUCCESS: this.incrementCounter(OsgiInstallerStatistics.OSGI_TASKS_COUNTER); break; Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java Thu Aug 12 10:07:03 2010 @@ -35,9 +35,8 @@ import java.util.TreeSet; */ class PersistentBundleInfo { - private Properties digests = new Properties(); + private final Properties digests = new Properties(); private final File dataFile; - // private final OsgiInstallerContext ctx; private static final String VERSION_PREFIX = "V:"; /** 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -78,7 +78,8 @@ public interface RegisteredResource { */ String getDigest(); - /**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.) */ 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -33,6 +33,8 @@ import org.osgi.framework.Version; */ class RegisteredResourceComparator implements Comparator, Serializable { + private static final String MAVEN_SNAPSHOT_MARKER = "SNAPSHOT"; + private static final long serialVersionUID = 1L; public int compare(RegisteredResource a, RegisteredResource b) { @@ -66,7 +68,7 @@ class RegisteredResourceComparator imple 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.toString().contains(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER); + isSnapshot = va.toString().contains(MAVEN_SNAPSHOT_MARKER); // higher version has more priority, must come first so invert comparison result = vb.compareTo(va); } 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -19,6 +19,7 @@ package org.apache.sling.osgi.installer.impl.tasks; import org.apache.sling.osgi.installer.InstallableResource; +import org.apache.sling.osgi.installer.impl.BundleTaskCreator; import org.apache.sling.osgi.installer.impl.Logger; import org.apache.sling.osgi.installer.impl.OsgiInstallerContext; import org.apache.sling.osgi.installer.impl.OsgiInstallerTask; @@ -27,7 +28,6 @@ import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.Version; import org.osgi.service.startlevel.StartLevel; -import org.osgi.util.tracker.ServiceTracker; /** Install a bundle supplied as a RegisteredResource. * Creates a BundleStartTask to start the bundle */ @@ -37,11 +37,12 @@ public class BundleInstallTask extends O private final RegisteredResource resource; - private final ServiceTracker startLevelServiceTracker; + private final BundleTaskCreator creator; - public BundleInstallTask(final RegisteredResource r, final ServiceTracker startLevelServiceTracker) { + public BundleInstallTask(final RegisteredResource r, + final BundleTaskCreator creator) { + this.creator = creator; this.resource = r; - this.startLevelServiceTracker = startLevelServiceTracker; } @Override @@ -64,9 +65,9 @@ public class BundleInstallTask extends O } } // get the start level service (if possible) so we can set the initial start level - final StartLevel startLevelService = (StartLevel) startLevelServiceTracker.getService(); + final StartLevel startLevelService = this.creator.getStartLevel(); try { - final Bundle b = ctx.getBundleContext().installBundle(resource.getURL(), resource.getInputStream()); + 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); @@ -74,9 +75,9 @@ public class BundleInstallTask extends O 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)); - ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString()); + this.creator.saveInstalledBundleInfo(b.getSymbolicName(), resource.getDigest(), newVersion.toString()); logExecution(); - ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId())); + ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId(), this.creator)); return Result.SUCCESS; } catch (Exception ex) { // if something goes wrong we simply try it again Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java Thu Aug 12 10:07:03 2010 @@ -18,13 +18,13 @@ */ package org.apache.sling.osgi.installer.impl.tasks; +import org.apache.sling.osgi.installer.impl.BundleTaskCreator; import org.apache.sling.osgi.installer.impl.OsgiInstallerContext; import org.apache.sling.osgi.installer.impl.OsgiInstallerTask; import org.apache.sling.osgi.installer.impl.RegisteredResource; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; -import org.osgi.util.tracker.ServiceTracker; /** Remove a bundle from a RegisteredResource. * Creates a SynchronousRefreshPackagesTask when @@ -36,12 +36,12 @@ public class BundleRemoveTask extends Os private final RegisteredResource resource; - /** Tracker for the package admin. */ - private final ServiceTracker packageAdminTracker; + private final BundleTaskCreator creator; - public BundleRemoveTask(final RegisteredResource r, final ServiceTracker packageAdminTracker) { + public BundleRemoveTask(final RegisteredResource r, + final BundleTaskCreator creator) { + this.creator = creator; this.resource = r; - this.packageAdminTracker = packageAdminTracker; } @Override @@ -53,7 +53,7 @@ public class BundleRemoveTask extends Os public Result execute(OsgiInstallerContext ctx) { logExecution(); final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); - final Bundle b = ctx.getMatchingBundle(symbolicName); + final Bundle b = this.creator.getMatchingBundle(symbolicName); if(b == null) { throw new IllegalStateException("Bundle to remove (" + symbolicName + ") not found"); } @@ -67,7 +67,7 @@ public class BundleRemoveTask extends Os ctx.addTaskToNextCycle(this); return Result.NOTHING; } - ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.packageAdminTracker)); + ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.creator)); return Result.SUCCESS; } 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -21,6 +21,7 @@ package org.apache.sling.osgi.installer. import java.text.DecimalFormat; import org.apache.sling.osgi.installer.impl.Activator; +import org.apache.sling.osgi.installer.impl.BundleTaskCreator; import org.apache.sling.osgi.installer.impl.Logger; import org.apache.sling.osgi.installer.impl.OsgiInstallerContext; import org.apache.sling.osgi.installer.impl.OsgiInstallerTask; @@ -41,8 +42,11 @@ public class BundleStartTask extends Osg private long eventsCountForRetrying; private int retryCount = 0; - public BundleStartTask(long bundleId) { + private final BundleTaskCreator creator; + + public BundleStartTask(final long bundleId, final BundleTaskCreator btc) { this.bundleId = bundleId; + this.creator = btc; sortKey = BUNDLE_START_ORDER + new DecimalFormat("00000").format(bundleId); } @@ -57,7 +61,7 @@ public class BundleStartTask extends Osg } public Result execute(OsgiInstallerContext ctx) { - final Bundle b = ctx.getBundleContext().getBundle(bundleId); + final Bundle b = this.creator.getBundleContext().getBundle(bundleId); boolean needToRetry = false; if(bundleId == 0) { 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=984709&r1=984708&r2=984709&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 Thu Aug 12 10:07:03 2010 @@ -20,6 +20,7 @@ package org.apache.sling.osgi.installer. import java.io.InputStream; +import org.apache.sling.osgi.installer.impl.BundleTaskCreator; import org.apache.sling.osgi.installer.impl.Logger; import org.apache.sling.osgi.installer.impl.OsgiInstallerContext; import org.apache.sling.osgi.installer.impl.OsgiInstallerTask; @@ -27,7 +28,6 @@ import org.apache.sling.osgi.installer.i import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.Version; -import org.osgi.util.tracker.ServiceTracker; /** Update a bundle from a RegisteredResource. Creates * a bundleStartTask to restart the bundle if it was @@ -37,15 +37,15 @@ public class BundleUpdateTask extends Os private static final String BUNDLE_UPDATE_ORDER = "40-"; - /** Tracker for the package admin. */ - private final ServiceTracker packageAdminTracker; - private final RegisteredResource resource; private boolean canRetry = true; - public BundleUpdateTask(final RegisteredResource r, final ServiceTracker packageAdminTracker) { + private final BundleTaskCreator creator; + + public BundleUpdateTask(final RegisteredResource r, + final BundleTaskCreator creator) { + this.creator = creator; this.resource = r; - this.packageAdminTracker = packageAdminTracker; } public RegisteredResource getResource() { @@ -60,7 +60,7 @@ public class BundleUpdateTask extends Os @Override public Result execute(OsgiInstallerContext ctx) { final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME); - final Bundle b = ctx.getMatchingBundle(symbolicName); + final Bundle b = this.creator.getMatchingBundle(symbolicName); if(b == null) { throw new IllegalStateException("Bundle to update (" + symbolicName + ") not found"); } @@ -69,7 +69,7 @@ public class BundleUpdateTask extends Os boolean snapshot = false; final Version currentVersion = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION)); final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION)); - snapshot = ctx.isSnapshot(newVersion); + snapshot = this.creator.isSnapshot(newVersion); if(currentVersion.equals(newVersion) && !snapshot) { Logger.logDebug("Same version is already installed, and not a snapshot, ignoring update:" + resource); return Result.NOTHING; @@ -80,7 +80,7 @@ public class BundleUpdateTask extends Os // of RegisteredResources is not saved, this might not have been detected earlier, // if the snapshot was installed and the installer was later restarted if(snapshot) { - final String oldDigest = ctx.getInstalledBundleDigest(b); + final String oldDigest = this.creator.getInstalledBundleDigest(b); if(resource.getDigest().equals(oldDigest)) { Logger.logDebug("Snapshot digest did not change, ignoring update:" + resource); return Result.NOTHING; @@ -91,7 +91,7 @@ public class BundleUpdateTask extends Os if(b.getState() == Bundle.ACTIVE) { // bundle was active before the update - restart it once updated, but // in sequence, not right now - ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId())); + ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId(), this.creator)); } b.stop(); final InputStream is = resource.getInputStream(); @@ -102,7 +102,7 @@ public class BundleUpdateTask extends Os + resource); } b.update(is); - ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString()); + this.creator.saveInstalledBundleInfo(b.getSymbolicName(), resource.getDigest(), newVersion.toString()); } catch (Exception e) { if ( canRetry ) { ctx.addTaskToCurrentCycle(this); @@ -111,7 +111,7 @@ public class BundleUpdateTask extends Os Logger.logWarn("Removing failing tasks - unable to retry: " + this, e); return Result.NOTHING; } - ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.packageAdminTracker)); + ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.creator)); Logger.logDebug("Bundle updated: " + b.getBundleId() + "/" + b.getSymbolicName()); return Result.SUCCESS; } Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java Thu Aug 12 10:07:03 2010 @@ -18,6 +18,7 @@ */ package org.apache.sling.osgi.installer.impl.tasks; +import org.apache.sling.osgi.installer.impl.BundleTaskCreator; import org.apache.sling.osgi.installer.impl.Logger; import org.apache.sling.osgi.installer.impl.OsgiInstallerContext; import org.apache.sling.osgi.installer.impl.OsgiInstallerTask; @@ -25,13 +26,12 @@ import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkEvent; import org.osgi.framework.FrameworkListener; import org.osgi.service.packageadmin.PackageAdmin; -import org.osgi.util.tracker.ServiceTracker; /** Execute an OSGi "refresh packages" operation, synchronously */ public class SynchronousRefreshPackagesTask extends OsgiInstallerTask implements FrameworkListener { /** Tracker for the package admin. */ - private final ServiceTracker packageAdminTracker; + private final BundleTaskCreator bundleTaskCreator; private static final String REFRESH_PACKAGES_ORDER = "60-"; @@ -40,8 +40,8 @@ public class SynchronousRefreshPackagesT private volatile int packageRefreshEventsCount; - public SynchronousRefreshPackagesTask(final ServiceTracker packageAdminTracker) { - this.packageAdminTracker = packageAdminTracker; + public SynchronousRefreshPackagesTask(final BundleTaskCreator btc) { + this.bundleTaskCreator = btc; } /** @@ -69,7 +69,7 @@ public class SynchronousRefreshPackagesT } private PackageAdmin getPackageAdmin() { - return (PackageAdmin)this.packageAdminTracker.getService(); + return this.bundleTaskCreator.getPackageAdmin(); } /** @@ -84,9 +84,9 @@ public class SynchronousRefreshPackagesT // Refreshing packages might cause some bundles to be stopped, // make sure all currently active ones are restarted after // this task executes - for(Bundle b : ctx.getBundleContext().getBundles()) { + for(Bundle b : this.bundleTaskCreator.getBundleContext().getBundles()) { if(b.getState() == Bundle.ACTIVE) { - final OsgiInstallerTask t = new BundleStartTask(b.getBundleId()); + final OsgiInstallerTask t = new BundleStartTask(b.getBundleId(), this.bundleTaskCreator); ctx.addTaskToCurrentCycle(t); Logger.logDebug("Added " + t + " to restart bundle if needed after refreshing packages"); } @@ -94,7 +94,7 @@ public class SynchronousRefreshPackagesT // It seems like (at least with Felix 1.0.4) we won't get a FrameworkEvent.PACKAGES_REFRESHED // if one happened very recently and there's nothing to refresh - ctx.getBundleContext().addFrameworkListener(this); + this.bundleTaskCreator.getBundleContext().addFrameworkListener(this); try { this.getPackageAdmin().refreshPackages(null); while(true) { @@ -117,7 +117,7 @@ public class SynchronousRefreshPackagesT } } } finally { - ctx.getBundleContext().removeFrameworkListener(this); + this.bundleTaskCreator.getBundleContext().removeFrameworkListener(this); } return Result.SUCCESS; } Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java (original) +++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java Thu Aug 12 10:07:03 2010 @@ -35,24 +35,24 @@ import org.osgi.framework.Bundle; public class BundleTaskCreatorTest { public static final String SN = "TestSymbolicName"; private MockOsgiInstallerContext ctx; - + @Before public void setUp() throws IOException { ctx = new MockOsgiInstallerContext(); } - + private SortedSet getTasks(RegisteredResource [] resources, BundleTaskCreator btc) throws IOException { final SortedSet s = OsgiInstallerThread.createRegisteredResourcesEntry(); for(RegisteredResource r : resources) { s.add(r); } - + final SortedSet tasks = new TreeSet(); btc.createTasks(ctx, s, tasks); return tasks; } - - @Test + + @Test public void testSingleBundleNew() throws IOException { final RegisteredResource [] r = { new MockBundleResource(SN, "1.0") @@ -68,14 +68,14 @@ public class BundleTaskCreatorTest { final RegisteredResource [] r = { new MockBundleResource(SN, "1.0") }; - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.0", Bundle.ACTIVE); final SortedSet s = getTasks(r, c); assertEquals("Expected no tasks, same version is active", 0, s.size()); } - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.0", Bundle.RESOLVED); @@ -83,13 +83,13 @@ public class BundleTaskCreatorTest { assertEquals("Expected no tasks, same version is installed", 0, s.size()); } } - - @Test + + @Test public void testBundleUpgrade() throws IOException { final RegisteredResource [] r = { new MockBundleResource(SN, "1.1") }; - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.0", Bundle.ACTIVE); @@ -98,14 +98,14 @@ public class BundleTaskCreatorTest { assertTrue("Expected a BundleUpdateTask", s.first() instanceof BundleUpdateTask); } } - - @Test + + @Test public void testBundleUpgradeBothRegistered() throws IOException { final RegisteredResource [] r = { new MockBundleResource(SN, "1.1"), new MockBundleResource(SN, "1.0") }; - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.0", Bundle.ACTIVE); @@ -114,14 +114,14 @@ public class BundleTaskCreatorTest { assertTrue("Expected a BundleUpdateTask", s.first() instanceof BundleUpdateTask); } } - - @Test + + @Test public void testBundleUpgradeBothRegisteredReversed() throws IOException { final RegisteredResource [] r = { new MockBundleResource(SN, "1.0"), new MockBundleResource(SN, "1.1") }; - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.0", Bundle.ACTIVE); @@ -130,8 +130,8 @@ public class BundleTaskCreatorTest { assertTrue("Expected a BundleUpdateTask", s.first() instanceof BundleUpdateTask); } } - - @Test + + @Test public void testBundleUpgradeSnapshot() throws IOException { // Need to use OSGi-compliant version number, in bundles // bnd and other tools generate correct numbers. @@ -139,7 +139,7 @@ public class BundleTaskCreatorTest { final RegisteredResource [] r = { new MockBundleResource(SN, v) }; - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, v, Bundle.ACTIVE); @@ -148,33 +148,33 @@ public class BundleTaskCreatorTest { assertTrue("Expected a BundleUpdateTask", s.first() instanceof BundleUpdateTask); } } - - @Test + + @Test public void testBundleRemoveSingle() throws IOException { final String version = "1.0"; final RegisteredResource [] r = { new MockBundleResource(SN, version) }; r[0].setInstallable(false); - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.0", Bundle.ACTIVE); final SortedSet s = getTasks(r, c); assertEquals("Expected no tasks, bundle was not installed by us", 0, s.size()); } - + { - ctx.saveInstalledBundleInfo(SN, r[0].getDigest(), version); final MockBundleTaskCreator c = new MockBundleTaskCreator(); + c.saveInstalledBundleInfo(SN, r[0].getDigest(), version); c.addBundleInfo(SN, "1.0", Bundle.ACTIVE); final SortedSet s = getTasks(r, c); assertEquals("Expected one task, as we installed that bundle", 1, s.size()); assertTrue("Expected a BundleRemoveTask", s.first() instanceof BundleRemoveTask); } } - - @Test + + @Test public void testBundleRemoveMultiple() throws IOException { final RegisteredResource [] r = { new MockBundleResource(SN, "1.0"), @@ -184,38 +184,38 @@ public class BundleTaskCreatorTest { for(RegisteredResource x : r) { x.setInstallable(false); } - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.1", Bundle.ACTIVE); final SortedSet s = getTasks(r, c); assertEquals("Expected no tasks, bundle was not installed by us", 0, s.size()); } - + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.1", Bundle.ACTIVE); - ctx.saveInstalledBundleInfo(SN, r[1].getDigest(), "1.1"); + c.saveInstalledBundleInfo(SN, r[1].getDigest(), "1.1"); final SortedSet s = getTasks(r, c); assertEquals("Expected one task, as we installed that bundle", 1, s.size()); assertTrue("Expected a BundleRemoveTask", s.first() instanceof BundleRemoveTask); } } - - @Test + + @Test public void testDowngradeOfRemovedResource() throws IOException { final RegisteredResource [] r = { new MockBundleResource(SN, "1.0.0"), new MockBundleResource(SN, "1.1.0"), }; - + // Simulate V1.1 installed but resource is gone -> downgrade to 1.0 - r[1].setInstallable(false); - + r[1].setInstallable(false); + { final MockBundleTaskCreator c = new MockBundleTaskCreator(); c.addBundleInfo(SN, "1.1.0", Bundle.ACTIVE); - ctx.saveInstalledBundleInfo(SN, "fakedigest", "1.1.0"); + c.saveInstalledBundleInfo(SN, "fakedigest", "1.1.0"); final SortedSet s = getTasks(r, c); assertEquals("Expected one task", 1, s.size()); assertTrue("Expected a BundleUpdateTask", s.first() instanceof BundleUpdateTask); Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java (original) +++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java Thu Aug 12 10:07:03 2010 @@ -19,6 +19,7 @@ package org.apache.sling.osgi.installer.impl; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.Dictionary; import java.util.HashMap; @@ -42,7 +43,7 @@ class MockBundleTaskCreator extends Bund private final Map fakeBundleInfo = new HashMap(); - public MockBundleTaskCreator() { + public MockBundleTaskCreator() throws IOException { super(new BundleContext() { public boolean ungetService(ServiceReference reference) { @@ -112,8 +113,13 @@ class MockBundleTaskCreator extends Bund } public File getDataFile(String filename) { - // TODO Auto-generated method stub - return null; + try { + final File f = File.createTempFile(MockOsgiInstallerContext.class.getSimpleName(), ".data"); + f.deleteOnExit(); + return f; + } catch (final IOException ioe) { + return null; + } } public Bundle[] getBundles() { Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java (original) +++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java Thu Aug 12 10:07:03 2010 @@ -18,22 +18,11 @@ */ package org.apache.sling.osgi.installer.impl; -import java.io.File; -import java.io.IOException; - import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; public class MockOsgiInstallerContext implements OsgiInstallerContext { - private final PersistentBundleInfo persistentBundleInfo; - - public MockOsgiInstallerContext() throws IOException { - final File f = File.createTempFile(MockOsgiInstallerContext.class.getSimpleName(), ".data"); - f.deleteOnExit(); - persistentBundleInfo = new PersistentBundleInfo(f); - } public void addTaskToCurrentCycle(OsgiInstallerTask t) { } @@ -45,33 +34,8 @@ public class MockOsgiInstallerContext im return null; } - public void incrementCounter(int index) { - } - - public void setCounter(int index, long value) { - } - public Bundle getMatchingBundle(String bundleSymbolicName) { return null; } - public boolean isSnapshot(Version v) { - return v.toString().indexOf(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER) >= 0; - } - - public String getInstalledBundleDigest(Bundle b) throws IOException { - return persistentBundleInfo.getDigest(b.getSymbolicName()); - } - - public String getInstalledBundleVersion(String symbolicName) throws IOException { - return persistentBundleInfo.getInstalledVersion(symbolicName); - } - - public void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException { - saveInstalledBundleInfo(b.getSymbolicName(), digest, version); - } - - public void saveInstalledBundleInfo(String symbolicName, String digest, String version) throws IOException { - persistentBundleInfo.putInfo(symbolicName, digest, version); - } } Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java?rev=984709&r1=984708&r2=984709&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java (original) +++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java Thu Aug 12 10:07:03 2010 @@ -74,7 +74,7 @@ public class TaskOrderingTest { new BundleUpdateTask(getRegisteredResource("test:url"), null), new BundleInstallTask(getRegisteredResource("test:url"), null), new SynchronousRefreshPackagesTask(null), - new BundleStartTask(0), + new BundleStartTask(0, null), }; taskSet.clear(); @@ -129,7 +129,7 @@ public class TaskOrderingTest { new BundleInstallTask(getRegisteredResource("test:someURIa.nothing"), null), new BundleInstallTask(getRegisteredResource("test:someURIb.nothing"), null), new SynchronousRefreshPackagesTask(null), - new BundleStartTask(0), + new BundleStartTask(0, null), }; taskSet.clear(); @@ -153,8 +153,8 @@ public class TaskOrderingTest { final OsgiInstallerTask [] tasksInOrder = { new BundleRemoveTask(getRegisteredResource("test:url"), null), new SynchronousRefreshPackagesTask(null), - new BundleStartTask(0), - new BundleStartTask(1), + new BundleStartTask(0, null), + new BundleStartTask(1, null), }; taskSet.clear(); @@ -185,11 +185,11 @@ public class TaskOrderingTest { public void testBundleStartOrder() { int testIndex = 1; final OsgiInstallerTask [] tasksInOrder = { - new BundleStartTask(0), - new BundleStartTask(1), - new BundleStartTask(5), - new BundleStartTask(11), - new BundleStartTask(51) + new BundleStartTask(0, null), + new BundleStartTask(1, null), + new BundleStartTask(5, null), + new BundleStartTask(11, null), + new BundleStartTask(51, null) }; taskSet.clear();