maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r1059093 - in /maven/shared/trunk/maven-verifier/src: main/java/org/apache/maven/it/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/maven/ test/java/org/apache/maven/it/
Date Fri, 14 Jan 2011 18:17:21 GMT
Author: bentmann
Date: Fri Jan 14 18:17:21 2011
New Revision: 1059093

URL: http://svn.apache.org/viewvc?rev=1059093&view=rev
Log:
o Simplified extraction of Maven version

Added:
    maven/shared/trunk/maven-verifier/src/test/   (with props)
    maven/shared/trunk/maven-verifier/src/test/java/   (with props)
    maven/shared/trunk/maven-verifier/src/test/java/org/   (with props)
    maven/shared/trunk/maven-verifier/src/test/java/org/apache/   (with props)
    maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/   (with props)
    maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/   (with props)
    maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java
  (with props)
Modified:
    maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java

Modified: maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java?rev=1059093&r1=1059092&r2=1059093&view=diff
==============================================================================
--- maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java (original)
+++ maven/shared/trunk/maven-verifier/src/main/java/org/apache/maven/it/Verifier.java Fri
Jan 14 18:17:21 2011
@@ -57,6 +57,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.StringTokenizer;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.xml.parsers.ParserConfigurationException;
@@ -1439,39 +1440,10 @@ public class Verifier
             throw new VerificationException( "IO Error communicating with commandline " +
e.toString(), e );
         }
 
-        String version = null;
-
         List logLines = loadFile( logFile, false );
         logFile.delete();
 
-        for ( Iterator it = logLines.iterator(); version == null && it.hasNext();
)
-        {
-            String line = (String) it.next();
-
-            final String MAVEN_VERSION = "Maven version: ";
-
-            // look out for "Maven version: 3.0-SNAPSHOT built on unknown"
-            if ( line.regionMatches( true, 0, MAVEN_VERSION, 0, MAVEN_VERSION.length() )
)
-            {
-                version = line.substring( MAVEN_VERSION.length() ).trim();
-                if ( version.indexOf( ' ' ) >= 0 )
-                {
-                    version = version.substring( 0, version.indexOf( ' ' ) );
-                }
-            }
-
-            final String NEW_MAVEN_VERSION = "Apache Maven ";
-
-            // look out for "Apache Maven 2.1.0-M2-SNAPSHOT (rXXXXXX; date)"
-            if ( line.regionMatches( true, 0, NEW_MAVEN_VERSION, 0, NEW_MAVEN_VERSION.length()
) )
-            {
-                version = line.substring( NEW_MAVEN_VERSION.length() ).trim();
-                if ( version.indexOf( ' ' ) >= 0 )
-                {
-                    version = version.substring( 0, version.indexOf( ' ' ) );
-                }
-            }
-        }
+        String version = extractMavenVersion( logLines );
 
         if ( version == null )
         {
@@ -1484,6 +1456,26 @@ public class Verifier
         }
     }
 
+    static String extractMavenVersion( List logLines )
+    {
+        String version = null;
+
+        final Pattern MAVEN_VERSION = Pattern.compile( "(?i).*Maven [^0-9]*([0-9]\\S*).*"
);
+
+        for ( Iterator it = logLines.iterator(); version == null && it.hasNext();
)
+        {
+            String line = (String) it.next();
+
+            Matcher m = MAVEN_VERSION.matcher( line );
+            if ( m.matches() )
+            {
+                version = m.group( 1 );
+            }
+        }
+
+        return version;
+    }
+
     private static String getLogContents( File logFile )
     {
         try

Propchange: maven/shared/trunk/maven-verifier/src/test/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jan 14 18:17:21 2011
@@ -0,0 +1 @@
+MSHARED-\d+

Propchange: maven/shared/trunk/maven-verifier/src/test/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/shared/trunk/maven-verifier/src/test/java/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jan 14 18:17:21 2011
@@ -0,0 +1 @@
+MSHARED-\d+

Propchange: maven/shared/trunk/maven-verifier/src/test/java/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jan 14 18:17:21 2011
@@ -0,0 +1 @@
+MSHARED-\d+

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jan 14 18:17:21 2011
@@ -0,0 +1 @@
+MSHARED-\d+

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jan 14 18:17:21 2011
@@ -0,0 +1 @@
+MSHARED-\d+

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jan 14 18:17:21 2011
@@ -0,0 +1 @@
+MSHARED-\d+

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java?rev=1059093&view=auto
==============================================================================
--- maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java
(added)
+++ maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java
Fri Jan 14 18:17:21 2011
@@ -0,0 +1,43 @@
+package org.apache.maven.it;
+
+/*
+ * 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 java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class VerifierTest
+    extends TestCase
+{
+
+    public void testExtractMavenVersion()
+    {
+        assertEquals( "2.0.6", Verifier.extractMavenVersion( Arrays.asList( new String[]
{ "Maven version: 2.0.6" } ) ) );
+        assertEquals( "2.0.10",
+                      Verifier.extractMavenVersion( Arrays.asList( new String[] { "Maven
version: 2.0.10",
+                          "Java version: 1.5.0_22",
+                          "OS name: \"windows 7\" version: \"6.1\" arch: \"x86\" Family:
\"windows\"" } ) ) );
+        assertEquals( "3.0",
+                      Verifier.extractMavenVersion( Arrays.asList( new String[] {
+                          "Apache Maven 3.0 (r1004208; 2010-10-04 13:50:56+0200)", "Java
version: 1.5.0_22",
+                          "OS name: \"windows 7\" version: \"6.1\" arch: \"x86\" Family:
\"windows\"" } ) ) );
+    }
+
+}

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-verifier/src/test/java/org/apache/maven/it/VerifierTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message