Skip to content

Commit

Permalink
[MPLUGIN-360] generated plugin-help.xml ignores descriptor mojo outpu…
Browse files Browse the repository at this point in the history
…tDirectory
  • Loading branch information
rfscholte committed Apr 20, 2021
1 parent 2f29e9a commit e477e6c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
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;
Expand All @@ -62,9 +61,7 @@ public PluginDescriptorGenerator( Log log )
this.log = log;
}

/**
* {@inheritDoc}
*/
@Override
public void execute( File destinationDirectory, PluginToolsRequest request )
throws GeneratorException
{
Expand All @@ -80,7 +77,7 @@ public void execute( File destinationDirectory, PluginToolsRequest request )
// 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 );
Expand Down Expand Up @@ -111,19 +108,13 @@ public void writeDescriptor( File destinationFile, PluginToolsRequest request, b
{
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" );
Expand Down Expand Up @@ -154,7 +145,7 @@ public void writeDescriptor( File destinationFile, PluginToolsRequest request, b

if ( pluginDescriptor.getMojos() != null )
{
@SuppressWarnings( "unchecked" ) List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();
List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();

PluginUtils.sortMojos( descriptors );

Expand All @@ -176,10 +167,6 @@ public void writeDescriptor( File destinationFile, PluginToolsRequest request, b
writer.flush();

}
finally
{
IOUtil.close( writer );
}
}

protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ else if ( !tmpPropertiesFile.getParentFile().exists() )

static String getPluginHelpPath( MavenProject mavenProject )
{
return "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + "/plugin-help.xml";
return mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + "/plugin-help.xml";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e477e6c

Please sign in to comment.