1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.plugin;
20
21 import javax.inject.Inject;
22
23 import java.io.IOException;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.scm.ScmException;
29 import org.apache.maven.scm.command.status.StatusScmResult;
30 import org.apache.maven.scm.manager.ScmManager;
31 import org.apache.maven.scm.repository.ScmRepository;
32 import org.apache.maven.settings.crypto.SettingsDecrypter;
33
34
35
36
37
38
39
40 @Mojo(name = "check-local-modification")
41 public class CheckLocalModificationsMojo extends AbstractScmMojo {
42
43
44
45
46 @Parameter(
47 property = "scm.checkLocalModification.errorMessage",
48 defaultValue = "The build will stop as there is local modifications")
49 private String errorMessage;
50
51
52
53
54 @Parameter(property = "scm.checkLocalModification.skip", defaultValue = "false")
55 private boolean skip;
56
57 @Inject
58 public CheckLocalModificationsMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
59 super(manager, settingsDecrypter);
60 }
61
62 public void execute() throws MojoExecutionException {
63 if (skip) {
64 getLog().info("check-local-modification execution has been skipped");
65 return;
66 }
67 super.execute();
68
69 try {
70 ScmRepository repository = getScmRepository();
71 StatusScmResult result = getScmManager().status(repository, getFileSet());
72
73 if (!result.isSuccess()) {
74 throw new MojoExecutionException(
75 "Unable to check for local modifications : " + result.getProviderMessage());
76 }
77
78 if (!result.getChangedFiles().isEmpty()) {
79 throw new MojoExecutionException(errorMessage);
80 }
81 } catch (IOException | ScmException e) {
82 throw new MojoExecutionException(e.getMessage(), e);
83 }
84 }
85 }