1 package org.apache.maven.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.Comparator;
28 import java.util.List;
29
30 import org.apache.commons.cli.Option;
31 import org.codehaus.plexus.PlexusTestCase;
32 import org.codehaus.plexus.util.FileUtils;
33
34
35
36
37
38 public class CLIManagerDocumentationTest
39 extends PlexusTestCase
40 {
41 private final static String LS = System.getProperty( "line.separator" );
42
43 private static class OptionComparator
44 implements Comparator<Option>
45 {
46 public int compare( Option opt1, Option opt2 )
47 {
48 return opt1.getOpt().compareToIgnoreCase( opt2.getOpt() );
49 }
50 }
51
52 private static class CLIManagerExtension
53 extends CLIManager
54 {
55 public Collection<Option> getOptions()
56 {
57 List<Option> optList = new ArrayList<>( options.getOptions() );
58 Collections.sort( optList, new OptionComparator() );
59 return optList;
60 }
61 }
62
63 public String getOptionsAsHtml()
64 {
65 StringBuilder sb = new StringBuilder( 512 );
66 boolean a = true;
67 sb.append( "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>" );
68 for ( Option option : new CLIManagerExtension().getOptions() )
69 {
70 a = !a;
71 sb.append( "<tr class='" ).append( a ? 'a' : 'b' ).append( "'><td><code>-<a name='" );
72 sb.append( option.getOpt() );
73 sb.append( "'>" );
74 sb.append( option.getOpt() );
75 sb.append( "</a>,--<a name='" );
76 sb.append( option.getLongOpt() );
77 sb.append( "'>" );
78 sb.append( option.getLongOpt() );
79 sb.append( "</a>" );
80 if ( option.hasArg() )
81 {
82 if ( option.hasArgName() )
83 {
84 sb.append( " <" ).append( option.getArgName() ).append( ">" );
85 }
86 else
87 {
88 sb.append( ' ' );
89 }
90 }
91 sb.append( "</code></td><td>" );
92 sb.append( option.getDescription() );
93 sb.append( "</td></tr>" );
94 sb.append( LS );
95 }
96 sb.append( "</table>" );
97 return sb.toString();
98 }
99
100 public void testOptionsAsHtml()
101 throws IOException
102 {
103 File options = getTestFile( "target/test-classes/options.html" );
104 FileUtils.fileWrite( options, "UTF-8", getOptionsAsHtml() );
105 }
106
107 }