Test fixtures improovements (#43956)

* Test fixtures improovements

Don't disable some of the precommit tasks on fixtures.
This no longer makes sense now that a project can both produce and use a
fixture.

In order for this to be possible, had to add an additional configuration
to make JarHell class accessible to the task even if it's not a
dependency of the project and fix some of the third party audit fallout
from  #43671 which wasn't detected at the time due to the issue being
fixed here.

Closes #43918
This commit is contained in:
Alpar Torok 2019-07-09 10:04:03 +03:00
parent 5b71340f99
commit bde5802ad6
3 changed files with 34 additions and 12 deletions

View File

@ -27,7 +27,9 @@ import org.elasticsearch.gradle.tool.ClasspathUtils
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.quality.Checkstyle
/**
@ -45,13 +47,23 @@ class PrecommitTasks {
forbiddenApisCliJar('de.thetaphi:forbiddenapis:2.6')
}
Configuration jarHellConfig = project.configurations.create("jarHell")
if (ClasspathUtils.isElasticsearchProject() && project.path.equals(":libs:elasticsearch-core") == false) {
// External plugins will depend on this already via transitive dependencies.
// Internal projects are not all plugins, so make sure the check is available
// we are not doing this for this project itself to avoid jar hell with itself
project.dependencies {
jarHell project.project(":libs:elasticsearch-core")
}
}
List<Task> precommitTasks = [
configureCheckstyle(project),
configureForbiddenApisCli(project),
project.tasks.create('forbiddenPatterns', ForbiddenPatternsTask.class),
project.tasks.create('licenseHeaders', LicenseHeadersTask.class),
project.tasks.create('filepermissions', FilePermissionsTask.class),
configureJarHell(project),
configureJarHell(project, jarHellConfig),
configureThirdPartyAudit(project),
configureTestingConventions(project)
]
@ -108,12 +120,13 @@ class PrecommitTasks {
return task
}
private static Task configureJarHell(Project project) {
private static Task configureJarHell(Project project, Configuration jarHelConfig) {
return project.tasks.create('jarHell', JarHellTask) { task ->
task.classpath = project.sourceSets.test.runtimeClasspath
task.classpath = project.sourceSets.test.runtimeClasspath + jarHelConfig;
if (project.plugins.hasPlugin(ShadowPlugin)) {
task.classpath += project.configurations.bundle
}
task.dependsOn(jarHelConfig);
}
}

View File

@ -22,9 +22,7 @@ import com.avast.gradle.dockercompose.ComposeExtension;
import com.avast.gradle.dockercompose.DockerComposePlugin;
import com.avast.gradle.dockercompose.tasks.ComposeUp;
import org.elasticsearch.gradle.OS;
import org.elasticsearch.gradle.precommit.JarHellTask;
import org.elasticsearch.gradle.precommit.TestingConventionsTasks;
import org.elasticsearch.gradle.precommit.ThirdPartyAuditTask;
import org.gradle.api.DefaultTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
@ -58,12 +56,6 @@ public class TestFixturesPlugin implements Plugin<Project> {
ext.set("testFixturesDir", testfixturesDir);
if (project.file(DOCKER_COMPOSE_YML).exists()) {
// convenience boilerplate with build plugin
// Can't reference tasks that are implemented in Groovy, use reflection instead
disableTaskByType(tasks, getTaskClass("org.elasticsearch.gradle.precommit.LicenseHeadersTask"));
disableTaskByType(tasks, ThirdPartyAuditTask.class);
disableTaskByType(tasks, JarHellTask.class);
// the project that defined a test fixture can also use it
extension.fixtures.add(project);
@ -116,6 +108,14 @@ public class TestFixturesPlugin implements Plugin<Project> {
.getByType(ExtraPropertiesExtension.class).set(name, port)
);
}
} else {
project.afterEvaluate(spec -> {
if (extension.fixtures.isEmpty()) {
// if only one fixture is used, that's this one, but without a compose file that's not a valid configuration
throw new IllegalStateException("No " + DOCKER_COMPOSE_YML + " found for " + project.getPath() +
" nor does it use other fixtures.");
}
});
}
extension.fixtures

View File

@ -323,7 +323,16 @@ thirdPartyAudit.ignoreMissingClasses (
'software.amazon.ion.system.IonBinaryWriterBuilder',
'software.amazon.ion.system.IonSystemBuilder',
'software.amazon.ion.system.IonTextWriterBuilder',
'software.amazon.ion.system.IonWriterBuilder'
'software.amazon.ion.system.IonWriterBuilder',
// We don't use the kms dependency
'com.amazonaws.services.kms.AWSKMS',
'com.amazonaws.services.kms.AWSKMSClient',
'com.amazonaws.services.kms.model.DecryptRequest',
'com.amazonaws.services.kms.model.DecryptResult',
'com.amazonaws.services.kms.model.EncryptRequest',
'com.amazonaws.services.kms.model.EncryptResult',
'com.amazonaws.services.kms.model.GenerateDataKeyRequest',
'com.amazonaws.services.kms.model.GenerateDataKeyResult'
)
// jarhell with jdk (intentionally, because jaxb was removed from default modules in java 9)