From d52ffdef81eab1caea1bb14ca6f04c01dd76daf9 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 24 Jul 2008 01:56:21 +0000 Subject: [PATCH] reapplying John's merge of all 2.0.10-RC changes to date by reverting r679244, sans artifact upgrade and user agent parts. Passes all integration tests locally, seeing if Hudson and Continuum agree git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@679263 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 8 ++ .../maven/lifecycle/LifecycleExecutor.java | 7 ++ .../DefaultLifecycleBindingManager.java | 7 +- .../binding/LifecycleBindingManager.java | 2 + .../project/DefaultMavenProjectBuilder.java | 4 + .../org/apache/maven/project/ModelUtils.java | 2 + .../project/artifact/MavenMetadataSource.java | 22 +++-- ...java => PathTranslatingPostProcessor.java} | 21 +++-- .../RegexBasedModelInterpolator.java | 22 +++-- .../org/apache/maven/project/pom-4.0.0.xml | 6 +- .../RegexBasedModelInterpolatorTest.java | 85 +++++++++++++++++++ .../project-dynamism/plugin-level-dep.pom.xml | 24 ++++++ pom.xml | 25 +++++- 13 files changed, 206 insertions(+), 29 deletions(-) rename maven-project/src/main/java/org/apache/maven/project/interpolation/{PathTranslatingValueSource.java => PathTranslatingPostProcessor.java} (78%) create mode 100644 maven-project/src/test/resources/project-dynamism/plugin-level-dep.pom.xml diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index f189ea6d8e..4f3737e666 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -28,6 +28,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; +import org.apache.maven.lifecycle.binding.LifecycleBindingManager; import org.apache.maven.lifecycle.binding.MojoBindingFactory; import org.apache.maven.lifecycle.model.MojoBinding; import org.apache.maven.lifecycle.plan.BuildPlan; @@ -91,6 +92,8 @@ public class DefaultLifecycleExecutor private BuildPlanner buildPlanner; private MojoBindingFactory mojoBindingFactory; + + private LifecycleBindingManager lifecycleBindingManager; // this is needed for setting the lookup realm before we start building a project. private PlexusContainer container; @@ -959,4 +962,9 @@ public class DefaultLifecycleExecutor { container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } + + public List getLifecycles() + { + return lifecycleBindingManager.getLifecycles(); + } } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java index 13df2855fa..9a09b7ad59 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java @@ -19,6 +19,8 @@ package org.apache.maven.lifecycle; * under the License. */ +import java.util.List; + import org.apache.maven.BuildFailureException; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; @@ -56,4 +58,9 @@ public interface LifecycleExecutor void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher ) throws LifecycleExecutionException, BuildFailureException; + /** + * @since 2.0.10 + */ + List getLifecycles(); + } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java index fbb00fe835..463736a1dd 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java @@ -64,13 +64,18 @@ public class DefaultLifecycleBindingManager private Logger logger; // configured. Moved out of DefaultLifecycleExecutor... - private List lifecycles; + private List lifecycles; // configured. Moved out of DefaultLifecycleExecutor... private List defaultReports; // contextualized, used for setting lookup realm before retrieving lifecycle bindings for packaging. private PlexusContainer container; + + public List getLifecycles() + { + return lifecycles; + } /** * {@inheritDoc} diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java index 88cad3a5db..4844ed3978 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java @@ -82,4 +82,6 @@ public interface LifecycleBindingManager final LifecycleBindings lifecycleBindings ) throws LifecycleSpecificationException; + List getLifecycles(); + } 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 af98731b7a..4f87ff378a 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 @@ -1087,6 +1087,8 @@ public class DefaultMavenProjectBuilder dPlugin.setGroupId( iPlugin.getGroupId() ); dPlugin.setArtifactId( iPlugin.getArtifactId() ); dPlugin.setVersion( iPlugin.getVersion() ); + + dPlugin.setDependencies( iPlugin.getDependencies() ); } } @@ -1108,6 +1110,8 @@ public class DefaultMavenProjectBuilder dPlugin.setGroupId( iPlugin.getGroupId() ); dPlugin.setArtifactId( iPlugin.getArtifactId() ); dPlugin.setVersion( iPlugin.getVersion() ); + + dPlugin.setDependencies( iPlugin.getDependencies() ); } } } diff --git a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java index f6e424e972..b453f0dfa7 100644 --- a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java +++ b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java @@ -562,6 +562,8 @@ public final class ModelUtils public static Model cloneModel( Model model ) { // TODO: would be nice for the modello:java code to generate this as a copy constructor + // FIXME: Fix deep cloning issues with existing plugin instances (setting + // a version when resolved will pollute the original model instance) Model newModel = new Model(); ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler(); newModel.setModelVersion( model.getModelVersion() ); diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index cc2e0dc050..d26710253a 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -101,22 +101,34 @@ public class MavenMetadataSource return artifact; } - ProjectRelocation res = retrieveRelocatedProject( artifact, localRepository, remoteRepositories ); - MavenProject project = res.project; - + ProjectRelocation rel = retrieveRelocatedProject( artifact, localRepository, remoteRepositories ); + + if ( rel == null ) + { + return artifact; + } + + MavenProject project = rel.project; if ( project == null || getRelocationKey( artifact ).equals( getRelocationKey( project.getArtifact() ) ) ) { return artifact; } + + // NOTE: Using artifact information here, since some POMs are deployed + // to central with one version in the filename, but another in the string! + // Case in point: org.apache.ws.commons:XmlSchema:1.1:pom. + // + // Since relocation triggers a reconfiguration of the artifact's information + // in retrieveRelocatedProject(..), this is safe to do. Artifact result = null; if ( artifact.getClassifier() != null ) { - result = artifactFactory.createArtifactWithClassifier( project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getType(), artifact.getClassifier() ); + result = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier() ); } else { - result = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), artifact.getScope(), artifact.getType() ); + result = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope(), artifact.getType() ); } result.setScope( artifact.getScope() ); diff --git a/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingValueSource.java b/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java similarity index 78% rename from maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingValueSource.java rename to maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java index 7f72d691d9..9561942392 100644 --- a/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingValueSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java @@ -1,3 +1,5 @@ +package org.apache.maven.project.interpolation; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -17,33 +19,34 @@ * under the License. */ -package org.apache.maven.project.interpolation; - import org.apache.maven.project.path.PathTranslator; import org.codehaus.plexus.interpolation.AbstractFunctionValueSourceWrapper; +import org.codehaus.plexus.interpolation.InterpolationPostProcessor; import org.codehaus.plexus.interpolation.ValueSource; import java.io.File; import java.util.List; -public class PathTranslatingValueSource - extends AbstractFunctionValueSourceWrapper +/** + * + * @version $Id: PathTranslatingPostProcessor.java 677447 2008-07-16 22:15:57Z jdcasey $ + */ +public class PathTranslatingPostProcessor + implements InterpolationPostProcessor { - private final List unprefixedPathKeys; + private final List unprefixedPathKeys; private final File projectDir; private final PathTranslator pathTranslator; - protected PathTranslatingValueSource( ValueSource valueSource, List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator ) + public PathTranslatingPostProcessor( List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator ) { - super( valueSource ); this.unprefixedPathKeys = unprefixedPathKeys; this.projectDir = projectDir; this.pathTranslator = pathTranslator; } - @Override - protected Object executeFunction( String expression, + public Object execute( String expression, Object value ) { if ( projectDir != null && value != null && unprefixedPathKeys.contains( expression ) ) 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 2baac050be..b2fb498a29 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 @@ -88,6 +88,12 @@ public class RegexBasedModelInterpolator throws IOException { } + + // for testing. + protected RegexBasedModelInterpolator( PathTranslator pathTranslator ) + { + this.pathTranslator = pathTranslator; + } public Model interpolate( Model model, Map context ) throws ModelInterpolationException @@ -199,15 +205,8 @@ public class RegexBasedModelInterpolator timestampFormat = modelProperties.getProperty( BUILD_TIMESTAMP_FORMAT_PROPERTY, timestampFormat ); } - ValueSource baseModelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false ); - ValueSource modelValueSource1 = new PathTranslatingValueSource( baseModelValueSource1, - TRANSLATED_PATH_EXPRESSIONS, - projectDir, pathTranslator ); - - ValueSource baseModelValueSource2 = new ObjectBasedValueSource( model ); - ValueSource modelValueSource2 = new PathTranslatingValueSource( baseModelValueSource2, - TRANSLATED_PATH_EXPRESSIONS, - projectDir, pathTranslator ); + ValueSource modelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false ); + ValueSource modelValueSource2 = new ObjectBasedValueSource( model ); ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource(){ public Object getValue( String expression ) @@ -232,6 +231,11 @@ public class RegexBasedModelInterpolator interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) ); interpolator.addValueSource( modelValueSource2 ); interpolator.addValueSource( new MapBasedValueSource( config.getUserProperties() ) ); + + PathTranslatingPostProcessor pathTranslatingPostProcessor = + new PathTranslatingPostProcessor( TRANSLATED_PATH_EXPRESSIONS, projectDir, pathTranslator ); + + interpolator.addPostProcessor( pathTranslatingPostProcessor ); RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES ); diff --git a/maven-project/src/main/resources/org/apache/maven/project/pom-4.0.0.xml b/maven-project/src/main/resources/org/apache/maven/project/pom-4.0.0.xml index c8ebf420a8..c89c1822a2 100644 --- a/maven-project/src/main/resources/org/apache/maven/project/pom-4.0.0.xml +++ b/maven-project/src/main/resources/org/apache/maven/project/pom-4.0.0.xml @@ -115,7 +115,7 @@ under the License. maven-plugin-plugin - 2.3 + 2.4.2 maven-rar-plugin @@ -131,7 +131,7 @@ under the License. maven-site-plugin - 2.0-beta-6 + 2.0-beta-7 maven-source-plugin @@ -139,7 +139,7 @@ under the License. maven-surefire-plugin - 2.4.2 + 2.4.3 maven-war-plugin diff --git a/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java b/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java index 0fdf57ce27..438cb40177 100644 --- a/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java @@ -19,19 +19,25 @@ package org.apache.maven.project.interpolation; * under the License. */ +import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Organization; import org.apache.maven.model.Repository; +import org.apache.maven.model.Resource; import org.apache.maven.model.Scm; import org.apache.maven.project.DefaultProjectBuilderConfiguration; import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.path.DefaultPathTranslator; +import org.apache.maven.project.path.PathTranslator; import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -297,4 +303,83 @@ public class RegexBasedModelInterpolatorTest assertEquals( "Expected '" + expectedVersion + "' for version expression '" + depVersionExpr + "', but was '" + result + "'", expectedVersion, result ); } + public void testShouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() + throws Exception + { + Model model = new Model(); + + Build build = new Build(); + build.setSourceDirectory( "correct" ); + + Resource res = new Resource(); + res.setDirectory( "${project.build.sourceDirectory}" ); + + build.addResource( res ); + + Resource res2 = new Resource(); + res2.setDirectory( "${pom.build.sourceDirectory}" ); + + build.addResource( res2 ); + + Resource res3 = new Resource(); + res3.setDirectory( "${build.sourceDirectory}" ); + + build.addResource( res3 ); + + model.setBuild( build ); + + Model out = new RegexBasedModelInterpolator().interpolate( model, context ); + + List outResources = out.getBuild().getResources(); + Iterator resIt = outResources.iterator(); + + assertEquals( build.getSourceDirectory(), ( (Resource) resIt.next() ).getDirectory() ); + assertEquals( build.getSourceDirectory(), ( (Resource) resIt.next() ).getDirectory() ); + assertEquals( build.getSourceDirectory(), ( (Resource) resIt.next() ).getDirectory() ); + } + + public void testShouldInterpolateUnprefixedBasedirExpression() + throws ModelInterpolationException, IOException + { + File basedir = new File( "/test/path" ); + Model model = new Model(); + Dependency dep = new Dependency(); + dep.setSystemPath( "${basedir}/artifact.jar" ); + + model.addDependency( dep ); + + Model result = new RegexBasedModelInterpolator().interpolate( model, basedir, new DefaultProjectBuilderConfiguration(), true ); + + List rDeps = result.getDependencies(); + assertNotNull( rDeps ); + assertEquals( 1, rDeps.size() ); + assertEquals( new File( basedir, "artifact.jar" ).getAbsolutePath(), new File( ( (Dependency) rDeps.get( 0 ) ) + .getSystemPath() ).getAbsolutePath() ); + } + + public void testTwoLevelRecursiveBasedirAlignedExpression() + throws Exception + { + Model model = new Model(); + Build build = new Build(); + + model.setBuild( build ); + + build.setDirectory( "${project.basedir}/target" ); + build.setOutputDirectory( "${project.build.directory}/classes" ); + + PathTranslator translator = new DefaultPathTranslator(); + RegexBasedModelInterpolator interpolator = new RegexBasedModelInterpolator( translator ); + + File basedir = new File( System.getProperty( "java.io.tmpdir" ), "base" ); + + String value = interpolator.interpolate( "${project.build.outputDirectory}/foo", model, basedir, new DefaultProjectBuilderConfiguration(), true ); + value = value.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); + + String check = new File( basedir, "target/classes/foo" ).getAbsolutePath(); + check = check.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); + + assertEquals( check, value ); + } + } diff --git a/maven-project/src/test/resources/project-dynamism/plugin-level-dep.pom.xml b/maven-project/src/test/resources/project-dynamism/plugin-level-dep.pom.xml new file mode 100644 index 0000000000..988736751a --- /dev/null +++ b/maven-project/src/test/resources/project-dynamism/plugin-level-dep.pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + testing + plugin-level-dep + jar + 3.8.1 + + + + + maven-compiler-plugin + 2.0.2 + + + junit + junit + ${pom.version} + + + + + + diff --git a/pom.xml b/pom.xml index 71519b7c65..d25ecbc7b6 100644 --- a/pom.xml +++ b/pom.xml @@ -202,6 +202,27 @@ maven-bundle-plugin 1.0.0 + + org.codehaus.mojo + clirr-maven-plugin + 2.2.1 + + + 2.0.9 + + + org/apache/maven/lifecycle/LifecycleExecutor* + org/apache/maven/artifact/metadata/ArtifactMetadataSource* + org/apache/maven/project/MavenProjectBuilder* + org/apache/maven/project/ProjectBuilderConfiguration* + org/apache/maven/project/interpolation/ModelInterpolator* + org/apache/maven/project/inheritance/ModelInheritanceAssembler* + org/apache/maven/execution/MavenExecutionRequest* + org/apache/maven/plugin/DefaultPluginManager* + + + org.apache.maven.plugins maven-surefire-plugin @@ -247,8 +268,8 @@ 3.8.1 1.0-alpha-48 1.0-alpha-6 - 1.0 - 1.5.4 + 1.1 + 1.5.5 1.0-beta-3