Coverage Report - org.apache.maven.shared.release.phase.RunPerformGoalsPhase
 
Classes in this File Line Coverage Branch Coverage Complexity
RunPerformGoalsPhase
91%
31/34
77%
14/18
3,25
 
 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  62
 public class RunPerformGoalsPhase
 40  
     extends AbstractRunGoalsPhase
 41  
 {
 42  
     public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
 43  
                                   List<MavenProject> reactorProjects )
 44  
         throws ReleaseExecutionException
 45  
     {
 46  16
         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  16
         String additionalArguments = releaseDescriptor.getAdditionalArguments();
 54  
 
 55  16
         if ( releaseDescriptor.isUseReleaseProfile() )
 56  
         {
 57  12
             if ( !StringUtils.isEmpty( additionalArguments ) )
 58  
             {
 59  2
                 additionalArguments = additionalArguments + " -DperformRelease=true";
 60  
             }
 61  
             else
 62  
             {
 63  10
                 additionalArguments = "-DperformRelease=true";
 64  
             }
 65  
         }
 66  
         
 67  16
         String pomFileName = releaseDescriptor.getPomFileName();
 68  16
         if ( pomFileName == null )
 69  
         {
 70  14
             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  16
         if ( !StringUtils.isEmpty( additionalArguments ) )
 76  
         {
 77  14
             additionalArguments = additionalArguments + " -f " + pomFileName;
 78  
         }
 79  
         else
 80  
         {
 81  2
             additionalArguments = "-f " + pomFileName;
 82  
         }
 83  
 
 84  16
         String workDir = releaseDescriptor.getWorkingDirectory();
 85  16
         if ( workDir == null )
 86  
         {
 87  16
             workDir = System.getProperty( "user.dir" );
 88  
         }
 89  
 
 90  
 
 91  16
         File pomFile = new File( workDir, pomFileName );
 92  16
         PomFinder pomFinder = new PomFinder( getLogger() );
 93  16
         boolean foundPom = false;
 94  
 
 95  16
         if ( StringUtils.isEmpty( releaseDescriptor.getScmRelativePathProjectDirectory() ) )
 96  
         {
 97  16
             foundPom = pomFinder.parsePom( pomFile );
 98  
         }
 99  
 
 100  
         File workDirectory;
 101  16
         if ( simulate )
 102  
         {
 103  0
             workDirectory = new File( releaseDescriptor.getWorkingDirectory() );
 104  
         }
 105  
         else
 106  
         {
 107  16
             workDirectory = new File( releaseDescriptor.getCheckoutDirectory() );
 108  
         }
 109  
 
 110  16
         if ( foundPom )
 111  
         {
 112  14
             File matchingPom = pomFinder.findMatchingPom( workDirectory );
 113  14
             if ( matchingPom != null )
 114  
             {
 115  0
                 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  0
                 workDirectory = matchingPom.getParentFile();
 121  
             }
 122  
         }
 123  
 
 124  16
         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  2
         ReleaseResult result = new ReleaseResult();
 132  
 
 133  2
         logInfo( result, "Executing perform goals  - since this is simulation mode these goals are skipped." );
 134  
 
 135  
         //runLogic( releaseDescriptor, releaseEnvironment, reactorProjects, true );
 136  
 
 137  2
         return result;
 138  
     }
 139  
 
 140  
     protected String getGoals( ReleaseDescriptor releaseDescriptor )
 141  
     {
 142  16
         return releaseDescriptor.getPerformGoals();
 143  
     }
 144  
 }