Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Support Gradle 7 (#1609) (#1622)" #1657

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ allprojects {
}
}
boolean hasShadow = project.plugins.hasPlugin(ShadowPlugin)
project.configurations.implementation.dependencies
project.configurations.compile.dependencies
.findAll()
.toSorted(sortClosure)
.each({ c -> depJavadocClosure(hasShadow, c) })
Expand Down Expand Up @@ -422,12 +422,6 @@ allprojects {
tasks.named('cleanEclipse') { dependsOn 'wipeEclipseSettings' }
// otherwise the eclipse merging is *super confusing*
tasks.named('eclipse') { dependsOn 'cleanEclipse', 'copyEclipseSettings' }

afterEvaluate {
tasks.findByName("eclipseJdt")?.configure {
dependsOn 'copyEclipseSettings'
}
}
}

wrapper {
Expand Down
8 changes: 2 additions & 6 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ tasks.withType(JavaCompile).configureEach {
*****************************************************************************/

repositories {
mavenCentral()
gradlePluginPortal()
jcenter()
}

dependencies {
Expand Down Expand Up @@ -124,7 +123,7 @@ dependencies {
testFixturesApi gradleTestKit()
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.23.2'
testImplementation "org.mockito:mockito-core:${props.getProperty('mockito')}"
integTestImplementation('org.spockframework:spock-core:2.0-groovy-3.0') {
integTestImplementation('org.spockframework:spock-core:1.3-groovy-2.5') {
exclude module: "groovy"
}
}
Expand Down Expand Up @@ -260,9 +259,6 @@ if (project != rootProject) {
*/
afterEvaluate {
generatePomFileForPluginMavenPublication.enabled = false
tasks.matching { it.name.contains("PluginMaven") }*.configure {
dependsOn("generatePomFileForNebulaPublication")
}
}

publishing.publications.named("nebula").configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public LoggedExec(FileSystemOperations fileSystemOperations) {
doLast(new Action<Task>() {
@Override
public void execute(Task task) {
if (LoggedExec.this.getExecutionResult().get().getExitValue() != 0) {
if (LoggedExec.this.getExecResult().getExitValue() != 0) {
try {
LoggedExec.this.getLogger().error("Output for " + LoggedExec.this.getExecutable() + ":");
outputLogger.accept(LoggedExec.this.getLogger());
Expand All @@ -94,7 +94,7 @@ public void execute(Task task) {
"Process '%s %s' finished with non-zero exit value %d",
LoggedExec.this.getExecutable(),
LoggedExec.this.getArgs(),
LoggedExec.this.getExecutionResult().get().getExitValue()
LoggedExec.this.getExecResult().getExitValue()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void apply(Project project) {
File heapdumpDir = new File(project.getBuildDir(), "heapdump");

project.getTasks().withType(Test.class).configureEach(test -> {
File testOutputDir = new File(test.getReports().getJunitXml().getOutputLocation().getAsFile().get(), "output");
File testOutputDir = new File(test.getReports().getJunitXml().getDestination(), "output");

ErrorReportingTestListener listener = new ErrorReportingTestListener(test.getTestLogging(), test.getLogger(), testOutputDir);
test.getExtensions().add("errorReportingTestListener", listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void configureRepositories(Project project) {
// such that we don't have to pass hardcoded files to gradle
repos.mavenLocal();
}
repos.mavenCentral();
repos.jcenter();

String luceneVersion = VersionProperties.getLucene();
if (luceneVersion.contains("-snapshot")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
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.internal.jvm.inspection.JvmInstallationMetadata;
import org.gradle.internal.jvm.inspection.JvmMetadataDetector;
import org.gradle.jvm.toolchain.JavaInstallation;
import org.gradle.jvm.toolchain.JavaInstallationRegistry;
import org.gradle.util.GradleVersion;

import javax.inject.Inject;
Expand Down Expand Up @@ -76,13 +77,13 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/Version.java";
private static Integer _defaultParallel = null;

private final JvmMetadataDetector jvmMetadataDetector;
private final JavaInstallationRegistry javaInstallationRegistry;
private final ObjectFactory objects;
private final ProviderFactory providers;

@Inject
public GlobalBuildInfoPlugin(JvmMetadataDetector jvmMetadataDetector, ObjectFactory objects, ProviderFactory providers) {
this.jvmMetadataDetector = jvmMetadataDetector;
public GlobalBuildInfoPlugin(JavaInstallationRegistry javaInstallationRegistry, ObjectFactory objects, ProviderFactory providers) {
this.javaInstallationRegistry = javaInstallationRegistry;
this.objects = objects;
this.providers = providers;
}
Expand Down Expand Up @@ -114,7 +115,7 @@ public void apply(Project project) {
params.setRuntimeJavaHome(runtimeJavaHome);
params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion));
params.setIsRutimeJavaHomeSet(runtimeJavaHomeOpt.isPresent());
params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getDisplayName());
params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getImplementationName());
params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion));
params.setMinimumCompilerVersion(minimumCompilerVersion);
params.setMinimumRuntimeVersion(minimumRuntimeVersion);
Expand Down Expand Up @@ -159,14 +160,14 @@ 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()).getDisplayName();
final String gradleJvmDetails = getJavaInstallation(gradleJvm.getJavaHome()).getImplementationName();

LOGGER.quiet("=======================================");
LOGGER.quiet("OpenSearch 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()).getDisplayName();
String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getImplementationName();
LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmDetails + ")");
LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome());
LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")");
Expand All @@ -181,8 +182,8 @@ private void logGlobalBuildInfo() {
}

private JavaVersion determineJavaVersion(String description, File javaHome, JavaVersion requiredVersion) {
JvmInstallationMetadata installation = getJavaInstallation(javaHome);
JavaVersion actualVersion = installation.getLanguageVersion();
JavaInstallation installation = getJavaInstallation(javaHome);
JavaVersion actualVersion = installation.getJavaVersion();
if (actualVersion.isCompatibleWith(requiredVersion) == false) {
throwInvalidJavaHomeException(
description,
Expand All @@ -195,8 +196,15 @@ private JavaVersion determineJavaVersion(String description, File javaHome, Java
return actualVersion;
}

private JvmInstallationMetadata getJavaInstallation(File javaHome) {
return jvmMetadataDetector.getMetadata(javaHome);
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 List<JavaHome> getAvailableJavaVersions(JavaVersion minimumCompilerVersion) {
Expand All @@ -206,9 +214,11 @@ private List<JavaHome> getAvailableJavaVersions(JavaVersion minimumCompilerVersi
String javaHomeEnvVarName = getJavaHomeEnvVarName(Integer.toString(version));
if (System.getenv(javaHomeEnvVarName) != null) {
File javaHomeDirectory = new File(findJavaHome(Integer.toString(version)));
JvmInstallationMetadata javaInstallation = jvmMetadataDetector.getMetadata(javaHomeDirectory);
Provider<JavaInstallation> javaInstallationProvider = javaInstallationRegistry.installationForDirectory(
objects.directoryProperty().fileValue(javaHomeDirectory)
);
JavaHome javaHome = JavaHome.of(version, providers.provider(() -> {
int actualVersion = Integer.parseInt(javaInstallation.getLanguageVersion().getMajorVersion());
int actualVersion = Integer.parseInt(javaInstallationProvider.get().getJavaVersion().getMajorVersion());
if (actualVersion != version) {
throwInvalidJavaHomeException("env variable " + javaHomeEnvVarName, javaHomeDirectory, version, actualVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskProvider;
Expand Down Expand Up @@ -81,83 +80,77 @@ TaskProvider<LoggedExec> bwcTask(String name, Action<LoggedExec> configuration)
}

private TaskProvider<LoggedExec> createRunBwcGradleTask(Project project, String name, Action<LoggedExec> configAction) {
return project.getTasks().register(name, LoggedExec.class, new Action<LoggedExec>() {
@Override
public void execute(LoggedExec loggedExec) {
// TODO revisit
loggedExec.dependsOn("checkoutBwcBranch");
loggedExec.setSpoolOutput(true);
loggedExec.setWorkingDir(checkoutDir.get());
loggedExec.doFirst(new Action<Task>() {
@Override
public void execute(Task t) {
// Execution time so that the checkouts are available
String javaVersionsString = readFromFile(new File(checkoutDir.get(), ".ci/java-versions.properties"));
loggedExec.environment(
"JAVA_HOME",
getJavaHome(
Integer.parseInt(
Arrays.asList(javaVersionsString.split("\n"))
.stream()
.filter(l -> l.trim().startsWith("OPENSEARCH_BUILD_JAVA="))
.map(l -> l.replace("OPENSEARCH_BUILD_JAVA=java", "").trim())
.map(l -> l.replace("OPENSEARCH_BUILD_JAVA=openjdk", "").trim())
.collect(Collectors.joining("!!"))
)
)
);
loggedExec.environment(
"RUNTIME_JAVA_HOME",
getJavaHome(
Integer.parseInt(
Arrays.asList(javaVersionsString.split("\n"))
.stream()
.filter(l -> l.trim().startsWith("OPENSEARCH_RUNTIME_JAVA="))
.map(l -> l.replace("OPENSEARCH_RUNTIME_JAVA=java", "").trim())
.map(l -> l.replace("OPENSEARCH_RUNTIME_JAVA=openjdk", "").trim())
.collect(Collectors.joining("!!"))
)
)
);
}
});

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
loggedExec.executable("cmd");
loggedExec.args("/C", "call", new File(checkoutDir.get(), "gradlew").toString());
} else {
loggedExec.executable(new File(checkoutDir.get(), "gradlew").toString());
}
if (project.getGradle().getStartParameter().isOffline()) {
loggedExec.args("--offline");
}
// TODO resolve
String buildCacheUrl = System.getProperty("org.opensearch.build.cache.url");
if (buildCacheUrl != null) {
loggedExec.args("-Dorg.opensearch.build.cache.url=" + buildCacheUrl);
}
return project.getTasks().register(name, LoggedExec.class, loggedExec -> {
// TODO revisit
loggedExec.dependsOn("checkoutBwcBranch");
loggedExec.setSpoolOutput(true);
loggedExec.setWorkingDir(checkoutDir.get());
loggedExec.doFirst(t -> {
// Execution time so that the checkouts are available
String javaVersionsString = readFromFile(new File(checkoutDir.get(), ".ci/java-versions.properties"));
loggedExec.environment(
"JAVA_HOME",
getJavaHome(
Integer.parseInt(
Arrays.asList(javaVersionsString.split("\n"))
.stream()
.filter(l -> l.trim().startsWith("OPENSEARCH_BUILD_JAVA="))
.map(l -> l.replace("OPENSEARCH_BUILD_JAVA=java", "").trim())
.map(l -> l.replace("OPENSEARCH_BUILD_JAVA=openjdk", "").trim())
.collect(Collectors.joining("!!"))
)
)
);
loggedExec.environment(
"RUNTIME_JAVA_HOME",
getJavaHome(
Integer.parseInt(
Arrays.asList(javaVersionsString.split("\n"))
.stream()
.filter(l -> l.trim().startsWith("OPENSEARCH_RUNTIME_JAVA="))
.map(l -> l.replace("OPENSEARCH_RUNTIME_JAVA=java", "").trim())
.map(l -> l.replace("OPENSEARCH_RUNTIME_JAVA=openjdk", "").trim())
.collect(Collectors.joining("!!"))
)
)
);
});

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
loggedExec.executable("cmd");
loggedExec.args("/C", "call", new File(checkoutDir.get(), "gradlew").toString());
} else {
loggedExec.executable(new File(checkoutDir.get(), "gradlew").toString());
}
if (project.getGradle().getStartParameter().isOffline()) {
loggedExec.args("--offline");
}
// TODO resolve
String buildCacheUrl = System.getProperty("org.opensearch.build.cache.url");
if (buildCacheUrl != null) {
loggedExec.args("-Dorg.opensearch.build.cache.url=" + buildCacheUrl);
}

loggedExec.args("-Dbuild.snapshot=true");
loggedExec.args("-Dscan.tag.NESTED");
final LogLevel logLevel = project.getGradle().getStartParameter().getLogLevel();
List<LogLevel> nonDefaultLogLevels = Arrays.asList(LogLevel.QUIET, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG);
if (nonDefaultLogLevels.contains(logLevel)) {
loggedExec.args("--" + logLevel.name().toLowerCase(Locale.ENGLISH));
}
final String showStacktraceName = project.getGradle().getStartParameter().getShowStacktrace().name();
assert Arrays.asList("INTERNAL_EXCEPTIONS", "ALWAYS", "ALWAYS_FULL").contains(showStacktraceName);
if (showStacktraceName.equals("ALWAYS")) {
loggedExec.args("--stacktrace");
} else if (showStacktraceName.equals("ALWAYS_FULL")) {
loggedExec.args("--full-stacktrace");
}
if (project.getGradle().getStartParameter().isParallelProjectExecutionEnabled()) {
loggedExec.args("--parallel");
}
loggedExec.setStandardOutput(new IndentingOutputStream(System.out, unreleasedVersionInfo.get().version));
loggedExec.setErrorOutput(new IndentingOutputStream(System.err, unreleasedVersionInfo.get().version));
configAction.execute(loggedExec);
loggedExec.args("-Dbuild.snapshot=true");
loggedExec.args("-Dscan.tag.NESTED");
final LogLevel logLevel = project.getGradle().getStartParameter().getLogLevel();
List<LogLevel> nonDefaultLogLevels = Arrays.asList(LogLevel.QUIET, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG);
if (nonDefaultLogLevels.contains(logLevel)) {
loggedExec.args("--" + logLevel.name().toLowerCase(Locale.ENGLISH));
}
final String showStacktraceName = project.getGradle().getStartParameter().getShowStacktrace().name();
assert Arrays.asList("INTERNAL_EXCEPTIONS", "ALWAYS", "ALWAYS_FULL").contains(showStacktraceName);
if (showStacktraceName.equals("ALWAYS")) {
loggedExec.args("--stacktrace");
} else if (showStacktraceName.equals("ALWAYS_FULL")) {
loggedExec.args("--full-stacktrace");
}
if (project.getGradle().getStartParameter().isParallelProjectExecutionEnabled()) {
loggedExec.args("--parallel");
}
loggedExec.setStandardOutput(new IndentingOutputStream(System.out, unreleasedVersionInfo.get().version));
loggedExec.setErrorOutput(new IndentingOutputStream(System.err, unreleasedVersionInfo.get().version));
configAction.execute(loggedExec);
});
}

Expand Down
Loading