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 javax.inject.Inject;
22  
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugin.MojoFailureException;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.scm.manager.ScmManager;
28  import org.apache.maven.shared.release.DefaultReleaseManagerListener;
29  import org.apache.maven.shared.release.ReleaseExecutionException;
30  import org.apache.maven.shared.release.ReleaseFailureException;
31  import org.apache.maven.shared.release.ReleaseManager;
32  import org.apache.maven.shared.release.ReleaseRollbackRequest;
33  import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
34  
35  /**
36   * Rollback changes made by a previous release. This requires that the previous release descriptor
37   * <code>release.properties</code> is still available in the local working copy. For more info see <a
38   * href="https://maven.apache.org/plugins/maven-release-plugin/usage/rollback-release.html"
39   * >https://maven.apache.org/plugins/maven-release-plugin/usage/rollback-release.html</a>.
40   *
41   * @since 2.0-beta-5
42   * @author Edwin Punzalan
43   */
44  @Mojo(name = "rollback", aggregator = true)
45  public class RollbackReleaseMojo extends AbstractScmReadWriteReleaseMojo {
46  
47      /**
48       * The SCM commit comment when rolling back.
49       * Defaults to "@{prefix} rollback the release of @{releaseLabel}".
50       * <p>
51       * Property interpolation is performed on the value, but in order to ensure that the interpolation occurs
52       * during release, you must use <code>@{...}</code> to reference the properties rather than <code>${...}</code>.
53       * The following properties are available:
54       * <ul>
55       *     <li><code>prefix</code> - The comment prefix.
56       *     <li><code>groupId</code> - The groupId of the root project.
57       *     <li><code>artifactId</code> - The artifactId of the root project.
58       *     <li><code>releaseLabel</code> - The release version of the root project.
59       * </ul>
60       *
61       * @since 3.0.0-M5
62       */
63      @Parameter(
64              defaultValue = "@{prefix} rollback the release of @{releaseLabel}",
65              property = "scmRollbackCommitComment")
66      private String scmRollbackCommitComment = "@{prefix} rollback the release of @{releaseLabel}";
67  
68      @Inject
69      public RollbackReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
70          super(releaseManager, scmManager);
71      }
72  
73      @Override
74      public void execute() throws MojoExecutionException, MojoFailureException {
75          super.execute();
76  
77          final ReleaseDescriptorBuilder config = createReleaseDescriptor();
78          config.setScmRollbackCommitComment(scmRollbackCommitComment);
79  
80          try {
81              ReleaseRollbackRequest rollbackRequest = new ReleaseRollbackRequest();
82              rollbackRequest.setReleaseDescriptorBuilder(config);
83              rollbackRequest.setReleaseEnvironment(getReleaseEnvironment());
84              rollbackRequest.setReactorProjects(getReactorProjects());
85              rollbackRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog()));
86  
87              releaseManager.rollback(rollbackRequest);
88          } catch (ReleaseExecutionException e) {
89              throw new MojoExecutionException(e.getMessage(), e);
90          } catch (ReleaseFailureException e) {
91              throw new MojoFailureException(e.getMessage(), e);
92          }
93      }
94  }