diff --git a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/DistributionDownloadPluginFuncTest.groovy b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/DistributionDownloadPluginFuncTest.groovy index 0cf70a1845fca..d7648c860130e 100644 --- a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/DistributionDownloadPluginFuncTest.groovy +++ b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/DistributionDownloadPluginFuncTest.groovy @@ -20,7 +20,6 @@ package org.elasticsearch.gradle import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest -import org.elasticsearch.gradle.transform.SymbolicLinkPreservingUntarTransform import org.gradle.testkit.runner.TaskOutcome import spock.lang.Unroll @@ -61,17 +60,21 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest { """ when: - def runner = gradleRunner('clean', 'setupDistro', '-i') + def guh = new File(testProjectDir.getRoot(), "gradle-user-home").absolutePath; + def runner = gradleRunner('clean', 'setupDistro', '-i', '-g', guh) def result = withMockedDistributionDownload(version, platform, runner) { // initial run - build() + def firstRun = build() + assertOutputContains(firstRun.output, "Unpacking elasticsearch-${version}-linux-x86_64.tar.gz " + + "using SymbolicLinkPreservingUntarTransform") // 2nd invocation build() } then: result.task(":setupDistro").outcome == TaskOutcome.SUCCESS - assertOutputContains(result.output, "Skipping ${SymbolicLinkPreservingUntarTransform.class.simpleName}") + assertOutputMissing(result.output, "Unpacking elasticsearch-${version}-linux-x86_64.tar.gz " + + "using SymbolicLinkPreservingUntarTransform") } def "transforms are reused across projects"() { @@ -109,7 +112,7 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest { then: result.tasks.size() == 3 result.output.count("Unpacking elasticsearch-${version}-linux-x86_64.tar.gz " + - "using SymbolicLinkPreservingUntarTransform.") == 1 + "using SymbolicLinkPreservingUntarTransform") == 1 } private boolean assertExtractedDistroCreated(String relativePath) { diff --git a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/ElasticsearchJavaPluginFuncTest.groovy b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/ElasticsearchJavaPluginFuncTest.groovy index b13c0cc61dbf6..f104473278291 100644 --- a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/ElasticsearchJavaPluginFuncTest.groovy +++ b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/ElasticsearchJavaPluginFuncTest.groovy @@ -58,11 +58,4 @@ class ElasticsearchJavaPluginFuncTest extends AbstractGradleFuncTest { then: gradleRunner("help").build() } - - private File someJavaSource() { - file("src/main/java/org/acme/SomeClass.java") << """ - package org.acme; - public class SomeClass {} - """ - } } diff --git a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/JdkDownloadPluginFuncTest.groovy b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/JdkDownloadPluginFuncTest.groovy index 643f5c6eacbbd..804fe2ef350a2 100644 --- a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/JdkDownloadPluginFuncTest.groovy +++ b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/JdkDownloadPluginFuncTest.groovy @@ -135,7 +135,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest { then: result.tasks.size() == 3 - result.output.count("Unpacking linux-12.0.2-x64.tar.gz using ${SymbolicLinkPreservingUntarTransform.simpleName}.") == 1 + result.output.count("Unpacking linux-12.0.2-x64.tar.gz using ${SymbolicLinkPreservingUntarTransform.simpleName}") == 1 where: platform | jdkVendor | jdkVersion | expectedJavaBin @@ -177,18 +177,20 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest { def commonGradleUserHome = testProjectDir.newFolder().toString() // initial run - gradleRunner('clean', 'getJdk', '-g', commonGradleUserHome).build() + def firstResult = gradleRunner('clean', 'getJdk', '-i', '--warning-mode', 'all', '-g', commonGradleUserHome).build() + // assert the output of an executed transform is shown + assertOutputContains(firstResult.output, "Unpacking $expectedArchiveName using $transformType") // run against up-to-date transformations - gradleRunner('clean', 'getJdk', '-i', '-g', commonGradleUserHome).build() + gradleRunner('clean', 'getJdk', '-i', '--warning-mode', 'all', '-g', commonGradleUserHome).build() } then: - assertOutputContains(result.output, "Skipping $transformType") + normalized(result.output).contains("Unpacking $expectedArchiveName using $transformType") == false where: - platform | transformType - "linux" | SymbolicLinkPreservingUntarTransform.class.simpleName - "windows" | UnzipTransform.class.simpleName + platform | expectedArchiveName | transformType + "linux" | "linux-12.0.2-x64.tar.gz" | SymbolicLinkPreservingUntarTransform.class.simpleName + "windows" | "windows-12.0.2-x64.zip" | UnzipTransform.class.simpleName } static boolean assertExtraction(String output, String javaBin) { @@ -237,6 +239,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest { if(repo.name == "jdk_repo_${jdkVendor}_${jdkVersion}") { repo.setUrl('${server.baseUrl()}') } + allowInsecureProtocol = true } }""" } diff --git a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy index a0f1033e0a131..716ba3cb62b88 100644 --- a/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy +++ b/buildSrc/src/integTest/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy @@ -35,11 +35,14 @@ abstract class AbstractGradleFuncTest extends Specification { File settingsFile File buildFile + File propertiesFile def setup() { settingsFile = testProjectDir.newFile('settings.gradle') settingsFile << "rootProject.name = 'hello-world'\n" buildFile = testProjectDir.newFile('build.gradle') + propertiesFile = testProjectDir.newFile('gradle.properties') + propertiesFile << "org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME" } GradleRunner gradleRunner(String... arguments) { @@ -60,6 +63,10 @@ abstract class AbstractGradleFuncTest extends Specification { true } + def assertOutputMissing(String givenOutput, String expected) { + assert normalized(givenOutput).contains(normalized(expected)) == false + true + } String normalized(String input) { String normalizedPathPrefix = testProjectDir.root.canonicalPath.replace('\\', '/') return input.readLines() diff --git a/buildSrc/src/integTest/java/org/elasticsearch/gradle/BuildPluginIT.java b/buildSrc/src/integTest/java/org/elasticsearch/gradle/BuildPluginIT.java index 3097a738446f1..2000f61fbc32c 100644 --- a/buildSrc/src/integTest/java/org/elasticsearch/gradle/BuildPluginIT.java +++ b/buildSrc/src/integTest/java/org/elasticsearch/gradle/BuildPluginIT.java @@ -105,7 +105,9 @@ private void runInsecureArtifactRepositoryTest(final String name, final String u .withProjectDir(tmpDir.getRoot()) .withArguments("clean", "hello", "-s", "-i", "--warning-mode=all", "--scan") .withPluginClasspath() + .forwardOutput() .buildAndFail(); + assertOutputContains( result.getOutput(), "repository [" + name + "] on project with path [:] is not using a secure protocol for artifacts on [" + url + "]" diff --git a/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/TestingConventionsTasksIT.java b/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/TestingConventionsTasksIT.java index 1ac206b2a5d36..374dfe40991bc 100644 --- a/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/TestingConventionsTasksIT.java +++ b/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/TestingConventionsTasksIT.java @@ -62,7 +62,7 @@ public void testNamingConvention() { " * org.elasticsearch.gradle.testkit.LooksLikeATestWithoutNamingConvention2", " * org.elasticsearch.gradle.testkit.LooksLikeATestWithoutNamingConvention3" ); - assertOutputDoesNotContain(result.getOutput(), "LooksLikeTestsButAbstract"); + assertOutputMissing(result.getOutput(), "LooksLikeTestsButAbstract"); } public void testNoEmptyTasks() { diff --git a/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTaskIT.java b/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTaskIT.java index e9431bbb3badc..2359cdf97ebd1 100644 --- a/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTaskIT.java +++ b/buildSrc/src/integTest/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTaskIT.java @@ -74,7 +74,7 @@ public void testViolationFoundAndCompileOnlyIgnored() { assertTaskFailed(result, ":absurd"); assertOutputContains(result.getOutput(), "Classes with violations:", " * TestingIO", "> Audit of third party dependencies failed"); - assertOutputDoesNotContain(result.getOutput(), "Missing classes:"); + assertOutputMissing(result.getOutput(), "Missing classes:"); assertNoDeprecationWarning(result); } @@ -96,7 +96,7 @@ public void testClassNotFoundAndCompileOnlyIgnored() { " * org.apache.logging.log4j.LogManager", "> Audit of third party dependencies failed" ); - assertOutputDoesNotContain(result.getOutput(), "Classes with violations:"); + assertOutputMissing(result.getOutput(), "Classes with violations:"); assertNoDeprecationWarning(result); } @@ -118,7 +118,7 @@ public void testJarHellWithJDK() { " Jar Hell with the JDK:", " * java.lang.String" ); - assertOutputDoesNotContain(result.getOutput(), "Classes with violations:"); + assertOutputMissing(result.getOutput(), "Classes with violations:"); assertNoDeprecationWarning(result); } diff --git a/buildSrc/src/integTest/resources/org/elasticsearch/gradle/internal/fake_git/remote/gradle.properties b/buildSrc/src/integTest/resources/org/elasticsearch/gradle/internal/fake_git/remote/gradle.properties index 6761776ee0ce4..8d6d05f0c768e 100644 --- a/buildSrc/src/integTest/resources/org/elasticsearch/gradle/internal/fake_git/remote/gradle.properties +++ b/buildSrc/src/integTest/resources/org/elasticsearch/gradle/internal/fake_git/remote/gradle.properties @@ -19,4 +19,7 @@ # forcing to use TLS1.2 to avoid failure in vault # see https://github.com/hashicorp/vault/issues/8750#issuecomment-631236121 -systemProp.jdk.tls.client.protocols=TLSv1.2 \ No newline at end of file +systemProp.jdk.tls.client.protocols=TLSv1.2 + +# java homes resolved by environment variables +org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java index 1478c0d78f355..482e622e480c3 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java @@ -28,12 +28,12 @@ import org.gradle.api.Project; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; -import org.gradle.api.model.ObjectFactory; -import org.gradle.api.provider.Provider; import org.gradle.api.provider.ProviderFactory; import org.gradle.internal.jvm.Jvm; -import org.gradle.jvm.toolchain.JavaInstallation; -import org.gradle.jvm.toolchain.JavaInstallationRegistry; +import org.gradle.internal.jvm.inspection.JvmInstallationMetadata; +import org.gradle.internal.jvm.inspection.JvmMetadataDetector; +import org.gradle.jvm.toolchain.internal.InstallationLocation; +import org.gradle.jvm.toolchain.internal.SharedJavaInstallationRegistry; import org.gradle.util.GradleVersion; import javax.inject.Inject; @@ -50,7 +50,6 @@ import java.nio.file.Paths; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; @@ -68,14 +67,18 @@ public class GlobalBuildInfoPlugin implements Plugin { private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java"; private static Integer _defaultParallel = null; - private final JavaInstallationRegistry javaInstallationRegistry; - private final ObjectFactory objects; + private final SharedJavaInstallationRegistry javaInstallationRegistry; + private final JvmMetadataDetector metadataDetector; private final ProviderFactory providers; @Inject - public GlobalBuildInfoPlugin(JavaInstallationRegistry javaInstallationRegistry, ObjectFactory objects, ProviderFactory providers) { + public GlobalBuildInfoPlugin( + SharedJavaInstallationRegistry javaInstallationRegistry, + JvmMetadataDetector metadataDetector, + ProviderFactory providers + ) { this.javaInstallationRegistry = javaInstallationRegistry; - this.objects = objects; + this.metadataDetector = metadataDetector; this.providers = providers; } @@ -105,8 +108,8 @@ public void apply(Project project) { params.setRuntimeJavaHome(runtimeJavaHome); params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion)); params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false); - params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getImplementationName()); - params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion)); + params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getDisplayName()); + params.setJavaVersions(getAvailableJavaVersions()); params.setMinimumCompilerVersion(minimumCompilerVersion); params.setMinimumRuntimeVersion(minimumRuntimeVersion); params.setGradleJavaVersion(Jvm.current().getJavaVersion()); @@ -146,20 +149,22 @@ private void logGlobalBuildInfo() { final String osVersion = System.getProperty("os.version"); final String osArch = System.getProperty("os.arch"); final Jvm gradleJvm = Jvm.current(); - final String gradleJvmDetails = getJavaInstallation(gradleJvm.getJavaHome()).getImplementationName(); - + JvmInstallationMetadata gradleJvmMetadata = metadataDetector.getMetadata(gradleJvm.getJavaHome()); + final String gradleJvmVendorDetails = gradleJvmMetadata.getVendor().getDisplayName(); LOGGER.quiet("======================================="); LOGGER.quiet("Elasticsearch Build Hamster says Hello!"); LOGGER.quiet(" Gradle Version : " + GradleVersion.current().getVersion()); LOGGER.quiet(" OS Info : " + osName + " " + osVersion + " (" + osArch + ")"); if (BuildParams.getIsRuntimeJavaHomeSet()) { - String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getImplementationName(); - LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmDetails + ")"); + final String runtimeJvmVendorDetails = metadataDetector.getMetadata(BuildParams.getRuntimeJavaHome()) + .getVendor() + .getDisplayName(); + LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmVendorDetails + ")"); LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome()); - LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")"); + LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmVendorDetails + ")"); LOGGER.quiet(" Gradle java.home : " + gradleJvm.getJavaHome()); } else { - LOGGER.quiet(" JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")"); + LOGGER.quiet(" JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmVendorDetails + ")"); LOGGER.quiet(" JAVA_HOME : " + gradleJvm.getJavaHome()); } LOGGER.quiet(" Random Testing Seed : " + BuildParams.getTestSeed()); @@ -168,8 +173,8 @@ private void logGlobalBuildInfo() { } private JavaVersion determineJavaVersion(String description, File javaHome, JavaVersion requiredVersion) { - JavaInstallation installation = getJavaInstallation(javaHome); - JavaVersion actualVersion = installation.getJavaVersion(); + InstallationLocation installation = getJavaInstallation(javaHome); + JavaVersion actualVersion = metadataDetector.getMetadata(installation.getLocation()).getLanguageVersion(); if (actualVersion.isCompatibleWith(requiredVersion) == false) { throwInvalidJavaHomeException( description, @@ -182,46 +187,33 @@ private JavaVersion determineJavaVersion(String description, File javaHome, Java return actualVersion; } - private JavaInstallation getJavaInstallation(File javaHome) { - JavaInstallation installation; - if (isCurrentJavaHome(javaHome)) { - installation = javaInstallationRegistry.getInstallationForCurrentVirtualMachine().get(); - } else { - installation = javaInstallationRegistry.installationForDirectory(objects.directoryProperty().fileValue(javaHome)).get(); - } - - return installation; + private InstallationLocation getJavaInstallation(File javaHome) { + return javaInstallationRegistry.listInstallations() + .stream() + .filter(installationLocation -> isSameFile(javaHome, installationLocation)) + .findFirst() + .get(); } - private List getAvailableJavaVersions(JavaVersion minimumCompilerVersion) { - final List javaVersions = new ArrayList<>(); - for (int v = 8; v <= Integer.parseInt(minimumCompilerVersion.getMajorVersion()); v++) { - int version = v; - String javaHomeEnvVarName = getJavaHomeEnvVarName(Integer.toString(version)); - if (System.getenv(javaHomeEnvVarName) != null) { - File javaHomeDirectory = new File(findJavaHome(Integer.toString(version))); - Provider javaInstallationProvider = javaInstallationRegistry.installationForDirectory( - objects.directoryProperty().fileValue(javaHomeDirectory) - ); - JavaHome javaHome = JavaHome.of(version, providers.provider(() -> { - int actualVersion = Integer.parseInt(javaInstallationProvider.get().getJavaVersion().getMajorVersion()); - if (actualVersion != version) { - throwInvalidJavaHomeException("env variable " + javaHomeEnvVarName, javaHomeDirectory, version, actualVersion); - } - return javaHomeDirectory; - })); - javaVersions.add(javaHome); - } + private boolean isSameFile(File javaHome, InstallationLocation installationLocation) { + try { + return Files.isSameFile(installationLocation.getLocation().toPath(), javaHome.toPath()); + } catch (IOException ioException) { + throw new UncheckedIOException(ioException); } - return javaVersions; } - private static boolean isCurrentJavaHome(File javaHome) { - try { - return Files.isSameFile(javaHome.toPath(), Jvm.current().getJavaHome().toPath()); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + /** + * We resolve all available java versions using auto detected by gradles tool chain + * To make transition more reliable we only take env var provided installations into account for now + */ + private List getAvailableJavaVersions() { + return javaInstallationRegistry.listInstallations().stream().map(installationLocation -> { + File installationDir = installationLocation.getLocation(); + JvmInstallationMetadata metadata = metadataDetector.getMetadata(installationDir); + int actualVersion = Integer.parseInt(metadata.getLanguageVersion().getMajorVersion()); + return JavaHome.of(actualVersion, providers.provider(() -> installationDir)); + }).collect(Collectors.toList()); } private static String getTestSeed() { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/JarHellPrecommitPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/JarHellPrecommitPlugin.java index 6cb5dd7f7a2a5..33f7b3a265e82 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/JarHellPrecommitPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/JarHellPrecommitPlugin.java @@ -32,6 +32,9 @@ public class JarHellPrecommitPlugin extends PrecommitPlugin { public TaskProvider createTask(Project project) { Configuration jarHellConfig = project.getConfigurations().create("jarHell"); if (BuildParams.isInternal() && project.getPath().equals(":libs:elasticsearch-core") == false) { + // ideally we would configure this as a default dependency. But Default dependencies do not work correctly + // with gradle project dependencies as they're resolved to late in the build and don't setup according task + // dependencies properly project.getDependencies().add("jarHell", project.project(":libs:elasticsearch-core")); } TaskProvider jarHell = project.getTasks().register("jarHell", JarHellTask.class); diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/transform/SymbolicLinkPreservingUntarTransform.java b/buildSrc/src/main/java/org/elasticsearch/gradle/transform/SymbolicLinkPreservingUntarTransform.java index 95cf2108766fb..5c6e7b4cb7ff0 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/transform/SymbolicLinkPreservingUntarTransform.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/transform/SymbolicLinkPreservingUntarTransform.java @@ -22,7 +22,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; -import org.gradle.api.logging.Logging; import java.io.File; import java.io.FileInputStream; @@ -40,8 +39,6 @@ public abstract class SymbolicLinkPreservingUntarTransform implements UnpackTran private static final Path CURRENT_DIR_PATH = Paths.get("."); public void unpack(File tarFile, File targetDir) throws IOException { - Logging.getLogger(SymbolicLinkPreservingUntarTransform.class) - .info("Unpacking " + tarFile.getName() + " using " + SymbolicLinkPreservingUntarTransform.class.getSimpleName() + "."); Function pathModifier = pathResolver(); TarArchiveInputStream tar = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarFile))); diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/transform/UnpackTransform.java b/buildSrc/src/main/java/org/elasticsearch/gradle/transform/UnpackTransform.java index 5994fdb2374ee..742ebc0b6803f 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/transform/UnpackTransform.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/transform/UnpackTransform.java @@ -24,6 +24,7 @@ import org.gradle.api.artifacts.transform.TransformOutputs; import org.gradle.api.artifacts.transform.TransformParameters; import org.gradle.api.file.FileSystemLocation; +import org.gradle.api.logging.Logging; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Optional; @@ -56,6 +57,8 @@ default void transform(TransformOutputs outputs) { File archiveFile = getArchiveFile().get().getAsFile(); File extractedDir = outputs.dir(archiveFile.getName()); try { + Logging.getLogger(UnpackTransform.class) + .info("Unpacking " + archiveFile.getName() + " using " + getClass().getSimpleName() + "."); unpack(archiveFile, extractedDir); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); diff --git a/buildSrc/src/main/resources/minimumGradleVersion b/buildSrc/src/main/resources/minimumGradleVersion index ba92e72f5775b..8004d903c33d8 100644 --- a/buildSrc/src/main/resources/minimumGradleVersion +++ b/buildSrc/src/main/resources/minimumGradleVersion @@ -1 +1 @@ -6.6.1 \ No newline at end of file +6.8 \ No newline at end of file diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginBuildPluginTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginBuildPluginTests.java deleted file mode 100644 index 1ec0ad93dfa45..0000000000000 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/plugin/PluginBuildPluginTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.plugin; - -import org.elasticsearch.gradle.BwcVersions; -import org.elasticsearch.gradle.test.GradleUnitTestCase; -import org.gradle.api.Project; -import org.gradle.api.Task; -import org.gradle.api.internal.project.ProjectInternal; -import org.gradle.testfixtures.ProjectBuilder; -import org.junit.Before; -import org.junit.Ignore; -import org.mockito.Mockito; - -import java.util.stream.Collectors; - -public class PluginBuildPluginTests extends GradleUnitTestCase { - - private Project project; - - @Before - public void setUp() throws Exception { - project = ProjectBuilder.builder().withName(getClass().getName()).build(); - } - - public void testApply() { - // FIXME: distribution download plugin doesn't support running externally - project.getExtensions().getExtraProperties().set("bwcVersions", Mockito.mock(BwcVersions.class)); - project.getPlugins().apply(PluginBuildPlugin.class); - - assertNotNull( - "plugin extension created with the right name", - project.getExtensions().findByName(PluginBuildPlugin.PLUGIN_EXTENSION_NAME) - ); - assertNotNull("plugin extensions has the right type", project.getExtensions().findByType(PluginPropertiesExtension.class)); - - assertNull("plugin should not create the integTest task", project.getTasks().findByName("integTest")); - } - - @Ignore("https://github.com/elastic/elasticsearch/issues/47123") - public void testApplyWithAfterEvaluate() { - project.getExtensions().getExtraProperties().set("bwcVersions", Mockito.mock(BwcVersions.class)); - project.getPlugins().apply(PluginBuildPlugin.class); - PluginPropertiesExtension extension = project.getExtensions().getByType(PluginPropertiesExtension.class); - extension.setNoticeFile(project.file("test.notice")); - extension.setLicenseFile(project.file("test.license")); - extension.setDescription("just a test"); - extension.setClassname(getClass().getName()); - - ((ProjectInternal) project).evaluate(); - - assertNotNull( - "Task to generate notice not created: " + project.getTasks().stream().map(Task::getPath).collect(Collectors.joining(", ")), - project.getTasks().findByName("generateNotice") - ); - } -} diff --git a/buildSrc/src/testFixtures/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java b/buildSrc/src/testFixtures/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java index 6c0a763745b42..2f8c8e82dde2c 100644 --- a/buildSrc/src/testFixtures/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java +++ b/buildSrc/src/testFixtures/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java @@ -99,13 +99,13 @@ protected void assertOutputContains(String output, String line) { assertThat("Expected the following line in output:\n\n" + line + "\n\nOutput is:\n" + output, output, containsString(line)); } - protected void assertOutputDoesNotContain(String output, String line) { + protected void assertOutputMissing(String output, String line) { assertFalse("Expected the following line not to be in output:\n\n" + line + "\n\nOutput is:\n" + output, output.contains(line)); } - protected void assertOutputDoesNotContain(String output, String... lines) { + protected void assertOutputMissing(String output, String... lines) { for (String line : lines) { - assertOutputDoesNotContain(line); + assertOutputMissing(line); } } @@ -167,7 +167,7 @@ protected void assertTaskUpToDate(BuildResult result, String... taskNames) { } protected void assertNoDeprecationWarning(BuildResult result) { - assertOutputDoesNotContain(result.getOutput(), "Deprecated Gradle features were used in this build"); + assertOutputMissing(result.getOutput(), "Deprecated Gradle features were used in this build"); } protected void assertBuildFileExists(BuildResult result, String projectName, String path) { diff --git a/buildSrc/src/testKit/elasticsearch-build-resources/gradle.properties b/buildSrc/src/testKit/elasticsearch-build-resources/gradle.properties new file mode 100644 index 0000000000000..60d628bb36ffc --- /dev/null +++ b/buildSrc/src/testKit/elasticsearch-build-resources/gradle.properties @@ -0,0 +1,22 @@ +# +# 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. +# + +# java homes resolved by environment variables +org.gradle.java.installations.auto-detect=false +org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME \ No newline at end of file diff --git a/buildSrc/src/testKit/elasticsearch.build/gradle.properties b/buildSrc/src/testKit/elasticsearch.build/gradle.properties new file mode 100644 index 0000000000000..60d628bb36ffc --- /dev/null +++ b/buildSrc/src/testKit/elasticsearch.build/gradle.properties @@ -0,0 +1,22 @@ +# +# 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. +# + +# java homes resolved by environment variables +org.gradle.java.installations.auto-detect=false +org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME \ No newline at end of file diff --git a/buildSrc/src/testKit/reaper/gradle.properties b/buildSrc/src/testKit/reaper/gradle.properties new file mode 100644 index 0000000000000..689e43304173e --- /dev/null +++ b/buildSrc/src/testKit/reaper/gradle.properties @@ -0,0 +1,22 @@ +# +# 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. +# + +# java homes resolved by environment variables +org.gradle.java.installations.auto-detect=false +org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME diff --git a/buildSrc/src/testKit/thirdPartyAudit/gradle.properties b/buildSrc/src/testKit/thirdPartyAudit/gradle.properties new file mode 100644 index 0000000000000..689e43304173e --- /dev/null +++ b/buildSrc/src/testKit/thirdPartyAudit/gradle.properties @@ -0,0 +1,22 @@ +# +# 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. +# + +# java homes resolved by environment variables +org.gradle.java.installations.auto-detect=false +org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME diff --git a/gradle.properties b/gradle.properties index 479f71390fa93..f884f0194bada 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,3 +12,7 @@ systemProp.org.gradle.warning.mode=fail # forcing to use TLS1.2 to avoid failure in vault # see https://github.com/hashicorp/vault/issues/8750#issuecomment-631236121 systemProp.jdk.tls.client.protocols=TLSv1.2 + +# java homes resolved by environment variables +org.gradle.java.installations.auto-detect=false +org.gradle.java.installations.fromEnv=JAVA_HOME,RUNTIME_JAVA_HOME,JAVA15_HOME,JAVA14_HOME,JAVA13_HOME,JAVA12_HOME,JAVA11_HOME,JAVA8_HOME diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c2d86efbc66d..b0ec4f40f948c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=11657af6356b7587bfb37287b5992e94a9686d5c8a0a1b60b87b9928a2decde5 +distributionSha256Sum=a7ca23b3ccf265680f2bfd35f1f00b1424f4466292c7337c85d46c9641b3f053