This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to annotated tag maven-help-plugin-2.0 in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git
commit 89cd8745b7feffb2e0055bf004640ed2155270c7 Author: Brett Leslie Porter <br...@apache.org> AuthorDate: Sun May 7 03:32:31 2006 +0000 [maven-scm] copy for tag maven-help-plugin-2.0 git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/tags/maven-help-plugin-2.0@400407 13f79535-47bb-0310-9956-ffa450edef68 --- maven-help-plugin/pom.xml | 46 ++ .../maven/plugins/help/ActiveProfilesMojo.java | 161 +++++ .../apache/maven/plugins/help/DescribeMojo.java | 767 +++++++++++++++++++++ .../maven/plugins/help/EffectivePomMojo.java | 162 +++++ .../maven/plugins/help/EffectiveSettingsMojo.java | 133 ++++ .../src/site/apt/active-profiles-mojo.apt | 27 + maven-help-plugin/src/site/apt/describe-mojo.apt | 93 +++ .../src/site/apt/effective-pom-mojo.apt | 28 + .../src/site/apt/effective-settings-mojo.apt | 26 + maven-help-plugin/src/site/site.xml | 43 ++ 10 files changed, 1486 insertions(+) diff --git a/maven-help-plugin/pom.xml b/maven-help-plugin/pom.xml new file mode 100644 index 0000000..3dbfbb0 --- /dev/null +++ b/maven-help-plugin/pom.xml @@ -0,0 +1,46 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>maven-plugins</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <version>1</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>maven-help-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>Maven Help Plugin</name> + <version>2.0.1</version> + <description> + The Maven Help plugin provides goals aimed at helping to make sense out of + the build environment. It includes the ability to view the effective + POM and settings files, after inheritance and active profiles + have been applied, as well as a describe a particular plugin goal to give usage information. + </description> + <inceptionYear>2001</inceptionYear> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-tools-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-descriptor</artifactId> + <version>2.0</version> + </dependency> + </dependencies> +</project> \ No newline at end of file diff --git a/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java new file mode 100644 index 0000000..2a9a251 --- /dev/null +++ b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java @@ -0,0 +1,161 @@ +package org.apache.maven.plugins.help; + +import org.apache.maven.model.Profile; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** Lists the profiles which are currently active for this build. + * + * @goal active-profiles + * @aggregator + */ +public class ActiveProfilesMojo extends AbstractMojo +{ + + /** + * This is the list of projects currently slated to be built by Maven. + * + * @parameter expression="${reactorProjects}" + * @required + * @readonly + */ + private List projects; + + /** + * This is an optional parameter for a file destination for the output + * of this mojo...the listing of active profiles per project. + * + * @parameter expression="${output}" + */ + private File output; + + public void execute() + throws MojoExecutionException + { + StringBuffer message = new StringBuffer(); + + for ( Iterator it = projects.iterator(); it.hasNext(); ) + { + MavenProject project = (MavenProject) it.next(); + + getActiveProfileStatement( project, message ); + + message.append( "\n\n" ); + } + + if ( output != null ) + { + writeFile( message ); + } + else + { + Log log = getLog(); + log.info( message ); + } + } + + private void writeFile( StringBuffer message ) + throws MojoExecutionException + { + Writer writer = null; + try + { + File dir = output.getParentFile(); + + if( !dir.exists() ) + { + dir.mkdirs(); + } + + writer = new FileWriter( output ); + + writer.write( "Created by: " + getClass().getName() + "\n" ); + writer.write( "Created on: " + new Date() + "\n\n" ); + writer.write( message.toString() ); + writer.flush(); + + getLog().info( "Active profile report written to: " + output ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot write output to file: " + output, e ); + } + finally + { + if ( writer != null ) + { + try + { + writer.close(); + } + catch ( IOException e ) + { + getLog().debug( "Failed to close output file writer.", e ); + } + } + } + } + + private void getActiveProfileStatement( MavenProject project, StringBuffer message ) + { + List profiles = project.getActiveProfiles(); + + message.append( "\n" ); + + message.append( "Active Profiles for Project \'" + project.getId() + "\': \n\n" ); + + if( profiles == null || profiles.isEmpty() ) + { + message.append( "There are no active profiles." ); + } + else + { + message.append( "The following profiles are active:\n" ); + + for ( Iterator it = profiles.iterator(); it.hasNext(); ) + { + Profile profile = (Profile) it.next(); + + message.append( "\n - " ) + .append( profile.getId() ) + .append(" (source: " ) + .append( profile.getSource() ).append( ")" ); + } + + } + + message.append( "\n" ); + } + + public final void setProjects( List projects ) + { + this.projects = projects; + } + +} diff --git a/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java new file mode 100644 index 0000000..c3dd2f3 --- /dev/null +++ b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java @@ -0,0 +1,767 @@ +package org.apache.maven.plugins.help; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.InvalidPluginException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.PluginManager; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.version.PluginVersionNotFoundException; +import org.apache.maven.plugin.version.PluginVersionResolutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.settings.Settings; +import org.codehaus.plexus.component.repository.ComponentRequirement; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; + +/** + * Describes the attributes of a plugin and/or plugin mojo. + * + * @goal describe + * @requiresProject false + * @aggregator + */ +public class DescribeMojo + extends AbstractMojo +{ + + /** + * The plugin/mojo to describe. This must be specified in one of three ways: + * <p/> + * 1. plugin-prefix + * 2. groupId:artifactId + * 3. groupId:artifactId:version + * + * @parameter expression="${plugin}" alias="prefix" + */ + private String plugin; + + /** + * The plugin groupId to describe. + * <br/> + * (Used with artifactId specification). + * + * @parameter expression="${groupId}" + */ + private String groupId; + + /** + * The plugin artifactId to describe. + * <br/> + * (Used with groupId specification). + * + * @parameter expression="${artifactId}" + */ + private String artifactId; + + /** + * The plugin version to describe. + * <br/> + * (Used with groupId/artifactId specification). + * + * @parameter expression="${version}" + */ + private String version; + + /** + * The goal name of a mojo to describe within the specified plugin. + * <br/> + * If this parameter is specified, only the corresponding mojo will + * <br/> + * be described, rather than the whole plugin. + * + * @parameter expression="${mojo}" + */ + private String mojo; + + /** + * The plugin manager instance used to resolve plugin descriptors. + * + * @component role="org.apache.maven.plugin.PluginManager" + */ + private PluginManager pluginManager; + + /** + * The project builder instance used to retrieve the super-project instance + * <br/> + * in the event there is no current MavenProject instance. Some MavenProject + * <br/> + * instance has to be present to use in the plugin manager APIs. + * + * @component role="org.apache.maven.project.MavenProjectBuilder" + */ + private MavenProjectBuilder projectBuilder; + + /** + * The current project, if there is one. This is listed as optional, since + * <br/> + * the help plugin should be able to function on its own. If this + * <br/> + * parameter is empty at execution time, this mojo will instead use the + * <br/> + * super-project. + * + * @parameter expression="${project}" + * @readonly + */ + private MavenProject project; + + /** + * The current user system settings for use in Maven. This is used for + * <br/> + * plugin manager API calls. + * + * @parameter expression="${settings}" + * @required + * @readonly + */ + private Settings settings; + + /** + * The current build session instance. This is used for + * <br/> + * plugin manager API calls. + * + * @parameter expression="${session}" + * @required + * @readonly + */ + private MavenSession session; + + /** + * The local repository ArtifactRepository instance. This is used + * <br/> + * for plugin manager API calls. + * + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + /** + * If specified, this parameter will cause the plugin/mojo descriptions + * <br/> + * to be written to the path specified, instead of writing to the console. + * + * @parameter expression="${output}" + */ + private File output; + + /** + * This flag specifies that full (verbose) information should be + * <br/> + * given. Use true/false. + * + * @parameter expression="${full}" default-value="false" + */ + private boolean full; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( project == null ) + { + try + { + project = projectBuilder.buildStandaloneSuperProject( localRepository ); + } + catch ( ProjectBuildingException e ) + { + throw new MojoExecutionException( "Error while retrieving the super-project.", e ); + } + } + + PluginInfo pi = new PluginInfo(); + + parsePluginLookupInfo( pi ); + + PluginDescriptor descriptor = lookupPluginDescriptor( pi ); + + StringBuffer descriptionBuffer = new StringBuffer(); + + if ( mojo != null && mojo.length() > 0 ) + { + describeMojo( descriptor.getMojo( mojo ), descriptionBuffer ); + } + else + { + describePlugin( descriptor, descriptionBuffer ); + } + + writeDescription( descriptionBuffer ); + } + + private void writeDescription( StringBuffer descriptionBuffer ) + throws MojoExecutionException + { + if ( output != null ) + { + Writer out = null; + try + { + output.getParentFile().mkdirs(); + + out = new FileWriter( output ); + + out.write( descriptionBuffer.toString() ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot write plugin/mojo description.", e ); + } + finally + { + if ( out != null ) + { + try + { + out.close(); + } + catch ( IOException e ) + { + getLog().debug( "Error closing file output.", e ); + } + } + } + + getLog().info( "Wrote descriptions to: " + output ); + } + else + { + getLog().info( descriptionBuffer.toString() ); + } + } + + private PluginDescriptor lookupPluginDescriptor( PluginInfo pi ) + throws MojoExecutionException, MojoFailureException + { + PluginDescriptor descriptor = null; + + Plugin forLookup = null; + + if ( pi.prefix != null ) + { + descriptor = pluginManager.getPluginDescriptorForPrefix( pi.prefix ); + + if ( descriptor == null ) + { + forLookup = pluginManager.getPluginDefinitionForPrefix( pi.prefix, session, project ); + } + } + else if ( pi.groupId != null && pi.artifactId != null ) + { + forLookup = new Plugin(); + + forLookup.setGroupId( pi.groupId ); + forLookup.setArtifactId( pi.artifactId ); + + if ( pi.version != null ) + { + forLookup.setVersion( pi.version ); + } + } + else + { + throw new MojoFailureException( + "You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." ); + } + + if ( descriptor == null && forLookup != null ) + { + try + { + descriptor = pluginManager.verifyPlugin( forLookup, project, settings, localRepository ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( PluginManagerException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( PluginVersionResolutionException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( ArtifactNotFoundException e ) + { + throw new MojoExecutionException( "Plugin dependency does not exist: " + e.getMessage(), e ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( InvalidPluginException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( PluginNotFoundException e ) + { + getLog().debug( "Unable to find plugin", e ); + throw new MojoFailureException( "Plugin does not exist: " + e.getMessage() ); + } + catch ( PluginVersionNotFoundException e ) + { + getLog().debug( "Unable to find plugin version", e ); + throw new MojoFailureException( e.getMessage() ); + } + } + + if ( descriptor == null ) + { + throw new MojoFailureException( + "Plugin could not be found. If you believe it is correct, check your pluginGroups setting, and run with -U to update the remote configuration" ); + } + + return descriptor; + } + + private void parsePluginLookupInfo( PluginInfo pi ) + throws MojoFailureException + { + if ( plugin != null && plugin.length() > 0 ) + { + if ( plugin.indexOf( ":" ) > -1 ) + { + String[] pluginParts = plugin.split( ":" ); + + switch ( pluginParts.length ) + { + case ( 1 ): + { + pi.prefix = pluginParts[0]; + break; + } + case ( 2 ): + { + pi.groupId = pluginParts[0]; + pi.artifactId = pluginParts[1]; + break; + } + case ( 3 ): + { + pi.groupId = pluginParts[0]; + pi.artifactId = pluginParts[1]; + pi.version = pluginParts[2]; + break; + } + default: + { + throw new MojoFailureException( + "plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." ); + } + } + } + else + { + pi.prefix = plugin; + } + } + else + { + pi.groupId = groupId; + pi.artifactId = artifactId; + pi.version = version; + } + } + + private void describePlugin( PluginDescriptor pd, StringBuffer buffer ) + { + String name = pd.getName(); + if ( name == null ) + { + name = pd.getId(); + } + + buffer.append( "Plugin: \'" ).append( name ).append( '\'' ); + buffer.append( "\n-----------------------------------------------" ); + buffer.append( "\nGroup Id: " ).append( pd.getGroupId() ); + buffer.append( "\nArtifact Id: " ).append( pd.getArtifactId() ); + buffer.append( "\nVersion: " ).append( pd.getVersion() ); + buffer.append( "\nGoal Prefix: " ).append( pd.getGoalPrefix() ); + + buffer.append( "\nDescription:\n\n" ); + prettyAppend( formatDescription( pd.getDescription() ), buffer ); + buffer.append( "\n" ); + + if ( full ) + { + buffer.append( "\nMojos:\n" ); + + String line = "\n==============================================="; + + for ( Iterator it = pd.getMojos().iterator(); it.hasNext(); ) + { + MojoDescriptor md = (MojoDescriptor) it.next(); + + buffer.append( line ); + buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( '\'' ); + buffer.append( line ); + + describeMojoGuts( md, buffer, true ); + + buffer.append( line ); + buffer.append( "\n\n" ); + } + } + } + + private String formatDescription( String description ) + { + if ( description == null ) + { + return null; + } + + String result = description.replaceAll( " ?\\<br\\/?\\> ?", "\n" ); + + result = result.replaceAll( " ?\\<p\\> ?", "" ); + result = result.replaceAll( " ?\\</p\\> ?", "\n\n" ); + + return result; + } + + private void prettyAppend( String messagePart, StringBuffer buffer ) + { + if ( messagePart != null && messagePart.length() > 0 ) + { + buffer.append( messagePart ); + } + else + { + buffer.append( "Unknown" ); + } + } + + private void describeMojo( MojoDescriptor md, StringBuffer buffer ) + { + String line = "\n==============================================="; + + buffer.append( "Mojo: \'" ).append( md.getFullGoalName() ).append( '\'' ); + buffer.append( line ); + buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( "\'" ); + + describeMojoGuts( md, buffer, full ); + + buffer.append( line ); + buffer.append( "\n\n" ); + } + + private void describeMojoGuts( MojoDescriptor md, StringBuffer buffer, boolean fullDescription ) + { + buffer.append( "\nDescription:\n\n" ); + prettyAppend( formatDescription( md.getDescription() ), buffer ); + buffer.append( "\n" ); + + String deprecation = md.getDeprecated(); + + if ( deprecation != null ) + { + buffer.append( "\n\nNOTE: This mojo is deprecated.\n" ).append( deprecation ).append( "\n" ); + } + + if ( fullDescription ) + { + buffer.append( "\nImplementation: " ).append( md.getImplementation() ); + buffer.append( "\nLanguage: " ).append( md.getLanguage() ); + + String phase = md.getPhase(); + if ( phase != null ) + { + buffer.append( "\nBound to Phase: " ).append( phase ); + } + + String eGoal = md.getExecuteGoal(); + String eLife = md.getExecuteLifecycle(); + String ePhase = md.getExecutePhase(); + + if ( eGoal != null || ePhase != null ) + { + buffer.append( "\n\nBefore this mojo executes, it will call:\n" ); + + if ( eGoal != null ) + { + buffer.append( "\nSingle mojo: \'" ).append( eGoal ).append( "\'" ); + } + + if ( ePhase != null ) + { + buffer.append( "\nPhase: \'" ).append( ePhase ).append( "\'" ); + + if ( eLife != null ) + { + buffer.append( " in Lifecycle Overlay: \'" ).append( eLife ).append( "\'" ); + } + } + } + + describeMojoParameters( md, buffer ); + + describeMojoRequirements( md, buffer ); + } + } + + private void describeMojoRequirements( MojoDescriptor md, StringBuffer buffer ) + { + buffer.append( "\n" ); + + List reqs = md.getRequirements(); + + if ( reqs == null || reqs.isEmpty() ) + { + buffer.append( "\nThis mojo doesn't have any component requirements." ); + } + else + { + buffer.append( "\nComponent Requirements:\n" ); + + String line = "\n-----------------------------------------------"; + + int idx = 0; + for ( Iterator it = reqs.iterator(); it.hasNext(); idx++ ) + { + ComponentRequirement req = (ComponentRequirement) it.next(); + + buffer.append( line ); + + buffer.append( "\n[" ).append( idx ).append( "] " ); + buffer.append( "Role: " ).append( req.getRole() ); + + String hint = req.getRoleHint(); + if ( hint != null ) + { + buffer.append( "\nRole-Hint: " ).append( hint ); + } + + buffer.append( "\n" ); + } + + buffer.append( line ); + } + } + + private void describeMojoParameters( MojoDescriptor md, StringBuffer buffer ) + { + buffer.append( "\n" ); + + List params = md.getParameters(); + + if ( params == null || params.isEmpty() ) + { + buffer.append( "\nThis mojo doesn't use any parameters." ); + } + else + { + buffer.append( "\nParameters:" ); + + String line = "\n-----------------------------------------------"; + + int idx = 0; + for ( Iterator it = params.iterator(); it.hasNext(); ) + { + Parameter parameter = (Parameter) it.next(); + + buffer.append( line ); + buffer.append( "\n\n[" ).append( idx++ ).append( "] " ); + buffer.append( "Name: " ); + prettyAppend( parameter.getName(), buffer ); + + String alias = parameter.getAlias(); + if ( alias != null ) + { + buffer.append( " (Alias: " ).append( alias ).append( ")" ); + } + + buffer.append( "\nType: " ); + prettyAppend( parameter.getType(), buffer ); + + String expression = parameter.getExpression(); + if ( expression != null ) + { + buffer.append( "\nExpression: " ).append( expression ); + } + + String defaultVal = parameter.getDefaultValue(); + if ( defaultVal != null ) + { + buffer.append( "\nDefault value: \'" ).append( defaultVal ); + } + + buffer.append( "\nRequired: " ).append( parameter.isRequired() ); + buffer.append( "\nDirectly editable: " ).append( parameter.isEditable() ); + + buffer.append( "\nDescription:\n\n" ); + prettyAppend( formatDescription( parameter.getDescription() ), buffer ); + + String deprecation = parameter.getDeprecated(); + + if ( deprecation != null ) + { + buffer.append( "\n\nNOTE: This parameter is deprecated.\n" ).append( deprecation ).append( "\n" ); + } + + buffer.append( "\n" ); + } + + buffer.append( line ); + } + } + + public final String getPlugin() + { + return plugin; + } + + public final void setPlugin( String plugin ) + { + this.plugin = plugin; + } + + public final PluginManager getPluginManager() + { + return pluginManager; + } + + public final void setPluginManager( PluginManager pluginManager ) + { + this.pluginManager = pluginManager; + } + + public final String getArtifactId() + { + return artifactId; + } + + public final void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public final String getGroupId() + { + return groupId; + } + + public final void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public final ArtifactRepository getLocalRepository() + { + return localRepository; + } + + public final void setLocalRepository( ArtifactRepository localRepository ) + { + this.localRepository = localRepository; + } + + public final String getMojo() + { + return mojo; + } + + public final void setMojo( String mojo ) + { + this.mojo = mojo; + } + + public final File getOutput() + { + return output; + } + + public final void setOutput( File output ) + { + this.output = output; + } + + public final MavenProject getProject() + { + return project; + } + + public final void setProject( MavenProject project ) + { + this.project = project; + } + + public final Settings getSettings() + { + return settings; + } + + public final void setSettings( Settings settings ) + { + this.settings = settings; + } + + public final String getVersion() + { + return version; + } + + public final void setVersion( String version ) + { + this.version = version; + } + + private static class PluginInfo + { + String prefix; + + String groupId; + + String artifactId; + + String version; + + String mojo; + + Plugin plugin; + + PluginDescriptor pluginDescriptor; + } + +} diff --git a/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java new file mode 100644 index 0000000..41f8325 --- /dev/null +++ b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -0,0 +1,162 @@ +package org.apache.maven.plugins.help; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** Display the effective POM for this build, with the active profiles factored in. + * + * @goal effective-pom + * @aggregator + */ +public class EffectivePomMojo + extends AbstractMojo +{ + + /** + * The projects in the current build. The effective-POM for + * each of these projects will written. + * + * @parameter expression="${reactorProjects}" + * @required + * @readonly + */ + private List projects; + + /** + * If specified, write the output to this path. + * + * @parameter expression="${output}" + */ + private File output; + + public void execute() + throws MojoExecutionException + { + StringBuffer message = new StringBuffer(); + + for ( Iterator it = projects.iterator(); it.hasNext(); ) + { + MavenProject project = (MavenProject) it.next(); + + getEffectivePom( project, message ); + + message.append( "\n\n" ); + } + + if ( output != null ) + { + FileWriter fWriter = null; + try + { + File dir = output.getParentFile(); + + if ( !dir.exists() ) + { + dir.mkdirs(); + } + + getLog().info( "Writing effective-POM to: " + output ); + + fWriter = new FileWriter( output ); + + fWriter.write( "Created by: " + getClass().getName() + "\n" ); + fWriter.write( "Created on: " + new Date() + "\n\n" ); + + fWriter.write( message.toString() ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot write effective-POM to output: " + output, e ); + } + finally + { + if ( fWriter != null ) + { + try + { + fWriter.close(); + } + catch ( IOException e ) + { + getLog().debug( "Cannot close FileWriter to output location: " + output, e ); + } + } + } + } + else + { + StringBuffer formatted = new StringBuffer(); + + formatted.append( "\nEffective POMs, after inheritance, interpolation, and profiles are applied:\n\n" ); + formatted.append( message.toString() ); + formatted.append( "\n" ); + + getLog().info( message ); + } + } + + private void getEffectivePom( MavenProject project, StringBuffer message ) + throws MojoExecutionException + { + Model pom = project.getModel(); + + StringWriter sWriter = new StringWriter(); + + MavenXpp3Writer pomWriter = new MavenXpp3Writer(); + + try + { + pomWriter.write( sWriter, pom ); + + message.append( "\n************************************************************************************" ); + message.append( "\nEffective POM for project \'" + project.getId() + "\'" ); + message.append( "\n************************************************************************************" ); + message.append( "\n" ); + message.append( sWriter.toString() ); + message.append( "\n************************************************************************************" ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot serialize POM to XML.", e ); + } + + } + + protected final void setOutput( File output ) + { + this.output = output; + } + + protected final void setProjects( List projects ) + { + this.projects = projects; + } + +} diff --git a/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java new file mode 100644 index 0000000..adeb2bf --- /dev/null +++ b/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -0,0 +1,133 @@ +package org.apache.maven.plugins.help; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.settings.Settings; +import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; + +/** Print out the calculated settings for this project, given any profile enhancement and + * the inheritance of the global settings into the user-level settings. + * + * @goal effective-settings + * @requiresProject false + */ +public class EffectiveSettingsMojo + extends AbstractMojo +{ + + /** + * The system settings for Maven. This is the instance resulting from + * merging global- and user-level settings files. + * + * @parameter expression="${settings}" + * @readonly + * @required + */ + private Settings settings; + + /** + * If specified write the effective settings file out to this path. + * + * @parameter expression="${output}" + */ + private String output; + + public void execute() + throws MojoExecutionException + { + StringWriter sWriter = new StringWriter(); + + SettingsXpp3Writer settingsWriter = new SettingsXpp3Writer(); + + try + { + settingsWriter.write( sWriter, settings ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot serialize Settings to XML.", e ); + } + + if ( output != null && output.trim().length() > 0 ) + { + FileWriter fWriter = null; + try + { + File outFile = new File( output ).getAbsoluteFile(); + + File dir = outFile.getParentFile(); + + if ( !dir.exists() ) + { + dir.mkdirs(); + } + + getLog().info( "Writing effective-settings to: " + outFile ); + + fWriter = new FileWriter( outFile ); + + fWriter.write( sWriter.toString() ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot write effective-settings to output: " + output, e ); + } + finally + { + if ( fWriter != null ) + { + try + { + fWriter.close(); + } + catch ( IOException e ) + { + getLog().debug( "Cannot close FileWriter to output location: " + output, e ); + } + } + } + } + else + { + StringBuffer message = new StringBuffer(); + + message.append( "\nEffective settings:\n\n" ); + message.append( sWriter.toString() ); + message.append( "\n\n" ); + + getLog().info( message ); + } + } + + public final void setOutput( String output ) + { + this.output = output; + } + + public final void setSettings( Settings settings ) + { + this.settings = settings; + } + +} diff --git a/maven-help-plugin/src/site/apt/active-profiles-mojo.apt b/maven-help-plugin/src/site/apt/active-profiles-mojo.apt new file mode 100644 index 0000000..75d15be --- /dev/null +++ b/maven-help-plugin/src/site/apt/active-profiles-mojo.apt @@ -0,0 +1,27 @@ + --- + Maven Help Plugin :: Active Profiles Mojo + --- + John Casey + --- + 12-October-2005 + --- + +Active Profiles Mojo + +*Summary + + The <<<active-profiles>>> mojo is used to discover which profiles have been + applied to the projects currently being built. For each project in the build + session, it will output a list of profiles which have been applied to that + project, along with the source of the profile (POM, settings.xml, or profiles.xml). + + Optionally, the output parameter can be specified to divert this output to a + file. + +*Configurable Parameters + +*---------------+----------------------------+--------------+-------------------+--------------+ +| <<Parameter>> | <<Description>> | <<Type>> | <<Default Value>> | <<Required>> | +*---------------+----------------------------+--------------+-------------------+--------------+ +| output | Write output to this path. | java.io.File | <<(none)>> | No | +*---------------+----------------------------+--------------+-------------------+--------------+ diff --git a/maven-help-plugin/src/site/apt/describe-mojo.apt b/maven-help-plugin/src/site/apt/describe-mojo.apt new file mode 100644 index 0000000..1af7688 --- /dev/null +++ b/maven-help-plugin/src/site/apt/describe-mojo.apt @@ -0,0 +1,93 @@ + --- + Maven Project Help Plugin :: Describe Mojo + --- + John Casey + --- + 12-October-2005 + --- + +Describe Mojo + +*Summary + + The <<<describe>>> mojo is used to discover information about Maven plugins. + Given a plugin prefix or groupId, artifactId, and optionally version, the mojo + will lookup that plugin and output details about it. If the user also specifies + which mojo to describe, the <<describe>> mojo will limit output to the details + of that mojo, including parameters. + + Optionally, the output parameter can be specified to divert this output to a + file. + +*Configurable Parameters + +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| <<Parameter>> | <<Description>> | <<Type>> | <<Default Value>> | <<Required>> | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| plugin | One-liner substitute for groupId/artifactId/version, or prefix | String | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| groupId | The plugin groupId to lookup | String | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| artifactId | The plugin artifactId to lookup | String | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| version | The plugin version to lookup | String | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| mojo | The specific mojo to describe, rather than the whole plugin | String | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| output | A path for description output, instead of the console | java.io.File | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ +| full | If false, provide a brief description. Otherwise, detail all | boolean | <<(none)>> | No | +*---------------+----------------------------------------------------------------+--------------+-------------------+--------------+ + +*Note on <<<-Dplugin=...>>> + + This parameter is meant to provide two things: convenience and prefix-based access. + + The convenience comes when specifying a plugin by groupId:artifactId, or by + groupId:artifactId:version. Where the more traditional specification of separate + fields would mean specifying this: + ++---+ + -DgroupId=org.somewhere -DartifactId=some-plugin -Dversion=0.0.0 ++---+ + + the use of the plugin parameter allows this: + ++---+ + -Dplugin=org.somewhere:some-plugin:0.0.0 ++---+ + + (NOTE: version is always optional here.) + + On the other hand, the plugin parameter also offers the option to specify a + plugin by its prefix, like this: + ++---+ + -Dplugin=help ++---+ + +*Examples + + [[1]] To display a brief summary of the entire help plugin, using the + prefix for plugin lookup: + ++---+ + mvn help:describe -Dplugin=help ++---+ + + [[2]] To display a full summary of only the describe mojo, again using the + prefix to lookup the plugin: + ++---+ + mvn help:describe -Dplugin=help -Dmojo=describe -Dfull=true ++---+ + + [[3]] To display the most information available for the entire help + plugin, and avoid any confusion about which plugin might be resolved + for a particular prefix: + ++---+ + mvn help:describe -Dfull=true \ + -DgroupId=org.apache.maven.plugins \ + -DartifactId=maven-help-plugin ++---+ diff --git a/maven-help-plugin/src/site/apt/effective-pom-mojo.apt b/maven-help-plugin/src/site/apt/effective-pom-mojo.apt new file mode 100644 index 0000000..5f4e3c2 --- /dev/null +++ b/maven-help-plugin/src/site/apt/effective-pom-mojo.apt @@ -0,0 +1,28 @@ + --- + Maven Help Plugin :: Effective POM Mojo + --- + John Casey + --- + 12-October-2005 + --- + +Effective POM Mojo + +*Summary + + The <<<effective-pom>>> mojo is used to make visible the POM that results from + the application of interpolation, inheritance, and active profiles. It provides + a useful way of removing the guesswork about just what ends up in the POM that + Maven uses to build your project. It will iterate over all projects in the current + build session, printing the effective POM for each. + + Optionally, the output parameter can be specified to divert this output to a + file. + +*Configurable Parameters + +*---------------+----------------------------+--------------+-------------------+--------------+ +| <<Parameter>> | <<Description>> | <<Type>> | <<Default Value>> | <<Required>> | +*---------------+----------------------------+--------------+-------------------+--------------+ +| output | Write output to this path. | java.io.File | <<(none)>> | No | +*---------------+----------------------------+--------------+-------------------+--------------+ diff --git a/maven-help-plugin/src/site/apt/effective-settings-mojo.apt b/maven-help-plugin/src/site/apt/effective-settings-mojo.apt new file mode 100644 index 0000000..d63c6c1 --- /dev/null +++ b/maven-help-plugin/src/site/apt/effective-settings-mojo.apt @@ -0,0 +1,26 @@ + --- + Maven Help Plugin :: Effective Settings Mojo + --- + John Casey + --- + 12-October-2005 + --- + +Effective Settings Mojo + +*Summary + + The <<<effective-settings>>> mojo is used to view the Settings that Maven + actually uses to run the build. This Settings instance is a result of merging + the global file with the user's file, with the user's file taking precedence. + + Optionally, the output parameter can be specified to divert this output to a + file. + +*Configurable Parameters + +*---------------+----------------------------+--------------+-------------------+--------------+ +| <<Parameter>> | <<Description>> | <<Type>> | <<Default Value>> | <<Required>> | +*---------------+----------------------------+--------------+-------------------+--------------+ +| output | Write output to this path. | java.io.File | <<(none)>> | No | +*---------------+----------------------------+--------------+-------------------+--------------+ diff --git a/maven-help-plugin/src/site/site.xml b/maven-help-plugin/src/site/site.xml new file mode 100644 index 0000000..e58efad --- /dev/null +++ b/maven-help-plugin/src/site/site.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<!-- +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +--> + +<project name="Maven Help Plugin"> + <bannerLeft> + <name>Maven Help</name> + <src>http://maven.apache.org/images/apache-maven-project.png</src> + <href>http://maven.apache.org/</href> + </bannerLeft> + <bannerRight> + <src>http://maven.apache.org/images/maven-small.gif</src> + </bannerRight> + <body> + <links> + <item name="Maven 2" href="http://maven.apache.org/maven2/"/> + </links> + + <menu name="Goals"> + <item name="active-profiles" href="/active-profiles-mojo.html"/> + <item name="describe" href="/describe-mojo.html"/> + <item name="effective-pom" href="/effective-pom-mojo.html"/> + <item name="effective-settings" href="/effective-settings-mojo.html"/> + </menu> + ${reports} + </body> +</project> -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.