You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2011/12/20 13:46:47 UTC
svn commit: r1221231 - in /sling/trunk/installer/core/src:
main/java/org/apache/sling/installer/api/tasks/
main/java/org/apache/sling/installer/core/impl/
test/java/org/apache/sling/installer/core/impl/
Author: cziegeler
Date: Tue Dec 20 12:46:47 2011
New Revision: 1221231
URL: http://svn.apache.org/viewvc?rev=1221231&view=rev
Log:
SLING-2335 : Provide support for versioned resources
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TransformationResult.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleResource.java
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java?rev=1221231&r1=1221230&r2=1221231&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResource.java Tue Dec 20 12:46:47 2011
@@ -18,6 +18,8 @@
*/
package org.apache.sling.installer.api.tasks;
+import org.osgi.framework.Version;
+
/**
* A task resource is a registered resource which has been
@@ -59,4 +61,11 @@ public interface TaskResource extends Re
* @param value The attribute value or <code>null</code> to remove it.
*/
void setTemporaryAttribute(String key, Object value);
+
+ /**
+ * Return the version of the artifact.
+ * @return The version of the artifact or <code>null</code>
+ * @since 1.2
+ */
+ Version getVersion();
}
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TransformationResult.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TransformationResult.java?rev=1221231&r1=1221230&r2=1221231&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TransformationResult.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TransformationResult.java Tue Dec 20 12:46:47 2011
@@ -21,6 +21,8 @@ package org.apache.sling.installer.api.t
import java.io.InputStream;
import java.util.Map;
+import org.osgi.framework.Version;
+
/**
* A result of a {@link ResourceTransformer}.
*
@@ -42,6 +44,9 @@ public class TransformationResult {
/** Unique id. */
private String id;
+ /** Optional version. */
+ private Version version;
+
/** Attributes */
private Map<String, Object> attributes;
@@ -106,4 +111,22 @@ public class TransformationResult {
public void setAttributes(final Map<String, Object> attr) {
this.attributes = attr;
}
+
+ /**
+ * Set the version.
+ * @param version The new version
+ * @since 1.2
+ */
+ public void setVersion(final Version version) {
+ this.version = version;
+ }
+
+ /**
+ * Get the version
+ * @return The version or <code>null</code>
+ * @since 1.2
+ */
+ public Version getVersion() {
+ return this.version;
+ }
}
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=1221231&r1=1221230&r2=1221231&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 Tue Dec 20 12:46:47 2011
@@ -389,12 +389,11 @@ public class RegisteredResourceImpl
* 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
-
+ // check if the artifacts have a version
+ final Version va = a.getVersion();
+ final Version vb = b.getVersion();
+ if ( va != null && vb != null ) {
// 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;
}
@@ -417,20 +416,30 @@ public class RegisteredResourceImpl
// check entity id first
int result = a.getEntityId().compareTo(b.getEntityId());
if ( result == 0 ) {
- if (a.getType().equals(InstallableResource.TYPE_BUNDLE)) {
- // we need a special comparison for bundles
- result = compareBundles(a, b);
- } else {
- // all other types: check prio and then digest
+ // compare versions
+ boolean isSnapshot = true;
+
+ // Order by version
+ final Version va = a.getVersion();
+ final Version vb = b.getVersion();
+
+ if ( va != null && vb != null ) {
+ isSnapshot = va.toString().contains("SNAPSHOT");
+ // higher version has more priority, must come first so invert comparison
+ result = vb.compareTo(va);
+ }
+
+ // Then by priority, higher values first
+ if (result == 0) {
result = Integer.valueOf(b.getPriority()).compareTo(a.getPriority());
+ }
- // check digest
- if ( result == 0 ) {
- // higher digest has more priority, must come first so invert comparison
- result = b.getDigest().compareTo(a.getDigest());
- }
+ if (result == 0 && isSnapshot) {
+ // higher digest has more priority, must come first so invert comparison
+ result = b.getDigest().compareTo(a.getDigest());
}
}
+
if ( result == 0 ) {
if ( a.getState() == ResourceState.INSTALLED ) {
return -1;
@@ -443,37 +452,6 @@ public class RegisteredResourceImpl
}
/**
- * Bundles are compared differently than other resource types:
- * - higher versions have always priority - regardless of the priority attribute!
- * - priority matters only if version is same
- * - if the version is a snapshot version, the serial number and the digest are used
- * in addition
- */
- private static int compareBundles(final TaskResource a, final TaskResource b) {
- boolean isSnapshot = false;
- int result = 0;
-
- // Order by version
- final Version va = new Version((String)a.getAttribute(Constants.BUNDLE_VERSION));
- final Version vb = new Version((String)b.getAttribute(Constants.BUNDLE_VERSION));
- isSnapshot = va.toString().contains("SNAPSHOT");
- // higher version has more priority, must come first so invert comparison
- result = vb.compareTo(va);
-
- // Then by priority, higher values first
- if (result == 0) {
- result = Integer.valueOf(b.getPriority()).compareTo(a.getPriority());
- }
-
- if (result == 0 && isSnapshot) {
- // higher digest has more priority, must come first so invert comparison
- result = b.getDigest().compareTo(a.getDigest());
- }
-
- return result;
- }
-
- /**
* @see org.apache.sling.installer.api.tasks.TaskResource#getTemporaryAttribute(java.lang.String)
*/
public Object getTemporaryAttribute(final String key) {
@@ -536,6 +514,9 @@ public class RegisteredResourceImpl
if ( tr.getAttributes() != null ) {
this.attributes.putAll(tr.getAttributes());
}
+ if ( tr.getVersion() != null ) {
+ this.attributes.put(Constants.BUNDLE_VERSION, tr.getVersion().toString());
+ }
}
/**
@@ -583,4 +564,12 @@ public class RegisteredResourceImpl
final int pos = url.indexOf(':');
this.urlScheme = url.substring(0, pos);
}
+
+ /**
+ * @see org.apache.sling.installer.api.tasks.TaskResource#getVersion()
+ */
+ public Version getVersion() {
+ final String vInfo = (String)this.getAttribute(Constants.BUNDLE_VERSION);
+ return (vInfo == null ? null : new Version(vInfo));
+ }
}
\ No newline at end of file
Modified: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleResource.java?rev=1221231&r1=1221230&r2=1221231&view=diff
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleResource.java (original)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleResource.java Tue Dec 20 12:46:47 2011
@@ -28,6 +28,7 @@ import org.apache.sling.installer.api.In
import org.apache.sling.installer.api.tasks.ResourceState;
import org.apache.sling.installer.api.tasks.TaskResource;
import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
/**
* Mock RegisteredResource that simulates a bundle
@@ -188,4 +189,12 @@ public class MockBundleResource implemen
this.tempAttributes.put(key, value);
}
}
+
+ /**
+ * @see org.apache.sling.installer.api.tasks.TaskResource#getVersion()
+ */
+ public Version getVersion() {
+ final String vInfo = (String)this.getAttribute(Constants.BUNDLE_VERSION);
+ return (vInfo == null ? null : new Version(vInfo));
+ }
}