Replace float comparision with String comparison, otherwise the floats 4.1.x and 4.10.x are considered the same version

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1747973 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java b/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
index 450b026..3e0f93a 100644
--- a/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
+++ b/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.IOUtil;
 
@@ -63,13 +64,15 @@
     }
 
     /**
-     * Get Maven version as major.minor float
+     * Returns a positive value if the version parameter is bigger compared to the runtime Maven version
+     * Returns a negative value if the version parameter is less compared to the runtime Maven version
+     * Returns 0 if they are the same.
      * 
-     * @return
+     * @param version the version to compare
+     * @return 
      */
-    public static float getMavenVersionAsFloat()
+    public static int compareToVersion( String version )
     {
-        String[] digits = getMavenVersion().split( "\\." );
-        return Float.parseFloat( digits[0] + '.' + digits[1] );
+        return new DefaultArtifactVersion( version ).compareTo( new DefaultArtifactVersion( getMavenVersion() ) );
     }
 }
diff --git a/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java b/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
index fea225b..5fa4401 100644
--- a/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
+++ b/src/main/java/org/apache/maven/shared/project/utils/AnsiUtils.java
@@ -28,7 +28,7 @@
  */
 public class AnsiUtils
 {
-    private static final float MINIMUM_MAVEN_VERSION = 3.4f; // color added in Maven 3.4.0: see MNG-3507
+    private static final String MINIMUM_MAVEN_VERSION = "3.4.0"; // color added in Maven 3.4.0: see MNG-3507
 
     private AnsiUtils()
     {
@@ -37,7 +37,7 @@
     public static void systemInstall()
     {
         AnsiConsole.systemInstall();
-        if ( MavenUtils.getMavenVersionAsFloat() < MINIMUM_MAVEN_VERSION )
+        if ( MavenUtils.compareToVersion( MINIMUM_MAVEN_VERSION ) >= 0 )
         {
             // ANSI color support was added in Maven 3.4.0: don't enable color if executing older Maven versions
             Ansi.setEnabled( false );
diff --git a/src/test/java/org/apache/maven/shared/project/runtime/MavenUtilsTest.java b/src/test/java/org/apache/maven/shared/project/runtime/MavenUtilsTest.java
new file mode 100644
index 0000000..ab73561
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/project/runtime/MavenUtilsTest.java
@@ -0,0 +1,36 @@
+package org.apache.maven.shared.project.runtime;

+

+/*

+ * 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 MavenUtilsTest

+{

+

+    @Test

+    public void testCompareToVersion()

+    {

+        assertTrue( MavenUtils.compareToVersion( "101.0.0" ) > 0 );

+        assertTrue( MavenUtils.compareToVersion( MavenUtils.getMavenVersion() ) == 0 );

+        assertTrue( MavenUtils.compareToVersion( "0.0.1" ) < 0 );

+    }

+}