You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/07/14 14:54:17 UTC
svn commit: r793891 - in /maven/components/trunk:
maven-core/src/main/java/org/apache/maven/project/
maven-model-builder/src/main/java/org/apache/maven/model/building/
Author: bentmann
Date: Tue Jul 14 12:54:16 2009
New Revision: 793891
URL: http://svn.apache.org/viewvc?rev=793891&view=rev
Log:
o Consolidated all inputs of the model builder in the building request
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java?rev=793891&r1=793890&r2=793891&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java Tue Jul 14 12:54:16 2009
@@ -91,6 +91,15 @@
DefaultModelBuildingListener listener = new DefaultModelBuildingListener( projectBuildingHelper, configuration );
request.setModelBuildingListeners( Arrays.asList( listener ) );
+ if ( localProject )
+ {
+ request.setPomFile( pomFile );
+ }
+ else
+ {
+ request.setModelSource( new FileModelSource( pomFile ) );
+ }
+
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
try
@@ -98,14 +107,7 @@
ModelBuildingResult result;
try
{
- if ( localProject )
- {
- result = modelBuilder.build( pomFile, request );
- }
- else
- {
- result = modelBuilder.build( new FileModelSource( pomFile ), request );
- }
+ result = modelBuilder.build( request );
}
catch ( ModelBuildingException e )
{
@@ -254,10 +256,12 @@
{
ModelBuildingRequest request = getModelBuildingRequest( config );
+ request.setModelSource( new UrlModelSource( getClass().getResource( "standalone.xml" ) ) );
+
ModelBuildingResult result;
try
{
- result = modelBuilder.build( new UrlModelSource( getClass().getResource( "standalone.xml" ) ), request );
+ result = modelBuilder.build( request );
}
catch ( ModelBuildingException e )
{
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=793891&r1=793890&r2=793891&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Tue Jul 14 12:54:16 2009
@@ -103,30 +103,18 @@
@Requirement
private PluginConfigurationExpander pluginConfigurationExpander;
- public ModelBuildingResult build( File pomFile, ModelBuildingRequest request )
- throws ModelBuildingException
- {
- return build( new FileModelSource( pomFile ), pomFile, request );
- }
-
- public ModelBuildingResult build( ModelSource modelSource, ModelBuildingRequest request )
- throws ModelBuildingException
- {
- return build( modelSource, null, request );
- }
-
- private ModelBuildingResult build( ModelSource modelSource, File pomFile, ModelBuildingRequest request )
+ public ModelBuildingResult build( ModelBuildingRequest request )
throws ModelBuildingException
{
DefaultModelBuildingResult result = new DefaultModelBuildingResult();
List<ModelProblem> problems = new ArrayList<ModelProblem>();
- ProfileActivationContext profileActivationContext = getProfileActivationContext( pomFile, request );
+ ProfileActivationContext profileActivationContext = getProfileActivationContext( request );
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems );
- Model inputModel = readModel( modelSource, pomFile, request, problems );
+ Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );
ModelData resultData = new ModelData( inputModel );
@@ -234,6 +222,18 @@
{
Model model;
+ if ( modelSource == null )
+ {
+ if ( pomFile != null )
+ {
+ modelSource = new FileModelSource( pomFile );
+ }
+ else
+ {
+ throw new IllegalArgumentException( "neither model source nor input file are specified" );
+ }
+ }
+
try
{
boolean strict = request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
@@ -300,14 +300,14 @@
}
}
- private ProfileActivationContext getProfileActivationContext( File pomFile, ModelBuildingRequest request )
+ private ProfileActivationContext getProfileActivationContext( ModelBuildingRequest request )
{
ProfileActivationContext context = new DefaultProfileActivationContext();
context.setActiveProfileIds( request.getActiveProfileIds() );
context.setInactiveProfileIds( request.getInactiveProfileIds() );
context.setExecutionProperties( request.getExecutionProperties() );
- context.setProjectDirectory( ( pomFile != null ) ? pomFile.getParentFile() : null );
+ context.setProjectDirectory( ( request.getPomFile() != null ) ? request.getPomFile().getParentFile() : null );
return context;
}
@@ -438,7 +438,7 @@
return null;
}
- Model candidateModel = readModel( new FileModelSource( pomFile ), pomFile, request, problems );
+ Model candidateModel = readModel( null, pomFile, request, problems );
String groupId = candidateModel.getGroupId();
if ( groupId == null && candidateModel.getParent() != null )
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java?rev=793891&r1=793890&r2=793891&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java Tue Jul 14 12:54:16 2009
@@ -19,6 +19,7 @@
* under the License.
*/
+import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -36,6 +37,10 @@
implements ModelBuildingRequest
{
+ private File pomFile;
+
+ private ModelSource modelSource;
+
private int validationLevel = VALIDATION_LEVEL_STRICT;
private boolean processPlugins;
@@ -54,6 +59,30 @@
private List<ModelBuildingListener> modelBuildingListeners;
+ public File getPomFile()
+ {
+ return pomFile;
+ }
+
+ public DefaultModelBuildingRequest setPomFile( File pomFile )
+ {
+ this.pomFile = pomFile;
+
+ return this;
+ }
+
+ public ModelSource getModelSource()
+ {
+ return modelSource;
+ }
+
+ public DefaultModelBuildingRequest setModelSource( ModelSource modelSource )
+ {
+ this.modelSource = modelSource;
+
+ return this;
+ }
+
public int getValidationLevel()
{
return validationLevel;
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java?rev=793891&r1=793890&r2=793891&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java Tue Jul 14 12:54:16 2009
@@ -19,10 +19,6 @@
* under the License.
*/
-import java.io.File;
-
-import org.apache.maven.model.resolution.ModelResolver;
-
/**
* Builds the effective model from a POM.
*
@@ -32,29 +28,13 @@
{
/**
- * Builds the effective model of the specified POM file. Note that this method overload is meant to build the
- * effective model for the build process of a project. Hence the effective model supports the notion of a project
- * directory.
- *
- * @param pomFile The POM file of the project to build the effective model from, must not be {@code null}.
- * @param request The model building request that holds further settings, must not be {@code null}.
- * @return The result of the model building, never {@code null}.
- * @throws ModelBuildingException If the effective model could not be built.
- */
- ModelBuildingResult build( File pomFile, ModelBuildingRequest request )
- throws ModelBuildingException;
-
- /**
- * Builds the effective model for the specified POM. In contrast to
- * {@link #build(File, ModelBuildingRequest, ModelResolver)} the resulting model does not support the notion of a
- * project directory. As a consequence, parent POMs are always resolved via the provided model resolver.
+ * Builds the effective model of the specified POM.
*
- * @param modelSource The source of the POM, must not be {@code null}.
- * @param request The model building request that holds further settings, must not be {@code null}.
+ * @param request The model building request that holds the parameters, must not be {@code null}.
* @return The result of the model building, never {@code null}.
* @throws ModelBuildingException If the effective model could not be built.
*/
- ModelBuildingResult build( ModelSource modelSource, ModelBuildingRequest request )
+ ModelBuildingResult build( ModelBuildingRequest request )
throws ModelBuildingException;
}
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java?rev=793891&r1=793890&r2=793891&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java Tue Jul 14 12:54:16 2009
@@ -19,6 +19,7 @@
* under the License.
*/
+import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@@ -62,6 +63,43 @@
static final int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
/**
+ * Gets the source of the POM to process.
+ *
+ * @return The source of the POM or {@code null} if not set.
+ */
+ ModelSource getModelSource();
+
+ /**
+ * Sets the source of the POM to process. Eventually, either {@link #setModelSource(ModelSource)} or
+ * {@link #setPomFile(File)} must be set.
+ *
+ * @param modelSource The source of the POM to process, may be {@code null}.
+ * @return This request, never {@code null}.
+ */
+ ModelBuildingRequest setModelSource( ModelSource modelSource );
+
+ /**
+ * Gets the POM file of the project to build.
+ *
+ * @return The POM file of the project or {@code null} if not applicable (i.e. when processing a POM from the
+ * repository).
+ */
+ File getPomFile();
+
+ /**
+ * Sets the POM file of the project to build. Note that providing the path to a POM file via this method will make
+ * the model builder operate in project mode. This mode is meant for effective models that are employed during the
+ * build process of a local project. Hence the effective model will support the notion of a project directory. To
+ * build the model for a POM from the repository, use {@link #setModelSource(ModelSource)} in combination with a
+ * {@link FileModelSource} instead.
+ *
+ * @param pomFile The POM file of the project to build the effective model for, may be {@code null} to build the
+ * model of some POM from the repository.
+ * @return This request, never {@code null}.
+ */
+ ModelBuildingRequest setPomFile( File pomFile );
+
+ /**
* Gets the level of validation to perform on processed models.
*
* @return The level of validation to perform on processed models.