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.shared.release.phase;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.util.List;
25  
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.shared.release.ReleaseExecutionException;
28  import org.apache.maven.shared.release.ReleaseFailureException;
29  import org.apache.maven.shared.release.ReleaseResult;
30  import org.apache.maven.shared.release.config.ReleaseDescriptor;
31  import org.apache.maven.shared.release.env.ReleaseEnvironment;
32  
33  /**
34   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   */
36  @Singleton
37  @Named("verify-completed-prepare-phases")
38  public class CheckCompletedPreparePhasesPhase extends AbstractReleasePhase {
39      @Override
40      public ReleaseResult execute(
41              ReleaseDescriptor releaseDescriptor,
42              ReleaseEnvironment releaseEnvironment,
43              List<MavenProject> reactorProjects)
44              throws ReleaseExecutionException, ReleaseFailureException {
45          ReleaseResult result = new ReleaseResult();
46  
47          // if we stopped mid-way through preparation - don't perform
48          if (releaseDescriptor.getCompletedPhase() != null
49                  && !"end-release".equals(releaseDescriptor.getCompletedPhase())) {
50              String message = "Cannot perform release - the preparation step was stopped mid-way. Please re-run "
51                      + "release:prepare to continue, or perform the release from an SCM tag.";
52  
53              result.setResultCode(ReleaseResult.ERROR);
54  
55              logError(result, message);
56  
57              throw new ReleaseFailureException(message);
58          }
59  
60          if (releaseDescriptor.getScmSourceUrl() == null) {
61              String message = "No SCM URL was provided to perform the release from";
62  
63              result.setResultCode(ReleaseResult.ERROR);
64  
65              logError(result, message);
66  
67              throw new ReleaseFailureException(message);
68          }
69  
70          result.setResultCode(ReleaseResult.SUCCESS);
71  
72          return result;
73      }
74  
75      @Override
76      public ReleaseResult simulate(
77              ReleaseDescriptor releaseDescriptor,
78              ReleaseEnvironment releaseEnvironment,
79              List<MavenProject> reactorProjects)
80              throws ReleaseExecutionException, ReleaseFailureException {
81          return execute(releaseDescriptor, releaseEnvironment, reactorProjects);
82      }
83  }