Coverage Report - org.apache.maven.plugin.reactor.ResumeMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ResumeMojo
62%
29/47
44%
16/36
24
 
 1  
 package org.apache.maven.plugin.reactor;
 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 java.io.File;
 23  
 import java.util.Arrays;
 24  
 import java.util.List;
 25  
 
 26  
 import org.apache.maven.plugin.AbstractMojo;
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.plugin.MojoFailureException;
 29  
 import org.apache.maven.project.MavenProject;
 30  
 import org.apache.maven.project.ProjectSorter;
 31  
 import org.apache.maven.shared.invoker.Invoker;
 32  
 
 33  
 /**
 34  
  * Goal to resume building a reactor at a certain point 
 35  
  *
 36  
  * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
 37  
  * @goal resume
 38  
  * @aggregator
 39  
  * @phase process-sources
 40  
  */
 41  1
 public class ResumeMojo
 42  
     extends AbstractMojo
 43  
 {
 44  
     
 45  
     /**
 46  
      * @parameter expression="${project.collectedProjects}"
 47  
      */
 48  
     List collectedProjects;
 49  
     
 50  
     /**
 51  
      * Location of the file.
 52  
      * @parameter expression="${basedir}"
 53  
      */
 54  
     File baseDir;
 55  
     
 56  
     /**
 57  
      * @parameter expression="${make.group}" default-value="${project.groupId}"
 58  
      */
 59  
     String continueFromGroup;
 60  
     
 61  
     /**
 62  
      * The artifact from which we'll resume, e.g. "com.mycompany:foo" or just "foo"
 63  
      * @parameter expression="${fromArtifact}" default-value="null"
 64  
      * @required
 65  
      */
 66  
     String continueFromProject;
 67  
     
 68  
     /**
 69  
      * The project folder from which we'll resume
 70  
      * @parameter expression="${from}" default-value="null"
 71  
      * @required
 72  
      */
 73  
     File continueFromFolder;
 74  
     
 75  
     /**
 76  
      * Goals to run on subproject
 77  
      * @parameter expression="${make.goals}" default-value="install"
 78  
      */
 79  
     String goals;
 80  
     
 81  
     /**
 82  
      * @component
 83  
      */
 84  
     Invoker invoker;
 85  
     
 86  
     /**
 87  
      * Don't really do anything; just print a message that describes what the command would have done
 88  
      * @parameter expression="${make.printOnly}"
 89  
      */
 90  1
     boolean printOnly = false;
 91  
     
 92  
     /**
 93  
      * @component
 94  
      */
 95  
     SimpleInvoker simpleInvoker;
 96  
     
 97  
     public void execute()
 98  
         throws MojoExecutionException, MojoFailureException
 99  
     {
 100  1
             if ( "null".equals( continueFromProject ) )
 101  
             {
 102  0
                 continueFromProject = null;
 103  
             }
 104  1
             if ( new File( "null" ).equals( continueFromFolder ) )
 105  
             {
 106  0
                 continueFromFolder = null;
 107  
             }
 108  1
         if ( continueFromFolder == null && continueFromProject == null )
 109  
         {
 110  0
             throw new MojoFailureException("You must specify either a folder or a project with -Dfrom=baz/bar or -DfromArtifact=com.mycompany:foo (groupId is optional)");
 111  
         }
 112  1
         if (continueFromFolder != null && continueFromProject != null )
 113  
         {
 114  0
             throw new MojoFailureException("You can't specify both a folder (" + continueFromFolder + ") and an artifact (" + continueFromProject + ")");
 115  
         }
 116  1
         if ( continueFromFolder != null && !continueFromFolder.exists() )
 117  
         {
 118  0
             throw new MojoFailureException("Folder doesn't exist: " + continueFromFolder.getAbsolutePath() );
 119  
         }
 120  
         String[] reactorIncludes;
 121  
         try
 122  
         {
 123  
             
 124  1
             if (collectedProjects.size() == 0) {
 125  0
                 throw new NonReactorException();
 126  
             }
 127  1
             ProjectSorter ps = new ProjectSorter( collectedProjects );
 128  
                         
 129  1
             List sortedProjects = ps.getSortedProjects();
 130  
             
 131  1
             String projectName = null;
 132  1
             if ( continueFromProject != null)
 133  
             {
 134  0
                 projectName = continueFromProject;
 135  0
                 if ( projectName.indexOf(':') != -1 ) {
 136  0
                     int index = continueFromProject.indexOf(':');
 137  0
                     continueFromGroup = continueFromProject.substring( 0, index );
 138  0
                     projectName = continueFromProject.substring( index+1 );
 139  
                 }
 140  
             }
 141  
             
 142  1
             boolean found = false;
 143  1
             int i = 0;
 144  3
             for (; i < sortedProjects.size(); i++) {
 145  2
                 MavenProject mp = (MavenProject) sortedProjects.get( i );
 146  2
                 if ( continueFromFolder == null )
 147  
                 {
 148  0
                     if ( continueFromGroup.equals( mp.getGroupId() ) && projectName.equals( mp.getArtifactId() ) )
 149  
                     {
 150  0
                         found = true;
 151  0
                         break;
 152  
                     }
 153  
                 } else {
 154  2
                     if ( continueFromFolder.equals( mp.getFile().getParentFile() ) )
 155  
                     {
 156  1
                         found = true;
 157  1
                         break;
 158  
                     }
 159  
                 }
 160  
             }
 161  
             
 162  1
             if (!found) throw new MissingProjectException(continueFromGroup + ":" + projectName);
 163  
             
 164  
             // construct array of relative POM paths
 165  1
             reactorIncludes = new String[sortedProjects.size() - i];
 166  3
             for ( int j = i; j < sortedProjects.size(); j++ )
 167  
             {
 168  2
                 MavenProject mp = (MavenProject) sortedProjects.get( j );
 169  2
                 String path = RelativePather.getRelativePath( baseDir, mp.getFile() );
 170  2
                 reactorIncludes[j- i] = path;
 171  
             }
 172  
         }
 173  0
         catch (MojoFailureException e) {
 174  0
             throw e;
 175  
         }
 176  0
         catch ( Exception e )
 177  
         {
 178  0
             throw new MojoExecutionException( "Problem generating dependency tree", e );
 179  1
         }
 180  
 
 181  1
         simpleInvoker.runReactor( reactorIncludes, Arrays.asList( goals.split( "," ) ), invoker, printOnly, getLog() );
 182  
 
 183  1
     }
 184  
 }