mirror of https://github.com/apache/maven.git
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
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@786838 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fed83d80b8
commit
7f526ca65d
|
@ -120,7 +120,8 @@ public class DefaultProjectBuilder
|
||||||
|
|
||||||
Model model = result.getEffectiveModel();
|
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() );
|
project.setOriginalModel( result.getRawModel() );
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ public class DefaultProjectBuilder
|
||||||
project.setFile( pomFile );
|
project.setFile( pomFile );
|
||||||
|
|
||||||
List<Profile> activeProfiles = new ArrayList<Profile>();
|
List<Profile> activeProfiles = new ArrayList<Profile>();
|
||||||
activeProfiles.addAll( result.getActivePomProfiles( result.getRawModel() ) );
|
activeProfiles.addAll( result.getActivePomProfiles( result.getModelIds().get( 0 ) ) );
|
||||||
activeProfiles.addAll( result.getActiveExternalProfiles() );
|
activeProfiles.addAll( result.getActiveExternalProfiles() );
|
||||||
project.setActiveProfiles( activeProfiles );
|
project.setActiveProfiles( activeProfiles );
|
||||||
|
|
||||||
|
|
|
@ -117,55 +117,55 @@ public class DefaultModelBuilder
|
||||||
|
|
||||||
List<Profile> activeExternalProfiles = getActiveExternalProfiles( request, profileActivationContext, problems );
|
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<ModelData> lineage = new ArrayList<ModelData>();
|
||||||
List<Model> resultModels = new ArrayList<Model>();
|
|
||||||
|
|
||||||
for ( Model current = model; current != null; current = readParent( current, request, problems ) )
|
for ( ModelData currentData = resultData; currentData != null; )
|
||||||
{
|
{
|
||||||
Model resultModel = current;
|
lineage.add( currentData );
|
||||||
resultModels.add( resultModel );
|
|
||||||
|
|
||||||
Model rawModel = ModelUtils.cloneModel( current );
|
Model tmpModel = currentData.getModel();
|
||||||
rawModels.add( rawModel );
|
|
||||||
|
|
||||||
modelNormalizer.mergeDuplicates( resultModel, request );
|
Model rawModel = ModelUtils.cloneModel( tmpModel );
|
||||||
|
currentData.setRawModel( rawModel );
|
||||||
|
|
||||||
|
modelNormalizer.mergeDuplicates( tmpModel, request );
|
||||||
|
|
||||||
List<Profile> activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext, problems );
|
List<Profile> activePomProfiles = getActivePomProfiles( rawModel, profileActivationContext, problems );
|
||||||
|
currentData.setActiveProfiles( activePomProfiles );
|
||||||
result.setActivePomProfiles( rawModel, activePomProfiles );
|
|
||||||
|
|
||||||
for ( Profile activeProfile : 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 )
|
for ( Profile activeProfile : activeExternalProfiles )
|
||||||
{
|
{
|
||||||
profileInjector.injectProfile( resultModel, activeProfile, request );
|
profileInjector.injectProfile( tmpModel, activeProfile, request );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configureResolver( request.getModelResolver(), resultModel, problems );
|
configureResolver( request.getModelResolver(), tmpModel, problems );
|
||||||
|
|
||||||
|
currentData = readParent( tmpModel, request, problems );
|
||||||
}
|
}
|
||||||
|
|
||||||
Model superModel = getSuperModel();
|
ModelData superData = new ModelData( getSuperModel() );
|
||||||
rawModels.add( superModel );
|
superData.setRawModel( superData.getModel() );
|
||||||
resultModels.add( superModel );
|
superData.setActiveProfiles( Collections.<Profile> emptyList() );
|
||||||
|
lineage.add( superData );
|
||||||
|
|
||||||
result.setRawModels( rawModels );
|
assembleInheritance( lineage, request );
|
||||||
|
|
||||||
assembleInheritance( resultModels, request );
|
Model resultModel = resultData.getModel();
|
||||||
|
|
||||||
Model resultModel = resultModels.get( 0 );
|
|
||||||
|
|
||||||
resultModel = interpolateModel( resultModel, request, problems );
|
resultModel = interpolateModel( resultModel, request, problems );
|
||||||
resultModels.set( 0, resultModel );
|
resultData.setModel( resultModel );
|
||||||
|
|
||||||
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
|
modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );
|
||||||
|
|
||||||
|
@ -191,8 +191,23 @@ public class DefaultModelBuilder
|
||||||
throw new ModelBuildingException( problems );
|
throw new ModelBuildingException( problems );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultData.setGroupId( resultModel.getGroupId() );
|
||||||
|
resultData.setArtifactId( resultModel.getArtifactId() );
|
||||||
|
resultData.setVersion( resultModel.getVersion() );
|
||||||
|
|
||||||
result.setEffectiveModel( resultModel );
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,12 +317,12 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 parent = lineage.get( i + 1 ).getModel();
|
||||||
Model child = models.get( i );
|
Model child = lineage.get( i ).getModel();
|
||||||
inheritanceAssembler.assembleModelInheritance( child, parent, request );
|
inheritanceAssembler.assembleModelInheritance( child, parent, request );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,31 +344,31 @@ public class DefaultModelBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Model readParent( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
|
private ModelData readParent( Model childModel, ModelBuildingRequest request, List<ModelProblem> problems )
|
||||||
throws ModelBuildingException
|
throws ModelBuildingException
|
||||||
{
|
{
|
||||||
Model parentModel;
|
ModelData parentData;
|
||||||
|
|
||||||
Parent parent = childModel.getParent();
|
Parent parent = childModel.getParent();
|
||||||
|
|
||||||
if ( parent != null )
|
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
|
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
|
throws ModelBuildingException
|
||||||
{
|
{
|
||||||
File projectDirectory = childModel.getProjectDirectory();
|
File projectDirectory = childModel.getProjectDirectory();
|
||||||
|
@ -401,10 +416,12 @@ public class DefaultModelBuilder
|
||||||
return null;
|
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
|
throws ModelBuildingException
|
||||||
{
|
{
|
||||||
Parent parent = childModel.getParent();
|
Parent parent = childModel.getParent();
|
||||||
|
@ -430,7 +447,12 @@ public class DefaultModelBuilder
|
||||||
throw new ModelBuildingException( problems );
|
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()
|
private Model getSuperModel()
|
||||||
|
|
|
@ -30,101 +30,104 @@ import java.util.Map;
|
||||||
*
|
*
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
public class DefaultModelBuildingResult
|
class DefaultModelBuildingResult
|
||||||
implements ModelBuildingResult
|
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;
|
private List<Profile> activeExternalProfiles;
|
||||||
|
|
||||||
public DefaultModelBuildingResult()
|
public DefaultModelBuildingResult()
|
||||||
{
|
{
|
||||||
rawModels = new ArrayList<Model>();
|
modelIds = new ArrayList<String>();
|
||||||
activePomProfiles = new HashMap<Model, List<Profile>>();
|
rawModels = new HashMap<String, Model>();
|
||||||
|
activePomProfiles = new HashMap<String, List<Profile>>();
|
||||||
activeExternalProfiles = new ArrayList<Profile>();
|
activeExternalProfiles = new ArrayList<Profile>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model getEffectiveModel()
|
public Model getEffectiveModel()
|
||||||
{
|
{
|
||||||
return model;
|
return effectiveModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultModelBuildingResult setEffectiveModel( Model model )
|
public DefaultModelBuildingResult setEffectiveModel( Model model )
|
||||||
{
|
{
|
||||||
this.model = model;
|
this.effectiveModel = model;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getModelIds()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableList( modelIds );
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultModelBuildingResult addModelId( String modelId )
|
||||||
|
{
|
||||||
|
if ( modelId == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "no model identifier specified" );
|
||||||
|
}
|
||||||
|
|
||||||
|
modelIds.add( modelId );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model getRawModel()
|
public Model getRawModel()
|
||||||
{
|
{
|
||||||
return rawModels.get( 0 );
|
return rawModels.get( modelIds.get( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Model> getRawModels()
|
public Model getRawModel( String modelId )
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableList( rawModels );
|
return rawModels.get( modelId );
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultModelBuildingResult setRawModels( List<Model> rawModels )
|
public DefaultModelBuildingResult setRawModel( String modelId, Model rawModel )
|
||||||
{
|
{
|
||||||
this.rawModels.clear();
|
if ( modelId == null )
|
||||||
if ( rawModels != null )
|
|
||||||
{
|
{
|
||||||
this.rawModels.addAll( rawModels );
|
throw new IllegalArgumentException( "no model identifier specified" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawModels.put( modelId, rawModel );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Profile> getActivePomProfiles( Model rawModel )
|
public List<Profile> getActivePomProfiles( String modelId )
|
||||||
{
|
{
|
||||||
List<Profile> profiles = this.activePomProfiles.get( rawModel );
|
List<Profile> profiles = this.activePomProfiles.get( modelId );
|
||||||
return ( profiles == null ) ? Collections.<Profile> emptyList() : Collections.unmodifiableList( profiles );
|
return ( profiles != null ) ? Collections.unmodifiableList( profiles ) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultModelBuildingResult setActivePomProfiles( Model rawModel, List<Profile> activeProfiles )
|
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" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( activeProfiles != null )
|
if ( activeProfiles != null )
|
||||||
{
|
{
|
||||||
this.activePomProfiles.put( rawModel, new ArrayList<Profile>( activeProfiles ) );
|
this.activePomProfiles.put( modelId, new ArrayList<Profile>( activeProfiles ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.activePomProfiles.remove( rawModel );
|
this.activePomProfiles.remove( modelId );
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultModelBuildingResult addActivePomProfiles( Model rawModel, List<Profile> activeProfiles )
|
|
||||||
{
|
|
||||||
if ( rawModel == null )
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException( "no model specified" );
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Profile> currentProfiles = this.activePomProfiles.get( rawModel );
|
|
||||||
if ( currentProfiles == null )
|
|
||||||
{
|
|
||||||
currentProfiles = new ArrayList<Profile>( activeProfiles.size() );
|
|
||||||
this.activePomProfiles.put( rawModel, currentProfiles );
|
|
||||||
}
|
|
||||||
currentProfiles.addAll( activeProfiles );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Profile> getActiveExternalProfiles()
|
public List<Profile> getActiveExternalProfiles()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableList( activeExternalProfiles );
|
return Collections.unmodifiableList( activeExternalProfiles );
|
||||||
|
@ -133,6 +136,7 @@ public class DefaultModelBuildingResult
|
||||||
public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles )
|
public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles )
|
||||||
{
|
{
|
||||||
this.activeExternalProfiles.clear();
|
this.activeExternalProfiles.clear();
|
||||||
|
|
||||||
if ( activeProfiles != null )
|
if ( activeProfiles != null )
|
||||||
{
|
{
|
||||||
this.activeExternalProfiles.addAll( activeProfiles );
|
this.activeExternalProfiles.addAll( activeProfiles );
|
||||||
|
|
|
@ -29,6 +29,16 @@ import java.util.List;
|
||||||
public interface ModelBuildingResult
|
public interface ModelBuildingResult
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Gets the fully assembled model.
|
||||||
*
|
*
|
||||||
|
@ -37,29 +47,34 @@ public interface ModelBuildingResult
|
||||||
Model getEffectiveModel();
|
Model getEffectiveModel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the raw model as it was read from the model source. Apart from basic validation, the raw model has not
|
* 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 or interpolation.
|
* undergone any updates by the model builder, e.g. reflects neither inheritance nor interpolation.
|
||||||
*
|
*
|
||||||
* @return The raw model, never {@code null}.
|
* @return The raw model, never {@code null}.
|
||||||
*/
|
*/
|
||||||
Model getRawModel();
|
Model getRawModel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the lineage of raw models from which the effective model was constructed. The first model is the model on
|
* Gets the specified raw model as it was read from a model source. Apart from basic validation, a raw model has not
|
||||||
* which the model builder was originally invoked, the last model is the super POM.
|
* 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
|
* Gets the profiles from the specified model that were active during model building. The model identifier should be
|
||||||
* should be a model from the collection obtained by {@link #getRawModels()}.
|
* 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}.
|
* @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, never {@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
|
* Gets the external profiles that were active during model building. External profiles are those that were
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue