1 | |
package org.apache.maven.plugin.reactor; |
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.util.ArrayList; |
24 | |
import java.util.HashSet; |
25 | |
import java.util.List; |
26 | |
import java.util.Set; |
27 | |
|
28 | |
import org.apache.maven.plugin.MojoExecutionException; |
29 | |
import org.apache.maven.plugin.MojoFailureException; |
30 | |
import org.apache.maven.project.MavenProject; |
31 | |
import org.apache.maven.scm.ScmFile; |
32 | |
import org.apache.maven.scm.ScmFileSet; |
33 | |
import org.apache.maven.scm.ScmFileStatus; |
34 | |
import org.apache.maven.scm.command.status.StatusScmResult; |
35 | |
import org.apache.maven.scm.manager.ScmManager; |
36 | |
import org.apache.maven.scm.repository.ScmRepository; |
37 | |
import org.codehaus.plexus.util.StringUtils; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 1 | public class MakeScmChanges |
48 | |
extends MakeDependentsMojo |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
String scmConnection; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | 1 | private boolean ignoreUnknown = true; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
ScmManager scmManager; |
68 | |
|
69 | |
public void execute() |
70 | |
throws MojoExecutionException, MojoFailureException |
71 | |
{ |
72 | 1 | if ( collectedProjects.size() == 0 ) |
73 | |
{ |
74 | 0 | throw new NonReactorException(); |
75 | |
} |
76 | 1 | if ( scmConnection == null ) |
77 | |
{ |
78 | 0 | throw new MojoFailureException("No SCM connection specified. You must specify an SCM connection by adding a <connection> element to your <scm> element in your POM"); |
79 | |
} |
80 | 1 | StatusScmResult result = null; |
81 | |
try |
82 | |
{ |
83 | 1 | ScmRepository repository = scmManager.makeScmRepository( scmConnection ); |
84 | 1 | result = scmManager.status( repository, new ScmFileSet( baseDir ) ); |
85 | |
} |
86 | 0 | catch ( Exception e ) |
87 | |
{ |
88 | 0 | throw new MojoExecutionException( "Couldn't configure SCM repository: " + e.getLocalizedMessage(), e ); |
89 | 1 | } |
90 | |
|
91 | 1 | List changedFiles = result.getChangedFiles(); |
92 | |
|
93 | 1 | List projectDirectories = getProjectDirectories(); |
94 | 1 | Set changedDirectories = new HashSet(); |
95 | 2 | for ( int i = 0; i < changedFiles.size(); i++ ) |
96 | |
{ |
97 | 1 | ScmFile changedScmFile = (ScmFile) changedFiles.get( i ); |
98 | 1 | getLog().debug( changedScmFile.toString() ); |
99 | 1 | ScmFileStatus status = changedScmFile.getStatus(); |
100 | 1 | if ( !status.isStatus() ) |
101 | |
{ |
102 | 0 | getLog().debug( "Not a diff: " + status ); |
103 | 0 | continue; |
104 | |
} |
105 | 1 | if ( ignoreUnknown && ScmFileStatus.UNKNOWN.equals( status ) ) |
106 | |
{ |
107 | 0 | getLog().debug( "Ignoring unknown" ); |
108 | 0 | continue; |
109 | |
} |
110 | |
|
111 | 1 | File changedFile = new File( changedScmFile.getPath() ); |
112 | 1 | boolean found = false; |
113 | |
|
114 | 2 | for ( int j = 0; j < projectDirectories.size(); j++ ) |
115 | |
{ |
116 | 2 | File projectDirectory = (File) projectDirectories.get( j ); |
117 | 2 | if ( changedFile.getAbsolutePath().startsWith( projectDirectory.getAbsolutePath() + File.separator ) ) |
118 | |
{ |
119 | 1 | String path = RelativePather.getRelativePath( baseDir, projectDirectory ); |
120 | 1 | if ( !changedDirectories.contains( path ) ) |
121 | |
{ |
122 | 1 | getLog().debug( "Including " + path ); |
123 | |
} |
124 | 1 | changedDirectories.add( path ); |
125 | 1 | found = true; |
126 | 1 | break; |
127 | |
} |
128 | |
} |
129 | 1 | if ( !found ) |
130 | |
{ |
131 | 0 | getLog().debug( "Couldn't find file in any reactor root: " + changedFile.getAbsolutePath() ); |
132 | |
} |
133 | |
} |
134 | 1 | folderList = StringUtils.join( changedDirectories.iterator(), "," ); |
135 | 1 | getLog().info( "Going to make dependents for: " + folderList ); |
136 | 1 | super.execute(); |
137 | |
|
138 | 1 | } |
139 | |
|
140 | |
private List getProjectDirectories() |
141 | |
{ |
142 | 1 | List dirs = new ArrayList( collectedProjects.size() ); |
143 | 4 | for ( int i = 0; i < collectedProjects.size(); i++ ) |
144 | |
{ |
145 | 3 | MavenProject mp = (MavenProject) collectedProjects.get( i ); |
146 | 3 | dirs.add( mp.getFile().getParentFile() ); |
147 | |
} |
148 | 1 | return dirs; |
149 | |
} |
150 | |
|
151 | |
} |