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.codehaus.doxia.sink.Sink;
27
28 import java.io.File;
29 import java.lang.reflect.InvocationHandler;
30 import java.lang.reflect.Method;
31 import java.lang.reflect.Proxy;
32 import java.util.List;
33 import java.util.Locale;
34
35
36
37
38
39
40
41
42
43
44
45 public class GenerateMojo
46 extends AbstractMojo
47 {
48
49
50
51
52
53
54 private File outputDirectory;
55
56
57
58
59
60
61 private String language = "en";
62
63
64
65
66
67
68 private boolean ignoreErrors;
69
70
71
72
73
74
75
76
77 private List reports;
78
79
80
81
82
83
84 public void execute()
85 throws MojoExecutionException, MojoFailureException
86 {
87 getLog().info( "[MAVEN-CORE-IT-LOG] Using output directory " + outputDirectory );
88
89 Locale locale = new Locale( language );
90 getLog().info( "[MAVEN-CORE-IT-LOG] Using locale " + locale );
91
92 InvocationHandler handler = new InvocationHandler()
93 {
94
95 public Object invoke( Object proxy, Method method, Object[] args )
96 throws Throwable
97 {
98 return null;
99 }
100
101 };
102 Sink sink = (Sink) Proxy.newProxyInstance( getClass().getClassLoader(), new Class[] { Sink.class }, handler );
103
104 for ( int i = 0; i < reports.size(); i++ )
105 {
106 MavenReport report = (MavenReport) reports.get( i );
107
108 if ( report.canGenerateReport() )
109 {
110 getLog().info( "[MAVEN-CORE-IT-LOG] Generating report " + report );
111 try
112 {
113 report.setReportOutputDirectory( outputDirectory );
114 report.generate( sink, locale );
115 }
116 catch ( Throwable e )
117 {
118 getLog().warn( "[MAVEN-CORE-IT-LOG] " + e, e );
119 if ( !ignoreErrors )
120 {
121 throw new MojoExecutionException( "Failed to generate report " + report, e );
122 }
123 }
124 }
125 else
126 {
127 getLog().info( "[MAVEN-CORE-IT-LOG] Skipping report " + report );
128 }
129 }
130 }
131
132 }