[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:
Brett Leslie Porter 2006-03-30 11:48:12 +00:00
parent d04fee6bb1
commit 32d8679253
5 changed files with 60 additions and 27 deletions

View File

@ -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 void execute()
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" ) );

View File

@ -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>

View File

@ -30,10 +30,10 @@ public void testProjectBuildDirectoryAfterResourceFiltering()
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 void testProjectBuildDirectoryAfterForMojoExecution()
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" ) );
}
}

View File

@ -687,20 +687,17 @@ private MavenProject buildInternal( String pomLocation,
// we don't have to force the collision exception for superModel here, it's already been done in getSuperModel()
MavenProject previousProject = superProject;
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;
try
{
pathAdjustment = previousProject.getModulePathAdjustment( currentProject );
@ -714,8 +711,6 @@ private MavenProject buildInternal( String pomLocation,
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 @@ private MavenProject processProjectLogic( String pomLocation,
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
@ -1005,18 +1010,18 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
// the only way this will have a value is if we find the parent on disk...
File parentDescriptor = null;
if ( parentProject != null )
{
model = parentProject.getOriginalModel();
parentDescriptor = parentProject.getFile();
}
else
{
model = null;
}
String parentRelativePath = parentModel.getRelativePath();
// if we can't find a cached model matching the parent spec, then let's try to look on disk using
@ -1024,7 +1029,7 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
if ( model == null && projectDir != null && StringUtils.isNotEmpty( parentRelativePath ) )
{
parentDescriptor = new File( projectDir, parentRelativePath );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Searching for parent-POM: " + parentModel.getId() + " of project: " + project.getId() + " in relative path: " + parentRelativePath );
@ -1046,7 +1051,7 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
{
getLogger().debug( "Parent-POM: " + parentModel.getId() + " for project: " + project.getId() + " cannot be loaded from relative path: " + parentDescriptor + "; path does not exist." );
}
parentDescriptor = null;
}
}
@ -1118,14 +1123,14 @@ else if ( getLogger().isDebugEnabled() )
// we can't query the parent to ask where it is :)
List remoteRepositories = new ArrayList( aggregatedRemoteWagonRepositories );
remoteRepositories.addAll( parentSearchRepositories );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Retrieving parent-POM: " + parentModel.getId() + " for project: "
+ project.getId() + " from the repository." );
}
parentArtifact = artifactFactory.createParentArtifact( parentModel.getGroupId(),
parentModel.getArtifactId(),
parentModel.getVersion() );
@ -1151,7 +1156,7 @@ else if ( getLogger().isDebugEnabled() )
{
parentProjectDir = parentDescriptor.getParentFile();
}
parentProject = assembleLineage( model, lineage, localRepository, parentProjectDir,
parentSearchRepositories, aggregatedRemoteWagonRepositories,
externalProfileManager, strict );
@ -1160,7 +1165,7 @@ else if ( getLogger().isDebugEnabled() )
project.setParent( parentProject );
project.setParentArtifact( parentArtifact );
}
return project;

View File

@ -129,6 +129,13 @@ private String interpolateInternal( String src, Model model, Map context )
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 );
}
@ -137,7 +144,7 @@ private String interpolateInternal( String src, Model model, Map context )
try
{
// NOTE: We've already trimmed off any leading expression parts like 'project.'
// or 'pom.', and now we have to ensure that the ReflectionValueExtractor
// or 'pom.', and now we have to ensure that the ReflectionValueExtractor
// doesn't try to do it again.
value = ReflectionValueExtractor.evaluate( realExpr, model, false );
}