maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fgi...@apache.org
Subject svn commit: r481639 - in /maven/plugins/trunk/maven-eclipse-plugin/src: main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java
Date Sat, 02 Dec 2006 22:05:25 GMT
Author: fgiust
Date: Sat Dec  2 14:05:24 2006
New Revision: 481639

URL: http://svn.apache.org/viewvc?view=rev&rev=481639
Log:
better conversion of OSGI->Maven version numbers. A parseable version for maven must use
the "-" separator for the build number

Modified:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java?view=diff&rev=481639&r1=481638&r2=481639
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java
(original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java
Sat Dec  2 14:05:24 2006
@@ -82,7 +82,7 @@
     private static final Pattern DEPLOYTO_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)" );
 
     /**
-     * A pattern for a 3 digit osgi version number.
+     * A pattern for a 4 digit osgi version number.
      */
     private static final Pattern VERSION_PATTERN = Pattern.compile( "(([0-9]+\\.)+[0-9]+)"
);
 
@@ -310,14 +310,7 @@
             return;
         }
 
-        if ( StringUtils.isNotEmpty( forcedQualifier ) && StringUtils.countMatches(
version, "." ) > 2 )
-        {
-            version = StringUtils.substring( version, 0, version.lastIndexOf( "." ) ) + "."
+ forcedQualifier;
-        }
-        else if ( stripQualifier && StringUtils.countMatches( version, "." ) >
2 )
-        {
-            version = StringUtils.substring( version, 0, version.lastIndexOf( "." ) );
-        }
+        version = osgiVersionToMavenVersion( version, forcedQualifier, stripQualifier );
 
         String name = manifestEntries.getValue( "Bundle-Name" );
 
@@ -332,7 +325,7 @@
         }
 
         String requireBundle = manifestEntries.getValue( "Require-Bundle" );
-        Dependency[] deps = parseDependencies( requireBundle, !this.stripQualifier );
+        Dependency[] deps = parseDependencies( requireBundle );
 
         String groupId = null;
         groupId = createGroupId( artifactId );
@@ -432,6 +425,36 @@
     }
 
     /**
+     * The 4th (build) token MUST be separed with "-" and not with "." in maven. A version
with 4 dots is not parsed,
+     * and the whole string is considered a qualifier. See tests in DefaultArtifactVersion
for reference.
+     * @param version initial version
+     * @param forcedQualifier build number
+     * @param stripQualifier always remove 4th token in version
+     * @return converted version
+     */
+    protected String osgiVersionToMavenVersion( String version, String forcedQualifier, boolean
stripQualifier )
+    {
+        if ( stripQualifier && StringUtils.countMatches( version, "." ) > 2 )
+        {
+            version = StringUtils.substring( version, 0, version.lastIndexOf( "." ) );
+        }
+        else if ( StringUtils.countMatches( version, "." ) > 2 )
+        {
+            int lastDot = version.lastIndexOf( "." );
+            if ( StringUtils.isNotEmpty( forcedQualifier ) )
+            {
+                version = StringUtils.substring( version, 0, lastDot ) + "-" + forcedQualifier;
+            }
+            else
+            {
+                version = StringUtils.substring( version, 0, lastDot ) + "-"
+                    + StringUtils.substring( version, lastDot + 1, version.length() );
+            }
+        }
+        return version;
+    }
+
+    /**
      * Resolves the deploy<code>deployTo</code> parameter to an <code>ArtifactRepository</code>
instance (if set).
      * 
      * @throws MojoFailureException
@@ -506,11 +529,9 @@
     /**
      * Parses the "Require-Bundle" and convert it to a list of dependencies.
      * @param requireBundle "Require-Bundle" entry
-     * @param addQualifier if true, a 4th version digit is added to dependency versions.
This is required for maven to
-     * allow dependencies with a qualifier to match the version range.
      * @return an array of <code>Dependency</code>
      */
-    protected Dependency[] parseDependencies( String requireBundle, boolean addQualifier
)
+    protected Dependency[] parseDependencies( String requireBundle )
     {
         if ( requireBundle == null )
         {
@@ -555,13 +576,11 @@
             if ( version == null )
             {
                 getLog().info( "Missing version for artifact " + artifactId + ", assuming
any version > 0" );
-                version = "[0.0.0.0,)";
-            }
-            else if ( addQualifier )
-            {
-                version = addQualifierToVersionsInRange( version );
+                version = "[0,)";
             }
 
+            version = fixBuildNumberSeparator( version );
+
             Dependency dep = new Dependency();
             dep.setArtifactId( artifactId );
             dep.setGroupId( createGroupId( artifactId ) );
@@ -576,14 +595,11 @@
     }
 
     /**
-     * Adds a qualifier (4th digit) to each version in a range. This is needed in maven poms
in order to make dependency
-     * ranges work when using qualifiers while generating artifacts.
-     * In maven the range <code>[3.2.0,4.0.0)</code> doesn't match version <code>3.2.100.v20060905</code>,
while
-     * <code>[3.2.0.0,4.0.0.0)</code> do.
+     * Fix the separator for the 4th token in a versions. In maven this must be "-", in OSGI
it's "."
      * @param versionRange input range
      * @return modified version range
      */
-    protected String addQualifierToVersionsInRange( String versionRange )
+    protected String fixBuildNumberSeparator( String versionRange )
     {
         // should not be called with a null versionRange, but a check doesn't hurt...
         if ( versionRange == null )
@@ -597,12 +613,16 @@
 
         while ( matcher.find() )
         {
-            String currentVersion = matcher.group();
-            int digitsToAdd = 3 - StringUtils.countMatches( currentVersion, "." );
-            if ( digitsToAdd > 0 )
+            String group = matcher.group();
+
+            if ( StringUtils.countMatches( group, "." ) > 2 )
             {
-                matcher.appendReplacement( newVersionRange, matcher.group() + ".0" );
+                // build number found, fix it
+                int lastDot = group.lastIndexOf( "." );
+                group = StringUtils.substring( group, 0, lastDot ) + "-"
+                    + StringUtils.substring( group, lastDot + 1, group.length() );
             }
+            matcher.appendReplacement( newVersionRange, group );
         }
 
         matcher.appendTail( newVersionRange );

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java?view=diff&rev=481639&r1=481638&r2=481639
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java
(original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java
Sat Dec  2 14:05:24 2006
@@ -49,7 +49,7 @@
     {
         Dependency[] deps = mojo.parseDependencies( "org.eclipse.ui;bundle-version=\"[3.2.0,4.0.0)\","
             + "org.eclipse.ui.console;resolution:=\"optional\";bundle-version=\"[3.1.100,4.0.0)\",org.eclipse.help;"
-            + "bundle-version=\"[3.2.0,4.0.0)\",org.eclipse.core.expressions;bundle-version=\"[3.2.0,4.0.0)\"",
false );
+            + "bundle-version=\"[3.2.0,4.0.0)\",org.eclipse.core.expressions;bundle-version=\"[3.2.0,4.0.0)\""
);
 
         assertEquals( 4, deps.length );
         assertEquals( "org.eclipse.ui", deps[0].getArtifactId() );
@@ -67,30 +67,20 @@
      */
     public void testParseDependenciesWithQualifier()
     {
-        Dependency[] deps = mojo.parseDependencies( "org.eclipse.ui;bundle-version=\"[3.2.0,4.0.0)\","
-            + "org.eclipse.ui.console;resolution:=\"optional\";bundle-version=\"[3.1.100,4.0.0)\",org.eclipse.help;"
-            + "bundle-version=\"[3.2.0,4.0.0)\",org.eclipse.core.expressions;bundle-version=\"[3.2.0,4.0.0)\"",
true );
+        Dependency[] deps = mojo
+            .parseDependencies( "org.eclipse.ui;bundle-version=\"[3.2.0.0,4.0.0.0)\","
+                + "org.eclipse.ui.console;resolution:=\"optional\";bundle-version=\"[3.1.100.0,4.0.0.0)\",org.eclipse.help;"
+                + "bundle-version=\"[3.2.0.1,4.0.0.2)\",org.eclipse.core.expressions;bundle-version=\"[3.2.0.0,4.0.0.0)\""
);
 
         assertEquals( 4, deps.length );
         assertEquals( "org.eclipse.ui", deps[0].getArtifactId() );
-        assertEquals( "[3.2.0.0,4.0.0.0)", deps[0].getVersion() );
+        assertEquals( "[3.2.0-0,4.0.0-0)", deps[0].getVersion() );
         assertEquals( "org.eclipse.ui.console", deps[1].getArtifactId() );
-        assertEquals( "[3.1.100.0,4.0.0.0)", deps[1].getVersion() );
+        assertEquals( "[3.1.100-0,4.0.0-0)", deps[1].getVersion() );
         assertEquals( "org.eclipse.help", deps[2].getArtifactId() );
-        assertEquals( "[3.2.0.0,4.0.0.0)", deps[2].getVersion() );
+        assertEquals( "[3.2.0-1,4.0.0-2)", deps[2].getVersion() );
         assertEquals( "org.eclipse.core.expressions", deps[3].getArtifactId() );
-        assertEquals( "[3.2.0.0,4.0.0.0)", deps[3].getVersion() );
-    }
-
-    /**
-     * Tests for addQualifierToVersionsInRange()
-     *
-     */
-    public void testAddQualifierToVersionsInRange()
-    {
-        assertEquals( "[3.2.0.0,4.0.0.0)", mojo.addQualifierToVersionsInRange( "[3.2.0,4.0.0)"
) );
-        assertEquals( "[,4.0.0.0)", mojo.addQualifierToVersionsInRange( "[,4.0.0)" ) );
-        assertEquals( "[3.2.0.0,4.0.0.0)", mojo.addQualifierToVersionsInRange( "[3.2.0.0,4.0.0.0)"
) );
+        assertEquals( "[3.2.0-0,4.0.0-0)", deps[3].getVersion() );
     }
 
     /**
@@ -103,5 +93,18 @@
         assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt" ) );
         assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt.apt" ) );
         assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt.apt.core" )
);
+    }
+
+    public void testOsgiVersionToMavenVersion()
+    {
+        assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", null, false ) );
+        assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", "20060101", false
) );
+        assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", null, true ) );
+        assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", "20060101", true
) );
+
+        assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3.1", null, true ) );
+        assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3.1", "20060101", true
) );
+        assertEquals( "1.2.3-20060101", mojo.osgiVersionToMavenVersion( "1.2.3.1", "20060101",
false ) );
+        assertEquals( "1.2.3-1", mojo.osgiVersionToMavenVersion( "1.2.3.1", null, false )
);
     }
 }



Mime
View raw message