Author: hboutemy
Date: Wed Nov 7 07:20:12 2012
New Revision: 1406480
URL: http://svn.apache.org/viewvc?rev=1406480&view=rev
Log:
[MPLUGIN-227]
o avoid NPE but get (intended-)explicit warning when unexpected situation
happens (probably caused by using different plugin version between source
generation and XML descriptor generation phases)
o try guessing the directory in such situation, using default location
o but don't fail in any case:
Modified:
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
Modified:
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java?rev=1406480&r1=1406479&r2=1406480&view=diff
==============================================================================
---
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
(original)
+++
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
Wed Nov 7 07:20:12 2012
@@ -28,6 +28,7 @@ import org.apache.maven.project.MavenPro
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.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
@@ -56,6 +57,7 @@ import java.util.Set;
* get validation directives to help users in IDEs.
*/
public class PluginDescriptorGenerator
+ extends AbstractLogEnabled
implements Generator
{
@@ -66,7 +68,7 @@ public class PluginDescriptorGenerator
throws GeneratorException
{
// eventually rewrite help mojo class to match actual package name
- PluginHelpGenerator.rewriteHelpMojo( request );
+ PluginHelpGenerator.rewriteHelpMojo( request, getLogger() );
try
{
Modified:
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
URL:
http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java?rev=1406480&r1=1406479&r2=1406480&view=diff
==============================================================================
---
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
(original)
+++
maven/plugin-tools/trunk/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
Wed Nov 7 07:20:12 2012
@@ -285,7 +285,7 @@ public class PluginHelpGenerator
* @param request
* @throws GeneratorException
*/
- static void rewriteHelpMojo( PluginToolsRequest request )
+ static void rewriteHelpMojo( PluginToolsRequest request, Logger log )
throws GeneratorException
{
File tmpPropertiesFile =
@@ -303,8 +303,22 @@ public class PluginHelpGenerator
// if helpPackageName property is empty, we have to rewrite the class
with a better package name than empty
if ( StringUtils.isEmpty( helpPackageName ) )
{
- File destinationDirectory = new File( properties.getProperty(
"destinationDirectory" ) );
- String helpMojoImplementation = rewriteHelpClassToMojoPackage(
request, destinationDirectory );
+ String destDir = properties.getProperty( "destinationDirectory" );
+ File destinationDirectory;
+ if ( StringUtils.isEmpty( destDir ) )
+ {
+ // writeHelpPropertiesFile() creates 2 properties: find one
without the other should not be possible
+ log.warn( "\n\nUnexpected situation: destinationDirectory not
defined in " + HELP_PROPERTIES_FILENAME
+ + " during help mojo source generation but expected during
XML descriptor generation." );
+ log.warn( "Please check helpmojo goal version used in previous
build phase." );
+ destinationDirectory = new File(
"target/generated-sources/plugin" );
+ log.warn( "Trying default location: " + destinationDirectory );
+ }
+ else
+ {
+ destinationDirectory = new File( destDir );
+ }
+ String helpMojoImplementation = rewriteHelpClassToMojoPackage(
request, destinationDirectory, log );
if ( helpMojoImplementation != null )
{
@@ -314,7 +328,7 @@ public class PluginHelpGenerator
}
}
- private static String rewriteHelpClassToMojoPackage( PluginToolsRequest
request, File destinationDirectory )
+ private static String rewriteHelpClassToMojoPackage( PluginToolsRequest
request, File destinationDirectory, Logger log )
throws GeneratorException
{
String destinationPackage = GeneratorUtils.discoverPackageName(
request.getPluginDescriptor() );
@@ -333,34 +347,42 @@ public class PluginHelpGenerator
// rewrite help mojo source
File helpSourceFile = new File( destinationDirectory,
HELP_MOJO_CLASS_NAME + ".java" );
- File helpSourceFileNew = new File( destinationDirectory,
packageAsDirectory + '/' + HELP_MOJO_CLASS_NAME + ".java" );
- if ( !helpSourceFileNew.getParentFile().exists() )
+ if ( !helpSourceFile.exists() )
{
- helpSourceFileNew.getParentFile().mkdirs();
+ log.warn( "HelpMojo.java not found in default location: " +
helpSourceFile.getAbsolutePath() );
+ log.warn( "Help goal source won't be moved to package: " +
destinationPackage );
}
- Reader sourceReader = null;
- PrintWriter sourceWriter = null;
- try
+ else
{
- sourceReader = new InputStreamReader( new FileInputStream(
helpSourceFile ), request.getEncoding() );
- sourceWriter =
- new PrintWriter( new OutputStreamWriter( new FileOutputStream(
helpSourceFileNew ),
- request.getEncoding()
) );
-
- sourceWriter.println( "package " + destinationPackage + ";" );
- IOUtil.copy( sourceReader, sourceWriter );
- }
- catch ( IOException e )
- {
- throw new GeneratorException( e.getMessage(), e );
- }
- finally
- {
- IOUtil.close( sourceReader );
- IOUtil.close( sourceWriter );
+ File helpSourceFileNew = new File( destinationDirectory,
packageAsDirectory + '/' + HELP_MOJO_CLASS_NAME + ".java" );
+ if ( !helpSourceFileNew.getParentFile().exists() )
+ {
+ helpSourceFileNew.getParentFile().mkdirs();
+ }
+ Reader sourceReader = null;
+ PrintWriter sourceWriter = null;
+ try
+ {
+ sourceReader = new InputStreamReader( new FileInputStream(
helpSourceFile ), request.getEncoding() );
+ sourceWriter =
+ new PrintWriter( new OutputStreamWriter( new
FileOutputStream( helpSourceFileNew ),
+
request.getEncoding() ) );
+
+ sourceWriter.println( "package " + destinationPackage + ";" );
+ IOUtil.copy( sourceReader, sourceWriter );
+ }
+ catch ( IOException e )
+ {
+ throw new GeneratorException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( sourceReader );
+ IOUtil.close( sourceWriter );
+ }
+ helpSourceFileNew.setLastModified( helpSourceFile.lastModified() );
+ helpSourceFile.delete();
}
- helpSourceFileNew.setLastModified( helpSourceFile.lastModified() );
- helpSourceFile.delete();
// rewrite help mojo .class
File rewriteHelpClassFile =