felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r919426 - in /felix/trunk/bundleplugin/src: main/java/org/apache/felix/bundleplugin/BundlePlugin.java main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
Date Fri, 05 Mar 2010 14:12:41 GMT
Author: gnodet
Date: Fri Mar  5 14:12:41 2010
New Revision: 919426

URL: http://svn.apache.org/viewvc?rev=919426&view=rev
Log:
FELIX-2173: Fix inconsistent maven->osgi version conversion between maven-bundle-plugin
and DefaultMaven2OsgiConverter

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
    felix/trunk/bundleplugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java
    felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=919426&r1=919425&r2=919426&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
(original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
Fri Mar  5 14:12:41 2010
@@ -852,7 +852,7 @@
         properties.put( MAVEN_SYMBOLICNAME, bsn );
         properties.put( Analyzer.BUNDLE_SYMBOLICNAME, bsn );
         properties.put( Analyzer.IMPORT_PACKAGE, "*" );
-        properties.put( Analyzer.BUNDLE_VERSION, currentProject.getVersion() );
+        properties.put( Analyzer.BUNDLE_VERSION, getMaven2OsgiConverter().getVersion(currentProject.getVersion())
);
 
         // remove the extraneous Include-Resource and Private-Package entries from generated
manifest
         properties.put( Analyzer.REMOVE_HEADERS, Analyzer.INCLUDE_RESOURCE + ',' + Analyzer.PRIVATE_PACKAGE
);

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java?rev=919426&r1=919425&r2=919426&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java
(original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java
Fri Mar  5 14:12:41 2010
@@ -46,15 +46,6 @@
     implements Maven2OsgiConverter
 {
 
-    /** Bundle-Version must match this pattern */
-    private static final Pattern OSGI_VERSION_PATTERN = Pattern
-        .compile( "[0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9A-Za-z_-]+)?" );
-
-    /** pattern used to change - to . */
-    // private static final Pattern P_VERSION = Pattern.compile("([0-9]+(\\.[0-9])*)-(.*)");
-    /** pattern that matches strings that contain only numbers */
-    private static final Pattern ONLY_NUMBERS = Pattern.compile( "[0-9]+" );
-
     private static final String FILE_SEPARATOR = System.getProperty( "file.separator" );
 
     private String getBundleSymbolicName( String groupId, String artifactId )
@@ -244,139 +235,70 @@
 
     public String getVersion( String version )
     {
-        String osgiVersion;
-
-        // Matcher m = P_VERSION.matcher(version);
-        // if (m.matches()) {
-        // osgiVersion = m.group(1) + "." + m.group(3);
-        // }
-
-        /* TODO need a regexp guru here */
-
-        Matcher m;
-
-        /* if it's already OSGi compliant don't touch it */
-        m = OSGI_VERSION_PATTERN.matcher( version );
-        if ( m.matches() )
-        {
-            return version;
-        }
-
-        osgiVersion = version;
-
-        /* check for dated snapshot versions with only major or major and minor */
-        Pattern DATED_SNAPSHOT = Pattern.compile( "([0-9])(\\.([0-9]))?(\\.([0-9]))?\\-([0-9]{8}\\.[0-9]{6}\\-[0-9]*)"
);
-        m = DATED_SNAPSHOT.matcher( osgiVersion );
-        if ( m.matches() )
-        {
-            String major = m.group( 1 );
-            String minor = ( m.group( 3 ) != null ) ? m.group( 3 ) : "0";
-            String service = ( m.group( 5 ) != null ) ? m.group( 5 ) : "0";
-            String qualifier = m.group( 6 ).replaceAll( "-", "_" ).replaceAll( "\\.", "_"
);
-            osgiVersion = major + "." + minor + "." + service + "." + qualifier;
-        }
-
-        /* else transform first - to . and others to _ */
-        osgiVersion = osgiVersion.replaceFirst( "-", "\\." );
-        osgiVersion = osgiVersion.replaceAll( "-", "_" );
-        m = OSGI_VERSION_PATTERN.matcher( osgiVersion );
-        if ( m.matches() )
-        {
-            return osgiVersion;
-        }
-
-        /* remove dots in the middle of the qualifier */
-        Pattern DOTS_IN_QUALIFIER = Pattern.compile( "([0-9])(\\.[0-9])?\\.([0-9A-Za-z_-]+)\\.([0-9A-Za-z_-]+)"
);
-        m = DOTS_IN_QUALIFIER.matcher( osgiVersion );
-        if ( m.matches() )
-        {
-            String s1 = m.group( 1 );
-            String s2 = m.group( 2 );
-            String s3 = m.group( 3 );
-            String s4 = m.group( 4 );
-
-            Matcher qualifierMatcher = ONLY_NUMBERS.matcher( s3 );
-            /*
-             * if last portion before dot is only numbers then it's not in the middle of
the
-             * qualifier
-             */
-            if ( !qualifierMatcher.matches() )
-            {
-                osgiVersion = s1 + s2 + "." + s3 + "_" + s4;
-            }
-        }
+        return cleanupVersion(version);
+    }
 
-        /* convert
-         * 1.string   -> 1.0.0.string
-         * 1.2.string -> 1.2.0.string
-         * 1          -> 1.0.0
-         * 1.1        -> 1.1.0
-         */
-        //Pattern NEED_TO_FILL_ZEROS = Pattern.compile( "([0-9])(\\.([0-9]))?\\.([0-9A-Za-z_-]+)"
);
-        Pattern NEED_TO_FILL_ZEROS = Pattern.compile( "([0-9])(\\.([0-9]))?(\\.([0-9A-Za-z_-]+))?"
);
-        m = NEED_TO_FILL_ZEROS.matcher( osgiVersion );
-        if ( m.matches() )
-        {
-            String major = m.group( 1 );
-            String minor = m.group( 3 );
-            String service = null;
-            String qualifier = m.group( 5 );
+    /**
+     * Clean up version parameters. Other builders use more fuzzy definitions of
+     * the version syntax. This method cleans up such a version to match an OSGi
+     * version.
+     *
+     * @param VERSION_STRING
+     * @return
+     */
+    static final Pattern FUZZY_VERSION = Pattern.compile("(\\d+)(\\.(\\d+)(\\.(\\d+))?)?([^a-zA-Z0-9](.*))?",
+                                                         Pattern.DOTALL);
 
-            /* if there's no qualifier just fill with 0s */
-            if ( qualifier == null )
-            {
-                osgiVersion = getVersion( major, minor, service, qualifier );
-            }
-            else
-            {
-                /* if last portion is only numbers then it's not a qualifier */
-                Matcher qualifierMatcher = ONLY_NUMBERS.matcher( qualifier );
-                if ( qualifierMatcher.matches() )
-                {
-                    if ( minor == null )
-                    {
-                        minor = qualifier;
-                    }
-                    else
-                    {
-                        service = qualifier;
+    static public String cleanupVersion(String version) {
+        StringBuffer result = new StringBuffer();
+        Matcher m = FUZZY_VERSION.matcher(version);
+        if (m.matches()) {
+            String major = m.group(1);
+            String minor = m.group(3);
+            String micro = m.group(5);
+            String qualifier = m.group(7);
+
+            if (major != null) {
+                result.append(major);
+                if (minor != null) {
+                    result.append(".");
+                    result.append(minor);
+                    if (micro != null) {
+                        result.append(".");
+                        result.append(micro);
+                        if (qualifier != null) {
+                            result.append(".");
+                            cleanupModifier(result, qualifier);
+                        }
+                    } else if (qualifier != null) {
+                        result.append(".0.");
+                        cleanupModifier(result, qualifier);
+                    } else {
+                        result.append(".0");
                     }
-                    osgiVersion = getVersion( major, minor, service, null );
-                }
-                else
-                {
-                    osgiVersion = getVersion( major, minor, service, qualifier );
+                } else if (qualifier != null) {
+                    result.append(".0.0.");
+                    cleanupModifier(result, qualifier);
+                } else {
+                    result.append(".0.0");
                 }
             }
+        } else {
+            result.append("0.0.0.");
+            cleanupModifier(result, version);
         }
-
-        m = OSGI_VERSION_PATTERN.matcher( osgiVersion );
-        /* if still its not OSGi version then add everything as qualifier */
-        if ( !m.matches() )
-        {
-            String major = "0";
-            String minor = "0";
-            String service = "0";
-            String qualifier = osgiVersion.replaceAll( "\\.", "_" );
-            osgiVersion = major + "." + minor + "." + service + "." + qualifier;
-        }
-
-        return osgiVersion;
+        return result.toString();
     }
 
-    private String getVersion( String major, String minor, String service, String qualifier
)
-    {
-        StringBuffer sb = new StringBuffer();
-        sb.append( major != null ? major : "0" );
-        sb.append( '.' );
-        sb.append( minor != null ? minor : "0" );
-        sb.append( '.' );
-        sb.append( service != null ? service : "0" );
-        if ( qualifier != null )
-        {
-            sb.append( '.' );
-            sb.append( qualifier );
+    static void cleanupModifier(StringBuffer result, String modifier) {
+        for (int i = 0; i < modifier.length(); i++) {
+            char c = modifier.charAt(i);
+            if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')
+                    || (c >= 'A' && c <= 'Z') || c == '_' || c == '-')
+                result.append(c);
+            else
+                result.append('_');
         }
-        return sb.toString();
     }
+
 }

Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java?rev=919426&r1=919425&r2=919426&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
(original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
Fri Mar  5 14:12:41 2010
@@ -83,22 +83,22 @@
         assertEquals( "2.1.3.4", osgiVersion );
 
         osgiVersion = plugin.convertVersionToOsgi( "4aug2000r7-dev" );
-        assertEquals( "0.0.0.4aug2000r7_dev", osgiVersion );
+        assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion );
 
         osgiVersion = plugin.convertVersionToOsgi( "1.1-alpha-2" );
-        assertEquals( "1.1.0.alpha_2", osgiVersion );
+        assertEquals( "1.1.0.alpha-2", osgiVersion );
 
         osgiVersion = plugin.convertVersionToOsgi( "1.0-alpha-16-20070122.203121-13" );
-        assertEquals( "1.0.0.alpha_16_20070122_203121_13", osgiVersion );
+        assertEquals( "1.0.0.alpha-16-20070122_203121-13", osgiVersion );
 
         osgiVersion = plugin.convertVersionToOsgi( "1.0-20070119.021432-1" );
-        assertEquals( "1.0.0.20070119_021432_1", osgiVersion );
+        assertEquals( "1.0.0.20070119_021432-1", osgiVersion );
 
         osgiVersion = plugin.convertVersionToOsgi( "1-20070119.021432-1" );
-        assertEquals( "1.0.0.20070119_021432_1", osgiVersion );
+        assertEquals( "1.0.0.20070119_021432-1", osgiVersion );
 
         osgiVersion = plugin.convertVersionToOsgi( "1.4.1-20070217.082013-7" );
-        assertEquals( "1.4.1.20070217_082013_7", osgiVersion );
+        assertEquals( "1.4.1.20070217_082013-7", osgiVersion );
     }
 
 



Mime
View raw message