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
index 218db79..d6e68f6 100644
--- 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
@@ -31,6 +31,7 @@ import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.tools.plugin.generator.GeneratorException;
+import org.apache.maven.tools.plugin.generator.GeneratorUtils;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.ReaderFactory;
@@ -233,7 +234,7 @@ public abstract class AbstractGeneratorMojo
try
{
- pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
+ pluginDescriptor.setDependencies( GeneratorUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
request.setEncoding( encoding );
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
index e22769c..5a831b1 100644
--- 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
@@ -34,6 +34,7 @@ import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.generator.GeneratorException;
+import org.apache.maven.tools.plugin.generator.GeneratorUtils;
import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.util.PluginUtils;
@@ -231,7 +232,7 @@ public class PluginReport
try
{
- pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
+ pluginDescriptor.setDependencies( GeneratorUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
request.setEncoding( encoding );
@@ -386,7 +387,7 @@ public class PluginReport
{
MojoDescriptor mojo = i.next();
- if ( PluginUtils.isMavenReport( mojo.getImplementation(), project ) )
+ if ( GeneratorUtils.isMavenReport( mojo.getImplementation(), project ) )
{
hasMavenReport = true;
}
@@ -424,11 +425,11 @@ public class PluginReport
{
description =
"" + getBundle( locale ).getString( "report.plugin.goal.deprecated" ) + " "
- + PluginUtils.makeHtmlValid( mojo.getDeprecated() );
+ + GeneratorUtils.makeHtmlValid( mojo.getDeprecated() );
}
else if ( StringUtils.isNotEmpty( mojo.getDescription() ) )
{
- description = PluginUtils.makeHtmlValid( mojo.getDescription() );
+ description = GeneratorUtils.makeHtmlValid( mojo.getDescription() );
}
else
{
@@ -439,7 +440,7 @@ public class PluginReport
tableCell( createLinkPatternedText( goalName, goalDocumentationLink ) );
if ( hasMavenReport )
{
- if ( PluginUtils.isMavenReport( mojo.getImplementation(), project ) )
+ if ( GeneratorUtils.isMavenReport( mojo.getImplementation(), project ) )
{
sink.tableCell();
sink.text( getBundle( locale ).getString( "report.plugin.isReport" ) );
diff --git a/maven-plugin-tools-api/pom.xml b/maven-plugin-tools-api/pom.xml
index 1e56f75..8387a47 100644
--- a/maven-plugin-tools-api/pom.xml
+++ b/maven-plugin-tools-api/pom.xml
@@ -56,12 +56,6 @@
maven-plugin-descriptor
-
- org.apache.maven.reporting
- maven-reporting-api
- 3.0
-
-
org.codehaus.plexus
@@ -72,20 +66,7 @@
plexus-container-default
-
-
- net.sf.jtidy
- jtidy
- r938
-
-
-
- org.apache.maven.reporting
- maven-reporting-impl
- 2.1
- test
-
org.apache.maven.plugin-testing
maven-plugin-testing-harness
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
index b1791ab..2fed00a 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
@@ -19,7 +19,6 @@ package org.apache.maven.tools.plugin.scanner;
* under the License.
*/
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@@ -31,6 +30,7 @@ import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.util.StringUtils;
import java.util.HashSet;
import java.util.List;
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
index 0c75fe3..cbfef23 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
@@ -19,44 +19,15 @@ package org.apache.maven.tools.plugin.util;
* under the License.
*/
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-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;
-import javax.swing.text.MutableAttributeSet;
-import javax.swing.text.html.HTML;
-import javax.swing.text.html.HTMLEditorKit;
-import javax.swing.text.html.parser.ParserDelegator;
-
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.reporting.MavenReport;
-import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.XMLWriter;
-import org.w3c.tidy.Tidy;
/**
* Convenience methods to play with Maven plugins.
@@ -106,303 +77,6 @@ public final class PluginUtils
return scanner.getIncludedFiles();
}
- /**
- * @param w not null writer
- * @param pluginDescriptor not null
- */
- public static void writeDependencies( XMLWriter w, PluginDescriptor pluginDescriptor )
- {
- w.startElement( "dependencies" );
-
- @SuppressWarnings( "unchecked" )
- List deps = pluginDescriptor.getDependencies();
- for ( ComponentDependency dep : deps )
- {
- w.startElement( "dependency" );
-
- PluginUtils.element( w, "groupId", dep.getGroupId() );
-
- PluginUtils.element( w, "artifactId", dep.getArtifactId() );
-
- PluginUtils.element( w, "type", dep.getType() );
-
- PluginUtils.element( w, "version", dep.getVersion() );
-
- w.endElement();
- }
-
- w.endElement();
- }
-
- /**
- * @param dependencies not null list of Dependency
- * @return list of component dependencies
- */
- public static List toComponentDependencies( List dependencies )
- {
- List componentDeps = new LinkedList();
-
- for ( Dependency dependency : dependencies )
- {
- ComponentDependency cd = new ComponentDependency();
-
- cd.setArtifactId( dependency.getArtifactId() );
- cd.setGroupId( dependency.getGroupId() );
- cd.setVersion( dependency.getVersion() );
- cd.setType( dependency.getType() );
-
- componentDeps.add( cd );
- }
-
- return componentDeps;
- }
-
- /**
- * @param w not null writer
- * @param name not null
- * @param value could be null
- */
- public static void element( XMLWriter w, String name, String value )
- {
- w.startElement( name );
-
- if ( value == null )
- {
- value = "";
- }
-
- w.writeText( value );
-
- w.endElement();
- }
-
- /**
- * @param impl a Mojo implementation, not null
- * @param project a MavenProject instance, could be null
- * @return true is the Mojo implementation implements MavenReport,
- * false otherwise.
- * @throws IllegalArgumentException if any
- */
- @SuppressWarnings( "unchecked" )
- public static boolean isMavenReport( String impl, MavenProject project )
- throws IllegalArgumentException
- {
- if ( impl == null )
- {
- throw new IllegalArgumentException( "mojo implementation should be declared" );
- }
-
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if ( project != null )
- {
- List classPathStrings;
- try
- {
- classPathStrings = project.getCompileClasspathElements();
- if ( project.getExecutionProject() != null )
- {
- classPathStrings.addAll( project.getExecutionProject().getCompileClasspathElements() );
- }
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new IllegalArgumentException( e );
- }
-
- List urls = new ArrayList( classPathStrings.size() );
- for ( String classPathString : classPathStrings )
- {
- try
- {
- urls.add( new File( classPathString ).toURL() );
- }
- catch ( MalformedURLException e )
- {
- throw new IllegalArgumentException( e );
- }
- }
-
- classLoader = new URLClassLoader( urls.toArray( new URL[urls.size()] ), classLoader );
- }
-
- try
- {
- Class> clazz = Class.forName( impl, false, classLoader );
-
- return MavenReport.class.isAssignableFrom( clazz );
- }
- catch ( ClassNotFoundException e )
- {
- return false;
- }
- }
-
- /**
- * Fixes some javadoc comment to become a valid XHTML snippet.
- *
- * @param description Javadoc description with HTML tags, may be null.
- * @return The description with valid XHTML tags, never null.
- */
- public static String makeHtmlValid( String description )
- {
- if ( StringUtils.isEmpty( description ) )
- {
- return "";
- }
-
- String commentCleaned = decodeJavadocTags( description );
-
- // Using jTidy to clean comment
- Tidy tidy = new Tidy();
- tidy.setDocType( "loose" );
- tidy.setXHTML( true );
- tidy.setXmlOut( true );
- tidy.setInputEncoding( "UTF-8" );
- tidy.setOutputEncoding( "UTF-8" );
- tidy.setMakeClean( true );
- tidy.setNumEntities( true );
- tidy.setQuoteNbsp( false );
- tidy.setQuiet( true );
- tidy.setShowWarnings( false );
- try
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream( commentCleaned.length() + 256 );
- tidy.parse( new ByteArrayInputStream( commentCleaned.getBytes( "UTF-8" ) ), out );
- commentCleaned = out.toString( "UTF-8" );
- }
- catch ( UnsupportedEncodingException e )
- {
- // cannot happen as every JVM must support UTF-8, see also class javadoc for java.nio.charset.Charset
- }
-
- if ( StringUtils.isEmpty( commentCleaned ) )
- {
- return "";
- }
-
- // strip the header/body stuff
- String ls = System.getProperty( "line.separator" );
- int startPos = commentCleaned.indexOf( "" + ls ) + 6 + ls.length();
- int endPos = commentCleaned.indexOf( ls + "" );
- commentCleaned = commentCleaned.substring( startPos, endPos );
-
- return commentCleaned;
- }
-
- /**
- * Decodes javadoc inline tags into equivalent HTML tags. For instance, the inline tag "{@code }" should be
- * rendered as "<A&B>".
- *
- * @param description The javadoc description to decode, may be null.
- * @return The decoded description, never null.
- */
- static String decodeJavadocTags( String description )
- {
- if ( StringUtils.isEmpty( description ) )
- {
- return "";
- }
-
- StringBuffer decoded = new StringBuffer( description.length() + 1024 );
-
- Matcher matcher = Pattern.compile( "\\{@(\\w+)\\s*([^\\}]*)\\}" ).matcher( description );
- while ( matcher.find() )
- {
- String tag = matcher.group( 1 );
- String text = matcher.group( 2 );
- text = StringUtils.replace( text, "&", "&" );
- text = StringUtils.replace( text, "<", "<" );
- text = StringUtils.replace( text, ">", ">" );
- if ( "code".equals( tag ) )
- {
- text = "" + text + "";
- }
- else if ( "link".equals( tag ) || "linkplain".equals( tag ) || "value".equals( tag ) )
- {
- String pattern = "(([^#\\.\\s]+\\.)*([^#\\.\\s]+))?" + "(#([^\\(\\s]*)(\\([^\\)]*\\))?\\s*(\\S.*)?)?";
- final int label = 7;
- final int clazz = 3;
- final int member = 5;
- final int args = 6;
- Matcher link = Pattern.compile( pattern ).matcher( text );
- if ( link.matches() )
- {
- text = link.group( label );
- if ( StringUtils.isEmpty( text ) )
- {
- text = link.group( clazz );
- if ( StringUtils.isEmpty( text ) )
- {
- text = "";
- }
- if ( StringUtils.isNotEmpty( link.group( member ) ) )
- {
- if ( StringUtils.isNotEmpty( text ) )
- {
- text += '.';
- }
- text += link.group( member );
- if ( StringUtils.isNotEmpty( link.group( args ) ) )
- {
- text += "()";
- }
- }
- }
- }
- if ( !"linkplain".equals( tag ) )
- {
- text = "" + text + "";
- }
- }
- matcher.appendReplacement( decoded, ( text != null ) ? quoteReplacement( text ) : "" );
- }
- matcher.appendTail( decoded );
-
- return decoded.toString();
- }
-
- /**
- * Returns a literal replacement String for the specified String. This method
- * produces a String that will work as a literal replacement s in the
- * appendReplacement method of the {@link Matcher} class. The String produced will
- * match the sequence of characters in s treated as a literal sequence. Slashes ('\') and dollar
- * signs ('$') will be given no special meaning. TODO: copied from Matcher class of Java 1.5, remove once target
- * platform can be upgraded
- *
- * @see java.util.regex.Matcher
- * @param s The string to be literalized
- * @return A literal string replacement
- */
- private static String quoteReplacement( String s )
- {
- if ( ( s.indexOf( '\\' ) == -1 ) && ( s.indexOf( '$' ) == -1 ) )
- {
- return s;
- }
-
- StringBuffer sb = new StringBuffer();
- for ( int i = 0; i < s.length(); i++ )
- {
- char c = s.charAt( i );
- if ( c == '\\' )
- {
- sb.append( '\\' );
- sb.append( '\\' );
- }
- else if ( c == '$' )
- {
- sb.append( '\\' );
- sb.append( '$' );
- }
- else
- {
- sb.append( c );
- }
- }
-
- return sb.toString();
- }
-
/**
* Sorts the specified mojo descriptors by goal name.
*
@@ -445,343 +119,4 @@ public final class PluginUtils
} );
}
}
-
- /**
- * Converts a HTML fragment as extracted from a javadoc comment to a plain text string. This method tries to retain
- * as much of the text formatting as possible by means of the following transformations:
- *
- * - List items are converted to leading tabs (U+0009), followed by the item number/bullet, another tab and
- * finally the item contents. Each tab denotes an increase of indentation.
- * - Flow breaking elements as well as literal line terminators in preformatted text are converted to a newline
- * (U+000A) to denote a mandatory line break.
- * - Consecutive spaces and line terminators from character data outside of preformatted text will be normalized
- * to a single space. The resulting space denotes a possible point for line wrapping.
- * - Each space in preformatted text will be converted to a non-breaking space (U+00A0).
- *
- *
- * @param html The HTML fragment to convert to plain text, may be null.
- * @return A string with HTML tags converted into pure text, never null.
- * @since 2.4.3
- */
- public static String toText( String html )
- {
- if ( StringUtils.isEmpty( html ) )
- {
- return "";
- }
-
- final StringBuffer sb = new StringBuffer();
-
- HTMLEditorKit.Parser parser = new ParserDelegator();
- HTMLEditorKit.ParserCallback htmlCallback = new MojoParserCallback( sb );
-
- try
- {
- parser.parse( new StringReader( makeHtmlValid( html ) ), htmlCallback, true );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
-
- return sb.toString().replace( '\"', '\'' ); // for CDATA
- }
-
- /**
- * ParserCallback implementation.
- */
- private static class MojoParserCallback
- extends HTMLEditorKit.ParserCallback
- {
- /**
- * Holds the index of the current item in a numbered list.
- */
- class Counter
- {
- public int value;
- }
-
- /**
- * A flag whether the parser is currently in the body element.
- */
- private boolean body;
-
- /**
- * A flag whether the parser is currently processing preformatted text, actually a counter to track nesting.
- */
- private int preformatted;
-
- /**
- * The current indentation depth for the output.
- */
- private int depth;
-
- /**
- * A stack of {@link Counter} objects corresponding to the nesting of (un-)ordered lists. A
- * null element denotes an unordered list.
- */
- private Stack numbering = new Stack();
-
- /**
- * A flag whether an implicit line break is pending in the output buffer. This flag is used to postpone the
- * output of implicit line breaks until we are sure that are not to be merged with other implicit line
- * breaks.
- */
- private boolean pendingNewline;
-
- /**
- * A flag whether we have just parsed a simple tag.
- */
- private boolean simpleTag;
-
- /**
- * The current buffer.
- */
- private final StringBuffer sb;
-
- /**
- * @param sb not null
- */
- public MojoParserCallback( StringBuffer sb )
- {
- this.sb = sb;
- }
-
- /** {@inheritDoc} */
- public void handleSimpleTag( HTML.Tag t, MutableAttributeSet a, int pos )
- {
- simpleTag = true;
- if ( body && HTML.Tag.BR.equals( t ) )
- {
- newline( false );
- }
- }
-
- /** {@inheritDoc} */
- public void handleStartTag( HTML.Tag t, MutableAttributeSet a, int pos )
- {
- simpleTag = false;
- if ( body && ( t.breaksFlow() || t.isBlock() ) )
- {
- newline( true );
- }
- if ( HTML.Tag.OL.equals( t ) )
- {
- numbering.push( new Counter() );
- }
- else if ( HTML.Tag.UL.equals( t ) )
- {
- numbering.push( null );
- }
- else if ( HTML.Tag.LI.equals( t ) )
- {
- Counter counter = numbering.peek();
- if ( counter == null )
- {
- text( "-\t" );
- }
- else
- {
- text( ++counter.value + ".\t" );
- }
- depth++;
- }
- else if ( HTML.Tag.DD.equals( t ) )
- {
- depth++;
- }
- else if ( t.isPreformatted() )
- {
- preformatted++;
- }
- else if ( HTML.Tag.BODY.equals( t ) )
- {
- body = true;
- }
- }
-
- /** {@inheritDoc} */
- public void handleEndTag( HTML.Tag t, int pos )
- {
- if ( HTML.Tag.OL.equals( t ) || HTML.Tag.UL.equals( t ) )
- {
- numbering.pop();
- }
- else if ( HTML.Tag.LI.equals( t ) || HTML.Tag.DD.equals( t ) )
- {
- depth--;
- }
- else if ( t.isPreformatted() )
- {
- preformatted--;
- }
- else if ( HTML.Tag.BODY.equals( t ) )
- {
- body = false;
- }
- if ( body && ( t.breaksFlow() || t.isBlock() ) && !HTML.Tag.LI.equals( t ) )
- {
- if ( ( HTML.Tag.P.equals( t ) || HTML.Tag.PRE.equals( t ) || HTML.Tag.OL.equals( t )
- || HTML.Tag.UL.equals( t ) || HTML.Tag.DL.equals( t ) )
- && numbering.isEmpty() )
- {
- pendingNewline = false;
- newline( pendingNewline );
- }
- else
- {
- newline( true );
- }
- }
- }
-
- /** {@inheritDoc} */
- public void handleText( char[] data, int pos )
- {
- /*
- * NOTE: Parsers before JRE 1.6 will parse XML-conform simple tags like
as "
" followed by
- * the text event ">..." so we need to watch out for the closing angle bracket.
- */
- int offset = 0;
- if ( simpleTag && data[0] == '>' )
- {
- simpleTag = false;
- for ( ++offset; offset < data.length && data[offset] <= ' '; )
- {
- offset++;
- }
- }
- if ( offset < data.length )
- {
- String text = new String( data, offset, data.length - offset );
- text( text );
- }
- }
-
- /** {@inheritDoc} */
- public void flush()
- {
- flushPendingNewline();
- }
-
- /**
- * Writes a line break to the plain text output.
- *
- * @param implicit A flag whether this is an explicit or implicit line break. Explicit line breaks are
- * always written to the output whereas consecutive implicit line breaks are merged into a single
- * line break.
- */
- private void newline( boolean implicit )
- {
- if ( implicit )
- {
- pendingNewline = true;
- }
- else
- {
- flushPendingNewline();
- sb.append( '\n' );
- }
- }
-
- /**
- * Flushes a pending newline (if any).
- */
- private void flushPendingNewline()
- {
- if ( pendingNewline )
- {
- pendingNewline = false;
- if ( sb.length() > 0 )
- {
- sb.append( '\n' );
- }
- }
- }
-
- /**
- * Writes the specified character data to the plain text output. If the last output was a line break, the
- * character data will automatically be prefixed with the current indent.
- *
- * @param data The character data, must not be null.
- */
- private void text( String data )
- {
- flushPendingNewline();
- if ( sb.length() <= 0 || sb.charAt( sb.length() - 1 ) == '\n' )
- {
- for ( int i = 0; i < depth; i++ )
- {
- sb.append( '\t' );
- }
- }
- String text;
- if ( preformatted > 0 )
- {
- text = data;
- }
- else
- {
- text = data.replace( '\n', ' ' );
- }
- 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 packageNames = new HashMap();
- @SuppressWarnings( "unchecked" )
- List 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, Integer.valueOf( next ) );
- }
- else
- {
- packageNames.put( name, Integer.valueOf( 1 ) );
- }
- }
- else
- {
- packageNames.put( "", Integer.valueOf( 1 ) );
- }
- }
-
- String packageName = "";
- int max = 0;
- for ( Map.Entry entry : packageNames.entrySet() )
- {
- int value = entry.getValue().intValue();
- if ( value > max )
- {
- max = value;
- packageName = entry.getKey();
- }
- }
-
- return packageName;
- }
}
diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java
index d895439..a5c740b 100644
--- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java
+++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java
@@ -21,13 +21,6 @@ package org.apache.maven.tools.plugin.util;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.codehaus.plexus.component.repository.ComponentDependency;
-import org.codehaus.plexus.util.xml.CompactXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-import java.io.StringWriter;
-import java.util.Collections;
/**
* @author jdcasey
@@ -45,32 +38,6 @@ public class PluginUtilsTest
assertEquals( "plugin", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-plugin" ) );
}
- public void testShouldWriteDependencies()
- throws Exception
- {
- ComponentDependency dependency = new ComponentDependency();
- dependency.setArtifactId( "testArtifactId" );
- dependency.setGroupId( "testGroupId" );
- dependency.setType( "pom" );
- dependency.setVersion( "0.0.0" );
-
- PluginDescriptor descriptor = new PluginDescriptor();
- descriptor.setDependencies( Collections.singletonList( dependency ) );
-
- StringWriter sWriter = new StringWriter();
- XMLWriter writer = new CompactXMLWriter( sWriter );
-
- PluginUtils.writeDependencies( writer, descriptor );
-
- String output = sWriter.toString();
-
- String pattern = "" + "" + "testGroupId"
- + "testArtifactId" + "pom" + "0.0.0"
- + "" + "";
-
- assertEquals( pattern, output );
- }
-
public void testShouldFindTwoScriptsWhenNoExcludesAreGiven()
{
String testScript = "test.txt";
@@ -96,144 +63,4 @@ public class PluginUtilsTest
assertEquals( 1, files.length );
}
- public void testIsMavenReport()
- throws Exception
- {
- try
- {
- PluginUtils.isMavenReport( null, null );
- }
- catch ( IllegalArgumentException e )
- {
- assertTrue( true );
- }
-
- String impl = "org.apache.maven.tools.plugin.util.stubs.MavenReportStub";
-
- MavenProjectStub stub = new MavenProjectStub();
- stub.setCompileSourceRoots( Collections.singletonList( getBasedir() + "/target/classes" ) );
-
- assertTrue( PluginUtils.isMavenReport( impl, stub ) );
-
- impl = "org.apache.maven.tools.plugin.util.stubs.MojoStub";
- assertFalse( PluginUtils.isMavenReport( impl, stub ) );
- }
-
- public void testMakeHtmlValid()
- {
- String javadoc = null;
- assertEquals( "", PluginUtils.makeHtmlValid( javadoc ) );
- javadoc = "";
- assertEquals( "", PluginUtils.makeHtmlValid( javadoc ) );
-
- // true HTML
- javadoc = "Generates something for the project.";
- assertEquals( "Generates something for the project.", PluginUtils.makeHtmlValid( javadoc ) );
-
- // wrong HTML
- javadoc = "Generates something for the project.";
- assertEquals( "Generates something for the project.", PluginUtils.makeHtmlValid( javadoc ) );
-
- // wrong XHTML
- javadoc = "Line1
Line2";
- assertEquals( "Line1
Line2", PluginUtils.makeHtmlValid( javadoc ).replaceAll( "\\s", "" ) );
-
- // special characters
- javadoc = "& & < > \u00A0";
- assertEquals( "& & < > \u00A0", PluginUtils.makeHtmlValid( javadoc ) );
-
- // non ASCII characters
- javadoc = "\u00E4 \u00F6 \u00FC \u00DF";
- assertEquals( javadoc, PluginUtils.makeHtmlValid( javadoc ) );
-
- // non Latin1 characters
- javadoc = "\u0130 \u03A3 \u05D0 \u06DE";
- assertEquals( javadoc, PluginUtils.makeHtmlValid( javadoc ) );
- }
-
- public void testDecodeJavadocTags()
- {
- String javadoc = null;
- assertEquals( "", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "";
- assertEquals( "", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@code text}";
- assertEquals( "text", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@code }";
- assertEquals( "<A&B>", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@literal text}";
- assertEquals( "text", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@literal text} {@literal text}";
- assertEquals( "text text", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@literal }";
- assertEquals( "<A&B>", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@link Class}";
- assertEquals( "Class", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain Class}";
- assertEquals( "Class", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain #field}";
- assertEquals( "field", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain Class#field}";
- assertEquals( "Class.field", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain #method()}";
- assertEquals( "method()", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain #method(Object arg)}";
- assertEquals( "method()", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain #method(Object, String)}";
- assertEquals( "method()", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain #method(Object, String) label}";
- assertEquals( "label", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain Class#method(Object, String)}";
- assertEquals( "Class.method()", PluginUtils.decodeJavadocTags( javadoc ) );
-
- javadoc = "{@linkplain Class#method(Object, String) label}";
- assertEquals( "label", PluginUtils.decodeJavadocTags( javadoc ) );
- }
-
- public void testToText()
- throws Exception
- {
- String javadoc = null;
- assertEquals( "", PluginUtils.toText( javadoc ) );
- javadoc = "";
- assertEquals( "", PluginUtils.toText( javadoc ) );
-
- // line breaks
- javadoc = "Line1\nLine2";
- assertEquals( "Line1 Line2", PluginUtils.toText( javadoc ) );
- javadoc = "Line1\rLine2";
- assertEquals( "Line1 Line2", PluginUtils.toText( javadoc ) );
- javadoc = "Line1\r\nLine2";
- assertEquals( "Line1 Line2", PluginUtils.toText( javadoc ) );
- javadoc = "Line1
Line2";
- assertEquals( "Line1\nLine2", PluginUtils.toText( javadoc ) );
-
- // true HTML
- javadoc = "Generates something for the project.";
- assertEquals( "Generates something for the project.", PluginUtils.toText( javadoc ) );
-
- // wrong HTML
- javadoc = "Generates something for the project.";
- assertEquals( "Generates something for the project.", PluginUtils.toText( javadoc ) );
-
- // javadoc inline tags
- javadoc = "Generates {@code something} for the project.";
- assertEquals( "Generates something for the project.", PluginUtils.toText( javadoc ) );
- }
-
}
diff --git a/maven-plugin-tools-generators/pom.xml b/maven-plugin-tools-generators/pom.xml
index f107a42..b987105 100644
--- a/maven-plugin-tools-generators/pom.xml
+++ b/maven-plugin-tools-generators/pom.xml
@@ -53,6 +53,12 @@
maven-plugin-descriptor
+
+ org.apache.maven.reporting
+ maven-reporting-api
+ 3.0
+
+
org.codehaus.plexus
@@ -87,6 +93,26 @@
asm
asm-commons
+
+
+
+ net.sf.jtidy
+ jtidy
+ r938
+
+
+
+
+ org.apache.maven.reporting
+ maven-reporting-impl
+ 2.1
+ test
+
+
+ org.apache.maven.plugin-testing
+ maven-plugin-testing-harness
+ test
+
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
new file mode 100644
index 0000000..be7f274
--- /dev/null
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
@@ -0,0 +1,705 @@
+package org.apache.maven.tools.plugin.generator;
+
+/*
+ * 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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+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;
+
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.parser.ParserDelegator;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.model.Dependency;
+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.MavenReport;
+import org.codehaus.plexus.component.repository.ComponentDependency;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XMLWriter;
+import org.w3c.tidy.Tidy;
+
+/**
+ * Convenience methods to play with Maven plugins.
+ *
+ * @author jdcasey
+ * @version $Id$
+ */
+public final class GeneratorUtils
+{
+ private GeneratorUtils()
+ {
+ // nop
+ }
+
+ /**
+ * @param w not null writer
+ * @param pluginDescriptor not null
+ */
+ public static void writeDependencies( XMLWriter w, PluginDescriptor pluginDescriptor )
+ {
+ w.startElement( "dependencies" );
+
+ @SuppressWarnings( "unchecked" )
+ List deps = pluginDescriptor.getDependencies();
+ for ( ComponentDependency dep : deps )
+ {
+ w.startElement( "dependency" );
+
+ element( w, "groupId", dep.getGroupId() );
+
+ element( w, "artifactId", dep.getArtifactId() );
+
+ element( w, "type", dep.getType() );
+
+ element( w, "version", dep.getVersion() );
+
+ w.endElement();
+ }
+
+ w.endElement();
+ }
+
+ /**
+ * @param w not null writer
+ * @param name not null
+ * @param value could be null
+ */
+ public static void element( XMLWriter w, String name, String value )
+ {
+ w.startElement( name );
+
+ if ( value == null )
+ {
+ value = "";
+ }
+
+ w.writeText( value );
+
+ w.endElement();
+ }
+
+ /**
+ * @param dependencies not null list of Dependency
+ * @return list of component dependencies
+ */
+ public static List toComponentDependencies( List dependencies )
+ {
+ List componentDeps = new LinkedList();
+
+ for ( Dependency dependency : dependencies )
+ {
+ ComponentDependency cd = new ComponentDependency();
+
+ cd.setArtifactId( dependency.getArtifactId() );
+ cd.setGroupId( dependency.getGroupId() );
+ cd.setVersion( dependency.getVersion() );
+ cd.setType( dependency.getType() );
+
+ componentDeps.add( cd );
+ }
+
+ return componentDeps;
+ }
+
+ /**
+ * Returns a literal replacement String for the specified String. This method
+ * produces a String that will work as a literal replacement s in the
+ * appendReplacement method of the {@link Matcher} class. The String produced will
+ * match the sequence of characters in s treated as a literal sequence. Slashes ('\') and dollar
+ * signs ('$') will be given no special meaning. TODO: copied from Matcher class of Java 1.5, remove once target
+ * platform can be upgraded
+ *
+ * @see java.util.regex.Matcher
+ * @param s The string to be literalized
+ * @return A literal string replacement
+ */
+ private static String quoteReplacement( String s )
+ {
+ if ( ( s.indexOf( '\\' ) == -1 ) && ( s.indexOf( '$' ) == -1 ) )
+ {
+ return s;
+ }
+
+ StringBuffer sb = new StringBuffer();
+ for ( int i = 0; i < s.length(); i++ )
+ {
+ char c = s.charAt( i );
+ if ( c == '\\' )
+ {
+ sb.append( '\\' );
+ sb.append( '\\' );
+ }
+ else if ( c == '$' )
+ {
+ sb.append( '\\' );
+ sb.append( '$' );
+ }
+ else
+ {
+ sb.append( c );
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Decodes javadoc inline tags into equivalent HTML tags. For instance, the inline tag "{@code }" should be
+ * rendered as "<A&B>".
+ *
+ * @param description The javadoc description to decode, may be null.
+ * @return The decoded description, never null.
+ */
+ static String decodeJavadocTags( String description )
+ {
+ if ( StringUtils.isEmpty( description ) )
+ {
+ return "";
+ }
+
+ StringBuffer decoded = new StringBuffer( description.length() + 1024 );
+
+ Matcher matcher = Pattern.compile( "\\{@(\\w+)\\s*([^\\}]*)\\}" ).matcher( description );
+ while ( matcher.find() )
+ {
+ String tag = matcher.group( 1 );
+ String text = matcher.group( 2 );
+ text = StringUtils.replace( text, "&", "&" );
+ text = StringUtils.replace( text, "<", "<" );
+ text = StringUtils.replace( text, ">", ">" );
+ if ( "code".equals( tag ) )
+ {
+ text = "" + text + "";
+ }
+ else if ( "link".equals( tag ) || "linkplain".equals( tag ) || "value".equals( tag ) )
+ {
+ String pattern = "(([^#\\.\\s]+\\.)*([^#\\.\\s]+))?" + "(#([^\\(\\s]*)(\\([^\\)]*\\))?\\s*(\\S.*)?)?";
+ final int label = 7;
+ final int clazz = 3;
+ final int member = 5;
+ final int args = 6;
+ Matcher link = Pattern.compile( pattern ).matcher( text );
+ if ( link.matches() )
+ {
+ text = link.group( label );
+ if ( StringUtils.isEmpty( text ) )
+ {
+ text = link.group( clazz );
+ if ( StringUtils.isEmpty( text ) )
+ {
+ text = "";
+ }
+ if ( StringUtils.isNotEmpty( link.group( member ) ) )
+ {
+ if ( StringUtils.isNotEmpty( text ) )
+ {
+ text += '.';
+ }
+ text += link.group( member );
+ if ( StringUtils.isNotEmpty( link.group( args ) ) )
+ {
+ text += "()";
+ }
+ }
+ }
+ }
+ if ( !"linkplain".equals( tag ) )
+ {
+ text = "" + text + "";
+ }
+ }
+ matcher.appendReplacement( decoded, ( text != null ) ? quoteReplacement( text ) : "" );
+ }
+ matcher.appendTail( decoded );
+
+ return decoded.toString();
+ }
+
+ /**
+ * Fixes some javadoc comment to become a valid XHTML snippet.
+ *
+ * @param description Javadoc description with HTML tags, may be null.
+ * @return The description with valid XHTML tags, never null.
+ */
+ public static String makeHtmlValid( String description )
+ {
+ if ( StringUtils.isEmpty( description ) )
+ {
+ return "";
+ }
+
+ String commentCleaned = decodeJavadocTags( description );
+
+ // Using jTidy to clean comment
+ Tidy tidy = new Tidy();
+ tidy.setDocType( "loose" );
+ tidy.setXHTML( true );
+ tidy.setXmlOut( true );
+ tidy.setInputEncoding( "UTF-8" );
+ tidy.setOutputEncoding( "UTF-8" );
+ tidy.setMakeClean( true );
+ tidy.setNumEntities( true );
+ tidy.setQuoteNbsp( false );
+ tidy.setQuiet( true );
+ tidy.setShowWarnings( false );
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream( commentCleaned.length() + 256 );
+ tidy.parse( new ByteArrayInputStream( commentCleaned.getBytes( "UTF-8" ) ), out );
+ commentCleaned = out.toString( "UTF-8" );
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ // cannot happen as every JVM must support UTF-8, see also class javadoc for java.nio.charset.Charset
+ }
+
+ if ( StringUtils.isEmpty( commentCleaned ) )
+ {
+ return "";
+ }
+
+ // strip the header/body stuff
+ String ls = System.getProperty( "line.separator" );
+ int startPos = commentCleaned.indexOf( "" + ls ) + 6 + ls.length();
+ int endPos = commentCleaned.indexOf( ls + "" );
+ commentCleaned = commentCleaned.substring( startPos, endPos );
+
+ return commentCleaned;
+ }
+
+ /**
+ * Converts a HTML fragment as extracted from a javadoc comment to a plain text string. This method tries to retain
+ * as much of the text formatting as possible by means of the following transformations:
+ *
+ * - List items are converted to leading tabs (U+0009), followed by the item number/bullet, another tab and
+ * finally the item contents. Each tab denotes an increase of indentation.
+ * - Flow breaking elements as well as literal line terminators in preformatted text are converted to a newline
+ * (U+000A) to denote a mandatory line break.
+ * - Consecutive spaces and line terminators from character data outside of preformatted text will be normalized
+ * to a single space. The resulting space denotes a possible point for line wrapping.
+ * - Each space in preformatted text will be converted to a non-breaking space (U+00A0).
+ *
+ *
+ * @param html The HTML fragment to convert to plain text, may be null.
+ * @return A string with HTML tags converted into pure text, never null.
+ * @since 2.4.3
+ */
+ public static String toText( String html )
+ {
+ if ( StringUtils.isEmpty( html ) )
+ {
+ return "";
+ }
+
+ final StringBuffer sb = new StringBuffer();
+
+ HTMLEditorKit.Parser parser = new ParserDelegator();
+ HTMLEditorKit.ParserCallback htmlCallback = new MojoParserCallback( sb );
+
+ try
+ {
+ parser.parse( new StringReader( makeHtmlValid( html ) ), htmlCallback, true );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( e );
+ }
+
+ return sb.toString().replace( '\"', '\'' ); // for CDATA
+ }
+
+ /**
+ * ParserCallback implementation.
+ */
+ private static class MojoParserCallback
+ extends HTMLEditorKit.ParserCallback
+ {
+ /**
+ * Holds the index of the current item in a numbered list.
+ */
+ class Counter
+ {
+ public int value;
+ }
+
+ /**
+ * A flag whether the parser is currently in the body element.
+ */
+ private boolean body;
+
+ /**
+ * A flag whether the parser is currently processing preformatted text, actually a counter to track nesting.
+ */
+ private int preformatted;
+
+ /**
+ * The current indentation depth for the output.
+ */
+ private int depth;
+
+ /**
+ * A stack of {@link Counter} objects corresponding to the nesting of (un-)ordered lists. A
+ * null element denotes an unordered list.
+ */
+ private Stack numbering = new Stack();
+
+ /**
+ * A flag whether an implicit line break is pending in the output buffer. This flag is used to postpone the
+ * output of implicit line breaks until we are sure that are not to be merged with other implicit line
+ * breaks.
+ */
+ private boolean pendingNewline;
+
+ /**
+ * A flag whether we have just parsed a simple tag.
+ */
+ private boolean simpleTag;
+
+ /**
+ * The current buffer.
+ */
+ private final StringBuffer sb;
+
+ /**
+ * @param sb not null
+ */
+ public MojoParserCallback( StringBuffer sb )
+ {
+ this.sb = sb;
+ }
+
+ /** {@inheritDoc} */
+ public void handleSimpleTag( HTML.Tag t, MutableAttributeSet a, int pos )
+ {
+ simpleTag = true;
+ if ( body && HTML.Tag.BR.equals( t ) )
+ {
+ newline( false );
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void handleStartTag( HTML.Tag t, MutableAttributeSet a, int pos )
+ {
+ simpleTag = false;
+ if ( body && ( t.breaksFlow() || t.isBlock() ) )
+ {
+ newline( true );
+ }
+ if ( HTML.Tag.OL.equals( t ) )
+ {
+ numbering.push( new Counter() );
+ }
+ else if ( HTML.Tag.UL.equals( t ) )
+ {
+ numbering.push( null );
+ }
+ else if ( HTML.Tag.LI.equals( t ) )
+ {
+ Counter counter = numbering.peek();
+ if ( counter == null )
+ {
+ text( "-\t" );
+ }
+ else
+ {
+ text( ++counter.value + ".\t" );
+ }
+ depth++;
+ }
+ else if ( HTML.Tag.DD.equals( t ) )
+ {
+ depth++;
+ }
+ else if ( t.isPreformatted() )
+ {
+ preformatted++;
+ }
+ else if ( HTML.Tag.BODY.equals( t ) )
+ {
+ body = true;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void handleEndTag( HTML.Tag t, int pos )
+ {
+ if ( HTML.Tag.OL.equals( t ) || HTML.Tag.UL.equals( t ) )
+ {
+ numbering.pop();
+ }
+ else if ( HTML.Tag.LI.equals( t ) || HTML.Tag.DD.equals( t ) )
+ {
+ depth--;
+ }
+ else if ( t.isPreformatted() )
+ {
+ preformatted--;
+ }
+ else if ( HTML.Tag.BODY.equals( t ) )
+ {
+ body = false;
+ }
+ if ( body && ( t.breaksFlow() || t.isBlock() ) && !HTML.Tag.LI.equals( t ) )
+ {
+ if ( ( HTML.Tag.P.equals( t ) || HTML.Tag.PRE.equals( t ) || HTML.Tag.OL.equals( t )
+ || HTML.Tag.UL.equals( t ) || HTML.Tag.DL.equals( t ) )
+ && numbering.isEmpty() )
+ {
+ pendingNewline = false;
+ newline( pendingNewline );
+ }
+ else
+ {
+ newline( true );
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void handleText( char[] data, int pos )
+ {
+ /*
+ * NOTE: Parsers before JRE 1.6 will parse XML-conform simple tags like
as "
" followed by
+ * the text event ">..." so we need to watch out for the closing angle bracket.
+ */
+ int offset = 0;
+ if ( simpleTag && data[0] == '>' )
+ {
+ simpleTag = false;
+ for ( ++offset; offset < data.length && data[offset] <= ' '; )
+ {
+ offset++;
+ }
+ }
+ if ( offset < data.length )
+ {
+ String text = new String( data, offset, data.length - offset );
+ text( text );
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void flush()
+ {
+ flushPendingNewline();
+ }
+
+ /**
+ * Writes a line break to the plain text output.
+ *
+ * @param implicit A flag whether this is an explicit or implicit line break. Explicit line breaks are
+ * always written to the output whereas consecutive implicit line breaks are merged into a single
+ * line break.
+ */
+ private void newline( boolean implicit )
+ {
+ if ( implicit )
+ {
+ pendingNewline = true;
+ }
+ else
+ {
+ flushPendingNewline();
+ sb.append( '\n' );
+ }
+ }
+
+ /**
+ * Flushes a pending newline (if any).
+ */
+ private void flushPendingNewline()
+ {
+ if ( pendingNewline )
+ {
+ pendingNewline = false;
+ if ( sb.length() > 0 )
+ {
+ sb.append( '\n' );
+ }
+ }
+ }
+
+ /**
+ * Writes the specified character data to the plain text output. If the last output was a line break, the
+ * character data will automatically be prefixed with the current indent.
+ *
+ * @param data The character data, must not be null.
+ */
+ private void text( String data )
+ {
+ flushPendingNewline();
+ if ( sb.length() <= 0 || sb.charAt( sb.length() - 1 ) == '\n' )
+ {
+ for ( int i = 0; i < depth; i++ )
+ {
+ sb.append( '\t' );
+ }
+ }
+ String text;
+ if ( preformatted > 0 )
+ {
+ text = data;
+ }
+ else
+ {
+ text = data.replace( '\n', ' ' );
+ }
+ 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 packageNames = new HashMap();
+ @SuppressWarnings( "unchecked" )
+ List 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, Integer.valueOf( next ) );
+ }
+ else
+ {
+ packageNames.put( name, Integer.valueOf( 1 ) );
+ }
+ }
+ else
+ {
+ packageNames.put( "", Integer.valueOf( 1 ) );
+ }
+ }
+
+ String packageName = "";
+ int max = 0;
+ for ( Map.Entry entry : packageNames.entrySet() )
+ {
+ int value = entry.getValue().intValue();
+ if ( value > max )
+ {
+ max = value;
+ packageName = entry.getKey();
+ }
+ }
+
+ return packageName;
+ }
+
+ /**
+ * @param impl a Mojo implementation, not null
+ * @param project a MavenProject instance, could be null
+ * @return true is the Mojo implementation implements MavenReport,
+ * false otherwise.
+ * @throws IllegalArgumentException if any
+ */
+ @SuppressWarnings( "unchecked" )
+ public static boolean isMavenReport( String impl, MavenProject project )
+ throws IllegalArgumentException
+ {
+ if ( impl == null )
+ {
+ throw new IllegalArgumentException( "mojo implementation should be declared" );
+ }
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if ( project != null )
+ {
+ List classPathStrings;
+ try
+ {
+ classPathStrings = project.getCompileClasspathElements();
+ if ( project.getExecutionProject() != null )
+ {
+ classPathStrings.addAll( project.getExecutionProject().getCompileClasspathElements() );
+ }
+ }
+ catch ( DependencyResolutionRequiredException e )
+ {
+ throw new IllegalArgumentException( e );
+ }
+
+ List urls = new ArrayList( classPathStrings.size() );
+ for ( String classPathString : classPathStrings )
+ {
+ try
+ {
+ urls.add( new File( classPathString ).toURL() );
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new IllegalArgumentException( e );
+ }
+ }
+
+ classLoader = new URLClassLoader( urls.toArray( new URL[urls.size()] ), classLoader );
+ }
+
+ try
+ {
+ Class> clazz = Class.forName( impl, false, classLoader );
+
+ return MavenReport.class.isAssignableFrom( clazz );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ return false;
+ }
+ }
+
+}
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 b0680be..ee0b9c6 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
@@ -151,27 +151,27 @@ public class PluginDescriptorGenerator
w.startElement( "plugin" );
- PluginUtils.element( w, "name", pluginDescriptor.getName() );
+ GeneratorUtils.element( w, "name", pluginDescriptor.getName() );
if ( cleanDescription )
{
- PluginUtils.element( w, "description", PluginUtils.toText( pluginDescriptor.getDescription() ) );
+ GeneratorUtils.element( w, "description", GeneratorUtils.toText( pluginDescriptor.getDescription() ) );
}
else
{
- PluginUtils.element( w, "description", pluginDescriptor.getDescription() );
+ GeneratorUtils.element( w, "description", pluginDescriptor.getDescription() );
}
- PluginUtils.element( w, "groupId", pluginDescriptor.getGroupId() );
+ GeneratorUtils.element( w, "groupId", pluginDescriptor.getGroupId() );
- PluginUtils.element( w, "artifactId", pluginDescriptor.getArtifactId() );
+ GeneratorUtils.element( w, "artifactId", pluginDescriptor.getArtifactId() );
- PluginUtils.element( w, "version", pluginDescriptor.getVersion() );
+ GeneratorUtils.element( w, "version", pluginDescriptor.getVersion() );
- PluginUtils.element( w, "goalPrefix", pluginDescriptor.getGoalPrefix() );
+ GeneratorUtils.element( w, "goalPrefix", pluginDescriptor.getGoalPrefix() );
- PluginUtils.element( w, "isolatedRealm", "" + pluginDescriptor.isIsolatedRealm() );
+ GeneratorUtils.element( w, "isolatedRealm", "" + pluginDescriptor.isIsolatedRealm() );
- PluginUtils.element( w, "inheritedByDefault", "" + pluginDescriptor.isInheritedByDefault() );
+ GeneratorUtils.element( w, "inheritedByDefault", "" + pluginDescriptor.isInheritedByDefault() );
w.startElement( "mojos" );
@@ -186,7 +186,7 @@ public class PluginDescriptorGenerator
w.endElement();
- PluginUtils.writeDependencies( w, pluginDescriptor );
+ GeneratorUtils.writeDependencies( w, pluginDescriptor );
w.endElement();
@@ -232,7 +232,7 @@ public class PluginDescriptorGenerator
w.startElement( "description" );
if ( cleanDescription )
{
- w.writeText( PluginUtils.toText( mojoDescriptor.getDescription() ) );
+ w.writeText( GeneratorUtils.toText( mojoDescriptor.getDescription() ) );
}
else
{
@@ -247,44 +247,44 @@ public class PluginDescriptorGenerator
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
{
- PluginUtils.element( w, "requiresDependencyResolution", mojoDescriptor.isDependencyResolutionRequired() );
+ GeneratorUtils.element( w, "requiresDependencyResolution", mojoDescriptor.isDependencyResolutionRequired() );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- PluginUtils.element( w, "requiresDirectInvocation", "" + mojoDescriptor.isDirectInvocationOnly() );
+ GeneratorUtils.element( w, "requiresDirectInvocation", "" + mojoDescriptor.isDirectInvocationOnly() );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- PluginUtils.element( w, "requiresProject", "" + mojoDescriptor.isProjectRequired() );
+ GeneratorUtils.element( w, "requiresProject", "" + mojoDescriptor.isProjectRequired() );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- PluginUtils.element( w, "requiresReports", "" + mojoDescriptor.isRequiresReports() );
+ GeneratorUtils.element( w, "requiresReports", "" + mojoDescriptor.isRequiresReports() );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- PluginUtils.element( w, "aggregator", "" + mojoDescriptor.isAggregator() );
+ GeneratorUtils.element( w, "aggregator", "" + mojoDescriptor.isAggregator() );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- PluginUtils.element( w, "requiresOnline", "" + mojoDescriptor.isOnlineRequired() );
+ GeneratorUtils.element( w, "requiresOnline", "" + mojoDescriptor.isOnlineRequired() );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- PluginUtils.element( w, "inheritedByDefault", "" + mojoDescriptor.isInheritedByDefault() );
+ GeneratorUtils.element( w, "inheritedByDefault", "" + mojoDescriptor.isInheritedByDefault() );
// ----------------------------------------------------------------------
//
@@ -292,7 +292,7 @@ public class PluginDescriptorGenerator
if ( mojoDescriptor.getPhase() != null )
{
- PluginUtils.element( w, "phase", mojoDescriptor.getPhase() );
+ GeneratorUtils.element( w, "phase", mojoDescriptor.getPhase() );
}
// ----------------------------------------------------------------------
@@ -301,17 +301,17 @@ public class PluginDescriptorGenerator
if ( mojoDescriptor.getExecutePhase() != null )
{
- PluginUtils.element( w, "executePhase", mojoDescriptor.getExecutePhase() );
+ GeneratorUtils.element( w, "executePhase", mojoDescriptor.getExecutePhase() );
}
if ( mojoDescriptor.getExecuteGoal() != null )
{
- PluginUtils.element( w, "executeGoal", mojoDescriptor.getExecuteGoal() );
+ GeneratorUtils.element( w, "executeGoal", mojoDescriptor.getExecuteGoal() );
}
if ( mojoDescriptor.getExecuteLifecycle() != null )
{
- PluginUtils.element( w, "executeLifecycle", mojoDescriptor.getExecuteLifecycle() );
+ GeneratorUtils.element( w, "executeLifecycle", mojoDescriptor.getExecuteLifecycle() );
}
// ----------------------------------------------------------------------
@@ -397,11 +397,11 @@ public class PluginDescriptorGenerator
ExtendedMojoDescriptor extendedMojoDescriptor = (ExtendedMojoDescriptor) mojoDescriptor;
if ( extendedMojoDescriptor.getDependencyCollectionRequired() != null )
{
- PluginUtils.element( w, "requiresDependencyCollection",
+ GeneratorUtils.element( w, "requiresDependencyCollection",
extendedMojoDescriptor.getDependencyCollectionRequired() );
}
- PluginUtils.element( w, "threadSafe", String.valueOf( extendedMojoDescriptor.isThreadSafe() ) );
+ GeneratorUtils.element( w, "threadSafe", String.valueOf( extendedMojoDescriptor.isThreadSafe() ) );
}
// ----------------------------------------------------------------------
@@ -452,42 +452,42 @@ public class PluginDescriptorGenerator
w.startElement( "parameter" );
- PluginUtils.element( w, "name", parameter.getName() );
+ GeneratorUtils.element( w, "name", parameter.getName() );
if ( parameter.getAlias() != null )
{
- PluginUtils.element( w, "alias", parameter.getAlias() );
+ GeneratorUtils.element( w, "alias", parameter.getAlias() );
}
- PluginUtils.element( w, "type", parameter.getType() );
+ GeneratorUtils.element( w, "type", parameter.getType() );
if ( parameter.getDeprecated() != null )
{
if ( StringUtils.isEmpty( parameter.getDeprecated() ) )
{
- PluginUtils.element( w, "deprecated", "No reason given" );
+ GeneratorUtils.element( w, "deprecated", "No reason given" );
}
else
{
- PluginUtils.element( w, "deprecated", parameter.getDeprecated() );
+ GeneratorUtils.element( w, "deprecated", parameter.getDeprecated() );
}
}
if ( parameter.getImplementation() != null )
{
- PluginUtils.element( w, "implementation", parameter.getImplementation() );
+ GeneratorUtils.element( w, "implementation", parameter.getImplementation() );
}
- PluginUtils.element( w, "required", Boolean.toString( parameter.isRequired() ) );
+ GeneratorUtils.element( w, "required", Boolean.toString( parameter.isRequired() ) );
- PluginUtils.element( w, "editable", Boolean.toString( parameter.isEditable() ) );
+ GeneratorUtils.element( w, "editable", Boolean.toString( parameter.isEditable() ) );
if ( cleanDescription )
{
- PluginUtils.element( w, "description", PluginUtils.toText( parameter.getDescription() ) );
+ GeneratorUtils.element( w, "description", GeneratorUtils.toText( parameter.getDescription() ) );
}
else
{
- PluginUtils.element( w, "description", parameter.getDescription() );
+ GeneratorUtils.element( w, "description", parameter.getDescription() );
}
if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) || StringUtils.isNotEmpty(
@@ -553,14 +553,14 @@ public class PluginDescriptorGenerator
w.startElement( "requirement" );
- PluginUtils.element( w, "role", requirement.getRole() );
+ GeneratorUtils.element( w, "role", requirement.getRole() );
if ( requirement.getRoleHint() != null )
{
- PluginUtils.element( w, "role-hint", requirement.getRoleHint() );
+ GeneratorUtils.element( w, "role-hint", requirement.getRoleHint() );
}
- PluginUtils.element( w, "field-name", key );
+ GeneratorUtils.element( w, "field-name", key );
w.endElement();
}
@@ -591,7 +591,7 @@ public class PluginDescriptorGenerator
protected String rewriteHelpClassToMojoPackage( PluginToolsRequest request )
throws GeneratorException
{
- String destinationPackage = PluginUtils.discoverPackageName( request.getPluginDescriptor() );
+ String destinationPackage = GeneratorUtils.discoverPackageName( request.getPluginDescriptor() );
if ( StringUtils.isEmpty( destinationPackage ) )
{
return null;
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 d21c9b5..a903627 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
@@ -223,7 +223,7 @@ public class PluginHelpGenerator
String packageName = helpPackageName;
if ( StringUtils.isEmpty( packageName ) )
{
- packageName = PluginUtils.discoverPackageName( pluginDescriptor );
+ packageName = GeneratorUtils.discoverPackageName( pluginDescriptor );
}
return StringUtils.isEmpty( packageName ) ? HELP_MOJO_CLASS_NAME : packageName + '.' + HELP_MOJO_CLASS_NAME;
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
index fbd3a1c..a23f303 100644
--- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
@@ -24,7 +24,6 @@ import org.apache.maven.plugin.descriptor.Parameter;
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;
@@ -212,7 +211,7 @@ public class PluginXdocGenerator
w.writeMarkup( getString( "pluginxdoc.mojodescriptor.deprecated" ) );
w.endElement(); // p
w.startElement( "div" );
- w.writeMarkup( PluginUtils.makeHtmlValid( mojoDescriptor.getDeprecated() ) );
+ w.writeMarkup( GeneratorUtils.makeHtmlValid( mojoDescriptor.getDeprecated() ) );
w.endElement(); // div
}
@@ -222,7 +221,7 @@ public class PluginXdocGenerator
w.startElement( "div" );
if ( StringUtils.isNotEmpty( mojoDescriptor.getDescription() ) )
{
- w.writeMarkup( PluginUtils.makeHtmlValid( mojoDescriptor.getDescription() ) );
+ w.writeMarkup( GeneratorUtils.makeHtmlValid( mojoDescriptor.getDescription() ) );
}
else
{
@@ -247,7 +246,7 @@ public class PluginXdocGenerator
*/
private void writeReportNotice( MojoDescriptor mojoDescriptor, XMLWriter w )
{
- if ( PluginUtils.isMavenReport( mojoDescriptor.getImplementation(), project ) )
+ if ( GeneratorUtils.isMavenReport( mojoDescriptor.getImplementation(), project ) )
{
w.startElement( "p" );
w.writeMarkup( getString( "pluginxdoc.mojodescriptor.notice.note" ) );
@@ -534,14 +533,14 @@ public class PluginXdocGenerator
{
w.startElement( "div" );
w.writeMarkup( format( "pluginxdoc.mojodescriptor.parameter.deprecated",
- PluginUtils.makeHtmlValid( parameter.getDeprecated() ) ) );
+ GeneratorUtils.makeHtmlValid( parameter.getDeprecated() ) ) );
w.endElement(); // div
}
w.startElement( "div" );
if ( StringUtils.isNotEmpty( parameter.getDescription() ) )
{
- w.writeMarkup( PluginUtils.makeHtmlValid( parameter.getDescription() ) );
+ w.writeMarkup( GeneratorUtils.makeHtmlValid( parameter.getDescription() ) );
}
else
{
@@ -729,11 +728,11 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) )
{
description = format( "pluginxdoc.mojodescriptor.parameter.deprecated",
- PluginUtils.makeHtmlValid( parameter.getDeprecated() ) );
+ GeneratorUtils.makeHtmlValid( parameter.getDeprecated() ) );
}
else if ( StringUtils.isNotEmpty( parameter.getDescription() ) )
{
- description = PluginUtils.makeHtmlValid( parameter.getDescription() );
+ description = GeneratorUtils.makeHtmlValid( parameter.getDescription() );
}
else
{
diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
new file mode 100644
index 0000000..d8d469e
--- /dev/null
+++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
@@ -0,0 +1,205 @@
+package org.apache.maven.tools.plugin.generator;
+
+/*
+ * 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.descriptor.PluginDescriptor;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.component.repository.ComponentDependency;
+import org.codehaus.plexus.util.xml.CompactXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+import java.io.StringWriter;
+import java.util.Collections;
+
+/**
+ * @author jdcasey
+ */
+public class GeneratorUtilsTest
+ extends AbstractMojoTestCase
+{
+ public void testShouldWriteDependencies()
+ throws Exception
+ {
+ ComponentDependency dependency = new ComponentDependency();
+ dependency.setArtifactId( "testArtifactId" );
+ dependency.setGroupId( "testGroupId" );
+ dependency.setType( "pom" );
+ dependency.setVersion( "0.0.0" );
+
+ PluginDescriptor descriptor = new PluginDescriptor();
+ descriptor.setDependencies( Collections.singletonList( dependency ) );
+
+ StringWriter sWriter = new StringWriter();
+ XMLWriter writer = new CompactXMLWriter( sWriter );
+
+ GeneratorUtils.writeDependencies( writer, descriptor );
+
+ String output = sWriter.toString();
+
+ String pattern =
+ "" + "" + "testGroupId"
+ + "testArtifactId" + "pom" + "0.0.0"
+ + "" + "";
+
+ assertEquals( pattern, output );
+ }
+
+ public void testMakeHtmlValid()
+ {
+ String javadoc = null;
+ assertEquals( "", GeneratorUtils.makeHtmlValid( javadoc ) );
+ javadoc = "";
+ assertEquals( "", GeneratorUtils.makeHtmlValid( javadoc ) );
+
+ // true HTML
+ javadoc = "Generates something for the project.";
+ assertEquals( "Generates something for the project.", GeneratorUtils.makeHtmlValid( javadoc ) );
+
+ // wrong HTML
+ javadoc = "Generates something for the project.";
+ assertEquals( "Generates something for the project.", GeneratorUtils.makeHtmlValid( javadoc ) );
+
+ // wrong XHTML
+ javadoc = "Line1
Line2";
+ assertEquals( "Line1
Line2", GeneratorUtils.makeHtmlValid( javadoc ).replaceAll( "\\s", "" ) );
+
+ // special characters
+ javadoc = "& & < > \u00A0";
+ assertEquals( "& & < > \u00A0", GeneratorUtils.makeHtmlValid( javadoc ) );
+
+ // non ASCII characters
+ javadoc = "\u00E4 \u00F6 \u00FC \u00DF";
+ assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
+
+ // non Latin1 characters
+ javadoc = "\u0130 \u03A3 \u05D0 \u06DE";
+ assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
+ }
+
+ public void testDecodeJavadocTags()
+ {
+ String javadoc = null;
+ assertEquals( "", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "";
+ assertEquals( "", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@code text}";
+ assertEquals( "text", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@code }";
+ assertEquals( "<A&B>", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@literal text}";
+ assertEquals( "text", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@literal text} {@literal text}";
+ assertEquals( "text text", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@literal }";
+ assertEquals( "<A&B>", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@link Class}";
+ assertEquals( "Class", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain Class}";
+ assertEquals( "Class", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain #field}";
+ assertEquals( "field", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain Class#field}";
+ assertEquals( "Class.field", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain #method()}";
+ assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain #method(Object arg)}";
+ assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain #method(Object, String)}";
+ assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain #method(Object, String) label}";
+ assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain Class#method(Object, String)}";
+ assertEquals( "Class.method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
+
+ javadoc = "{@linkplain Class#method(Object, String) label}";
+ assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
+ }
+
+ public void testToText()
+ throws Exception
+ {
+ String javadoc = null;
+ assertEquals( "", GeneratorUtils.toText( javadoc ) );
+ javadoc = "";
+ assertEquals( "", GeneratorUtils.toText( javadoc ) );
+
+ // line breaks
+ javadoc = "Line1\nLine2";
+ assertEquals( "Line1 Line2", GeneratorUtils.toText( javadoc ) );
+ javadoc = "Line1\rLine2";
+ assertEquals( "Line1 Line2", GeneratorUtils.toText( javadoc ) );
+ javadoc = "Line1\r\nLine2";
+ assertEquals( "Line1 Line2", GeneratorUtils.toText( javadoc ) );
+ javadoc = "Line1
Line2";
+ assertEquals( "Line1\nLine2", GeneratorUtils.toText( javadoc ) );
+
+ // true HTML
+ javadoc = "Generates something for the project.";
+ assertEquals( "Generates something for the project.", GeneratorUtils.toText( javadoc ) );
+
+ // wrong HTML
+ javadoc = "Generates something for the project.";
+ assertEquals( "Generates something for the project.", GeneratorUtils.toText( javadoc ) );
+
+ // javadoc inline tags
+ javadoc = "Generates {@code something} for the project.";
+ assertEquals( "Generates something for the project.", GeneratorUtils.toText( javadoc ) );
+ }
+
+ public void testIsMavenReport()
+ throws Exception
+ {
+ try
+ {
+ GeneratorUtils.isMavenReport( null, null );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ assertTrue( true );
+ }
+
+ String impl = "org.apache.maven.tools.plugin.generator.stubs.MavenReportStub";
+
+ MavenProjectStub stub = new MavenProjectStub();
+ stub.setCompileSourceRoots( Collections.singletonList( getBasedir() + "/target/classes" ) );
+
+ assertTrue( GeneratorUtils.isMavenReport( impl, stub ) );
+
+ impl = "org.apache.maven.tools.plugin.util.stubs.MojoStub";
+ assertFalse( GeneratorUtils.isMavenReport( impl, stub ) );
+ }
+
+}
diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/stubs/MavenReportStub.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/stubs/MavenReportStub.java
similarity index 98%
rename from maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/stubs/MavenReportStub.java
rename to maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/stubs/MavenReportStub.java
index eed9ea7..918dc54 100644
--- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/stubs/MavenReportStub.java
+++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/stubs/MavenReportStub.java
@@ -1,4 +1,4 @@
-package org.apache.maven.tools.plugin.util.stubs;
+package org.apache.maven.tools.plugin.generator.stubs;
/*
* Licensed to the Apache Software Foundation (ASF) under one