Coverage Report - org.apache.maven.scm.plugin.UpdateMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
UpdateMojo
78%
14/18
50%
2/4
7
 
 1  
 package org.apache.maven.scm.plugin;
 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.plugin.MojoExecutionException;
 23  
 import org.apache.maven.project.MavenProject;
 24  
 import org.apache.maven.scm.ScmException;
 25  
 import org.apache.maven.scm.command.update.UpdateScmResult;
 26  
 import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
 27  
 import org.apache.maven.scm.repository.ScmRepository;
 28  
 
 29  
 import java.io.IOException;
 30  
 
 31  
 /**
 32  
  * Update the local working copy with the latest source from the configured scm url.
 33  
  *
 34  
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
 35  
  * @version $Id: UpdateMojo.java 654745 2008-05-09 10:07:11Z evenisse $
 36  
  * @goal update
 37  
  * @aggregator
 38  
  * @description Update the project
 39  
  */
 40  1
 public class UpdateMojo
 41  
     extends AbstractScmMojo
 42  
 {
 43  
     /**
 44  
      * The version type (branch/tag/revision) of scmVersion.
 45  
      *
 46  
      * @parameter expression="${scmVersionType}"
 47  
      */
 48  
     private String scmVersionType;
 49  
 
 50  
     /**
 51  
      * The version (revision number/branch name/tag name).
 52  
      *
 53  
      * @parameter expression="${scmVersion}"
 54  
      */
 55  
     private String scmVersion;
 56  
 
 57  
     /**
 58  
      * The project property where to store the revision name.
 59  
      *
 60  
      * @parameter expression="${revisionKey}" default-value="scm.revision"
 61  
      */
 62  
     private String revisionKey;
 63  
 
 64  
     /**
 65  
      * The maven project.
 66  
      *
 67  
      * @parameter expression="${project}"
 68  
      * @required
 69  
      * @readonly
 70  
      */
 71  
     private MavenProject project;
 72  
 
 73  
     /**
 74  
      * Run Changelog after update.
 75  
      *
 76  
      * @parameter expression="${runChangelog}" default-value="false"
 77  
      */
 78  1
     private boolean runChangelog = false;
 79  
 
 80  
     public void execute()
 81  
         throws MojoExecutionException
 82  
     {
 83  1
         super.execute();
 84  
 
 85  
         try
 86  
         {
 87  1
             ScmRepository repository = getScmRepository();
 88  
 
 89  1
             UpdateScmResult result = getScmManager().update( repository, getFileSet(),
 90  
                                                              getScmVersion( scmVersionType, scmVersion ),
 91  
                                                              runChangelog );
 92  
 
 93  1
             checkResult( result );
 94  
 
 95  1
             if ( result instanceof UpdateScmResultWithRevision )
 96  
             {
 97  1
                 String revision = ( (UpdateScmResultWithRevision) result ).getRevision();
 98  
 
 99  1
                 getLog().info( "Storing revision in '" + revisionKey + "' project property." );
 100  
 
 101  1
                 if ( project.getProperties() != null ) // Remove the test when we'll use plugin-test-harness 1.0-alpha-2
 102  
                 {
 103  1
                     project.getProperties().put( revisionKey, revision );
 104  
                 }
 105  
 
 106  1
                 getLog().info( "Project at revision " + revision );
 107  
             }
 108  
         }
 109  0
         catch ( IOException e )
 110  
         {
 111  0
             throw new MojoExecutionException( "Cannot run update command : ", e );
 112  
         }
 113  0
         catch ( ScmException e )
 114  
         {
 115  0
             throw new MojoExecutionException( "Cannot run update command : ", e );
 116  1
         }
 117  1
     }
 118  
 }