Michael Blow has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/2598
Change subject: [NO ISSUE][LIC] Add ability to fail and/or generate file on license warning ...................................................................... [NO ISSUE][LIC] Add ability to fail and/or generate file on license warning Change-Id: I236832b6bcf362b0faebe9baeff154c01e53495b --- M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseMojo.java 3 files changed, 103 insertions(+), 2 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/98/2598/1 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..e93c428 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); } 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..753e5ce 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; @@ -105,6 +108,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,11 +124,99 @@ 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(); + } + 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); + } + } + } + }); excludedScopes.add("system"); excludePatterns = compileExcludePatterns(); supplementModels = SupplementalModelHelper.loadSupplements(getLog(), models); -- To view, visit https://asterix-gerrit.ics.uci.edu/2598 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I236832b6bcf362b0faebe9baeff154c01e53495b Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: release-0.9.4-pre-rc Gerrit-Owner: Michael Blow <mb...@apache.org>