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