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.AddVersionCommand; 23 import de.smartics.maven.issue.command.CommandResult; 24 import de.smartics.maven.issue.command.ProductNavigationCommand; 25 import de.smartics.maven.issue.util.VersionHelper; 26 27 /** 28 * Helper to add versions. 29 */ 30 class MojoHelperVersion extends AbstractMojoHelper 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 * @see de.smartics.maven.bugzilla.AbstractMojoHelper#AbstractMojoHelper(org.apache.maven.project.MavenProject, 50 * de.smartics.maven.bugzilla.MavenCommandFactory, 51 * de.smartics.maven.bugzilla.Console) 52 */ 53 protected MojoHelperVersion(final MavenProject project, 54 final MavenCommandFactory commandFactory, final Console console) 55 { 56 super(project, commandFactory, console); 57 } 58 59 // ****************************** Inner Classes ***************************** 60 61 // ********************************* Methods ******************************** 62 63 // --- init ----------------------------------------------------------------- 64 65 // --- get&set -------------------------------------------------------------- 66 67 // --- business ------------------------------------------------------------- 68 69 /** 70 * Executes the helpers commands. 71 * 72 * @param product the name of the product whose version is to be added. 73 * @param version the version to add. 74 * @throws MojoExecutionException if an unexpected problem occurs. Throwing 75 * this exception causes a "BUILD ERROR" message to be displayed. 76 * @throws MojoFailureException if an expected problem (such as a compilation 77 * failure) occurs. Throwing this exception causes a "BUILD FAILURE" 78 * message to be displayed. 79 */ 80 public final void run(final String product, final String version) 81 throws MojoExecutionException, MojoFailureException 82 { 83 final ProductNavigationCommand navigationCommand = 84 createNavigationCommand(product); 85 console.execute(navigationCommand); 86 87 final CommandResult<?> navigationResult = navigationCommand.getResult(); 88 final String token = navigationResult.getToken(); 89 final AddVersionCommand addVersionCommand = 90 createAddVersionCommand(product, version, token); 91 console.execute(addVersionCommand); 92 } 93 94 private ProductNavigationCommand createNavigationCommand(final String product) 95 { 96 final ProductNavigationCommand command = 97 commandFactory.createVersionProductNavigationCommand(product); 98 return command; 99 } 100 101 private AddVersionCommand createAddVersionCommand(final String product, 102 final String version, final String token) 103 { 104 final VersionHelper helper = new VersionHelper(project); 105 final String nextVersion = helper.calculateNextVersion(version); 106 if (nextVersion == null) 107 { 108 return null; 109 } 110 final AddVersionCommand command = 111 commandFactory.createAddVersionCommand(product, nextVersion, token); 112 return command; 113 } 114 115 // --- object basics -------------------------------------------------------- 116 117 }