o adding new logic to process build extensions

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@718165 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2008-11-17 03:23:35 +00:00
parent 3164c0088f
commit eec6ed1e2c
5 changed files with 89 additions and 80 deletions

View File

@ -42,7 +42,8 @@ public final class ArtifactModelContainerFactory
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri,
ProjectUri.Build.Plugins.Plugin.xUri, ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.xUri, ProjectUri.Build.Plugins.Plugin.xUri, ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.xUri,
ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.Exclusions.Exclusion.xUri ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.Exclusions.Exclusion.xUri,
ProjectUri.Build.Extensions.Extension.xUri
) ); ) );
public Collection<String> getUris() public Collection<String> getUris()

View File

@ -33,7 +33,7 @@ import org.apache.maven.project.builder.PomArtifactResolver;
import org.apache.maven.project.builder.PomClassicDomainModel; import org.apache.maven.project.builder.PomClassicDomainModel;
import org.apache.maven.project.builder.PomClassicTransformer; import org.apache.maven.project.builder.PomClassicTransformer;
import org.apache.maven.project.builder.ProjectBuilder; import org.apache.maven.project.builder.ProjectBuilder;
import org.apache.maven.project.builder.listeners.PluginExtensionListener; import org.apache.maven.project.builder.listeners.BuildExtensionListener;
import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.*;
@ -176,7 +176,7 @@ public final class DefaultProjectBuilder
transformer, transformer,
importModels, importModels,
properties, properties,
Arrays.asList((ModelEventListener) new PluginExtensionListener())) ); Arrays.asList((ModelEventListener) new BuildExtensionListener())) );
try try
{ {
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory, MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,

View File

@ -0,0 +1,85 @@
package org.apache.maven.project.builder.listeners;
import org.apache.maven.shared.model.ModelEventListener;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelContainerFactory;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
import java.util.Arrays;
import java.util.ArrayList;
public class BuildExtensionListener
implements ModelEventListener
{
public void fire( List<ModelContainer> modelContainers )
{
List<BuildExtension> buildExtensions = new ArrayList<BuildExtension>();
for ( ModelContainer mc : modelContainers )
{
if ( hasExtension( mc ) )
{
buildExtensions.add( new BuildExtension( mc.getProperties() ) );
}
}
for( BuildExtension be : buildExtensions )
{
System.out.println( "Extension ---> " + be.groupId + " : " + be.artifactId + " : " + be.version );
}
}
public List<String> getUris()
{
return Arrays.asList( ProjectUri.Build.Extensions.Extension.xUri );
}
public Collection<ModelContainerFactory> getModelContainerFactories()
{
return Arrays.asList( (ModelContainerFactory) new ArtifactModelContainerFactory() );
}
private static boolean hasExtension( ModelContainer container )
{
for ( ModelProperty mp : container.getProperties() )
{
if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.xUri ) )
{
return true;
}
}
return false;
}
private static class BuildExtension
{
private String groupId;
private String artifactId;
private String version;
BuildExtension( List<ModelProperty> modelProperties )
{
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.groupId ) )
{
groupId = mp.getValue();
}
else if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.artifactId ) )
{
artifactId = mp.getValue();
}
else if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.version ) )
{
version = mp.getValue();
}
}
}
}
}

View File

@ -1,66 +0,0 @@
package org.apache.maven.project.builder.listeners;
import org.apache.maven.shared.model.ModelEventListener;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelContainerFactory;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
import java.util.List;
import java.util.Collection;
import java.util.Arrays;
import java.util.ArrayList;
public class PluginExtensionListener implements ModelEventListener {
public void fire(List<ModelContainer> modelContainers) {
List<Plugin> pluginsWithExtension = new ArrayList<Plugin>();
for (ModelContainer mc : modelContainers) {
if(hasExtension(mc)) {
pluginsWithExtension.add(new Plugin(mc.getProperties()));
}
}
//Do something with plugins here
}
public List<String> getUris() {
return Arrays.asList(ProjectUri.Build.Plugins.Plugin.xUri);
}
public Collection<ModelContainerFactory> getModelContainerFactories() {
return Arrays.asList((ModelContainerFactory) new ArtifactModelContainerFactory());
}
private static boolean hasExtension(ModelContainer container) {
for (ModelProperty mp : container.getProperties()) {
if (mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.extensions) && mp.getValue().equals("true")) {
return true;
}
}
return false;
}
private static class Plugin {
private String groupId;
private String artifactId;
private String version;
Plugin(List<ModelProperty> modelProperties) {
for(ModelProperty mp : modelProperties) {
if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.groupId)) {
groupId = mp.getValue();
} else if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.artifactId)) {
artifactId = mp.getValue();
} else if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.version)) {
version = mp.getValue();
}
//Add additional info if needed
}
}
}
}

View File

@ -38,7 +38,6 @@ import java.util.Set;
* Provides methods for marshalling and unmarshalling XML that does not contain attributes. * Provides methods for marshalling and unmarshalling XML that does not contain attributes.
*/ */
public final class ModelMarshaller public final class ModelMarshaller
implements ModelPropertiesGenerator
{ {
/** /**
@ -48,16 +47,6 @@ public final class ModelMarshaller
{ {
} }
public List<ModelProperty> generateModelProperties( InputStream inputStream, String baseUri, Set<String> collections )
throws IOException
{
return marshallXmlToModelProperties( inputStream, baseUri, collections );
}
public void registerModelPropertyListener( String uri )
{
}
/** /**
* Returns list of model properties transformed from the specified input stream. * Returns list of model properties transformed from the specified input stream.
* *