Author: cziegeler
Date: Fri Oct 14 09:31:12 2011
New Revision: 1183262
URL: http://svn.apache.org/viewvc?rev=1183262&view=rev
Log:
SLING-2217 : Need a good way to downgrade a bundle
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java?rev=1183262&r1=1183261&r2=1183262&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
Fri Oct 14 09:31:12 2011
@@ -271,13 +271,25 @@ public class EntityResourceList implemen
// If an object with same url is already present, replace with the
// new one which might have different attributes
boolean first = true;
- for(final TaskResource rr : resources) {
+ final Iterator<TaskResource> taskIter = this.resources.iterator();
+ while ( taskIter.hasNext() ) {
+ final TaskResource rr = taskIter.next();
if ( rr.getURL().equals(r.getURL()) ) {
- LOGGER.debug("Cleanup obsolete resource: {}", rr);
- this.cleanup(rr);
- resources.remove(rr);
- if ( first && rr.equals(r) ) {
- ((RegisteredResourceImpl)r).setState(rr.getState());
+ boolean removeAndCleanup = true;
+ if ( first ) {
+ if (
RegisteredResourceImpl.isSameResource((RegisteredResourceImpl)rr,
(RegisteredResourceImpl)r) ) {
+ // same resource, just replace
+ ((RegisteredResourceImpl)r).setState(rr.getState());
+ } else if (rr.getState() == ResourceState.INSTALLED) {
+ // it's not the same, but the first one is installed,
so uninstall
+
((RegisteredResourceImpl)rr).setState(ResourceState.UNINSTALL);
+ removeAndCleanup = false;
+ }
+ }
+ if ( removeAndCleanup ) {
+ LOGGER.debug("Cleanup obsolete resource: {}", rr);
+ taskIter.remove();
+ this.cleanup(rr);
}
break;
}
@@ -319,10 +331,12 @@ public class EntityResourceList implemen
public boolean compact() {
boolean changed = false;
final List<TaskResource> toDelete = new ArrayList<TaskResource>();
+ boolean first = true;
for(final TaskResource r : resources) {
- if ( r.getState() == ResourceState.UNINSTALLED ) {
+ if ( r.getState() == ResourceState.UNINSTALLED || (!first &&
r.getState() == ResourceState.UNINSTALL) ) {
toDelete.add(r);
}
+ first = false;
}
for(final RegisteredResource r : toDelete) {
changed = true;
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1183262&r1=1183261&r2=1183262&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
Fri Oct 14 09:31:12 2011
@@ -231,10 +231,12 @@ public class PersistentResourceList {
}
// iterate over untransformed resources and remove
// the resource with that url
- for(final RegisteredResource rr : this.untransformedResources) {
+ final Iterator<RegisteredResource> i =
this.untransformedResources.iterator();
+ while ( i.hasNext() ) {
+ final RegisteredResource rr = i.next();
if ( rr.getURL().equals(url) ) {
((RegisteredResourceImpl)rr).cleanup();
- this.untransformedResources.remove(rr);
+ i.remove();
break;
}
}
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java?rev=1183262&r1=1183261&r2=1183262&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
Fri Oct 14 09:31:12 2011
@@ -385,6 +385,29 @@ public class RegisteredResourceImpl
}
/**
+ * Compare two resources where we know that they point to the same entity
and have the
+ * same URL!
+ */
+ public static boolean isSameResource(final RegisteredResourceImpl a, final
RegisteredResourceImpl b) {
+ if (a.getType().equals(InstallableResource.TYPE_BUNDLE)) {
+ // we need a special comparison for bundles
+
+ // Compare version
+ final Version va = new
Version((String)a.getAttribute(Constants.BUNDLE_VERSION));
+ final Version vb = new
Version((String)b.getAttribute(Constants.BUNDLE_VERSION));
+ if ( !vb.equals(va) ) {
+ return false;
+ }
+ final boolean isSnapshot = va.toString().contains("SNAPSHOT");
+ if ( !isSnapshot ) {
+ return true;
+ }
+ }
+ // we just compare the digest
+ return a.getDigest().equals(b.getDigest());
+ }
+
+ /**
* Compare resources.
* First we compare the entity id - the entity id contains the resource
type
* together with an entity identifier for the to be installed resource like