diff --git a/maven-mercury/pom.xml b/maven-mercury/pom.xml index 5500f29e8c..600c02377f 100644 --- a/maven-mercury/pom.xml +++ b/maven-mercury/pom.xml @@ -20,6 +20,7 @@ 4.0.0 maven-mercury Maven Mercury + org.apache.maven.mercury @@ -44,6 +45,7 @@ test + @@ -51,5 +53,6 @@ plexus-component-metadata - + + diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java index 7669202a2f..80f77ca5ed 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java @@ -25,7 +25,7 @@ import org.apache.maven.shared.model.ModelTransformerContext; import org.codehaus.plexus.component.annotations.Component; /** - * + * * Maven supplied plexus component that implements POM dependency processing for Mercury * * @author Shane Isbell @@ -34,9 +34,10 @@ import org.codehaus.plexus.component.annotations.Component; */ @Component( role=DependencyProcessor.class, hint="maven" ) public final class MavenDependencyProcessor -implements DependencyProcessor + implements DependencyProcessor { - public List getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user ) + public List getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, + Map user ) throws MetadataReaderException, DependencyProcessorException { if ( bmd == null ) @@ -50,23 +51,26 @@ implements DependencyProcessor } List interpolatorProperties = new ArrayList(); - interpolatorProperties.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT", PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) ); + interpolatorProperties.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT", + PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) ); if ( system != null ) { - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) ); + interpolatorProperties.addAll( + InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) ); } if ( user != null ) { - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( user, PomInterpolatorTag.USER_PROPERTIES.name() ) ); + interpolatorProperties.addAll( + InterpolatorProperty.toInterpolatorProperties( user, PomInterpolatorTag.USER_PROPERTIES.name() ) ); } List domainModels = new ArrayList(); try { - // MavenDomainModel superPom = - // new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" )); - // domainModels.add(superPom); + // MavenDomainModel superPom = + // new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" )); + // domainModels.add(superPom); byte[] superBytes = mdReader.readMetadata( bmd ); @@ -91,11 +95,15 @@ implements DependencyProcessor } 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 ) ); + MavenDomainModel model = + ( (MavenDomainModel) ctx.transform( domainModels, transformer, transformer, null, + interpolatorProperties, null ) ); return model.getDependencyMetadata(); } catch ( IOException e ) @@ -110,7 +118,8 @@ implements DependencyProcessor List domainModels = new ArrayList(); if ( domainModel.hasParent() ) { - MavenDomainModel parentDomainModel = new MavenDomainModel( mdReader.readMetadata( domainModel.getParentMetadata() ) ); + MavenDomainModel parentDomainModel = + new MavenDomainModel( mdReader.readMetadata( domainModel.getParentMetadata() ) ); domainModels.add( parentDomainModel ); domainModels.addAll( getParentsOfDomainModel( parentDomainModel, mdReader ) ); } @@ -122,10 +131,12 @@ implements DependencyProcessor List properties = new ArrayList(); for ( ModelProperty mp : modelProperties ) { - if ( mp.getUri().startsWith( ProjectUri.Profiles.Profile.xUri ) && !mp.getUri().equals( ProjectUri.Profiles.Profile.id ) + 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() ) ); + properties.add( new ModelProperty( mp.getUri().replace( ProjectUri.Profiles.Profile.xUri, + ProjectUri.xUri ), mp.getResolvedValue() ) ); } } return properties; diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java index ff0923300d..8994b7883f 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java @@ -46,7 +46,9 @@ import org.apache.maven.shared.model.impl.DefaultModelDataSource; /** * Provides a wrapper for the maven model. */ -public final class MavenDomainModel implements DomainModel { +public final class MavenDomainModel + implements DomainModel +{ /** * Bytes containing the underlying model @@ -60,171 +62,220 @@ public final class MavenDomainModel implements DomainModel { private ArtifactBasicMetadata parentMetadata; - /** * Constructor - * + * * @throws IOException if there is a problem constructing the model */ public MavenDomainModel( byte[] bytes ) - throws IOException + throws IOException { - this( new ByteArrayInputStream(bytes) ); + this( new ByteArrayInputStream( bytes ) ); } /** * Constructor - * + * * @throws IOException if there is a problem constructing the model */ - public MavenDomainModel(InputStream inputStream) - throws IOException { - this(ModelMarshaller.marshallXmlToModelProperties(inputStream, ProjectUri.baseUri, PomTransformer.URIS)); + public MavenDomainModel( InputStream inputStream ) + throws IOException + { + this( ModelMarshaller.marshallXmlToModelProperties( inputStream, ProjectUri.baseUri, PomTransformer.URIS ) ); } /** * Constructor - * + * * @throws IOException if there is a problem constructing the model */ - public MavenDomainModel(List modelProperties) - throws IOException { - if (modelProperties == null) { - throw new IllegalArgumentException("modelProperties: null"); + public MavenDomainModel( List modelProperties ) + throws IOException + { + if ( modelProperties == null ) + { + throw new IllegalArgumentException( "modelProperties: null" ); } - this.modelProperties = new ArrayList(modelProperties); + this.modelProperties = new ArrayList( modelProperties ); } - public boolean hasParent() { - //TODO: Expensive call if no parent + public boolean hasParent() + { + // TODO: Expensive call if no parent return getParentMetadata() != null; } - public List getDependencyMetadata() throws DataSourceException { + public List getDependencyMetadata() + throws DataSourceException + { List metadatas = new ArrayList(); ModelDataSource source = new DefaultModelDataSource(); - source.init(modelProperties, Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory())); - for(ModelContainer modelContainer: source.queryFor(ProjectUri.Dependencies.Dependency.xUri)) { - metadatas.add(transformContainerToMetadata(modelContainer)); + source.init( modelProperties, + Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) ); + + for ( ModelContainer modelContainer : source.queryFor( ProjectUri.Dependencies.Dependency.xUri ) ) + { + metadatas.add( transformContainerToMetadata( modelContainer ) ); } return metadatas; } - public Collection getActiveProfileContainers(List properties) throws DataSourceException { + public Collection getActiveProfileContainers( List properties ) + throws DataSourceException + { ModelDataSource dataSource = new DefaultModelDataSource(); - dataSource.init(modelProperties, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) ); - return new ProfileContext(dataSource, properties).getActiveProfiles(); + dataSource.init( modelProperties, Arrays.asList( new ArtifactModelContainerFactory(), + new IdModelContainerFactory() ) ); + return new ProfileContext( dataSource, properties ).getActiveProfiles(); } - public ArtifactBasicMetadata getParentMetadata() { - if (parentMetadata != null) { - return copyArtifactBasicMetadata(parentMetadata); + public ArtifactBasicMetadata getParentMetadata() + { + if ( parentMetadata != null ) + { + return copyArtifactBasicMetadata( parentMetadata ); } + String groupId = null, artifactId = null, version = null; - for (ModelProperty mp : modelProperties) { - if (mp.getUri().equals(ProjectUri.Parent.version)) { + for ( ModelProperty mp : modelProperties ) + { + if ( mp.getUri().equals( ProjectUri.Parent.version ) ) + { version = mp.getValue(); - } else if (mp.getUri().equals(ProjectUri.Parent.artifactId)) { + } + else if ( mp.getUri().equals( ProjectUri.Parent.artifactId ) ) + { artifactId = mp.getValue(); - } else if (mp.getUri().equals(ProjectUri.Parent.groupId)) { + } + else if ( mp.getUri().equals( ProjectUri.Parent.groupId ) ) + { groupId = mp.getValue(); } - if (groupId != null && artifactId != null && version != null) { + if ( groupId != null && artifactId != null && version != null ) + { break; } } - if (groupId == null || artifactId == null || version == null) { + if ( groupId == null || artifactId == null || version == null ) + { return null; } parentMetadata = new ArtifactBasicMetadata(); - parentMetadata.setArtifactId(artifactId); - parentMetadata.setVersion(version); - parentMetadata.setGroupId(groupId); + parentMetadata.setArtifactId( artifactId ); + parentMetadata.setVersion( version ); + parentMetadata.setGroupId( groupId ); - return copyArtifactBasicMetadata(parentMetadata); + return copyArtifactBasicMetadata( parentMetadata ); } - private ArtifactBasicMetadata copyArtifactBasicMetadata(ArtifactBasicMetadata metadata) { + private ArtifactBasicMetadata copyArtifactBasicMetadata( ArtifactBasicMetadata metadata ) + { ArtifactBasicMetadata amd = new ArtifactBasicMetadata(); - amd.setArtifactId(metadata.getArtifactId()); - amd.setGroupId(metadata.getGroupId()); - amd.setVersion(metadata.getVersion()); + amd.setArtifactId( metadata.getArtifactId() ); + amd.setGroupId( metadata.getGroupId() ); + amd.setVersion( metadata.getVersion() ); return amd; } /** * @see org.apache.maven.shared.model.DomainModel#getEventHistory() */ - public String getEventHistory() { + public String getEventHistory() + { return eventHistory; } /** * @see org.apache.maven.shared.model.DomainModel#setEventHistory(String) */ - public void setEventHistory(String eventHistory) { - if (eventHistory == null) { - throw new IllegalArgumentException("eventHistory: null"); + public void setEventHistory( String eventHistory ) + { + if ( eventHistory == null ) + { + throw new IllegalArgumentException( "eventHistory: null" ); } this.eventHistory = eventHistory; } - public List getModelProperties() throws IOException { - return new ArrayList(modelProperties); + public List getModelProperties() + throws IOException + { + return new ArrayList( modelProperties ); } - private ArtifactBasicMetadata transformContainerToMetadata( ModelContainer container ) throws DataSourceException + private ArtifactBasicMetadata transformContainerToMetadata( ModelContainer container ) + throws DataSourceException { List modelProperties = container.getProperties(); ArtifactBasicMetadata metadata = new ArtifactBasicMetadata(); for ( ModelProperty mp : modelProperties ) { - if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.groupId)) { - metadata.setGroupId(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.artifactId)) { - metadata.setArtifactId(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.version)) { - metadata.setVersion(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.classifier)) { - metadata.setClassifier(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) { - metadata.setScope(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.type)) { - metadata.setType(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.optional)) { - metadata.setOptional(mp.getValue()); + if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.groupId ) ) + { + metadata.setGroupId( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.artifactId ) ) + { + metadata.setArtifactId( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.version ) ) + { + metadata.setVersion( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.classifier ) ) + { + metadata.setClassifier( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.scope ) ) + { + metadata.setScope( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) ) + { + metadata.setType( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.optional ) ) + { + metadata.setOptional( mp.getValue() ); } } - if(metadata.getScope() == null) { - metadata.setScope("runtime"); + if ( metadata.getScope() == null ) + { + metadata.setScope( "runtime" ); } ModelDataSource dataSource = new DefaultModelDataSource(); - dataSource.init(container.getProperties(), Arrays.asList(new ArtifactModelContainerFactory(), new ExclusionModelContainerFactory()) ); + dataSource.init( container.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(), + new ExclusionModelContainerFactory() ) ); List exclusions = new ArrayList(); - for(ModelContainer exclusion : dataSource.queryFor(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.xUri)) { + for ( ModelContainer exclusion : dataSource.queryFor( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.xUri ) ) + { ArtifactBasicMetadata meta = new ArtifactBasicMetadata(); - exclusions.add(meta); + exclusions.add( meta ); - for(ModelProperty mp : exclusion.getProperties()) { - if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.artifactId)) { - meta.setArtifactId(mp.getValue()); - } else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.groupId)) { - meta.setGroupId(mp.getValue()); + for ( ModelProperty mp : exclusion.getProperties() ) + { + if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.artifactId ) ) + { + meta.setArtifactId( mp.getValue() ); + } + else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.groupId ) ) + { + meta.setGroupId( mp.getValue() ); } } } - metadata.setExclusions(exclusions); - + metadata.setExclusions( exclusions ); + return metadata; } } diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java index 10dbcecb7f..531e8d28fc 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModelFactory.java @@ -7,9 +7,13 @@ import org.apache.maven.shared.model.ModelProperty; import java.util.List; import java.io.IOException; -public class MavenDomainModelFactory implements DomainModelFactory { - - public DomainModel createDomainModel(List modelProperties) throws IOException { - return new MavenDomainModel(modelProperties); +public class MavenDomainModelFactory + implements DomainModelFactory +{ + + public DomainModel createDomainModel( List modelProperties ) + throws IOException + { + return new MavenDomainModel( modelProperties ); } }