Author: olamy
Date: Thu Nov 29 15:05:54 2007
New Revision: 599618
URL: http://svn.apache.org/viewvc?rev=599618&view=rev
Log:
[MINVOKER-12] Interpolate it pom with a different token ${..} -> @...@
Added:
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
(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/site/apt/advance-usage.apt
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=599618&r1=599617&r2=599618&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
Thu Nov 29 15:05:54 2007
@@ -23,6 +23,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
@@ -50,6 +51,7 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.InterpolationFilterReader;
import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
import bsh.EvalError;
import bsh.Interpreter;
@@ -228,6 +230,9 @@
* @since 1.1
*/
private MavenProject project;
+
+ // list to store interpolated pom for delete at the end
+ private List/*File*/ interpolatedPomFiles = new ArrayList();
public void execute()
throws MojoExecutionException, MojoFailureException
@@ -294,11 +299,19 @@
final List failures = new ArrayList();
- for ( int i = 0; i < includedPoms.length; i++ )
+ try
{
- final String pom = includedPoms[i];
+ for ( int i = 0; i < includedPoms.length; i++ )
+ {
+ final String pom = includedPoms[i];
- runBuild( projectsDir, pom, failures );
+ runBuild( projectsDir, pom, failures );
+ }
+ }
+ finally
+ {
+ // interpolated files cleanup
+ cleanupInterpolatedPomFiles();
}
if ( !suppressSummaries )
@@ -408,18 +421,17 @@
private void runBuild( final File projectsDir, final String pom, final
List failures )
throws MojoExecutionException
{
+
File pomFile = new File( projectsDir, pom );
-
final File basedir = pomFile.getParentFile();
-
- getLog().info( "Building: " + pom );
-
- final File outputLog = new File( basedir, "build.log" );
-
+ File interpolatedPomFile = buildInterpolatedPomFile( pomFile, basedir
);
FileLogger logger = null;
-
try
{
+ getLog().info( "Building: " + pom );
+
+ final File outputLog = new File( basedir, "build.log" );
+
if ( !noLog )
{
outputLog.getParentFile().mkdirs();
@@ -448,7 +460,7 @@
}
}
- if ( !prebuild( basedir, pom, failures, logger ) )
+ if ( !prebuild( basedir, interpolatedPomFile, failures, logger ) )
{
getLog().info( "...FAILED[pre-build script returned false]" );
@@ -529,8 +541,7 @@
request.setOutputHandler( logger );
}
- request.setPomFile( pomFile );
-
+ request.setPomFile( interpolatedPomFile );
if ( profiles != null )
{
request.setProfiles( profiles );
@@ -580,7 +591,7 @@
failures.add( pom );
}
- else if ( !verify( basedir, pom, failures, logger ) )
+ else if ( !verify( basedir, interpolatedPomFile, failures, logger
) )
{
if ( !suppressSummaries )
{
@@ -589,7 +600,7 @@
failures.add( pom );
}
- else if (!suppressSummaries )
+ else if ( !suppressSummaries )
{
getLog().info( "...SUCCESS." );
}
@@ -632,7 +643,7 @@
return testProps;
}
- private boolean verify( final File basedir, final String pom, final List
failures, final FileLogger logger )
+ private boolean verify( final File basedir, final File pom, final List
failures, final FileLogger logger )
{
boolean result = true;
@@ -715,7 +726,7 @@
return scriptResult;
}
- private boolean prebuild( final File basedir, final String pom, final List
failures, final FileLogger logger )
+ private boolean prebuild( final File basedir, final File pom, final List
failures, final FileLogger logger )
{
boolean result = true;
@@ -903,6 +914,80 @@
}
return result;
+ }
+
+ protected File buildInterpolatedPomFile( File pomFile, File
targetDirectory )
+ throws MojoExecutionException
+ {
+ File interpolatedPomFile = new File( targetDirectory,
"interpolated-pom.xml" );
+ interpolatedPomFiles.add( interpolatedPomFile );
+ Map composite = new CompositeMap( this.project,
this.interpolationsProperties );
+
+ try
+ {
+ boolean created = interpolatedPomFile.createNewFile();
+ if ( !created )
+ {
+ throw new MojoExecutionException( "fail to create file " +
interpolatedPomFile.getPath() );
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "fail to create file " +
interpolatedPomFile.getPath() );
+ }
+ getLog().debug( "interpolate it pom to create interpolated in " +
interpolatedPomFile.getPath() );
+
+ BufferedReader reader = null;
+ FileWriter fileWriter = null;
+ try
+ {
+ // pom interpolation with token @...@
+ reader = new BufferedReader( new InterpolationFilterReader( new
XmlStreamReader( pomFile ), composite, "@",
+ "@" )
);
+ fileWriter = new FileWriter( interpolatedPomFile );
+ String line = null;
+ while ( ( line = reader.readLine() ) != null )
+ {
+ fileWriter.write( line );
+ }
+ fileWriter.flush();
+ }
+ catch ( IOException e )
+ {
+ String message = "error when interpolating it pom";
+ throw new MojoExecutionException( message, e );
+ }
+ finally
+ {
+ // IOUtil in p-u is null check and silently NPE
+ IOUtil.close( reader );
+ IOUtil.close( fileWriter );
+ }
+
+ if ( interpolatedPomFile == null )
+ {
+ // null check : normally impossibe but :-)
+ throw new MojoExecutionException( "pom file is null after
interpolation" );
+ }
+ return interpolatedPomFile;
+ }
+
+ private void cleanupInterpolatedPomFiles()
+ {
+ for ( Iterator iterator = this.interpolatedPomFiles.iterator();
iterator.hasNext(); )
+ {
+ File file = (File) iterator.next();
+ if ( file.exists() )
+ {
+ try
+ {
+ FileUtils.forceDelete( file );
+ } catch (IOException e)
+ {
+ getLog().warn( "fail to clean file " + file.getPath() );
+ }
+ }
+ }
}
}
Modified:
maven/plugins/trunk/maven-invoker-plugin/src/site/apt/advance-usage.apt
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/apt/advance-usage.apt?rev=599618&r1=599617&r2=599618&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/site/apt/advance-usage.apt
(original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/site/apt/advance-usage.apt Thu
Nov 29 15:05:54 2007
@@ -12,10 +12,17 @@
goals files can be interpolated with some values :
- * values from the project pom (you can use $\{pom.groupId} in your goals
file)
+ * values from the project pom (you must use $\{pom.groupId} notation in your
goals file)
* In the plugin configuration you can add some properties in a
interpolationsProperties element
+
+* it Pom Interpolation
+
+ It poms can be interpolated with some values :
+ * values from the project pom (you must use @pom.groupId@ notation in your
pom file)
+
+ * In the plugin configuration you can add some properties in a
interpolationsProperties element
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=599618&r1=599617&r2=599618&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
Thu Nov 29 15:05:54 2007
@@ -19,12 +19,14 @@
package org.apache.maven.plugin.invoker;
import java.io.File;
+import java.io.FileReader;
import java.util.List;
import java.util.Properties;
import org.apache.maven.model.Scm;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">olamy</a>
@@ -71,10 +73,47 @@
properties.put( "cleanProps", "clean" );
properties.put( "version", "2.0-SNAPSHOT" );
setVariableValueToObject( invokerMojo, "interpolationsProperties",
properties );
- String dirPath = getBasedir() +
"/src/test/resources/unit/interpolation/";
+ String dirPath = getBasedir() + File.separatorChar + "src" +
File.separatorChar + "test"
+ + File.separatorChar + "resources" + File.separatorChar + "unit" +
File.separatorChar + "interpolation";
List goals = invokerMojo.getGoals( new File( dirPath ) );
assertEquals( goals.toString(), 2, goals.size() );
assertEquals( "clean", goals.get( 0 ) );
assertEquals( "bar:foo:1.0-SNAPSHOT:mygoal", goals.get( 1 ) );
+ }
+
+ public void testPomInterpolation()
+ throws Exception
+ {
+ FileReader fileReader = null;
+ File interpolatedPomFile = null;
+ try
+ {
+ InvokerMojo invokerMojo = new InvokerMojo();
+ setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
+ setVariableValueToObject( invokerMojo, "project",
buildMavenProjectStub() );
+ Properties properties = new Properties();
+ properties.put( "foo", "bar" );
+ properties.put( "version", "2.0-SNAPSHOT" );
+ setVariableValueToObject( invokerMojo, "interpolationsProperties",
properties );
+ String dirPath = getBasedir() + File.separatorChar + "src" +
File.separatorChar + "test"
+ + File.separatorChar + "resources" + File.separatorChar +
"unit" + File.separatorChar + "interpolation";
+ interpolatedPomFile = invokerMojo.buildInterpolatedPomFile( new
File( dirPath, "pom.xml" ),
+ new
File( getBasedir() + File.separatorChar
+ +
"target" ) );
+ fileReader = new FileReader( interpolatedPomFile );
+ String content = IOUtil.toString( fileReader );
+ assertTrue( content.indexOf(
"<interpolateValue>bar</interpolateValue>" ) > 0 );
+ }
+ finally
+ {
+ if ( fileReader != null )
+ {
+ fileReader.close();
+ }
+ if ( interpolatedPomFile != null )
+ {
+ interpolatedPomFile.delete();
+ }
+ }
}
}
Added:
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml?rev=599618&view=auto
==============================================================================
---
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
(added)
+++
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
Thu Nov 29 15:05:54 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>unit</artifactId>
+ <packaging>pom</packaging>
+ <version>0.1-SNAPSHOT</version>
+ <properties>
+ <interpolateValue>@foo@</interpolateValue>
+ </properties>
+</project>
\ No newline at end of file
Propchange:
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
------------------------------------------------------------------------------
svn:eol-style = LF
Propchange:
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
------------------------------------------------------------------------------
svn:executable = *
Propchange:
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/interpolation/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"