| 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.IOException; |
| 23 |
|
| 24 |
import org.apache.maven.plugin.MojoExecutionException; |
| 25 |
import org.apache.maven.plugins.annotations.Mojo; |
| 26 |
import org.apache.maven.plugins.annotations.Parameter; |
| 27 |
import org.apache.maven.scm.ScmException; |
| 28 |
import org.apache.maven.scm.command.status.StatusScmResult; |
| 29 |
import org.apache.maven.scm.repository.ScmRepository; |
| 30 |
|
| 31 |
/** |
| 32 |
* This mojo will fail the build if there is any local modifications |
| 33 |
* |
| 34 |
* @author Olivier Lamy |
| 35 |
* @since 1.2 |
| 36 |
*/ |
| 37 |
@Mojo( name = "check-local-modification" ) |
| 38 |
public class CheckLocalModificationsMojo |
| 39 |
extends AbstractScmMojo |
| 40 |
{ |
| 41 |
|
| 42 |
/** |
| 43 |
* Custom error message |
| 44 |
*/ |
| 45 |
@Parameter( property = "scm.checkLocalModification.errorMessage", |
| 46 |
defaultValue = "The build will stop as there is local modifications" ) |
| 47 |
private String errorMessage; |
| 48 |
|
| 49 |
/** |
| 50 |
* Skip the check for local modifications if set to {@code true}. |
| 51 |
*/ |
| 52 |
@Parameter( property = "scm.checkLocalModification.skip", defaultValue = "false" ) |
| 53 |
private boolean skip; |
| 54 |
|
| 55 |
public void execute() |
| 56 |
throws MojoExecutionException |
| 57 |
{ |
| 58 |
if ( skip ) |
| 59 |
{ |
| 60 |
getLog().info( "check-local-modification execution has been skipped" ); |
| 61 |
return; |
| 62 |
} |
| 63 |
super.execute(); |
| 64 |
|
| 65 |
StatusScmResult result = null; |
| 66 |
|
| 67 |
try |
| 68 |
{ |
| 69 |
ScmRepository repository = getScmRepository(); |
| 70 |
result = getScmManager().status( repository, getFileSet() ); |
| 71 |
} |
| 72 |
catch ( IOException | ScmException e ) |
| 73 |
{ |
| 74 |
throw new MojoExecutionException( e.getMessage(), e ); |
| 75 |
} |
| 76 |
|
| 77 |
if ( !result.isSuccess() ) |
| 78 |
{ |
| 79 |
throw new MojoExecutionException( "Unable to check for local modifications : " |
| 80 |
+ result.getProviderMessage() ); |
| 81 |
} |
| 82 |
|
| 83 |
if ( !result.getChangedFiles().isEmpty() ) |
| 84 |
{ |
| 85 |
getLog().error( errorMessage ); |
| 86 |
throw new MojoExecutionException( errorMessage ); |
| 87 |
} |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
} |