From 887d534ad27e54e3100bff03adba5f90773485c4 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sun, 30 Nov 2008 06:41:42 +0000 Subject: [PATCH] o formatting git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@721771 13f79535-47bb-0310-9956-ffa450edef68 --- .../mercury/MavenDependencyProcessor.java | 128 +++++++++--------- 1 file changed, 65 insertions(+), 63 deletions(-) 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 e63915d4ac..fa961a062c 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 @@ -11,97 +11,99 @@ 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 List getDependencies(ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user) - throws MetadataReaderException, DependencyProcessorException +public final class MavenDependencyProcessor + implements DependencyProcessor +{ + public List getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user ) + throws MetadataReaderException, DependencyProcessorException { - if (bmd == null) { - throw new IllegalArgumentException("bmd: null"); + if ( bmd == null ) + { + throw new IllegalArgumentException( "bmd: null" ); } - if (mdReader == null) { - throw new IllegalArgumentException("mdReader: null"); + if ( mdReader == null ) + { + throw new IllegalArgumentException( "mdReader: null" ); } List interpolatorProperties = new ArrayList(); - 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.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT", 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 domainModels = new ArrayList(); - try { -// MavenDomainModel superPom = -// new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" )); -// domainModels.add(superPom); + try + { + // MavenDomainModel superPom = + // new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" )); + // domainModels.add(superPom); + + byte[] superBytes = mdReader.readMetadata( bmd ); + + if ( superBytes == null || superBytes.length < 1 ) + throw new DependencyProcessorException( "cannot read metadata for " + bmd.getGAV() ); - byte [] superBytes = mdReader.readMetadata( bmd ); - - if( superBytes == null || superBytes.length < 1 ) - throw new DependencyProcessorException("cannot read metadata for " + bmd.getGAV() ); - MavenDomainModel domainModel = new MavenDomainModel( superBytes ); - domainModels.add(domainModel); + domainModels.add( domainModel ); - Collection activeProfiles = domainModel.getActiveProfileContainers(interpolatorProperties); + Collection activeProfiles = domainModel.getActiveProfileContainers( interpolatorProperties ); - for(ModelContainer mc : activeProfiles) { - domainModels.add(new MavenDomainModel(transformProfiles(mc.getProperties()))); + for ( ModelContainer mc : activeProfiles ) + { + domainModels.add( new MavenDomainModel( transformProfiles( mc.getProperties() ) ) ); } - - domainModels.addAll(getParentsOfDomainModel(domainModel, mdReader)); - } catch (IOException e) { - throw new MetadataReaderException("Failed to create domain model. Message = " + e.getMessage()); + domainModels.addAll( getParentsOfDomainModel( domainModel, mdReader ) ); + } + 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())); + PomTransformer transformer = new PomTransformer( new MavenDomainModelFactory() ); + 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) { - throw new MetadataReaderException("Unable to transform model"); + } + catch ( IOException e ) + { + throw new MetadataReaderException( "Unable to transform model" ); } } - private static List getParentsOfDomainModel(MavenDomainModel domainModel, MetadataReader mdReader) - throws IOException, MetadataReaderException { + private static List getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader ) + throws IOException, MetadataReaderException + { List domainModels = new ArrayList(); - if (domainModel.hasParent()) { - MavenDomainModel parentDomainModel = new MavenDomainModel(mdReader.readMetadata(domainModel.getParentMetadata())); - domainModels.add(parentDomainModel); - domainModels.addAll(getParentsOfDomainModel(parentDomainModel, mdReader)); + if ( domainModel.hasParent() ) + { + MavenDomainModel parentDomainModel = new MavenDomainModel( mdReader.readMetadata( domainModel.getParentMetadata() ) ); + domainModels.add( parentDomainModel ); + domainModels.addAll( getParentsOfDomainModel( parentDomainModel, mdReader ) ); } return domainModels; } - private static List transformProfiles(List modelProperties) { + private static List transformProfiles( List modelProperties ) + { List properties = new ArrayList(); - 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;