From ae675f8157e59ad442c50483a315fc2a60785617 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 29 May 2009 21:28:45 +0000 Subject: [PATCH] o Made ProjectBuilder use ProjectBuildingRequest for naming consistency within API git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@780115 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/DefaultMaven.java | 4 +- .../DefaultMavenExecutionRequest.java | 32 +-- .../execution/MavenExecutionRequest.java | 4 +- .../apache/maven/execution/MavenSession.java | 6 +- .../project/DefaultMavenProjectBuilder.java | 54 +---- .../maven/project/DefaultProjectBuilder.java | 49 ++++- .../DefaultProjectBuildingRequest.java | 189 ++++++++++++++++++ .../apache/maven/project/MavenProject.java | 12 +- .../apache/maven/project/ProjectBuilder.java | 12 +- .../project/ProjectBuilderConfiguration.java | 3 +- .../maven/project/ProjectBuildingRequest.java | 75 +++++++ .../project/artifact/MavenMetadataSource.java | 6 +- .../AbstractCoreMavenComponentTestCase.java | 6 +- .../maven/project/PomConstructionTest.java | 2 +- .../PomConstructionWithSettingsTest.java | 6 +- .../apache/maven/embedder/MavenEmbedder.java | 17 +- 16 files changed, 359 insertions(+), 118 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java create mode 100644 maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index e1a37b18eb..a4704f7c11 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -100,7 +100,7 @@ public class DefaultMaven //TODO: We really need to get rid of this requirement in here. If we know there is no project present if ( projects.isEmpty() ) { - MavenProject project = projectBuilder.buildStandaloneSuperProject( request.getProjectBuildingConfiguration() ); + MavenProject project = projectBuilder.buildStandaloneSuperProject( request.getProjectBuilderRequest() ); projects.put( ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project ); request.setProjectPresent( false ); } @@ -190,7 +190,7 @@ public class DefaultMaven for ( File file : files ) { - MavenProject project = projectBuilder.build( file, request.getProjectBuildingConfiguration() ); + MavenProject project = projectBuilder.build( file, request.getProjectBuilderRequest() ); if ( ( project.getPrerequisites() != null ) && ( project.getPrerequisites().getMaven() != null ) ) { diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 2180352580..3f156079e9 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -23,8 +23,8 @@ import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Profile; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; -import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.settings.Settings; import org.apache.maven.wagon.events.TransferListener; @@ -232,9 +232,9 @@ public class DefaultMavenExecutionRequest return this; } - public void setProjectBuildingConfiguration( ProjectBuilderConfiguration projectBuildingConfiguration ) + public void setProjectBuildingConfiguration( ProjectBuildingRequest projectBuildingConfiguration ) { - this.projectBuildingConfiguration = projectBuildingConfiguration; + this.projectBuilderRequest = projectBuildingConfiguration; } public List getActiveProfiles() @@ -617,7 +617,7 @@ public class DefaultMavenExecutionRequest private Settings settings; // calculated from request attributes. - private ProjectBuilderConfiguration projectBuildingConfiguration; + private ProjectBuildingRequest projectBuilderRequest; public MavenExecutionRequest setSettings( Settings settings ) { @@ -706,21 +706,21 @@ public class DefaultMavenExecutionRequest } //TODO: this does not belong here. - public ProjectBuilderConfiguration getProjectBuildingConfiguration() + public ProjectBuildingRequest getProjectBuilderRequest() { - if ( projectBuildingConfiguration == null ) + if ( projectBuilderRequest == null ) { - projectBuildingConfiguration = new DefaultProjectBuilderConfiguration(); - projectBuildingConfiguration.setLocalRepository( getLocalRepository() ); - projectBuildingConfiguration.setExecutionProperties( getProperties() ); - projectBuildingConfiguration.setRemoteRepositories( getRemoteRepositories() ); - projectBuildingConfiguration.setActiveProfileIds( getActiveProfiles() ); - projectBuildingConfiguration.setInactiveProfileIds( getInactiveProfiles() ); - projectBuildingConfiguration.setProfiles( getProfiles() ); - projectBuildingConfiguration.setProcessPlugins( true ); + projectBuilderRequest = new DefaultProjectBuildingRequest(); + projectBuilderRequest.setLocalRepository( getLocalRepository() ); + projectBuilderRequest.setExecutionProperties( getProperties() ); + projectBuilderRequest.setRemoteRepositories( getRemoteRepositories() ); + projectBuilderRequest.setActiveProfileIds( getActiveProfiles() ); + projectBuilderRequest.setInactiveProfileIds( getInactiveProfiles() ); + projectBuilderRequest.setProfiles( getProfiles() ); + projectBuilderRequest.setProcessPlugins( true ); } - return projectBuildingConfiguration; + return projectBuilderRequest; } public MavenExecutionRequest addProfile( Profile profile ) diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index fbf19eafb1..c719f147ed 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -27,7 +27,7 @@ import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.model.Profile; -import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.settings.Settings; import org.apache.maven.wagon.events.TransferListener; import org.codehaus.plexus.logging.Logger; @@ -202,5 +202,5 @@ public interface MavenExecutionRequest File getUserToolchainsFile(); MavenExecutionRequest setUserToolchainsFile( File userToolchainsFile ); - ProjectBuilderConfiguration getProjectBuildingConfiguration(); + ProjectBuildingRequest getProjectBuilderRequest(); } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index af55036303..996ac32468 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -28,7 +28,7 @@ import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.settings.Settings; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.util.dag.CycleDetectedException; @@ -132,9 +132,9 @@ public class MavenSession return currentProject; } - public ProjectBuilderConfiguration getProjectBuilderConfiguration() + public ProjectBuildingRequest getProjectBuilderRequest() { - return request.getProjectBuildingConfiguration(); + return request.getProjectBuilderRequest(); } public List getPluginGroups() diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index b9906c9cb3..2bbe2accc0 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -19,16 +19,10 @@ import java.io.File; import java.util.List; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.profiles.ProfileManager; -import org.apache.maven.project.artifact.ProjectArtifact; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.util.StringUtils; /** * @version $Id$ @@ -41,9 +35,6 @@ public class DefaultMavenProjectBuilder @Requirement private ProjectBuilder projectBuilder; - @Requirement - private RepositorySystem repositorySystem; - // ---------------------------------------------------------------------- // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- @@ -101,50 +92,7 @@ public class DefaultMavenProjectBuilder public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException { - MavenProject project = projectBuilder.build( pomFile, configuration ); - - Artifact artifact = new ProjectArtifact( project ); - - ArtifactResolutionRequest request = new ArtifactResolutionRequest() - .setArtifact( artifact ) - .setResolveRoot( false ) - .setResolveTransitively( true ) - .setLocalRepository( configuration.getLocalRepository() ) - .setRemoteRepostories( project.getRemoteArtifactRepositories() ) - .setManagedVersionMap( project.getManagedVersionMap() ); - - ArtifactResolutionResult result = repositorySystem.resolve( request ); - - if ( result.hasExceptions() ) - { - Exception e = result.getExceptions().get( 0 ); - - throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), - pomFile, e ); - } - - project.setArtifacts( result.getArtifacts() ); - - return new MavenProjectBuildingResult( project, result ); - } - - private static String safeVersionlessKey( String groupId, String artifactId ) - { - String gid = groupId; - - if ( StringUtils.isEmpty( gid ) ) - { - gid = "unknown"; - } - - String aid = artifactId; - - if ( StringUtils.isEmpty( aid ) ) - { - aid = "unknown"; - } - - return ArtifactUtils.versionlessKey( gid, aid ); + return projectBuilder.buildProjectWithDependencies( pomFile, configuration ); } } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 83fe3a425f..947f79aefb 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -50,6 +50,7 @@ import org.apache.maven.model.profile.ProfileInjector; import org.apache.maven.model.profile.ProfileSelector; import org.apache.maven.model.validation.ModelValidationResult; import org.apache.maven.model.validation.ModelValidator; +import org.apache.maven.project.artifact.ProjectArtifact; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -114,13 +115,13 @@ public class DefaultProjectBuilder // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- - public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration ) + public MavenProject build( File pomFile, ProjectBuildingRequest configuration ) throws ProjectBuildingException { return build( pomFile, pomFile.getParentFile(), configuration ); } - private MavenProject build( File pomFile, File projectDirectory, ProjectBuilderConfiguration configuration ) + private MavenProject build( File pomFile, File projectDirectory, ProjectBuildingRequest configuration ) throws ProjectBuildingException { String cacheKey = getCacheKey( pomFile, configuration ); @@ -225,7 +226,7 @@ public class DefaultProjectBuilder return project; } - private String getCacheKey( File pomFile, ProjectBuilderConfiguration configuration ) + private String getCacheKey( File pomFile, ProjectBuildingRequest configuration ) { StringBuilder buffer = new StringBuilder( 256 ); buffer.append( pomFile.getAbsolutePath() ); @@ -233,7 +234,7 @@ public class DefaultProjectBuilder return buffer.toString(); } - public MavenProject build( Artifact artifact, ProjectBuilderConfiguration configuration ) + public MavenProject build( Artifact artifact, ProjectBuildingRequest configuration ) throws ProjectBuildingException { if ( !artifact.getType().equals( "pom" ) ) @@ -266,7 +267,7 @@ public class DefaultProjectBuilder * 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( ProjectBuildingRequest config ) throws ProjectBuildingException { if ( superProject != null ) @@ -290,7 +291,37 @@ public class DefaultProjectBuilder return superProject; } - private Model interpolateModel( Model model, ProjectBuilderConfiguration config, File projectDescriptor ) + public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, ProjectBuildingRequest request ) + throws ProjectBuildingException + { + MavenProject project = build( pomFile, request ); + + Artifact artifact = new ProjectArtifact( project ); + + ArtifactResolutionRequest artifactRequest = new ArtifactResolutionRequest() + .setArtifact( artifact ) + .setResolveRoot( false ) + .setResolveTransitively( true ) + .setLocalRepository( request.getLocalRepository() ) + .setRemoteRepostories( project.getRemoteArtifactRepositories() ) + .setManagedVersionMap( project.getManagedVersionMap() ); + + ArtifactResolutionResult result = repositorySystem.resolve( artifactRequest ); + + if ( result.hasExceptions() ) + { + Exception e = result.getExceptions().get( 0 ); + + throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), + pomFile, e ); + } + + project.setArtifacts( result.getArtifacts() ); + + return new MavenProjectBuildingResult( project, result ); + } + + private Model interpolateModel( Model model, ProjectBuildingRequest config, File projectDescriptor ) throws ProjectBuildingException { try @@ -306,7 +337,7 @@ public class DefaultProjectBuilder return model; } - private MavenProject fromModelToMavenProject( Model model, File parentFile, ProjectBuilderConfiguration config, File projectDescriptor ) + private MavenProject fromModelToMavenProject( Model model, File parentFile, ProjectBuildingRequest config, File projectDescriptor ) throws InvalidProjectModelException, IOException { MavenProject project; @@ -329,7 +360,7 @@ public class DefaultProjectBuilder return project; } - private List build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration ) + private List build( String projectId, File pomFile, ProjectBuildingRequest projectBuilderConfiguration ) throws ProjectBuildingException, IOException { Model mainModel = readModel( projectId, pomFile, !projectBuilderConfiguration.istLenientValidation() ); @@ -564,7 +595,7 @@ public class DefaultProjectBuilder * @throws ProjectBuildingException */ private List getDomainModelParentsFromLocalPath( Model model, ArtifactRepository localRepository, List remoteRepositories, File projectDirectory, - ProjectBuilderConfiguration projectBuilderConfiguration ) + ProjectBuildingRequest projectBuilderConfiguration ) throws IOException, ProjectBuildingException { List models = new ArrayList(); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java new file mode 100644 index 0000000000..a57583263e --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java @@ -0,0 +1,189 @@ +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.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.ModelEventListener; +import org.apache.maven.model.Profile; + +public class DefaultProjectBuildingRequest + implements ProjectBuildingRequest +{ + private ArtifactRepository localRepository; + + private List remoteRepositories; + + private Properties executionProperties; + + private List listeners; + + private MavenProject topProject; + + private boolean processPlugins = true; + + private boolean lenientValidation; + + private List activeProfileIds; + + private List inactiveProfileIds; + + private List profiles; + + public MavenProject getTopLevelProjectFromReactor() + { + return topProject; + } + + public void setTopLevelProjectForReactor(MavenProject mavenProject) + { + this.topProject = mavenProject; + } + + public ProjectBuildingRequest setLocalRepository( ArtifactRepository localRepository ) + { + this.localRepository = localRepository; + return this; + } + + public ArtifactRepository getLocalRepository() + { + return localRepository; + } + + public List getRemoteRepositories() + { + if ( remoteRepositories == null ) + { + remoteRepositories = new ArrayList(); + } + return remoteRepositories; + } + + public ProjectBuildingRequest setRemoteRepositories( List remoteRepositories ) + { + this.remoteRepositories = remoteRepositories; + return this; + } + + public Properties getExecutionProperties() + { + if ( executionProperties == null ) + { + executionProperties = new Properties(); + } + return executionProperties; + } + + public ProjectBuildingRequest setExecutionProperties( Properties executionProperties ) + { + this.executionProperties = executionProperties; + return this; + } + + public List getModelEventListeners() + { + return listeners; + } + + public ProjectBuildingRequest setModelEventListeners( List listeners ) + { + this.listeners = listeners; + return this; + } + + public boolean isProcessPlugins() + { + return processPlugins; + } + + public ProjectBuildingRequest setProcessPlugins( boolean processPlugins ) + { + this.processPlugins = processPlugins; + return this; + } + + public ProjectBuildingRequest setLenientValidation( boolean lenientValidation ) + { + this.lenientValidation = lenientValidation; + return this; + } + + public boolean istLenientValidation() + { + return lenientValidation; + } + + public List getActiveProfileIds() + { + if ( activeProfileIds == null ) + { + activeProfileIds = new ArrayList(); + } + return activeProfileIds; + } + + public void setActiveProfileIds( List activeProfileIds ) + { + this.activeProfileIds = activeProfileIds; + } + + public List getInactiveProfileIds() + { + if ( inactiveProfileIds == null ) + { + inactiveProfileIds = new ArrayList(); + } + return inactiveProfileIds; + } + + public void setInactiveProfileIds( List inactiveProfileIds ) + { + this.inactiveProfileIds = inactiveProfileIds; + } + + public void setProfiles( List profiles ) + { + this.profiles = profiles; + } + + public void addProfile( Profile profile ) + { + if ( profiles == null ) + { + profiles = new ArrayList(); + } + + profiles.add( profile ); + } + + public List getProfiles() + { + if ( profiles == null ) + { + profiles = new ArrayList(); + } + return profiles; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 38bbf5bd2d..cdc0bf891b 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -153,7 +153,7 @@ public class MavenProject private ProjectBuilder mavenProjectBuilder; - private ProjectBuilderConfiguration projectBuilderConfiguration; + private ProjectBuildingRequest projectBuilderConfiguration; private RepositorySystem repositorySystem; // @@ -212,7 +212,7 @@ public class MavenProject * @param projectBuilderConfiguration * @throws InvalidRepositoryException */ - public MavenProject( Model model, RepositorySystem repositorySystem, ProjectBuilder mavenProjectBuilder, ProjectBuilderConfiguration projectBuilderConfiguration ) + public MavenProject( Model model, RepositorySystem repositorySystem, ProjectBuilder mavenProjectBuilder, ProjectBuildingRequest projectBuilderConfiguration ) throws InvalidRepositoryException { if ( model == null ) @@ -291,7 +291,7 @@ public class MavenProject { for ( Iterator it = modules.iterator(); it.hasNext(); ) { - String modulePath = (String) it.next(); + String modulePath = it.next(); String moduleName = modulePath; if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) ) @@ -319,7 +319,7 @@ public class MavenProject } } - return (String) moduleAdjustments.get( module ); + return moduleAdjustments.get( module ); } // ---------------------------------------------------------------------- @@ -1672,7 +1672,7 @@ public class MavenProject public Plugin getPlugin( String pluginKey ) { - return (Plugin) getBuild().getPluginsAsMap().get( pluginKey ); + return getBuild().getPluginsAsMap().get( pluginKey ); } /** @@ -1904,7 +1904,7 @@ public class MavenProject else { String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId(), a.getVersion() ); - MavenProject project = (MavenProject) projectReferences.get( refId ); + MavenProject project = projectReferences.get( refId ); boolean projectDirFound = false; if ( project != null ) diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java index e0713f4177..f495245003 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java @@ -22,16 +22,22 @@ import org.apache.maven.artifact.Artifact; public interface ProjectBuilder { - MavenProject build( File projectFile, ProjectBuilderConfiguration configuration ) + MavenProject build( File projectFile, ProjectBuildingRequest request ) throws ProjectBuildingException; - MavenProject build( Artifact projectArtifact, ProjectBuilderConfiguration configuration ) + MavenProject build( Artifact projectArtifact, ProjectBuildingRequest request ) throws ProjectBuildingException; // TODO: this is only to provide a project for plugins that don't need a project to execute but need some // of the values from a MavenProject. Ideally this should be something internal and nothing outside Maven // would ever need this so it should not be exposed in a public API - MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration ) + MavenProject buildStandaloneSuperProject( ProjectBuildingRequest request ) + throws ProjectBuildingException; + + // TODO: This also doesn't really belong here as it's a mix of project builder and artifact resolution and belongs + // in an integration component like the embedder. + @Deprecated + MavenProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuildingRequest request ) throws ProjectBuildingException; } 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 index 3c7639f048..5e5cb21f12 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java @@ -5,10 +5,9 @@ import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Profile; -import org.apache.maven.model.profile.ProfileActivationContext; public interface ProjectBuilderConfiguration - extends ProfileActivationContext + extends ProjectBuildingRequest { ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository ); diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java new file mode 100644 index 0000000000..8b7e989f19 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java @@ -0,0 +1,75 @@ +package org.apache.maven.project; + +import java.util.List; +import java.util.Properties; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Profile; +import org.apache.maven.model.profile.ProfileActivationContext; + +public interface ProjectBuildingRequest + extends ProfileActivationContext +{ + ProjectBuildingRequest setLocalRepository( ArtifactRepository localRepository ); + + ArtifactRepository getLocalRepository(); + + ProjectBuildingRequest setRemoteRepositories( List remoteRepositories ); + + List getRemoteRepositories(); + + ProjectBuildingRequest setExecutionProperties( Properties executionProperties ); + + Properties getExecutionProperties(); + + void setTopLevelProjectForReactor(MavenProject mavenProject); + + MavenProject getTopLevelProjectFromReactor(); + + ProjectBuildingRequest setProcessPlugins( boolean processPlugins ); + + boolean isProcessPlugins(); + + /** + * Controls the level of validation to perform on processed models. By default, models are validated in strict mode. + * + * @param lenientValidation A flag whether validation should be lenient instead of strict. For building of projects, + * strict validation should be used to ensure proper building. For the mere retrievel of dependencies + * during artifact resolution, lenient validation should be used to account for models of poor quality. + * @return This configuration, never {@code null}. + */ + ProjectBuildingRequest setLenientValidation( boolean lenientValidation ); + + /** + * Gets the level of validation to perform on processed models. + * + * @return {@code true} if lenient validation is enabled and only the dependency information is to be validated, + * {@code false} if strict validation is enabled and the entire model is validated. + */ + boolean istLenientValidation(); + + // 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(); +} diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 07cedbf4ae..81a95750ac 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -37,10 +37,10 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.model.Dependency; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; +import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingException; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; @@ -107,7 +107,7 @@ public class MavenMetadataSource pomArtifact.setFile( artifact.getFile() ); } - ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); + ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); configuration.setLocalRepository( localRepository ); configuration.setRemoteRepositories( remoteRepositories ); configuration.setLenientValidation( true ); diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 03e8027f19..626ba660e0 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -18,9 +18,9 @@ import org.apache.maven.model.Exclusion; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.PluginManager; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; +import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusTestCase; @@ -103,7 +103,7 @@ public abstract class AbstractCoreMavenComponentTestCase { MavenExecutionRequest request = createMavenExecutionRequest( pom ); - ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration() + ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest() .setLocalRepository( request.getLocalRepository() ) .setRemoteRepositories( request.getRemoteRepositories() ); diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 9bf736d53e..3cf4cb9446 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -1480,7 +1480,7 @@ public class PomConstructionTest pomFile = new File( pomFile, "pom.xml" ); } - ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration(); + ProjectBuildingRequest config = new DefaultProjectBuildingRequest(); String localRepoUrl = System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" ); localRepoUrl = "file://" + localRepoUrl; diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index e44046abff..8c244cdd6b 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -8,9 +8,9 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Profile; import org.apache.maven.project.DefaultProjectBuilder; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; +import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.codehaus.plexus.PlexusTestCase; @@ -73,7 +73,7 @@ public class PomConstructionWithSettingsTest File settingsFile = new File( testDirectory + File.separator + pomPath, "settings.xml" ); Settings settings = readSettingsFile(settingsFile); - ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration(); + ProjectBuildingRequest config = new DefaultProjectBuildingRequest(); for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 7ab33b8b20..f67911f130 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -34,14 +34,13 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.model.Model; import org.apache.maven.model.io.ModelReader; import org.apache.maven.model.io.ModelWriter; import org.apache.maven.plugin.PluginManager; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuildingResult; +import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Settings; @@ -97,9 +96,7 @@ public class MavenEmbedder private Maven maven; - private PluginManager pluginManager; - - private MavenProjectBuilder mavenProjectBuilder; + private ProjectBuilder projectBuilder; private ModelReader modelReader; @@ -124,8 +121,6 @@ public class MavenEmbedder private Configuration configuration; private MavenExecutionRequest request; - - private LifecycleExecutor lifecycleExecutor; // ---------------------------------------------------------------------------- // Constructors @@ -283,7 +278,7 @@ public class MavenEmbedder { getLogger().debug( "Building MavenProject instance: " + mavenProject ); - return mavenProjectBuilder.build( mavenProject, request.getProjectBuildingConfiguration() ); + return projectBuilder.build( mavenProject, request.getProjectBuilderRequest() ); } /** @@ -313,7 +308,7 @@ public class MavenEmbedder try { - MavenProjectBuildingResult projectBuildingResult = mavenProjectBuilder.buildProjectWithDependencies( request.getPom(), request.getProjectBuildingConfiguration() ); + MavenProjectBuildingResult projectBuildingResult = projectBuilder.buildProjectWithDependencies( request.getPom(), request.getProjectBuilderRequest() ); result.setProject( projectBuildingResult.getProject() ); @@ -398,14 +393,12 @@ public class MavenEmbedder maven = container.lookup( Maven.class ); - mavenProjectBuilder = container.lookup( MavenProjectBuilder.class ); + projectBuilder = container.lookup( ProjectBuilder.class ); populator = container.lookup( MavenExecutionRequestPopulator.class ); container.lookup( RepositorySystem.class ); - lifecycleExecutor = container.lookup( LifecycleExecutor.class ); - // This is temporary as we can probably cache a single request and use it for default values and // simply cascade values in from requests used for individual executions. request = new DefaultMavenExecutionRequest();