You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/08/03 23:13:55 UTC

svn commit: r1369213 - in /maven/surefire/trunk/surefire-integration-tests: pom.xml src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java

Author: olamy
Date: Fri Aug  3 21:13:55 2012
New Revision: 1369213

URL: http://svn.apache.org/viewvc?rev=1369213&view=rev
Log:
add a hach a la invoker plugin to download dependency from local repo

Modified:
    maven/surefire/trunk/surefire-integration-tests/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java

Modified: maven/surefire/trunk/surefire-integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/pom.xml?rev=1369213&r1=1369212&r2=1369213&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/pom.xml (original)
+++ maven/surefire/trunk/surefire-integration-tests/pom.xml Fri Aug  3 21:13:55 2012
@@ -96,6 +96,8 @@
             <maven.settings.file>${project.basedir}/../surefire-setup-integration-tests/target/private/it-settings.xml</maven.settings.file>
             <maven.repo.local>${project.basedir}/../surefire-setup-integration-tests/target/it-repo</maven.repo.local>
             <maven.test.tmpdir>${project.build.directory}</maven.test.tmpdir>
+            <user.localRepository>${settings.localRepository}</user.localRepository>
+            <testBuildDirectory>${project.build.testOutputDirectory}</testBuildDirectory>
           </systemPropertyVariables>
         </configuration>
         <executions>

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java?rev=1369213&r1=1369212&r2=1369213&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java Fri Aug  3 21:13:55 2012
@@ -19,12 +19,7 @@ package org.apache.maven.surefire.its.fi
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import org.apache.commons.lang.text.StrSubstitutor;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@@ -34,6 +29,13 @@ import org.apache.maven.it.Verifier;
 import org.apache.maven.it.util.FileUtils;
 import org.apache.maven.it.util.ResourceExtractor;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Encapsulate all needed features to start a surefire run
  * <p/>
@@ -277,6 +279,32 @@ public class SurefireLauncher
 
     public OutputValidator executeCurrentGoals()
     {
+
+        // hack "a la" invoker plugin to download dependencies from local repo
+        // and not download from central
+        try
+        {
+            String userLocalRepo = System.getProperty( "user.localRepository" );
+            String testBuildDirectory = System.getProperty( "testBuildDirectory" );
+
+            Map<String, String> values = new HashMap<String, String>( 1 );
+            values.put( "localRepositoryUrl", toUrl( userLocalRepo ) );
+            StrSubstitutor strSubstitutor = new StrSubstitutor( values );
+
+            String fileContent = FileUtils.fileRead( new File( testBuildDirectory, "settings.xml" ) );
+
+            File interpolatedSettings = new File( testBuildDirectory, "interpolated-settings.xml" );
+            String filtered = strSubstitutor.replace( fileContent );
+
+            FileUtils.fileWrite( interpolatedSettings.getAbsolutePath(), filtered );
+
+            cliOptions.add( "-s " + interpolatedSettings.getAbsolutePath() );
+        }
+        catch ( IOException e )
+        {
+            throw new SurefireVerifierException( e );
+        }
+
         verifier.setCliOptions( cliOptions );
         try
         {
@@ -293,6 +321,20 @@ public class SurefireLauncher
         }
     }
 
+    private static String toUrl( String filename )
+    {
+        /*
+         * NOTE: Maven fails to properly handle percent-encoded "file:" URLs (WAGON-111) so don't use File.toURI() here
+         * as-is but use the decoded path component in the URL.
+         */
+        String url = "file://" + new File( filename ).toURI().getPath();
+        if ( url.endsWith( "/" ) )
+        {
+            url = url.substring( 0, url.length() - 1 );
+        }
+        return url;
+    }
+
 
     public SurefireLauncher printSummary( boolean printsummary )
     {