View Javadoc

1   /*
2    * Copyright 2012-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.bugzilla;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.maven.project.MavenProject;
20  
21  import de.smartics.maven.bugzilla.AbstractMojoHelperProduct.ComponentsInfo;
22  import de.smartics.maven.bugzilla.AbstractMojoHelperProduct.ProductInfo;
23  import de.smartics.maven.issue.util.VersionHelper;
24  
25  /**
26   * Base implementation of mojos dealing with products.
27   */
28  public abstract class AbstractProductMojo extends AbstractIssueManagementMojo
29  {
30    // ********************************* Fields *********************************
31  
32    // --- constants ------------------------------------------------------------
33  
34    // --- members --------------------------------------------------------------
35  
36    /**
37     * The name of product.
38     *
39     * @parameter expression="${product}" default-value="${project.artifactId}"
40     * @since 1.0
41     */
42    private String product;
43  
44    /**
45     * The default milestone to use. Defaults to the current version without
46     * <code>-SNAPSHOT</code> suffix.
47     *
48     * @parameter expression="${defaultMilestone}"
49     * @since 1.0
50     */
51    private String defaultMilestone;
52  
53    /**
54     * The initial version to use.
55     *
56     * @parameter expression="${initialVersion}"
57     *            default-value="${project.Version}"
58     * @since 1.0
59     */
60    private String initialVersion;
61  
62    /**
63     * The name of the initial owner of issues for the components. Currently the
64     * initial owner for each component is the same.
65     *
66     * @parameter expression="${initialOwner}"
67     * @since 1.0
68     */
69    protected String initialOwner;
70  
71    /**
72     * The name of the resource on the class path that contains the configuration.
73     * The XML file must conform to
74     * <code>http://www.smartics.de/schema/bugzilla-configuration/1"</code>.
75     *
76     * @parameter default-value="bugzilla-configuration-default.xml"
77     * @since 1.0
78     */
79    protected String configurationName;
80  
81    /**
82     * The locale to use to select default component descriptions. If a not
83     * supported locale is used, it defaults to the given default.
84     * If specified, the {@code configurationName} is adjusted by adding this
85     * locale (e.g. {@code bugzilla-configuration-default-en.xml}).
86     *
87     * @parameter default-value="en"
88     * @since 1.0
89     */
90    protected String locale;
91  
92    /**
93     * Signals to add the default component descriptions for multi module
94     * projects. The default descriptions are added in addition to the names of
95     * the sub modules. This has no effect on single modules where the default
96     * component descriptions are always added.
97     *
98     * @parameter default-value="false"
99     * @since 1.0
100    */
101   private boolean addDefaultComponentsForMultiModuleProjects;
102 
103   /**
104    * Signals that in the case of a multi module project the sub module names
105    * should not be added as components. Note: If you do not set
106    * 'addDefaultComponentsForMultiModuleProjects' to 'true' the product will
107    * be added without any components.
108    *
109    * @parameter default-value="false"
110    * @since 1.0
111    */
112   private boolean suppressSubModuleNamesAsComponents;
113 
114   // ****************************** Initializer *******************************
115 
116   // ****************************** Constructors ******************************
117 
118   // ****************************** Inner Classes *****************************
119 
120   // ********************************* Methods ********************************
121 
122   // --- init -----------------------------------------------------------------
123 
124   // --- get&set --------------------------------------------------------------
125 
126   // --- business -------------------------------------------------------------
127 
128   /**
129    * Returns the name of product.
130    *
131    * @return the name of product.
132    */
133   protected final String getProduct()
134   {
135     if (StringUtils.isNotBlank(product))
136     {
137       return product;
138     }
139     final MavenProject project = getProject();
140     return project.getArtifactId();
141   }
142 
143   /**
144    * Returns the initial version to use.
145    *
146    * @return the initial version to use.
147    */
148   protected final String getInitialVersion()
149   {
150     if (StringUtils.isNotBlank(initialVersion))
151     {
152       return initialVersion;
153     }
154     final MavenProject project = getProject();
155     return project.getVersion();
156   }
157 
158   /**
159    * Returns the default milestone to use. Defaults to the current version
160    * without <code>-SNAPSHOT</code> suffix.
161    *
162    * @return the default milestone to use.
163    */
164   protected final String getDefaultMilestone()
165   {
166     if (StringUtils.isNotBlank(defaultMilestone))
167     {
168       return defaultMilestone;
169     }
170     final MavenProject project = getProject();
171     return VersionHelper.getVersionStrippedFromSnapshotSuffix(project
172         .getVersion());
173   }
174 
175   /**
176    * Creates a loader for component descriptions.
177    *
178    * @return a loader for component descriptions.
179    */
180   protected final ComponentDescriptionLoader createLoader()
181   {
182     return new ComponentDescriptionLoader(configurationName, locale);
183   }
184 
185   /**
186    * Creates a product info instance based on the information passed to this
187    * mojo.
188    *
189    * @return a product info instance based on the information passed to this
190    *         mojo.
191    */
192   protected final ProductInfo createProductInfo()
193   {
194     final ComponentDescriptionLoader loader = createLoader();
195     final ComponentsInfo components =
196         new ComponentsInfo(loader, addDefaultComponentsForMultiModuleProjects,
197             suppressSubModuleNamesAsComponents);
198 
199     final String product = getProduct();
200     final String defaultMilestone = getDefaultMilestone();
201 
202     final ProductInfo productInfo =
203         new ProductInfo(product, defaultMilestone, initialOwner, components);
204     return productInfo;
205   }
206 
207   // --- object basics --------------------------------------------------------
208 
209 }