You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/08/08 20:20:31 UTC

svn commit: r684034 - in /maven/plugins/trunk/maven-invoker-plugin/src: main/java/org/apache/maven/plugin/invoker/FileLogger.java main/java/org/apache/maven/plugin/invoker/InvokerMojo.java test/java/org/apache/maven/plugin/invoker/InterpolationTest.java

Author: bentmann
Date: Fri Aug  8 11:20:31 2008
New Revision: 684034

URL: http://svn.apache.org/viewvc?rev=684034&view=rev
Log:
o Refactored code to ease maintenance
o Added more javadoc

Modified:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/FileLogger.java
    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/FileLogger.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/FileLogger.java?rev=684034&r1=684033&r2=684034&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/FileLogger.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/FileLogger.java Fri Aug  8 11:20:31 2008
@@ -36,6 +36,11 @@
 {
 
     /**
+     * The path to the log file.
+     */
+    private File file;
+
+    /**
      * The underlying file stream this logger writes to.
      */
     private PrintStream stream;
@@ -72,7 +77,10 @@
     public FileLogger( File outputFile, Log log )
         throws IOException
     {
+        this.file = outputFile;
         this.log = log;
+
+        outputFile.getParentFile().mkdirs();
         stream = new PrintStream( new FileOutputStream( outputFile ) );
 
         Runnable finalizer = new Runnable()
@@ -94,6 +102,16 @@
     }
 
     /**
+     * Gets the path to the output file.
+     * 
+     * @return The path to the output file, never <code>null</code>.
+     */
+    public File getOutputFile()
+    {
+        return file;
+    }
+
+    /**
      * Gets the underlying stream used to write message to the log file.
      * 
      * @return The underlying stream used to write message to the log file, never <code>null</code>.

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=684034&r1=684033&r2=684034&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 Fri Aug  8 11:20:31 2008
@@ -22,7 +22,6 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
@@ -408,6 +407,12 @@
     private Map scriptInterpreters;
 
 
+    /**
+     * Invokes Maven on the configured test projects.
+     * 
+     * @throws MojoExecutionException If the goal encountered severe errors.
+     * @throws MojoFailureException If any of the Maven builds failed.
+     */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
@@ -449,7 +454,7 @@
 
         if ( ( includedPoms == null ) || ( includedPoms.length < 1 ) )
         {
-            getLog().info( "No test-projects were selected for execution." );
+            getLog().info( "No test projects were selected for execution." );
             return;
         }
 
@@ -468,8 +473,6 @@
 
         if ( cloneProjectsTo != null )
         {
-            cloneProjectsTo.mkdirs();
-
             try
             {
                 cloneProjects( includedPoms );
@@ -558,6 +561,8 @@
     private void cloneProjects( String[] includedProjects )
         throws IOException
     {
+        cloneProjectsTo.mkdirs();
+
         List clonedSubpaths = new ArrayList();
 
         for ( int i = 0; i < includedProjects.length; i++ )
@@ -612,7 +617,7 @@
             }
         }
     }
-    
+
     /**
      * Copied a directory structure with deafault exclusions (.svn, CVS, etc)
      * 
@@ -620,11 +625,12 @@
      * @param destDir
      * @throws IOException
      */
-    private void copyDirectoryStructure( File sourceDir, File destDir ) throws IOException
+    private void copyDirectoryStructure( File sourceDir, File destDir )
+        throws IOException
     {
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir( sourceDir );
-        if ( ! cloneAllFiles )
+        if ( !cloneAllFiles )
         {
             scanner.addDefaultExcludes();
         }
@@ -638,8 +644,8 @@
         String[] includedFiles = scanner.getIncludedFiles();
         for ( int i = 0; i < includedFiles.length; ++i )
         {
-            File sourceFile = new File( sourceDir, includedFiles[ i ] );
-            File destFile = new File( destDir, includedFiles[ i ] );
+            File sourceFile = new File( sourceDir, includedFiles[i] );
+            File destFile = new File( destDir, includedFiles[i] );
             FileUtils.copyFile( sourceFile, destFile );
         }
     }
@@ -690,59 +696,33 @@
         {
             basedir = pomFile.getParentFile();
         }
-        File interpolatedPomFile = null;
-        if ( pomFile != null )
-        {
-            interpolatedPomFile = buildInterpolatedFile( pomFile, basedir, "interpolated-pom.xml" );
-        }
 
-        FileLogger logger = null;
-        try
-        {
-            getLog().info( "Building: " + project );
-
-            final File outputLog = new File( basedir, "build.log" );
+        getLog().info( "Building: " + project );
 
-            final Properties invokerProperties = getInvokerProperties( basedir );
-            if ( getLog().isDebugEnabled() && !invokerProperties.isEmpty() )
+        final Properties invokerProperties = getInvokerProperties( basedir );
+        if ( getLog().isDebugEnabled() && !invokerProperties.isEmpty() )
+        {
+            getLog().debug( "Using invoker properties:" );
+            for ( Iterator it = new TreeSet( invokerProperties.keySet() ).iterator(); it.hasNext(); )
             {
-                getLog().debug( "Using invoker properties:" );
-                for ( Iterator it = new TreeSet( invokerProperties.keySet() ).iterator(); it.hasNext(); )
-                {
-                    String key = (String) it.next();
-                    String value = invokerProperties.getProperty( key );
-                    getLog().debug( "  " + key + " = " + value );
-                }
+                String key = (String) it.next();
+                String value = invokerProperties.getProperty( key );
+                getLog().debug( "  " + key + " = " + value );
             }
+        }
 
-            if ( !noLog )
-            {
-                outputLog.getParentFile().mkdirs();
-
-                try
-                {
-                    if ( streamLogs )
-                    {
-                        logger = new FileLogger( outputLog, getLog() );
-                    }
-                    else
-                    {
-                        logger = new FileLogger( outputLog );
-                    }
-
-                    getLog().debug( "build log initialized in: " + outputLog );
-                }
-                catch ( final IOException e )
-                {
-                    getLog().debug( "Error initializing build logfile in: " + outputLog, e );
-                    getLog().info( "...FAILED[could not initialize logfile in: " + outputLog + "]" );
-
-                    failures.add( project );
+        File interpolatedPomFile = null;
+        if ( pomFile != null )
+        {
+            interpolatedPomFile = new File( basedir, "interpolated-pom.xml" );
+            buildInterpolatedFile( pomFile, interpolatedPomFile );
+        }
 
-                    return;
-                }
-            }
+        final Properties loadedProperties = loadTestProperties( basedir );
 
+        FileLogger logger = setupLogger( basedir );
+        try
+        {
             if ( !prebuild( basedir, logger ) )
             {
                 getLog().info( "...FAILED[pre-build script returned false]" );
@@ -756,7 +736,8 @@
 
             final List invocationGoals = getGoals( basedir );
 
-            if ( ( invocationGoals.size() == 1 ) && "_default".equals( invocationGoals.get( 0 ) ) )
+            if ( invocationGoals.isEmpty()
+                || ( invocationGoals.size() == 1 && "_default".equals( invocationGoals.get( 0 ) ) ) )
             {
                 getLog().debug( "Executing default goal for project in: " + project );
             }
@@ -767,38 +748,20 @@
                 request.setGoals( invocationGoals );
             }
 
-            try
+            Properties collectedTestProperties = new Properties();
+            if ( testProperties != null )
             {
-                Properties collectedTestProperties = new Properties();
-
-                if ( testProperties != null )
-                {
-                    collectedTestProperties.putAll( testProperties );
-                }
-
-                if ( properties != null )
-                {
-                    collectedTestProperties.putAll( properties );
-                }
-
-                final Properties loadedProperties = loadTestProperties( basedir );
-
-                if ( loadedProperties != null )
-                {
-                    collectedTestProperties.putAll( loadedProperties );
-                }
-
-                request.setProperties( collectedTestProperties );
+                collectedTestProperties.putAll( testProperties );
             }
-            catch ( final IOException e )
+            if ( properties != null )
             {
-                getLog().debug( "Error reading test-properties file in: " + testPropertiesFile, e );
-                getLog().info( "...FAILED[error reading test properties in: " + testPropertiesFile + "]" );
-
-                failures.add( project );
-
-                return;
+                collectedTestProperties.putAll( properties );
+            }
+            if ( loadedProperties != null )
+            {
+                collectedTestProperties.putAll( loadedProperties );
             }
+            request.setProperties( collectedTestProperties );
 
             if ( localRepositoryPath != null )
             {
@@ -822,7 +785,7 @@
 
             request.setBaseDirectory( basedir );
 
-            if ( !noLog )
+            if ( logger != null )
             {
                 request.setErrorHandler( logger );
 
@@ -838,10 +801,10 @@
 
             if ( settingsFile != null )
             {
-                buildInterpolatedFile( settingsFile, settingsFile.getParentFile(), settingsFile.getName()
-                    + ".interpolated" );
-                request.setUserSettingsFile( new File( settingsFile.getParentFile(), settingsFile.getName()
-                    + ".interpolated" ) );
+                File interpolatedSettingsFile =
+                    new File( settingsFile.getParentFile(), "interpolated-" + settingsFile.getName() );
+                buildInterpolatedFile( settingsFile, interpolatedSettingsFile );
+                request.setUserSettingsFile( interpolatedSettingsFile );
             }
 
             request.setMavenOpts( mavenOpts );
@@ -884,9 +847,11 @@
                 {
                     StringBuffer buffer = new StringBuffer( 256 );
                     buffer.append( "...FAILED. " );
-                    if ( !noLog )
+                    if ( logger != null )
                     {
-                        buffer.append( "See " ).append( outputLog.getAbsolutePath() ).append( " for details." );
+                        buffer.append( "See " );
+                        buffer.append( logger.getOutputFile().getAbsolutePath() );
+                        buffer.append( " for details." );
                     }
                     else
                     {
@@ -903,9 +868,11 @@
                 {
                     StringBuffer buffer = new StringBuffer( 256 );
                     buffer.append( "...FAILED[code=" ).append( result.getExitCode() ).append( "]. " );
-                    if ( !noLog )
+                    if ( logger != null )
                     {
-                        buffer.append( "See " ).append( outputLog.getAbsolutePath() ).append( " for details." );
+                        buffer.append( "See " );
+                        buffer.append( logger.getOutputFile().getAbsolutePath() );
+                        buffer.append( " for details." );
                     }
                     else
                     {
@@ -939,8 +906,52 @@
         }
     }
 
+    /**
+     * Initializes the build logger for the specified project.
+     * 
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @return The build logger or <code>null</code> if logging has been disabled.
+     * @throws MojoExecutionException If the log file could not be created.
+     */
+    private FileLogger setupLogger( File basedir )
+        throws MojoExecutionException
+    {
+        FileLogger logger = null;
+
+        if ( !noLog )
+        {
+            File outputLog = new File( basedir, "build.log" );
+            try
+            {
+                if ( streamLogs )
+                {
+                    logger = new FileLogger( outputLog, getLog() );
+                }
+                else
+                {
+                    logger = new FileLogger( outputLog );
+                }
+
+                getLog().debug( "build log initialized in: " + outputLog );
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "Error initializing build logfile in: " + outputLog, e );
+            }
+        }
+
+        return logger;
+    }
+
+    /**
+     * Reads the system properties to use for the specified project (if any).
+     * 
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @return The system properties to use, may be empty but never <code>null</code>.
+     * @throws MojoExecutionException If the properties file exists but could not be read.
+     */
     private Properties loadTestProperties( final File basedir )
-        throws IOException
+        throws MojoExecutionException
     {
         final Properties testProps = new Properties();
 
@@ -957,6 +968,11 @@
 
                     testProps.load( fin );
                 }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( "Error reading system properties for test: "
+                        + testPropertiesFile );
+                }
                 finally
                 {
                     IOUtil.close( fin );
@@ -967,7 +983,16 @@
         return testProps;
     }
 
+    /**
+     * Runs the pre-build-hook script of the specified project (if any).
+     * 
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @param logger The logger to redirect the script output to, may be <code>null</code> to use stdout/stderr.
+     * @return <code>true</code> if the script does not exist or completed successfully, <code>false</code> otherwise.
+     * @throws MojoExecutionException If an I/O error occurred while reading the script file.
+     */
     private boolean prebuild( final File basedir, final FileLogger logger )
+        throws MojoExecutionException
     {
         boolean result = true;
 
@@ -979,7 +1004,16 @@
         return result;
     }
 
+    /**
+     * Runs the post-build-hook script of the specified project (if any).
+     * 
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @param logger The logger to redirect the script output to, may be <code>null</code> to use stdout/stderr.
+     * @return <code>true</code> if the script does not exist or completed successfully, <code>false</code> otherwise.
+     * @throws MojoExecutionException If an I/O error occurred while reading the script file.
+     */
     private boolean verify( final File basedir, final FileLogger logger )
+        throws MojoExecutionException
     {
         boolean result = true;
 
@@ -991,8 +1025,20 @@
         return result;
     }
 
+    /**
+     * Runs the specified hook script of the specified project (if any).
+     * 
+     * @param scriptDescription The description of the script to use for logging, must not be <code>null</code>.
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @param relativeScriptPath The path to the script relative to the project base directory, must not be
+     *            <code>null</code>.
+     * @param logger The logger to redirect the script output to, may be <code>null</code> to use stdout/stderr.
+     * @return <code>true</code> if the script does not exist or completed successfully, <code>false</code> otherwise.
+     * @throws MojoExecutionException If an I/O error occurred while reading the script file.
+     */
     private boolean runScript( final String scriptDescription, final File basedir, final String relativeScriptPath,
                                final FileLogger logger )
+        throws MojoExecutionException
     {
         final File scriptFile = resolveScript( new File( basedir, relativeScriptPath ) );
 
@@ -1003,7 +1049,7 @@
             Map globalVariables = new HashMap();
             globalVariables.put( "basedir", basedir );
 
-            PrintStream out = noLog ? null : logger.getPrintStream();
+            PrintStream out = ( logger != null ) ? logger.getPrintStream() : null;
 
             ScriptInterpreter interpreter = getInterpreter( scriptFile );
             if ( getLog().isDebugEnabled() )
@@ -1023,18 +1069,17 @@
                 String errorMessage =
                     "error reading " + scriptDescription + " " + basedir.getPath() + File.separatorChar
                         + postBuildHookScript + ", " + e.getMessage();
-                getLog().error( errorMessage, e );
-                return false;
+                throw new MojoExecutionException( errorMessage, e );
             }
 
             try
             {
-                if ( !noLog )
+                if ( logger != null )
                 {
                     logger.consumeLine( "Running " + scriptDescription + " in: " + scriptFile );
                 }
                 Object result = interpreter.evaluateScript( script, classPath, globalVariables, out );
-                if ( !noLog )
+                if ( logger != null )
                 {
                     logger.consumeLine( "Finished " + scriptDescription + " in: " + scriptFile );
                 }
@@ -1098,27 +1143,44 @@
         return interpreter;
     }
 
+    /**
+     * Gets the goal list for the specified project.
+     * 
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @return The list of goals to run when building the project, may be empty but never <code>null</code>.
+     * @throws MojoExecutionException If the profile file could not be read.
+     */
     List getGoals( final File basedir )
+        throws MojoExecutionException
     {
-        List invocationGoals = goals;
-
-        if ( goalsFile != null )
+        try
         {
-            final File projectGoalList = new File( basedir, goalsFile );
-
-            if ( projectGoalList.exists() )
-            {
-                final List goals = readFromFile( projectGoalList );
-
-                if ( ( goals != null ) && !goals.isEmpty() )
-                {
-                    getLog().debug( "Using goals specified in file: " + projectGoalList );
-                    invocationGoals = goals;
-                }
-            }
+            return getTokens( basedir, goalsFile, goals );
         }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "error reading goals", e );
+        }
+    }
 
-        return invocationGoals;
+    /**
+     * Gets the profile list for the specified project.
+     * 
+     * @param basedir The base directory of the project, must not be <code>null</code>.
+     * @return The list of profiles to activate when building the project, may be empty but never <code>null</code>.
+     * @throws MojoExecutionException If the profile file could not be read.
+     */
+    List getProfiles( File basedir )
+        throws MojoExecutionException
+    {
+        try
+        {
+            return getTokens( basedir, profilesFile, profiles );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "error reading profiles", e );
+        }
     }
 
     String[] getPoms()
@@ -1230,18 +1292,54 @@
         }
     }
 
-    private List readFromFile( final File projectGoalList )
+    /**
+     * Gets goal/profile names for the specified project, either directly from the plugin configuration or from an
+     * external token file.
+     * 
+     * @param basedir The base directory of the test project, must not be <code>null</code>.
+     * @param filename The (simple) name of an optional file in the project base directory from which to read
+     *            goals/profiles, may be <code>null</code>.
+     * @param defaultTokens The list of tokens to return in case the specified token file does not exist, may be
+     *            <code>null</code>.
+     * @return The list of goal/profile names, may be empty but never <code>null</code>.
+     * @throws IOException If the token file exists but could not be parsed.
+     */
+    private List getTokens( File basedir, String filename, List defaultTokens )
+        throws IOException
     {
-        BufferedReader reader = null;
+        List tokens = ( defaultTokens != null ) ? defaultTokens : new ArrayList();
+
+        if ( StringUtils.isNotEmpty( filename ) )
+        {
+            File tokenFile = new File( basedir, filename );
+
+            if ( tokenFile.exists() )
+            {
+                tokens = readTokens( tokenFile );
+            }
+        }
 
-        List result = null;
+        return tokens;
+    }
 
+    /**
+     * Reads the tokens from the specified file. Tokens are separated either by line terminators or commas. During
+     * parsing, the file contents will be interpolated.
+     * 
+     * @param tokenFile The file to read the tokens from, must not be <code>null</code>.
+     * @return The list of tokens, may be empty but never <code>null</code>.
+     * @throws IOException If the token file could not be read.
+     */
+    private List readTokens( final File tokenFile )
+        throws IOException
+    {
+        List result = new ArrayList();
+
+        BufferedReader reader = null;
         try
         {
             Map composite = new CompositeMap( this.project, this.interpolationsProperties );
-            reader = new BufferedReader( new InterpolationFilterReader( newReader( projectGoalList ), composite ) );
-
-            result = new ArrayList();
+            reader = new BufferedReader( new InterpolationFilterReader( newReader( tokenFile ), composite ) );
 
             String line = null;
             while ( ( line = reader.readLine() ) != null )
@@ -1249,13 +1347,6 @@
                 result.addAll( collectListFromCSV( line ) );
             }
         }
-        catch ( final IOException e )
-        {
-            getLog().warn(
-                           "Failed to load goal list from file: " + projectGoalList
-                               + ". Using 'goal' parameter configured on this plugin instead." );
-            getLog().debug( "Error reading goals file: " + projectGoalList, e );
-        }
         finally
         {
             IOUtil.close( reader );
@@ -1264,6 +1355,12 @@
         return result;
     }
 
+    /**
+     * Gets a list of comma separated tokens from the specified line.
+     * 
+     * @param csv The line with comma separated tokens, may be <code>null</code>.
+     * @return The list of tokens from the line, may be empty but never <code>null</code>.
+     */
     private List collectListFromCSV( final String csv )
     {
         final List result = new ArrayList();
@@ -1281,46 +1378,53 @@
         return result;
     }
 
-    File buildInterpolatedFile( File originalFile, File targetDirectory, String targetFileName )
+    /**
+     * Interpolates the specified POM/settings file to a temporary file.
+     * 
+     * @param originalFile The XML file to interpolate, must not be <code>null</code>.
+     * @param interpolatedFile The target file to write the interpolated contents of the original file to, must not be
+     *            <code>null</code>.
+     * @throws MojoExecutionException If the target file could not be created.
+     */
+    void buildInterpolatedFile( File originalFile, File interpolatedFile )
         throws MojoExecutionException
     {
-        File interpolatedFile = new File( targetDirectory, targetFileName );
         if ( interpolatedFile.exists() )
         {
             interpolatedFile.delete();
         }
         interpolatedFile.deleteOnExit();
-        if ( settings.getLocalRepository() != null )
+        try
         {
-            if ( this.interpolationsProperties == null )
+            if ( !interpolatedFile.createNewFile() )
             {
-                this.interpolationsProperties = new Properties();
+                throw new MojoExecutionException( "failed to create file " + interpolatedFile.getPath() );
             }
-            this.interpolationsProperties.put( "localRepository", settings.getLocalRepository() );
         }
-        Map composite = new CompositeMap( this.project, this.interpolationsProperties );
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "failed to create file " + interpolatedFile.getPath(), e );
+        }
+        getLog().debug( "interpolate file to create interpolated in " + interpolatedFile.getPath() );
 
-        try
+        if ( settings.getLocalRepository() != null )
         {
-            boolean created = interpolatedFile.createNewFile();
-            if ( !created )
+            if ( this.interpolationsProperties == null )
             {
-                throw new MojoExecutionException( "fail to create file " + interpolatedFile.getPath() );
+                this.interpolationsProperties = new Properties();
             }
+            this.interpolationsProperties.put( "localRepository", settings.getLocalRepository() );
         }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "fail to create file " + interpolatedFile.getPath() );
-        }
-        getLog().debug( "interpolate it pom to create interpolated in " + interpolatedFile.getPath() );
+        Map composite = new CompositeMap( this.project, this.interpolationsProperties );
 
         BufferedReader reader = null;
         Writer writer = null;
         try
         {
             // interpolation with token @...@
-            reader = new BufferedReader( new InterpolationFilterReader( ReaderFactory.newXmlReader( originalFile ),
-                                                                        composite, "@", "@" ) );
+            reader =
+                new BufferedReader( new InterpolationFilterReader( ReaderFactory.newXmlReader( originalFile ),
+                                                                   composite, "@", "@" ) );
             writer = WriterFactory.newXmlWriter( interpolatedFile );
             String line = null;
             while ( ( line = reader.readLine() ) != null )
@@ -1331,8 +1435,7 @@
         }
         catch ( IOException e )
         {
-            String message = "error when interpolating it pom";
-            throw new MojoExecutionException( message, e );
+            throw new MojoExecutionException( "failed to interpolate file " + originalFile.getPath(), e );
         }
         finally
         {
@@ -1340,53 +1443,6 @@
             IOUtil.close( reader );
             IOUtil.close( writer );
         }
-
-        if ( interpolatedFile == null )
-        {
-            // null check : normally impossibe but :-)
-            throw new MojoExecutionException( "pom file is null after interpolation" );
-        }
-        return interpolatedFile;
-    }
-
-    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( newReader( 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 );
-        }
     }
 
     /**
@@ -1394,7 +1450,7 @@
      * 
      * @param projectDirectory The base directory of the IT project, must not be <code>null</code>.
      * @return The invoker properties, may be empty but never <code>null</code>.
-     * @throws MojoExecutionException If an error occurred.
+     * @throws MojoExecutionException If an I/O error occurred during reading the properties.
      */
     private Properties getInvokerProperties( final File projectDirectory )
         throws MojoExecutionException

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=684034&r1=684033&r2=684034&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 Fri Aug  8 11:20:31 2008
@@ -19,7 +19,7 @@
 package org.apache.maven.plugin.invoker;
 
 import java.io.File;
-import java.io.FileReader;
+import java.io.Reader;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
@@ -29,6 +29,7 @@
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 
 /**
  * @author <a href="mailto:olamy@apache.org">olamy</a>
@@ -91,7 +92,7 @@
     public void testPomInterpolation()
         throws Exception
     {
-        FileReader fileReader = null;
+        Reader reader = null;
         File interpolatedPomFile = null;
         try
         {
@@ -105,31 +106,23 @@
             setVariableValueToObject( invokerMojo, "interpolationsProperties", properties );
             String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test"
                 + File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation";
-            interpolatedPomFile = invokerMojo.buildInterpolatedFile( new File( dirPath, "pom.xml" ),
-                                                                        new File( getBasedir() + File.separatorChar
-                                                                            + "target" ), "interpolated-pom.xml"  );
-            fileReader = new FileReader( interpolatedPomFile );
-            String content = IOUtil.toString( fileReader );
+            
+            interpolatedPomFile = new File( getBasedir(), "target/interpolated-pom.xml" );
+            invokerMojo.buildInterpolatedFile( new File( dirPath, "pom.xml" ), interpolatedPomFile );
+            reader = ReaderFactory.newXmlReader( interpolatedPomFile );
+            String content = IOUtil.toString( reader );
             assertTrue( content.indexOf( "<interpolateValue>bar</interpolateValue>" ) > 0 );
-            fileReader.close();
+            reader.close();
             // recreate it to test delete if exists before creation
-            interpolatedPomFile = invokerMojo.buildInterpolatedFile( new File( dirPath, "pom.xml" ),
-                                                                        new File( getBasedir() + File.separatorChar
-                                                                            + "target" ), "interpolated-pom.xml"  );
-            fileReader = new FileReader( interpolatedPomFile );
-            content = IOUtil.toString( fileReader );
+            invokerMojo.buildInterpolatedFile( new File( dirPath, "pom.xml" ), interpolatedPomFile );
+            reader = ReaderFactory.newXmlReader( interpolatedPomFile );
+            content = IOUtil.toString( reader );
             assertTrue( content.indexOf( "<interpolateValue>bar</interpolateValue>" ) > 0 );
-            fileReader.close();
-        } catch (Exception e)
-        {
-            throw e;
+            reader.close();
         }
         finally
         {
-            if ( fileReader != null )
-            {
-                fileReader.close();
-            }
+            IOUtil.close( reader );
         }
     }
 
@@ -137,6 +130,7 @@
         throws Exception
     {
         InvokerMojo invokerMojo = new InvokerMojo();
+        setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
         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";
@@ -150,6 +144,7 @@
     {
 
         InvokerMojo invokerMojo = new InvokerMojo();
+        setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
         setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] { "zloug" } ) );
         setVariableValueToObject( invokerMojo, "profilesFile", "emptyProfiles.txt" );
         setVariableValueToObject( invokerMojo, "settings", new Settings() );