View Javadoc
1   package org.apache.maven.shared.release.phase;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.project.MavenProject;
23  import org.apache.maven.shared.release.ReleaseExecutionException;
24  import org.apache.maven.shared.release.ReleaseFailureException;
25  import org.apache.maven.shared.release.ReleaseResult;
26  import org.apache.maven.shared.release.config.ReleaseDescriptor;
27  import org.apache.maven.shared.release.env.ReleaseEnvironment;
28  import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
29  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
30  
31  import java.util.List;
32  
33  /**
34   * Commit the changes that were done to prepare the branch or tag to the SCM.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   */
38  public class ScmCommitPreparationPhase
39      extends AbstractScmCommitPhase
40  {
41  
42      protected void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
43                               List<MavenProject> reactorProjects, ReleaseResult result, boolean simulating )
44          throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException
45      {
46          // no prepare-commit required
47          if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() )
48          {
49              String parameterName;
50              if ( releaseDescriptor.isBranchCreation() ) 
51              {
52                  parameterName = "suppressCommitBeforeBranch";
53              }
54              else 
55              {
56                  parameterName = "suppressCommitBeforeTag";
57              }
58  
59              if ( simulating )
60              {
61                  logInfo( result,
62                           "Full run would not commit changes, " + "because " + parameterName + " is set to true." );
63              }
64              else
65              {
66                  logInfo( result,
67                           "Modified POMs are not committed because " + parameterName + " is set to true." );
68              }
69          }
70          // commit development versions required
71          else
72          {
73              String message = createMessage( reactorProjects, releaseDescriptor );
74              if ( simulating )
75              {
76                  simulateCheckins( releaseDescriptor, reactorProjects, result, message );
77              }
78              else
79              {
80                  performCheckins( releaseDescriptor, releaseEnvironment, reactorProjects, message );
81              }
82          }
83      }
84  
85      protected void validateConfiguration( ReleaseDescriptor releaseDescriptor )
86          throws ReleaseFailureException
87      {
88          super.validateConfiguration( releaseDescriptor );
89  
90          if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() && releaseDescriptor.isRemoteTagging() )
91          {
92              throw new ReleaseFailureException(
93                  "Cannot perform a remote tag or branch without committing the working copy first." );
94          }
95      }
96  }