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