parent
fdac9e99fa
commit
51158a2d8b
|
@ -23,10 +23,16 @@ import org.gradle.util.GradleVersion
|
|||
plugins {
|
||||
id 'java-gradle-plugin'
|
||||
id 'groovy'
|
||||
id 'java-test-fixtures'
|
||||
}
|
||||
|
||||
group = 'org.elasticsearch.gradle'
|
||||
|
||||
String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
|
||||
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
|
||||
throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
|
||||
}
|
||||
|
||||
if (project == rootProject) {
|
||||
// change the build dir used during build init, so that doing a clean
|
||||
// won't wipe out the buildscript jar
|
||||
|
@ -64,6 +70,11 @@ if (JavaVersion.current() < JavaVersion.VERSION_11) {
|
|||
sourceSets {
|
||||
// We have a few classes that need to be compiled for older java versions
|
||||
minimumRuntime {}
|
||||
|
||||
integTest {
|
||||
compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"]
|
||||
runtimeClasspath += output + compileClasspath
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
@ -117,8 +128,10 @@ dependencies {
|
|||
compile 'com.networknt:json-schema-validator:1.0.36'
|
||||
compileOnly "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
|
||||
testCompile "com.puppycrawl.tools:checkstyle:${props.getProperty('checkstyle')}"
|
||||
testCompile "junit:junit:${props.getProperty('junit')}"
|
||||
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
|
||||
testFixturesApi "junit:junit:${props.getProperty('junit')}"
|
||||
testFixturesApi "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
|
||||
testFixturesApi gradleApi()
|
||||
testFixturesApi gradleTestKit()
|
||||
testCompile 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
|
||||
testCompile 'org.mockito:mockito-core:1.9.5'
|
||||
minimumRuntimeCompile "junit:junit:${props.getProperty('junit')}"
|
||||
|
@ -165,10 +178,11 @@ if (project != rootProject) {
|
|||
// build-tools is not ready for primetime with these...
|
||||
dependencyLicenses.enabled = false
|
||||
dependenciesInfo.enabled = false
|
||||
disableTasks('forbiddenApisMain', 'forbiddenApisMinimumRuntime', 'forbiddenApisTest')
|
||||
disableTasks('forbiddenApisMain', 'forbiddenApisMinimumRuntime',
|
||||
'forbiddenApisTest', 'forbiddenApisIntegTest', 'forbiddenApisTestFixtures')
|
||||
jarHell.enabled = false
|
||||
thirdPartyAudit.enabled = false
|
||||
if (Boolean.parseBoolean(System.getProperty("tests.fips.enabled"))){
|
||||
if (Boolean.parseBoolean(System.getProperty("tests.fips.enabled"))) {
|
||||
test.enabled = false
|
||||
}
|
||||
|
||||
|
@ -237,6 +251,8 @@ if (project != rootProject) {
|
|||
systemProperty 'test.version_under_test', version
|
||||
onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false }
|
||||
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")
|
||||
|
||||
|
@ -252,6 +268,11 @@ if (project != rootProject) {
|
|||
afterEvaluate {
|
||||
generatePomFileForPluginMavenPublication.enabled = false
|
||||
}
|
||||
|
||||
publishing.publications.named("nebula").configure {
|
||||
suppressPomMetadataWarningsFor("testFixturesApiElements")
|
||||
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
* 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.
|
||||
* 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,
|
||||
* software distributed under the License is distributed on an
|
||||
|
@ -22,6 +16,13 @@ import org.junit.Before;
|
|||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
|
||||
@Before
|
||||
|
@ -41,6 +42,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
|||
"-PcompileVersion=0.0.1"
|
||||
).build();
|
||||
assertTaskNoSource(result, ":empty");
|
||||
assertNoDeprecationWarning(result);
|
||||
}
|
||||
|
||||
public void testWithEmptyRules() {
|
||||
|
@ -69,6 +71,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
|||
assertTaskFailed(result, ":absurd");
|
||||
assertOutputContains(result.getOutput(), "Classes with violations:", " * TestingIO", "> Audit of third party dependencies failed");
|
||||
assertOutputDoesNotContain(result.getOutput(), "Missing classes:");
|
||||
assertNoDeprecationWarning(result);
|
||||
}
|
||||
|
||||
public void testClassNotFoundAndCompileOnlyIgnored() {
|
||||
|
@ -90,6 +93,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
|||
"> Audit of third party dependencies failed"
|
||||
);
|
||||
assertOutputDoesNotContain(result.getOutput(), "Classes with violations:");
|
||||
assertNoDeprecationWarning(result);
|
||||
}
|
||||
|
||||
public void testJarHellWithJDK() {
|
||||
|
@ -111,6 +115,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
|||
" * java.lang.String"
|
||||
);
|
||||
assertOutputDoesNotContain(result.getOutput(), "Classes with violations:");
|
||||
assertNoDeprecationWarning(result);
|
||||
}
|
||||
|
||||
public void testElasticsearchIgnoredWithViolations() {
|
||||
|
@ -124,6 +129,7 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
|
|||
"-PcompileVersion=0.0.1"
|
||||
).build();
|
||||
assertTaskNoSource(result, ":absurd");
|
||||
assertNoDeprecationWarning(result);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.gradle
|
||||
|
||||
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin
|
||||
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
@ -27,15 +28,16 @@ import org.gradle.api.tasks.TaskProvider
|
|||
|
||||
class DependenciesInfoPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
void apply(Project project) {
|
||||
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
|
||||
TaskProvider<DependenciesInfoTask> depsInfo = project.getTasks().register("dependenciesInfo", DependenciesInfoTask.class);
|
||||
depsInfo.configure { DependenciesInfoTask t ->
|
||||
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") { ->
|
||||
TaskProvider<DependencyLicensesTask> depLic = project.getTasks().named("dependencyLicenses", DependencyLicensesTask.class);
|
||||
return depLic.get().getMappings();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.gradle.api.plugins.JavaPlugin;
|
|||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
import org.gradle.api.tasks.bundling.Jar;
|
||||
import org.gradle.api.tasks.compile.CompileOptions;
|
||||
import org.gradle.api.tasks.compile.GroovyCompile;
|
||||
|
@ -96,12 +97,12 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
|||
|
||||
/**
|
||||
* Makes dependencies non-transitive.
|
||||
*
|
||||
* <p>
|
||||
* Gradle allows setting all dependencies as non-transitive very easily.
|
||||
* 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,
|
||||
* we must exclude each transitive dependency of each direct dependency.
|
||||
*
|
||||
* <p>
|
||||
* Determining the transitive deps of a dependency which has been resolved as
|
||||
* non-transitive is difficult because the process of resolving removes the
|
||||
* transitive deps. To sidestep this issue, we create a configuration per
|
||||
|
@ -533,10 +534,6 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
|||
private static void configureJavadoc(Project project) {
|
||||
project.getTasks().withType(Javadoc.class).configureEach(javadoc -> {
|
||||
|
||||
// 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`
|
||||
* that the default will change to html5 in the future.
|
||||
|
@ -544,10 +541,15 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
|||
CoreJavadocOptions javadocOptions = (CoreJavadocOptions) javadoc.getOptions();
|
||||
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'
|
||||
project.getTasks()
|
||||
.named(LifecycleBasePlugin.CHECK_TASK_NAME)
|
||||
.configure(t -> t.dependsOn(project.getTasks().withType(Javadoc.class)));
|
||||
project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(t -> t.dependsOn(javadoc));
|
||||
}
|
||||
|
||||
static class TestFailureReportingPlugin implements Plugin<Project> {
|
||||
|
|
|
@ -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;
|
||||
|
||||
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
|
@ -29,13 +30,15 @@ public class DependencyLicensesPrecommitPlugin extends PrecommitPlugin {
|
|||
|
||||
@Override
|
||||
public TaskProvider<? extends Task> createTask(Project project) {
|
||||
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
|
||||
TaskProvider<DependencyLicensesTask> dependencyLicenses = project.getTasks()
|
||||
.register("dependencyLicenses", DependencyLicensesTask.class);
|
||||
|
||||
// only require dependency licenses for non-elasticsearch deps
|
||||
dependencyLicenses.configure(t -> {
|
||||
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(
|
||||
runtimeClasspath.fileCollection(dependency -> dependency.getGroup().startsWith("org.elasticsearch") == false)
|
||||
.minus(compileOnly)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.gradle.precommit;
|
||||
|
||||
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask;
|
||||
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
|
||||
import org.elasticsearch.gradle.info.BuildParams;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
|
@ -28,19 +29,20 @@ import org.gradle.api.tasks.TaskProvider;
|
|||
public class ThirdPartyAuditPrecommitPlugin extends PrecommitPlugin {
|
||||
@Override
|
||||
public TaskProvider<? extends Task> createTask(Project project) {
|
||||
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
|
||||
project.getConfigurations().create("forbiddenApisCliJar");
|
||||
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);
|
||||
audit.configure(t -> {
|
||||
t.dependsOn(buildResources);
|
||||
t.setSignatureFile(buildResources.get().copy("forbidden/third-party-audit.txt"));
|
||||
t.dependsOn("buildResources");
|
||||
t.setJavaHome(BuildParams.getRuntimeJavaHome().toString());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import de.thetaphi.forbiddenapis.cli.CliMain;
|
|||
import org.apache.commons.io.output.NullOutputStream;
|
||||
import org.elasticsearch.gradle.JdkJarHellCheck;
|
||||
import org.elasticsearch.gradle.OS;
|
||||
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.GradleException;
|
||||
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;
|
||||
Set<File> jars = getRuntimeConfiguration().getResolvedConfiguration().getFiles(reallyThirdParty);
|
||||
Set<File> compileOnlyConfiguration = getProject().getConfigurations()
|
||||
.getByName("compileOnly")
|
||||
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
|
||||
.getResolvedConfiguration()
|
||||
.getFiles(reallyThirdParty);
|
||||
// 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(
|
||||
getForbiddenAPIsConfiguration(),
|
||||
getRuntimeConfiguration(),
|
||||
getProject().getConfigurations().getByName("compileOnly")
|
||||
getProject().getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
|
||||
);
|
||||
spec.jvmArgs("-Xmx1g");
|
||||
spec.setMain("de.thetaphi.forbiddenapis.cli.CliMain");
|
||||
|
@ -364,7 +365,7 @@ public class ThirdPartyAuditTask extends DefaultTask {
|
|||
spec.classpath(
|
||||
location.toURI().getPath(),
|
||||
getRuntimeConfiguration(),
|
||||
getProject().getConfigurations().getByName("compileOnly")
|
||||
getProject().getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
|
||||
);
|
||||
} catch (URISyntaxException 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) {
|
||||
Path absPath = getBuildDir(projectName).toPath().resolve(path);
|
||||
assertTrue(
|
|
@ -1,11 +1,15 @@
|
|||
import org.elasticsearch.gradle.precommit.ThirdPartyAuditPrecommitPlugin
|
||||
import org.elasticsearch.gradle.precommit.ThirdPartyAuditTask
|
||||
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
// bring in build-tools onto the classpath
|
||||
id 'elasticsearch.global-build-info' apply false
|
||||
}
|
||||
|
||||
plugins.apply(ThirdPartyAuditPrecommitPlugin)
|
||||
|
||||
repositories {
|
||||
/**
|
||||
* Local test repo contains dummy jars with different group names and versions.
|
||||
|
@ -23,12 +27,10 @@ repositories {
|
|||
jcenter()
|
||||
}
|
||||
|
||||
configurations.register("forbiddenApisCliJar")
|
||||
|
||||
dependencies {
|
||||
forbiddenApisCliJar 'de.thetaphi:forbiddenapis:2.7'
|
||||
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) {
|
||||
|
|
|
@ -5,7 +5,7 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
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 ->
|
||||
|
|
Loading…
Reference in New Issue