View Javadoc

1   /*
2    * DaCapo Benchmark Maven Plugin
3    * Copyright (C) 2010 Technische Universität Darmstadt
4    * info@scalabench.org
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  package org.scalabench.plugins.dacapo.reporting;
19  
20  import java.io.File;
21  import java.util.Locale;
22  import java.util.ResourceBundle;
23  
24  import org.apache.maven.doxia.siterenderer.Renderer;
25  import org.apache.maven.project.MavenProject;
26  import org.apache.maven.reporting.AbstractMavenReport;
27  import org.apache.maven.reporting.AbstractMavenReportRenderer;
28  import org.apache.maven.reporting.MavenReportException;
29  import org.dacapo.parser.Config;
30  import org.scalabench.plugins.dacapo.AbstractDacapoBenchmarkMojo;
31  
32  /**
33   * Reports the benchmark's configuration.
34   * 
35   * @since 0.1.0
36   * 
37   * @threadSafe
38   * @goal report-configuration
39   * @phase site
40   * @execute phase="process-resources"
41   */
42  public class ConfigurationReport extends AbstractMavenReport {
43      
44      /**
45       * The Maven project being built.
46       * 
47       * @required
48       * @readonly
49       * @parameter expression="${project}"
50       */
51      private MavenProject project;
52      
53      /**
54       * The name of the benchmark. If unspecified, it is derived from the project's <code>artifactId</code>.
55       * 
56       * If the <code>artifactId</code> matches one of the following patterns, the benchmark name is extracted from it as
57       * indicated:
58       * 
59       * <ul>
60       *   <li><code>${benchmarkName}</code>-dacapo-benchmark</li>
61       *   <li>dacapo-<code>${benchmarkName}</code>-benchmark</li>
62       * </ul>
63       * 
64       * Otherwise, the <code>artifactId</code> is taken wholesale.
65       * 
66       * @parameter
67       */
68      private String benchmarkName;
69      
70      /**
71       * The directory where the benchmark configuration is located.
72       * 
73       * @required
74       * @readonly
75       * @parameter expression="${project.build.outputDirectory}/cnf"
76       */
77      private File configurationDirectory;
78      
79      /**
80       * @required
81       * @readonly
82       * @parameter expression="${project.reporting.outputDirectory}"
83       */
84      private String outputDirectory;
85      
86      /**
87       * @component
88       */
89      private Renderer siteRenderer;
90      
91      public MavenProject getProject() {
92          return project;
93      }
94      
95      public String getBenchmarkName() {
96          if (benchmarkName == null)
97              return AbstractDacapoBenchmarkMojo.getBenchmarkNameFromArtifactId(getProject().getArtifactId());
98          else
99              return benchmarkName;
100     }
101     
102     @Override
103     protected void executeReport(Locale locale) throws MavenReportException {
104         final Config config = Config.parse(getConfigurationFile());
105         final AbstractMavenReportRenderer renderer =
106             new ConfigurationReportRenderer(getSink(), config, locale);
107         renderer.render();
108     }
109     
110     @Override
111     public boolean canGenerateReport() {
112         return getConfigurationFile().exists();
113     }
114     
115     public File getConfigurationFile() {
116         return new File(getConfigurationDirectory(), getBenchmarkName() + ".cnf");
117     }
118     
119     public File getConfigurationDirectory() {
120         return configurationDirectory;
121     }
122     
123     @Override
124     public String getOutputName() {
125         return "dacapo-benchmark-configuration";
126     }
127     
128     @Override
129     public String getOutputDirectory() {
130         return outputDirectory;
131     }
132     
133     @Override
134     public Renderer getSiteRenderer() {
135         return siteRenderer;
136     }
137     
138     @Override
139     public String getName(Locale locale) {
140         return getBundle(locale).getString("report.dacapo.name");
141     }
142     
143     @Override
144     public String getDescription(Locale locale) {
145         return getBundle(locale).getString("report.dacapo.description");
146     }
147     
148     public static ResourceBundle getBundle(Locale locale) {
149         return ResourceBundle.getBundle("configuration-report", locale, ConfigurationReport.class.getClassLoader());
150     }
151 }