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 static de.smartics.maven.issue.util.VersionHelper.CURRENT;
19  import static de.smartics.maven.issue.util.VersionHelper.MAJOR;
20  import static de.smartics.maven.issue.util.VersionHelper.MICRO;
21  import static de.smartics.maven.issue.util.VersionHelper.MINOR;
22  import static de.smartics.maven.issue.util.VersionHelper.SNAPSHOT;
23  import static de.smartics.maven.issue.util.VersionHelper.getVersionStrippedFromSnapshotSuffix;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugin.MojoFailureException;
27  import org.apache.maven.project.MavenProject;
28  
29  import de.smartics.maven.issue.util.VersionHelper;
30  
31  /**
32   * Helper to sync version information.
33   */
34  final class MojoHelperSync extends AbstractMojoHelper
35  {
36  
37    // ********************************* Fields *********************************
38  
39    // --- constants ------------------------------------------------------------
40  
41    // --- members --------------------------------------------------------------
42  
43    // ****************************** Initializer *******************************
44  
45    // ****************************** Constructors ******************************
46  
47    /**
48     * Default constructor.
49     *
50     * @param project the Maven project.
51     * @param commandFactory the helper to create commands.
52     * @param console the console to execute commands.
53     * @see de.smartics.maven.bugzilla.AbstractMojoHelper#AbstractMojoHelper(org.apache.maven.project.MavenProject,
54     *      de.smartics.maven.bugzilla.MavenCommandFactory,
55     *      de.smartics.maven.bugzilla.Console)
56     */
57    protected MojoHelperSync(final MavenProject project,
58        final MavenCommandFactory commandFactory, final Console console)
59    {
60      super(project, commandFactory, console);
61    }
62  
63    // ****************************** Inner Classes *****************************
64  
65    // ********************************* Methods ********************************
66  
67    // --- init -----------------------------------------------------------------
68  
69    // --- get&set --------------------------------------------------------------
70  
71    // --- business -------------------------------------------------------------
72  
73    /**
74     * {@inheritDoc}
75     */
76    void execute(final String releasedVersion) throws MojoExecutionException,
77      MojoFailureException
78    {
79      final String product = project.getArtifactId();
80  
81      final String normalizedVersion = normalize(releasedVersion);
82      final MojoHelperVersion versionHelper =
83          new MojoHelperVersion(project, commandFactory, console);
84      versionHelper.run(product, normalizedVersion);
85  
86      final VersionHelper helper = new VersionHelper(normalizedVersion);
87      final MojoHelperMilestone milestoneHelper =
88          new MojoHelperMilestone(project, commandFactory, console);
89  
90      final String micro =
91          !SNAPSHOT.equals(releasedVersion) ? helper.calculateNextVersion(MICRO)
92              : getVersionStrippedFromSnapshotSuffix(project.getVersion());
93      milestoneHelper.run(product, micro, null);
94      final String minor = helper.calculateNextVersion(MINOR);
95      milestoneHelper.run(product, minor, null);
96      final String major = helper.calculateNextVersion(MAJOR);
97      milestoneHelper.run(product, major, null);
98    }
99  
100   private String normalize(final String releasedVersion)
101   {
102     final String normalized;
103 
104     if (SNAPSHOT.equals(releasedVersion))
105     {
106       normalized = project.getVersion();
107     }
108     else if (CURRENT.equals(releasedVersion))
109     {
110       normalized = getVersionStrippedFromSnapshotSuffix(project.getVersion());
111     }
112     else
113     {
114       normalized = releasedVersion;
115     }
116 
117     return normalized;
118   }
119 
120   // --- object basics --------------------------------------------------------
121 
122 }