View Javadoc

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