You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/04/23 09:04:35 UTC
[maven-plugin-tools] 01/05: [MPLUGIN-360] generated plugin-help.xml
ignores descriptor mojo outputDirectory
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch dependencies
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git
commit 7230d58388878f6735fb25f2463ef4c5ebe7f855
Author: rfscholte <rf...@apache.org>
AuthorDate: Tue Apr 20 19:42:21 2021 +0200
[MPLUGIN-360] generated plugin-help.xml ignores descriptor mojo outputDirectory
---
.../plugin/plugin/DescriptorGeneratorMojo.java | 2 +-
.../generator/PluginDescriptorGenerator.java | 25 ++++++----------------
.../plugin/generator/PluginHelpGenerator.java | 2 +-
.../src/main/resources/help-class-source.vm | 4 ++--
4 files changed, 10 insertions(+), 23 deletions(-)
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
index a0bcf5c..8b141c4 100644
--- 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
@@ -50,7 +50,7 @@ public class DescriptorGeneratorMojo
/**
* The directory where the generated <code>plugin.xml</code> file will be put.
*/
- @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven" )
+ @Parameter( defaultValue = "${project.build.outputDirectory}/META-INF/maven", readonly = true )
protected File outputDirectory;
/**
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
index 59f2b7c..a3e5162 100644
--- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
@@ -41,7 +41,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
@@ -62,9 +61,7 @@ public class PluginDescriptorGenerator
this.log = log;
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void execute( File destinationDirectory, PluginToolsRequest request )
throws GeneratorException
{
@@ -80,7 +77,7 @@ public class PluginDescriptorGenerator
// write plugin-help.xml help-descriptor
MavenProject mavenProject = request.getProject();
- f = new File( mavenProject.getBuild().getOutputDirectory(),
+ f = new File( destinationDirectory,
PluginHelpGenerator.getPluginHelpPath( mavenProject ) );
writeDescriptor( f, request, true );
@@ -111,19 +108,13 @@ public class PluginDescriptorGenerator
{
destinationFile.delete();
}
- else
+ else if ( !destinationFile.getParentFile().exists() )
{
- if ( !destinationFile.getParentFile().exists() )
- {
- destinationFile.getParentFile().mkdirs();
- }
+ destinationFile.getParentFile().mkdirs();
}
- Writer writer = null;
- try
+ try ( Writer writer = new OutputStreamWriter( new FileOutputStream( destinationFile ), UTF_8 ) )
{
- writer = new OutputStreamWriter( new FileOutputStream( destinationFile ), UTF_8 );
-
XMLWriter w = new PrettyPrintXMLWriter( writer, UTF_8.name(), null );
w.writeMarkup( "\n<!-- Generated by maven-plugin-tools " + getVersion() + " -->\n\n" );
@@ -154,7 +145,7 @@ public class PluginDescriptorGenerator
if ( pluginDescriptor.getMojos() != null )
{
- @SuppressWarnings( "unchecked" ) List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();
+ List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();
PluginUtils.sortMojos( descriptors );
@@ -176,10 +167,6 @@ public class PluginDescriptorGenerator
writer.flush();
}
- finally
- {
- IOUtil.close( writer );
- }
}
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w )
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
index 884e386..06f4e29 100644
--- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
@@ -267,7 +267,7 @@ public class PluginHelpGenerator
static String getPluginHelpPath( MavenProject mavenProject )
{
- return "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + "/plugin-help.xml";
+ return mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + "/plugin-help.xml";
}
/**
diff --git a/maven-plugin-tools-generators/src/main/resources/help-class-source.vm b/maven-plugin-tools-generators/src/main/resources/help-class-source.vm
index 178a242..7dd7209 100644
--- a/maven-plugin-tools-generators/src/main/resources/help-class-source.vm
+++ b/maven-plugin-tools-generators/src/main/resources/help-class-source.vm
@@ -103,9 +103,9 @@ public class HelpMojo
#end
private int indentSize;
- // groupId/artifactId/plugin-help.xml
+ // /META-INF/maven/<groupId>/<artifactId>/plugin-help.xml
private static final String PLUGIN_HELP_PATH =
- "/${pluginHelpPath}";
+ "/META-INF/maven/${pluginHelpPath}";
private static final int DEFAULT_LINE_LENGTH = 80;