Skip to content

Commit

Permalink
Merge branch 'master' into remove-unused-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Büscher committed Sep 20, 2018
2 parents 95d8624 + 8d50c10 commit ff0d7f4
Show file tree
Hide file tree
Showing 382 changed files with 13,604 additions and 5,729 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.carrotsearch.gradle.junit4

import com.carrotsearch.ant.tasks.junit4.JUnit4
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
Expand All @@ -11,12 +10,8 @@ import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test

import java.util.concurrent.atomic.AtomicBoolean

class RandomizedTestingPlugin implements Plugin<Project> {

static private AtomicBoolean sanityCheckConfigured = new AtomicBoolean(false)

void apply(Project project) {
setupSeed(project)
replaceTestTask(project.tasks)
Expand All @@ -27,16 +22,10 @@ class RandomizedTestingPlugin implements Plugin<Project> {
private static void configureSanityCheck(Project project) {
// Check the task graph to confirm tasks were indeed replaced
// https://github.com/elastic/elasticsearch/issues/31324
if (sanityCheckConfigured.getAndSet(true) == false) {
project.rootProject.getGradle().getTaskGraph().whenReady {
List<Task> nonConforming = project.getGradle().getTaskGraph().allTasks
.findAll { it.name == "test" }
.findAll { (it instanceof RandomizedTestingTask) == false}
.collect { "${it.path} -> ${it.class}" }
if (nonConforming.isEmpty() == false) {
throw new GradleException("Found the ${nonConforming.size()} `test` tasks:" +
"\n ${nonConforming.join("\n ")}")
}
project.rootProject.getGradle().getTaskGraph().whenReady {
Task test = project.getTasks().findByName("test")
if (test != null && (test instanceof RandomizedTestingTask) == false) {
throw new IllegalStateException("Test task was not replaced in project ${project.path}. Found ${test.getClass()}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,6 @@ class BuildPlugin implements Plugin<Project> {
// TODO: remove this once ctx isn't added to update script params in 7.0
systemProperty 'es.scripting.update.ctx_in_params', 'false'

//TODO: remove this once the cname is prepended to the address by default in 7.0
systemProperty 'es.http.cname_in_publish_address', 'true'

// Set the system keystore/truststore password if we're running tests in a FIPS-140 JVM
if (project.inFipsJvm) {
systemProperty 'javax.net.ssl.trustStorePassword', 'password'
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.elasticsearch.gradle.precommit

import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.gradle.api.Project
import org.gradle.api.Task
Expand Down Expand Up @@ -87,6 +88,11 @@ class PrecommitTasks {
private static Task configureJarHell(Project project) {
Task task = project.tasks.create('jarHell', JarHellTask.class)
task.classpath = project.sourceSets.test.runtimeClasspath
if (project.plugins.hasPlugin(ShadowPlugin)) {
task.classpath += project.configurations.bundle
}
task.dependsOn(project.sourceSets.test.classesTaskName)
task.javaHome = project.runtimeJavaHome
return task
}

Expand Down Expand Up @@ -205,22 +211,20 @@ class PrecommitTasks {

private static Task configureNamingConventions(Project project) {
if (project.sourceSets.findByName("test")) {
return project.tasks.create('namingConventions', NamingConventionsTask)
Task namingConventionsTask = project.tasks.create('namingConventions', NamingConventionsTask)
namingConventionsTask.javaHome = project.runtimeJavaHome
return namingConventionsTask
}
return null
}

private static Task configureLoggerUsage(Project project) {
Task loggerUsageTask = project.tasks.create('loggerUsageCheck', LoggerUsageTask.class)

project.configurations.create('loggerUsagePlugin')
project.dependencies.add('loggerUsagePlugin',
"org.elasticsearch.test:logger-usage:${org.elasticsearch.gradle.VersionProperties.elasticsearch}")

loggerUsageTask.configure {
return project.tasks.create('loggerUsageCheck', LoggerUsageTask.class) {
classpath = project.configurations.loggerUsagePlugin
javaHome = project.runtimeJavaHome
}

return loggerUsageTask
}
}
45 changes: 43 additions & 2 deletions buildSrc/src/main/java/org/elasticsearch/gradle/LoggedExec.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.elasticsearch.gradle;

import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.tasks.Exec;
import org.gradle.process.BaseExecSpec;
import org.gradle.process.ExecResult;
import org.gradle.process.ExecSpec;
import org.gradle.process.JavaExecSpec;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.function.Function;

/**
* A wrapper around gradle's Exec task to capture output and log on error.
*/
@SuppressWarnings("unchecked")
public class LoggedExec extends Exec {

protected ByteArrayOutputStream output = new ByteArrayOutputStream();

public LoggedExec() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
if (getLogger().isInfoEnabled() == false) {
setStandardOutput(output);
setErrorOutput(output);
Expand All @@ -41,4 +47,39 @@ public LoggedExec() {
);
}
}

public static ExecResult exec(Project project, Action<ExecSpec> action) {
return genericExec(project, project::exec, action);
}

public static ExecResult javaexec(Project project, Action<JavaExecSpec> action) {
return genericExec(project, project::javaexec, action);
}

private static <T extends BaseExecSpec> ExecResult genericExec(
Project project,
Function<Action<T>,ExecResult> function,
Action<T> action
) {
if (project.getLogger().isInfoEnabled()) {
return function.apply(action);
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
return function.apply(spec -> {
spec.setStandardOutput(output);
spec.setErrorOutput(output);
action.execute(spec);
});
} catch (Exception e) {
try {
for (String line : output.toString("UTF-8").split("\\R")) {
project.getLogger().error(line);
}
} catch (UnsupportedEncodingException ue) {
throw new GradleException("Failed to read exec output", ue);
}
throw e;
}
}
}
Loading

0 comments on commit ff0d7f4

Please sign in to comment.