o formatting

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@721771 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2008-11-30 06:41:42 +00:00
parent 8532f36055
commit 887d534ad2
1 changed files with 65 additions and 63 deletions

View File

@ -11,37 +11,37 @@ import org.apache.maven.mercury.builder.api.MetadataReaderException;
import org.apache.maven.project.builder.*;
import org.apache.maven.shared.model.*;
public final class MavenDependencyProcessor implements DependencyProcessor {
public MavenDependencyProcessor() {
}
public final class MavenDependencyProcessor
implements DependencyProcessor
{
public List<ArtifactBasicMetadata> getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user )
throws MetadataReaderException, DependencyProcessorException
{
if (bmd == null) {
if ( bmd == null )
{
throw new IllegalArgumentException( "bmd: null" );
}
if (mdReader == null) {
if ( mdReader == null )
{
throw new IllegalArgumentException( "mdReader: null" );
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT", PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) );
if(system != null) {
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( system,
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
if ( system != null )
{
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) );
}
if(user != null) {
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( user,
PomInterpolatorTag.USER_PROPERTIES.name()));
if ( user != null )
{
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( user, PomInterpolatorTag.USER_PROPERTIES.name() ) );
}
List<DomainModel> domainModels = new ArrayList<DomainModel>();
try {
try
{
// MavenDomainModel superPom =
// new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" ));
// domainModels.add(superPom);
@ -56,37 +56,38 @@ public final class MavenDependencyProcessor implements DependencyProcessor {
Collection<ModelContainer> activeProfiles = domainModel.getActiveProfileContainers( interpolatorProperties );
for(ModelContainer mc : activeProfiles) {
for ( ModelContainer mc : activeProfiles )
{
domainModels.add( new MavenDomainModel( transformProfiles( mc.getProperties() ) ) );
}
domainModels.addAll( getParentsOfDomainModel( domainModel, mdReader ) );
} catch (IOException e) {
}
catch ( IOException e )
{
throw new MetadataReaderException( "Failed to create domain model. Message = " + e.getMessage() );
}
PomTransformer transformer = new PomTransformer( new MavenDomainModelFactory() );
ModelTransformerContext ctx = new ModelTransformerContext(
Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory()));
ModelTransformerContext ctx = new ModelTransformerContext( Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
try {
MavenDomainModel model = ((MavenDomainModel) ctx.transform(domainModels,
transformer,
transformer,
null,
interpolatorProperties,
null));
try
{
MavenDomainModel model = ( (MavenDomainModel) ctx.transform( domainModels, transformer, transformer, null, interpolatorProperties, null ) );
return model.getDependencyMetadata();
} catch (IOException e) {
}
catch ( IOException e )
{
throw new MetadataReaderException( "Unable to transform model" );
}
}
private static List<DomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
throws IOException, MetadataReaderException {
throws IOException, MetadataReaderException
{
List<DomainModel> domainModels = new ArrayList<DomainModel>();
if (domainModel.hasParent()) {
if ( domainModel.hasParent() )
{
MavenDomainModel parentDomainModel = new MavenDomainModel( mdReader.readMetadata( domainModel.getParentMetadata() ) );
domainModels.add( parentDomainModel );
domainModels.addAll( getParentsOfDomainModel( parentDomainModel, mdReader ) );
@ -94,14 +95,15 @@ public final class MavenDependencyProcessor implements DependencyProcessor {
return domainModels;
}
private static List<ModelProperty> transformProfiles(List<ModelProperty> modelProperties) {
private static List<ModelProperty> transformProfiles( List<ModelProperty> modelProperties )
{
List<ModelProperty> properties = new ArrayList<ModelProperty>();
for(ModelProperty mp : modelProperties) {
if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri)
&& !mp.getUri().equals(ProjectUri.Profiles.Profile.id)
&& !mp.getUri().startsWith(ProjectUri.Profiles.Profile.Activation.xUri)) {
properties.add(new ModelProperty(mp.getUri().replace( ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri ),
mp.getResolvedValue() ));
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().startsWith( ProjectUri.Profiles.Profile.xUri ) && !mp.getUri().equals( ProjectUri.Profiles.Profile.id )
&& !mp.getUri().startsWith( ProjectUri.Profiles.Profile.Activation.xUri ) )
{
properties.add( new ModelProperty( mp.getUri().replace( ProjectUri.Profiles.Profile.xUri, ProjectUri.xUri ), mp.getResolvedValue() ) );
}
}
return properties;