1 package org.apache.maven.scm.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
33
34
35
36
37 @Mojo( name = "check-local-modification" )
38 public class CheckLocalModificationsMojo
39 extends AbstractScmMojo
40 {
41
42
43
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
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 }