View Javadoc

1   /*
2    * Copyright 2008-2010 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package de.smartics.maven.issues.bugzilla;
18  
19  import java.util.List;
20  import java.util.ResourceBundle;
21  
22  import org.apache.maven.artifact.versioning.ArtifactVersion;
23  import org.apache.maven.doxia.sink.Sink;
24  import org.eclipse.mylyn.tasks.core.data.TaskData;
25  
26  import de.smartics.maven.issues.RendererConfig;
27  import de.smartics.maven.issues.bugzilla.Versions.VersionedSections;
28  
29  /**
30   * The renderer prints issue information in different sections within their
31   * version. The sections are defines by the key
32   * {@link RendererConfig#getSectionType()} and are selected and ordered by
33   * {@link RendererConfig#getSections()}.
34   *
35   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
36   */
37  public class VersionedSectionReportRenderer extends
38      AbstractSectionReportRenderer
39  {
40    // ********************************* Fields *********************************
41  
42    // --- constants ------------------------------------------------------------
43  
44    // --- members --------------------------------------------------------------
45  
46    /**
47     * The version text to be used by template methods provided by the parent's
48     * class.
49     */
50    protected String currentVersionString;
51  
52    // ****************************** Initializer *******************************
53  
54    // ****************************** Constructors ******************************
55  
56    /**
57     * Default constructor.
58     *
59     * @param config the configuration to control the rendering process.
60     * @param sink the sink to write to.
61     * @param issues the issue information to render in the report.
62     */
63    public VersionedSectionReportRenderer(final RendererConfig config,
64        final Sink sink, final List<TaskData> issues)
65    {
66      super(config, sink, issues);
67    }
68  
69    // ****************************** Inner Classes *****************************
70  
71    // ********************************* Methods ********************************
72  
73    // --- init -----------------------------------------------------------------
74  
75    // --- get&set --------------------------------------------------------------
76  
77    /**
78     * {@inheritDoc}
79     */
80    @Override
81    public String getTitle()
82    {
83      return getTitle("report.name.release");
84    }
85  
86    /**
87     * {@inheritDoc}
88     */
89    @Override
90    public String getDescription()
91    {
92      return getDescription("report.description.release");
93    }
94  
95    /**
96     * {@inheritDoc}
97     */
98    @Override
99    public String getNoResultsDescription()
100   {
101     return getNoResultsDescription("report.noResultsDescription.release");
102   }
103 
104   // --- business -------------------------------------------------------------
105 
106   /**
107    * {@inheritDoc}
108    */
109   @Override
110   protected void renderBody()
111   {
112     sink.section1();
113     final boolean noResults = issues.isEmpty();
114     renderTitle(noResults);
115 
116     if (!noResults)
117     {
118       final ResourceBundle bundle = config.getBundle();
119       final String versionText =
120           ReportHelper.getLabel(bundle, getVersionTextId());
121 
122       final VersionSkipper skipper = createVersionSkipper();
123       final Sectioner<Versions> sectioner = createSectioner();
124       final Versions versions = sectioner.run();
125       final ArtifactVersion releaseVersion = config.getCurrentReleaseVersion();
126       for (VersionedSections versionedSections : versions)
127       {
128         final ArtifactVersion version = versionedSections.getVersion();
129         if (skipper.skipVersion(releaseVersion, version))
130         {
131           continue;
132         }
133         sink.section2();
134         sink.sectionTitle2();
135         final String versionString = version.toString();
136         this.currentVersionString = versionString;
137         sink.text(versionText + ' ' + versionString);
138         sink.sectionTitle2_();
139 
140         renderSections(versionedSections.getSections());
141         sink.section2_();
142       }
143     }
144 
145     renderPreviousReportReferences();
146 
147     renderFooter();
148     sink.section1_();
149   }
150 
151   /**
152    * Returns the arbiter to determine which versions are excluded from the
153    * report.
154    *
155    * @return the arbiter to determine which versions are excluded from the
156    *         report.
157    */
158   protected VersionSkipper createVersionSkipper()
159   {
160     return new DefaultVersionSkipper(config.getIncludeOnSamePageAllOfVersion(),
161         config.getVersionRange() != null);
162   }
163 
164   /**
165    * Creates the sectioner to use.
166    *
167    * @return the sectioner to use.
168    */
169   protected Sectioner<Versions> createSectioner()
170   {
171     return new VersionedSectioner(config, issues);
172   }
173 
174   /**
175    * Returns the identifier part for the version text rendered in the report.
176    *
177    * @return the identifier part for the version text rendered in the report.
178    */
179   protected String getVersionTextId()
180   {
181     return "version.header";
182   }
183 
184   /**
185    * Renders the start of a section.
186    *
187    * @impl Subclasses should override this if the default level 3 is not
188    *       adequate for the report.
189    */
190   protected void renderSectionSectionStart()
191   {
192     sink.section3();
193   }
194 
195   /**
196    * Renders the end of a section.
197    *
198    * @impl Subclasses should override this if the default level 3 is not
199    *       adequate for the report.
200    */
201   protected void renderSectionSectionEnd()
202   {
203     sink.section3_();
204   }
205 
206   /**
207    * Renders the start of a section title.
208    *
209    * @impl Subclasses should override this if the default level 3 is not
210    *       adequate for the report.
211    */
212   protected void renderSectionTitleStart()
213   {
214     sink.sectionTitle3();
215   }
216 
217   /**
218    * Renders the end of a section title.
219    *
220    * @impl Subclasses should override this if the default level 3 is not
221    *       adequate for the report.
222    */
223   protected void renderSectionTitleEnd()
224   {
225     sink.sectionTitle3_();
226   }
227 
228   /**
229    * Returns the introduction text after the section title.
230    *
231    * @param bundle the resource bundle to use.
232    * @param sectionId the identifier (an attribute key of the issue management
233    *          system) of the section.
234    * @return the localized text to render.
235    */
236   protected String getSectionText(final ResourceBundle bundle,
237       final String sectionId)
238   {
239     return ReportHelper.getLabel(bundle, "section.text.versioned", sectionId,
240         currentVersionString);
241   }
242 
243   // --- object basics --------------------------------------------------------
244 
245 }