1 package org.apache.maven.plugin.checkstyle.rss;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.checkstyle.CheckstyleReport;
26 import org.apache.maven.plugin.checkstyle.CheckstyleResults;
27 import org.apache.maven.plugin.checkstyle.VelocityTemplate;
28 import org.apache.maven.reporting.MavenReportException;
29 import org.apache.velocity.VelocityContext;
30 import org.apache.velocity.context.Context;
31 import org.apache.velocity.exception.ResourceNotFoundException;
32 import org.apache.velocity.exception.VelocityException;
33 import org.codehaus.plexus.component.annotations.Component;
34 import org.codehaus.plexus.component.annotations.Requirement;
35 import org.codehaus.plexus.util.StringUtils;
36 import org.codehaus.plexus.velocity.VelocityComponent;
37
38 import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
39
40
41
42
43
44 @Component( role = CheckstyleRssGenerator.class, hint = "default" )
45 public class DefaultCheckstyleRssGenerator
46 implements CheckstyleRssGenerator
47 {
48 @Requirement
49 private VelocityComponent velocityComponent;
50
51
52
53
54 public void generateRSS( CheckstyleResults results, CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest )
55 throws MavenReportException
56 {
57
58 VelocityTemplate vtemplate = new VelocityTemplate( velocityComponent, CheckstyleReport.PLUGIN_RESOURCES );
59 vtemplate.setLog( checkstyleRssGeneratorRequest.getLog() );
60
61 Context context = new VelocityContext();
62 context.put( "results", results );
63 context.put( "project", checkstyleRssGeneratorRequest.getMavenProject() );
64 context.put( "copyright", checkstyleRssGeneratorRequest.getCopyright() );
65 context.put( "levelInfo", SeverityLevel.INFO );
66 context.put( "levelWarning", SeverityLevel.WARNING );
67 context.put( "levelError", SeverityLevel.ERROR );
68 context.put( "stringutils", new StringUtils() );
69
70 try
71 {
72 vtemplate.generate( checkstyleRssGeneratorRequest.getOutputDirectory().getPath() + "/checkstyle.rss",
73 "checkstyle-rss.vm", context );
74 }
75 catch ( ResourceNotFoundException e )
76 {
77 throw new MavenReportException( "Unable to find checkstyle-rss.vm resource.", e );
78 }
79 catch ( MojoExecutionException e )
80 {
81 throw new MavenReportException( "Unable to generate checkstyle.rss.", e );
82 }
83 catch ( VelocityException e )
84 {
85 throw new MavenReportException( "Unable to generate checkstyle.rss.", e );
86 }
87 catch ( IOException e )
88 {
89 throw new MavenReportException( "Unable to generate checkstyle.rss.", e );
90 }
91 }
92
93 }