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