From d041ecb851070172815e85efbd7d044ec6be53b0 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 29 Oct 2007 01:57:40 +0000 Subject: [PATCH] move the plugin-plugin to the plugin-tools module git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@589471 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 175 +++++++++++ .../plugin/plugin/AbstractGeneratorMojo.java | 156 ++++++++++ .../plugin/DescriptorGeneratorMojo.java | 57 ++++ .../maven/plugin/plugin/PluginReport.java | 278 ++++++++++++++++++ .../plugin/UpdatePluginRegistryMojo.java | 205 +++++++++++++ .../plugin/plugin/XdocGeneratorMojo.java | 54 ++++ .../AddPluginArtifactMetadataMojo.java | 85 ++++++ .../main/resources/plugin-report.properties | 27 ++ .../resources/plugin-report_fr.properties | 27 ++ .../site/apt/examples/generate-descriptor.apt | 52 ++++ maven-plugin-plugin/src/site/apt/index.apt | 61 ++++ .../site/apt/multiple-language-support.apt | 50 ++++ maven-plugin-plugin/src/site/apt/usage.apt | 90 ++++++ maven-plugin-plugin/src/site/fml/faq.fml | 34 +++ maven-plugin-plugin/src/site/site.xml | 41 +++ 15 files changed, 1392 insertions(+) create mode 100644 maven-plugin-plugin/pom.xml create mode 100644 maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java create mode 100644 maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java create mode 100644 maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java create mode 100644 maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/UpdatePluginRegistryMojo.java create mode 100644 maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/XdocGeneratorMojo.java create mode 100644 maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java create mode 100644 maven-plugin-plugin/src/main/resources/plugin-report.properties create mode 100644 maven-plugin-plugin/src/main/resources/plugin-report_fr.properties create mode 100644 maven-plugin-plugin/src/site/apt/examples/generate-descriptor.apt create mode 100644 maven-plugin-plugin/src/site/apt/index.apt create mode 100644 maven-plugin-plugin/src/site/apt/multiple-language-support.apt create mode 100644 maven-plugin-plugin/src/site/apt/usage.apt create mode 100644 maven-plugin-plugin/src/site/fml/faq.fml create mode 100644 maven-plugin-plugin/src/site/site.xml diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml new file mode 100644 index 0000000..b7d47a1 --- /dev/null +++ b/maven-plugin-plugin/pom.xml @@ -0,0 +1,175 @@ + + + + + org.apache.maven.plugintools + maven-plugin-tools + 2.4-SNAPSHOT + + 4.0.0 + org.apache.maven.plugins + maven-plugin-plugin + maven-plugin + Maven PLUGIN Plugin + + The Plugin Plugin is used to create a Maven plugin descriptor for any Mojo's found in the source tree, + to include in the JAR. It is also used to generate Xdoc files for the Mojos as well as for updating the + plugin registry and the artifact metadata. + + 2001 + + 2.0.6 + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven + maven-repository-metadata + 2.0 + + + org.apache.maven + maven-project + 2.0 + + + org.apache.maven + maven-plugin-descriptor + 2.0 + + + org.apache.maven + maven-plugin-registry + 2.0 + + + org.apache.maven + maven-plugin-tools-api + 2.1 + + + org.apache.maven + maven-plugin-tools-java + 2.1 + runtime + + + org.apache.maven + maven-artifact-manager + 2.0 + + + org.apache.maven + maven-artifact + 2.0 + + + org.apache.maven + maven-plugin-tools-beanshell + 2.1 + runtime + + + org.apache.maven.reporting + maven-reporting-impl + 2.0.4 + + + org.apache.maven.reporting + maven-reporting-api + 2.0.4 + + + + + org.apache.maven.doxia + doxia-sink-api + ${doxia.version} + + + org.apache.maven.doxia + doxia-core + ${doxia.version} + + + org.apache.maven.doxia + doxia-site-renderer + ${doxia-sitetools.version} + + + org.codehaus.plexus + plexus-container-default + + + org.codehaus.plexus + plexus-component-api + + + + + + + org.codehaus.plexus + plexus-utils + 1.4.5 + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9 + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 2.3 + + + + + + 1.0-alpha-10-SNAPSHOT + 1.0-alpha-10-SNAPSHOT + + + + apache.website + scp://people.apache.org/www/maven.apache.org/plugins/maven-plugin-plugin + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + + + diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java new file mode 100644 index 0000000..2f219b7 --- /dev/null +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java @@ -0,0 +1,156 @@ +package org.apache.maven.plugin.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.plugin.descriptor.InvalidPluginDescriptorException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; +import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.apache.maven.tools.plugin.generator.Generator; +import org.apache.maven.tools.plugin.scanner.MojoScanner; +import org.apache.maven.tools.plugin.util.PluginUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Set; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public abstract class AbstractGeneratorMojo + extends AbstractMojo +{ + /** + * The project currently being built. + * + * @parameter expression="${project}" + * @required + */ + protected MavenProject project; + + /** + * The component used for scanning the source tree for mojos. + * + * @parameter expression="${component.org.apache.maven.tools.plugin.scanner.MojoScanner}" + * @required + */ + protected MojoScanner mojoScanner; + + /** + * The goal prefix that will appear before the ":". + * + * @parameter + */ + protected String goalPrefix; + + /** + * The names of extractors to use. + *

+ * If not set, all extractors will be used. If set to an empty extractor name, no extractors + * will be used. + *

+ * Example: + *

+ *

+     *  <!-- Use all extractors -->
+     *  <extractors/>
+     *  <!-- Use no extractors -->
+     *  <extractors>
+     *      <extractor/>
+     *  </extractors>
+     *  <!-- Use only bsh extractor -->
+     *  <extractors>
+     *      <extractor>bsh</extractor>
+     *  </extractors>
+     * 
+ * + * @parameter + */ + protected Set/* */extractors; + + protected abstract File getOutputDirectory(); + + protected abstract Generator createGenerator(); + + public void execute() + throws MojoExecutionException + { + if ( !project.getPackaging().equals( "maven-plugin" ) ) + { + return; + } + + String defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ); + if ( goalPrefix == null ) + { + goalPrefix = defaultGoalPrefix; + } + else + { + getLog().warn( + "Goal prefix is: " + goalPrefix + "; Maven currently expects it to be " + defaultGoalPrefix ); + } + + mojoScanner.setActiveExtractors( extractors ); + + // TODO: could use this more, eg in the writing of the plugin descriptor! + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + + pluginDescriptor.setGroupId( project.getGroupId() ); + + pluginDescriptor.setArtifactId( project.getArtifactId() ); + + pluginDescriptor.setVersion( project.getVersion() ); + + pluginDescriptor.setGoalPrefix( goalPrefix ); + + pluginDescriptor.setName( project.getName() ); + + pluginDescriptor.setDescription( project.getDescription() ); + + try + { + pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) ); + + mojoScanner.populatePluginDescriptor( project, pluginDescriptor ); + + getOutputDirectory().mkdirs(); + + createGenerator().execute( getOutputDirectory(), pluginDescriptor ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error writing plugin descriptor", e ); + } + catch ( InvalidPluginDescriptorException e ) + { + throw new MojoExecutionException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", + e ); + } + catch ( ExtractionException e ) + { + throw new MojoExecutionException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", + e ); + } + } +} diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java new file mode 100644 index 0000000..82ed107 --- /dev/null +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java @@ -0,0 +1,57 @@ +package org.apache.maven.plugin.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.tools.plugin.generator.Generator; +import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator; + +import java.io.File; + +/** + * Generate a plugin descriptor. + *

+ * Note: Phase is after the "compilation" of any scripts + * + * @author Jason van Zyl + * @version $Id$ + * @goal descriptor + * @phase generate-resources + */ +public class DescriptorGeneratorMojo + extends AbstractGeneratorMojo +{ + /** + * The directory where the generated plugin.xml file will be put. + * + * @parameter expression="${project.build.outputDirectory}/META-INF/maven" + * @required + */ + protected File outputDirectory; + + protected File getOutputDirectory() + { + return outputDirectory; + } + + protected Generator createGenerator() + { + return new PluginDescriptorGenerator(); + } +} diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java new file mode 100644 index 0000000..ed1385a --- /dev/null +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java @@ -0,0 +1,278 @@ +package org.apache.maven.plugin.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.doxia.sink.Sink; +import org.apache.maven.doxia.siterenderer.Renderer; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; +import org.apache.maven.reporting.AbstractMavenReport; +import org.apache.maven.reporting.AbstractMavenReportRenderer; +import org.apache.maven.reporting.MavenReportException; +import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.apache.maven.tools.plugin.generator.Generator; +import org.apache.maven.tools.plugin.generator.PluginXdocGenerator; +import org.apache.maven.tools.plugin.scanner.MojoScanner; +import org.apache.maven.tools.plugin.util.PluginUtils; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Generates the Plugin's documentation report. + * + * @author Stephane Nicoll + * @author Vincent Siveton + * @version $Id $ + * @goal report + */ +public class PluginReport + extends AbstractMavenReport +{ + /** + * Report output directory. + * + * @parameter expression="${project.build.directory}/generated-site/xdoc" + * @required + */ + private String outputDirectory; + + /** + * Doxia Site Renderer. + * + * @component + */ + private Renderer siteRenderer; + + /** + * The Maven Project. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * Mojo scanner tools. + * + * @component + */ + protected MojoScanner mojoScanner; + + /** + * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() + */ + protected Renderer getSiteRenderer() + { + return siteRenderer; + } + + /** + * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() + */ + protected String getOutputDirectory() + { + return outputDirectory; + } + + /** + * @see org.apache.maven.reporting.AbstractMavenReport#getProject() + */ + protected MavenProject getProject() + { + return project; + } + + /** + * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale) + */ + protected void executeReport( Locale locale ) + throws MavenReportException + { + if ( !project.getPackaging().equals( "maven-plugin" ) ) + { + return; + } + + String goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ); + + // TODO: could use this more, eg in the writing of the plugin descriptor! + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + + pluginDescriptor.setGroupId( project.getGroupId() ); + + pluginDescriptor.setArtifactId( project.getArtifactId() ); + + pluginDescriptor.setVersion( project.getVersion() ); + + pluginDescriptor.setGoalPrefix( goalPrefix ); + + try + { + pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) ); + + mojoScanner.populatePluginDescriptor( project, pluginDescriptor ); + + // Generate the plugin's documentation + generatePluginDocumentation( pluginDescriptor ); + + // Write the overview + PluginOverviewRenderer r = new PluginOverviewRenderer( getSink(), pluginDescriptor, locale ); + r.render(); + } + catch ( InvalidPluginDescriptorException e ) + { + throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", + e ); + } + catch ( ExtractionException e ) + { + throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", + e ); + } + } + + /** + * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) + */ + public String getDescription( Locale locale ) + { + return getBundle( locale ).getString( "report.plugin.description" ); + } + + /** + * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) + */ + public String getName( Locale locale ) + { + return getBundle( locale ).getString( "report.plugin.name" ); + } + + /** + * @see org.apache.maven.reporting.MavenReport#getOutputName() + */ + public String getOutputName() + { + return "plugin-info"; + } + + private void generatePluginDocumentation( PluginDescriptor pluginDescriptor ) + throws MavenReportException + { + try + { + File outputDir = new File( getOutputDirectory() ); + outputDir.mkdirs(); + + Generator generator = new PluginXdocGenerator(); + generator.execute( outputDir, pluginDescriptor ); + } + catch ( IOException e ) + { + throw new MavenReportException( "Error writing plugin documentation", e ); + } + + } + + private static ResourceBundle getBundle( Locale locale ) + { + return ResourceBundle.getBundle( "plugin-report", locale, PluginReport.class.getClassLoader() ); + } + + /** + * Generates an overview page with the list of goals + * and a link to the goal's page. + */ + static class PluginOverviewRenderer + extends AbstractMavenReportRenderer + { + private final PluginDescriptor pluginDescriptor; + + private final Locale locale; + + public PluginOverviewRenderer( Sink sink, PluginDescriptor pluginDescriptor, Locale locale ) + { + super( sink ); + + this.pluginDescriptor = pluginDescriptor; + + this.locale = locale; + } + + /** + * @see org.apache.maven.reporting.MavenReportRenderer#getTitle() + */ + public String getTitle() + { + return getBundle( locale ).getString( "report.plugin.title" ); + } + + /** + * @see org.apache.maven.reporting.AbstractMavenReportRenderer#renderBody() + */ + public void renderBody() + { + startSection( getTitle() ); + + paragraph( getBundle( locale ).getString( "report.plugin.goals.intro" ) ); + + startTable(); + + String goalColumnName = getBundle( locale ).getString( "report.plugin.goals.column.goal" ); + String descriptionColumnName = getBundle( locale ).getString( "report.plugin.goals.column.description" ); + + tableHeader( new String[]{goalColumnName, descriptionColumnName} ); + + for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) + { + MojoDescriptor mojo = (MojoDescriptor) i.next(); + + String goalName = mojo.getFullGoalName(); + /* + * Added ./ to define a relative path + * @see AbstractMavenReportRenderer#getValidHref(java.lang.String) + */ + String goalDocumentationLink = "./" + mojo.getGoal() + "-mojo.html"; + String description = mojo.getDescription(); + if ( StringUtils.isEmpty( mojo.getDescription() ) ) + { + description = getBundle( locale ).getString( "report.plugin.goal.nodescription" ); + + } + + sink.tableRow(); + tableCell( createLinkPatternedText( goalName, goalDocumentationLink ) ); + tableCell( description, true ); + sink.tableRow_(); + } + + endTable(); + + endSection(); + } + } +} diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/UpdatePluginRegistryMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/UpdatePluginRegistryMojo.java new file mode 100644 index 0000000..6c09efd --- /dev/null +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/UpdatePluginRegistryMojo.java @@ -0,0 +1,205 @@ +package org.apache.maven.plugin.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.ArtifactUtils; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.registry.MavenPluginRegistryBuilder; +import org.apache.maven.plugin.registry.Plugin; +import org.apache.maven.plugin.registry.PluginRegistry; +import org.apache.maven.plugin.registry.PluginRegistryUtils; +import org.apache.maven.plugin.registry.io.xpp3.PluginRegistryXpp3Writer; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Update the user plugin registry (if it's in use) to reflect the version we're installing. + * + * @goal updateRegistry + * @phase install + */ +public class UpdatePluginRegistryMojo + extends AbstractMojo +{ + + /** + * Indicates whether the plugin-registry.xml is used by Maven or not + * to manage plugin versions. + * + * @parameter default-value="${settings.usePluginRegistry}" + * @required + * @readonly + */ + private boolean usePluginRegistry; + + /** + * The group id of the project currently being built. + * + * @parameter default-value="${project.groupId}" + * @required + * @readonly + */ + private String groupId; + + /** + * The artifact id of the project currently being built. + * + * @parameter default-value="${project.artifactId}" + * @required + * @readonly + */ + private String artifactId; + + /** + * The version of the project currently being built. + * + * @parameter default-value="${project.artifact.version}" + * @required + * @readonly + */ + private String version; + + /** + * Plexus component for retrieving the plugin registry info. + * + * @component role="org.apache.maven.plugin.registry.MavenPluginRegistryBuilder" + */ + private MavenPluginRegistryBuilder pluginRegistryBuilder; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( usePluginRegistry ) + { + updatePluginVersionInRegistry( groupId, artifactId, version ); + } + } + + private void updatePluginVersionInRegistry( String groupId, String artifactId, String version ) + throws MojoExecutionException + { + PluginRegistry pluginRegistry; + try + { + pluginRegistry = getPluginRegistry( groupId, artifactId ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Failed to read plugin registry.", e ); + } + catch ( XmlPullParserException e ) + { + throw new MojoExecutionException( "Failed to parse plugin registry.", e ); + } + + String pluginKey = ArtifactUtils.versionlessKey( groupId, artifactId ); + Plugin plugin = (Plugin) pluginRegistry.getPluginsByKey().get( pluginKey ); + + // if we can find the plugin, but we've gotten here, the useVersion must be missing; fill it in. + if ( plugin != null ) + { + if ( PluginRegistry.GLOBAL_LEVEL.equals( plugin.getSourceLevel() ) ) + { + // do nothing. We don't rewrite the globals, under any circumstances. + getLog().warn( "Cannot update registered version for plugin {" + groupId + ":" + artifactId + + "}; it is specified in the global registry." ); + } + else + { + plugin.setUseVersion( version ); + + SimpleDateFormat format = + new SimpleDateFormat( org.apache.maven.plugin.registry.Plugin.LAST_CHECKED_DATE_FORMAT ); + + plugin.setLastChecked( format.format( new Date() ) ); + } + } + else + { + plugin = new org.apache.maven.plugin.registry.Plugin(); + + plugin.setGroupId( groupId ); + plugin.setArtifactId( artifactId ); + plugin.setUseVersion( version ); + + pluginRegistry.addPlugin( plugin ); + + pluginRegistry.flushPluginsByKey(); + } + + writeUserRegistry( groupId, artifactId, pluginRegistry ); + } + + private void writeUserRegistry( String groupId, String artifactId, PluginRegistry pluginRegistry ) + { + File pluginRegistryFile = pluginRegistry.getRuntimeInfo().getFile(); + + PluginRegistry extractedUserRegistry = PluginRegistryUtils.extractUserPluginRegistry( pluginRegistry ); + + // only rewrite the user-level registry if one existed before, or if we've created user-level data here. + if ( extractedUserRegistry != null ) + { + FileWriter fWriter = null; + + try + { + pluginRegistryFile.getParentFile().mkdirs(); + fWriter = new FileWriter( pluginRegistryFile ); + + PluginRegistryXpp3Writer writer = new PluginRegistryXpp3Writer(); + + writer.write( fWriter, extractedUserRegistry ); + } + catch ( IOException e ) + { + getLog().warn( "Cannot rewrite user-level plugin-registry.xml with new plugin version of plugin: \'" + + groupId + ":" + artifactId + "\'.", e ); + } + finally + { + IOUtil.close( fWriter ); + } + } + } + + private PluginRegistry getPluginRegistry( String groupId, String artifactId ) + throws IOException, XmlPullParserException + { + PluginRegistry pluginRegistry = null; + + pluginRegistry = pluginRegistryBuilder.buildPluginRegistry(); + + if ( pluginRegistry == null ) + { + pluginRegistry = pluginRegistryBuilder.createUserPluginRegistry(); + } + + return pluginRegistry; + } + +} diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/XdocGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/XdocGeneratorMojo.java new file mode 100644 index 0000000..24ac1cc --- /dev/null +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/XdocGeneratorMojo.java @@ -0,0 +1,54 @@ +package org.apache.maven.plugin.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.tools.plugin.generator.Generator; +import org.apache.maven.tools.plugin.generator.PluginXdocGenerator; + +import java.io.File; + +/** + * Generate Xdoc files for the project mojos or goals + * + * @author Brett Porter + * @version $Id$ + * @goal xdoc + */ +public class XdocGeneratorMojo + extends AbstractGeneratorMojo +{ + /** + * The directory where the generated Xdoc files will be put. + * + * @parameter expression="${project.build.directory}/generated-site/xdoc" + * @required + */ + protected File outputDirectory; + + protected File getOutputDirectory() + { + return outputDirectory; + } + + protected Generator createGenerator() + { + return new PluginXdocGenerator(); + } +} diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java new file mode 100644 index 0000000..85fb061 --- /dev/null +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java @@ -0,0 +1,85 @@ +package org.apache.maven.plugin.plugin.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.Artifact; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; + +/** + * Inject any plugin-specific artifact metadata to the project's artifact, for subsequent installation + * and deployment. The first use-case for this is to add the LATEST metadata (which is plugin-specific) + * for shipping alongside the plugin's artifact. + * + * @phase package + * @goal addPluginArtifactMetadata + */ +public class AddPluginArtifactMetadataMojo + extends AbstractMojo +{ + + /** + * The project artifact, which should have the LATEST metadata added to it. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * The prefix for the plugin goal. + * + * @parameter + */ + private String goalPrefix; + + public void execute() + throws MojoExecutionException + { + Artifact projectArtifact = project.getArtifact(); + + Versioning versioning = new Versioning(); + versioning.setLatest( projectArtifact.getVersion() ); + versioning.updateTimestamp(); + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( projectArtifact, versioning ); + projectArtifact.addMetadata( metadata ); + + GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata( project.getGroupId() ); + groupMetadata.addPluginMapping( getGoalPrefix(), project.getArtifactId(), project.getName() ); + + projectArtifact.addMetadata( groupMetadata ); + } + + private String getGoalPrefix() + { + if ( goalPrefix == null ) + { + goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ); + } + + return goalPrefix; + } +} diff --git a/maven-plugin-plugin/src/main/resources/plugin-report.properties b/maven-plugin-plugin/src/main/resources/plugin-report.properties new file mode 100644 index 0000000..fda6135 --- /dev/null +++ b/maven-plugin-plugin/src/main/resources/plugin-report.properties @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +report.plugin.name=Plugin documentation +report.plugin.description=This report provides goals and parameters documentation of a plugin +report.plugin.title=Plugin documentation + +report.plugin.goals.intro=Goals available: +report.plugin.goals.column.goal=Goal +report.plugin.goals.column.description=Description +report.plugin.goal.nodescription=No description \ No newline at end of file diff --git a/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties b/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties new file mode 100644 index 0000000..83987f7 --- /dev/null +++ b/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +report.plugin.name=Documentation du plugin +report.plugin.description=Ce rapport fournit de la documenations sur les goals et les paramètres d'un plugin +report.plugin.title=Documentation du plugin + +report.plugin.goals.intro=Goals disponibles : +report.plugin.goals.column.goal=Goal +report.plugin.goals.column.description=Description +report.plugin.goal.nodescription=Pas de description \ No newline at end of file diff --git a/maven-plugin-plugin/src/site/apt/examples/generate-descriptor.apt b/maven-plugin-plugin/src/site/apt/examples/generate-descriptor.apt new file mode 100644 index 0000000..c1c8451 --- /dev/null +++ b/maven-plugin-plugin/src/site/apt/examples/generate-descriptor.apt @@ -0,0 +1,52 @@ + ------ + Configuring Generation of Plugin Descriptor + ------ + Maria Odea Ching + ------ + July 2006 + ------ + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you 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. + +Configuring Generation of Plugin Descriptor + + To configure the generation of the plugin descriptor, add the following to the project's pom: + ++-----+ + + ... + + + + org.apache.maven.plugins + maven-plugin-plugin + + plugin + ${basedir}/target/dir + + + + ... + + ... + ++-----+ + + The <<>> parameter will set the goal prefix for the plugin that is specified in the descriptor. The <<>> + parameter, on the other hand, specifies the target location of the generated plugin descriptor. + diff --git a/maven-plugin-plugin/src/site/apt/index.apt b/maven-plugin-plugin/src/site/apt/index.apt new file mode 100644 index 0000000..d665aee --- /dev/null +++ b/maven-plugin-plugin/src/site/apt/index.apt @@ -0,0 +1,61 @@ + ------ + Introduction + ------ + Maria Odea Ching + ------ + 27 July 2006 + ------ + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you 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. + +Maven 2 Plugin Plugin + + The Plugin Plugin is used to create a Maven plugin descriptor for any Mojo's found in the source tree, to include in the JAR. + It is also used to generate Xdoc files for the Mojos as well as for updating the plugin registry and the artifact metadata. + +* Goals Overview + + The Plugin Plugin has five goals: + + * {{{descriptor-mojo.html}plugin:descriptor}} generates a plugin descriptor. + + * {{{report-mojo.html}plugin:report}} generates the plugin documentation report. + + * {{{updateRegistry-mojo.html}plugin:updateRegistry}} updates the user plugin registry (if it's in use) to reflect the + version being installed. + + * {{{xdoc-mojo.html}plugin:xdoc}} generates Xdoc files for the project mojos or goals. + + * {{{addPluginArtifactMetadata-mojo.html}plugin:addPluginArtifactMetadata}} injects any plugin-specific artifact metadata to the project's + artifact, for subsequent installation and deployment. The first use-case for this is to add the LATEST metadata + (which is plugin-specific) for shipping alongside the plugin's artifact. + +* Usage + + Instructions on how to use the Plugin Plugin can be found {{{usage.html}here}}. + +* Examples + + The following example shows how to use the Plugin Plugin in more advanced usecases: + + * {{{examples/generate-descriptor.html}Configuring Generation of Plugin Descriptor}} + + + + + diff --git a/maven-plugin-plugin/src/site/apt/multiple-language-support.apt b/maven-plugin-plugin/src/site/apt/multiple-language-support.apt new file mode 100644 index 0000000..1098898 --- /dev/null +++ b/maven-plugin-plugin/src/site/apt/multiple-language-support.apt @@ -0,0 +1,50 @@ + --- + Multiple Language Support for the Plugin Plugin: Redesign Notes + --- + John Casey + --- + 09-Feb-2005 + --- + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you 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. + +<> + +*Abstract + + The Plugin plugin needs to be refactored in order to support multiple mojo + implementation languages. This document will detail the steps needed to + add this functionality. + +*Current Status + + The plugin plugin currently calls out to a set of generators in the + maven-plugin-tools library, which in turn uses qdox to generate various things + based on annotations in the java source code. + +*Refactored Design + + The new design will have a generator-manager which is a component that the + plugin mojos will lookup. This component will have access to a mapping of all + generators and the language they're registered for. It'll iterate through the + mappings, and extract mojo descriptors from all relevant scripts/sources using + each language's registered generator. Results from each generator will be + centrally aggregated by the generator-manager. After all generators have run, + the generator-manager will call another class (depending on what it's meant to + produce) to take all the aggregated mojo descriptors and produce a result + (such as plugin.xml file for the project). \ No newline at end of file diff --git a/maven-plugin-plugin/src/site/apt/usage.apt b/maven-plugin-plugin/src/site/apt/usage.apt new file mode 100644 index 0000000..f9d899d --- /dev/null +++ b/maven-plugin-plugin/src/site/apt/usage.apt @@ -0,0 +1,90 @@ + ------ + Usage + ------ + Maria Odea Ching + ------ + 27 July 2006 + ------ + +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you 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. + +Usage + + The Plugin Plugin is generally used for Maven 2 plugins. Its mojos are bound to different phases in the build life cycle. + So when you execute a specific phase, the Plugin Plugin mojos bound to it are also executed. Aside from this, each goal can + also be explicitly executed from the command line. + +* The <<>> Goal + + The <<>> goal is bound to the <<>> phase. This goal generates the plugin descriptor, which + is an xml file that contains information about the plugin. + + For example, you want to create an archive of your plugin and you execute + ++-----+ +mvn package ++-----+ + + You will see that the plugin.xml file is generated in the target/classes/META-INF/maven directory of your project. The file is + also bundled in the generated jar file. + + To explicitly execute the <<>> goal, type the following in the command line: + ++-----+ +mvn plugin:descriptor ++-----+ + +* The <<>> Goal + + To generate Xdoc files for the mojos of your plugin, execute the following on the command line: + ++-----+ +mvn plugin:xdoc ++-----+ + +* The <<>> Goal + + The <<>> goal is bound to the <<>> phase of the build life cycle. This goal updates the + plugin registry to reflect the changes in the version of the plugin you're installing in your local repository. + + So when you execute + ++-----+ +mvn install ++-----+ + + you will see that the version of the plugin in the plugin-registry.xml is changed to the same version of the plugin + that you have just installed. + + You can also explicitly execute the <<>> goal by executing + ++-----+ +mvn plugin:updateRegistry ++-----+ + + from the command line. + +* The <<>> Goal + + The <<>> goal, on the other hand, is bound to the <<>> phase of the build life cycle. + This goal will add the metadata to the project artifact. To do this, execute + ++-----+ +mvn package ++-----+ + diff --git a/maven-plugin-plugin/src/site/fml/faq.fml b/maven-plugin-plugin/src/site/fml/faq.fml new file mode 100644 index 0000000..10303fb --- /dev/null +++ b/maven-plugin-plugin/src/site/fml/faq.fml @@ -0,0 +1,34 @@ + + + + + + + + Where is the plugin-registry.xml? + +

+ The plugin-registry.xml file can be found in the M2 repository, inside the .m2 directory. It contains the + list of the plugins installed in your repository including the last version installed. +

+ + + + \ No newline at end of file diff --git a/maven-plugin-plugin/src/site/site.xml b/maven-plugin-plugin/src/site/site.xml new file mode 100644 index 0000000..226ebeb --- /dev/null +++ b/maven-plugin-plugin/src/site/site.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + +