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 java.io.File;
22 import java.io.IOException;
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.scm.ScmException;
28 import org.apache.maven.scm.ScmFile;
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 = "status", aggregator = true)
39 public class StatusMojo extends AbstractScmMojo {
40
41 public void execute() throws MojoExecutionException {
42 super.execute();
43
44 try {
45 ScmRepository repository = getScmRepository();
46
47 StatusScmResult result = getScmManager().status(repository, getFileSet());
48
49 checkResult(result);
50
51 File baseDir = getFileSet().getBasedir();
52
53
54 int maxLen = 0;
55
56 for (ScmFile file : result.getChangedFiles()) {
57 maxLen = Math.max(maxLen, file.getStatus().toString().length());
58 }
59
60 for (ScmFile file : result.getChangedFiles()) {
61
62 getLog().info(StringUtils.leftPad(file.getStatus().toString(), maxLen) + " status for "
63 + getRelativePath(baseDir, file.getPath()));
64 }
65 } catch (IOException | ScmException e) {
66 throw new MojoExecutionException("Cannot run status command : ", e);
67 }
68 }
69
70
71
72
73
74
75
76
77 protected String getRelativePath(File baseDir, String path) {
78 if (path.equals(baseDir.getAbsolutePath())) {
79 return ".";
80 } else if (path.indexOf(baseDir.getAbsolutePath()) == 0) {
81
82 return path.substring(baseDir.getAbsolutePath().length() + 1);
83 } else {
84 return path;
85 }
86 }
87 }