Coverage Report - org.apache.maven.scm.plugin.StatusMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
StatusMojo
42%
11/26
25%
2/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 org.apache.maven.plugin.MojoExecutionException;
 23  
 import org.apache.maven.scm.ScmException;
 24  
 import org.apache.maven.scm.ScmFile;
 25  
 import org.apache.maven.scm.command.status.StatusScmResult;
 26  
 import org.apache.maven.scm.repository.ScmRepository;
 27  
 import org.codehaus.plexus.util.StringUtils;
 28  
 
 29  
 import java.io.File;
 30  
 import java.io.IOException;
 31  
 import java.util.Iterator;
 32  
 
 33  
 /**
 34  
  * Display the modification status of the files in the configured scm url.
 35  
  *
 36  
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
 37  
  * @version $Id: StatusMojo.java 538856 2007-05-17 09:58:55Z evenisse $
 38  
  * @goal status
 39  
  * @description Project status
 40  
  * @aggregator
 41  
  */
 42  1
 public class StatusMojo
 43  
     extends AbstractScmMojo
 44  
 {
 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 ( Iterator iter = result.getChangedFiles().iterator(); iter.hasNext(); )
 64  
             {
 65  0
                 ScmFile file = (ScmFile) iter.next();
 66  0
                 maxLen = Math.max( maxLen, file.getStatus().toString().length() );
 67  0
             }
 68  
 
 69  1
             for ( Iterator iter = result.getChangedFiles().iterator(); iter.hasNext(); )
 70  
             {
 71  0
                 ScmFile file = (ScmFile) iter.next();
 72  
 
 73  
                 // right align all of the statuses
 74  0
                 getLog().info( StringUtils.leftPad( file.getStatus().toString(), maxLen ) + " status for " +
 75  
                     getRelativePath( baseDir, file.getPath() ) );
 76  0
             }
 77  
         }
 78  0
         catch ( IOException e )
 79  
         {
 80  0
             throw new MojoExecutionException( "Cannot run status command : ", e );
 81  
         }
 82  0
         catch ( ScmException e )
 83  
         {
 84  0
             throw new MojoExecutionException( "Cannot run status command : ", e );
 85  1
         }
 86  1
     }
 87  
 
 88  
     /**
 89  
      * Formats the filename so that it is a relative directory from the base.
 90  
      *
 91  
      * @param baseDir
 92  
      * @param path
 93  
      * @return The relative path
 94  
      */
 95  
     protected String getRelativePath( File baseDir, String path )
 96  
     {
 97  0
         if ( path.equals( baseDir.getAbsolutePath() ) )
 98  
         {
 99  0
             return ".";
 100  
         }
 101  0
         else if ( path.indexOf( baseDir.getAbsolutePath() ) == 0 )
 102  
         {
 103  
             // the + 1 gets rid of a leading file separator
 104  0
             return path.substring( baseDir.getAbsolutePath().length() + 1 );
 105  
         }
 106  
         else
 107  
         {
 108  0
             return path;
 109  
         }
 110  
     }
 111  
 }