felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r484632 - /incubator/felix/trunk/tools/maven2/maven-osgi-plugin/src/main/java/org/apache/felix/tools/maven/plugin/OsgiJarMojo.java
Date Fri, 08 Dec 2006 15:11:43 GMT
Author: rickhall
Date: Fri Dec  8 07:11:42 2006
New Revision: 484632

URL: http://svn.apache.org/viewvc?view=rev&rev=484632
Log:
Fixed version number conversion to properly convert version numbers
with multiple '-' characters to the OSGi version syntax; patch submitted
by Steven Harris.

Modified:
    incubator/felix/trunk/tools/maven2/maven-osgi-plugin/src/main/java/org/apache/felix/tools/maven/plugin/OsgiJarMojo.java

Modified: incubator/felix/trunk/tools/maven2/maven-osgi-plugin/src/main/java/org/apache/felix/tools/maven/plugin/OsgiJarMojo.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/maven2/maven-osgi-plugin/src/main/java/org/apache/felix/tools/maven/plugin/OsgiJarMojo.java?view=diff&rev=484632&r1=484631&r2=484632
==============================================================================
--- incubator/felix/trunk/tools/maven2/maven-osgi-plugin/src/main/java/org/apache/felix/tools/maven/plugin/OsgiJarMojo.java
(original)
+++ incubator/felix/trunk/tools/maven2/maven-osgi-plugin/src/main/java/org/apache/felix/tools/maven/plugin/OsgiJarMojo.java
Fri Dec  8 07:11:42 2006
@@ -42,6 +42,11 @@
  * @description build an OSGi bundle jar
  */
 public class OsgiJarMojo extends AbstractMojo {
+    private static final java.util.regex.Pattern versionPattern =
+        java.util.regex.Pattern.compile("^(\\d+(\\.\\d+(\\.\\d+)?)?)-");
+    private static final String[] versionCompleters =
+        new String[] { ".0.0", ".0" };
+
     public static final String OSGI_REFERENCES = "osgi.references";
     public static final String AUTO_DETECT = "auto-detect";
 
@@ -678,14 +683,36 @@
 		}
 	}
 
+    private static String fixBundleVersion(String version) {
+        // Maven uses a '-' to separate the version qualifier, while
+        // OSGi uses a '.', so we need to convert the first '-' to a
+        // '.' and fill in any missing minor or micro version
+        // components if necessary.
+        final java.util.regex.Matcher matcher = versionPattern.matcher(version);
+        if (!matcher.lookingAt())
+            return version;
+
+        final StringBuffer sb = new StringBuffer(version.length());
+        sb.append(matcher.group(1));
+
+        int count = 0;
+        for ( int i = matcher.groupCount(); i != 0; --i )
+            if ( null != matcher.group( i ) )
+                ++count;
+
+        if ( 3 != count )
+            sb.append(versionCompleters[count - 1]);
+
+        sb.append('.');
+        sb.append(version.substring(matcher.end(), version.length()));
+        return sb.toString();
+    }
+
 	/**
 	 * Auto-set the bundle version.
 	 */
 	private void addBundleVersion() {
-        // Maven uses a '-' to separate the version qualifier,
-	    // while OSGi uses a '.', so we need to convert to a '.'
-        String version = project.getVersion().replace('-', '.');
-        osgiManifest.setBundleVersion(version);
+        osgiManifest.setBundleVersion(fixBundleVersion(project.getVersion()));
 	}
 
 	/**
@@ -832,4 +859,4 @@
 			}
 		}
     }
-}
\ No newline at end of file
+}



Mime
View raw message