Coverage Report - org.apache.maven.scm.plugin.TagMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
TagMojo
70%
21/30
75%
3/4
9
 
 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.scm.ScmException;
 24  
 import org.apache.maven.scm.command.tag.TagScmResult;
 25  
 import org.apache.maven.scm.provider.ScmProvider;
 26  
 import org.apache.maven.scm.repository.ScmRepository;
 27  
 
 28  
 import java.io.IOException;
 29  
 import java.text.SimpleDateFormat;
 30  
 import java.util.Date;
 31  
 
 32  
 /**
 33  
  * Tag the project.
 34  
  *
 35  
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
 36  
  * @author <a href="saden1@gmil.com">Sharmarke Aden</a>
 37  
  * @version $Id: TagMojo.java 533717 2007-04-30 12:12:41Z evenisse $
 38  
  * @goal tag
 39  
  * @aggregator
 40  
  * @description Tag the project
 41  
  */
 42  2
 public class TagMojo
 43  
     extends AbstractScmMojo
 44  
 {
 45  
     /**
 46  
      * Tag name.
 47  
      *
 48  
      * @parameter expression="${tag}"
 49  
      */
 50  
     private String tag;
 51  
 
 52  
     /**
 53  
      * The message applied to the tag creation.
 54  
      *
 55  
      * @parameter expression="${message}"
 56  
      */
 57  
     private String message;
 58  
 
 59  
     /**
 60  
      * Set the timestamp format.
 61  
      *
 62  
      * @parameter expression="${timestampFormat}" default-value="yyyyMMddHHmmss"
 63  
      */
 64  
     private String timestampFormat;
 65  
 
 66  
     /**
 67  
      * Use timestamp tagging.
 68  
      *
 69  
      * @parameter expression="${addTimestamp}" default-value="false"
 70  
      */
 71  
     private boolean addTimestamp;
 72  
 
 73  
     /**
 74  
      * Define the timestamp position (end or begin).
 75  
      *
 76  
      * @parameter expression="${timestampPosition}" default-value="end"
 77  
      */
 78  
     private String timestampPosition;
 79  
 
 80  
     /**
 81  
      * Timestamp tag prefix.
 82  
      *
 83  
      * @parameter expression="${timestampPrefix}" default-value="-"
 84  
      */
 85  
     private String timestampPrefix;
 86  
 
 87  
     public void execute()
 88  
         throws MojoExecutionException
 89  
     {
 90  2
         super.execute();
 91  
 
 92  
         try
 93  
         {
 94  2
             SimpleDateFormat dateFormat = null;
 95  2
             String tagTimestamp = "";
 96  2
             String finalTag = tag;
 97  
 
 98  2
             if ( addTimestamp )
 99  
             {
 100  
                 try
 101  
                 {
 102  1
                     getLog().info( "Using timestamp pattern '" + timestampFormat + "'" );
 103  1
                     dateFormat = new SimpleDateFormat( timestampFormat );
 104  1
                     tagTimestamp = dateFormat.format( new Date() );
 105  1
                     getLog().info( "Using timestamp '" + tagTimestamp + "'" );
 106  
                 }
 107  0
                 catch ( IllegalArgumentException e )
 108  
                 {
 109  0
                     String msg = "The timestamp format '" + timestampFormat + "' is invalid.";
 110  0
                     getLog().error( msg, e );
 111  0
                     throw new MojoExecutionException( msg, e );
 112  1
                 }
 113  
 
 114  1
                 if ( "end".equals( timestampPosition ) )
 115  
                 {
 116  0
                     finalTag += timestampPrefix + tagTimestamp;
 117  
                 }
 118  
                 else
 119  
                 {
 120  1
                     finalTag = tagTimestamp + timestampPrefix + finalTag;
 121  
                 }
 122  
             }
 123  
 
 124  2
             ScmRepository repository = getScmRepository();
 125  2
             ScmProvider provider = getScmManager().getProviderByRepository( repository );
 126  
 
 127  2
             finalTag = provider.sanitizeTagName( finalTag );
 128  2
             getLog().info( "Final Tag Name: '" + finalTag + "'" );
 129  
 
 130  2
             TagScmResult result = provider.tag( repository, getFileSet(), finalTag, message );
 131  
 
 132  2
             checkResult( result );
 133  
         }
 134  0
         catch ( IOException e )
 135  
         {
 136  0
             throw new MojoExecutionException( "Cannot run tag command : ", e );
 137  
         }
 138  0
         catch ( ScmException e )
 139  
         {
 140  0
             throw new MojoExecutionException( "Cannot run tag command : ", e );
 141  2
         }
 142  2
     }
 143  
 }