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