001package org.andromda.maven.plugin.site;
002
003import java.util.ArrayList;
004import java.util.Iterator;
005import java.util.List;
006
007import org.apache.maven.plugin.AbstractMojo;
008import org.apache.maven.plugin.MojoExecutionException;
009
010/**
011 * Display help information on andromda-site-plugin.<br/> Call <pre>  mvn andromda-site:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
012 *
013 * @version generated on Thu Sep 18 16:30:53 EDT 2014
014 * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.9)
015 * @goal help
016 * @requiresProject false
017 * @threadSafe
018 */
019public class HelpMojo
020    extends AbstractMojo
021{
022    /**
023     * If <code>true</code>, display all settable properties for each goal.
024     * 
025     * @parameter expression="${detail}" default-value="false"
026     */
027    private boolean detail;
028
029    /**
030     * The name of the goal for which to show help. If unspecified, all goals will be displayed.
031     * 
032     * @parameter expression="${goal}"
033     */
034    private java.lang.String goal;
035
036    /**
037     * The maximum length of a display line, should be positive.
038     * 
039     * @parameter expression="${lineLength}" default-value="80"
040     */
041    private int lineLength;
042
043    /**
044     * The number of spaces per indentation level, should be positive.
045     * 
046     * @parameter expression="${indentSize}" default-value="2"
047     */
048    private int indentSize;
049
050
051    /** {@inheritDoc} */
052    public void execute()
053        throws MojoExecutionException
054    {
055        if ( lineLength <= 0 )
056        {
057            getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
058            lineLength = 80;
059        }
060        if ( indentSize <= 0 )
061        {
062            getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
063            indentSize = 2;
064        }
065
066        StringBuffer sb = new StringBuffer();
067
068        append( sb, "org.andromda.maven.plugins.site:andromda-site-plugin:3.5-SNAPSHOT", 0 );
069        append( sb, "", 0 );
070
071        append( sb, "AndroMDA Site Plugin", 0 );
072        append( sb, "A plugin that enhances the maven site plugin to suit AndroMDA\'s modifications. It creates the namespace and profile documentation, copy and unpack site artifacts.", 1 );
073        append( sb, "", 0 );
074
075        if ( goal == null || goal.length() <= 0 )
076        {
077            append( sb, "This plugin has 5 goals:", 0 );
078            append( sb, "", 0 );
079        }
080
081        if ( goal == null || goal.length() <= 0 || "copy-documentation".equals( goal ) )
082        {
083            append( sb, "andromda-site:copy-documentation", 0 );
084            append( sb, "Goal that copies the required AndroMDA site files to suitable locations preparing for deployment.", 1 );
085            append( sb, "", 0 );
086            if ( detail )
087            {
088                append( sb, "Available parameters:", 1 );
089                append( sb, "", 0 );
090
091                append( sb, "animalQuizOutputDirectory", 2 );
092                append( sb, "Path to the destination directory to copy the animal-quiz model", 3 );
093                append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
094                append( sb, "", 0 );
095
096                append( sb, "animalQuizSourcePath", 2 );
097                append( sb, "Path to the animal-quiz model", 3 );
098                append( sb, "Expression: ${basedir}/../samples/animal-quiz/mda/src/main/uml/AnimalQuiz.xml.zip", 3 );
099                append( sb, "", 0 );
100
101                append( sb, "carRentalSystemOutputDirectory", 2 );
102                append( sb, "Path to the destination directory to copy the car-rental-system model", 3 );
103                append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
104                append( sb, "", 0 );
105
106                append( sb, "carRentalSystemSourcePath", 2 );
107                append( sb, "Path to the car-rental-system model", 3 );
108                append( sb, "Expression: ${basedir}/../samples/car-rental-system/mda/src/main/uml/CarRentalSystem.xml.zip", 3 );
109                append( sb, "", 0 );
110
111                append( sb, "documentationOutputDirectory", 2 );
112                append( sb, "The documentation output directory used to copy the generated site reporting artifacts", 3 );
113                append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
114                append( sb, "", 0 );
115
116                append( sb, "documentationSourceDirectory", 2 );
117                append( sb, "The directory containing the documentation site reporting artifacts", 3 );
118                append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
119                append( sb, "", 0 );
120
121                append( sb, "mappingsOutputDirectory", 2 );
122                append( sb, "Path to the mapping destination directory", 3 );
123                append( sb, "Expression: ${project.reporting.outputDirectory}/mappings", 3 );
124                append( sb, "", 0 );
125
126                append( sb, "mappingsSourceDirectory", 2 );
127                append( sb, "Path to the mapping source directory containing the mappings", 3 );
128                append( sb, "Expression: ${basedir}/../andromda-etc/mappings", 3 );
129                append( sb, "", 0 );
130
131                append( sb, "projectName (Default: ${project.name})", 2 );
132                append( sb, "The name of the project injected from pom.xml. Not used.", 3 );
133                append( sb, "", 0 );
134            }
135        }
136
137        if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
138        {
139            append( sb, "andromda-site:help", 0 );
140            append( sb, "Display help information on andromda-site-plugin.\nCall\n\u00a0\u00a0mvn\u00a0andromda-site:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
141            append( sb, "", 0 );
142            if ( detail )
143            {
144                append( sb, "Available parameters:", 1 );
145                append( sb, "", 0 );
146
147                append( sb, "detail (Default: false)", 2 );
148                append( sb, "If true, display all settable properties for each goal.", 3 );
149                append( sb, "Expression: ${detail}", 3 );
150                append( sb, "", 0 );
151
152                append( sb, "goal", 2 );
153                append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
154                append( sb, "Expression: ${goal}", 3 );
155                append( sb, "", 0 );
156
157                append( sb, "indentSize (Default: 2)", 2 );
158                append( sb, "The number of spaces per indentation level, should be positive.", 3 );
159                append( sb, "Expression: ${indentSize}", 3 );
160                append( sb, "", 0 );
161
162                append( sb, "lineLength (Default: 80)", 2 );
163                append( sb, "The maximum length of a display line, should be positive.", 3 );
164                append( sb, "Expression: ${lineLength}", 3 );
165                append( sb, "", 0 );
166            }
167        }
168
169        if ( goal == null || goal.length() <= 0 || "namespace-xsl".equals( goal ) )
170        {
171            append( sb, "andromda-site:namespace-xsl", 0 );
172            append( sb, "Used to perform the transformation of the namespace XSL document to namespace.xml xdoc format within the site plugin.", 1 );
173            append( sb, "", 0 );
174            if ( detail )
175            {
176                append( sb, "Available parameters:", 1 );
177                append( sb, "", 0 );
178
179                append( sb, "namespaceDocumentPath", 2 );
180                append( sb, "Path to the project namespace.xml", 3 );
181                append( sb, "Expression: ${basedir}/src/main/resources/META-INF/andromda/namespace.xml", 3 );
182                append( sb, "", 0 );
183
184                append( sb, "namespaceOutputPath", 2 );
185                append( sb, "Path to the project namespace document output", 3 );
186                append( sb, "Expression: ${basedir}/src/site/xdoc/namespace.xml", 3 );
187                append( sb, "", 0 );
188
189                append( sb, "namespaceTransformationPath", 2 );
190                append( sb, "Not used", 3 );
191                append( sb, "Expression: ${basedir}/src/main/resources/META-INF/xsl/namespace.xsl", 3 );
192                append( sb, "", 0 );
193
194                append( sb, "projectName (Default: ${project.name})", 2 );
195                append( sb, "The name of the project injected from pom.xml", 3 );
196                append( sb, "", 0 );
197            }
198        }
199
200        if ( goal == null || goal.length() <= 0 || "profile-xsl".equals( goal ) )
201        {
202            append( sb, "andromda-site:profile-xsl", 0 );
203            append( sb, "Used to perform the transformation of the profile XSL document to profile.xml xdoc format within the site plugin.", 1 );
204            append( sb, "", 0 );
205            if ( detail )
206            {
207                append( sb, "Available parameters:", 1 );
208                append( sb, "", 0 );
209
210                append( sb, "profileDocumentPath", 2 );
211                append( sb, "Path to the project profile.xml", 3 );
212                append( sb, "Expression: ${basedir}/src/main/resources/META-INF/andromda/profile.xml", 3 );
213                append( sb, "", 0 );
214
215                append( sb, "profileOutputPath", 2 );
216                append( sb, "Path to the project profile document output", 3 );
217                append( sb, "Expression: ${basedir}/src/site/xdoc/profile.xml", 3 );
218                append( sb, "", 0 );
219
220                append( sb, "profileTransformationPath", 2 );
221                append( sb, "Not used.", 3 );
222                append( sb, "Expression: ${basedir}/src/main/resources/META-INF/xsl/profile.xsl", 3 );
223                append( sb, "", 0 );
224
225                append( sb, "projectName (Default: ${project.name})", 2 );
226                append( sb, "The name of the project injected from pom.xml", 3 );
227                append( sb, "", 0 );
228            }
229        }
230
231        if ( goal == null || goal.length() <= 0 || "unpack-documentation".equals( goal ) )
232        {
233            append( sb, "andromda-site:unpack-documentation", 0 );
234            append( sb, "Goal that unpacks the required AndroMDA site zip packages to suitable locations preparing for deployment.", 1 );
235            append( sb, "", 0 );
236            if ( detail )
237            {
238                append( sb, "Available parameters:", 1 );
239                append( sb, "", 0 );
240
241                append( sb, "jmiApiOutputDirectory", 2 );
242                append( sb, "Path to the JMI 1.4 API destination extraction directory", 3 );
243                append( sb, "Expression: ${basedir}/../../target/site", 3 );
244                append( sb, "", 0 );
245
246                append( sb, "jmiApiSourcePath", 2 );
247                append( sb, "Path to the JMI 1.4 API zip source", 3 );
248                append( sb, "Expression: ${basedir}/src/site/resources/resources/jmi-uml1.4.zip", 3 );
249                append( sb, "", 0 );
250
251                append( sb, "projectName (Default: ${project.name})", 2 );
252                append( sb, "The name of the project injected from pom.xml. Not used.", 3 );
253                append( sb, "", 0 );
254
255                append( sb, "umlDocCarRentalSampleOutputDirectory", 2 );
256                append( sb, "Path to the UmlDoc car-rental-sample extraction directory", 3 );
257                append( sb, "Expression: ${basedir}/../../target/site", 3 );
258                append( sb, "", 0 );
259
260                append( sb, "umlDocCarRentalSampleSourcePath", 2 );
261                append( sb, "Path to the UmlDoc car-rental-sample zip source", 3 );
262                append( sb, "Expression: ${basedir}/src/site/resources/resources/car-rental-umldoc.zip", 3 );
263                append( sb, "", 0 );
264            }
265        }
266
267        if ( getLog().isInfoEnabled() )
268        {
269            getLog().info( sb.toString() );
270        }
271    }
272
273    /**
274     * <p>Repeat a String <code>n</code> times to form a new string.</p>
275     *
276     * @param str String to repeat
277     * @param repeat number of times to repeat str
278     * @return String with repeated String
279     * @throws NegativeArraySizeException if <code>repeat < 0</code>
280     * @throws NullPointerException if str is <code>null</code>
281     */
282    private static String repeat( String str, int repeat )
283    {
284        StringBuffer buffer = new StringBuffer( repeat * str.length() );
285
286        for ( int i = 0; i < repeat; i++ )
287        {
288            buffer.append( str );
289        }
290
291        return buffer.toString();
292    }
293
294    /** 
295     * Append a description to the buffer by respecting the indentSize and lineLength parameters.
296     * <b>Note</b>: The last character is always a new line.
297     * 
298     * @param sb The buffer to append the description, not <code>null</code>.
299     * @param description The description, not <code>null</code>.
300     * @param indent The base indentation level of each line, must not be negative.
301     */
302    private void append( StringBuffer sb, String description, int indent )
303    {
304        for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
305        {
306            sb.append( it.next().toString() ).append( '\n' );
307        }
308    }
309
310    /** 
311     * Splits the specified text into lines of convenient display length.
312     * 
313     * @param text The text to split into lines, must not be <code>null</code>.
314     * @param indent The base indentation level of each line, must not be negative.
315     * @param indentSize The size of each indentation, must not be negative.
316     * @param lineLength The length of the line, must not be negative.
317     * @return The sequence of display lines, never <code>null</code>.
318     * @throws NegativeArraySizeException if <code>indent < 0</code>
319     */
320    private static List toLines( String text, int indent, int indentSize, int lineLength )
321    {
322        List lines = new ArrayList();
323
324        String ind = repeat( "\t", indent );
325        String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
326        for ( int i = 0; i < plainLines.length; i++ )
327        {
328            toLines( lines, ind + plainLines[i], indentSize, lineLength );
329        }
330
331        return lines;
332    }
333
334    /** 
335     * Adds the specified line to the output sequence, performing line wrapping if necessary.
336     * 
337     * @param lines The sequence of display lines, must not be <code>null</code>.
338     * @param line The line to add, must not be <code>null</code>.
339     * @param indentSize The size of each indentation, must not be negative.
340     * @param lineLength The length of the line, must not be negative.
341     */
342    private static void toLines( List lines, String line, int indentSize, int lineLength )
343    {
344        int lineIndent = getIndentLevel( line );
345        StringBuffer buf = new StringBuffer( 256 );
346        String[] tokens = line.split( " +" );
347        for ( int i = 0; i < tokens.length; i++ )
348        {
349            String token = tokens[i];
350            if ( i > 0 )
351            {
352                if ( buf.length() + token.length() >= lineLength )
353                {
354                    lines.add( buf.toString() );
355                    buf.setLength( 0 );
356                    buf.append( repeat( " ", lineIndent * indentSize ) );
357                }
358                else
359                {
360                    buf.append( ' ' );
361                }
362            }
363            for ( int j = 0; j < token.length(); j++ )
364            {
365                char c = token.charAt( j );
366                if ( c == '\t' )
367                {
368                    buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
369                }
370                else if ( c == '\u00A0' )
371                {
372                    buf.append( ' ' );
373                }
374                else
375                {
376                    buf.append( c );
377                }
378            }
379        }
380        lines.add( buf.toString() );
381    }
382
383    /** 
384     * Gets the indentation level of the specified line.
385     * 
386     * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
387     * @return The indentation level of the line.
388     */
389    private static int getIndentLevel( String line )
390    {
391        int level = 0;
392        for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
393        {
394            level++;
395        }
396        for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
397        {
398            if ( line.charAt( i ) == '\t' )
399            {
400                level++;
401                break;
402            }
403        }
404        return level;
405    }
406}