From c3715849bf0cea22e1145c6cf7a833f414b1b152 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Tue, 28 Apr 2009 04:12:32 +0000 Subject: [PATCH] Default plugins. git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@769235 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultMavenExecutionRequest.java | 23 +++++++ .../execution/MavenExecutionRequest.java | 6 ++ .../java/org/apache/maven/cli/MavenCli.java | 3 +- .../apache/maven/embedder/MavenEmbedder.java | 7 +++ .../apache/maven/model/ProcessorContext.java | 63 ++++++++++++++++++- .../interpolator/DefaultInterpolator.java | 16 ++++- .../model/interpolator/Interpolator.java | 5 +- .../project/DefaultMavenProjectBuilder.java | 6 +- .../DefaultProjectBuilderConfiguration.java | 19 ++++++ .../project/ProjectBuilderConfiguration.java | 6 ++ 10 files changed, 149 insertions(+), 5 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 70817a0e0b..5d6f0589d8 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -18,10 +18,13 @@ package org.apache.maven.execution; import java.io.File; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Properties; +import java.util.Set; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Plugin; import org.apache.maven.profiles.ProfileActivationContext; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.DefaultProjectBuilderConfiguration; @@ -68,6 +71,8 @@ public class DefaultMavenExecutionRequest private File globalSettingsFile; private File userToolchainsFile; + + private Set plugins; // ---------------------------------------------------------------------------- // Request @@ -115,6 +120,8 @@ public class DefaultMavenExecutionRequest * @issue MNG-2681 */ private boolean noSnapshotUpdates; + + public DefaultMavenExecutionRequest() { } public static MavenExecutionRequest copy( MavenExecutionRequest original ) { @@ -149,6 +156,7 @@ public class DefaultMavenExecutionRequest copy.setProfileManager( original.getProfileManager() ); copy.setRemoteRepositories( original.getRemoteRepositories() ); copy.setNoSnapshotUpdates( original.isNoSnapshotUpdates() ); + copy.setPlugins(original.getPlugins());//TODO - deeper copy return original; } @@ -697,8 +705,23 @@ public class DefaultMavenExecutionRequest projectBuildingConfiguration.setUserProperties( getUserProperties() ); projectBuildingConfiguration.setBuildStartTime( getStartTime() ); projectBuildingConfiguration.setRemoteRepositories( getRemoteRepositories() ); + projectBuildingConfiguration.setPlugins(getPlugins()); } return projectBuildingConfiguration; } + + public void setPlugins(Set plugins) + { + this.plugins = plugins; + } + + public Set getPlugins() + { + if(plugins == null) + { + plugins = new HashSet(); + } + return plugins; + } } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index 68ec7baf47..eb62589123 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -23,9 +23,11 @@ import java.io.File; import java.util.Date; import java.util.List; import java.util.Properties; +import java.util.Set; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.model.Plugin; import org.apache.maven.profiles.ProfileActivationContext; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.ProjectBuilderConfiguration; @@ -211,4 +213,8 @@ public interface MavenExecutionRequest MavenExecutionRequest setUserToolchainsFile( File userToolchainsFile ); ProjectBuilderConfiguration getProjectBuildingConfiguration(); + + void setPlugins(Set plugins); + + Set getPlugins(); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index c100e2ab94..b9f5d2eedb 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -34,6 +34,7 @@ import org.apache.maven.embedder.MavenEmbedderFileLogger; import org.apache.maven.embedder.MavenEmbedderLogger; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.classworlds.ClassWorld; @@ -242,7 +243,7 @@ public class MavenCli { configuration.setLocalRepository( new File( localRepoProperty ) ); } - + return configuration; } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index d9fb599f58..0250b72c6b 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -33,6 +33,7 @@ import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; @@ -125,6 +126,8 @@ public class MavenEmbedder private Configuration configuration; private MavenExecutionRequest request; + + private LifecycleExecutor lifecycleExecutor; // ---------------------------------------------------------------------------- // Constructors @@ -452,6 +455,8 @@ public class MavenEmbedder container.lookup( RepositorySystem.class ); + lifecycleExecutor = container.lookup( LifecycleExecutor.class ); + // This is temporary as we can probably cache a single request and use it for default values and // simply cascade values in from requests used for individual executions. request = new DefaultMavenExecutionRequest(); @@ -572,6 +577,8 @@ public class MavenEmbedder int oldThreshold = loggerManager.getThreshold(); + request.setPlugins(lifecycleExecutor.lifecyclePlugins("default", "jar")); + try { loggerManager.setThresholds( request.getLoggingLevel() ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java b/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java index 539a7fa8fe..2637d62343 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/ProcessorContext.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; + import org.apache.maven.model.BuildBase; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -256,10 +258,69 @@ public class ProcessorContext } + private static void addPlugin(Build build, String id) + { + Plugin p1 = new Plugin(); + p1.setArtifactId(id); + build.addPlugin(p1); + } + + public static void addPluginsToModel(Model target, Set plugins) + { + Build build = target.getBuild(); + addPlugin(build, "maven-compiler-plugin"); + addPlugin(build, "maven-resources-plugin"); + addPlugin(build, "maven-deploy-plugin"); + addPlugin(build, "maven-jar-plugin"); + addPlugin(build, "maven-compiler-plugin"); + addPlugin(build, "maven-surefire-plugin"); + + /* + rg.apache.maven.plugins:maven-jar-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-resources-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-deploy-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-install-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-jar-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-resources-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-surefire-plugin + [java] PLUGIN: org.apache.maven.plugins:maven-deploy-plugin +/* + List mPlugins = target.getBuild().getPlugins(); + + List lifecyclePlugins = new ArrayList(); + + for( Plugin p : plugins ) + { + if( !containsPlugin( p, mPlugins) ) + { + lifecyclePlugins.add(p); + System.out.println("PLUGIN: " + p.getKey()); + } + } + + target.getBuild().getPlugins().addAll(lifecyclePlugins); + */ + } + + private static boolean containsPlugin(Plugin plugin, List plugins) + { + for(Plugin p : plugins) + { + if( p.getGroupId().equals(plugin.getGroupId()) && p.getArtifactId().equals(plugin.getArtifactId())) + { + return true; + } + } + + return false; + } + public static Model processManagementNodes(Model target) throws IOException { - + // Plugin plugin = new Plugin(); + // plugin.setArtifactId("maven-compiler-plugin"); + // target.getBuild().addPlugin(plugin); // Dependency Management DependencyManagementProcessor depProc = new DependencyManagementProcessor(); if ( target.getDependencyManagement() != null ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java index e125e4a85a..9fd469ea90 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java @@ -14,7 +14,9 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; +import java.util.Map.Entry; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; @@ -55,7 +57,19 @@ public class DefaultInterpolator implements Interpolator { interpolateModelProperties( modelProperties, ips ); return unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); } - + + public PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, Properties properties ) + throws IOException + { + List props = new ArrayList(); + for(Entry e : properties + .entrySet()) + { + // props.add(new InterpolatorProperty(e.getKey(), e.getValue(), PomInterpolatorTag.EXECUTION_PROPERTIES)) + } + return interpolateDomainModel(dm, props); + } + public PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, List interpolatorProperties ) throws IOException { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java index 63c2972db7..f559fb85e0 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java @@ -2,6 +2,7 @@ package org.apache.maven.model.interpolator; import java.io.IOException; import java.util.List; +import java.util.Properties; import org.apache.maven.model.PomClassicDomainModel; @@ -13,5 +14,7 @@ public interface Interpolator PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, List interpolatorProperties ) throws IOException ; - + + PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, Properties interpolatorProperties ) + throws IOException ; } diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 3e9aedc8d8..3699e30243 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -168,7 +168,10 @@ public class DefaultMavenProjectBuilder //Interpolation & Management MavenProject project; try { - Model model = ProcessorContext.processManagementNodes(interpolateDomainModel( domainModel, configuration, pomFile )); + Model model = interpolateDomainModel( domainModel, configuration, pomFile ); + ProcessorContext.addPluginsToModel(model, configuration.getPlugins()); + + ProcessorContext.processManagementNodes(model); project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, pomFile); } catch (IOException e) { throw new ProjectBuildingException("", ""); @@ -281,6 +284,7 @@ public class DefaultMavenProjectBuilder throw new ProjectBuildingException("", ""); } + try { Model model = ProcessorContext.processManagementNodes(interpolateDomainModel( domainModel, configuration, artifact.getFile() )); project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, artifact.getFile()); diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java index 8f77ab0362..76f0ab151e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java @@ -20,11 +20,14 @@ package org.apache.maven.project; */ import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Properties; +import java.util.Set; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.ModelEventListener; +import org.apache.maven.model.Plugin; import org.apache.maven.profiles.ProfileManager; public class DefaultProjectBuilderConfiguration @@ -47,6 +50,22 @@ public class DefaultProjectBuilderConfiguration private MavenProject topProject; + private Set plugins; + + public void setPlugins(Set plugins) + { + this.plugins = plugins; + } + + public Set getPlugins() + { + if(plugins == null) + { + plugins = new HashSet(); + } + return plugins; + } + public MavenProject getTopLevelProjectFromReactor() { return topProject; diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java b/maven-project/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java index bef479f14b..03f80169d0 100644 --- a/maven-project/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java +++ b/maven-project/src/main/java/org/apache/maven/project/ProjectBuilderConfiguration.java @@ -1,11 +1,13 @@ package org.apache.maven.project; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Plugin; import org.apache.maven.profiles.ProfileManager; import java.util.Date; import java.util.List; import java.util.Properties; +import java.util.Set; public interface ProjectBuilderConfiguration { @@ -37,4 +39,8 @@ public interface ProjectBuilderConfiguration MavenProject getTopLevelProjectFromReactor(); void setTopLevelProjectForReactor(MavenProject mavenProject); + + void setPlugins(Set plugins); + + Set getPlugins(); }