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.CommandResult;
23  import de.smartics.maven.issue.command.ProductNavigationCommand;
24  import de.smartics.maven.issue.command.UpdateProductCommand;
25  import de.smartics.maven.issue.util.VersionHelper;
26  
27  /**
28   * Helper to add and update product information.
29   */
30  class MojoHelperProductUpdate extends AbstractMojoHelperProduct
31  {
32  
33    // ********************************* Fields *********************************
34  
35    // --- constants ------------------------------------------------------------
36  
37    // --- members --------------------------------------------------------------
38  
39    // ****************************** Initializer *******************************
40  
41    // ****************************** Constructors ******************************
42  
43    /**
44     * Default constructor.
45     *
46     * @param project the Maven project.
47     * @param commandFactory the helper to create commands.
48     * @param console the console to execute commands.
49     * @param productInfo the core product information.
50     */
51    protected MojoHelperProductUpdate(
52        final MavenProject project, // NOPMD
53        final MavenCommandFactory commandFactory, final Console console,
54        final ProductInfo productInfo)
55    {
56      super(project, commandFactory, console, productInfo);
57    }
58  
59    // ****************************** Inner Classes *****************************
60  
61    // ********************************* Methods ********************************
62  
63    // --- init -----------------------------------------------------------------
64  
65    // --- get&set --------------------------------------------------------------
66  
67    // --- business -------------------------------------------------------------
68  
69    void execute(final String oldProduct) throws MojoExecutionException,
70      MojoFailureException
71    {
72      final String version = VersionHelper.CURRENT;
73      final MojoHelperMilestone milestoneHelper =
74          new MojoHelperMilestone(project, commandFactory, console);
75      milestoneHelper.run(oldProduct, version);
76  
77      final ProductNavigationCommand navigationCommand =
78          createProductNavigationCommand(oldProduct);
79      console.execute(navigationCommand);
80  
81      final CommandResult<?> navigationResult = navigationCommand.getResult();
82      final String token = navigationResult.getToken();
83      final UpdateProductCommand updateProductCommand =
84          createUpdateProductCommand(oldProduct, token);
85      console.execute(updateProductCommand);
86  
87      updateComponents();
88    }
89  
90    private ProductNavigationCommand createProductNavigationCommand(
91        final String product)
92    {
93      final ProductNavigationCommand command =
94          commandFactory.createProductNavigationCommand(product);
95      return command;
96    }
97  
98    private UpdateProductCommand createUpdateProductCommand(
99        final String oldProduct, final String token)
100   {
101     final String description = project.getDescription();
102     final String product = getProduct();
103     final String defaultMilestone = getDefaultMilestone();
104 
105     final UpdateProductCommand command =
106         commandFactory.createUpdateProductCommand(oldProduct, product,
107             description, defaultMilestone, token);
108     return command;
109   }
110 
111   // --- object basics --------------------------------------------------------
112 
113 }