mirror of https://github.com/apache/maven.git
Checked in support for plugin extension listener. Not using a configurable plexus component yet. The listener is added directly to the transform.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@714122 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1a9ef5d0e0
commit
7de89c1ee9
|
@ -33,12 +33,10 @@ 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.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.DomainModel;
|
import org.apache.maven.shared.model.*;
|
||||||
import org.apache.maven.shared.model.ImportModel;
|
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
|
||||||
import org.apache.maven.shared.model.ModelTransformerContext;
|
|
||||||
import org.codehaus.plexus.logging.LogEnabled;
|
import org.codehaus.plexus.logging.LogEnabled;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
|
||||||
|
@ -178,7 +176,7 @@ public final class DefaultProjectBuilder
|
||||||
transformer,
|
transformer,
|
||||||
importModels,
|
importModels,
|
||||||
properties,
|
properties,
|
||||||
null) );
|
Arrays.asList((ModelEventListener) new PluginExtensionListener())) );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
|
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
|
||||||
|
|
|
@ -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<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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue