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