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 2017/05/26 08:52:35 UTC
svn commit: r1796256 - in /sling/whiteboard/cziegeler/provisioning-model: ./
src/main/java/org/apache/sling/feature/
src/test/java/org/apache/sling/feature/
Author: cziegeler
Date: Fri May 26 08:52:34 2017
New Revision: 1796256
URL: http://svn.apache.org/viewvc?rev=1796256&view=rev
Log:
Use OSGi Version class
Added:
sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/ArtifactIdTest.java
- copied, changed from r1796255, sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/VersionTest.java
Removed:
sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/Version.java
sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/VersionRange.java
sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/VersionTest.java
Modified:
sling/whiteboard/cziegeler/provisioning-model/pom.xml
sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/ArtifactId.java
Modified: sling/whiteboard/cziegeler/provisioning-model/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/pom.xml?rev=1796256&r1=1796255&r2=1796256&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/pom.xml (original)
+++ sling/whiteboard/cziegeler/provisioning-model/pom.xml Fri May 26 08:52:34 2017
@@ -51,6 +51,10 @@
</build>
<dependencies>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
<version>1.0-alpha-1</version>
Modified: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/ArtifactId.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/ArtifactId.java?rev=1796256&r1=1796255&r2=1796256&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/ArtifactId.java (original)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/ArtifactId.java Fri May 26 08:52:34 2017
@@ -16,6 +16,8 @@
*/
package org.apache.sling.feature;
+import org.osgi.framework.Version;
+
/**
* An artifact identifier.
* An artifact is described by it's Apache Maven coordinates consisting of group id, artifact id, and version.
@@ -25,13 +27,17 @@ public class ArtifactId implements Compa
/** The required group id. */
private final String groupId;
+
/** The required artifact id. */
private final String artifactId;
+
/** The required version. */
- private final Version version;
+ private final String version;
+
/** The optional classifier. */
private final String classifier;
- /** The optional type. */
+
+ /** The required type. Defaults to jar. */
private final String type;
/**
@@ -54,7 +60,7 @@ public class ArtifactId implements Compa
}
this.groupId = groupId;
this.artifactId = artifactId;
- this.version = new Version(version);
+ this.version = version;
if ( "bundle".equals(type) || type == null || type.isEmpty() ) {
this.type = "jar";
} else {
@@ -124,24 +130,6 @@ public class ArtifactId implements Compa
return new ArtifactId(gId, aId, version, classifier, type);
}
- @Override
- public int hashCode() {
- return toMvnUrl().hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- if(o == null) return false;
- if(!(o instanceof ArtifactId)) return false;
- return toMvnUrl().equals(((ArtifactId)o).toMvnUrl());
- }
-
- @Override
- public int compareTo(final ArtifactId o) {
- if(o == null) return 1;
- return toMvnUrl().compareTo(o.toMvnUrl());
- }
-
/**
* Return a mvn url
* @return A mvn url
@@ -153,7 +141,7 @@ public class ArtifactId implements Compa
sb.append('/');
sb.append(this.artifactId);
sb.append('/');
- sb.append(this.version);
+ sb.append(version);
if ( this.classifier != null || !"jar".equals(this.type)) {
sb.append('/');
sb.append(this.type);
@@ -185,10 +173,31 @@ public class ArtifactId implements Compa
* Return the version.
* @return The version.
*/
- public Version getVersion() {
+ public String getVersion() {
return version;
}
+ public Version getOSGiVersion() {
+ final int qualifier = this.version.indexOf('-');
+ if ( qualifier == -1 ) {
+ return new Version(this.version);
+ }
+ int dots = 0;
+ int index = 0;
+ while ( index < qualifier) {
+ if ( this.version.charAt(index) == '.') {
+ dots++;
+ }
+ index++;
+ }
+ if ( dots >= 2 ) {
+ return new Version(this.version.replace('-', '.'));
+ } else if ( dots == 1 ) {
+ return new Version(this.version.substring(0, qualifier) + ".0." + this.version.substring(qualifier + 1));
+ }
+ return new Version(this.version.substring(0, qualifier) + ".0.0." + this.version.substring(qualifier + 1));
+ }
+
/**
* Return the optional classifier.
* @return The classifier or null.
@@ -209,7 +218,7 @@ public class ArtifactId implements Compa
* Create a Maven like relative repository path.
* @return A relative repository path.
*/
- public String getRepositoryPath() {
+ public String toMvnPath() {
final StringBuilder sb = new StringBuilder();
sb.append(groupId.replace('.', '/'));
sb.append('/');
@@ -230,12 +239,25 @@ public class ArtifactId implements Compa
}
@Override
+ public int hashCode() {
+ return toMvnUrl().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if(o == null) return false;
+ if(!(o instanceof ArtifactId)) return false;
+ return toMvnUrl().equals(((ArtifactId)o).toMvnUrl());
+ }
+
+ @Override
+ public int compareTo(final ArtifactId o) {
+ if(o == null) return 1;
+ return toMvnUrl().compareTo(o.toMvnUrl());
+ }
+
+ @Override
public String toString() {
- return "Artifact [groupId=" + groupId
- + ", artifactId=" + artifactId
- + ", version=" + version
- + ", classifier=" + classifier
- + ", type=" + type
- + "]";
+ return toMvnUrl().substring(4);
}
}
Copied: sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/ArtifactIdTest.java (from r1796255, sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/VersionTest.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/ArtifactIdTest.java?p2=sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/ArtifactIdTest.java&p1=sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/VersionTest.java&r1=1796255&r2=1796256&rev=1796256&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/VersionTest.java (original)
+++ sling/whiteboard/cziegeler/provisioning-model/src/test/java/org/apache/sling/feature/ArtifactIdTest.java Fri May 26 08:52:34 2017
@@ -20,8 +20,12 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.osgi.framework.Version;
-public class VersionTest {
+public class ArtifactIdTest {
+
+ private static final String G = "g";
+ private static final String A = "a";
@Test
public void testSameVersion() {
@@ -29,9 +33,9 @@ public class VersionTest {
final String v10 = "1.0";
final String v100 = "1.0.0";
- final Version ve1 = new Version(v1);
- final Version ve10 = new Version(v10);
- final Version ve100 = new Version(v100);
+ final Version ve1 = new ArtifactId(G, A, v1, null, null).getOSGiVersion();
+ final Version ve10 = new ArtifactId(G, A, v10, null, null).getOSGiVersion();
+ final Version ve100 = new ArtifactId(G, A, v100, null, null).getOSGiVersion();
assertEquals(0, ve1.compareTo(ve10));
assertEquals(0, ve10.compareTo(ve100));
@@ -47,9 +51,9 @@ public class VersionTest {
final String v20 = "2.0";
final String v150 = "1.5.0";
- final Version ve1 = new Version(v1);
- final Version ve20 = new Version(v20);
- final Version ve150 = new Version(v150);
+ final Version ve1 = new ArtifactId(G, A, v1, null, null).getOSGiVersion();
+ final Version ve20 = new ArtifactId(G, A, v20, null, null).getOSGiVersion();
+ final Version ve150 = new ArtifactId(G, A, v150, null, null).getOSGiVersion();
assertTrue(ve1.compareTo(ve20) < 0);
assertTrue(ve20.compareTo(ve150) > 0);
@@ -61,27 +65,27 @@ public class VersionTest {
@Test
public void testSnapshotQualifier() {
- final Version v1 = new Version("1");
- final Version v1snapshot = new Version("1-SNAPSHOT");
- final Version v1a = new Version("1-A");
-
- // snapshot is lower than the corresponding version
- assertTrue(v1.compareTo(v1snapshot) > 0);
- assertTrue(v1snapshot.compareTo(v1) < 0);
+ final Version v1 = new ArtifactId(G, A, "1", null, null).getOSGiVersion();
+ final Version v1snapshot = new ArtifactId(G, A, "1-SNAPSHOT", null, null).getOSGiVersion();
+ final Version v1a = new ArtifactId(G, A, "1-A", null, null).getOSGiVersion();
+
+ // snapshot in OSGi is higher than the corresponding version
+ assertTrue(v1.compareTo(v1snapshot) < 0);
+ assertTrue(v1snapshot.compareTo(v1) > 0);
// qualifier is higher than the version
assertTrue(v1a.compareTo(v1) > 0);
assertTrue(v1.compareTo(v1a) < 0);
- // qualifier is higher than snapshot
- assertTrue(v1a.compareTo(v1snapshot) > 0);
- assertTrue(v1snapshot.compareTo(v1a) < 0);
+ // qualifier in OSGi is lower than snapshot (A is lower than SNAPSHOT)
+ assertTrue(v1a.compareTo(v1snapshot) < 0);
+ assertTrue(v1snapshot.compareTo(v1a) > 0);
}
@Test
public void testQualifiers() {
- final Version va = new Version("1-A");
- final Version vb = new Version("1-B");
+ final Version va = new ArtifactId(G, A, "1-A", null, null).getOSGiVersion();
+ final Version vb = new ArtifactId(G, A, "1-B", null, null).getOSGiVersion();
assertTrue(va.compareTo(vb) < 0);
assertTrue(vb.compareTo(va) > 0);
@@ -89,10 +93,10 @@ public class VersionTest {
@Test
public void testOSGiVersion() {
- final Version v = new Version("1.5.2.SNAPSHOT");
- assertEquals(1, v.getMajorVersion());
- assertEquals(5, v.getMinorVersion());
- assertEquals(2, v.getMicroVersion());
+ final Version v = new ArtifactId(G, A, "1.5.2.SNAPSHOT", null, null).getOSGiVersion();
+ assertEquals(1, v.getMajor());
+ assertEquals(5, v.getMinor());
+ assertEquals(2, v.getMicro());
assertEquals("SNAPSHOT", v.getQualifier());
}
}