Skip to content

Commit 35bd6d7

Browse files
committed
Run Third party audit with forbidden APIs CLI (part3/3) (#33052)
The new implementation is functional equivalent with the old, ant based one. It parses task standard error to get the missing classes and violations in the same way. I considered re-using ForbiddenApisCliTask but Gradle makes it hard to build inheritance with tasks that have task actions , since the order of the task actions can't be controlled. This inheritance isn't dully desired either as the third party audit task is much more opinionated and we don't want to expose some of the configuration. We could probably extract a common base class without any task actions, but probably more trouble than it's worth. Closes #31715
1 parent 01fad77 commit 35bd6d7

File tree

17 files changed

+505
-348
lines changed

17 files changed

+505
-348
lines changed

buildSrc/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ dependencies {
102102
compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
103103
compile 'org.eclipse.jgit:org.eclipse.jgit:3.2.0.201312181205-r'
104104
compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
105-
compile 'de.thetaphi:forbiddenapis:2.5'
106105
compile 'org.apache.rat:apache-rat:0.11'
107106
compile "org.elasticsearch:jna:4.5.1"
108107
compile 'com.github.jengelman.gradle.plugins:shadow:2.0.4'

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class PrecommitTasks {
3131

3232
/** Adds a precommit task, which depends on non-test verification tasks. */
3333
public static Task create(Project project, boolean includeDependencyLicenses) {
34+
Configuration forbiddenApisConfiguration = project.configurations.create("forbiddenApisCliJar")
35+
project.dependencies {
36+
forbiddenApisCliJar ('de.thetaphi:forbiddenapis:2.5')
37+
}
38+
3439
List<Task> precommitTasks = [
3540
configureCheckstyle(project),
3641
configureForbiddenApisCli(project),
@@ -39,7 +44,7 @@ class PrecommitTasks {
3944
project.tasks.create('licenseHeaders', LicenseHeadersTask.class),
4045
project.tasks.create('filepermissions', FilePermissionsTask.class),
4146
project.tasks.create('jarHell', JarHellTask.class),
42-
project.tasks.create('thirdPartyAudit', ThirdPartyAuditTask.class)
47+
configureThirdPartyAudit(project)
4348
]
4449

4550
// tasks with just tests don't need dependency licenses, so this flag makes adding
@@ -75,32 +80,26 @@ class PrecommitTasks {
7580
return project.tasks.create(precommitOptions)
7681
}
7782

78-
private static Task configureForbiddenApisCli(Project project) {
79-
Configuration forbiddenApisConfiguration = project.configurations.create("forbiddenApisCliJar")
80-
project.dependencies {
81-
forbiddenApisCliJar ('de.thetaphi:forbiddenapis:2.5')
83+
private static Task configureThirdPartyAudit(Project project) {
84+
ThirdPartyAuditTask thirdPartyAuditTask = project.tasks.create('thirdPartyAudit', ThirdPartyAuditTask.class)
85+
ExportElasticsearchBuildResourcesTask buildResources = project.tasks.getByName('buildResources')
86+
thirdPartyAuditTask.configure {
87+
dependsOn(buildResources)
88+
signatureFile = buildResources.copy("forbidden/third-party-audit.txt")
89+
javaHome = project.runtimeJavaHome
8290
}
83-
Task forbiddenApisCli = project.tasks.create('forbiddenApis')
91+
return thirdPartyAuditTask
92+
}
8493

94+
private static Task configureForbiddenApisCli(Project project) {
95+
Task forbiddenApisCli = project.tasks.create('forbiddenApis')
8596
project.sourceSets.forEach { sourceSet ->
8697
forbiddenApisCli.dependsOn(
8798
project.tasks.create(sourceSet.getTaskName('forbiddenApis', null), ForbiddenApisCliTask) {
8899
ExportElasticsearchBuildResourcesTask buildResources = project.tasks.getByName('buildResources')
89100
dependsOn(buildResources)
90-
execAction = { spec ->
91-
spec.classpath = project.files(
92-
project.configurations.forbiddenApisCliJar,
93-
sourceSet.compileClasspath,
94-
sourceSet.runtimeClasspath
95-
)
96-
spec.executable = "${project.runtimeJavaHome}/bin/java"
97-
}
98-
inputs.files(
99-
forbiddenApisConfiguration,
100-
sourceSet.compileClasspath,
101-
sourceSet.runtimeClasspath
102-
)
103-
101+
it.sourceSet = sourceSet
102+
javaHome = project.runtimeJavaHome
104103
targetCompatibility = project.compilerJavaVersion
105104
bundledSignatures = [
106105
"jdk-unsafe", "jdk-deprecated", "jdk-non-portable", "jdk-system-out"

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.groovy

Lines changed: 0 additions & 297 deletions
This file was deleted.

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class StandaloneRestTestPlugin implements Plugin<Project> {
5353

5454
// only setup tests to build
5555
project.sourceSets.create('test')
56+
// create a compileOnly configuration as others might expect it
57+
project.configurations.create("compileOnly")
5658
project.dependencies.add('testCompile', "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}")
5759

5860
project.eclipse.classpath.sourceSets = [project.sourceSets.test]

0 commit comments

Comments
 (0)