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