Fix deprecation warning in ThirdpartyAuditTask (#57123)
This commit is contained in:
parent
1fde128c40
commit
aed2119fed
|
@ -23,13 +23,14 @@ import org.gradle.util.GradleVersion
|
||||||
plugins {
|
plugins {
|
||||||
id 'java-gradle-plugin'
|
id 'java-gradle-plugin'
|
||||||
id 'groovy'
|
id 'groovy'
|
||||||
|
id 'java-test-fixtures'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'org.elasticsearch.gradle'
|
group = 'org.elasticsearch.gradle'
|
||||||
|
|
||||||
String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
|
String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
|
||||||
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
|
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
|
||||||
throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
|
throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (project == rootProject) {
|
if (project == rootProject) {
|
||||||
|
@ -75,6 +76,11 @@ allprojects {
|
||||||
sourceSets {
|
sourceSets {
|
||||||
// We have a few classes that need to be compiled for older java versions
|
// We have a few classes that need to be compiled for older java versions
|
||||||
minimumRuntime {}
|
minimumRuntime {}
|
||||||
|
|
||||||
|
integTest {
|
||||||
|
compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"]
|
||||||
|
runtimeClasspath += output + compileClasspath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileMinimumRuntimeJava {
|
compileMinimumRuntimeJava {
|
||||||
|
@ -124,8 +130,10 @@ dependencies {
|
||||||
compile 'com.networknt:json-schema-validator:1.0.36'
|
compile 'com.networknt:json-schema-validator:1.0.36'
|
||||||
compileOnly "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
|
compileOnly "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
|
||||||
testCompile "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
|
testCompile "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
|
||||||
testCompile "junit:junit:${props.getProperty('junit')}"
|
testFixturesApi "junit:junit:${props.getProperty('junit')}"
|
||||||
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
|
testFixturesApi "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
|
||||||
|
testFixturesApi gradleApi()
|
||||||
|
testFixturesApi gradleTestKit()
|
||||||
testCompile 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
|
testCompile 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
|
||||||
testCompile 'org.mockito:mockito-core:1.9.5'
|
testCompile 'org.mockito:mockito-core:1.9.5'
|
||||||
minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}"
|
minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}"
|
||||||
|
@ -167,10 +175,11 @@ if (project != rootProject) {
|
||||||
// build-tools is not ready for primetime with these...
|
// build-tools is not ready for primetime with these...
|
||||||
dependencyLicenses.enabled = false
|
dependencyLicenses.enabled = false
|
||||||
dependenciesInfo.enabled = false
|
dependenciesInfo.enabled = false
|
||||||
disableTasks('forbiddenApisMain', 'forbiddenApisMinimumRuntime', 'forbiddenApisTest')
|
disableTasks('forbiddenApisMain', 'forbiddenApisMinimumRuntime',
|
||||||
|
'forbiddenApisTest', 'forbiddenApisIntegTest', 'forbiddenApisTestFixtures')
|
||||||
jarHell.enabled = false
|
jarHell.enabled = false
|
||||||
thirdPartyAudit.enabled = false
|
thirdPartyAudit.enabled = false
|
||||||
if (Boolean.parseBoolean(System.getProperty("tests.fips.enabled"))){
|
if (Boolean.parseBoolean(System.getProperty("tests.fips.enabled"))) {
|
||||||
test.enabled = false
|
test.enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +248,8 @@ if (project != rootProject) {
|
||||||
systemProperty 'test.version_under_test', version
|
systemProperty 'test.version_under_test', version
|
||||||
onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false }
|
onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false }
|
||||||
maxParallelForks = System.getProperty('tests.jvms', org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer
|
maxParallelForks = System.getProperty('tests.jvms', org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer
|
||||||
|
testClassesDirs = sourceSets.integTest.output.classesDirs
|
||||||
|
classpath = sourceSets.integTest.runtimeClasspath
|
||||||
}
|
}
|
||||||
check.dependsOn("integTest")
|
check.dependsOn("integTest")
|
||||||
|
|
||||||
|
@ -254,6 +265,11 @@ if (project != rootProject) {
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
generatePomFileForPluginMavenPublication.enabled = false
|
generatePomFileForPluginMavenPublication.enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publishing.publications.named("nebula").configure {
|
||||||
|
suppressPomMetadataWarningsFor("testFixturesApiElements")
|
||||||
|
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define this here because we need it early.
|
// Define this here because we need it early.
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
package org.elasticsearch.gradle.precommit;
|
|
||||||
|
|
||||||
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to Elasticsearch under one or more contributor
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
* license agreements. See the NOTICE file distributed with
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
@ -13,7 +7,7 @@ import org.junit.Before;
|
||||||
* not use this file except in compliance with the License.
|
* not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
|
@ -22,6 +16,13 @@ import org.junit.Before;
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.gradle.precommit;
|
||||||
|
|
||||||
|
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
|
||||||
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -41,6 +42,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
||||||
"-PcompileVersion=0.0.1"
|
"-PcompileVersion=0.0.1"
|
||||||
).build();
|
).build();
|
||||||
assertTaskNoSource(result, ":empty");
|
assertTaskNoSource(result, ":empty");
|
||||||
|
assertNoDeprecationWarning(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithEmptyRules() {
|
public void testWithEmptyRules() {
|
||||||
|
@ -69,6 +71,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
||||||
assertTaskFailed(result, ":absurd");
|
assertTaskFailed(result, ":absurd");
|
||||||
assertOutputContains(result.getOutput(), "Classes with violations:", " * TestingIO", "> Audit of third party dependencies failed");
|
assertOutputContains(result.getOutput(), "Classes with violations:", " * TestingIO", "> Audit of third party dependencies failed");
|
||||||
assertOutputDoesNotContain(result.getOutput(), "Missing classes:");
|
assertOutputDoesNotContain(result.getOutput(), "Missing classes:");
|
||||||
|
assertNoDeprecationWarning(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassNotFoundAndCompileOnlyIgnored() {
|
public void testClassNotFoundAndCompileOnlyIgnored() {
|
||||||
|
@ -90,6 +93,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
||||||
"> Audit of third party dependencies failed"
|
"> Audit of third party dependencies failed"
|
||||||
);
|
);
|
||||||
assertOutputDoesNotContain(result.getOutput(), "Classes with violations:");
|
assertOutputDoesNotContain(result.getOutput(), "Classes with violations:");
|
||||||
|
assertNoDeprecationWarning(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testJarHellWithJDK() {
|
public void testJarHellWithJDK() {
|
||||||
|
@ -111,6 +115,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
||||||
" * java.lang.String"
|
" * java.lang.String"
|
||||||
);
|
);
|
||||||
assertOutputDoesNotContain(result.getOutput(), "Classes with violations:");
|
assertOutputDoesNotContain(result.getOutput(), "Classes with violations:");
|
||||||
|
assertNoDeprecationWarning(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testElasticsearchIgnoredWithViolations() {
|
public void testElasticsearchIgnoredWithViolations() {
|
||||||
|
@ -124,6 +129,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
||||||
"-PcompileVersion=0.0.1"
|
"-PcompileVersion=0.0.1"
|
||||||
).build();
|
).build();
|
||||||
assertTaskNoSource(result, ":absurd");
|
assertTaskNoSource(result, ":absurd");
|
||||||
|
assertNoDeprecationWarning(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.gradle
|
package org.elasticsearch.gradle
|
||||||
|
|
||||||
|
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin
|
||||||
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
|
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
@ -27,15 +28,16 @@ import org.gradle.api.tasks.TaskProvider
|
||||||
|
|
||||||
class DependenciesInfoPlugin implements Plugin<Project> {
|
class DependenciesInfoPlugin implements Plugin<Project> {
|
||||||
@Override
|
@Override
|
||||||
public void apply(Project project) {
|
void apply(Project project) {
|
||||||
|
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
|
||||||
TaskProvider<DependenciesInfoTask> depsInfo = project.getTasks().register("dependenciesInfo", DependenciesInfoTask.class);
|
TaskProvider<DependenciesInfoTask> depsInfo = project.getTasks().register("dependenciesInfo", DependenciesInfoTask.class);
|
||||||
depsInfo.configure { DependenciesInfoTask t ->
|
depsInfo.configure { DependenciesInfoTask t ->
|
||||||
t.setRuntimeConfiguration(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
|
t.setRuntimeConfiguration(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
|
||||||
t.setCompileOnlyConfiguration(project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME));
|
t.setCompileOnlyConfiguration(project.getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME));
|
||||||
t.getConventionMapping().map("mappings") { ->
|
t.getConventionMapping().map("mappings") { ->
|
||||||
TaskProvider<DependencyLicensesTask> depLic = project.getTasks().named("dependencyLicenses", DependencyLicensesTask.class);
|
TaskProvider<DependencyLicensesTask> depLic = project.getTasks().named("dependencyLicenses", DependencyLicensesTask.class);
|
||||||
return depLic.get().getMappings();
|
return depLic.get().getMappings();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.gradle.api.plugins.JavaPlugin;
|
||||||
import org.gradle.api.plugins.JavaPluginExtension;
|
import org.gradle.api.plugins.JavaPluginExtension;
|
||||||
import org.gradle.api.tasks.SourceSet;
|
import org.gradle.api.tasks.SourceSet;
|
||||||
import org.gradle.api.tasks.SourceSetContainer;
|
import org.gradle.api.tasks.SourceSetContainer;
|
||||||
|
import org.gradle.api.tasks.TaskProvider;
|
||||||
import org.gradle.api.tasks.bundling.Jar;
|
import org.gradle.api.tasks.bundling.Jar;
|
||||||
import org.gradle.api.tasks.compile.CompileOptions;
|
import org.gradle.api.tasks.compile.CompileOptions;
|
||||||
import org.gradle.api.tasks.compile.GroovyCompile;
|
import org.gradle.api.tasks.compile.GroovyCompile;
|
||||||
|
@ -96,12 +97,12 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes dependencies non-transitive.
|
* Makes dependencies non-transitive.
|
||||||
*
|
* <p>
|
||||||
* Gradle allows setting all dependencies as non-transitive very easily.
|
* Gradle allows setting all dependencies as non-transitive very easily.
|
||||||
* Sadly this mechanism does not translate into maven pom generation. In order
|
* Sadly this mechanism does not translate into maven pom generation. In order
|
||||||
* to effectively make the pom act as if it has no transitive dependencies,
|
* to effectively make the pom act as if it has no transitive dependencies,
|
||||||
* we must exclude each transitive dependency of each direct dependency.
|
* we must exclude each transitive dependency of each direct dependency.
|
||||||
*
|
* <p>
|
||||||
* Determining the transitive deps of a dependency which has been resolved as
|
* Determining the transitive deps of a dependency which has been resolved as
|
||||||
* non-transitive is difficult because the process of resolving removes the
|
* non-transitive is difficult because the process of resolving removes the
|
||||||
* transitive deps. To sidestep this issue, we create a configuration per
|
* transitive deps. To sidestep this issue, we create a configuration per
|
||||||
|
@ -555,9 +556,6 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove compiled classes from the Javadoc classpath:
|
|
||||||
// http://mail.openjdk.java.net/pipermail/javadoc-dev/2018-January/000400.html
|
|
||||||
javadoc.setClasspath(Util.getJavaMainSourceSet(project).get().getCompileClasspath());
|
|
||||||
/*
|
/*
|
||||||
* Generate docs using html5 to suppress a warning from `javadoc`
|
* Generate docs using html5 to suppress a warning from `javadoc`
|
||||||
* that the default will change to html5 in the future.
|
* that the default will change to html5 in the future.
|
||||||
|
@ -565,9 +563,14 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
||||||
CoreJavadocOptions javadocOptions = (CoreJavadocOptions) javadoc.getOptions();
|
CoreJavadocOptions javadocOptions = (CoreJavadocOptions) javadoc.getOptions();
|
||||||
javadocOptions.addBooleanOption("html5", true);
|
javadocOptions.addBooleanOption("html5", true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
TaskProvider<Javadoc> javadoc = project.getTasks().withType(Javadoc.class).named("javadoc");
|
||||||
|
javadoc.configure(doc ->
|
||||||
|
// remove compiled classes from the Javadoc classpath:
|
||||||
|
// http://mail.openjdk.java.net/pipermail/javadoc-dev/2018-January/000400.html
|
||||||
|
doc.setClasspath(Util.getJavaMainSourceSet(project).get().getCompileClasspath()));
|
||||||
|
|
||||||
// ensure javadoc task is run with 'check'
|
// ensure javadoc task is run with 'check'
|
||||||
project.getTasks()
|
project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(t -> t.dependsOn(javadoc));
|
||||||
.named(LifecycleBasePlugin.CHECK_TASK_NAME)
|
|
||||||
.configure(t -> t.dependsOn(project.getTasks().withType(Javadoc.class)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.gradle.dependencies;
|
||||||
|
|
||||||
|
import org.gradle.api.NamedDomainObjectProvider;
|
||||||
|
import org.gradle.api.Plugin;
|
||||||
|
import org.gradle.api.Project;
|
||||||
|
import org.gradle.api.artifacts.Configuration;
|
||||||
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
|
|
||||||
|
public class CompileOnlyResolvePlugin implements Plugin<Project> {
|
||||||
|
public static final String RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME = "resolveableCompileOnly";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Project project) {
|
||||||
|
project.getConfigurations().all(configuration -> {
|
||||||
|
if (configuration.getName().equals(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME)) {
|
||||||
|
NamedDomainObjectProvider<Configuration> resolvableCompileOnly = project.getConfigurations()
|
||||||
|
.register(RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
|
||||||
|
resolvableCompileOnly.configure((c) -> {
|
||||||
|
c.setCanBeResolved(true);
|
||||||
|
c.setCanBeConsumed(false);
|
||||||
|
c.extendsFrom(configuration);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.gradle.precommit;
|
package org.elasticsearch.gradle.precommit;
|
||||||
|
|
||||||
|
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
|
@ -29,13 +30,15 @@ public class DependencyLicensesPrecommitPlugin extends PrecommitPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TaskProvider<? extends Task> createTask(Project project) {
|
public TaskProvider<? extends Task> createTask(Project project) {
|
||||||
|
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
|
||||||
TaskProvider<DependencyLicensesTask> dependencyLicenses = project.getTasks()
|
TaskProvider<DependencyLicensesTask> dependencyLicenses = project.getTasks()
|
||||||
.register("dependencyLicenses", DependencyLicensesTask.class);
|
.register("dependencyLicenses", DependencyLicensesTask.class);
|
||||||
|
|
||||||
// only require dependency licenses for non-elasticsearch deps
|
// only require dependency licenses for non-elasticsearch deps
|
||||||
dependencyLicenses.configure(t -> {
|
dependencyLicenses.configure(t -> {
|
||||||
Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
|
Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
|
||||||
Configuration compileOnly = project.getConfigurations().getByName(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME);
|
Configuration compileOnly = project.getConfigurations()
|
||||||
|
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
|
||||||
t.setDependencies(
|
t.setDependencies(
|
||||||
runtimeClasspath.fileCollection(dependency -> dependency.getGroup().startsWith("org.elasticsearch") == false)
|
runtimeClasspath.fileCollection(dependency -> dependency.getGroup().startsWith("org.elasticsearch") == false)
|
||||||
.minus(compileOnly)
|
.minus(compileOnly)
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.gradle.precommit;
|
package org.elasticsearch.gradle.precommit;
|
||||||
|
|
||||||
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask;
|
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask;
|
||||||
|
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
|
||||||
import org.elasticsearch.gradle.info.BuildParams;
|
import org.elasticsearch.gradle.info.BuildParams;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
|
@ -28,19 +29,20 @@ import org.gradle.api.tasks.TaskProvider;
|
||||||
public class ThirdPartyAuditPrecommitPlugin extends PrecommitPlugin {
|
public class ThirdPartyAuditPrecommitPlugin extends PrecommitPlugin {
|
||||||
@Override
|
@Override
|
||||||
public TaskProvider<? extends Task> createTask(Project project) {
|
public TaskProvider<? extends Task> createTask(Project project) {
|
||||||
|
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
|
||||||
project.getConfigurations().create("forbiddenApisCliJar");
|
project.getConfigurations().create("forbiddenApisCliJar");
|
||||||
project.getDependencies().add("forbiddenApisCliJar", "de.thetaphi:forbiddenapis:2.7");
|
project.getDependencies().add("forbiddenApisCliJar", "de.thetaphi:forbiddenapis:2.7");
|
||||||
|
|
||||||
TaskProvider<ExportElasticsearchBuildResourcesTask> buildResources = project.getTasks()
|
|
||||||
.named("buildResources", ExportElasticsearchBuildResourcesTask.class);
|
|
||||||
|
|
||||||
TaskProvider<ThirdPartyAuditTask> audit = project.getTasks().register("thirdPartyAudit", ThirdPartyAuditTask.class);
|
TaskProvider<ThirdPartyAuditTask> audit = project.getTasks().register("thirdPartyAudit", ThirdPartyAuditTask.class);
|
||||||
audit.configure(t -> {
|
audit.configure(t -> {
|
||||||
t.dependsOn(buildResources);
|
t.dependsOn("buildResources");
|
||||||
t.setSignatureFile(buildResources.get().copy("forbidden/third-party-audit.txt"));
|
|
||||||
t.setJavaHome(BuildParams.getRuntimeJavaHome().toString());
|
t.setJavaHome(BuildParams.getRuntimeJavaHome().toString());
|
||||||
t.getTargetCompatibility().set(project.provider(BuildParams::getRuntimeJavaVersion));
|
t.getTargetCompatibility().set(project.provider(BuildParams::getRuntimeJavaVersion));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
project.getTasks()
|
||||||
|
.withType(ExportElasticsearchBuildResourcesTask.class)
|
||||||
|
.configureEach((br) -> { audit.get().setSignatureFile(br.copy("forbidden/third-party-audit.txt")); });
|
||||||
return audit;
|
return audit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import de.thetaphi.forbiddenapis.cli.CliMain;
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
import org.elasticsearch.gradle.JdkJarHellCheck;
|
import org.elasticsearch.gradle.JdkJarHellCheck;
|
||||||
import org.elasticsearch.gradle.OS;
|
import org.elasticsearch.gradle.OS;
|
||||||
|
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
|
||||||
import org.gradle.api.DefaultTask;
|
import org.gradle.api.DefaultTask;
|
||||||
import org.gradle.api.GradleException;
|
import org.gradle.api.GradleException;
|
||||||
import org.gradle.api.JavaVersion;
|
import org.gradle.api.JavaVersion;
|
||||||
|
@ -175,7 +176,7 @@ public class ThirdPartyAuditTask extends DefaultTask {
|
||||||
Spec<Dependency> reallyThirdParty = dep -> dep.getGroup() != null && dep.getGroup().startsWith("org.elasticsearch") == false;
|
Spec<Dependency> reallyThirdParty = dep -> dep.getGroup() != null && dep.getGroup().startsWith("org.elasticsearch") == false;
|
||||||
Set<File> jars = getRuntimeConfiguration().getResolvedConfiguration().getFiles(reallyThirdParty);
|
Set<File> jars = getRuntimeConfiguration().getResolvedConfiguration().getFiles(reallyThirdParty);
|
||||||
Set<File> compileOnlyConfiguration = getProject().getConfigurations()
|
Set<File> compileOnlyConfiguration = getProject().getConfigurations()
|
||||||
.getByName("compileOnly")
|
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
|
||||||
.getResolvedConfiguration()
|
.getResolvedConfiguration()
|
||||||
.getFiles(reallyThirdParty);
|
.getFiles(reallyThirdParty);
|
||||||
// don't scan provided dependencies that we already scanned, e.x. don't scan cores dependencies for every plugin
|
// don't scan provided dependencies that we already scanned, e.x. don't scan cores dependencies for every plugin
|
||||||
|
@ -329,7 +330,7 @@ public class ThirdPartyAuditTask extends DefaultTask {
|
||||||
spec.classpath(
|
spec.classpath(
|
||||||
getForbiddenAPIsConfiguration(),
|
getForbiddenAPIsConfiguration(),
|
||||||
getRuntimeConfiguration(),
|
getRuntimeConfiguration(),
|
||||||
getProject().getConfigurations().getByName("compileOnly")
|
getProject().getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
|
||||||
);
|
);
|
||||||
spec.jvmArgs("-Xmx1g");
|
spec.jvmArgs("-Xmx1g");
|
||||||
spec.setMain("de.thetaphi.forbiddenapis.cli.CliMain");
|
spec.setMain("de.thetaphi.forbiddenapis.cli.CliMain");
|
||||||
|
@ -364,7 +365,7 @@ public class ThirdPartyAuditTask extends DefaultTask {
|
||||||
spec.classpath(
|
spec.classpath(
|
||||||
location.toURI().getPath(),
|
location.toURI().getPath(),
|
||||||
getRuntimeConfiguration(),
|
getRuntimeConfiguration(),
|
||||||
getProject().getConfigurations().getByName("compileOnly")
|
getProject().getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
|
||||||
);
|
);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
|
|
@ -143,6 +143,10 @@ public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void assertNoDeprecationWarning(BuildResult result) {
|
||||||
|
assertOutputDoesNotContain(result.getOutput(), "Deprecated Gradle features were used in this build");
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertBuildFileExists(BuildResult result, String projectName, String path) {
|
protected void assertBuildFileExists(BuildResult result, String projectName, String path) {
|
||||||
Path absPath = getBuildDir(projectName).toPath().resolve(path);
|
Path absPath = getBuildDir(projectName).toPath().resolve(path);
|
||||||
assertTrue(
|
assertTrue(
|
|
@ -1,11 +1,15 @@
|
||||||
|
import org.elasticsearch.gradle.precommit.ThirdPartyAuditPrecommitPlugin
|
||||||
import org.elasticsearch.gradle.precommit.ThirdPartyAuditTask
|
import org.elasticsearch.gradle.precommit.ThirdPartyAuditTask
|
||||||
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
// bring in build-tools onto the classpath
|
// bring in build-tools onto the classpath
|
||||||
id 'elasticsearch.global-build-info' apply false
|
id 'elasticsearch.global-build-info' apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins.apply(ThirdPartyAuditPrecommitPlugin)
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
/**
|
/**
|
||||||
* Local test repo contains dummy jars with different group names and versions.
|
* Local test repo contains dummy jars with different group names and versions.
|
||||||
|
@ -23,12 +27,10 @@ repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations.register("forbiddenApisCliJar")
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
forbiddenApisCliJar 'de.thetaphi:forbiddenapis:2.7'
|
forbiddenApisCliJar 'de.thetaphi:forbiddenapis:2.7'
|
||||||
compileOnly "org.${project.properties.compileOnlyGroup}:${project.properties.compileOnlyVersion}"
|
compileOnly "org.${project.properties.compileOnlyGroup}:${project.properties.compileOnlyVersion}"
|
||||||
compile "org.${project.properties.compileGroup}:${project.properties.compileVersion}"
|
implementation "org.${project.properties.compileGroup}:${project.properties.compileVersion}"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("empty", ThirdPartyAuditTask) {
|
tasks.register("empty", ThirdPartyAuditTask) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.apache.logging.log4j:log4j-core:2.11.1'
|
implementation 'org.apache.logging.log4j:log4j-core:2.11.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
["0.0.1", "0.0.2"].forEach { v ->
|
["0.0.1", "0.0.2"].forEach { v ->
|
||||||
|
|
Loading…
Reference in New Issue