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 2007/12/03 23:31:50 UTC
svn commit: r600713 - in /maven/plugins/trunk/maven-invoker-plugin/src:
main/java/org/apache/maven/plugin/invoker/
test/java/org/apache/maven/plugin/invoker/
test/resources/unit/profiles-from-file/
Author: olamy
Date: Mon Dec 3 14:31:39 2007
New Revision: 600713
URL: http://svn.apache.org/viewvc?rev=600713&view=rev
Log:
[MINVOKER-10] Capability to define different profiles per it test
Added:
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/emptyProfiles.txt (with props)
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt (with props)
Modified:
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java?rev=600713&r1=600712&r2=600713&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java Mon Dec 3 14:31:39 2007
@@ -22,6 +22,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -241,6 +242,14 @@
* @since 1.1
*/
private String invokerTest;
+
+ /**
+ * The name of the project-specific file that contains the enumeration of profiles to use for that test.
+ * <b>If the file exists and empty no profiles will be used even if the profiles is set</b>
+ * @parameter expression="${invoker.profilesFile}" default-value="profiles.txt"
+ * @since 1.1
+ */
+ private String profilesFile;
public void execute()
throws MojoExecutionException, MojoFailureException
@@ -543,10 +552,8 @@
}
request.setPomFile( interpolatedPomFile );
- if ( profiles != null )
- {
- request.setProfiles( profiles );
- }
+
+ request.setProfiles( getProfiles(basedir) );
try
{
@@ -995,5 +1002,44 @@
throw new MojoExecutionException( "pom file is null after interpolation" );
}
return interpolatedPomFile;
+ }
+
+ protected List getProfiles( File projectDirectory )
+ throws MojoExecutionException
+ {
+ if ( profilesFile == null )
+ {
+ return profiles == null ? Collections.EMPTY_LIST : profiles;
+ }
+ File projectProfilesFile = new File( projectDirectory, profilesFile );
+ if ( !projectProfilesFile.exists() )
+ {
+ return profiles == null ? Collections.EMPTY_LIST : profiles;
+ }
+ BufferedReader reader = null;
+ try
+ {
+ List profilesInFiles = new ArrayList();
+ reader = new BufferedReader( new FileReader( projectProfilesFile ) );
+ String line = null;
+ while ( ( line = reader.readLine() ) != null )
+ {
+ profilesInFiles.addAll( collectListFromCSV( line ) );
+ }
+ return profilesInFiles;
+ }
+ catch ( FileNotFoundException e )
+ {
+ // as we check first if the file it should not happened
+ throw new MojoExecutionException( projectProfilesFile + " not found ", e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "error reading profile in file " + projectProfilesFile + " not found ", e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
}
Modified: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java?rev=600713&r1=600712&r2=600713&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java Mon Dec 3 14:31:39 2007
@@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileReader;
+import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@@ -112,4 +113,46 @@
}
}
}
+
+ public void testProfilesFromFile()
+ throws Exception
+ {
+ InvokerMojo invokerMojo = new InvokerMojo();
+ setVariableValueToObject( invokerMojo, "profilesFile", "profiles.txt" );
+ String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
+ + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
+ List profiles = invokerMojo.getProfiles( new File( dirPath ) );
+ assertEquals( 2, profiles.size() );
+ assertTrue( profiles.contains( "foo" ) );
+ }
+
+ public void testEmptyProfilesFromFile()
+ throws Exception
+ {
+
+ InvokerMojo invokerMojo = new InvokerMojo();
+ setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] { "zloug" } ) );
+ setVariableValueToObject( invokerMojo, "profilesFile", "emptyProfiles.txt" );
+ String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
+ + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
+ List profiles = invokerMojo.getProfiles( new File( dirPath ) );
+ assertFalse( profiles.contains( "zloug" ) );
+ assertEquals( 0, profiles.size() );
+
+ }
+
+ public void testProfilesWithNoFile()
+ throws Exception
+ {
+
+ InvokerMojo invokerMojo = new InvokerMojo();
+ setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] { "zloug" } ) );
+ setVariableValueToObject( invokerMojo, "profilesFile", "zorglubProfiles.txt" );
+ String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
+ + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
+ List profiles = invokerMojo.getProfiles( new File( dirPath ) );
+ assertTrue( profiles.contains( "zloug" ) );
+ assertEquals( 1, profiles.size() );
+
+ }
}
Added: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/emptyProfiles.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/emptyProfiles.txt?rev=600713&view=auto
==============================================================================
(empty)
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/emptyProfiles.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/emptyProfiles.txt
------------------------------------------------------------------------------
svn:executable = *
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/emptyProfiles.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt?rev=600713&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt Mon Dec 3 14:31:39 2007
@@ -0,0 +1 @@
+foo, bar
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt
------------------------------------------------------------------------------
svn:executable = *
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/profiles-from-file/profiles.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"