mirror of https://github.com/apache/maven.git
[MNG-1927] Fixing the ${pom.build.directory} path translation and interpolation so that an absolute path
is rendered. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@367457 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0a8d6787a9
commit
f52a730b74
|
@ -0,0 +1,47 @@
|
|||
package org.apache.maven.plugin.coreit;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Take some configuration values that use interpolated POM values and write them to a properties file
|
||||
* to make sure they are passing through the system properly. We have reports (MNG-1927) that we're
|
||||
*
|
||||
* @goal generate-properties
|
||||
*/
|
||||
public class InterpolatedPomConfigurationMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
/**
|
||||
* @parameter expression="${basedir}"
|
||||
*/
|
||||
private String basedir;
|
||||
|
||||
/**
|
||||
* @parameter expression="${project.build.directory}"
|
||||
*/
|
||||
private String projectBuildDirectory;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
Properties mojoGeneratedPropeties = new Properties();
|
||||
|
||||
mojoGeneratedPropeties.put( "project.build.directory", projectBuildDirectory );
|
||||
|
||||
FileOutputStream fos = new FileOutputStream( new File( basedir, "target/mojo-generated.properties" ) );
|
||||
|
||||
mojoGeneratedPropeties.store( fos, "# Properties generated by the execution of a mojo that uses interpolated POM values for configuration." );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
getLog().error( "Error creating mojo generated properties.", e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,5 +19,22 @@
|
|||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-core-it-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<pomBuildDirectory>${pom.build.directory}</pomBuildDirectory>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>generate-properties</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -17,7 +17,7 @@ public class PomInterpolationTest
|
|||
basedir = System.getProperty( "basedir" );
|
||||
}
|
||||
|
||||
public void testProjectBuildDirectory()
|
||||
public void testProjectBuildDirectoryAfterResourceFiltering()
|
||||
throws Exception
|
||||
{
|
||||
Properties testProperties = new Properties();
|
||||
|
@ -32,4 +32,20 @@ public class PomInterpolationTest
|
|||
|
||||
assertEquals( testProperties.getProperty( "project.build.directory" ), projectBuildDirectory.getAbsolutePath() );
|
||||
}
|
||||
|
||||
public void testProjectBuildDirectoryAfterForMojoExecution()
|
||||
throws Exception
|
||||
{
|
||||
Properties testProperties = new Properties();
|
||||
|
||||
File testPropertiesFile = new File( basedir, "target/mojo-generated.properties" );
|
||||
|
||||
assertTrue( testPropertiesFile.exists() );
|
||||
|
||||
testProperties.load( new FileInputStream( testPropertiesFile ) );
|
||||
|
||||
File projectBuildDirectory = new File( basedir, "target" );
|
||||
|
||||
assertEquals( testProperties.getProperty( "project.build.directory" ), projectBuildDirectory.getAbsolutePath() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -722,6 +722,43 @@ public class DefaultMavenProjectBuilder
|
|||
context.put( "basedir", projectDir.getAbsolutePath() );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// We need to translate the paths before interpolation so that things
|
||||
// like this:
|
||||
//
|
||||
//<project>
|
||||
// ...
|
||||
// <build>
|
||||
// <plugins>
|
||||
// <plugin>
|
||||
// <groupId>org.apache.maven.plugins</groupId>
|
||||
// <artifactId>maven-core-it-plugin</artifactId>
|
||||
// <executions>
|
||||
// <execution>
|
||||
// <phase>process-resources</phase>
|
||||
// <configuration>
|
||||
// <pomBuildDirectory>${pom.build.directory}</pomBuildDirectory>
|
||||
// </configuration>
|
||||
// <goals>
|
||||
// <goal>generate-properties</goal>
|
||||
// </goals>
|
||||
// </execution>
|
||||
// </executions>
|
||||
// </plugin>
|
||||
// </plugins>
|
||||
// </build>
|
||||
//</project>
|
||||
//
|
||||
// Are handled correctly where the ${pom.build.directory} must be path
|
||||
// translated in the POM first. So in the Super POM the ${pom.build.directory}
|
||||
// will get shifted to /some/absolute/path/target and then during the
|
||||
// interpolation phase the <pomBuildDirectory/> element up thre will
|
||||
// have the ${pom.build.directory} string swapped out and replaced with
|
||||
// /some/absolute/path/target. [MNG-1927]
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
pathTranslator.alignToBaseDirectory( project.getModel(), projectDir );
|
||||
|
||||
model = modelInterpolator.interpolate( model, context, strict );
|
||||
|
||||
// interpolation is before injection, because interpolation is off-limits in the injected variables
|
||||
|
|
|
@ -80,7 +80,7 @@ public class DefaultPathTranslator
|
|||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
s = new File( basedir, s ).getPath();
|
||||
s = new File( basedir, s ).getAbsolutePath();
|
||||
}
|
||||
|
||||
return s;
|
||||
|
|
Loading…
Reference in New Issue