Skip to content

Commit

Permalink
Eliminate Gradle task input warnings (#47538)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira authored Oct 4, 2019
1 parent c26ce1d commit e86d40f
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@
package org.elasticsearch.gradle

import org.elasticsearch.gradle.precommit.DependencyLicensesTask
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.DependencyResolutionListener
import org.gradle.api.artifacts.DependencySet
import org.gradle.api.internal.ConventionTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

import java.util.regex.Matcher
import java.util.regex.Pattern

/**
* A task to gather information about the dependencies and export them into a csv file.
*
Expand All @@ -46,31 +42,31 @@ import java.util.regex.Pattern
* </ul>
*
*/
public class DependenciesInfoTask extends ConventionTask {
class DependenciesInfoTask extends ConventionTask {

/** Dependencies to gather information from. */
@Input
public Configuration runtimeConfiguration
@InputFiles
Configuration runtimeConfiguration

/** We subtract compile-only dependencies. */
@Input
public Configuration compileOnlyConfiguration

private LinkedHashMap<String, String> mappings
@InputFiles
Configuration compileOnlyConfiguration

/** Directory to read license files */
@InputDirectory
public File licensesDir = new File(project.projectDir, 'licenses')
File licensesDir = new File(project.projectDir, 'licenses')

@OutputFile
File outputFile = new File(project.buildDir, "reports/dependencies/dependencies.csv")

public DependenciesInfoTask() {
private LinkedHashMap<String, String> mappings

DependenciesInfoTask() {
description = 'Create a CSV file with dependencies information.'
}

@TaskAction
public void generateDependenciesInfo() {
void generateDependenciesInfo() {

final DependencySet runtimeDependencies = runtimeConfiguration.getAllDependencies()
// we have to resolve the transitive dependencies and create a group:artifactId:version map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import java.nio.file.Path
/**
* Generates REST tests for each snippet marked // TEST.
*/
public class RestTestsFromSnippetsTask extends SnippetsTask {
class RestTestsFromSnippetsTask extends SnippetsTask {
/**
* These languages aren't supported by the syntax highlighter so we
* shouldn't use them.
Expand All @@ -58,7 +58,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
@OutputDirectory
File testRoot = project.file('build/rest')

public RestTestsFromSnippetsTask() {
RestTestsFromSnippetsTask() {
project.afterEvaluate {
// Wait to set this so testRoot can be customized
project.sourceSets.test.output.dir(testRoot, builtBy: this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.gradle.api.InvalidUserDataException
import org.gradle.api.file.ConfigurableFileTree
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction

import java.nio.file.Path
Expand All @@ -36,7 +37,7 @@ import java.util.regex.Matcher
/**
* A task which will run a closure on each snippet in the documentation.
*/
public class SnippetsTask extends DefaultTask {
class SnippetsTask extends DefaultTask {
private static final String SCHAR = /(?:\\\/|[^\/])/
private static final String SUBSTITUTION = /s\/($SCHAR+)\/($SCHAR*)\//
private static final String CATCH = /catch:\s*((?:\/[^\/]+\/)|[^ \]]+)/
Expand All @@ -51,6 +52,7 @@ public class SnippetsTask extends DefaultTask {
* Action to take on each snippet. Called with a single parameter, an
* instance of Snippet.
*/
@Internal
Closure perSnippet

/**
Expand All @@ -73,7 +75,7 @@ public class SnippetsTask extends DefaultTask {
Map<String, String> defaultSubstitutions = [:]

@TaskAction
public void executeTask() {
void executeTask() {
/*
* Walks each line of each file, building snippets as it encounters
* the lines that make up the snippet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal

/**
* A fixture for integration tests which runs in a separate process launched by Ant.
*/
public class AntFixture extends AntTask implements Fixture {
class AntFixture extends AntTask implements Fixture {

/** The path to the executable that starts the fixture. */
@Input
@Internal
String executable

private final List<Object> arguments = new ArrayList<>()

@Input
public void args(Object... args) {
void args(Object... args) {
arguments.addAll(args)
}

Expand All @@ -49,16 +49,15 @@ public class AntFixture extends AntTask implements Fixture {
*/
private final Map<String, Object> environment = new HashMap<>()

@Input
public void env(String key, Object value) {
void env(String key, Object value) {
environment.put(key, value)
}

/** A flag to indicate whether the command should be executed from a shell. */
@Input
@Internal
boolean useShell = false

@Input
@Internal
int maxWaitInSeconds = 30

/**
Expand All @@ -72,6 +71,7 @@ public class AntFixture extends AntTask implements Fixture {
* as well as a groovy AntBuilder, to enable running ant condition checks. The default wait
* condition is for http on the http port.
*/
@Internal
Closure waitCondition = { AntFixture fixture, AntBuilder ant ->
File tmpFile = new File(fixture.cwd, 'wait.success')
ant.get(src: "http://${fixture.addressAndPort}",
Expand All @@ -83,13 +83,14 @@ public class AntFixture extends AntTask implements Fixture {

private final Task stopTask

public AntFixture() {
AntFixture() {
stopTask = createStopTask()
finalizedBy(stopTask)
}

@Override
public Task getStopTask() {
@Internal
Task getStopTask() {
return stopTask
}

Expand Down Expand Up @@ -168,6 +169,7 @@ public class AntFixture extends AntTask implements Fixture {
}

/** Returns a debug string used to log information about how the fixture was run. */
@Internal
protected String getCommandString() {
String commandString = "\n${name} configuration:\n"
commandString += "-----------------------------------------\n"
Expand Down Expand Up @@ -247,46 +249,55 @@ public class AntFixture extends AntTask implements Fixture {
* A path relative to the build dir that all configuration and runtime files
* will live in for this fixture
*/
@Internal
protected File getBaseDir() {
return new File(project.buildDir, "fixtures/${name}")
}

/** Returns the working directory for the process. Defaults to "cwd" inside baseDir. */
@Internal
protected File getCwd() {
return new File(baseDir, 'cwd')
}

/** Returns the file the process writes its pid to. Defaults to "pid" inside baseDir. */
@Internal
protected File getPidFile() {
return new File(baseDir, 'pid')
}

/** Reads the pid file and returns the process' pid */
public int getPid() {
@Internal
int getPid() {
return Integer.parseInt(pidFile.getText('UTF-8').trim())
}

/** Returns the file the process writes its bound ports to. Defaults to "ports" inside baseDir. */
@Internal
protected File getPortsFile() {
return new File(baseDir, 'ports')
}

/** Returns an address and port suitable for a uri to connect to this node over http */
public String getAddressAndPort() {
@Internal
String getAddressAndPort() {
return portsFile.readLines("UTF-8").get(0)
}

/** Returns a file that wraps around the actual command when {@code spawn == true}. */
@Internal
protected File getWrapperScript() {
return new File(cwd, Os.isFamily(Os.FAMILY_WINDOWS) ? 'run.bat' : 'run')
}

/** Returns a file that the wrapper script writes when the command failed. */
@Internal
protected File getFailureMarker() {
return new File(cwd, 'run.failed')
}

/** Returns a file that the wrapper script writes when the command failed. */
@Internal
protected File getRunLog() {
return new File(cwd, 'run.log')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package org.elasticsearch.gradle.test

import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.options.Option
import org.gradle.util.ConfigureUtil

public class RunTask extends DefaultTask {
class RunTask extends DefaultTask {

@Internal
ClusterConfiguration clusterConfig

public RunTask() {
RunTask() {
description = "Runs elasticsearch with '${project.path}'"
group = 'Verification'
clusterConfig = new ClusterConfiguration(project)
Expand All @@ -26,13 +28,13 @@ public class RunTask extends DefaultTask {
option = "debug-jvm",
description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
)
public void setDebug(boolean enabled) {
void setDebug(boolean enabled) {
clusterConfig.debug = enabled;
}

/** Configure the cluster that will be run. */
@Override
public Task configure(Closure closure) {
Task configure(Closure closure) {
ConfigureUtil.configure(closure, clusterConfig)
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AbstractLazyPropertyCollection(String name, Object owner) {
this.owner = owner;
}

abstract List<? extends Object> getNormalizedCollection();
public abstract List<? extends Object> getNormalizedCollection();

void assertNotNull(Object value, String description) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.file.Chmod;

Expand All @@ -49,11 +50,16 @@ public Chmod getChmod() {
throw new UnsupportedOperationException();
}

@Input
@Internal
public File getDir() {
return dir;
}

@Input
public String getDirPath() {
return dir.getPath();
}

/**
* @param dir The directory to create
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.StopExecutionException;
import org.gradle.api.tasks.TaskAction;

Expand Down Expand Up @@ -66,7 +65,6 @@ public DirectoryProperty getOutputDir() {
}

@Input
@SkipWhenEmpty
public Set<String> getResources() {
return Collections.unmodifiableSet(resources);
}
Expand All @@ -78,8 +76,8 @@ public String getResourcesClasspath() {
return System.getProperty("java.class.path");
}

public void setOutputDir(DirectoryProperty outputDir) {
this.outputDir = outputDir;
public void setOutputDir(File outputDir) {
this.outputDir.set(outputDir);
}

public File copy(String resource) {
Expand All @@ -95,6 +93,7 @@ public File copy(String resource) {
@TaskAction
public void doExport() {
if (resources.isEmpty()) {
setDidWork(false);
throw new StopExecutionException();
}
resources.stream().parallel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.elasticsearch.gradle;

import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -171,8 +170,7 @@ public List<T> subList(int fromIndex, int toIndex) {
}

@Override
@Nested
List<? extends Object> getNormalizedCollection() {
public List<? extends Object> getNormalizedCollection() {
return delegate.stream()
.peek(this::validate)
.filter(entry -> entry.getNormalization() != PropertyNormalization.IGNORE_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.gradle.api.Named;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;

import java.util.Collection;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -117,8 +116,7 @@ public Set<Entry<K, V>> entrySet() {
}

@Override
@Nested
List<? extends Object> getNormalizedCollection() {
public List<? extends Object> getNormalizedCollection() {
return delegate.values().stream()
.peek(this::validate)
.filter(entry -> entry.getNormalization() != PropertyNormalization.IGNORE_VALUE)
Expand Down
Loading

0 comments on commit e86d40f

Please sign in to comment.