mirror of https://github.com/apache/lucene.git
LUCENE-5209: Allow the license checker to optionally avoid check sum comparisons on SNAPSHOT dependencies.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1523356 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c3fd78cae6
commit
2eb1750f4d
|
@ -57,7 +57,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}">
|
<licenses licenseDirectory="@{licensedir}" skipSnapshotsChecksum="${skipSnapshotsChecksum}">
|
||||||
<fileset dir="@{dir}">
|
<fileset dir="@{dir}">
|
||||||
<include name="**/*.jar" />
|
<include name="**/*.jar" />
|
||||||
<!-- Speed up scanning a bit. -->
|
<!-- Speed up scanning a bit. -->
|
||||||
|
|
|
@ -54,6 +54,8 @@ public class LicenseCheckTask extends Task {
|
||||||
private static final int CHECKSUM_BUFFER_SIZE = 8 * 1024;
|
private static final int CHECKSUM_BUFFER_SIZE = 8 * 1024;
|
||||||
private static final int CHECKSUM_BYTE_MASK = 0xFF;
|
private static final int CHECKSUM_BYTE_MASK = 0xFF;
|
||||||
|
|
||||||
|
private boolean skipSnapshotsChecksum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All JAR files to check.
|
* All JAR files to check.
|
||||||
*/
|
*/
|
||||||
|
@ -104,6 +106,10 @@ public class LicenseCheckTask extends Task {
|
||||||
licenseDirectory = file;
|
licenseDirectory = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSkipSnapshotsChecksum(boolean skipSnapshotsChecksum) {
|
||||||
|
this.skipSnapshotsChecksum = skipSnapshotsChecksum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the task.
|
* Execute the task.
|
||||||
*/
|
*/
|
||||||
|
@ -113,6 +119,7 @@ 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);
|
||||||
jarResources.setProject(getProject());
|
jarResources.setProject(getProject());
|
||||||
processJars();
|
processJars();
|
||||||
|
|
||||||
|
@ -161,48 +168,53 @@ 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);
|
||||||
|
|
||||||
// validate the jar matches against our expected hash
|
if (!skipSnapshotsChecksum || !jarFile.getName().contains("-SNAPSHOT")) {
|
||||||
final File checksumFile = new File(licenseDirectory,
|
// validate the jar matches against our expected hash
|
||||||
jarFile.getName() + "." + CHECKSUM_TYPE);
|
final File checksumFile = new File(licenseDirectory,
|
||||||
if (! (checksumFile.exists() && checksumFile.canRead()) ) {
|
jarFile.getName() + "." + CHECKSUM_TYPE);
|
||||||
log("MISSING " +CHECKSUM_TYPE+ " checksum file for: " + jarFile.getPath(), Project.MSG_ERR);
|
if (! (checksumFile.exists() && checksumFile.canRead()) ) {
|
||||||
this.failures = true;
|
log("MISSING " +CHECKSUM_TYPE+ " checksum file for: " + jarFile.getPath(), Project.MSG_ERR);
|
||||||
return false;
|
log("EXPECTED " +CHECKSUM_TYPE+ " checksum file : " + checksumFile.getPath(), Project.MSG_ERR);
|
||||||
} else {
|
this.failures = true;
|
||||||
final String expectedChecksum = readChecksumFile(checksumFile);
|
return false;
|
||||||
try {
|
} else {
|
||||||
final MessageDigest md = MessageDigest.getInstance(CHECKSUM_TYPE);
|
final String expectedChecksum = readChecksumFile(checksumFile);
|
||||||
byte[] buf = new byte[CHECKSUM_BUFFER_SIZE];
|
|
||||||
try {
|
try {
|
||||||
FileInputStream fis = new FileInputStream(jarFile);
|
final MessageDigest md = MessageDigest.getInstance(CHECKSUM_TYPE);
|
||||||
|
byte[] buf = new byte[CHECKSUM_BUFFER_SIZE];
|
||||||
try {
|
try {
|
||||||
DigestInputStream dis = new DigestInputStream(fis, md);
|
FileInputStream fis = new FileInputStream(jarFile);
|
||||||
try {
|
try {
|
||||||
while (dis.read(buf, 0, CHECKSUM_BUFFER_SIZE) != -1) {
|
DigestInputStream dis = new DigestInputStream(fis, md);
|
||||||
// NOOP
|
try {
|
||||||
|
while (dis.read(buf, 0, CHECKSUM_BUFFER_SIZE) != -1) {
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
dis.close();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
dis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
} finally {
|
} catch (IOException ioe) {
|
||||||
fis.close();
|
throw new BuildException("IO error computing checksum of file: " + jarFile, ioe);
|
||||||
|
}
|
||||||
|
final byte[] checksumBytes = md.digest();
|
||||||
|
final String checksum = createChecksumString(checksumBytes);
|
||||||
|
if ( ! checksum.equals(expectedChecksum) ) {
|
||||||
|
log("CHECKSUM FAILED for " + jarFile.getPath() +
|
||||||
|
" (expected: \"" + expectedChecksum + "\" was: \"" + checksum + "\")",
|
||||||
|
Project.MSG_ERR);
|
||||||
|
this.failures = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
|
||||||
throw new BuildException("IO error computing checksum of file: " + jarFile, ioe);
|
|
||||||
}
|
|
||||||
final byte[] checksumBytes = md.digest();
|
|
||||||
final String checksum = createChecksumString(checksumBytes);
|
|
||||||
if ( ! checksum.equals(expectedChecksum) ) {
|
|
||||||
log("CHECKSUM FAILED for " + jarFile.getPath() +
|
|
||||||
" (expected: \"" + expectedChecksum + "\" was: \"" + checksum + "\")",
|
|
||||||
Project.MSG_ERR);
|
|
||||||
this.failures = true;
|
|
||||||
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) {
|
||||||
|
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