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.File;
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.ScmFileSet;
29 import org.apache.maven.scm.command.status.StatusScmResult;
30 import org.apache.maven.scm.repository.ScmRepository;
31
32
33
34
35
36
37
38 @Mojo( name = "check-local-modification" )
39 public class CheckLocalModificationsMojo
40 extends AbstractScmMojo
41 {
42
43
44
45
46 @Parameter( property = "scm.checkLocalModification.errorMessage",
47 defaultValue = "The build will stop as there is local modifications" )
48 private String errorMessage;
49
50
51
52
53 @Parameter( property = "scm.checkLocalModification.skip", defaultValue = "false" )
54 private boolean skip;
55
56
57
58
59 @Parameter( defaultValue = "${basedir}", readonly = true )
60 private File baseDirectory;
61
62 public void execute()
63 throws MojoExecutionException
64 {
65 if ( skip )
66 {
67 getLog().info( "check-local-modification execution has been skipped" );
68 return;
69 }
70 super.execute();
71
72 StatusScmResult result = null;
73
74 try
75 {
76 ScmRepository repository = getScmRepository();
77 result = getScmManager().status( repository, new ScmFileSet( baseDirectory ) );
78 }
79 catch ( ScmException e )
80 {
81 throw new MojoExecutionException( e.getMessage(), e );
82 }
83
84 if ( !result.isSuccess() )
85 {
86 throw new MojoExecutionException( "Unable to check for local modifications : "
87 + result.getProviderMessage() );
88 }
89
90 if ( !result.getChangedFiles().isEmpty() )
91 {
92 getLog().error( errorMessage );
93 throw new MojoExecutionException( errorMessage );
94 }
95
96 }
97
98 }