diff --git a/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 7c1d7e5329..9981a8a253 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -23,6 +23,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Properties; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; @@ -38,6 +39,7 @@ import org.apache.maven.model.building.ModelSource; import org.apache.maven.model.building.UrlModelSource; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.profiles.ProfileManager; +import org.apache.maven.properties.internal.EnvironmentUtils; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.events.TransferListener; import org.codehaus.plexus.component.annotations.Component; @@ -65,21 +67,65 @@ public class DefaultMavenProjectBuilder // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- - public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration ) - throws ProjectBuildingException + private ProjectBuildingRequest toRequest( ProjectBuilderConfiguration configuration ) { - return projectBuilder.build( pomFile, configuration ).getProject(); + DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest(); + + request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ); + request.setResolveDependencies( false ); + + request.setLocalRepository( configuration.getLocalRepository() ); + request.setBuildStartTime( configuration.getBuildStartTime() ); + request.setUserProperties( configuration.getUserProperties() ); + request.setSystemProperties( configuration.getExecutionProperties() ); + + ProfileManager profileManager = configuration.getGlobalProfileManager(); + if ( profileManager != null ) + { + request.setActiveProfileIds( profileManager.getExplicitlyActivatedIds() ); + request.setInactiveProfileIds( profileManager.getExplicitlyDeactivatedIds() ); + } + + return request; } - public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration, boolean allowStubModel ) - throws ProjectBuildingException + private ProjectBuildingRequest injectSession( ProjectBuildingRequest request ) { - normalizeToArtifactRepositories( configuration ); + MavenSession session = legacySupport.getSession(); + if ( session != null ) + { + request.setOffline( session.isOffline() ); + request.setSystemProperties( session.getSystemProperties() ); + if ( request.getUserProperties().isEmpty() ) + { + request.setUserProperties( session.getUserProperties() ); + } - return projectBuilder.build( artifact, allowStubModel, configuration ).getProject(); + MavenExecutionRequest req = session.getRequest(); + if ( req != null ) + { + request.setServers( req.getServers() ); + request.setMirrors( req.getMirrors() ); + request.setProxies( req.getProxies() ); + request.setRemoteRepositories( req.getRemoteRepositories() ); + request.setTransferListener( req.getTransferListener() ); + request.setForceUpdate( req.isUpdateSnapshots() ); + } + } + else + { + Properties props = new Properties(); + EnvironmentUtils.addEnvVars( props ); + props.putAll( System.getProperties() ); + request.setSystemProperties( props ); + } + + return request; } - private void normalizeToArtifactRepositories( ProjectBuilderConfiguration configuration ) + @SuppressWarnings( "unchecked" ) + private List normalizeToArtifactRepositories( List repositories, + ProjectBuildingRequest request ) throws ProjectBuildingException { /* @@ -87,8 +133,6 @@ public class DefaultMavenProjectBuilder * populate the builder configuration with model repositories instead of artifact repositories. */ - List repositories = configuration.getRemoteRepositories(); - if ( repositories != null ) { boolean normalized = false; @@ -102,9 +146,9 @@ public class DefaultMavenProjectBuilder try { ArtifactRepository repo = repositorySystem.buildArtifactRepository( (Repository) repository ); - repositorySystem.injectMirror( Arrays.asList( repo ), configuration.getMirrors() ); - repositorySystem.injectProxy( Arrays.asList( repo ), configuration.getProxies() ); - repositorySystem.injectAuthentication( Arrays.asList( repo ), configuration.getServers() ); + repositorySystem.injectMirror( Arrays.asList( repo ), request.getMirrors() ); + repositorySystem.injectProxy( Arrays.asList( repo ), request.getProxies() ); + repositorySystem.injectAuthentication( Arrays.asList( repo ), request.getServers() ); repos.add( repo ); } catch ( InvalidRepositoryException e ) @@ -121,19 +165,66 @@ public class DefaultMavenProjectBuilder if ( normalized ) { - configuration.setRemoteRepositories( repos ); + return repos; } } + + return (List) repositories; + } + + private ProjectBuildingException transformError( ProjectBuildingException e ) + { + if ( e.getCause() instanceof ModelBuildingException ) + { + return new InvalidProjectModelException( e.getProjectId(), e.getMessage(), e.getPomFile() ); + } + + return e; + } + + public MavenProject build( File pom, ProjectBuilderConfiguration configuration ) + throws ProjectBuildingException + { + ProjectBuildingRequest request = injectSession( toRequest( configuration ) ); + + try + { + return projectBuilder.build( pom, request ).getProject(); + } + catch ( ProjectBuildingException e ) + { + throw transformError( e ); + } } // This is used by the SITE plugin. - public MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) + public MavenProject build( File pom, ArtifactRepository localRepository, ProfileManager profileManager ) throws ProjectBuildingException { - ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() - .setLocalRepository( localRepository ); + ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); + configuration.setLocalRepository( localRepository ); + configuration.setGlobalProfileManager( profileManager ); - return build( project, configuration ); + return build( pom, configuration ); + } + + public MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, + ProjectBuilderConfiguration configuration, boolean allowStubModel ) + throws ProjectBuildingException + { + ProjectBuildingRequest request = injectSession( toRequest( configuration ) ); + request.setRemoteRepositories( normalizeToArtifactRepositories( remoteRepositories, request ) ); + request.setProcessPlugins( false ); + request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); + + try + { + return projectBuilder.build( artifact, allowStubModel, request ).getProject(); + } + catch ( ProjectBuildingException e ) + { + throw transformError( e ); + } } public MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, @@ -142,44 +233,8 @@ public class DefaultMavenProjectBuilder { ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); configuration.setLocalRepository( localRepository ); - configuration.setRemoteRepositories( remoteRepositories ); - configuration.setProcessPlugins( false ); - configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); - MavenSession session = legacySupport.getSession(); - if ( session != null ) - { - MavenExecutionRequest request = session.getRequest(); - if ( request != null ) - { - configuration.setServers( request.getServers() ); - configuration.setMirrors( request.getMirrors() ); - configuration.setProxies( request.getProxies() ); - configuration.setTransferListener( request.getTransferListener() ); - configuration.setForceUpdate( request.isUpdateSnapshots() ); - } - configuration.setOffline( session.isOffline() ); - configuration.setSystemProperties( session.getSystemProperties() ); - configuration.setUserProperties( session.getUserProperties() ); - } - else - { - configuration.setSystemProperties( System.getProperties() ); - } - - try - { - return buildFromRepository( artifact, configuration, allowStubModel ); - } - catch ( ProjectBuildingException e ) - { - if ( e.getCause() instanceof ModelBuildingException ) - { - throw new InvalidProjectModelException( e.getProjectId(), e.getMessage(), e.getPomFile() ); - } - - throw e; - } + return buildFromRepository( artifact, remoteRepositories, configuration, allowStubModel ); } public MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, @@ -190,16 +245,19 @@ 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. + * 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 ) + public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration ) throws ProjectBuildingException { + ProjectBuildingRequest request = injectSession( toRequest( configuration ) ); + request.setProcessPlugins( false ); + request.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); + ModelSource modelSource = new UrlModelSource( getClass().getResource( "standalone.xml" ) ); - MavenProject project = projectBuilder.build( modelSource, config ).getProject(); + + MavenProject project = projectBuilder.build( modelSource, request ).getProject(); project.setExecutionRoot( true ); return project; } @@ -215,42 +273,38 @@ public class DefaultMavenProjectBuilder { ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); configuration.setLocalRepository( localRepository ); - configuration.setProcessPlugins( false ); - configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); - - if ( profileManager != null ) - { - configuration.setActiveProfileIds( profileManager.getExplicitlyActivatedIds() ); - configuration.setInactiveProfileIds( profileManager.getExplicitlyDeactivatedIds() ); - } + configuration.setGlobalProfileManager( profileManager ); return buildStandaloneSuperProject( configuration ); } - public MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, + public MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository, ProfileManager profileManager, TransferListener transferListener ) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException { ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); - configuration.setLocalRepository( localRepository ); + configuration.setGlobalProfileManager( profileManager ); - if ( profileManager != null ) + ProjectBuildingRequest request = injectSession( toRequest( configuration ) ); + + request.setResolveDependencies( true ); + + try { - configuration.setActiveProfileIds( profileManager.getExplicitlyActivatedIds() ); - configuration.setInactiveProfileIds( profileManager.getExplicitlyDeactivatedIds() ); + return projectBuilder.build( pom, request ).getProject(); + } + catch ( ProjectBuildingException e ) + { + throw transformError( e ); } - - configuration.setResolveDependencies( true ); - - return build( project, configuration ); } - public MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, + public MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository, ProfileManager profileManager ) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException { - return buildWithDependencies( project, localRepository, profileManager, null ); + return buildWithDependencies( pom, localRepository, profileManager, null ); } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java b/maven-compat/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java similarity index 51% rename from maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java rename to maven-compat/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java index 011978d571..d08f18e0b9 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java +++ b/maven-compat/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java @@ -19,51 +19,88 @@ package org.apache.maven.project; * under the License. */ -import java.util.List; +import java.util.Date; import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.profiles.ProfileManager; @Deprecated public class DefaultProjectBuilderConfiguration - extends DefaultProjectBuildingRequest implements ProjectBuilderConfiguration { + private ProfileManager globalProfileManager; + + private ArtifactRepository localRepository; + + private Properties userProperties; + + private Properties executionProperties = System.getProperties(); + + private Date buildStartTime; + public DefaultProjectBuilderConfiguration() { - setProcessPlugins( false ); - setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ); + } + + public ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager ) + { + this.globalProfileManager = globalProfileManager; + return this; + } + + public ProfileManager getGlobalProfileManager() + { + return globalProfileManager; } public ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository ) { - super.setLocalRepository( localRepository ); + this.localRepository = localRepository; return this; } - public ProjectBuilderConfiguration setRemoteRepositories( List remoteRepositories ) + public ArtifactRepository getLocalRepository() { - super.setRemoteRepositories( remoteRepositories ); + return localRepository; + } + + public ProjectBuilderConfiguration setUserProperties( Properties userProperties ) + { + this.userProperties = userProperties; return this; } + public Properties getUserProperties() + { + if ( userProperties == null ) + { + userProperties = new Properties(); + } + + return userProperties; + } + + public Properties getExecutionProperties() + { + return executionProperties; + } + public ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties ) { - super.setSystemProperties( executionProperties ); + this.executionProperties = executionProperties; return this; } - public ProjectBuilderConfiguration setProcessPlugins( boolean processPlugins ) + public Date getBuildStartTime() { - super.setProcessPlugins( processPlugins ); - return this; + return buildStartTime; } - public ProjectBuilderConfiguration setValidationLevel( int validationLevel ) + public ProjectBuilderConfiguration setBuildStartTime( Date buildStartTime ) { - super.setValidationLevel( validationLevel ); + this.buildStartTime = buildStartTime; return this; } diff --git a/maven-compat/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-compat/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index ad00981acf..f1b382e79f 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-compat/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -33,11 +33,11 @@ import org.apache.maven.wagon.events.TransferListener; public interface MavenProjectBuilder { - MavenProject build( File projectFile, ProjectBuilderConfiguration configuration ) + MavenProject build( File pom, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException; //TODO maven-site-plugin -- Vincent, Dennis and Lukas are checking but this doesn't appear to be required anymore. - MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) + MavenProject build( File pom, ArtifactRepository localRepository, ProfileManager profileManager ) throws ProjectBuildingException; //TODO remote-resources-plugin @@ -62,11 +62,11 @@ public interface MavenProjectBuilder MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, ProfileManager profileManager ) throws ProjectBuildingException; - MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, + MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository, ProfileManager globalProfileManager, TransferListener transferListener ) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException; - MavenProject buildWithDependencies( File project, ArtifactRepository localRepository, + MavenProject buildWithDependencies( File pom, ArtifactRepository localRepository, ProfileManager globalProfileManager ) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException; diff --git a/maven-compat/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java b/maven-compat/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java new file mode 100644 index 0000000000..53836540da --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java @@ -0,0 +1,52 @@ +package org.apache.maven.project; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Date; +import java.util.Properties; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.profiles.ProfileManager; + +@Deprecated +public interface ProjectBuilderConfiguration +{ + + ArtifactRepository getLocalRepository(); + + ProfileManager getGlobalProfileManager(); + + Properties getUserProperties(); + + Properties getExecutionProperties(); + + ProjectBuilderConfiguration setGlobalProfileManager( ProfileManager globalProfileManager ); + + ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository ); + + ProjectBuilderConfiguration setUserProperties( Properties userProperties ); + + ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties ); + + Date getBuildStartTime(); + + ProjectBuilderConfiguration setBuildStartTime( Date buildStartTime ); + +} diff --git a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java index 30b9d34faa..9497f17115 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java @@ -261,12 +261,12 @@ public abstract class AbstractStringBasedModelInterpolator valueSources.add( modelValueSource1 ); valueSources.add( new MapBasedValueSource( config.getUserProperties() ) ); valueSources.add( new MapBasedValueSource( modelProperties ) ); - valueSources.add( new MapBasedValueSource( config.getSystemProperties() ) ); + valueSources.add( new MapBasedValueSource( config.getExecutionProperties() ) ); valueSources.add( new AbstractValueSource( false ) { public Object getValue( String expression ) { - return config.getSystemProperties().getProperty( "env." + expression ); + return config.getExecutionProperties().getProperty( "env." + expression ); } } ); valueSources.add( modelValueSource2 ); diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java deleted file mode 100644 index e7a4ed4550..0000000000 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.apache.maven.project; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.List; -import java.util.Properties; - -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Profile; - -@Deprecated -public interface ProjectBuilderConfiguration - extends ProjectBuildingRequest -{ - ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository ); - - ArtifactRepository getLocalRepository(); - - ProjectBuilderConfiguration setRemoteRepositories( List remoteRepositories ); - - List getRemoteRepositories(); - - ProjectBuilderConfiguration setExecutionProperties( Properties executionProperties ); - - Properties getSystemProperties(); - - void setProject( MavenProject mavenProject ); - - MavenProject getProject(); - - ProjectBuilderConfiguration setProcessPlugins( boolean processPlugins ); - - boolean isProcessPlugins(); - - // Profiles - - /** - * Set any active profiles that the {@link ProjectBuilder} should consider while constructing - * a {@link MavenProject}. - */ - void setActiveProfileIds( List activeProfileIds ); - - List getActiveProfileIds(); - - void setInactiveProfileIds( List inactiveProfileIds ); - - List getInactiveProfileIds(); - - /** - * Add a {@link org.apache.maven.model.Profile} that has come from an external source. This may be from a custom - * configuration like the MavenCLI settings.xml file, or from a custom dialog in an IDE integration like M2Eclipse. - * @param profile - */ - void addProfile( Profile profile ); - - void setProfiles( List profiles ); - - List getProfiles(); -}