mirror of https://github.com/apache/maven.git
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:
parent
8532f36055
commit
887d534ad2
|
@ -11,97 +11,99 @@ import org.apache.maven.mercury.builder.api.MetadataReaderException;
|
||||||
import org.apache.maven.project.builder.*;
|
import org.apache.maven.project.builder.*;
|
||||||
import org.apache.maven.shared.model.*;
|
import org.apache.maven.shared.model.*;
|
||||||
|
|
||||||
public final class MavenDependencyProcessor implements DependencyProcessor {
|
public final class MavenDependencyProcessor
|
||||||
|
implements DependencyProcessor
|
||||||
public MavenDependencyProcessor() {
|
{
|
||||||
|
public List<ArtifactBasicMetadata> getDependencies( ArtifactBasicMetadata bmd, MetadataReader mdReader, Map system, Map user )
|
||||||
}
|
throws MetadataReaderException, DependencyProcessorException
|
||||||
|
|
||||||
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");
|
{
|
||||||
|
throw new IllegalArgumentException( "bmd: null" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mdReader == null) {
|
if ( mdReader == null )
|
||||||
throw new IllegalArgumentException("mdReader: null");
|
{
|
||||||
|
throw new IllegalArgumentException( "mdReader: null" );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
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) {
|
if ( system != null )
|
||||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( system,
|
{
|
||||||
PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
|
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.SYSTEM_PROPERTIES.name() ) );
|
||||||
}
|
}
|
||||||
if(user != null) {
|
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>();
|
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||||
try {
|
try
|
||||||
// MavenDomainModel superPom =
|
{
|
||||||
// new MavenDomainModel(MavenDependencyProcessor.class.getResourceAsStream( "pom-4.0.0.xml" ));
|
// MavenDomainModel superPom =
|
||||||
// domainModels.add(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 );
|
MavenDomainModel domainModel = new MavenDomainModel( superBytes );
|
||||||
domainModels.add(domainModel);
|
domainModels.add( domainModel );
|
||||||
|
|
||||||
Collection<ModelContainer> activeProfiles = domainModel.getActiveProfileContainers(interpolatorProperties);
|
Collection<ModelContainer> activeProfiles = domainModel.getActiveProfileContainers( interpolatorProperties );
|
||||||
|
|
||||||
for(ModelContainer mc : activeProfiles) {
|
for ( ModelContainer mc : activeProfiles )
|
||||||
domainModels.add(new MavenDomainModel(transformProfiles(mc.getProperties())));
|
{
|
||||||
|
domainModels.add( new MavenDomainModel( transformProfiles( mc.getProperties() ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
domainModels.addAll( getParentsOfDomainModel( domainModel, mdReader ) );
|
||||||
domainModels.addAll(getParentsOfDomainModel(domainModel, mdReader));
|
}
|
||||||
} catch (IOException e) {
|
catch ( IOException e )
|
||||||
throw new MetadataReaderException("Failed to create domain model. Message = " + e.getMessage());
|
{
|
||||||
|
throw new MetadataReaderException( "Failed to create domain model. Message = " + e.getMessage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
PomTransformer transformer = new PomTransformer(new MavenDomainModelFactory());
|
PomTransformer transformer = new PomTransformer( new MavenDomainModelFactory() );
|
||||||
ModelTransformerContext ctx = new ModelTransformerContext(
|
ModelTransformerContext ctx = new ModelTransformerContext( Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
|
||||||
Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory()));
|
|
||||||
|
|
||||||
try {
|
try
|
||||||
MavenDomainModel model = ((MavenDomainModel) ctx.transform(domainModels,
|
{
|
||||||
transformer,
|
MavenDomainModel model = ( (MavenDomainModel) ctx.transform( domainModels, transformer, transformer, null, interpolatorProperties, null ) );
|
||||||
transformer,
|
|
||||||
null,
|
|
||||||
interpolatorProperties,
|
|
||||||
null));
|
|
||||||
return model.getDependencyMetadata();
|
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<DomainModel> getParentsOfDomainModel(MavenDomainModel domainModel, MetadataReader mdReader)
|
private static List<DomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
|
||||||
throws IOException, MetadataReaderException {
|
throws IOException, MetadataReaderException
|
||||||
|
{
|
||||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||||
if (domainModel.hasParent()) {
|
if ( domainModel.hasParent() )
|
||||||
MavenDomainModel parentDomainModel = new MavenDomainModel(mdReader.readMetadata(domainModel.getParentMetadata()));
|
{
|
||||||
domainModels.add(parentDomainModel);
|
MavenDomainModel parentDomainModel = new MavenDomainModel( mdReader.readMetadata( domainModel.getParentMetadata() ) );
|
||||||
domainModels.addAll(getParentsOfDomainModel(parentDomainModel, mdReader));
|
domainModels.add( parentDomainModel );
|
||||||
|
domainModels.addAll( getParentsOfDomainModel( parentDomainModel, mdReader ) );
|
||||||
}
|
}
|
||||||
return domainModels;
|
return domainModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ModelProperty> transformProfiles(List<ModelProperty> modelProperties) {
|
private static List<ModelProperty> transformProfiles( List<ModelProperty> modelProperties )
|
||||||
|
{
|
||||||
List<ModelProperty> properties = new ArrayList<ModelProperty>();
|
List<ModelProperty> properties = new ArrayList<ModelProperty>();
|
||||||
for(ModelProperty mp : modelProperties) {
|
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)) {
|
&& !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;
|
return properties;
|
||||||
|
|
Loading…
Reference in New Issue