This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to annotated tag maven-invoker-plugin-1.1 in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit 2644771fb3df9e33e1c47dc065646bcb525ec3d7 Author: Oliver Lamy <ol...@apache.org> AuthorDate: Mon Dec 3 22:31:39 2007 +0000 [MINVOKER-10] Capability to define different profiles per it test git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-invoker-plugin@600713 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/plugin/invoker/InvokerMojo.java | 54 ++++++++++++++++++++-- .../maven/plugin/invoker/InterpolationTest.java | 43 +++++++++++++++++ .../unit/profiles-from-file/emptyProfiles.txt | 0 .../resources/unit/profiles-from-file/profiles.txt | 1 + 4 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java index 543004c..f5e5fc5 100644 --- a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java +++ b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java @@ -22,6 +22,7 @@ package org.apache.maven.plugin.invoker; 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 @@ public class InvokerMojo * @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 @@ public class InvokerMojo } request.setPomFile( interpolatedPomFile ); - if ( profiles != null ) - { - request.setProfiles( profiles ); - } + + request.setProfiles( getProfiles(basedir) ); try { @@ -996,4 +1003,43 @@ public class InvokerMojo } 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 ); + } + } } diff --git a/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java b/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java index 26ed45b..9f9525d 100755 --- a/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java +++ b/src/test/java/org/apache/maven/plugin/invoker/InterpolationTest.java @@ -20,6 +20,7 @@ package org.apache.maven.plugin.invoker; 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 class InterpolationTest } } } + + 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() ); + + } } diff --git a/src/test/resources/unit/profiles-from-file/emptyProfiles.txt b/src/test/resources/unit/profiles-from-file/emptyProfiles.txt new file mode 100755 index 0000000..e69de29 diff --git a/src/test/resources/unit/profiles-from-file/profiles.txt b/src/test/resources/unit/profiles-from-file/profiles.txt new file mode 100755 index 0000000..f33f47f --- /dev/null +++ b/src/test/resources/unit/profiles-from-file/profiles.txt @@ -0,0 +1 @@ +foo, bar -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.