Coverage Report - org.apache.maven.scm.plugin.CheckLocalModificationsMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckLocalModificationsMojo
0%
0/17
0%
0/6
9
 
 1  
 package org.apache.maven.scm.plugin;
 2  
 
 3  
 import java.io.File;
 4  
 
 5  
 import org.apache.maven.plugin.MojoExecutionException;
 6  
 import org.apache.maven.scm.ScmException;
 7  
 import org.apache.maven.scm.ScmFileSet;
 8  
 import org.apache.maven.scm.command.status.StatusScmResult;
 9  
 import org.apache.maven.scm.repository.ScmRepository;
 10  
 
 11  
 /*
 12  
  * Licensed to the Apache Software Foundation (ASF) under one
 13  
  * or more contributor license agreements.  See the NOTICE file
 14  
  * distributed with this work for additional information
 15  
  * regarding copyright ownership.  The ASF licenses this file
 16  
  * to you under the Apache License, Version 2.0 (the
 17  
  * "License"); you may not use this file except in compliance
 18  
  * with the License.  You may obtain a copy of the License at
 19  
  *
 20  
  *    http://www.apache.org/licenses/LICENSE-2.0
 21  
  *
 22  
  * Unless required by applicable law or agreed to in writing,
 23  
  * software distributed under the License is distributed on an
 24  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 25  
  * KIND, either express or implied.  See the License for the
 26  
  * specific language governing permissions and limitations
 27  
  * under the License.
 28  
  */
 29  
 
 30  
 /**
 31  
  * This mojo will fail the build if there is any local modifications
 32  
  * @goal check-local-modification
 33  
  * @author <a href="mailto:olamy@apache.org">olamy</a>
 34  
  * @since 1.2
 35  
  */
 36  0
 public class CheckLocalModificationsMojo
 37  
     extends AbstractScmMojo
 38  
 {
 39  
 
 40  
     /**
 41  
      * Custom error message
 42  
      *
 43  
      * @parameter expression="${scm.checkLocalModification.errorMessage}" 
 44  
      *            default-value="The build will stop as there is local modifications";
 45  
      */
 46  
     private String errorMessage; 
 47  
     
 48  
     /**
 49  
      * Custom error message
 50  
      *
 51  
      * @parameter expression="${scm.checkLocalModification.skip}" default-value="false";
 52  
      */    
 53  
     private boolean skip;
 54  
     
 55  
     /**
 56  
      * current directory
 57  
      *
 58  
      * @parameter default-value="${basedir}";
 59  
      * @readonly
 60  
      */     
 61  
     private File baseDirectory;
 62  
 
 63  
     public void execute()
 64  
         throws MojoExecutionException
 65  
     {
 66  0
         if ( skip )
 67  
         {
 68  0
             getLog().info( "check-local-modification execution has been skipped" );
 69  0
             return;
 70  
         }
 71  0
         super.execute();
 72  
 
 73  0
         StatusScmResult result = null;
 74  
 
 75  
         try
 76  
         {
 77  0
             ScmRepository repository = getScmRepository();
 78  0
             result = getScmManager().status( repository, new ScmFileSet( baseDirectory ) );
 79  
         }
 80  0
         catch ( ScmException e )
 81  
         {
 82  0
             throw new MojoExecutionException( e.getMessage(), e );
 83  0
         }
 84  
 
 85  0
         if ( !result.isSuccess() )
 86  
         {
 87  0
             throw new MojoExecutionException( "Unable to check for local modifications :" + result.getProviderMessage() );
 88  
         }
 89  
 
 90  0
         if ( !result.getChangedFiles().isEmpty() )
 91  
         {
 92  0
             getLog().error( errorMessage );
 93  0
             throw new MojoExecutionException( errorMessage );
 94  
         }
 95  
 
 96  0
     }
 97  
     
 98  
 }