mirror of https://github.com/apache/lucene.git
LUCENE-5295: Allow the license checker to optionally avoid check sum comparisons.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1533791 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d4f285c177
commit
5bfdfac931
|
@ -59,7 +59,7 @@
|
||||||
<sequential>
|
<sequential>
|
||||||
<!-- LICENSE and NOTICE verification macro. -->
|
<!-- LICENSE and NOTICE verification macro. -->
|
||||||
<echo>License check under: @{dir}</echo>
|
<echo>License check under: @{dir}</echo>
|
||||||
<licenses licenseDirectory="@{licensedir}" skipSnapshotsChecksum="${skipSnapshotsChecksum}">
|
<licenses licenseDirectory="@{licensedir}" skipChecksum="${skipChecksum}" skipSnapshotsChecksum="${skipSnapshotsChecksum}">
|
||||||
<fileset dir="@{dir}">
|
<fileset dir="@{dir}">
|
||||||
<include name="**/*.jar" />
|
<include name="**/*.jar" />
|
||||||
<!-- Speed up scanning a bit. -->
|
<!-- Speed up scanning a bit. -->
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class LicenseCheckTask extends Task {
|
||||||
private static final int CHECKSUM_BYTE_MASK = 0xFF;
|
private static final int CHECKSUM_BYTE_MASK = 0xFF;
|
||||||
|
|
||||||
private boolean skipSnapshotsChecksum;
|
private boolean skipSnapshotsChecksum;
|
||||||
|
private boolean skipChecksum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All JAR files to check.
|
* All JAR files to check.
|
||||||
|
@ -110,6 +111,10 @@ public class LicenseCheckTask extends Task {
|
||||||
this.skipSnapshotsChecksum = skipSnapshotsChecksum;
|
this.skipSnapshotsChecksum = skipSnapshotsChecksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSkipChecksum(boolean skipChecksum) {
|
||||||
|
this.skipChecksum = skipChecksum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the task.
|
* Execute the task.
|
||||||
*/
|
*/
|
||||||
|
@ -119,7 +124,12 @@ public class LicenseCheckTask extends Task {
|
||||||
throw new BuildException("Expected an embedded <licenseMapper>.");
|
throw new BuildException("Expected an embedded <licenseMapper>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skipSnapshotsChecksum) log("Skipping checksum for SNAPSHOT dependencies", Project.MSG_INFO);
|
if (skipChecksum) {
|
||||||
|
log("Skipping checksum verification for dependencies", Project.MSG_INFO);
|
||||||
|
} else if (skipSnapshotsChecksum) {
|
||||||
|
log("Skipping checksum for SNAPSHOT dependencies", Project.MSG_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
jarResources.setProject(getProject());
|
jarResources.setProject(getProject());
|
||||||
processJars();
|
processJars();
|
||||||
|
|
||||||
|
@ -168,13 +178,16 @@ public class LicenseCheckTask extends Task {
|
||||||
private boolean checkJarFile(File jarFile) {
|
private boolean checkJarFile(File jarFile) {
|
||||||
log("Scanning: " + jarFile.getPath(), verboseLevel);
|
log("Scanning: " + jarFile.getPath(), verboseLevel);
|
||||||
|
|
||||||
|
if (!skipChecksum) {
|
||||||
if (!skipSnapshotsChecksum || !jarFile.getName().contains("-SNAPSHOT")) {
|
if (!skipSnapshotsChecksum || !jarFile.getName().contains("-SNAPSHOT")) {
|
||||||
// validate the jar matches against our expected hash
|
// validate the jar matches against our expected hash
|
||||||
final File checksumFile = new File(licenseDirectory,
|
final File checksumFile = new File(licenseDirectory, jarFile.getName()
|
||||||
jarFile.getName() + "." + CHECKSUM_TYPE);
|
+ "." + CHECKSUM_TYPE);
|
||||||
if (! (checksumFile.exists() && checksumFile.canRead()) ) {
|
if (!(checksumFile.exists() && checksumFile.canRead())) {
|
||||||
log("MISSING " +CHECKSUM_TYPE+ " checksum file for: " + jarFile.getPath(), Project.MSG_ERR);
|
log("MISSING " + CHECKSUM_TYPE + " checksum file for: "
|
||||||
log("EXPECTED " +CHECKSUM_TYPE+ " checksum file : " + checksumFile.getPath(), Project.MSG_ERR);
|
+ jarFile.getPath(), Project.MSG_ERR);
|
||||||
|
log("EXPECTED " + CHECKSUM_TYPE + " checksum file : "
|
||||||
|
+ checksumFile.getPath(), Project.MSG_ERR);
|
||||||
this.failures = true;
|
this.failures = true;
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -197,24 +210,28 @@ public class LicenseCheckTask extends Task {
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new BuildException("IO error computing checksum of file: " + jarFile, ioe);
|
throw new BuildException("IO error computing checksum of file: "
|
||||||
|
+ jarFile, ioe);
|
||||||
}
|
}
|
||||||
final byte[] checksumBytes = md.digest();
|
final byte[] checksumBytes = md.digest();
|
||||||
final String checksum = createChecksumString(checksumBytes);
|
final String checksum = createChecksumString(checksumBytes);
|
||||||
if ( ! checksum.equals(expectedChecksum) ) {
|
if (!checksum.equals(expectedChecksum)) {
|
||||||
log("CHECKSUM FAILED for " + jarFile.getPath() +
|
log("CHECKSUM FAILED for " + jarFile.getPath() + " (expected: \""
|
||||||
" (expected: \"" + expectedChecksum + "\" was: \"" + checksum + "\")",
|
+ expectedChecksum + "\" was: \"" + checksum + "\")",
|
||||||
Project.MSG_ERR);
|
Project.MSG_ERR);
|
||||||
this.failures = true;
|
this.failures = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException ae) {
|
} catch (NoSuchAlgorithmException ae) {
|
||||||
throw new BuildException("Digest type " + CHECKSUM_TYPE + " not supported by your JVM", ae);
|
throw new BuildException("Digest type " + CHECKSUM_TYPE
|
||||||
|
+ " not supported by your JVM", ae);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (skipSnapshotsChecksum) {
|
} else if (skipSnapshotsChecksum) {
|
||||||
log("Skipping jar because it is a SNAPSHOT : " + jarFile.getAbsolutePath(), Project.MSG_INFO);
|
log("Skipping jar because it is a SNAPSHOT : "
|
||||||
|
+ jarFile.getAbsolutePath(), Project.MSG_INFO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the expected license path base from the mapper and search for license files.
|
// Get the expected license path base from the mapper and search for license files.
|
||||||
|
|
Loading…
Reference in New Issue