View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.release;
20  
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.apache.maven.plugin.MojoFailureException;
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.shared.release.DefaultReleaseManagerListener;
26  import org.apache.maven.shared.release.ReleaseExecutionException;
27  import org.apache.maven.shared.release.ReleaseFailureException;
28  import org.apache.maven.shared.release.ReleaseRollbackRequest;
29  import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
30  
31  /**
32   * Rollback changes made by a previous release. This requires that the previous release descriptor
33   * <code>release.properties</code> is still available in the local working copy. For more info see <a
34   * href="https://maven.apache.org/plugins/maven-release-plugin/usage/rollback-release.html"
35   * >https://maven.apache.org/plugins/maven-release-plugin/usage/rollback-release.html</a>.
36   *
37   * @since 2.0-beta-5
38   * @author Edwin Punzalan
39   */
40  @Mojo(name = "rollback", aggregator = true)
41  public class RollbackReleaseMojo extends AbstractScmReleaseMojo {
42  
43      /**
44       * The SCM commit comment when rolling back.
45       * Defaults to "@{prefix} rollback the release of @{releaseLabel}".
46       * <p>
47       * Property interpolation is performed on the value, but in order to ensure that the interpolation occurs
48       * during release, you must use <code>@{...}</code> to reference the properties rather than <code>${...}</code>.
49       * The following properties are available:
50       * <ul>
51       *     <li><code>prefix</code> - The comment prefix.
52       *     <li><code>groupId</code> - The groupId of the root project.
53       *     <li><code>artifactId</code> - The artifactId of the root project.
54       *     <li><code>releaseLabel</code> - The release version of the root project.
55       * </ul>
56       *
57       * @since 3.0.0-M5
58       */
59      @Parameter(
60              defaultValue = "@{prefix} rollback the release of @{releaseLabel}",
61              property = "scmRollbackCommitComment")
62      private String scmRollbackCommitComment = "@{prefix} rollback the release of @{releaseLabel}";
63  
64      @Override
65      public void execute() throws MojoExecutionException, MojoFailureException {
66          super.execute();
67  
68          final ReleaseDescriptorBuilder config = createReleaseDescriptor();
69          config.setScmRollbackCommitComment(scmRollbackCommitComment);
70  
71          try {
72              ReleaseRollbackRequest rollbackRequest = new ReleaseRollbackRequest();
73              rollbackRequest.setReleaseDescriptorBuilder(config);
74              rollbackRequest.setReleaseEnvironment(getReleaseEnvironment());
75              rollbackRequest.setReactorProjects(getReactorProjects());
76              rollbackRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog()));
77  
78              releaseManager.rollback(rollbackRequest);
79          } catch (ReleaseExecutionException e) {
80              throw new MojoExecutionException(e.getMessage(), e);
81          } catch (ReleaseFailureException e) {
82              throw new MojoFailureException(e.getMessage(), e);
83          }
84      }
85  }