Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-8353: Support regex for skipping license checksums

Gregory Chanan75c00c78771e
diff --git a/lucene/build.xml b/lucene/build.xml
index 54d33b0a694..b7f790db356 100644
--- a/lucene/build.xml
+++ b/lucene/build.xml
@@ -82,6 +82,7 @@
</target>
<target name="check-licenses" depends="compile-tools,resolve,load-custom-tasks" description="Validate license stuff.">
+ <property name="skipRegexChecksum" value=""/>
<license-check-macro dir="${basedir}" licensedir="${common.dir}/licenses">
<additional-filters>
<replaceregex pattern="jetty([^/]+)$" replace="jetty" flags="gi" />
diff --git a/lucene/tools/custom-tasks.xml b/lucene/tools/custom-tasks.xml
index 8210002d10a..71e3f975c9f 100644
--- a/lucene/tools/custom-tasks.xml
+++ b/lucene/tools/custom-tasks.xml
@@ -59,7 +59,7 @@
<sequential>
<!-- LICENSE and NOTICE verification macro. -->
<echo>License check under: @{dir}</echo>
- <licenses licenseDirectory="@{licensedir}" skipChecksum="${skipChecksum}" skipSnapshotsChecksum="${skipSnapshotsChecksum}">
+ <licenses licenseDirectory="@{licensedir}" skipChecksum="${skipChecksum}" skipRegexChecksum="${skipRegexChecksum}" skipSnapshotsChecksum="${skipSnapshotsChecksum}">
<fileset dir="@{dir}">
<include name="**/*.jar" />
<!-- Speed up scanning a bit. -->
diff --git a/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java b/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java
index e1e2c8ea115..b1bdab7a0f2 100644
--- a/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java
+++ b/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java
@@ -29,6 +29,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -56,6 +59,7 @@ public class LicenseCheckTask extends Task {
+ "If you recently modified ivy-versions.properties or any module's ivy.xml,\n"
+ "make sure you run \"ant clean-jars jar-checksums\" before running precommit.";
+ private Pattern skipRegexChecksum;
private boolean skipSnapshotsChecksum;
private boolean skipChecksum;
@@ -117,6 +121,17 @@ public class LicenseCheckTask extends Task {
this.skipChecksum = skipChecksum;
}
+ public void setSkipRegexChecksum(String skipRegexChecksum) {
+ try {
+ if (skipRegexChecksum != null && skipRegexChecksum.length() > 0) {
+ this.skipRegexChecksum = Pattern.compile(skipRegexChecksum);
+ }
+ } catch (PatternSyntaxException e) {
+ throw new BuildException("Unable to compile skipRegexChecksum pattern. Reason: "
+ + e.getMessage() + " " + skipRegexChecksum, e);
+ }
+ }
+
/**
* Execute the task.
*/
@@ -128,8 +143,15 @@ public class LicenseCheckTask extends Task {
if (skipChecksum) {
log("Skipping checksum verification for dependencies", Project.MSG_INFO);
- } else if (skipSnapshotsChecksum) {
- log("Skipping checksum for SNAPSHOT dependencies", Project.MSG_INFO);
+ } else {
+ if (skipSnapshotsChecksum) {
+ log("Skipping checksum for SNAPSHOT dependencies", Project.MSG_INFO);
+ }
+
+ if (skipRegexChecksum != null) {
+ log("Skipping checksum for dependencies matching regex: " + skipRegexChecksum.pattern(),
+ Project.MSG_INFO);
+ }
}
jarResources.setProject(getProject());
@@ -181,7 +203,8 @@ public class LicenseCheckTask extends Task {
log("Scanning: " + jarFile.getPath(), verboseLevel);
if (!skipChecksum) {
- if (!skipSnapshotsChecksum || !jarFile.getName().contains("-SNAPSHOT")) {
+ boolean skipDueToSnapshot = skipSnapshotsChecksum && jarFile.getName().contains("-SNAPSHOT");
+ if (!skipDueToSnapshot && !matchesRegexChecksum(jarFile, skipRegexChecksum)) {
// validate the jar matches against our expected hash
final File checksumFile = new File(licenseDirectory, jarFile.getName()
+ "." + CHECKSUM_TYPE);
@@ -230,9 +253,12 @@ public class LicenseCheckTask extends Task {
+ " not supported by your JVM", ae);
}
}
- } else if (skipSnapshotsChecksum) {
+ } else if (skipDueToSnapshot) {
log("Skipping jar because it is a SNAPSHOT : "
+ jarFile.getAbsolutePath(), Project.MSG_INFO);
+ } else {
+ log("Skipping jar because it matches regex pattern: "
+ + jarFile.getAbsolutePath() + " pattern: " + skipRegexChecksum.pattern(), Project.MSG_INFO);
}
}
@@ -319,4 +345,11 @@ outer:
}
}
+ private static final boolean matchesRegexChecksum(File jarFile, Pattern skipRegexChecksum) {
+ if (skipRegexChecksum == null) {
+ return false;
+ }
+ Matcher m = skipRegexChecksum.matcher(jarFile.getName());
+ return m.matches();
+ }
}
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index d7ed203ea2f..d1933a572f0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -224,6 +224,8 @@ Other Changes
called SolrDocumentBase. Deprecated methods toSolrInputDocument and toSolrDocument in ClientUtils.
(Ishan Chattopadhyaya via shalin)
+* SOLR-8353: Support regex for skipping license checksums (Gregory Chanan)
+
================== 5.4.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
diff --git a/solr/build.xml b/solr/build.xml
index f79d1af7709..fbed3cb75ec 100644
--- a/solr/build.xml
+++ b/solr/build.xml
@@ -313,6 +313,7 @@
</target>
<target name="check-licenses" depends="compile-tools,resolve,load-custom-tasks" description="Validate license stuff.">
+ <property name="skipRegexChecksum" value=""/>
<license-check-macro dir="${basedir}" licensedir="${common-solr.dir}/licenses">
<additional-excludes>
<exclude name="example/exampledocs/post.jar" />