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.util.FileUtils;
32
33 import junit.framework.TestCase;
34
35
36
37
38
39 public class CLIManagerDocumentationTest
40 extends TestCase
41 {
42 private final static String LS = System.getProperty( "line.separator" );
43
44 private static class OptionComparator
45 implements Comparator<Option>
46 {
47 public int compare( Option opt1, Option opt2 )
48 {
49 return opt1.getOpt().compareToIgnoreCase( opt2.getOpt() );
50 }
51 }
52
53 private static class CLIManagerExtension
54 extends CLIManager
55 {
56 public Collection<Option> getOptions()
57 {
58 List<Option> optList = new ArrayList<>( options.getOptions() );
59 Collections.sort( optList, new OptionComparator() );
60 return optList;
61 }
62 }
63
64 public String getOptionsAsHtml()
65 {
66 StringBuilder sb = new StringBuilder( 512 );
67 boolean a = true;
68 sb.append( "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>" );
69 for ( Option option : new CLIManagerExtension().getOptions() )
70 {
71 a = !a;
72 sb.append( "<tr class='" ).append( a ? 'a' : 'b' ).append( "'><td><code>-<a name='" );
73 sb.append( option.getOpt() );
74 sb.append( "'>" );
75 sb.append( option.getOpt() );
76 sb.append( "</a>,--<a name='" );
77 sb.append( option.getLongOpt() );
78 sb.append( "'>" );
79 sb.append( option.getLongOpt() );
80 sb.append( "</a>" );
81 if ( option.hasArg() )
82 {
83 if ( option.hasArgName() )
84 {
85 sb.append( " <" ).append( option.getArgName() ).append( ">" );
86 }
87 else
88 {
89 sb.append( ' ' );
90 }
91 }
92 sb.append( "</code></td><td>" );
93 sb.append( option.getDescription() );
94 sb.append( "</td></tr>" );
95 sb.append( LS );
96 }
97 sb.append( "</table>" );
98 return sb.toString();
99 }
100
101 public void testOptionsAsHtml()
102 throws IOException
103 {
104 File options = new File( "target/test-classes/options.html" );
105 FileUtils.fileWrite( options, "UTF-8", getOptionsAsHtml() );
106 }
107
108 }