29 | 29 |
import java.io.PrintWriter;
|
30 | 30 |
import java.util.ArrayList;
|
31 | 31 |
import java.util.Collection;
|
|
32 |
import java.util.HashMap;
|
|
33 |
import java.util.HashSet;
|
32 | 34 |
import java.util.Iterator;
|
33 | 35 |
import java.util.List;
|
34 | 36 |
import java.util.Properties;
|
|
52 | 54 |
*/
|
53 | 55 |
public class DependenciesSolver {
|
54 | 56 |
|
|
57 |
// Plugins not useful for the build or whose use is against the
|
|
58 |
// Debian policy
|
|
59 |
private static final String[][] PLUGINS_TO_IGNORE = {
|
|
60 |
{"org.apache.maven.plugins", "maven-ant-plugin"},
|
|
61 |
{"org.apache.maven.plugins", "maven-archetype-plugin"},
|
|
62 |
{"org.apache.maven.plugins", "maven-deploy-plugin"},
|
|
63 |
{"org.apache.maven.plugins", "maven-release-plugin"},
|
|
64 |
{"org.apache.maven.plugins", "maven-remote-resources-plugin"},
|
|
65 |
{"org.apache.maven.plugins", "maven-repository-plugin"},
|
|
66 |
{"org.apache.maven.plugins", "maven-scm-plugin"},
|
|
67 |
{"org.apache.maven.plugins", "maven-stage-plugin"},
|
|
68 |
{"org.apache.maven.plugins", "maven-eclipse-plugin"},
|
|
69 |
{"org.apache.maven.plugins", "maven-idea-plugin"},
|
|
70 |
{"org.codehaus.mojo", "netbeans-freeform-maven-plugin"},
|
|
71 |
{"org.codehaus.mojo", "nbm-maven-plugin"},
|
|
72 |
{"org.codehaus.mojo", "ideauidesigner-maven-plugin"},
|
|
73 |
{"org.codehaus.mojo", "scmchangelog-maven-plugin"},};
|
|
74 |
private static final String[][] PLUGINS_THAT_CAN_BE_IGNORED = {
|
|
75 |
{"org.apache.maven.plugins", "maven-assembly-plugin"},
|
|
76 |
{"org.codehaus.mojo", "buildnumber-maven-plugin"},
|
|
77 |
{"org.apache.maven.plugins", "maven-verifier-plugin"},
|
|
78 |
{"org.codehaus.mojo", "findbugs-maven-plugin"},
|
|
79 |
{"org.codehaus.mojo", "fitnesse-maven-plugin"},
|
|
80 |
{"org.codehaus.mojo", "selenium-maven-plugin"},
|
|
81 |
{"org.codehaus.mojo", "dbunit-maven-plugin"},
|
|
82 |
{"org.codehaus.mojo", "failsafe-maven-plugin"},
|
|
83 |
{"org.codehaus.mojo", "shitty-maven-plugin"},};
|
|
84 |
private static final String[][] DOC_PLUGINS = {
|
|
85 |
{"org.apache.maven.plugins", "maven-changelog-plugin"},
|
|
86 |
{"org.apache.maven.plugins", "maven-changes-plugin"},
|
|
87 |
{"org.apache.maven.plugins", "maven-checkstyle-plugin"},
|
|
88 |
{"org.apache.maven.plugins", "maven-docck-plugin"},
|
|
89 |
{"org.apache.maven.plugins", "maven-javadoc-plugin"},
|
|
90 |
{"org.apache.maven.plugins", "maven-jxr-plugin"},
|
|
91 |
{"org.apache.maven.plugins", "maven-pmd-plugin"},
|
|
92 |
{"org.apache.maven.plugins", "maven-project-info-reports-plugin"},
|
|
93 |
{"org.apache.maven.plugins", "maven-surefire-report-plugin"},
|
|
94 |
{"org.apache.maven.plugins", "maven-pdf-plugin"},
|
|
95 |
{"org.apache.maven.plugins", "maven-site-plugin"},
|
|
96 |
{"org.codehaus.mojo", "clirr-maven-plugin"},
|
|
97 |
{"org.codehaus.mojo", "cobertura-maven-plugin"},
|
|
98 |
{"org.codehaus.mojo", "taglist-maven-plugin"},
|
|
99 |
{"org.codehaus.mojo", "dita-maven-plugin"},
|
|
100 |
{"org.codehaus.mojo", "docbook-maven-plugin"},
|
|
101 |
{"org.codehaus.mojo", "javancss-maven-plugin"},
|
|
102 |
{"org.codehaus.mojo", "jdepend-maven-plugin"},
|
|
103 |
{"org.codehaus.mojo", "dashboard-maven-plugin"},
|
|
104 |
{"org.codehaus.mojo", "emma-maven-plugin"},
|
|
105 |
{"org.codehaus.mojo", "sonar-maven-plugin"},};
|
|
106 |
private static final String[][] TEST_PLUGINS = {
|
|
107 |
{"org.apache.maven.plugins", "maven-failsafe-plugin"},
|
|
108 |
{"org.apache.maven.plugins", "maven-surefire-plugin"},
|
|
109 |
{"org.apache.maven.plugins", "maven-verifier-plugin"},
|
|
110 |
{"org.codehaus.mojo", "findbugs-maven-plugin"},
|
|
111 |
{"org.codehaus.mojo", "fitnesse-maven-plugin"},
|
|
112 |
{"org.codehaus.mojo", "selenium-maven-plugin"},
|
|
113 |
{"org.codehaus.mojo", "dbunit-maven-plugin"},
|
|
114 |
{"org.codehaus.mojo", "failsafe-maven-plugin"},
|
|
115 |
{"org.codehaus.mojo", "shitty-maven-plugin"},};
|
|
116 |
private static final String[][] EXTENSIONS_TO_IGNORE = {
|
|
117 |
{"org.apache.maven.wagon", "wagon-ssh"},
|
|
118 |
{"org.apache.maven.wagon", "wagon-ssh-external"},
|
|
119 |
{"org.apache.maven.wagon", "wagon-ftp"},
|
|
120 |
{"org.apache.maven.wagon", "wagon-http"},
|
|
121 |
{"org.apache.maven.wagon", "wagon-http-lightweight"},
|
|
122 |
{"org.apache.maven.wagon", "wagon-scm"},};
|
|
123 |
|
55 | 124 |
protected File baseDir;
|
|
125 |
protected File listOfPoms;
|
56 | 126 |
protected File outputDirectory;
|
57 | 127 |
protected String packageName;
|
58 | 128 |
protected String packageType;
|
59 | 129 |
protected File mavenRepo = new File("/usr/share/maven-repo");
|
60 | 130 |
protected boolean exploreProjects;
|
61 | 131 |
protected List projects = new ArrayList();
|
62 | |
|
63 | 132 |
private Repository repository;
|
64 | 133 |
private List issues = new ArrayList();
|
65 | 134 |
private List pomsConfig = new ArrayList();
|
|
135 |
private List projectPoms = new ArrayList();
|
|
136 |
private List toResolve = new ArrayList();
|
66 | 137 |
private Set compileDepends = new TreeSet();
|
67 | 138 |
private Set testDepends = new TreeSet();
|
68 | 139 |
private Set runtimeDepends = new TreeSet();
|
69 | 140 |
private Set optionalDepends = new TreeSet();
|
70 | 141 |
private Set rules = new TreeSet();
|
|
142 |
private Set ignoreRules = new TreeSet();
|
|
143 |
private Set cleanIgnoreRules = new TreeSet();
|
|
144 |
private Set ignoredDependencies = new HashSet();
|
71 | 145 |
private boolean checkedAptFile;
|
|
146 |
private boolean runTests;
|
|
147 |
private boolean generateJavadoc;
|
|
148 |
private boolean nonInteractive;
|
|
149 |
private boolean askedToFilterModules = false;
|
|
150 |
private boolean filterModules = false;
|
|
151 |
|
|
152 |
public void setRunTests(boolean b) {
|
|
153 |
this.runTests = b;
|
|
154 |
}
|
|
155 |
|
|
156 |
private void setGenerateJavadoc(boolean b) {
|
|
157 |
this.generateJavadoc = b;
|
|
158 |
}
|
|
159 |
|
|
160 |
private boolean containsPlugin(String[][] pluginDefinitions, Dependency plugin) {
|
|
161 |
for (int i = 0; i < pluginDefinitions.length; i++) {
|
|
162 |
if (!plugin.getGroupId().equals(pluginDefinitions[i][0])) {
|
|
163 |
continue;
|
|
164 |
}
|
|
165 |
if (plugin.getArtifactId().equals(pluginDefinitions[i][1])) {
|
|
166 |
return true;
|
|
167 |
}
|
|
168 |
}
|
|
169 |
return false;
|
|
170 |
}
|
|
171 |
|
|
172 |
private boolean isJavadocPlugin(Dependency dependency) {
|
|
173 |
return containsPlugin(DOC_PLUGINS, dependency);
|
|
174 |
}
|
|
175 |
|
|
176 |
private boolean isTestPlugin(Dependency dependency) {
|
|
177 |
return containsPlugin(TEST_PLUGINS, dependency);
|
|
178 |
}
|
|
179 |
|
|
180 |
private boolean isDefaultMavenPlugin(Dependency dependency) {
|
|
181 |
if (repository != null && repository.getSuperPOM() != null) {
|
|
182 |
for (Iterator i = repository.getSuperPOM().getPluginManagement().iterator(); i.hasNext();) {
|
|
183 |
Dependency defaultPlugin = (Dependency) i.next();
|
|
184 |
if (defaultPlugin.equalsIgnoreVersion(dependency)) {
|
|
185 |
return true;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
}
|
|
189 |
return false;
|
|
190 |
}
|
|
191 |
|
|
192 |
private boolean canIgnorePlugin(Dependency dependency) {
|
|
193 |
return containsPlugin(PLUGINS_TO_IGNORE, dependency);
|
|
194 |
}
|
|
195 |
|
|
196 |
private boolean canIgnoreExtension(Dependency dependency) {
|
|
197 |
return containsPlugin(EXTENSIONS_TO_IGNORE, dependency);
|
|
198 |
}
|
|
199 |
|
|
200 |
private boolean canBeIgnoredPlugin(Dependency dependency) {
|
|
201 |
return containsPlugin(PLUGINS_THAT_CAN_BE_IGNORED, dependency);
|
|
202 |
}
|
|
203 |
|
|
204 |
private boolean askIgnoreDependency(Dependency dependency, String message) {
|
|
205 |
if (nonInteractive) {
|
|
206 |
return false;
|
|
207 |
}
|
|
208 |
System.out.println(message);
|
|
209 |
System.out.println(" " + dependency);
|
|
210 |
System.out.print("[y]/n > ");
|
|
211 |
String s = System.console().readLine().trim().toLowerCase();
|
|
212 |
if (s.startsWith("n")) {
|
|
213 |
return false;
|
|
214 |
}
|
|
215 |
return true;
|
|
216 |
}
|
|
217 |
|
|
218 |
public void setNonInteractive(boolean nonInteractive) {
|
|
219 |
this.nonInteractive = nonInteractive;
|
|
220 |
}
|
|
221 |
|
|
222 |
private class ToResolve {
|
|
223 |
|
|
224 |
private final File sourcePom;
|
|
225 |
private final Collection poms;
|
|
226 |
private final boolean buildTime;
|
|
227 |
private final boolean mavenExtension;
|
|
228 |
private final boolean management;
|
|
229 |
|
|
230 |
private ToResolve(File sourcePom, Collection poms, boolean buildTime, boolean mavenExtension, boolean management) {
|
|
231 |
this.sourcePom = sourcePom;
|
|
232 |
this.poms = poms;
|
|
233 |
this.buildTime = buildTime;
|
|
234 |
this.mavenExtension = mavenExtension;
|
|
235 |
this.management = management;
|
|
236 |
}
|
|
237 |
|
|
238 |
public void resolve() {
|
|
239 |
resolveDependencies(sourcePom, poms, buildTime, mavenExtension, management);
|
|
240 |
}
|
|
241 |
}
|
72 | 242 |
|
73 | 243 |
public File getBaseDir() {
|
74 | 244 |
return baseDir;
|
75 | 245 |
}
|
76 | 246 |
|
|
247 |
public File getListOfPoms() {
|
|
248 |
return listOfPoms;
|
|
249 |
}
|
|
250 |
|
|
251 |
public void setListOfPoms(File listOfPoms) {
|
|
252 |
this.listOfPoms = listOfPoms;
|
|
253 |
}
|
|
254 |
|
77 | 255 |
public void saveListOfPoms() {
|
78 | |
File listPoms = new File(outputDirectory, packageName + ".poms");
|
79 | |
if (!listPoms.exists()) {
|
|
256 |
if (listOfPoms != null && !listOfPoms.exists()) {
|
80 | 257 |
try {
|
81 | |
PrintWriter out = new PrintWriter(new FileWriter(listPoms));
|
|
258 |
PrintWriter out = new PrintWriter(new FileWriter(listOfPoms));
|
82 | 259 |
for (Iterator i = pomsConfig.iterator(); i.hasNext();) {
|
83 | 260 |
String config = (String) i.next();
|
84 | 261 |
out.println(config);
|
85 | 262 |
}
|
|
263 |
out.flush();
|
86 | 264 |
out.close();
|
87 | 265 |
} catch (Exception ex) {
|
88 | 266 |
Logger.getLogger(DependenciesSolver.class.getName()).log(Level.SEVERE, null, ex);
|
|
95 | 273 |
if (!mavenRules.exists()) {
|
96 | 274 |
try {
|
97 | 275 |
PrintWriter out = new PrintWriter(new FileWriter(mavenRules));
|
|
276 |
out.println("# Maven rules - transform Maven dependencies and plugins");
|
|
277 |
out.println("# Format of this file is:");
|
|
278 |
out.println("# [group] [artifact] [type] [version]");
|
|
279 |
out.println("# where each element can be either");
|
|
280 |
out.println("# - the exact string, for example org.apache for the group, or 3.1");
|
|
281 |
out.println("# for the version. In this case, the element is simply matched");
|
|
282 |
out.println("# and left as it is");
|
|
283 |
out.println("# - * (the star character, alone). In this case, anything will");
|
|
284 |
out.println("# match and be left as it is. For example, using * on the");
|
|
285 |
out.println("# position of the artifact field will match any artifact id");
|
|
286 |
out.println("# - a regular expression of the form s/match/replace/");
|
|
287 |
out.println("# in this case, elements that match are transformed using");
|
|
288 |
out.println("# the regex rule.");
|
|
289 |
out.println("# All elements much match before a rule can be applied");
|
|
290 |
out.println("# Example rule: match jar with groupid= junit, artifactid= junit");
|
|
291 |
out.println("# and version starting with 3., replacing the version with 3.x");
|
|
292 |
out.println("# junit junit jar s/3\\..*/3.x/");
|
|
293 |
|
98 | 294 |
for (Iterator i = rules.iterator(); i.hasNext();) {
|
99 | 295 |
String rule = (String) i.next();
|
100 | 296 |
out.println(rule);
|
101 | 297 |
}
|
|
298 |
out.flush();
|
|
299 |
out.close();
|
|
300 |
} catch (IOException ex) {
|
|
301 |
Logger.getLogger(DependenciesSolver.class.getName()).log(Level.SEVERE, null, ex);
|
|
302 |
}
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
public void saveMavenPublishedRules() {
|
|
307 |
File mavenRules = new File(outputDirectory, "maven.publishedRules");
|
|
308 |
if (!mavenRules.exists()) {
|
|
309 |
try {
|
|
310 |
PrintWriter out = new PrintWriter(new FileWriter(mavenRules));
|
|
311 |
out.println("# Maven published rules - additional rules to publish, to help");
|
|
312 |
out.println("# the packaging work of Debian maintainers using mh_make");
|
|
313 |
out.println("# Format of this file is:");
|
|
314 |
out.println("# [group] [artifact] [type] [version]");
|
|
315 |
out.println("# where each element can be either");
|
|
316 |
out.println("# - the exact string, for example org.apache for the group, or 3.1");
|
|
317 |
out.println("# for the version. In this case, the element is simply matched");
|
|
318 |
out.println("# and left as it is");
|
|
319 |
out.println("# - * (the star character, alone). In this case, anything will");
|
|
320 |
out.println("# match and be left as it is. For example, using * on the");
|
|
321 |
out.println("# position of the artifact field will match any artifact id");
|
|
322 |
out.println("# - a regular expression of the form s/match/replace/");
|
|
323 |
out.println("# in this case, elements that match are transformed using");
|
|
324 |
out.println("# the regex rule.");
|
|
325 |
out.println("# All elements much match before a rule can be applied");
|
|
326 |
out.println("# Example rule: match any dependency whose group is ant,");
|
|
327 |
out.println("# replacing it with org.apache.ant");
|
|
328 |
out.println("# s/ant/org.apache.ant/ * * s/.*/debian/");
|
|
329 |
|
|
330 |
out.flush();
|
|
331 |
out.close();
|
|
332 |
} catch (IOException ex) {
|
|
333 |
Logger.getLogger(DependenciesSolver.class.getName()).log(Level.SEVERE, null, ex);
|
|
334 |
}
|
|
335 |
}
|
|
336 |
}
|
|
337 |
|
|
338 |
public void saveMavenIgnoreRules() {
|
|
339 |
File mavenRules = new File(outputDirectory, "maven.ignoreRules");
|
|
340 |
if (!mavenRules.exists()) {
|
|
341 |
try {
|
|
342 |
PrintWriter out = new PrintWriter(new FileWriter(mavenRules));
|
|
343 |
out.println("# Maven ignore rules - ignore some Maven dependencies and plugins");
|
|
344 |
out.println("# Format of this file is:");
|
|
345 |
out.println("# [group] [artifact] [type] [version]");
|
|
346 |
out.println("# where each element can be either");
|
|
347 |
out.println("# - the exact string, for example org.apache for the group, or 3.1");
|
|
348 |
out.println("# for the version. In this case, the element is simply matched");
|
|
349 |
out.println("# and left as it is");
|
|
350 |
out.println("# - * (the star character, alone). In this case, anything will");
|
|
351 |
out.println("# match and be left as it is. For example, using * on the");
|
|
352 |
out.println("# position of the artifact field will match any artifact id");
|
|
353 |
out.println("# All elements much match before a rule can be applied");
|
|
354 |
out.println("# Example rule: match jar with groupid= junit, artifactid= junit");
|
|
355 |
out.println("# and version starting with 3., this dependency is then removed");
|
|
356 |
out.println("# from the POM");
|
|
357 |
out.println("# junit junit jar s/3\\..*/3.x/");
|
|
358 |
|
|
359 |
for (Iterator i = ignoreRules.iterator(); i.hasNext();) {
|
|
360 |
String rule = (String) i.next();
|
|
361 |
out.println(rule);
|
|
362 |
}
|
|
363 |
|
|
364 |
out.flush();
|
|
365 |
out.close();
|
|
366 |
} catch (IOException ex) {
|
|
367 |
Logger.getLogger(DependenciesSolver.class.getName()).log(Level.SEVERE, null, ex);
|
|
368 |
}
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
public void saveMavenCleanIgnoreRules() {
|
|
373 |
File mavenRules = new File(outputDirectory, "maven.cleanIgnoreRules");
|
|
374 |
if (!mavenRules.exists()) {
|
|
375 |
try {
|
|
376 |
PrintWriter out = new PrintWriter(new FileWriter(mavenRules));
|
|
377 |
out.println("# Maven clean ignore rules - ignore some Maven dependencies and plugins during the clean phase");
|
|
378 |
out.println("# Format of this file is:");
|
|
379 |
out.println("# [group] [artifact] [type] [version]");
|
|
380 |
out.println("# where each element can be either");
|
|
381 |
out.println("# - the exact string, for example org.apache for the group, or 3.1");
|
|
382 |
out.println("# for the version. In this case, the element is simply matched");
|
|
383 |
out.println("# and left as it is");
|
|
384 |
out.println("# - * (the star character, alone). In this case, anything will");
|
|
385 |
out.println("# match and be left as it is. For example, using * on the");
|
|
386 |
out.println("# position of the artifact field will match any artifact id");
|
|
387 |
out.println("# All elements much match before a rule can be applied");
|
|
388 |
out.println("# Example rule: match jar with groupid= junit, artifactid= junit");
|
|
389 |
out.println("# and version starting with 3., this dependency is then removed");
|
|
390 |
out.println("# from the POM");
|
|
391 |
out.println("# junit junit jar s/3\\..*/3.x/");
|
|
392 |
|
|
393 |
for (Iterator i = cleanIgnoreRules.iterator(); i.hasNext();) {
|
|
394 |
String rule = (String) i.next();
|
|
395 |
out.println(rule);
|
|
396 |
}
|
|
397 |
|
|
398 |
out.flush();
|
102 | 399 |
out.close();
|
103 | 400 |
} catch (IOException ex) {
|
104 | 401 |
Logger.getLogger(DependenciesSolver.class.getName()).log(Level.SEVERE, null, ex);
|
|
121 | 418 |
depVars.put("maven.Depends", toString(runtimeDepends));
|
122 | 419 |
depVars.put("maven.OptionalDepends", toString(optionalDepends));
|
123 | 420 |
Set docRuntimeDepends = new TreeSet();
|
124 | |
docRuntimeDepends.add("openjdk-6-doc | classpath-doc");
|
|
421 |
docRuntimeDepends.add("default-jdk-doc");
|
125 | 422 |
for (Iterator i = runtimeDepends.iterator(); i.hasNext();) {
|
126 | 423 |
docRuntimeDepends.add(i.next() + "-doc");
|
127 | 424 |
}
|
|
224 | 521 |
}
|
225 | 522 |
}
|
226 | 523 |
|
227 | |
for (Iterator i = issues.iterator(); i.hasNext();) {
|
228 | |
String issue = (String) i.next();
|
229 | |
System.err.println(issue);
|
|
524 |
resolveDependenciesNow();
|
|
525 |
|
|
526 |
if (!issues.isEmpty()) {
|
|
527 |
System.err.println("WARNING:");
|
|
528 |
for (Iterator i = issues.iterator(); i.hasNext();) {
|
|
529 |
String issue = (String) i.next();
|
|
530 |
System.err.println(issue);
|
|
531 |
}
|
|
532 |
System.err.println("--------");
|
230 | 533 |
}
|
231 | 534 |
}
|
232 | 535 |
|
|
235 | 538 |
String pomRelPath = projectPom.getAbsolutePath().substring(baseDir.getAbsolutePath().length() + 1);
|
236 | 539 |
try {
|
237 | 540 |
POMInfo pom = reader.readPom(projectPom);
|
|
541 |
pom.setProperties(new HashMap());
|
|
542 |
pom.getProperties().put("debian.package", getPackageName());
|
|
543 |
// System.out.println("Register POM " + pom.getThisPom().getGroupId() + ":" + pom.getThisPom().getArtifactId()
|
|
544 |
// + ":" + pom.getThisPom().getVersion());
|
238 | 545 |
repository.registerPom(projectPom, pom);
|
|
546 |
|
|
547 |
if (filterModules) {
|
|
548 |
System.out.println("Include the module " + pomRelPath + " ?");
|
|
549 |
System.out.print("[y]/n > ");
|
|
550 |
String s = System.console().readLine().trim().toLowerCase();
|
|
551 |
boolean includeModule = !s.startsWith("n");
|
|
552 |
if (!includeModule) {
|
|
553 |
pomsConfig.add(pomRelPath + " --ignore");
|
|
554 |
String type = "*";
|
|
555 |
if (pom.getThisPom().getType() != null) {
|
|
556 |
type = pom.getThisPom().getType();
|
|
557 |
}
|
|
558 |
ignoreRules.add(pom.getThisPom().getGroupId() + " " + pom.getThisPom().getArtifactId()
|
|
559 |
+ " " + type + " *");
|
|
560 |
return;
|
|
561 |
}
|
|
562 |
}
|
239 | 563 |
|
240 | 564 |
boolean noParent = false;
|
241 | 565 |
if (pom.getParent() != null) {
|
242 | 566 |
POMInfo parentPom = repository.searchMatchingPOM(pom.getParent());
|
243 | |
if (parentPom == null) {
|
|
567 |
if (parentPom == null || parentPom.equals(repository.getSuperPOM())) {
|
244 | 568 |
noParent = true;
|
245 | 569 |
}
|
246 | 570 |
if (!baseDir.equals(projectPom.getParentFile())) {
|
247 | |
System.out.println("Check the parent dependency in the sub project " + projectPom);
|
|
571 |
// System.out.println("Checking the parent dependency in the sub project " + projectPom);
|
248 | 572 |
Set parentDependencies = new TreeSet();
|
249 | 573 |
parentDependencies.add(pom.getParent());
|
250 | |
resolveDependencies(parentDependencies, false, false);
|
251 | |
}
|
252 | |
}
|
253 | |
|
|
574 |
resolveDependenciesLater(projectPom, parentDependencies, false, false, false);
|
|
575 |
}
|
|
576 |
}
|
|
577 |
|
|
578 |
projectPoms.add(pom.getThisPom());
|
254 | 579 |
if (noParent) {
|
255 | 580 |
pomsConfig.add(pomRelPath + " --no-parent");
|
256 | 581 |
} else {
|
257 | 582 |
pomsConfig.add(pomRelPath);
|
258 | 583 |
}
|
259 | 584 |
|
260 | |
resolveDependencies(pom.getDependencies(), false, false);
|
261 | |
resolveDependencies(pom.getPlugins(), true, true);
|
262 | |
resolveDependencies(pom.getPluginDependencies(), true, true);
|
263 | |
resolveDependencies(pom.getExtensions(), true, true);
|
264 | |
|
265 | |
if (exploreProjects) {
|
|
585 |
resolveDependenciesLater(projectPom, pom.getDependencies(), false, false, false);
|
|
586 |
resolveDependenciesLater(projectPom, pom.getDependencyManagement(), false, false, true);
|
|
587 |
resolveDependenciesLater(projectPom, pom.getPlugins(), true, true, false);
|
|
588 |
resolveDependenciesLater(projectPom, pom.getPluginDependencies(), true, true, false);
|
|
589 |
resolveDependenciesLater(projectPom, pom.getPluginManagement(), true, true, true);
|
|
590 |
resolveDependenciesLater(projectPom, pom.getExtensions(), true, true, false);
|
|
591 |
|
|
592 |
if (exploreProjects && !pom.getModules().isEmpty()) {
|
|
593 |
if (!nonInteractive && !askedToFilterModules) {
|
|
594 |
System.out.println("This project contains modules. Include all modules?");
|
|
595 |
System.out.print("[y]/n > ");
|
|
596 |
String s = System.console().readLine().trim().toLowerCase();
|
|
597 |
filterModules = s.startsWith("n");
|
|
598 |
}
|
266 | 599 |
for (Iterator i = pom.getModules().iterator(); i.hasNext();) {
|
267 | 600 |
String module = (String) i.next();
|
268 | 601 |
File modulePom = new File(projectPom.getParent(), module + "/pom.xml");
|
|
276 | 609 |
}
|
277 | 610 |
}
|
278 | 611 |
|
279 | |
private void resolveDependencies(Collection poms, boolean buildTime, boolean mavenExtension) {
|
|
612 |
private void resolveDependenciesNow() {
|
|
613 |
for (Iterator i = toResolve.iterator(); i.hasNext();) {
|
|
614 |
ToResolve tr = (ToResolve) i.next();
|
|
615 |
tr.resolve();
|
|
616 |
i.remove();
|
|
617 |
}
|
|
618 |
}
|
|
619 |
|
|
620 |
private void resolveDependenciesLater(File sourcePom, Collection poms, boolean buildTime, boolean mavenExtension, boolean management) {
|
|
621 |
toResolve.add(new ToResolve(sourcePom, poms, buildTime, mavenExtension, management));
|
|
622 |
}
|
|
623 |
|
|
624 |
private void resolveDependencies(File sourcePom, Collection poms, boolean buildTime, boolean mavenExtension, boolean management) {
|
|
625 |
String sourcePomLoc = sourcePom.getAbsolutePath();
|
|
626 |
String baseDirPath = baseDir.getAbsolutePath();
|
|
627 |
sourcePomLoc = sourcePomLoc.substring(baseDirPath.length() + 1, sourcePomLoc.length());
|
|
628 |
|
|
629 |
nextDependency:
|
280 | 630 |
for (Iterator i = poms.iterator(); i.hasNext();) {
|
281 | 631 |
Dependency dependency = (Dependency) i.next();
|
|
632 |
if (containsDependencyIgnoreVersion(ignoredDependencies, dependency) ||
|
|
633 |
(management && isDefaultMavenPlugin(dependency))) {
|
|
634 |
continue;
|
|
635 |
}
|
|
636 |
|
|
637 |
boolean ignoreDependency = false;
|
|
638 |
if (canIgnorePlugin(dependency)) {
|
|
639 |
ignoreDependency = askIgnoreDependency(dependency, "This plugin is not useful for the build or its use is against Debian policies. Ignore this plugin?");
|
|
640 |
} else if (canIgnoreExtension(dependency)) {
|
|
641 |
ignoreDependency = askIgnoreDependency(dependency, "This extension is not useful for the build or its use is against Debian policies. Ignore this extension?");
|
|
642 |
} else if (canBeIgnoredPlugin(dependency)) {
|
|
643 |
ignoreDependency = askIgnoreDependency(dependency, "This plugin may be ignored in some cases. Ignore this plugin?");
|
|
644 |
} else if (!runTests) {
|
|
645 |
if ("test".equals(dependency.getScope())) {
|
|
646 |
ignoreDependency = askIgnoreDependency(dependency, "Tests are turned off. Ignore this test dependency?");
|
|
647 |
} else if (isTestPlugin(dependency)) {
|
|
648 |
ignoreDependency = askIgnoreDependency(dependency, "Tests are turned off. Ignore this test plugin?");
|
|
649 |
}
|
|
650 |
} else if (!generateJavadoc && isJavadocPlugin(dependency)) {
|
|
651 |
ignoreDependency = askIgnoreDependency(dependency, "Documentation is turned off. Ignore this documentation plugin?");
|
|
652 |
}
|
|
653 |
|
|
654 |
if (ignoreDependency) {
|
|
655 |
ignoredDependencies.add(dependency);
|
|
656 |
ignoreRules.add(dependency.getGroupId() + " " + dependency.getArtifactId() + " maven-plugin *");
|
|
657 |
continue;
|
|
658 |
}
|
|
659 |
|
282 | 660 |
POMInfo pom = repository.searchMatchingPOM(dependency);
|
283 | 661 |
if (pom == null && "maven-plugin".equals(dependency.getType())) {
|
284 | 662 |
List matchingPoms = repository.searchMatchingPOMsIgnoreVersion(dependency);
|
285 | 663 |
if (matchingPoms.size() > 1) {
|
286 | |
issues.add("More than one version matches the plugin " + dependency.getGroupId() + ":" +
|
287 | |
dependency.getArtifactId() + ":" + dependency.getVersion());
|
|
664 |
issues.add(sourcePomLoc + ": More than one version matches the plugin " + dependency.getGroupId() + ":"
|
|
665 |
+ dependency.getArtifactId() + ":" + dependency.getVersion());
|
288 | 666 |
}
|
289 | 667 |
if (!matchingPoms.isEmpty()) {
|
290 | 668 |
pom = (POMInfo) matchingPoms.get(0);
|
291 | |
// Adapt the version of the plugin to what is in the repository
|
292 | |
rules.add(dependency.getGroupId() + " " +
|
293 | |
dependency.getArtifactId() + " maven-plugin s/.*/" + pom.getOriginalVersion() + "/");
|
|
669 |
// Don't add a rule to force the version of a Maven plugin, it's now done
|
|
670 |
// automatically at build time
|
294 | 671 |
}
|
295 | 672 |
}
|
296 | 673 |
if (pom == null) {
|
297 | |
issues.add("Dependency is not packaged in the Maven repository for Debian: " + dependency.getGroupId() + ":" +
|
298 | |
dependency.getArtifactId() + ":" + dependency.getVersion());
|
|
674 |
if (!management) {
|
|
675 |
issues.add(sourcePomLoc + ": Dependency is not packaged in the Maven repository for Debian: " + dependency.getGroupId() + ":"
|
|
676 |
+ dependency.getArtifactId() + ":" + dependency.getVersion());
|
|
677 |
}
|
299 | 678 |
return;
|
300 | 679 |
}
|
|
680 |
|
|
681 |
// Handle the case of Maven plugins built and used in a multi-module build:
|
|
682 |
// they need to be added to maven.cleanIgnoreRules to avoid errors during
|
|
683 |
// a mvn clean
|
|
684 |
if ("maven-plugin".equals(dependency.getType()) && containsDependencyIgnoreVersion(projectPoms, dependency)) {
|
|
685 |
cleanIgnoreRules.add(dependency.getGroupId() + " " + dependency.getArtifactId() + " maven-plugin *");
|
|
686 |
}
|
|
687 |
|
|
688 |
// Discover the library to import for the dependency
|
301 | 689 |
String library = null;
|
302 | 690 |
if (pom.getProperties() != null) {
|
303 | 691 |
library = (String) pom.getProperties().get("debian.package");
|
304 | 692 |
}
|
305 | 693 |
if (library == null) {
|
306 | |
issues.add("Dependency is missing the Debian properties in its POM: " + dependency.getGroupId() + ":" +
|
307 | |
dependency.getArtifactId() + ":" + dependency.getVersion());
|
|
694 |
issues.add(sourcePomLoc + ": Dependency is missing the Debian properties in its POM: " + dependency.getGroupId() + ":"
|
|
695 |
+ dependency.getArtifactId() + ":" + dependency.getVersion());
|
308 | 696 |
File pomFile = new File(mavenRepo, dependency.getGroupId().replace(".", "/") + "/" + dependency.getArtifactId() + "/" + dependency.getVersion() + "/" + dependency.getArtifactId() + "-" + dependency.getVersion() + ".pom");
|
309 | 697 |
library = searchPkg(pomFile);
|
310 | 698 |
}
|
311 | |
if (library != null) {
|
|
699 |
if (library != null && !library.equals(getPackageName())) {
|
312 | 700 |
if (buildTime) {
|
313 | 701 |
if ("test".equals(dependency.getScope())) {
|
314 | 702 |
testDepends.add(library);
|
|
345 | 733 |
}
|
346 | 734 |
}
|
347 | 735 |
|
|
736 |
private boolean containsDependencyIgnoreVersion(Collection dependencies, Dependency dependency) {
|
|
737 |
for (Iterator j = dependencies.iterator(); j.hasNext();) {
|
|
738 |
Dependency ignoredDependency = (Dependency) j.next();
|
|
739 |
if (ignoredDependency.equalsIgnoreVersion(dependency)) {
|
|
740 |
return true;
|
|
741 |
}
|
|
742 |
}
|
|
743 |
return false;
|
|
744 |
}
|
|
745 |
|
348 | 746 |
private String searchPkg(File pomFile) {
|
349 | 747 |
GetPackageResult packageResult = new GetPackageResult();
|
350 | 748 |
executeProcess(new String[]{"dpkg", "--search", pomFile.getAbsolutePath()}, packageResult);
|
|
480 | 878 |
System.out.println(" -i<rules>, --published-rules=<rules>: path to the file containing the");
|
481 | 879 |
System.out.println(" extra rules to publish in the property debian.mavenRules in the cleaned POM");
|
482 | 880 |
System.out.println(" --ant: use ant for the packaging");
|
|
881 |
System.out.println(" --run-tests: run the unit tests");
|
|
882 |
System.out.println(" --generate-javadoc: generate Javadoc");
|
483 | 883 |
return;
|
484 | 884 |
}
|
485 | 885 |
DependenciesSolver solver = new DependenciesSolver();
|
|
500 | 900 |
debianPackage = arg.substring(2);
|
501 | 901 |
} else if (arg.startsWith("--package=")) {
|
502 | 902 |
debianPackage = arg.substring("--package=".length());
|
503 | |
} else if (arg.startsWith("--ant")) {
|
|
903 |
} else if (arg.equals("--ant")) {
|
504 | 904 |
packageType = "ant";
|
|
905 |
} else if (arg.equals("--run-tests")) {
|
|
906 |
solver.setRunTests(true);
|
|
907 |
} else if (arg.equals("--generate-javadoc")) {
|
|
908 |
solver.setGenerateJavadoc(true);
|
505 | 909 |
}
|
506 | 910 |
i = inc(i, args);
|
507 | 911 |
}
|
|
912 |
File poms = new File(solver.getOutputDirectory(), debianPackage + ".poms");
|
508 | 913 |
|
509 | 914 |
solver.setPackageName(debianPackage);
|
510 | 915 |
solver.setPackageType(packageType);
|
511 | 916 |
solver.setExploreProjects(true);
|
|
917 |
solver.setListOfPoms(poms);
|
512 | 918 |
|
513 | 919 |
if (verbose) {
|
514 | 920 |
System.out.println("Solving dependencies for package " + debianPackage);
|
|
518 | 924 |
|
519 | 925 |
solver.saveListOfPoms();
|
520 | 926 |
solver.saveMavenRules();
|
|
927 |
solver.saveMavenIgnoreRules();
|
|
928 |
solver.saveMavenCleanIgnoreRules();
|
|
929 |
solver.saveMavenPublishedRules();
|
521 | 930 |
solver.saveSubstvars();
|
522 | 931 |
}
|
523 | 932 |
|
|
527 | 936 |
} while (i < args.length && args[i].isEmpty());
|
528 | 937 |
return i;
|
529 | 938 |
}
|
530 | |
|
531 | 939 |
}
|