[NO ISSUE][LIC] Add ability to fail and/or generate file on license warning
Change-Id: I236832b6bcf362b0faebe9baeff154c01e53495b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2598
Reviewed-by: Michael Blow <mblow@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
index 1b2961f..293c08c 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
@@ -63,7 +63,7 @@
String fileName = entry.getLicense().getContentFile(false);
doDownload(timeoutMillis, i, url, fileName);
});
- } catch (IOException | ProjectBuildingException e) {
+ } catch (ProjectBuildingException e) {
throw new MojoExecutionException("Unexpected exception: " + e, e);
}
}
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
index 22646c5..f61dadf 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
@@ -121,6 +121,10 @@
persistLicenseMap();
buildNoticeProjectMap();
generateFiles();
+ if (seenWarning && failOnWarning) {
+ throw new MojoFailureException(
+ "'failOnWarning' enabled and warning(s) (or error(s)) occurred during execution; see output");
+ }
} catch (IOException | TemplateException | ProjectBuildingException e) {
throw new MojoExecutionException("Unexpected exception: " + e, e);
}
@@ -327,8 +331,9 @@
UnaryOperator.identity());
}
- private void resolveArtifactFiles(final String name, ProjectFlag ignoreFlag, ProjectFlag alternateFilenameFlag,
- Predicate<JarEntry> filter, BiConsumer<Project, String> consumer, UnaryOperator<String> contentTransformer)
+ private void resolveArtifactFiles(final String name, final ProjectFlag ignoreFlag,
+ final ProjectFlag alternateFilenameFlag, final Predicate<JarEntry> filter,
+ final BiConsumer<Project, String> consumer, final UnaryOperator<String> contentTransformer)
throws MojoExecutionException, IOException {
for (Project p : getProjects()) {
File artifactFile = new File(p.getArtifactPath());
@@ -339,11 +344,10 @@
continue;
}
String alternateFilename = (String) getProjectFlag(p.gav(), alternateFilenameFlag);
- if (alternateFilename != null) {
- filter = entry -> entry.getName().equals(alternateFilename);
- }
+ Predicate<JarEntry> finalFilter =
+ alternateFilename != null ? entry -> entry.getName().equals(alternateFilename) : filter;
try (JarFile jarFile = new JarFile(artifactFile)) {
- SortedMap<String, JarEntry> matches = gatherMatchingEntries(jarFile, filter);
+ SortedMap<String, JarEntry> matches = gatherMatchingEntries(jarFile, finalFilter);
if (matches.isEmpty()) {
warnUnlessFlag(p, ignoreFlag, "No " + name + " file found for " + p.gav());
} else {
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseMojo.java b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseMojo.java
index 4466d20..55987da 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseMojo.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseMojo.java
@@ -22,6 +22,7 @@
import static org.apache.hyracks.maven.license.ProjectFlag.IGNORE_LICENSE_OVERRIDE;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -37,6 +38,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@@ -50,6 +52,7 @@
import org.apache.maven.model.Model;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
@@ -59,7 +62,6 @@
public abstract class LicenseMojo extends AbstractMojo {
- private static final String VERIFIED_VERSIONS_PROP = "license-automation-plugin.verifiedVersions";
@Parameter
protected List<Override> overrides = new ArrayList<>();
@@ -105,6 +107,12 @@
@Parameter(required = true)
protected File licenseDirectory;
+ @Parameter
+ protected File warningTouchFile;
+
+ @Parameter
+ protected boolean failOnWarning;
+
private Map<String, MavenProject> projectCache = new HashMap<>();
private Map<String, Model> supplementModels;
@@ -115,17 +123,109 @@
Map<String, LicensedProjects> licenseMap = new TreeMap<>();
private Map<Pair<String, ProjectFlag>, Object> projectFlags = new HashMap<>();
+ protected boolean seenWarning;
+
protected Map<String, LicensedProjects> getLicenseMap() {
return licenseMap;
}
- protected void init() throws MojoExecutionException, MalformedURLException, ProjectBuildingException {
+ protected void init() throws MojoExecutionException {
+ if (warningTouchFile != null) {
+ warningTouchFile.getParentFile().mkdirs();
+ }
+ interceptLogs();
excludedScopes.add("system");
excludePatterns = compileExcludePatterns();
supplementModels = SupplementalModelHelper.loadSupplements(getLog(), models);
buildUrlLicenseMap();
}
+ private void interceptLogs() {
+ final Log originalLog = getLog();
+ setLog(new Log() {
+ public boolean isDebugEnabled() {
+ return originalLog.isDebugEnabled();
+ }
+
+ public void debug(CharSequence charSequence) {
+ originalLog.debug(charSequence);
+ }
+
+ public void debug(CharSequence charSequence, Throwable throwable) {
+ originalLog.debug(charSequence, throwable);
+ }
+
+ public void debug(Throwable throwable) {
+ originalLog.debug(throwable);
+ }
+
+ public boolean isInfoEnabled() {
+ return originalLog.isInfoEnabled();
+ }
+
+ public void info(CharSequence charSequence) {
+ originalLog.info(charSequence);
+ }
+
+ public void info(CharSequence charSequence, Throwable throwable) {
+ originalLog.info(charSequence, throwable);
+ }
+
+ public void info(Throwable throwable) {
+ originalLog.info(throwable);
+ }
+
+ public boolean isWarnEnabled() {
+ return originalLog.isWarnEnabled();
+ }
+
+ public void warn(CharSequence charSequence) {
+ seenWarning();
+ originalLog.warn(charSequence);
+ }
+
+ public void warn(CharSequence charSequence, Throwable throwable) {
+ seenWarning();
+ originalLog.warn(charSequence, throwable);
+ }
+
+ public void warn(Throwable throwable) {
+ seenWarning();
+ originalLog.warn(throwable);
+ }
+
+ public boolean isErrorEnabled() {
+ return originalLog.isErrorEnabled();
+ }
+
+ public void error(CharSequence charSequence) {
+ seenWarning();
+ originalLog.error(charSequence);
+ }
+
+ public void error(CharSequence charSequence, Throwable throwable) {
+ seenWarning();
+ originalLog.error(charSequence, throwable);
+ }
+
+ public void error(Throwable throwable) {
+ seenWarning();
+ originalLog.error(throwable);
+ }
+
+ private void seenWarning() {
+ seenWarning = true;
+ if (warningTouchFile != null) {
+ try {
+ FileUtils.touch(warningTouchFile);
+ } catch (IOException e) {
+ originalLog.error("unable to touch " + warningTouchFile, e);
+ }
+ }
+ }
+ });
+ }
+
protected void addDependenciesToLicenseMap() throws ProjectBuildingException {
Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap = gatherDependencies();
dependencyLicenseMap.forEach((depProject, value) -> {