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

Remove deprecation warnings to prepare for Gradle 5 (sourceSets.main.output.classesDirs) #30389

Merged
merged 27 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8b1affc
Remove deprecation warnings to prepare for Gradle 5
alpar-t May 3, 2018
684234b
Merge branch 'master' into fix/30354
alpar-t May 7, 2018
9bd9389
Only check Java tests, PR feedback
alpar-t May 7, 2018
a7e641c
Merge branch 'master' into fix/30354
alpar-t May 9, 2018
2149a16
Replace `add` with `addAll`
alpar-t May 15, 2018
b8bf651
Revert "Only check Java tests, PR feedback"
alpar-t May 15, 2018
f9bf8fa
Remove `basedOn` helper
alpar-t May 15, 2018
af3ac3e
Bring some changes back
alpar-t May 15, 2018
f514cc8
Fix negation
alpar-t May 15, 2018
c0bf1af
Merge commit '9434f25' into fix/30354
alpar-t May 16, 2018
32a6438
add back public
alpar-t May 21, 2018
202f8f7
Merge commit 'c6be3b4' into fix/30354
alpar-t May 22, 2018
a2800c0
revert name check changes
alpar-t May 23, 2018
3bb77ff
Revert "revert name check changes"
alpar-t May 28, 2018
9f56f93
Pass all dirs to name check
alpar-t May 28, 2018
8265b0b
Merge commit 'e888467d0a7af4115789d08e4cd96bb98375968e' into fix/30354
alpar-t May 28, 2018
cb11667
remove self tests from name check
alpar-t May 30, 2018
a1f93cf
First test to run a Gradle build
alpar-t May 30, 2018
4b6cb42
Add tests that replace the name check self test
alpar-t May 30, 2018
ced99bf
Merge commit '8e4ab82' into fix/30354
alpar-t May 31, 2018
a3f1cfc
Merge commit '8b698f0' into fix/30354
alpar-t Jun 25, 2018
b7f8a1a
Clean up integ test base class
alpar-t Jun 25, 2018
c179844
Always run tests
alpar-t Jun 25, 2018
1712976
Align with test naming conventions
alpar-t Jun 26, 2018
9578cb8
Make integ. test case inherit from unit test case
alpar-t Jun 26, 2018
72fb7a9
Remove `import static org.junit.Assert.*`
alpar-t Jun 28, 2018
572dbe8
Merge branch 'master' into fix/30354
alpar-t Jun 28, 2018
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
29 changes: 11 additions & 18 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
* under the License.
*/

import java.nio.file.Files

import org.gradle.util.GradleVersion
import java.nio.file.Files

apply plugin: 'groovy'
plugins {
id 'java-gradle-plugin'
id 'groovy'
}

group = 'org.elasticsearch.gradle'

Expand Down Expand Up @@ -83,9 +85,10 @@ repositories {
}

dependencies {
compile gradleApi()
compile localGroovy()
compile "com.carrotsearch.randomizedtesting:junit4-ant:${props.getProperty('randomizedrunner')}"
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"

compile("junit:junit:${props.getProperty('junit')}") {
transitive = false
}
Expand All @@ -97,8 +100,10 @@ dependencies {
compile 'de.thetaphi:forbiddenapis:2.5'
compile 'org.apache.rat:apache-rat:0.11'
compile "org.elasticsearch:jna:4.5.1"
testCompile "junit:junit:${props.getProperty('junit')}"
}


// Gradle 2.14+ removed ProgressLogger(-Factory) classes from the public APIs
// Use logging dependency instead
// Gradle 4.3.1 stopped releasing the logging jars to jcenter, just use the last available one
Expand All @@ -113,14 +118,12 @@ dependencies {
*****************************************************************************/
// this will only happen when buildSrc is built on its own during build init
if (project == rootProject) {

repositories {
if (System.getProperty("repos.mavenLocal") != null) {
mavenLocal()
}
mavenCentral()
}
test.exclude 'org/elasticsearch/test/NamingConventionsCheckBadClasses*'
}

/*****************************************************************************
Expand All @@ -145,9 +148,6 @@ if (project != rootProject) {
jarHell.enabled = false
thirdPartyAudit.enabled = false

// test for elasticsearch.build tries to run with ES...
test.enabled = false

// TODO: re-enable once randomizedtesting gradle code is published and removed from here
licenseHeaders.enabled = false

Expand All @@ -158,14 +158,7 @@ if (project != rootProject) {
}

namingConventions {
testClass = 'org.elasticsearch.test.NamingConventionsCheckBadClasses$UnitTestCase'
integTestClass = 'org.elasticsearch.test.NamingConventionsCheckBadClasses$IntegTestCase'
}

task namingConventionsMain(type: org.elasticsearch.gradle.precommit.NamingConventionsTask) {
checkForTestsInMain = true
testClass = namingConventions.testClass
integTestClass = namingConventions.integTestClass
testClass = 'org.elasticsearch.gradle.test.GradleUnitTestCase'
integTestClass = 'org.elasticsearch.gradle.test.GradleIntegrationTestCase'
}
precommit.dependsOn namingConventionsMain
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RandomizedTestingPlugin implements Plugin<Project> {
description = 'Runs unit tests with the randomized testing framework'
dependsOn oldTestTask.dependsOn, 'testClasses'
classpath = oldTestTask.classpath
testClassesDir = oldTestTask.project.sourceSets.test.output.classesDir
testClassesDirs = oldTestTask.project.sourceSets.test.output.classesDirs
}

// hack so check task depends on custom test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import groovy.xml.NamespaceBuilder
import groovy.xml.NamespaceBuilderSupport
import org.apache.tools.ant.BuildException
import org.apache.tools.ant.DefaultLogger
import org.apache.tools.ant.Project
import org.apache.tools.ant.RuntimeConfigurable
import org.apache.tools.ant.UnknownElement
import org.elasticsearch.gradle.BuildPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.InvalidUserDataException
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTreeElement
import org.gradle.api.internal.tasks.options.Option
import org.gradle.api.specs.Spec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.api.tasks.util.PatternSet
import org.gradle.internal.logging.progress.ProgressLoggerFactory
Expand All @@ -43,8 +45,8 @@ class RandomizedTestingTask extends DefaultTask {
@Input
String parallelism = '1'

@InputDirectory
File testClassesDir
@Input
FileCollection testClassesDirs

@Optional
@Input
Expand Down Expand Up @@ -220,15 +222,15 @@ class RandomizedTestingTask extends DefaultTask {
listener = new DefaultLogger(
errorPrintStream: System.err,
outputPrintStream: System.out,
messageOutputLevel: org.apache.tools.ant.Project.MSG_INFO)
messageOutputLevel: Project.MSG_INFO)
} else {
// we want to buffer the info, and emit it if the test fails
antLoggingBuffer = new ByteArrayOutputStream()
PrintStream stream = new PrintStream(antLoggingBuffer, true, "UTF-8")
listener = new DefaultLogger(
errorPrintStream: stream,
outputPrintStream: stream,
messageOutputLevel: org.apache.tools.ant.Project.MSG_INFO)
messageOutputLevel: Project.MSG_INFO)
}
project.ant.project.addBuildListener(listener)
}
Expand All @@ -251,12 +253,10 @@ class RandomizedTestingTask extends DefaultTask {
if (argLine != null) {
jvmarg(line: argLine)
}
fileset(dir: testClassesDir) {
for (String includePattern : patternSet.getIncludes()) {
include(name: includePattern)
}
for (String excludePattern : patternSet.getExcludes()) {
exclude(name: excludePattern)
testClassesDirs.each { testClassDir ->
fileset(dir: testClassDir) {
patternSet.getIncludes().each { include(name: it) }
patternSet.getExcludes().each { exclude(name: it) }
}
}
for (Map.Entry<String, Object> prop : systemProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class BuildPlugin implements Plugin<Project> {
project.extensions.add('additionalTest', { String name, Closure config ->
RandomizedTestingTask additionalTest = project.tasks.create(name, RandomizedTestingTask.class)
additionalTest.classpath = test.classpath
additionalTest.testClassesDir = test.testClassesDir
additionalTest.testClassesDirs = test.testClassesDirs
additionalTest.configure(commonTestConfig(project))
additionalTest.configure(config)
additionalTest.dependsOn(project.tasks.testClasses)
Expand Down

This file was deleted.

41 changes: 41 additions & 0 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/LoggedExec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.elasticsearch.gradle;

import groovy.lang.Closure;
import org.gradle.api.GradleException;
import org.gradle.api.Task;
import org.gradle.api.tasks.Exec;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.stream.Collectors;

/**
* A wrapper around gradle's Exec task to capture output and log on error.
*/
public class LoggedExec extends Exec {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be moved to a java file, but still exists under src/main/groovy?


protected ByteArrayOutputStream output = new ByteArrayOutputStream();

public LoggedExec() {
if (getLogger().isInfoEnabled() == false) {
setStandardOutput(output);
setErrorOutput(output);
setIgnoreExitValue(true);
doLast(new Closure<Void>(this, this) {
public void doCall(Task it) throws IOException {
if (getExecResult().getExitValue() != 0) {
for (String line : output.toString("UTF-8").split("\\R")) {
getLogger().error(line);
}
throw new GradleException(
"Process \'" + getExecutable() + " " +
getArgs().stream().collect(Collectors.joining(" "))+
"\' finished with non-zero exit value " +
String.valueOf(getExecResult().getExitValue())
);
}
}
});
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.elasticsearch.gradle;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
* Accessor for shared dependency versions used by elasticsearch, namely the elasticsearch and lucene versions.
*/
public class VersionProperties {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears this is being moved to a java file, but it is still under src/main/groovy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is because the Groovy compiler knows how to deal with this and delegate these files to the Java compiler. The reason these can't move to src/main/java (yet) us that they make use of Groovy classes that are not on the cp when pure java is compiled. Moving those Groovy classes to Java creates a ripple effect, so my thinking is that we can have java files in the groovy source set until we have critical mass, eventually removing the groovy source set. It's easier and less risky than converting to Java at once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a great plan!

public static Version getElasticsearch() {
return elasticsearch;
}

public static String getLucene() {
return lucene;
}

public static Map<String, String> getVersions() {
return versions;
}

private static final Version elasticsearch;
private static final String lucene;
private static final Map<String, String> versions = new HashMap<String, String>();
static {
Properties props = getVersionProperties();
elasticsearch = Version.fromString(props.getProperty("elasticsearch"));
lucene = props.getProperty("lucene");
for (String property : props.stringPropertyNames()) {
versions.put(property, props.getProperty(property));
}
}

private static Properties getVersionProperties() {
Properties props = new Properties();
InputStream propsStream = VersionProperties.class.getResourceAsStream("/version.properties");
if (propsStream == null) {
throw new RuntimeException("/version.properties resource missing");
}
try {
props.load(propsStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
return props;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class LoggerUsageTask extends LoggedExec {
List files = []
// But only if the source sets that will make them exist
if (project.sourceSets.findByName("main")) {
files.add(project.sourceSets.main.output.classesDir)
files.addAll(project.sourceSets.main.output.classesDirs.getFiles())
dependsOn project.tasks.classes
}
if (project.sourceSets.findByName("test")) {
files.add(project.sourceSets.test.output.classesDir)
files.addAll(project.sourceSets.test.output.classesDirs.getFiles())
dependsOn project.tasks.testClasses
}
/* In an extra twist, it isn't good enough that the source set
Expand Down
Loading