You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2012/05/12 23:52:23 UTC
svn commit: r1337699 - in
/maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin:
generator/PluginDescriptorGenerator.java generator/PluginHelpGenerator.java
util/PluginUtils.java
Author: hboutemy
Date: Sat May 12 21:52:23 2012
New Revision: 1337699
URL: http://svn.apache.org/viewvc?rev=1337699&view=rev
Log:
extracted method to PluginUtils instead of 2 copy/paste
Modified:
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
Modified: maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java?rev=1337699&r1=1337698&r2=1337699&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java (original)
+++ maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java Sat May 12 21:52:23 2012
@@ -44,7 +44,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -214,7 +213,7 @@ public class PluginDescriptorGenerator
if ( StringUtils.isEmpty( packageName ) )
{
- packageName = discoverPackageName( pluginDescriptor );
+ packageName = PluginUtils.discoverPackageName( pluginDescriptor );
}
if ( StringUtils.isNotEmpty( packageName ) )
{
@@ -272,55 +271,6 @@ public class PluginDescriptorGenerator
return descriptor;
}
- /**
- * Find the best package name, based on the number of hits of actual Mojo classes.
- *
- * @param pluginDescriptor not null
- * @return the best name of the package for the generated mojo
- */
- private static String discoverPackageName( PluginDescriptor pluginDescriptor )
- {
- Map<String, Integer> packageNames = new HashMap<String, Integer>();
- @SuppressWarnings( "unchecked" )
- List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();
- for ( MojoDescriptor descriptor : descriptors )
- {
- String impl = descriptor.getImplementation();
- if ( impl.lastIndexOf( '.' ) != -1 )
- {
- String name = impl.substring( 0, impl.lastIndexOf( '.' ) );
- if ( packageNames.get( name ) != null )
- {
- int next = packageNames.get( name ).intValue() + 1;
- packageNames.put( name, new Integer( next ) );
- }
- else
- {
- packageNames.put( name, new Integer( 1 ) );
- }
- }
- else
- {
- packageNames.put( "", new Integer( 1 ) );
- }
- }
-
- String packageName = "";
- int max = 0;
- for ( Map.Entry<String, Integer> entry : packageNames.entrySet() )
- {
- String key = entry.getKey();
- int value = entry.getValue().intValue();
- if ( value > max )
- {
- max = value;
- packageName = key;
- }
- }
-
- return packageName;
- }
-
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w )
{
processMojoDescriptor( mojoDescriptor, w, false );
@@ -696,7 +646,7 @@ public class PluginDescriptorGenerator
protected String rewriteHelpClassToMojoPackage( PluginToolsRequest request )
throws GeneratorException
{
- String destinationPackage = PluginHelpGenerator.discoverPackageName( request.getPluginDescriptor() );
+ String destinationPackage = PluginUtils.discoverPackageName( request.getPluginDescriptor() );
if ( StringUtils.isEmpty( destinationPackage ) )
{
return null;
Modified: maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java?rev=1337699&r1=1337698&r2=1337699&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java (original)
+++ maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java Sat May 12 21:52:23 2012
@@ -24,6 +24,7 @@ import org.apache.maven.plugin.descripto
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.PluginToolsRequest;
+import org.apache.maven.tools.plugin.util.PluginUtils;
import org.apache.velocity.VelocityContext;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
@@ -40,10 +41,7 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
/**
@@ -104,6 +102,7 @@ public class PluginHelpGenerator
MojoDescriptor helpDescriptor = makeHelpDescriptor( pluginDescriptor );
+ @SuppressWarnings( "unchecked" )
List<MojoDescriptor> mojoDescriptors = pluginDescriptor.getMojos();
if ( mojoDescriptors != null )
@@ -251,7 +250,7 @@ public class PluginHelpGenerator
String packageName = helpPackageName;
if ( StringUtils.isEmpty( packageName ) )
{
- packageName = discoverPackageName( pluginDescriptor );
+ packageName = PluginUtils.discoverPackageName( pluginDescriptor );
}
if ( StringUtils.isNotEmpty( packageName ) )
{
@@ -308,62 +307,4 @@ public class PluginHelpGenerator
return descriptor;
}
-
- /**
- * Find the best package name, based on the number of hits of actual Mojo classes.
- *
- * @param pluginDescriptor not null
- * @return the best name of the package for the generated mojo
- */
- protected static String discoverPackageName( PluginDescriptor pluginDescriptor )
- {
- Map<String, Integer> packageNames = new HashMap<String, Integer>();
- List<MojoDescriptor> mojoDescriptors = pluginDescriptor.getMojos();
- if ( mojoDescriptors == null )
- {
- return "";
- }
- for ( MojoDescriptor descriptor : mojoDescriptors )
- {
-
- String impl = descriptor.getImplementation();
- if ( StringUtils.equals( descriptor.getGoal(), "help" ) && StringUtils.equals( "HelpMojo", impl ) )
- {
- continue;
- }
- if ( impl.lastIndexOf( '.' ) != -1 )
- {
- String name = impl.substring( 0, impl.lastIndexOf( '.' ) );
- if ( packageNames.get( name ) != null )
- {
- int next = ( packageNames.get( name ) ).intValue() + 1;
- packageNames.put( name, new Integer( next ) );
- }
- else
- {
- packageNames.put( name, new Integer( 1 ) );
- }
- }
- else
- {
- packageNames.put( "", new Integer( 1 ) );
- }
- }
-
- String packageName = "";
- int max = 0;
- for ( Iterator it = packageNames.keySet().iterator(); it.hasNext(); )
- {
- String key = it.next().toString();
- int value = ( packageNames.get( key ) ).intValue();
- if ( value > max )
- {
- max = value;
- packageName = key;
- }
- }
-
- return packageName;
- }
-
}
Modified: maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java?rev=1337699&r1=1337698&r2=1337699&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java (original)
+++ maven/plugin-tools/trunk/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java Sat May 12 21:52:23 2012
@@ -31,8 +31,10 @@ import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -181,6 +183,7 @@ public final class PluginUtils
* <code>false</code> otherwise.
* @throws IllegalArgumentException if any
*/
+ @SuppressWarnings( "unchecked" )
public static boolean isMavenReport( String impl, MavenProject project )
throws IllegalArgumentException
{
@@ -724,4 +727,61 @@ public final class PluginUtils
sb.append( text );
}
}
+
+ /**
+ * Find the best package name, based on the number of hits of actual Mojo classes.
+ *
+ * @param pluginDescriptor not null
+ * @return the best name of the package for the generated mojo
+ */
+ public static String discoverPackageName( PluginDescriptor pluginDescriptor )
+ {
+ Map<String, Integer> packageNames = new HashMap<String, Integer>();
+ @SuppressWarnings( "unchecked" )
+ List<MojoDescriptor> mojoDescriptors = pluginDescriptor.getMojos();
+ if ( mojoDescriptors == null )
+ {
+ return "";
+ }
+ for ( MojoDescriptor descriptor : mojoDescriptors )
+ {
+
+ String impl = descriptor.getImplementation();
+ if ( StringUtils.equals( descriptor.getGoal(), "help" ) && StringUtils.equals( "HelpMojo", impl ) )
+ {
+ continue;
+ }
+ if ( impl.lastIndexOf( '.' ) != -1 )
+ {
+ String name = impl.substring( 0, impl.lastIndexOf( '.' ) );
+ if ( packageNames.get( name ) != null )
+ {
+ int next = ( packageNames.get( name ) ).intValue() + 1;
+ packageNames.put( name, new Integer( next ) );
+ }
+ else
+ {
+ packageNames.put( name, new Integer( 1 ) );
+ }
+ }
+ else
+ {
+ packageNames.put( "", new Integer( 1 ) );
+ }
+ }
+
+ String packageName = "";
+ int max = 0;
+ for ( Map.Entry<String, Integer> entry : packageNames.entrySet() )
+ {
+ int value = entry.getValue().intValue();
+ if ( value > max )
+ {
+ max = value;
+ packageName = entry.getKey();
+ }
+ }
+
+ return packageName;
+ }
}