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.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(
64        // NOPMD
65        final MavenProject project, final MavenCommandFactory commandFactory,
66        final Console console, final String classification,
67        final ProductInfo productInfo, final String initialVersion)
68    {
69      // CHECKSTYLE:ON
70      super(project, commandFactory, console, productInfo);
71  
72      this.classification = classification;
73      this.initialVersion = initialVersion;
74    }
75  
76    // ****************************** Inner Classes *****************************
77  
78    // ********************************* Methods ********************************
79  
80    // --- init -----------------------------------------------------------------
81  
82    // --- get&set --------------------------------------------------------------
83  
84    // --- business -------------------------------------------------------------
85  
86    /**
87     * Adds a product to the Bugzilla server.
88     */
89    public void execute() throws MojoExecutionException, MojoFailureException
90    {
91      final ClassificationNavigationCommand navigationCommand =
92          createNavigationCommand(classification);
93      console.execute(navigationCommand);
94  
95      final CommandResult<?> navigationResult = navigationCommand.getResult();
96      final String token = navigationResult.getToken();
97      final AddProductCommand addProductCommand =
98          createAddProductCommand(classification, token);
99      console.execute(addProductCommand);
100 
101     updateComponents();
102   }
103 
104   private ClassificationNavigationCommand createNavigationCommand(
105       final String classification)
106   {
107     final ClassificationNavigationCommand command =
108         commandFactory.createClassificationNavigationCommand(classification);
109     return command;
110   }
111 
112   private AddProductCommand createAddProductCommand(
113       final String classification, final String token)
114     throws MojoExecutionException
115   {
116     final String description = project.getDescription();
117     final String product = getProduct();
118     final String defaultMilestone = getDefaultMilestone();
119 
120     final AddProductCommand command =
121         commandFactory.createAddProductCommand(classification, product,
122             description, defaultMilestone, initialVersion, token, productInfo,
123             getComponents());
124     return command;
125   }
126 
127   // --- object basics --------------------------------------------------------
128 
129 }