mirror of
https://github.com/apache/maven.git
synced 2025-02-28 05:39:15 +00:00
[MNG-3355] Use translated paths to resolve expressions referencing build directories in the model during interpolation, if the project-descriptor is known (if the project is from the local filesystem, not from the repository system).
Also, merge repositories and pluginRepositories when creating their ArtifactRepository analogs, to restore the pluginRepository functionality. I've added a deprecation warning in these cases, but it may need to be made more prominent. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@637326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
78f361ecd4
commit
b8fb4e3471
@ -945,19 +945,29 @@ private MavenProject processProjectLogic( MavenProject project,
|
||||
|
||||
if ( pomFile != null )
|
||||
{
|
||||
File projectDir = pomFile.getAbsoluteFile().getParentFile();
|
||||
|
||||
context.put( "basedir", pomFile.getParentFile().getAbsolutePath() );
|
||||
context.put( "basedir", projectDir.getAbsolutePath() );
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
// MNG-1927, MNG-2124, MNG-3355:
|
||||
// If the build section is present and the project directory is non-null, we should make
|
||||
// sure interpolation of the directories below uses translated paths.
|
||||
// Afterward, we'll double back and translate any paths that weren't covered during interpolation via the
|
||||
// code below...
|
||||
context.put( "build.directory", pathTranslator.alignToBaseDirectory( build.getDirectory(), projectDir ) );
|
||||
context.put( "build.outputDirectory", pathTranslator.alignToBaseDirectory( build.getOutputDirectory(), projectDir ) );
|
||||
context.put( "build.testOutputDirectory", pathTranslator.alignToBaseDirectory( build.getTestOutputDirectory(), projectDir ) );
|
||||
context.put( "build.sourceDirectory", pathTranslator.alignToBaseDirectory( build.getSourceDirectory(), projectDir ) );
|
||||
context.put( "build.testSourceDirectory", pathTranslator.alignToBaseDirectory( build.getTestSourceDirectory(), projectDir ) );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
|
||||
// [MNG-2339] ensure the system properties are still interpolated for backwards compat, but the model values must win
|
||||
context.putAll( System.getProperties() );
|
||||
model = modelInterpolator.interpolate( model, context, strict );
|
||||
|
||||
// interpolation is before injection, because interpolation is off-limits in the injected variables
|
||||
@ -1009,8 +1019,20 @@ private MavenProject processProjectLogic( MavenProject project,
|
||||
|
||||
try
|
||||
{
|
||||
LinkedHashSet repoSet = new LinkedHashSet();
|
||||
if ( ( model.getRepositories() != null ) && !model.getRepositories().isEmpty() )
|
||||
{
|
||||
repoSet.addAll( model.getRepositories() );
|
||||
}
|
||||
|
||||
if ( ( model.getPluginRepositories() != null ) && !model.getPluginRepositories().isEmpty() )
|
||||
{
|
||||
getLogger().warn( "The <pluginRepositories/> section of the POM has been deprecated. Please update your POMs." );
|
||||
repoSet.addAll( model.getPluginRepositories() );
|
||||
}
|
||||
|
||||
project.setRemoteArtifactRepositories(
|
||||
mavenTools.buildArtifactRepositories( model.getRepositories() ) );
|
||||
mavenTools.buildArtifactRepositories( new ArrayList( repoSet ) ) );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
|
@ -22,7 +22,9 @@
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -105,6 +107,31 @@ public void testDuplicatePluginDefinitionsMerged()
|
||||
assertEquals( 2, ( (Plugin) project.getBuildPlugins().get( 0 ) ).getDependencies().size() );
|
||||
}
|
||||
|
||||
public void testBuildDirectoryExpressionInterpolatedWithTranslatedValue()
|
||||
throws Exception
|
||||
{
|
||||
File pom = getTestFile( "src/test/resources/projects/build-path-expression-pom.xml" );
|
||||
|
||||
MavenProject project = getProject( pom );
|
||||
|
||||
Build build = project.getBuild();
|
||||
assertNotNull( "Project should have a build section containing the test resource.", build );
|
||||
|
||||
String sourceDirectory = build.getSourceDirectory();
|
||||
assertNotNull( "Project build should contain a valid source directory.", sourceDirectory );
|
||||
|
||||
List resources = build.getResources();
|
||||
assertNotNull( "Project should contain a build resource.", resources );
|
||||
assertEquals( "Project should contain exactly one build resource.", 1, resources.size() );
|
||||
|
||||
Resource res = (Resource) resources.get( 0 );
|
||||
assertEquals( "Project resource should be the same directory as the source directory.",
|
||||
sourceDirectory,
|
||||
res.getDirectory() );
|
||||
|
||||
System.out.println( "Interpolated, translated resource directory is: " + res.getDirectory() );
|
||||
}
|
||||
|
||||
protected ArtifactRepository getLocalRepository()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -0,0 +1,14 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.project.tests</groupId>
|
||||
<artifactId>build-path-expression</artifactId>
|
||||
<version>1</version>
|
||||
<build>
|
||||
<sourceDirectory>sources</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.sourceDirectory}</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user