From 32d8679253197b09529f44a6b789eee0ca0a6ac7 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 30 Mar 2006 11:48:12 +0000 Subject: [PATCH] [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 --- .../InterpolatedPomConfigurationMojo.java | 18 +++++++++ maven-core-it/it0088/pom.xml | 8 ++-- .../maven/it0088/PomInterpolationTest.java | 13 ++++--- .../project/DefaultMavenProjectBuilder.java | 39 +++++++++++-------- .../RegexBasedModelInterpolator.java | 9 ++++- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java index 43556b94ce..04e791edc4 100644 --- a/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java +++ b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/InterpolatedPomConfigurationMojo.java @@ -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" ) ); diff --git a/maven-core-it/it0088/pom.xml b/maven-core-it/it0088/pom.xml index c168fedca6..0e063010b5 100644 --- a/maven-core-it/it0088/pom.xml +++ b/maven-core-it/it0088/pom.xml @@ -29,6 +29,8 @@ process-resources ${project.build.directory} + target + target generate-properties @@ -40,9 +42,9 @@ - snapshots - Maven Central Plugins Development Repository - http://snapshots.maven.codehaus.org/maven2 + apache.snapshots + Maven Plugins Development Repository + http://cvs.apache.org/maven-snapshot-repository diff --git a/maven-core-it/it0088/src/test/java/org/apache/maven/it0088/PomInterpolationTest.java b/maven-core-it/it0088/src/test/java/org/apache/maven/it0088/PomInterpolationTest.java index c65fc295ae..8e38533e08 100644 --- a/maven-core-it/it0088/src/test/java/org/apache/maven/it0088/PomInterpolationTest.java +++ b/maven-core-it/it0088/src/test/java/org/apache/maven/it0088/PomInterpolationTest.java @@ -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" ) ); } } diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index ffa50e7779..87182e50a5 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -687,20 +687,17 @@ public class DefaultMavenProjectBuilder // 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 @@ 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 @@ -1005,18 +1010,18 @@ public class DefaultMavenProjectBuilder // 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 @@ public class DefaultMavenProjectBuilder 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 @@ public class DefaultMavenProjectBuilder { 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 @@ public class DefaultMavenProjectBuilder // 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 @@ public class DefaultMavenProjectBuilder { parentProjectDir = parentDescriptor.getParentFile(); } - + parentProject = assembleLineage( model, lineage, localRepository, parentProjectDir, parentSearchRepositories, aggregatedRemoteWagonRepositories, externalProfileManager, strict ); @@ -1160,7 +1165,7 @@ public class DefaultMavenProjectBuilder project.setParent( parentProject ); project.setParentArtifact( parentArtifact ); - + } return project; diff --git a/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java b/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java index 63c8d154ec..c9898285f9 100644 --- a/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java +++ b/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java @@ -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 ); } @@ -137,7 +144,7 @@ public class RegexBasedModelInterpolator 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 ); }