You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2017/07/08 19:03:09 UTC

svn commit: r1801315 - in /maven/plugins/trunk/maven-javadoc-plugin/src: main/java/org/apache/maven/plugin/javadoc/JavadocVersion.java test/java/org/apache/maven/plugin/javadoc/JavadocVersionTest.java

Author: rfscholte
Date: Sat Jul  8 19:03:08 2017
New Revision: 1801315

URL: http://svn.apache.org/viewvc?rev=1801315&view=rev
Log:
[MJAVADOC-485] Upgrade to commons-lang3
Introduce JavadocVersion, first step to get rid of floats comparison

Added:
    maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocVersion.java
    maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocVersionTest.java

Added: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocVersion.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocVersion.java?rev=1801315&view=auto
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocVersion.java (added)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocVersion.java Sat Jul  8 19:03:08 2017
@@ -0,0 +1,86 @@
+package org.apache.maven.plugin.javadoc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Once the plugin requires Java9, this class can be replaced with java.lang.Runtime.Version
+ * <p>
+ * <strong>Note: </strong> Ensure the methods match, although parse+compareTo+toString should be enough.
+ * </p>
+ * 
+ * 
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+public class JavadocVersion implements Comparable<JavadocVersion>
+{
+    private String rawVersion;
+
+    private JavadocVersion( String rawVersion )
+    {
+        if ( StringUtils.isEmpty( rawVersion ) )
+        {
+            throw new IllegalArgumentException( "The rawVersion could not be null." );
+        }
+        this.rawVersion = rawVersion;
+    }
+
+    /**
+     * Parser only the version-scheme.
+     * 
+     * @param s the version string
+     * @return the version wrapped in a JavadocVersion
+     */
+    static JavadocVersion parse( String s ) {
+        return new JavadocVersion( s );
+    }
+
+    @Override
+    public int compareTo( JavadocVersion other )
+    {
+        String[] thisSegments = this.rawVersion.split( "\\." );
+        String[] otherSegments = other.rawVersion.split( "\\." );
+        
+        int minSegments = Math.min( thisSegments.length, otherSegments.length );
+        
+        for ( int index = 0; index < minSegments; index++ )
+        {
+            int thisValue = Integer.parseInt( thisSegments[index] );
+            int otherValue = Integer.parseInt( otherSegments[index] );
+            
+            int compareValue = Integer.compare( thisValue, otherValue );
+            
+            if ( compareValue != 0 )
+            {
+                return compareValue;
+            }
+        }
+        
+        return ( thisSegments.length - otherSegments.length );
+    }
+
+    @Override
+    public String toString()
+    {
+        return rawVersion;
+    }
+}

Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocVersionTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocVersionTest.java?rev=1801315&view=auto
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocVersionTest.java (added)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocVersionTest.java Sat Jul  8 19:03:08 2017
@@ -0,0 +1,48 @@
+package org.apache.maven.plugin.javadoc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class JavadocVersionTest
+{
+    /**
+     * Parsing is lazy, only triggered when comparing
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testParse() throws Exception
+    {
+        assertTrue( JavadocVersion.parse( "1.4" ).compareTo( JavadocVersion.parse( "1.4.2" ) ) < 0 );
+        assertTrue( JavadocVersion.parse( "1.4" ).compareTo( JavadocVersion.parse( "1.5" ) ) < 0 );
+        assertTrue( JavadocVersion.parse( "1.8" ).compareTo( JavadocVersion.parse( "9" ) ) < 0 );
+
+        assertTrue( JavadocVersion.parse( "1.4" ).compareTo( JavadocVersion.parse( "1.4" ) ) == 0 );
+        assertTrue( JavadocVersion.parse( "1.4.2" ).compareTo( JavadocVersion.parse( "1.4.2" ) ) == 0 );
+        assertTrue( JavadocVersion.parse( "9" ).compareTo( JavadocVersion.parse( "9" ) ) == 0 );
+
+        assertTrue( JavadocVersion.parse( "1.4.2" ).compareTo( JavadocVersion.parse( "1.4" ) ) > 0 );
+        assertTrue( JavadocVersion.parse( "1.5" ).compareTo( JavadocVersion.parse( "1.4" ) ) > 0 );
+        assertTrue( JavadocVersion.parse( "9" ).compareTo( JavadocVersion.parse( "1.8" ) ) > 0 );
+    }
+}