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 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.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 import org.codehaus.plexus.util.StringUtils;
32
33
34
35
36
37
38
39 @Mojo( name = "status", aggregator = true )
40 public class StatusMojo
41 extends AbstractScmMojo
42 {
43
44 public void execute()
45 throws MojoExecutionException
46 {
47 super.execute();
48
49 try
50 {
51 ScmRepository repository = getScmRepository();
52
53 StatusScmResult result = getScmManager().status( repository, getFileSet() );
54
55 checkResult( result );
56
57 File baseDir = getFileSet().getBasedir();
58
59
60 int maxLen = 0;
61
62 for ( ScmFile file : result.getChangedFiles() )
63 {
64 maxLen = Math.max( maxLen, file.getStatus().toString().length() );
65 }
66
67 for ( ScmFile file : result.getChangedFiles() )
68 {
69
70 getLog().info(
71 StringUtils.leftPad( file.getStatus().toString(), maxLen ) + " status for "
72 + getRelativePath( baseDir, file.getPath() ) );
73 }
74 }
75 catch ( IOException e )
76 {
77 throw new MojoExecutionException( "Cannot run status command : ", e );
78 }
79 catch ( ScmException e )
80 {
81 throw new MojoExecutionException( "Cannot run status command : ", e );
82 }
83 }
84
85
86
87
88
89
90
91
92 protected String getRelativePath( File baseDir, String path )
93 {
94 if ( path.equals( baseDir.getAbsolutePath() ) )
95 {
96 return ".";
97 }
98 else if ( path.indexOf( baseDir.getAbsolutePath() ) == 0 )
99 {
100
101 return path.substring( baseDir.getAbsolutePath().length() + 1 );
102 }
103 else
104 {
105 return path;
106 }
107 }
108 }