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
39 public class CLIManagerTest
40 extends PlexusTestCase
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 @SuppressWarnings( "unchecked" )
59 List<Option> optList = new ArrayList<Option>( options.getOptions() );
60 Collections.sort( optList, new OptionComparator() );
61 return optList;
62 }
63 }
64
65 public String getOptionsAsHtml()
66 {
67 StringBuilder sb = new StringBuilder();
68 boolean a = true;
69 sb.append( "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>" );
70 for ( Option option : new CLIManagerExtension().getOptions() )
71 {
72 a = !a;
73 sb.append( "<tr class='" + ( a ? 'a' : 'b' ) + "'><td><code>-<a name='" );
74 sb.append( option.getOpt() );
75 sb.append( "'>" );
76 sb.append( option.getOpt() );
77 sb.append( "</a>,--<a name='" );
78 sb.append( option.getLongOpt() );
79 sb.append( "'>" );
80 sb.append( option.getLongOpt() );
81 sb.append( "</a>" );
82 if ( option.hasArg() )
83 {
84 if ( option.hasArgName() )
85 {
86 sb.append( " <" ).append( option.getArgName() ).append( ">" );
87 }
88 else
89 {
90 sb.append( ' ' );
91 }
92 }
93 sb.append( "</code></td><td>" );
94 sb.append( option.getDescription() );
95 sb.append( "</td></tr>" );
96 sb.append( LS );
97 }
98 sb.append( "</table>" );
99 return sb.toString();
100 }
101
102 public void testOptionsAsHtml()
103 throws IOException
104 {
105 File options = getTestFile( "target/test-classes/options.html" );
106 FileUtils.fileWrite( options, "UTF-8", getOptionsAsHtml() );
107 }
108 }