diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index c1388a0b14..da0fc8355f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -566,7 +566,7 @@ public class DefaultPluginManager List interpolatorProperties = new ArrayList(); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties(), - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); + PomInterpolatorTag.EXECUTION_PROPERTIES.name())); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(), PomInterpolatorTag.USER_PROPERTIES.name())); diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java index c95cef64c2..c6fa363788 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java @@ -71,12 +71,12 @@ public final class MavenDependencyProcessor List interpolatorProperties = new ArrayList(); interpolatorProperties.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT", - PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) ); + PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) ); if ( system != null ) { interpolatorProperties.addAll( - InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) ); + InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) ); } if ( user != null ) { diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java index 37af3d9ea0..5f7693550e 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java @@ -8,7 +8,5 @@ public enum PomInterpolatorTag PROJECT_PROPERTIES, - SYSTEM_PROPERTIES - - + EXECUTION_PROPERTIES } 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 d0c753b6f8..1ac1fa9362 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 @@ -22,9 +22,6 @@ package org.apache.maven.project; import java.io.File; import java.io.IOException; import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -46,7 +43,6 @@ import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Profile; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.profiles.MavenProfilesBuilder; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.activation.DefaultProfileActivationContext; @@ -55,7 +51,6 @@ import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.build.ProfileAdvisor; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.builder.DefaultPomArtifactResolver; -import org.apache.maven.project.builder.Interpolator; import org.apache.maven.project.builder.PomArtifactResolver; import org.apache.maven.project.builder.PomInterpolatorTag; import org.apache.maven.project.builder.ProjectBuilder; @@ -218,98 +213,34 @@ public class DefaultMavenProjectBuilder /** * This is used for pom-less execution like running archetype:generate. + * + * I am taking out the profile handling and the interpolation of the base directory until we spec + * this out properly. */ public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config ) throws ProjectBuildingException { Model superModel = getSuperModel(); - - ProfileManager profileManager = config.getGlobalProfileManager(); - - List activeProfiles = new ArrayList(); - if ( profileManager != null ) - { - List activated = profileAdvisor.applyActivatedProfiles( superModel, null, false, - profileManager.getProfileActivationContext() ); - if ( !activated.isEmpty() ) - { - activeProfiles.addAll( activated ); - } - - activated = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager ); - if ( !activated.isEmpty() ) - { - activeProfiles.addAll( activated ); - } - } - - List interpolatorProperties = new ArrayList(); + + MavenProject project = null; - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); - - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), - PomInterpolatorTag.USER_PROPERTIES.name())); - - if(config.getBuildStartTime() != null) - { - interpolatorProperties.add(new InterpolatorProperty("${build.timestamp}", - new SimpleDateFormat("yyyyMMdd-hhmm").format( config.getBuildStartTime() ), - PomInterpolatorTag.PROJECT_PROPERTIES.name())); - } - - File basedir = null; - for(InterpolatorProperty ip : interpolatorProperties ) - { - if(ip.getKey().equals("${basedir}")) - { - basedir = new File(ip.getValue()); - break; - } - } - - if(basedir == null) - { - String bd = System.getProperty("basedir"); - if( bd != null ) - { - basedir = new File(bd); - } - } - - try - { - superModel = Interpolator.interpolateModel(superModel, interpolatorProperties, basedir ); - } - catch (IOException e) - { - throw new ProjectBuildingException(STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID, "Interpolation failure:", e); - } - - MavenProject project; try { project = new MavenProject( superModel, artifactFactory, mavenTools, this, config ); } catch ( InvalidRepositoryException e ) { - throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID, - "Maven super-POM contains an invalid repository!", e ); + // Not going to happen. } - getLogger().debug( "Activated the following profiles for standalone super-pom: " + activeProfiles ); - try { - project = constructMavenProjectFromModel( project.getModel(), null, null, config ); - project.setActiveProfiles( activeProfiles ); project.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); } catch ( InvalidRepositoryException e ) { - throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID, - "Maven super-POM contains an invalid repository!", e ); + // Not going to happen. } project.setExecutionRoot( true ); @@ -391,7 +322,16 @@ public class DefaultMavenProjectBuilder try { - project = constructMavenProjectFromModel( model, projectDescriptor, parentDescriptor, config ); + project = new MavenProject( model, artifactFactory, mavenTools, this, config ); + + validateModel( model, projectDescriptor ); + + Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), + project.getVersion(), project.getPackaging() ); + project.setArtifact( projectArtifact ); + + project.setParentFile( parentDescriptor ); + } catch ( InvalidRepositoryException e ) { @@ -409,22 +349,6 @@ public class DefaultMavenProjectBuilder return project; } - private MavenProject constructMavenProjectFromModel( Model model, File pomFile, File parentFile, - ProjectBuilderConfiguration config ) - throws ProjectBuildingException, InvalidRepositoryException - { - - MavenProject project = new MavenProject( model, artifactFactory, mavenTools, this, config ); - validateModel( model, pomFile ); - - Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), project.getPackaging() ); - project.setArtifact( projectArtifact ); - project.setParentFile( parentFile ); - - return project; - } - private MavenProject superProject; private MavenProject getSuperProject( ProjectBuilderConfiguration config, File projectDescriptor ) @@ -489,7 +413,7 @@ public class DefaultMavenProjectBuilder List interpolatorProperties = new ArrayList(); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), - PomInterpolatorTag.SYSTEM_PROPERTIES.name())); + PomInterpolatorTag.EXECUTION_PROPERTIES.name())); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), PomInterpolatorTag.USER_PROPERTIES.name())); @@ -501,14 +425,14 @@ public class DefaultMavenProjectBuilder PomInterpolatorTag.PROJECT_PROPERTIES.name())); } - interpolatorProperties.add(new InterpolatorProperty("${mavenVersion}", MavenProjectBuilder.STANDALONE_SUPERPOM_VERSION, PomInterpolatorTag.SYSTEM_PROPERTIES.name())); + interpolatorProperties.add(new InterpolatorProperty("${mavenVersion}", MavenProjectBuilder.STANDALONE_SUPERPOM_VERSION, PomInterpolatorTag.EXECUTION_PROPERTIES.name())); MavenProject mavenProject; try { mavenProject = projectBuilder.buildFromLocalPath( projectDescriptor, - Arrays.asList( getSuperProject( config, projectDescriptor ).getModel() ), + Arrays.asList( getSuperModel() ), interpolatorProperties, resolver, config ); diff --git a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java index a3b18ec56a..06253bb45a 100644 --- a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java @@ -41,33 +41,6 @@ public class SuperPomProjectBuilderTest projectBuilder = lookup( MavenProjectBuilder.class ); } - public void testStandaloneSuperPomContainsInjectedExternalProfileRepositories() - throws Exception - { - Profile profile = new Profile(); - profile.setId( "test-profile" ); - - Repository repo = new Repository(); - repo.setId( "test" ); - repo.setUrl( "http://www.nowhere.com" ); - - profile.addRepository( repo ); - - ProfileManager pm = new DefaultProfileManager( getContainer(), new DefaultProfileActivationContext( new Properties(), true ) ); - - pm.addProfile( profile ); - pm.explicitlyActivate( profile.getId() ); - - ProjectBuilderConfiguration pbc = new DefaultProjectBuilderConfiguration(); - pbc.setGlobalProfileManager( pm ); - MavenProject project = projectBuilder.buildStandaloneSuperProject( pbc ); - - assertRepository( repo.getId(), project.getRepositories() ); - assertRepository( repo.getId(), project.getPluginRepositories() ); - assertArtifactRepository( repo.getId(), project.getRemoteArtifactRepositories() ); - assertArtifactRepository( repo.getId(), project.getPluginArtifactRepositories() ); - } - public void testStandaloneSuperPomContainsCentralRepo() throws ProjectBuildingException {