Coverage Report - org.apache.maven.scm.plugin.StatusMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
StatusMojo
72 %
16/22
75 %
6/8
6
 
 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 java.io.File;
 23  
 import java.io.IOException;
 24  
 
 25  
 import org.apache.maven.plugin.MojoExecutionException;
 26  
 import org.apache.maven.scm.ScmException;
 27  
 import org.apache.maven.scm.ScmFile;
 28  
 import org.apache.maven.scm.command.status.StatusScmResult;
 29  
 import org.apache.maven.scm.repository.ScmRepository;
 30  
 import org.codehaus.plexus.util.StringUtils;
 31  
 
 32  
 /**
 33  
  * Display the modification status of the files in the configured scm url.
 34  
  *
 35  
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
 36  
  * @author Olivier Lamy
 37  
  * @version $Id: StatusMojo.java 1054215 2011-01-01 09:45:44Z olamy $
 38  
  * @goal status
 39  
  * @aggregator
 40  
  */
 41  1
 public class StatusMojo
 42  
     extends AbstractScmMojo
 43  
 {
 44  
     /** {@inheritDoc} */
 45  
     public void execute()
 46  
         throws MojoExecutionException
 47  
     {
 48  1
         super.execute();
 49  
 
 50  
         try
 51  
         {
 52  1
             ScmRepository repository = getScmRepository();
 53  
 
 54  1
             StatusScmResult result = getScmManager().status( repository, getFileSet() );
 55  
 
 56  1
             checkResult( result );
 57  
 
 58  1
             File baseDir = getFileSet().getBasedir();
 59  
 
 60  
             // Determine the maximum length of the status column
 61  1
             int maxLen = 0;
 62  
 
 63  1
             for ( ScmFile file : result.getChangedFiles() )
 64  
             {
 65  1
                 maxLen = Math.max( maxLen, file.getStatus().toString().length() );
 66  
             }
 67  
 
 68  1
             for ( ScmFile file : result.getChangedFiles() )
 69  
             {
 70  
                 // right align all of the statuses
 71  1
                 getLog().info(
 72  
                                StringUtils.leftPad( file.getStatus().toString(), maxLen ) + " status for "
 73  
                                    + getRelativePath( baseDir, file.getPath() ) );
 74  
             }
 75  
         }
 76  0
         catch ( IOException e )
 77  
         {
 78  0
             throw new MojoExecutionException( "Cannot run status command : ", e );
 79  
         }
 80  0
         catch ( ScmException e )
 81  
         {
 82  0
             throw new MojoExecutionException( "Cannot run status command : ", e );
 83  1
         }
 84  1
     }
 85  
 
 86  
     /**
 87  
      * Formats the filename so that it is a relative directory from the base.
 88  
      *
 89  
      * @param baseDir
 90  
      * @param path
 91  
      * @return The relative path
 92  
      */
 93  
     protected String getRelativePath( File baseDir, String path )
 94  
     {
 95  1
         if ( path.equals( baseDir.getAbsolutePath() ) )
 96  
         {
 97  0
             return ".";
 98  
         }
 99  1
         else if ( path.indexOf( baseDir.getAbsolutePath() ) == 0 )
 100  
         {
 101  
             // the + 1 gets rid of a leading file separator
 102  0
             return path.substring( baseDir.getAbsolutePath().length() + 1 );
 103  
         }
 104  
         else
 105  
         {
 106  1
             return path;
 107  
         }
 108  
     }
 109  
 }