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/06/20 17:00:45 UTC
svn commit: r786838 - in /maven/components/trunk:
maven-core/src/main/java/org/apache/maven/project/
maven-model-builder/src/main/java/org/apache/maven/model/
Author: bentmann
Date: Sat Jun 20 15:00:45 2009
New Revision: 786838
URL: http://svn.apache.org/viewvc?rev=786838&view=rev
Log:
o Extended model builder to report the ids of the models from the lineage and used these ids as keys to pull infos from the building result
Added:
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java (with props)
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/DefaultModelBuilder.java
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java
maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.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=786838&r1=786837&r2=786838&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 Sat Jun 20 15:00:45 2009
@@ -120,7 +120,8 @@
Model model = result.getEffectiveModel();
- MavenProject project = fromModelToMavenProject( model, result.getRawModels().get( 1 ).getPomFile(), configuration, model.getPomFile() );
+ File parentPomFile = result.getRawModel( result.getModelIds().get( 1 ) ).getPomFile();
+ MavenProject project = fromModelToMavenProject( model, parentPomFile, configuration, model.getPomFile() );
project.setOriginalModel( result.getRawModel() );
@@ -145,7 +146,7 @@
project.setFile( pomFile );
List<Profile> activeProfiles = new ArrayList<Profile>();
- activeProfiles.addAll( result.getActivePomProfiles( result.getRawModel() ) );
+ activeProfiles.addAll( result.getActivePomProfiles( result.getModelIds().get( 0 ) ) );
activeProfiles.addAll( result.getActiveExternalProfiles() );
project.setActiveProfiles( activeProfiles );
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java?rev=786838&r1=786837&r2=786838&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuilder.java Sat Jun 20 15:00:45 2009
@@ -117,55 +117,55 @@
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems );
- result.setActiveExternalProfiles( activeExternalProfiles );
+ Model inputModel = readModel( modelSource, pomFile, request, problems );
- Model model = readModel( modelSource, pomFile, request, problems );
+ ModelData resultData = new ModelData( inputModel );
- List<Model> rawModels = new ArrayList<Model>();
- List<Model> resultModels = new ArrayList<Model>();
+ List<ModelData> lineage = new ArrayList<ModelData>();
- for ( Model current = model; current != null; current = readParent( current, request, problems ) )
+ for ( ModelData currentData = resultData; currentData != null; )
{
- Model resultModel = current;
- resultModels.add( resultModel );
+ lineage.add( currentData );
- Model rawModel = ModelUtils.cloneModel( current );
- rawModels.add( rawModel );
+ Model tmpModel = currentData.getModel();
- modelNormalizer.mergeDuplicates( resultModel, request );
+ Model rawModel = ModelUtils.cloneModel( tmpModel );
+ currentData.setRawModel( rawModel );
- List<Profile> activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext, problems );
+ modelNormalizer.mergeDuplicates( tmpModel, request );
- result.setActivePomProfiles( rawModel, activePomProfiles );
+ List<Profile> activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext, problems );
+ currentData.setActiveProfiles( activePomProfiles );
for ( Profile activeProfile : activePomProfiles )
{
- profileInjector.injectProfile( resultModel, activeProfile, request );
+ profileInjector.injectProfile( tmpModel, activeProfile, request );
}
- if ( current == model )
+ if ( currentData == resultData )
{
for ( Profile activeProfile : activeExternalProfiles )
{
- profileInjector.injectProfile( resultModel, activeProfile, request );
+ profileInjector.injectProfile( tmpModel, activeProfile, request );
}
}
- configureResolver( request.getModelResolver(), resultModel, problems );
- }
+ configureResolver( request.getModelResolver(), tmpModel, problems );
- Model superModel = getSuperModel();
- rawModels.add( superModel );
- resultModels.add( superModel );
+ currentData = readParent( tmpModel, request, problems );
+ }
- result.setRawModels( rawModels );
+ ModelData superData = new ModelData( getSuperModel() );
+ superData.setRawModel( superData.getModel() );
+ superData.setActiveProfiles( Collections.<Profile> emptyList() );
+ lineage.add( superData );
- assembleInheritance( resultModels, request );
+ assembleInheritance( lineage, request );
- Model resultModel = resultModels.get( 0 );
+ Model resultModel = resultData.getModel();
resultModel = interpolateModel( resultModel, request, problems );
- resultModels.set( 0, resultModel );
+ resultData.setModel( resultModel );
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
@@ -191,8 +191,23 @@
throw new ModelBuildingException( problems );
}
+ resultData.setGroupId( resultModel.getGroupId() );
+ resultData.setArtifactId( resultModel.getArtifactId() );
+ resultData.setVersion( resultModel.getVersion() );
+
result.setEffectiveModel( resultModel );
+ result.setActiveExternalProfiles( activeExternalProfiles );
+
+ for ( ModelData currentData : lineage )
+ {
+ String modelId = ( currentData != superData ) ? currentData.getId() : "";
+
+ result.addModelId( modelId );
+ result.setActivePomProfiles( modelId, currentData.getActiveProfiles() );
+ result.setRawModel( modelId, currentData.getRawModel() );
+ }
+
return result;
}
@@ -302,12 +317,12 @@
}
}
- private void assembleInheritance( List<Model> models, ModelBuildingRequest request )
+ private void assembleInheritance( List<ModelData> lineage, ModelBuildingRequest request )
{
- for ( int i = models.size() - 2; i >= 0; i-- )
+ for ( int i = lineage.size() - 2; i >= 0; i-- )
{
- Model parent = models.get( i + 1 );
- Model child = models.get( i );
+ Model parent = lineage.get( i + 1 ).getModel();
+ Model child = lineage.get( i ).getModel();
inheritanceAssembler.assembleModelInheritance( child, parent, request );
}
}
@@ -329,31 +344,31 @@
}
}
- private Model readParent( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
+ private ModelData readParent( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
throws ModelBuildingException
{
- Model parentModel;
+ ModelData parentData;
Parent parent = childModel.getParent();
if ( parent != null )
{
- parentModel = readParentLocally( childModel, request, problems );
+ parentData = readParentLocally( childModel, request, problems );
- if ( parentModel == null )
+ if ( parentData == null )
{
- parentModel = readParentExternally( childModel, request, problems );
+ parentData = readParentExternally( childModel, request, problems );
}
}
else
{
- parentModel = null;
+ parentData = null;
}
- return parentModel;
+ return parentData;
}
- private Model readParentLocally( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
+ private ModelData readParentLocally( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
throws ModelBuildingException
{
File projectDirectory = childModel.getProjectDirectory();
@@ -401,10 +416,12 @@
return null;
}
- return candidateModel;
+ ModelData parentData = new ModelData( candidateModel, groupId, artifactId, version );
+
+ return parentData;
}
- private Model readParentExternally( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
+ private ModelData readParentExternally( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
throws ModelBuildingException
{
Parent parent = childModel.getParent();
@@ -430,7 +447,12 @@
throw new ModelBuildingException( problems );
}
- return readModel( modelSource, null, request, problems );
+ Model parentModel = readModel( modelSource, null, request, problems );
+
+ ModelData parentData =
+ new ModelData( parentModel, parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
+
+ return parentData;
}
private Model getSuperModel()
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java?rev=786838&r1=786837&r2=786838&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/DefaultModelBuildingResult.java Sat Jun 20 15:00:45 2009
@@ -30,97 +30,100 @@
*
* @author Benjamin Bentmann
*/
-public class DefaultModelBuildingResult
+class DefaultModelBuildingResult
implements ModelBuildingResult
{
- private Model model;
+ private Model effectiveModel;
- private List<Model> rawModels;
+ private List<String> modelIds;
- private Map<Model, List<Profile>> activePomProfiles;
+ private Map<String, Model> rawModels;
+
+ private Map<String, List<Profile>> activePomProfiles;
private List<Profile> activeExternalProfiles;
public DefaultModelBuildingResult()
{
- rawModels = new ArrayList<Model>();
- activePomProfiles = new HashMap<Model, List<Profile>>();
+ modelIds = new ArrayList<String>();
+ rawModels = new HashMap<String, Model>();
+ activePomProfiles = new HashMap<String, List<Profile>>();
activeExternalProfiles = new ArrayList<Profile>();
}
public Model getEffectiveModel()
{
- return model;
+ return effectiveModel;
}
public DefaultModelBuildingResult setEffectiveModel( Model model )
{
- this.model = model;
+ this.effectiveModel = model;
return this;
}
- public Model getRawModel()
- {
- return rawModels.get( 0 );
- }
-
- public List<Model> getRawModels()
+ public List<String> getModelIds()
{
- return Collections.unmodifiableList( rawModels );
+ return Collections.unmodifiableList( modelIds );
}
- public DefaultModelBuildingResult setRawModels( List<Model> rawModels )
+ public DefaultModelBuildingResult addModelId( String modelId )
{
- this.rawModels.clear();
- if ( rawModels != null )
+ if ( modelId == null )
{
- this.rawModels.addAll( rawModels );
+ throw new IllegalArgumentException( "no model identifier specified" );
}
+ modelIds.add( modelId );
+
return this;
}
- public List<Profile> getActivePomProfiles( Model rawModel )
+ public Model getRawModel()
{
- List<Profile> profiles = this.activePomProfiles.get( rawModel );
- return ( profiles == null ) ? Collections.<Profile> emptyList() : Collections.unmodifiableList( profiles );
+ return rawModels.get( modelIds.get( 0 ) );
}
- public DefaultModelBuildingResult setActivePomProfiles( Model rawModel, List<Profile> activeProfiles )
+ public Model getRawModel( String modelId )
{
- if ( rawModel == null )
- {
- throw new IllegalArgumentException( "no model specified" );
- }
+ return rawModels.get( modelId );
+ }
- if ( activeProfiles != null )
- {
- this.activePomProfiles.put( rawModel, new ArrayList<Profile>( activeProfiles ) );
- }
- else
+ public DefaultModelBuildingResult setRawModel( String modelId, Model rawModel )
+ {
+ if ( modelId == null )
{
- this.activePomProfiles.remove( rawModel );
+ throw new IllegalArgumentException( "no model identifier specified" );
}
+ rawModels.put( modelId, rawModel );
+
return this;
}
- public DefaultModelBuildingResult addActivePomProfiles( Model rawModel, List<Profile> activeProfiles )
+ public List<Profile> getActivePomProfiles( String modelId )
+ {
+ List<Profile> profiles = this.activePomProfiles.get( modelId );
+ return ( profiles != null ) ? Collections.unmodifiableList( profiles ) : null;
+ }
+
+ public DefaultModelBuildingResult setActivePomProfiles( String modelId, List<Profile> activeProfiles )
{
- if ( rawModel == null )
+ if ( modelId == null )
{
- throw new IllegalArgumentException( "no model specified" );
+ throw new IllegalArgumentException( "no model identifier specified" );
}
- List<Profile> currentProfiles = this.activePomProfiles.get( rawModel );
- if ( currentProfiles == null )
+ if ( activeProfiles != null )
+ {
+ this.activePomProfiles.put( modelId, new ArrayList<Profile>( activeProfiles ) );
+ }
+ else
{
- currentProfiles = new ArrayList<Profile>( activeProfiles.size() );
- this.activePomProfiles.put( rawModel, currentProfiles );
+ this.activePomProfiles.remove( modelId );
}
- currentProfiles.addAll( activeProfiles );
return this;
}
@@ -133,6 +136,7 @@
public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles )
{
this.activeExternalProfiles.clear();
+
if ( activeProfiles != null )
{
this.activeExternalProfiles.addAll( activeProfiles );
Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java?rev=786838&r1=786837&r2=786838&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelBuildingResult.java Sat Jun 20 15:00:45 2009
@@ -30,6 +30,16 @@
{
/**
+ * Gets the sequence of model identifiers that denote the lineage of models from which the effective model was
+ * constructed. Model identifiers have the form {@code <groupId>:<artifactId>:<version>}. The first identifier from
+ * the list denotes the model on which the model builder was originally invoked. The last identifier will always be
+ * an empty string that by definition denotes the super POM.
+ *
+ * @return The model identifiers from the lineage of models, never {@code null}.
+ */
+ List<String> getModelIds();
+
+ /**
* Gets the fully assembled model.
*
* @return The fully assembled model, never {@code null}.
@@ -37,29 +47,34 @@
Model getEffectiveModel();
/**
- * Gets the raw model as it was read from the model source. Apart from basic validation, the raw model has not
- * undergone any updates by the model builder, e.g. reflects neither inheritance or interpolation.
+ * Gets the raw model as it was read from the input model source. Apart from basic validation, the raw model has not
+ * undergone any updates by the model builder, e.g. reflects neither inheritance nor interpolation.
*
* @return The raw model, never {@code null}.
*/
Model getRawModel();
/**
- * Gets the lineage of raw models from which the effective model was constructed. The first model is the model on
- * which the model builder was originally invoked, the last model is the super POM.
+ * Gets the specified raw model as it was read from a model source. Apart from basic validation, a raw model has not
+ * undergone any updates by the model builder, e.g. reflects neither inheritance nor interpolation. The model
+ * identifier should be from the collection obtained by {@link #getModelIds()}. As a special case, an empty string
+ * can be used as the identifier for the super POM.
*
- * @return The lineage of raw models, never {@code null}.
+ * @param modelId The identifier of the desired raw model, must not be {@code null}.
+ * @return The raw model or {@code null} if the specified model id does not refer to a known model.
*/
- List<Model> getRawModels();
+ Model getRawModel( String modelId );
/**
- * Gets the profiles from the specified (raw) model that were active during model building. The input parameter
- * should be a model from the collection obtained by {@link #getRawModels()}.
+ * Gets the profiles from the specified model that were active during model building. The model identifier should be
+ * from the collection obtained by {@link #getModelIds()}. As a special case, an empty string can be used as the
+ * identifier for the super POM.
*
- * @param rawModel The (raw) model for whose active profiles should be retrieved, must not be {@code null}.
- * @return The active profiles of the model or an empty list if none, never {@code null}.
+ * @param modelId The identifier of the model whose active profiles should be retrieved, must not be {@code null}.
+ * @return The active profiles of the model or an empty list if none or {@code null} if the specified model id does
+ * not refer to a known model.
*/
- List<Profile> getActivePomProfiles( Model rawModel );
+ List<Profile> getActivePomProfiles( String modelId );
/**
* Gets the external profiles that were active during model building. External profiles are those that were
Added: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java?rev=786838&view=auto
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java (added)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java Sat Jun 20 15:00:45 2009
@@ -0,0 +1,211 @@
+package org.apache.maven.model;
+
+/*
+ * 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;
+
+/**
+ * Holds a model along with some auxiliary information. This internal utility class assists the model builder during POM
+ * processing by providing a means to transport information that cannot be (easily) extracted from the model itself.
+ *
+ * @author Benjamin Bentmann
+ */
+class ModelData
+{
+
+ private Model model;
+
+ private Model rawModel;
+
+ private List<Profile> activeProfiles;
+
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
+
+ /**
+ * Creates a new container for the specified model.
+ *
+ * @param model The model to wrap, may be {@code null}.
+ */
+ public ModelData( Model model )
+ {
+ this.model = model;
+ }
+
+ /**
+ * Creates a new container for the specified model.
+ *
+ * @param model The model to wrap, may be {@code null}.
+ * @param groupId The effective group identifier of the model, may be {@code null}.
+ * @param artifactId The effective artifact identifier of the model, may be {@code null}.
+ * @param version The effective version of the model, may be {@code null}.
+ */
+ public ModelData( Model model, String groupId, String artifactId, String version )
+ {
+ this.model = model;
+ setGroupId( groupId );
+ setArtifactId( artifactId );
+ setVersion( version );
+ }
+
+ /**
+ * Gets the model being wrapped.
+ *
+ * @return The model or {@code null} if not set.
+ */
+ public Model getModel()
+ {
+ return model;
+ }
+
+ /**
+ * Sets the model being wrapped.
+ *
+ * @param model The model, may be {@code null}.
+ */
+ public void setModel( Model model )
+ {
+ this.model = model;
+ }
+
+ /**
+ * Gets the raw model being wrapped.
+ *
+ * @return The raw model or {@code null} if not set.
+ */
+ public Model getRawModel()
+ {
+ return rawModel;
+ }
+
+ /**
+ * Sets the raw model being wrapped.
+ *
+ * @param rawModel The raw model, may be {@code null}.
+ */
+ public void setRawModel( Model rawModel )
+ {
+ this.rawModel = rawModel;
+ }
+
+ /**
+ * Gets the active profiles from the model.
+ *
+ * @return The active profiles or {@code null} if not set.
+ */
+ public List<Profile> getActiveProfiles()
+ {
+ return activeProfiles;
+ }
+
+ /**
+ * Sets the active profiles from the model.
+ *
+ * @param activeProfiles The active profiles, may be {@code null}.
+ */
+ public void setActiveProfiles( List<Profile> activeProfiles )
+ {
+ this.activeProfiles = activeProfiles;
+ }
+
+ /**
+ * Gets the effective group identifier of the model.
+ *
+ * @return The effective group identifier of the model or an empty string if unknown, never {@code null}.
+ */
+ public String getGroupId()
+ {
+ return ( groupId != null ) ? groupId : "";
+ }
+
+ /**
+ * Sets the effective group identifier of the model.
+ *
+ * @param groupId The effective group identifier of the model, may be {@code null}.
+ */
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ /**
+ * Gets the effective artifact identifier of the model.
+ *
+ * @return The effective artifact identifier of the model or an empty string if unknown, never {@code null}.
+ */
+ public String getArtifactId()
+ {
+ return ( artifactId != null ) ? artifactId : "";
+ }
+
+ /**
+ * Sets the effective artifact identifier of the model.
+ *
+ * @param artifactId The effective artifact identifier of the model, may be {@code null}.
+ */
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ /**
+ * Gets the effective version of the model.
+ *
+ * @return The effective version of the model or an empty string if unknown, never {@code null}.
+ */
+ public String getVersion()
+ {
+ return ( version != null ) ? version : "";
+ }
+
+ /**
+ * Sets the effective version of the model.
+ *
+ * @param version The effective version of the model, may be {@code null}.
+ */
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ /**
+ * Gets the effective identifier of the model in the form {@code <groupId>:<artifactId>:<version>}.
+ *
+ * @return The effective identifier of the model, never {@code null}.
+ */
+ public String getId()
+ {
+ StringBuilder buffer = new StringBuilder( 64 );
+
+ buffer.append( getGroupId() ).append( ':' ).append( getArtifactId() ).append( ':' ).append( getVersion() );
+
+ return buffer.toString();
+ }
+
+ @Override
+ public String toString()
+ {
+ return model.toString();
+ }
+
+}
Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/ModelData.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision