1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.mojo.license;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.List;
21 import java.util.SortedMap;
22 import java.util.SortedSet;
23
24 import org.apache.commons.collections.CollectionUtils;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.apache.maven.plugin.logging.Log;
27 import org.apache.maven.project.MavenProject;
28 import org.apache.maven.project.ProjectBuildingException;
29 import org.codehaus.mojo.license.model.LicenseMap;
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class AggregatorAddThirdPartyMojo extends AbstractAddThirdPartyMojo {
44
45
46
47
48
49
50
51
52
53 protected List<?> reactorProjects;
54
55 @Override
56 protected boolean checkPackaging() {
57 return acceptPackaging("pom");
58 }
59
60 @Override
61 protected boolean checkSkip() {
62 if (!isDoGenerate() && !isDoGenerateBundle()) {
63
64 getLog().info("All files are up to date, skip goal execution.");
65 return false;
66 }
67 return super.checkSkip();
68 }
69
70 @Override
71 protected SortedMap<String, MavenProject> loadDependencies() {
72
73 return getArtifactCache();
74 }
75
76 @Override
77 protected SortedProperties createUnsafeMapping() throws ProjectBuildingException, IOException {
78
79 String path = getMissingFile().getAbsolutePath().substring(
80 getProject().getBasedir().getAbsolutePath().length() + 1);
81
82 if (isVerbose()) {
83 getLog().info("Use missing file path : " + path);
84 }
85
86 SortedProperties unsafeMappings = new SortedProperties(getEncoding());
87
88 LicenseMap licenseMap = getLicenseMap();
89
90 for (Object o : reactorProjects) {
91 MavenProject p = (MavenProject) o;
92
93 File file = new File(p.getBasedir(), path);
94
95 if (file.exists()) {
96
97 SortedProperties tmp = getThirdPartyTool().loadUnsafeMapping(licenseMap, getArtifactCache(),
98 getEncoding(), file);
99 unsafeMappings.putAll(tmp);
100 }
101
102 SortedSet<MavenProject> unsafes = getThirdPartyTool().getProjectsWithNoLicense(licenseMap, isVerbose());
103 if (CollectionUtils.isEmpty(unsafes)) {
104
105
106 break;
107 }
108 }
109 return unsafeMappings;
110 }
111
112 @Override
113 protected void doAction() throws Exception {
114 Log log = getLog();
115
116 if (exists(getArtifactLicenseMapping())) {
117 File propertiesFile = copyToFileSystem(getArtifactLicenseMapping());
118 setMissingFile(propertiesFile);
119 }
120
121 if (isVerbose()) {
122 log.info("After executing on " + reactorProjects.size() + " project(s)");
123 }
124 SortedMap<String, MavenProject> artifacts = getArtifactCache();
125
126 LicenseMap licenseMap = getLicenseMap();
127
128 getLog().info(artifacts.size() + " detected artifact(s).");
129 if (isVerbose()) {
130 for (String id : artifacts.keySet()) {
131 getLog().info(" - " + id);
132 }
133 }
134 getLog().info(licenseMap.size() + " detected license(s).");
135 if (isVerbose()) {
136 for (String id : licenseMap.keySet()) {
137 getLog().info(" - " + id);
138 }
139 }
140 boolean unsafe = checkUnsafeDependencies();
141
142 writeThirdPartyFile();
143
144 if (unsafe && isFailIfWarning()) {
145 throw new MojoFailureException("There is some dependencies with no license, please review the modules.");
146 }
147 }
148
149 }