1 package org.apache.maven.plugin.coreit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.AbstractMojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.reporting.MavenReport;
26 import org.apache.maven.reporting.MavenReportException;
27
28 import org.codehaus.doxia.sink.Sink;
29
30 import java.io.File;
31 import java.io.FileOutputStream;
32 import java.io.IOException;
33 import java.io.OutputStream;
34 import java.util.Locale;
35 import java.util.Properties;
36
37
38
39
40
41
42
43
44
45 public class InfoReport
46 extends AbstractMojo
47 implements MavenReport
48 {
49
50
51
52
53
54
55
56
57 private File basedir;
58
59
60
61
62
63
64
65
66 private String infoFile = "info.properties";
67
68
69
70
71
72
73 private File outputDirectory;
74
75
76
77
78 private Locale locale;
79
80
81
82
83
84
85
86 public void execute()
87 throws MojoExecutionException, MojoFailureException
88 {
89 getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + infoFile );
90
91 if ( infoFile == null || infoFile.length() <= 0 )
92 {
93 throw new MojoFailureException( "Path name for output file has not been specified" );
94 }
95
96 File outputFile = new File( outputDirectory, infoFile );
97 if ( !outputFile.isAbsolute() )
98 {
99 outputFile = new File( new File( basedir, outputDirectory.getPath() ), infoFile ).getAbsoluteFile();
100 }
101
102 Properties props = new Properties();
103 props.setProperty( "site.output.directory", outputDirectory.getPath() );
104 if ( locale != null )
105 {
106 props.setProperty( "locale.language", locale.getLanguage() );
107 props.setProperty( "locale.country", locale.getCountry() );
108 props.setProperty( "locale.variant", locale.getVariant() );
109 }
110
111 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile );
112
113 OutputStream out = null;
114 try
115 {
116 outputFile.getParentFile().mkdirs();
117 out = new FileOutputStream( outputFile );
118 props.store( out, "MAVEN-CORE-IT-LOG" );
119 }
120 catch ( IOException e )
121 {
122 throw new MojoExecutionException( "Output file could not be created: " + outputFile, e );
123 }
124 finally
125 {
126 if ( out != null )
127 {
128 try
129 {
130 out.close();
131 }
132 catch ( IOException e )
133 {
134
135 }
136 }
137 }
138
139 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + outputFile );
140 }
141
142
143
144
145
146
147 public void generate( Sink sink, Locale locale )
148 throws MavenReportException
149 {
150 this.locale = locale;
151 try
152 {
153 execute();
154 }
155 catch ( Exception e )
156 {
157 throw new MavenReportException( "Report could not be created", e );
158 }
159 }
160
161 public String getOutputName()
162 {
163 return "info";
164 }
165
166 public String getCategoryName()
167 {
168 return "Project Reports";
169 }
170
171 public String getName( Locale locale )
172 {
173 return "name";
174 }
175
176 public String getDescription( Locale locale )
177 {
178 return "description";
179 }
180
181 public void setReportOutputDirectory( File outputDirectory )
182 {
183 this.outputDirectory = outputDirectory;
184 }
185
186 public File getReportOutputDirectory()
187 {
188 return outputDirectory;
189 }
190
191 public boolean isExternalReport()
192 {
193 return true;
194 }
195
196 public boolean canGenerateReport()
197 {
198 return true;
199 }
200
201 }