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.ReleaseResult;
25  import org.apache.maven.shared.release.config.ReleaseDescriptor;
26  import org.apache.maven.shared.release.env.ReleaseEnvironment;
27  import org.apache.maven.shared.release.util.PomFinder;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  import java.io.File;
31  import java.util.List;
32  
33  /**
34   * Run the integration tests for the project to verify that it builds before committing.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   * @plexus.component role="org.apache.maven.shared.release.phase.ReleasePhase" role-hint="run-perform-goals"
38   */
39  public class RunPerformGoalsPhase
40      extends AbstractRunGoalsPhase
41  {
42      public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
43                                    List<MavenProject> reactorProjects )
44          throws ReleaseExecutionException
45      {
46          return runLogic( releaseDescriptor, releaseEnvironment, reactorProjects, false );
47      }
48  
49      private ReleaseResult runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
50                                    List<MavenProject> reactorProjects, boolean simulate )
51          throws ReleaseExecutionException
52      {
53          String additionalArguments = releaseDescriptor.getAdditionalArguments();
54  
55          if ( releaseDescriptor.isUseReleaseProfile() )
56          {
57              if ( !StringUtils.isEmpty( additionalArguments ) )
58              {
59                  additionalArguments = additionalArguments + " -DperformRelease=true";
60              }
61              else
62              {
63                  additionalArguments = "-DperformRelease=true";
64              }
65          }
66          
67          String pomFileName = releaseDescriptor.getPomFileName();
68          if ( pomFileName == null )
69          {
70              pomFileName = "pom.xml";
71          }
72  
73          // ensure we don't use the release pom for the perform goals
74          // ^^ paranoia? A MavenExecutor has already access to this. Probably worth refactoring. 
75          if ( !StringUtils.isEmpty( additionalArguments ) )
76          {
77              additionalArguments = additionalArguments + " -f " + pomFileName;
78          }
79          else
80          {
81              additionalArguments = "-f " + pomFileName;
82          }
83  
84          String workDir = releaseDescriptor.getWorkingDirectory();
85          if ( workDir == null )
86          {
87              workDir = System.getProperty( "user.dir" );
88          }
89  
90  
91          File pomFile = new File( workDir, pomFileName );
92          PomFinder pomFinder = new PomFinder( getLogger() );
93          boolean foundPom = false;
94  
95          if ( StringUtils.isEmpty( releaseDescriptor.getScmRelativePathProjectDirectory() ) )
96          {
97              foundPom = pomFinder.parsePom( pomFile );
98          }
99  
100         File workDirectory;
101         if ( simulate )
102         {
103             workDirectory = new File( releaseDescriptor.getWorkingDirectory() );
104         }
105         else
106         {
107             workDirectory = new File( releaseDescriptor.getCheckoutDirectory() );
108         }
109 
110         if ( foundPom )
111         {
112             File matchingPom = pomFinder.findMatchingPom( workDirectory );
113             if ( matchingPom != null )
114             {
115                 getLogger().info( "Invoking perform goals in directory " + matchingPom.getParent() );
116                 // The directory of the POM in a flat project layout is not
117                 // the same directory as the SCM checkout directory!
118                 // The same is true for a sparse checkout in e.g. GIT
119                 // the project to build could be in target/checkout/some/dir/
120                 workDirectory = matchingPom.getParentFile();
121             }
122         }
123 
124         return execute( releaseDescriptor, releaseEnvironment, workDirectory, additionalArguments );
125     }
126 
127     public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
128                                    List<MavenProject> reactorProjects )
129         throws ReleaseExecutionException
130     {
131         ReleaseResult result = new ReleaseResult();
132 
133         logInfo( result, "Executing perform goals  - since this is simulation mode these goals are skipped." );
134 
135         //runLogic( releaseDescriptor, releaseEnvironment, reactorProjects, true );
136 
137         return result;
138     }
139 
140     protected String getGoals( ReleaseDescriptor releaseDescriptor )
141     {
142         return releaseDescriptor.getPerformGoals();
143     }
144 }