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 2013/09/01 11:38:51 UTC

svn commit: r1519255 - in /maven/plugins/trunk/maven-eclipse-plugin: ./ src/test/java/org/apache/maven/plugin/eclipse/it/

Author: rfscholte
Date: Sun Sep  1 09:38:51 2013
New Revision: 1519255

URL: http://svn.apache.org/r1519255
Log:
Add support skipping tests based on Maven version
Add skip condition for EclipsePluginIT.testProject13 due to MNG-5509

Added:
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java
Modified:
    maven/plugins/trunk/maven-eclipse-plugin/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java

Modified: maven/plugins/trunk/maven-eclipse-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/pom.xml?rev=1519255&r1=1519254&r2=1519255&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/pom.xml Sun Sep  1 09:38:51 2013
@@ -200,6 +200,12 @@ under the License.
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-invoker</artifactId>
+      <version>2.1.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.2</version>

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java?rev=1519255&r1=1519254&r2=1519255&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/AbstractEclipsePluginIT.java Sun Sep  1 09:38:51 2013
@@ -123,6 +123,8 @@ public abstract class AbstractEclipsePlu
      * .classpath file name
      */
     private static final String CLASSPATH_FILENAME = ".classpath";
+    
+    private File mavenHome;
 
     /**
      * @see org.codehaus.plexus.PlexusTestCase#setUp()
@@ -149,14 +151,20 @@ public abstract class AbstractEclipsePlu
         {
             String path = System.getProperty( "java.library.path" );
             String[] paths = StringUtils.split( path, System.getProperty( "path.separator" ) );
-            for (String pt : paths) {
-                if (new File(pt, "mvn").exists()) {
-                    System.setProperty("maven.home", new File(pt).getAbsoluteFile().getParent());
+            for ( String pt : paths )
+            {
+                if ( new File( pt, "mvn" ).exists() )
+                {
+                    System.setProperty( "maven.home", mavenHome = new File( pt ).getAbsoluteFile().getParent() );
                     break;
                 }
-
             }
         }
+        
+        if ( mavenHome != null )
+        {
+            this.mavenHome = new File( mavenHome );
+        }
 
         System.setProperty( "MAVEN_TERMINATE_CMD", "on" );
 
@@ -220,6 +228,11 @@ public abstract class AbstractEclipsePlu
         }
     }
 
+    protected final File getMavenHome()
+    {
+        return mavenHome;
+    }
+    
     /**
      * Execute the eclipse:eclipse goal on a test project and verify generated files.
      *

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java?rev=1519255&r1=1519254&r2=1519255&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/EclipsePluginIT.java Sun Sep  1 09:38:51 2013
@@ -146,7 +146,15 @@ public class EclipsePluginIT
     public void testProject13()
         throws Exception
     {
-        testProject( "project-13" );
+        String mavenVersion = SelectorUtils.getMavenVersion( getMavenHome() );
+        if( SelectorUtils.isMavenVersion( "!3.0.5, !3.1.0-alpha-1, !3.1.0", mavenVersion ) )
+        {
+            testProject( "project-13" );
+        }
+        else
+        {
+            System.out.println( "  Skipping project-13 due to Maven version" );
+        }
     }
 
     /**

Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java?rev=1519255&view=auto
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java Sun Sep  1 09:38:51 2013
@@ -0,0 +1,284 @@
+package org.apache.maven.plugin.eclipse.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.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Provides utility methods for selecting build jobs based on environmental conditions.
+ * 
+ * From org.apache.maven.plugin.invoker.SelectorUtils
+ *
+ * @author Benjamin Bentmann
+ */
+class SelectorUtils
+{
+
+    static void parseList( String list, Collection<String> includes, Collection<String> excludes )
+    {
+        String[] tokens = ( list != null ) ? StringUtils.split( list, "," ) : new String[0];
+
+        for ( int i = 0; i < tokens.length; i++ )
+        {
+            String token = tokens[i].trim();
+
+            if ( token.startsWith( "!" ) )
+            {
+                excludes.add( token.substring( 1 ) );
+            }
+            else
+            {
+                includes.add( token );
+            }
+        }
+    }
+
+    static boolean isOsFamily( String osSpec )
+    {
+        List<String> includes = new ArrayList<String>();
+        List<String> excludes = new ArrayList<String>();
+        parseList( osSpec, includes, excludes );
+
+        return isOsFamily( includes, true ) && !isOsFamily( excludes, false );
+    }
+
+    static boolean isOsFamily( List<String> families, boolean defaultMatch )
+    {
+        if ( families != null && !families.isEmpty() )
+        {
+            for ( String family : families )
+            {
+                if ( Os.isFamily( family ) )
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+        else
+        {
+            return defaultMatch;
+        }
+    }
+
+    /**
+     * Retrieves the current Maven version.
+     * @return The current Maven version.
+     */
+    static String getMavenVersion()
+    {
+        try
+        {
+            // This relies on the fact that MavenProject is the in core classloader
+            // and that the core classloader is for the maven-core artifact
+            // and that should have a pom.properties file
+            // if this ever changes, we will have to revisit this code.
+            Properties properties = new Properties();
+            properties.load( MavenProject.class.getClassLoader().getResourceAsStream(
+                "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) );
+            return StringUtils.trim( properties.getProperty( "version" ) );
+        }
+        catch ( Exception e )
+        {
+            return null;
+        }
+    }
+    
+    static String getMavenVersion( File mavenHome )
+    {
+        File mavenLib = new File( mavenHome, "lib" );
+        File[] jarFiles = mavenLib.listFiles( new FilenameFilter()
+        {
+            public boolean accept( File dir, String name )
+            {
+                return name.endsWith( ".jar" );
+            }
+        } );
+
+        for ( File file : jarFiles )
+        {
+            try
+            {
+                @SuppressWarnings( "deprecation" )
+                URL url =
+                    new URL( "jar:" + file.toURL().toExternalForm()
+                        + "!/META-INF/maven/org.apache.maven/maven-core/pom.properties" );
+
+                Properties properties = new Properties();
+                properties.load( url.openStream() );
+                String version = StringUtils.trim( properties.getProperty( "version" ) );
+                if ( version != null )
+                {
+                    return version;
+                }
+            }
+            catch ( MalformedURLException e )
+            {
+                // ignore
+            }
+            catch ( IOException e )
+            {
+                // ignore
+            }
+        }
+        return null;
+    }
+
+    static boolean isMavenVersion( String mavenSpec )
+    {
+        return isMavenVersion( mavenSpec, getMavenVersion() );
+    }
+    
+    static boolean isMavenVersion( String mavenSpec, String actualVersion )
+    {
+        List<String> includes = new ArrayList<String>();
+        List<String> excludes = new ArrayList<String>();
+        parseList( mavenSpec, includes, excludes );
+
+        List<Integer> mavenVersionList = parseVersion( actualVersion );
+
+        return isJreVersion( mavenVersionList, includes, true ) && !isJreVersion( mavenVersionList, excludes, false );
+    }
+
+    static String getJreVersion()
+    {
+        return System.getProperty( "java.version", "" );
+    }
+    
+    static String getJreVersion( File javaHome )
+    {
+        //@todo detect actual version
+        return null;
+    }
+
+    static boolean isJreVersion( String jreSpec )
+    {
+        return isJreVersion( jreSpec, getJreVersion() );
+    }
+    
+    static boolean isJreVersion( String jreSpec, String actualJreVersion )
+    {
+        List<String> includes = new ArrayList<String>();
+        List<String> excludes = new ArrayList<String>();
+        parseList( jreSpec, includes, excludes );
+
+        List<Integer> jreVersion = parseVersion( actualJreVersion );
+
+        return isJreVersion( jreVersion, includes, true ) && !isJreVersion( jreVersion, excludes, false );
+    }
+
+
+    static boolean isJreVersion( List<Integer> jreVersion, List<String> versionPatterns, boolean defaultMatch )
+    {
+        if ( versionPatterns != null && !versionPatterns.isEmpty() )
+        {
+            for ( String versionPattern : versionPatterns )
+            {
+                if ( isJreVersion( jreVersion, versionPattern ) )
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+        else
+        {
+            return defaultMatch;
+        }
+    }
+
+    static boolean isJreVersion( List<Integer> jreVersion, String versionPattern )
+    {
+        List<Integer> checkVersion = parseVersion( versionPattern );
+
+        if ( versionPattern.endsWith( "+" ) )
+        {
+            // 1.5+ <=> [1.5,)
+            return compareVersions( jreVersion, checkVersion ) >= 0;
+        }
+        else if ( versionPattern.endsWith( "-" ) )
+        {
+            // 1.5- <=> (,1.5)
+            return compareVersions( jreVersion, checkVersion ) < 0;
+        }
+        else
+        {
+            // 1.5 <=> [1.5,1.6)
+            return checkVersion.size() <= jreVersion.size() && checkVersion.equals(
+                jreVersion.subList( 0, checkVersion.size() ) );
+        }
+    }
+
+    static List<Integer> parseVersion( String version )
+    {
+        version = version.replaceAll( "[^0-9]", "." );
+
+        String[] tokens = StringUtils.split( version, "." );
+
+        List<Integer> numbers = new ArrayList<Integer>();
+
+        for ( int i = 0; i < tokens.length; i++ )
+        {
+            numbers.add( Integer.valueOf( tokens[i] ) );
+        }
+
+        return numbers;
+    }
+
+    static int compareVersions( List<Integer> version1, List<Integer> version2 )
+    {
+        for ( Iterator<Integer> it1 = version1.iterator(), it2 = version2.iterator(); ; )
+        {
+            if ( !it1.hasNext() )
+            {
+                return it2.hasNext() ? -1 : 0;
+            }
+            if ( !it2.hasNext() )
+            {
+                return it1.hasNext() ? 1 : 0;
+            }
+
+            Integer num1 = it1.next();
+            Integer num2 = it2.next();
+
+            int rel = num1.compareTo( num2 );
+            if ( rel != 0 )
+            {
+                return rel;
+            }
+        }
+    }
+
+}