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.shared.release.DefaultReleaseManagerListener;
25 import org.apache.maven.shared.release.ReleaseCleanRequest;
26 import org.apache.maven.shared.release.ReleaseFailureException;
27 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
28
29 /**
30 * Clean up after a release preparation. This is done automatically after a successful <code>release:perform</code>,
31 * so is best served for cleaning up a failed or abandoned release, or a dry run. Note that only the working copy
32 * is cleaned up, no previous steps are rolled back.
33 * For more info see <a href="https://maven.apache.org/plugins/maven-release-plugin/usage/clean-release.html"
34 * >https://maven.apache.org/plugins/maven-release-plugin/usage/clean-release.html</a>.
35 *
36 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37 */
38 @Mojo(name = "clean", aggregator = true)
39 public class CleanReleaseMojo extends AbstractReleaseMojo {
40 @Override
41 public void execute() throws MojoExecutionException, MojoFailureException {
42 ReleaseDescriptorBuilder releaseDescriptor = new ReleaseDescriptorBuilder();
43 releaseDescriptor.setWorkingDirectory(getBasedir().getAbsolutePath());
44
45 ReleaseCleanRequest cleanRequest = new ReleaseCleanRequest();
46 cleanRequest.setReleaseDescriptorBuilder(releaseDescriptor);
47 cleanRequest.setReactorProjects(getReactorProjects());
48 cleanRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog()));
49
50 try {
51 releaseManager.clean(cleanRequest);
52 } catch (ReleaseFailureException e) {
53 throw new MojoFailureException(e.getMessage());
54 }
55 }
56 }