diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java index 540f009399..8f74e7d1fb 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java @@ -33,12 +33,10 @@ import org.apache.maven.project.builder.PomArtifactResolver; import org.apache.maven.project.builder.PomClassicDomainModel; import org.apache.maven.project.builder.PomClassicTransformer; import org.apache.maven.project.builder.ProjectBuilder; +import org.apache.maven.project.builder.listeners.PluginExtensionListener; import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidator; -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.ImportModel; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelTransformerContext; +import org.apache.maven.shared.model.*; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; @@ -178,7 +176,7 @@ public final class DefaultProjectBuilder transformer, importModels, properties, - null) ); + Arrays.asList((ModelEventListener) new PluginExtensionListener())) ); try { MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory, diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/listeners/PluginExtensionListener.java b/maven-project/src/main/java/org/apache/maven/project/builder/listeners/PluginExtensionListener.java new file mode 100644 index 0000000000..4a568596ed --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/builder/listeners/PluginExtensionListener.java @@ -0,0 +1,66 @@ +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 modelContainers) { + List pluginsWithExtension = new ArrayList(); + for (ModelContainer mc : modelContainers) { + if(hasExtension(mc)) { + pluginsWithExtension.add(new Plugin(mc.getProperties())); + } + } + + //Do something with plugins here + } + + public List getUris() { + return Arrays.asList(ProjectUri.Build.Plugins.Plugin.xUri); + } + + public Collection 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 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 + } + } + } +}