KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > reporting > AbstractMavenReport


1 package org.apache.maven.reporting;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.doxia.sink.Sink;
20 import org.apache.maven.doxia.siterenderer.Renderer;
21 import org.apache.maven.doxia.siterenderer.RendererException;
22 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.project.MavenProject;
26
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.Locale JavaDoc;
30
31 /**
32  * The basis for a Maven report.
33  *
34  * @author <a HREF="evenisse@apache.org">Emmanuel Venisse</a>
35  * @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
36  */

37 public abstract class AbstractMavenReport
38     extends AbstractMojo
39     implements MavenReport
40 {
41     private Sink sink;
42
43     private Locale JavaDoc locale = Locale.ENGLISH;
44
45     protected abstract Renderer getSiteRenderer();
46
47     protected abstract String JavaDoc getOutputDirectory();
48
49     protected abstract MavenProject getProject();
50
51     private File JavaDoc reportOutputDirectory;
52
53     /**
54      * @see org.apache.maven.plugin.Mojo#execute()
55      */

56     public void execute()
57         throws MojoExecutionException
58     {
59         try
60         {
61             String JavaDoc outputDirectory = getOutputDirectory();
62
63             SiteRendererSink sink =
64                 getSiteRenderer().createSink( new File JavaDoc( outputDirectory ), getOutputName() + ".html" );
65
66             generate( sink, Locale.getDefault() );
67
68             // TODO: add back when skinning support is in the site renderer
69
// getSiteRenderer().copyResources( outputDirectory, "maven" );
70
}
71         catch ( RendererException e )
72         {
73             throw new MojoExecutionException( "An error has occurred in " + getName( locale ) + " report generation.",
74                                               e );
75         }
76         catch ( IOException JavaDoc e )
77         {
78             throw new MojoExecutionException( "An error has occurred in " + getName( locale ) + " report generation.",
79                                               e );
80         }
81         catch ( MavenReportException e )
82         {
83             throw new MojoExecutionException( "An error has occurred in " + getName( locale ) + " report generation.",
84                                               e );
85         }
86     }
87
88     /**
89      * @see org.apache.maven.reporting.MavenReport#generate(org.codehaus.doxia.sink.Sink, java.util.Locale)
90      */

91     public void generate( org.codehaus.doxia.sink.Sink sink, Locale JavaDoc locale )
92         throws MavenReportException
93     {
94         if ( sink == null )
95         {
96             throw new MavenReportException( "You must specify a sink." );
97         }
98
99         this.sink = sink;
100
101         executeReport( locale );
102
103         closeReport();
104     }
105
106     protected abstract void executeReport( Locale JavaDoc locale )
107         throws MavenReportException;
108
109     protected void closeReport()
110     {
111     }
112
113     public String JavaDoc getCategoryName()
114     {
115         return CATEGORY_PROJECT_REPORTS;
116     }
117
118     public File JavaDoc getReportOutputDirectory()
119     {
120         if ( reportOutputDirectory == null )
121         {
122             reportOutputDirectory = new File JavaDoc( getOutputDirectory() );
123         }
124         return reportOutputDirectory;
125     }
126
127     public void setReportOutputDirectory( File JavaDoc reportOutputDirectory )
128     {
129         this.reportOutputDirectory = reportOutputDirectory;
130     }
131
132     public Sink getSink()
133     {
134         return sink;
135     }
136
137     public boolean isExternalReport()
138     {
139         return false;
140     }
141
142     public boolean canGenerateReport()
143     {
144         return true;
145     }
146 }
147
Popular Tags