applied our coding conventions (no code change)

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@725035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Herve Boutemy 2008-12-10 09:06:40 +00:00
parent 845dfab57c
commit d242ddfaf2
4 changed files with 162 additions and 93 deletions

View File

@ -20,6 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-mercury</artifactId>
<name>Maven Mercury</name>
<dependencies>
<dependency>
<groupId>org.apache.maven.mercury</groupId>
@ -44,6 +45,7 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@ -52,4 +54,5 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -36,7 +36,8 @@ import org.codehaus.plexus.component.annotations.Component;
public final class MavenDependencyProcessor
implements DependencyProcessor
{
public List<ArtifactBasicMetadata> getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user )
public List<ArtifactBasicMetadata> getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system,
Map user )
throws MetadataReaderException, DependencyProcessorException
{
if ( bmd == null )
@ -50,15 +51,18 @@ implements DependencyProcessor
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
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<DomainModel> domainModels = new ArrayList<DomainModel>();
@ -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<DomainModel> domainModels = new ArrayList<DomainModel>();
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<ModelProperty> properties = new ArrayList<ModelProperty>();
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;

View File

@ -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,7 +62,6 @@ public final class MavenDomainModel implements DomainModel {
private ArtifactBasicMetadata parentMetadata;
/**
* Constructor
*
@ -78,7 +79,8 @@ public final class MavenDomainModel implements DomainModel {
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel( InputStream inputStream )
throws IOException {
throws IOException
{
this( ModelMarshaller.marshallXmlToModelProperties( inputStream, ProjectUri.baseUri, PomTransformer.URIS ) );
}
@ -88,57 +90,79 @@ public final class MavenDomainModel implements DomainModel {
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel( List<ModelProperty> modelProperties )
throws IOException {
if (modelProperties == null) {
throws IOException
{
if ( modelProperties == null )
{
throw new IllegalArgumentException( "modelProperties: null" );
}
this.modelProperties = new ArrayList<ModelProperty>( modelProperties );
}
public boolean hasParent() {
public boolean hasParent()
{
// TODO: Expensive call if no parent
return getParentMetadata() != null;
}
public List<ArtifactBasicMetadata> getDependencyMetadata() throws DataSourceException {
public List<ArtifactBasicMetadata> getDependencyMetadata()
throws DataSourceException
{
List<ArtifactBasicMetadata> metadatas = new ArrayList<ArtifactBasicMetadata>();
ModelDataSource source = new DefaultModelDataSource();
source.init(modelProperties, Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory()));
for(ModelContainer modelContainer: source.queryFor(ProjectUri.Dependencies.Dependency.xUri)) {
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<ModelContainer> getActiveProfileContainers(List<InterpolatorProperty> properties) throws DataSourceException {
public Collection<ModelContainer> getActiveProfileContainers( List<InterpolatorProperty> properties )
throws DataSourceException
{
ModelDataSource dataSource = new DefaultModelDataSource();
dataSource.init(modelProperties, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
dataSource.init( modelProperties, Arrays.asList( new ArtifactModelContainerFactory(),
new IdModelContainerFactory() ) );
return new ProfileContext( dataSource, properties ).getActiveProfiles();
}
public ArtifactBasicMetadata getParentMetadata() {
if (parentMetadata != null) {
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();
@ -149,7 +173,8 @@ public final class MavenDomainModel implements DomainModel {
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() );
@ -160,64 +185,90 @@ public final class MavenDomainModel implements DomainModel {
/**
* @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) {
public void setEventHistory( String eventHistory )
{
if ( eventHistory == null )
{
throw new IllegalArgumentException( "eventHistory: null" );
}
this.eventHistory = eventHistory;
}
public List<ModelProperty> getModelProperties() throws IOException {
public List<ModelProperty> getModelProperties()
throws IOException
{
return new ArrayList<ModelProperty>( modelProperties );
}
private ArtifactBasicMetadata transformContainerToMetadata( ModelContainer container ) throws DataSourceException
private ArtifactBasicMetadata transformContainerToMetadata( ModelContainer container )
throws DataSourceException
{
List<ModelProperty> modelProperties = container.getProperties();
ArtifactBasicMetadata metadata = new ArtifactBasicMetadata();
for ( ModelProperty mp : modelProperties )
{
if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.groupId)) {
if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.groupId ) )
{
metadata.setGroupId( mp.getValue() );
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.artifactId)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.artifactId ) )
{
metadata.setArtifactId( mp.getValue() );
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.version)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.version ) )
{
metadata.setVersion( mp.getValue() );
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.classifier)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.classifier ) )
{
metadata.setClassifier( mp.getValue() );
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.scope ) )
{
metadata.setScope( mp.getValue() );
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.type)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) )
{
metadata.setType( mp.getValue() );
} else if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.optional)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.optional ) )
{
metadata.setOptional( mp.getValue() );
}
}
if(metadata.getScope() == null) {
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<ArtifactBasicMetadata> exclusions = new ArrayList<ArtifactBasicMetadata>();
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 );
for(ModelProperty mp : exclusion.getProperties()) {
if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.artifactId)) {
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)) {
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.groupId ) )
{
meta.setGroupId( mp.getValue() );
}
}

View File

@ -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 class MavenDomainModelFactory
implements DomainModelFactory
{
public DomainModel createDomainModel(List<ModelProperty> modelProperties) throws IOException {
public DomainModel createDomainModel( List<ModelProperty> modelProperties )
throws IOException
{
return new MavenDomainModel( modelProperties );
}
}