1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.codehaus.mojo.license;
27
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugin.MojoFailureException;
30 import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer;
31
32 import java.util.*;
33
34
35
36
37
38
39
40
41
42
43 public class CommentStyleListMojo
44 extends AbstractLicenseMojo
45 {
46
47
48
49
50
51
52
53 private boolean detail;
54
55
56
57
58
59
60
61 private Map<String, FileHeaderTransformer> transformers;
62
63 @Override
64 protected void init()
65 throws Exception
66 {
67
68 }
69
70 @Override
71 public void doAction()
72 throws MojoExecutionException, MojoFailureException
73 {
74
75 StringBuilder buffer = new StringBuilder();
76 if ( isVerbose() )
77 {
78 buffer.append( "\n\n-------------------------------------------------------------------------------\n" );
79 buffer.append( " license-maven-plugin\n" );
80 buffer.append( "-------------------------------------------------------------------------------\n\n" );
81 }
82 List<String> names = new ArrayList<String>( transformers.keySet() );
83 Collections.sort( names );
84
85 int maxLength = 0;
86 int maxDLength = 0;
87 for ( String name : names )
88 {
89 if ( name.length() > maxLength )
90 {
91 maxLength = name.length();
92 }
93 FileHeaderTransformer transformer = transformers.get( name );
94 if ( transformer.getDescription().length() > maxDLength )
95 {
96 maxDLength = transformer.getDescription().length();
97 }
98 }
99
100 String pattern = " - %1$-" + maxLength + "s : %2$-" + maxDLength + "s, extensions : %3$s\n";
101
102 buffer.append( "List of available comment styles:\n\n" );
103 for ( String transformerName : names )
104 {
105 FileHeaderTransformer transformer = transformers.get( transformerName );
106 buffer.append( String.format( pattern, transformerName, transformer.getDescription(),
107 Arrays.toString( transformer.getDefaultAcceptedExtensions() ) ) );
108 if ( detail )
109 {
110 buffer.append( "\n example : \n" );
111 buffer.append( transformer.boxComment( "header", true ) );
112 buffer.append( '\n' );
113 }
114 }
115
116 getLog().info( buffer.toString() );
117 }
118
119 public boolean isDetail()
120 {
121 return detail;
122 }
123
124 public void setDetail( boolean detail )
125 {
126 this.detail = detail;
127 }
128
129 public Map<String, FileHeaderTransformer> getTransformers()
130 {
131 return transformers;
132 }
133
134 public void setTransformers( Map<String, FileHeaderTransformer> transformers )
135 {
136 this.transformers = transformers;
137 }
138 }