View Javadoc

1   /*
2    * Copyright 2012 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.maven.plugin.MojoExecutionException;
19  import org.apache.maven.plugin.MojoFailureException;
20  import org.apache.maven.project.MavenProject;
21  
22  import de.smartics.maven.issue.command.AddProductCommand;
23  import de.smartics.maven.issue.command.ClassificationNavigationCommand;
24  import de.smartics.maven.issue.command.CommandResult;
25  
26  /**
27   * Helper to add and update product information.
28   */
29  final class MojoHelperProductAdd extends AbstractMojoHelperProduct
30  {
31  
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    // --- members --------------------------------------------------------------
37  
38    /**
39     * The classification to the product to add.
40     */
41    private final String classification;
42  
43    /**
44     * The initial version of the product to add.
45     */
46    private final String initialVersion;
47  
48    // ****************************** Initializer *******************************
49  
50    // ****************************** Constructors ******************************
51  
52    // CHECKSTYLE:OFF
53    /**
54     * Default constructor.
55     *
56     * @param project the Maven project.
57     * @param commandFactory the helper to create commands.
58     * @param console the console to execute commands.
59     * @param classification the classification to the product to add.
60     * @param productInfo the core product information.
61     * @param initialVersion the initial version of the product to add.
62     */
63    protected MojoHelperProductAdd(// NOPMD
64        final MavenProject project, final MavenCommandFactory commandFactory,
65        final Console console, final String classification,
66        final ProductInfo productInfo, final String initialVersion)
67    {
68      // CHECKSTYLE:ON
69      super(project, commandFactory, console, productInfo);
70  
71      this.classification = classification;
72      this.initialVersion = initialVersion;
73    }
74  
75    // ****************************** Inner Classes *****************************
76  
77    // ********************************* Methods ********************************
78  
79    // --- init -----------------------------------------------------------------
80  
81    // --- get&set --------------------------------------------------------------
82  
83    // --- business -------------------------------------------------------------
84  
85    /**
86     * Adds a product to the Bugzilla server.
87     */
88    public void execute() throws MojoExecutionException, MojoFailureException
89    {
90      final ClassificationNavigationCommand navigationCommand =
91          createNavigationCommand(classification);
92      console.execute(navigationCommand);
93  
94      final CommandResult<?> navigationResult = navigationCommand.getResult();
95      final String token = navigationResult.getToken();
96      final AddProductCommand addProductCommand =
97          createAddProductCommand(classification, token);
98      console.execute(addProductCommand);
99  
100     updateComponents();
101   }
102 
103   private ClassificationNavigationCommand createNavigationCommand(
104       final String classification)
105   {
106     final ClassificationNavigationCommand command =
107         commandFactory.createClassificationNavigationCommand(classification);
108     return command;
109   }
110 
111   private AddProductCommand createAddProductCommand(
112       final String classification, final String token)
113   {
114     final String description = project.getDescription();
115     final String product = getProduct();
116     final String defaultMilestone = getDefaultMilestone();
117 
118     final AddProductCommand command =
119         commandFactory.createAddProductCommand(classification, product,
120             description, defaultMilestone, initialVersion, token);
121     return command;
122   }
123 
124   // --- object basics --------------------------------------------------------
125 
126 }