Ignore JAR manifests when snapshotting runtime classpaths (#42548)

(cherry picked from commit d5281fc96f6fb2f022c87699bdad64d88614e04c)
This commit is contained in:
Mark Vieira 2019-05-24 18:08:51 -07:00
parent 3a6c2525ca
commit 24cf86a013
No known key found for this signature in database
GPG Key ID: CA947EF7E6D4B105
4 changed files with 42 additions and 19 deletions

View File

@ -108,6 +108,7 @@ class BuildPlugin implements Plugin<Project> {
globalBuildInfo(project)
configureRepositories(project)
project.ext.versions = VersionProperties.versions
configureInputNormalization(project)
configureSourceSets(project)
configureCompile(project)
configureJavadoc(project)
@ -118,7 +119,7 @@ class BuildPlugin implements Plugin<Project> {
configureDependenciesInfo(project)
// Common config when running with a FIPS-140 runtime JVM
// Need to do it here to support external plugins
// Need to do it here to support external plugins
if (project.ext.inFipsJvm) {
project.tasks.withType(Test) {
systemProperty 'javax.net.ssl.trustStorePassword', 'password'
@ -783,6 +784,13 @@ class BuildPlugin implements Plugin<Project> {
}
}
/**
* Apply runtime classpath input normalization so that changes in JAR manifests don't break build cacheability
*/
static void configureInputNormalization(Project project) {
project.normalization.runtimeClasspath.ignore('META-INF/MANIFEST.MF')
}
/** Adds compiler settings to the project */
static void configureCompile(Project project) {
if (project.compilerJavaVersion < JavaVersion.VERSION_1_10) {

View File

@ -60,6 +60,7 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
BuildPlugin.globalBuildInfo(project)
BuildPlugin.configureRepositories(project)
BuildPlugin.configureTestTasks(project)
BuildPlugin.configureInputNormalization(project)
// only setup tests to build
SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer)

View File

@ -3,6 +3,7 @@ package org.elasticsearch.gradle;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.logging.Logger;
import org.gradle.api.tasks.Exec;
import org.gradle.api.tasks.Internal;
@ -34,22 +35,27 @@ public class LoggedExec extends Exec {
if (getLogger().isInfoEnabled() == false) {
setIgnoreExitValue(true);
setSpoolOutput(false);
doLast(task -> {
if (getExecResult().getExitValue() != 0) {
try {
getLogger().error("Output for " + getExecutable() + ":");
outputLogger.accept(getLogger());
} catch (Exception e) {
throw new GradleException("Failed to read exec output", e);
// We use an anonymous inner class here because Gradle cannot properly snapshot this input for the purposes of
// incremental build if we use a lambda. This ensures LoggedExec tasks that declare output can be UP-TO-DATE.
doLast(new Action<Task>() {
@Override
public void execute(Task task) {
if (LoggedExec.this.getExecResult().getExitValue() != 0) {
try {
LoggedExec.this.getLogger().error("Output for " + LoggedExec.this.getExecutable() + ":");
outputLogger.accept(LoggedExec.this.getLogger());
} catch (Exception e) {
throw new GradleException("Failed to read exec output", e);
}
throw new GradleException(
String.format(
"Process '%s %s' finished with non-zero exit value %d",
LoggedExec.this.getExecutable(),
LoggedExec.this.getArgs(),
LoggedExec.this.getExecResult().getExitValue()
)
);
}
throw new GradleException(
String.format(
"Process '%s %s' finished with non-zero exit value %d",
getExecutable(),
getArgs(),
getExecResult().getExitValue()
)
);
}
});
}

View File

@ -56,7 +56,7 @@ dependencies {
}
// needed to be consistent with ssl host checking
String host = InetAddress.getLoopbackAddress().getHostAddress();
String host = InetAddress.getLoopbackAddress().getHostAddress()
// location of keystore and files to generate it
File keystore = new File(project.buildDir, 'keystore/test-node.jks')
@ -67,6 +67,7 @@ task createKey(type: LoggedExec) {
project.delete(keystore.parentFile)
keystore.parentFile.mkdirs()
}
outputs.file(keystore).withPropertyName('keystoreFile')
executable = new File(project.runtimeJavaHome, 'bin/keytool')
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
args '-genkey',
@ -81,8 +82,15 @@ task createKey(type: LoggedExec) {
}
// add keystore to test classpath: it expects it there
sourceSets.test.resources.srcDir(keystore.parentFile)
processTestResources.dependsOn(createKey)
processTestResources {
from createKey
}
normalization {
runtimeClasspath {
ignore 'test-node.jks'
}
}
dependencyLicenses {
mapping from: /azure-.*/, to: 'azure'