Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta authored Dec 3, 2021
1 parent df25ea3 commit 93bd32b
Show file tree
Hide file tree
Showing 30 changed files with 303 additions and 217 deletions.
8 changes: 7 additions & 1 deletion 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.compile.dependencies
project.configurations.implementation.dependencies
.findAll()
.toSorted(sortClosure)
.each({ c -> depJavadocClosure(hasShadow, c) })
Expand Down Expand Up @@ -422,6 +422,12 @@ 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: 6 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ tasks.withType(JavaCompile).configureEach {
*****************************************************************************/

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

dependencies {
Expand Down Expand Up @@ -123,7 +124,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:1.3-groovy-2.5') {
integTestImplementation('org.spockframework:spock-core:2.0-groovy-3.0') {
exclude module: "groovy"
}
}
Expand Down Expand Up @@ -259,6 +260,9 @@ if (project != rootProject) {
*/
afterEvaluate {
generatePomFileForPluginMavenPublication.enabled = false
tasks.matching { it.name.contains("PluginMaven") }*.configure {
dependsOn("generatePomFileForNebulaPublication")
}
}

publishing.publications.named("nebula").configure {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/org/opensearch/gradle/LoggedExec.java
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.getExecResult().getExitValue() != 0) {
if (LoggedExec.this.getExecutionResult().get().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.getExecResult().getExitValue()
LoggedExec.this.getExecutionResult().get().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().getDestination(), "output");
File testOutputDir = new File(test.getReports().getJunitXml().getOutputLocation().getAsFile().get(), "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.jcenter();
repos.mavenCentral();

String luceneVersion = VersionProperties.getLucene();
if (luceneVersion.contains("-snapshot")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
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.util.GradleVersion;

import javax.inject.Inject;
Expand Down Expand Up @@ -77,13 +76,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 JavaInstallationRegistry javaInstallationRegistry;
private final JvmMetadataDetector jvmMetadataDetector;
private final ObjectFactory objects;
private final ProviderFactory providers;

@Inject
public GlobalBuildInfoPlugin(JavaInstallationRegistry javaInstallationRegistry, ObjectFactory objects, ProviderFactory providers) {
this.javaInstallationRegistry = javaInstallationRegistry;
public GlobalBuildInfoPlugin(JvmMetadataDetector jvmMetadataDetector, ObjectFactory objects, ProviderFactory providers) {
this.jvmMetadataDetector = jvmMetadataDetector;
this.objects = objects;
this.providers = providers;
}
Expand Down Expand Up @@ -115,7 +114,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).getImplementationName());
params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getDisplayName());
params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion));
params.setMinimumCompilerVersion(minimumCompilerVersion);
params.setMinimumRuntimeVersion(minimumRuntimeVersion);
Expand Down Expand Up @@ -160,14 +159,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()).getImplementationName();
final String gradleJvmDetails = getJavaInstallation(gradleJvm.getJavaHome()).getDisplayName();

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()).getImplementationName();
String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getDisplayName();
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 @@ -182,8 +181,8 @@ private void logGlobalBuildInfo() {
}

private JavaVersion determineJavaVersion(String description, File javaHome, JavaVersion requiredVersion) {
JavaInstallation installation = getJavaInstallation(javaHome);
JavaVersion actualVersion = installation.getJavaVersion();
JvmInstallationMetadata installation = getJavaInstallation(javaHome);
JavaVersion actualVersion = installation.getLanguageVersion();
if (actualVersion.isCompatibleWith(requiredVersion) == false) {
throwInvalidJavaHomeException(
description,
Expand All @@ -196,15 +195,8 @@ 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 JvmInstallationMetadata getJavaInstallation(File javaHome) {
return jvmMetadataDetector.getMetadata(javaHome);
}

private List<JavaHome> getAvailableJavaVersions(JavaVersion minimumCompilerVersion) {
Expand All @@ -214,11 +206,9 @@ 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)));
Provider<JavaInstallation> javaInstallationProvider = javaInstallationRegistry.installationForDirectory(
objects.directoryProperty().fileValue(javaHomeDirectory)
);
JvmInstallationMetadata javaInstallation = jvmMetadataDetector.getMetadata(javaHomeDirectory);
JavaHome javaHome = JavaHome.of(version, providers.provider(() -> {
int actualVersion = Integer.parseInt(javaInstallationProvider.get().getJavaVersion().getMajorVersion());
int actualVersion = Integer.parseInt(javaInstallation.getLanguageVersion().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,6 +39,7 @@
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 @@ -80,77 +81,83 @@ 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, 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);
}
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);
}

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.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.setStandardOutput(new IndentingOutputStream(System.out, unreleasedVersionInfo.get().version));
loggedExec.setErrorOutput(new IndentingOutputStream(System.err, unreleasedVersionInfo.get().version));
configAction.execute(loggedExec);
});
}

Expand Down
Loading

0 comments on commit 93bd32b

Please sign in to comment.