mirror of https://github.com/apache/maven.git
[MNG-2186] correct the regression of MNG-1927 from the solution of MNG-2124
The interpolator was only working based on an incorrect assumption for a limited set of expressions. This assumption is guaranteed by the solution in the interim, until it can be properly reconsidered. The proper solution would be to not cache an interpolated model, and to apply path translation and then interpolation after retrieving the cached model. However, this will require some other related changes and should be planned for 2.1. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@390098 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d04fee6bb1
commit
32d8679253
|
@ -26,6 +26,16 @@ public class InterpolatedPomConfigurationMojo
|
|||
*/
|
||||
private String projectBuildDirectory;
|
||||
|
||||
/**
|
||||
* @parameter expression="${targetDirectoryString}"
|
||||
*/
|
||||
private String targetDirectoryString;
|
||||
|
||||
/**
|
||||
* @parameter expression="${targetDirectoryFile}"
|
||||
*/
|
||||
private File targetDirectoryFile;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
|
@ -34,6 +44,14 @@ public class InterpolatedPomConfigurationMojo
|
|||
Properties mojoGeneratedPropeties = new Properties();
|
||||
|
||||
mojoGeneratedPropeties.put( "project.build.directory", projectBuildDirectory );
|
||||
if ( targetDirectoryString != null )
|
||||
{
|
||||
mojoGeneratedPropeties.put( "targetDirectoryString", targetDirectoryString );
|
||||
}
|
||||
if ( targetDirectoryFile != null )
|
||||
{
|
||||
mojoGeneratedPropeties.put( "targetDirectoryFile", targetDirectoryFile.getAbsolutePath() );
|
||||
}
|
||||
|
||||
FileOutputStream fos = new FileOutputStream( new File( basedir, "target/mojo-generated.properties" ) );
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<projectBuildDirectory>${project.build.directory}</projectBuildDirectory>
|
||||
<targetDirectoryString>target</targetDirectoryString>
|
||||
<targetDirectoryFile>target</targetDirectoryFile>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>generate-properties</goal>
|
||||
|
@ -40,9 +42,9 @@
|
|||
</build>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>snapshots</id>
|
||||
<name>Maven Central Plugins Development Repository</name>
|
||||
<url>http://snapshots.maven.codehaus.org/maven2</url>
|
||||
<id>apache.snapshots</id>
|
||||
<name>Maven Plugins Development Repository</name>
|
||||
<url>http://cvs.apache.org/maven-snapshot-repository</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
||||
|
|
|
@ -30,10 +30,10 @@ public class PomInterpolationTest
|
|||
|
||||
File projectBuildDirectory = new File( basedir, "target" );
|
||||
|
||||
assertEquals( testProperties.getProperty( "project.build.directory" ), projectBuildDirectory.getAbsolutePath() );
|
||||
assertEquals( projectBuildDirectory.getAbsolutePath(), testProperties.getProperty( "project.build.directory" ) );
|
||||
}
|
||||
|
||||
public void testProjectBuildDirectoryAfterForMojoExecution()
|
||||
public void testProjectBuildDirectoryForMojoExecution()
|
||||
throws Exception
|
||||
{
|
||||
Properties testProperties = new Properties();
|
||||
|
@ -44,9 +44,10 @@ public class PomInterpolationTest
|
|||
|
||||
testProperties.load( new FileInputStream( testPropertiesFile ) );
|
||||
|
||||
// [jdcasey] NOTE: This property is not a java.io.File, so it will NOT be adjusted
|
||||
// to the basedir! We need to simply check that it's value is "target", rather than
|
||||
// new java.io.File( basedir, "target" ).getAbsolutePath();
|
||||
assertEquals( testProperties.getProperty( "project.build.directory" ), "target" );
|
||||
File projectBuildDirectory = new File( basedir, "target" );
|
||||
|
||||
assertEquals( projectBuildDirectory.getAbsolutePath(), testProperties.getProperty( "project.build.directory" ) );
|
||||
assertEquals( projectBuildDirectory.getAbsolutePath(), testProperties.getProperty( "targetDirectoryFile" ) );
|
||||
assertEquals( "target", testProperties.getProperty( "targetDirectoryString" ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -690,13 +690,10 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
Model previous = superProject.getModel();
|
||||
|
||||
// System.out.println( "Assembling inheritance..." );
|
||||
|
||||
for ( Iterator i = lineage.iterator(); i.hasNext(); )
|
||||
{
|
||||
MavenProject currentProject = (MavenProject) i.next();
|
||||
|
||||
// System.out.println( "Assembling inheritance: " + previousProject.getId() + "(" + previousProject.getName() + ")" + " <- " + currentProject.getId() + "(" + currentProject.getName() + ")" );
|
||||
Model current = currentProject.getModel();
|
||||
|
||||
String pathAdjustment = null;
|
||||
|
@ -714,8 +711,6 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
previous = current;
|
||||
previousProject = currentProject;
|
||||
|
||||
// System.out.println( "New parent project is: " + previousProject.getId() + "(" + previousProject.getName() + ")" );
|
||||
}
|
||||
|
||||
// only add the super repository if it wasn't overridden by a profile or project
|
||||
|
@ -841,6 +836,16 @@ public class DefaultMavenProjectBuilder
|
|||
context.put( "basedir", projectDir.getAbsolutePath() );
|
||||
}
|
||||
|
||||
// TODO: this is a hack to ensure MNG-2124 can be satisfied without triggering MNG-1927
|
||||
// MNG-1927 relies on the false assumption that ${project.build.*} evaluates to null, which occurs before
|
||||
// MNG-2124 is fixed. The null value would leave it uninterpolated, to be handled after path translation.
|
||||
// Until these steps are correctly sequenced, we guarantee these fields remain uninterpolated.
|
||||
context.put( "build.directory", null );
|
||||
context.put( "build.outputDirectory", null );
|
||||
context.put( "build.testOutputDirectory", null );
|
||||
context.put( "build.sourceDirectory", null );
|
||||
context.put( "build.testSourceDirectory", null );
|
||||
|
||||
model = modelInterpolator.interpolate( model, context, strict );
|
||||
|
||||
// interpolation is before injection, because interpolation is off-limits in the injected variables
|
||||
|
|
|
@ -129,6 +129,13 @@ public class RegexBasedModelInterpolator
|
|||
|
||||
if ( value == null )
|
||||
{
|
||||
// This may look out of place, but its here for the MNG-2124/MNG-1927 fix described in the project builder
|
||||
if ( context.containsKey( realExpr ) )
|
||||
{
|
||||
// It existed, but was null. Leave it alone.
|
||||
continue;
|
||||
}
|
||||
|
||||
value = model.getProperties().getProperty( realExpr );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue