Skip to content

Commit

Permalink
Build: remove progress logger hack for gradle 2.13 (#23679)
Browse files Browse the repository at this point in the history
We are now on minimum gradle 3.3, so we no longer need the groovy/gradle
hacks used to support both 2.13 and 2.14+.
  • Loading branch information
rjernst authored Mar 22, 2017
1 parent ee802ad commit 25448e3
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 164 deletions.
21 changes: 5 additions & 16 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,12 @@ dependencies {
compile 'org.apache.rat:apache-rat:0.11'
}

// Gradle version-specific options (allows build to run with Gradle 2.13 as well as 2.14+/3.+)
if (GradleVersion.current() == GradleVersion.version("2.13")) {
// ProgressLogger(-Factory) classes are part of the public Gradle API
sourceSets.main.groovy.srcDir 'src/main/gradle-2.13-groovy'
// Gradle 2.14+ removed ProgressLogger(-Factory) classes from the public APIs
// Use logging dependency instead

dependencies {
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.0.1' // last version compatible with Gradle 2.13
}
} else {
// Gradle 2.14+ removed ProgressLogger(-Factory) classes from the public APIs
// Use logging dependency instead
sourceSets.main.groovy.srcDir 'src/main/gradle-2.14-groovy'

dependencies {
compileOnly "org.gradle:gradle-logging:${GradleVersion.current().getVersion()}"
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.2.0' // Gradle 2.14 requires a version > 1.0.1
}
dependencies {
compileOnly "org.gradle:gradle-logging:${GradleVersion.current().getVersion()}"
compile 'ru.vyarus:gradle-animalsniffer-plugin:1.2.0' // Gradle 2.14 requires a version > 1.0.1
}

/*****************************************************************************
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.apache.tools.ant.BuildException
import org.apache.tools.ant.DefaultLogger
import org.apache.tools.ant.RuntimeConfigurable
import org.apache.tools.ant.UnknownElement
import org.elasticsearch.gradle.ProgressLoggerFactoryInjection
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTreeElement
Expand All @@ -20,9 +19,12 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.api.tasks.util.PatternSet
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.gradle.util.ConfigureUtil

class RandomizedTestingTask extends DefaultTask implements ProgressLoggerFactoryInjection {
import javax.inject.Inject

class RandomizedTestingTask extends DefaultTask {

// TODO: change to "executable" to match gradle test params?
@Optional
Expand Down Expand Up @@ -92,6 +94,11 @@ class RandomizedTestingTask extends DefaultTask implements ProgressLoggerFactory
listenersConfig.listeners.add(new TestReportLogger(logger: logger, config: testLoggingConfig))
}

@Inject
ProgressLoggerFactory getProgressLoggerFactory() {
throw new UnsupportedOperationException()
}

void jvmArgs(Iterable<String> arguments) {
jvmArgs.addAll(arguments)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedStartEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteResultEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
import org.elasticsearch.gradle.ProgressLogger
import org.gradle.internal.logging.progress.ProgressLogger
import org.gradle.internal.logging.progress.ProgressLoggerFactory

import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDurationInSeconds
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.ERROR
Expand All @@ -51,6 +52,8 @@ import static java.lang.Math.max
* quick.
*/
class TestProgressLogger implements AggregatedEventListener {
/** Factory to build a progress logger when testing starts */
ProgressLoggerFactory factory
ProgressLogger progressLogger
int totalSuites
int totalSlaves
Expand All @@ -74,17 +77,14 @@ class TestProgressLogger implements AggregatedEventListener {
/** Have we finished a whole suite yet? */
volatile boolean suiteFinished = false
/* Note that we probably overuse volatile here but it isn't hurting us and
lets us move things around without worying about breaking things. */

TestProgressLogger(Map args) {
progressLogger = new ProgressLogger(args.factory.newOperation(TestProgressLogger))
progressLogger.setDescription('Randomized test runner')
}
lets us move things around without worrying about breaking things. */

@Subscribe
void onStart(AggregatedStartEvent e) throws IOException {
totalSuites = e.suiteCount
totalSlaves = e.slaveCount
progressLogger = factory.newOperation(TestProgressLogger)
progressLogger.setDescription('Randomized test runner')
progressLogger.started()
progressLogger.progress(
"Starting JUnit4 for ${totalSuites} suites on ${totalSlaves} jvms")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
package org.elasticsearch.gradle.vagrant

import com.carrotsearch.gradle.junit4.LoggingOutputStream
import groovy.transform.PackageScope
import org.elasticsearch.gradle.ProgressLogger
import org.gradle.api.GradleScriptException
import org.gradle.api.logging.Logger
import org.gradle.internal.logging.progress.ProgressLogger

import java.util.regex.Matcher

Expand All @@ -48,7 +47,7 @@ public class TapLoggerOutputStream extends LoggingOutputStream {

TapLoggerOutputStream(Map args) {
logger = args.logger
progressLogger = new ProgressLogger(args.factory.newOperation(VagrantLoggerOutputStream))
progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
progressLogger.setDescription("TAP output for `${args.command}`")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
package org.elasticsearch.gradle.vagrant

import org.apache.commons.io.output.TeeOutputStream
import org.elasticsearch.gradle.ProgressLoggerFactoryInjection
import org.elasticsearch.gradle.LoggedExec
import org.gradle.api.tasks.Input
import org.gradle.internal.logging.progress.ProgressLoggerFactory

import javax.inject.Inject

/**
* Runs a vagrant command. Pretty much like Exec task but with a nicer output
* formatter and defaults to `vagrant` as first part of commandLine.
*/
public class VagrantCommandTask extends LoggedExec implements ProgressLoggerFactoryInjection {
public class VagrantCommandTask extends LoggedExec {

@Input
String boxName
Expand All @@ -47,6 +49,11 @@ public class VagrantCommandTask extends LoggedExec implements ProgressLoggerFact
}
}

@Inject
ProgressLoggerFactory getProgressLoggerFactory() {
throw new UnsupportedOperationException()
}

protected OutputStream createLoggerOutputStream() {
return new VagrantLoggerOutputStream(
command: commandLine.join(' '),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.elasticsearch.gradle.vagrant

import com.carrotsearch.gradle.junit4.LoggingOutputStream
import org.elasticsearch.gradle.ProgressLogger
import org.gradle.internal.logging.progress.ProgressLogger

/**
* Adapts an OutputStream being written to by vagrant into a ProcessLogger. It
Expand Down Expand Up @@ -53,7 +53,7 @@ public class VagrantLoggerOutputStream extends LoggingOutputStream {
private String heading = ''

VagrantLoggerOutputStream(Map args) {
progressLogger = new ProgressLogger(args.factory.newOperation(VagrantLoggerOutputStream))
progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
progressLogger.setDescription("Vagrant output for `$args.command`")
squashedPrefix = args.squashedPrefix
}
Expand Down

0 comments on commit 25448e3

Please sign in to comment.