Eliminate Gradle task input warnings (#47538)

(cherry picked from commit e86d40ff4576fb20c64fe88f01f13e201f3b948f)
This commit is contained in:
Mark Vieira 2019-10-04 13:12:42 -07:00
parent 35ca3d68d7
commit d966e5a9b9
No known key found for this signature in database
GPG Key ID: CA947EF7E6D4B105
16 changed files with 112 additions and 70 deletions

View File

@ -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.
*
@ -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

View File

@ -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.
@ -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)

View File

@ -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
@ -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*((?:\/[^\/]+\/)|[^ \]]+)/
@ -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
/**
@ -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.

View File

@ -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)
}
@ -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
/**
@ -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}",
@ -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
}
@ -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"
@ -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')
}

View File

@ -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)
@ -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
}

View File

@ -16,7 +16,7 @@ public abstract class AbstractLazyPropertyCollection {
this.owner = owner;
}
abstract List<? extends Object> getNormalizedCollection();
public abstract List<? extends Object> getNormalizedCollection();
void assertNotNull(Object value, String description) {
if (value == null) {

View File

@ -24,6 +24,7 @@ import javax.inject.Inject;
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;
@ -49,11 +50,16 @@ public class EmptyDirTask extends DefaultTask {
throw new UnsupportedOperationException();
}
@Input
@Internal
public File getDir() {
return dir;
}
@Input
public String getDirPath() {
return dir.getPath();
}
/**
* @param dir The directory to create
*/

View File

@ -26,7 +26,6 @@ import org.gradle.api.logging.Logging;
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;
@ -66,7 +65,6 @@ public class ExportElasticsearchBuildResourcesTask extends DefaultTask {
}
@Input
@SkipWhenEmpty
public Set<String> getResources() {
return Collections.unmodifiableSet(resources);
}
@ -78,8 +76,8 @@ public class ExportElasticsearchBuildResourcesTask extends DefaultTask {
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) {
@ -95,6 +93,7 @@ public class ExportElasticsearchBuildResourcesTask extends DefaultTask {
@TaskAction
public void doExport() {
if (resources.isEmpty()) {
setDidWork(false);
throw new StopExecutionException();
}
resources.stream().parallel()

View File

@ -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;
@ -171,8 +170,7 @@ public class LazyPropertyList<T> extends AbstractLazyPropertyCollection implemen
}
@Override
@Nested
List<? extends Object> getNormalizedCollection() {
public List<? extends Object> getNormalizedCollection() {
return delegate.stream()
.peek(this::validate)
.filter(entry -> entry.getNormalization() != PropertyNormalization.IGNORE_VALUE)

View File

@ -2,7 +2,6 @@ package org.elasticsearch.gradle;
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;
@ -117,8 +116,7 @@ public class LazyPropertyMap<K, V> extends AbstractLazyPropertyCollection implem
}
@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)

View File

@ -28,6 +28,7 @@ import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
@ -306,6 +307,7 @@ public class DependencyLicensesTask extends DefaultTask {
return new File(licensesDir, jarName + SHA_EXTENSION);
}
@Internal
Set<File> getShaFiles() {
File[] array = licensesDir.listFiles();
if (array == null) {

View File

@ -87,7 +87,7 @@ public class ForbiddenPatternsTask extends DefaultTask {
@InputFiles
@SkipWhenEmpty
public FileCollection files() {
public FileCollection getFiles() {
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets()
.stream()
.map(sourceSet -> sourceSet.getAllSource().matching(filesFilter))
@ -99,7 +99,7 @@ public class ForbiddenPatternsTask extends DefaultTask {
public void checkInvalidPatterns() throws IOException {
Pattern allPatterns = Pattern.compile("(" + String.join(")|(", getPatterns().values()) + ")");
List<String> failures = new ArrayList<>();
for (File f : files()) {
for (File f : getFiles()) {
List<String> lines;
try(Stream<String> stream = Files.lines(f.toPath(), StandardCharsets.UTF_8)) {
lines = stream.collect(Collectors.toList());

View File

@ -22,6 +22,7 @@ package org.elasticsearch.gradle.precommit;
import org.gradle.api.DefaultTask;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;
@ -77,6 +78,7 @@ public class UpdateShasTask extends DefaultTask {
Files.write(shaFile.toPath(), sha.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
}
@Internal
public DependencyLicensesTask getParentTask() {
return parentTask.get();
}

View File

@ -27,8 +27,8 @@ import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;
@ -69,13 +69,17 @@ public class SymbolicLinkPreservingUntarTask extends DefaultTask {
private Function<String, Path> transform;
@Internal
public Function<String, Path> getTransform() {
return transform;
}
/**
* A transform to apply to the tar entry, to derive the relative path from the entry name. If the return value is null, the entry is
* dropped from the exploded tar archive.
*
* @param transform the transform
*/
@Input
public void setTransform(Function<String, Path> transform) {
this.transform = transform;
}

View File

@ -27,6 +27,7 @@ import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import java.io.File;
@ -107,14 +108,17 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
return nodes.getAt(clusterName + "-0");
}
@Internal
public int getNumberOfNodes() {
return nodes.size();
}
@Internal
public String getName() {
return clusterName;
}
@Internal
public String getPath() {
return path;
}
@ -383,24 +387,28 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
}
@Override
@Internal
public String getHttpSocketURI() {
waitForAllConditions();
return getFirstNode().getHttpSocketURI();
}
@Override
@Internal
public String getTransportPortURI() {
waitForAllConditions();
return getFirstNode().getTransportPortURI();
}
@Override
@Internal
public List<String> getAllHttpSocketURI() {
waitForAllConditions();
return nodes.stream().flatMap(each -> each.getAllHttpSocketURI().stream()).collect(Collectors.toList());
}
@Override
@Internal
public List<String> getAllTransportPortURI() {
waitForAllConditions();
return nodes.stream().flatMap(each -> each.getAllTransportPortURI().stream()).collect(Collectors.toList());
@ -424,6 +432,7 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
}
@Override
@Internal
public boolean isProcessAlive() {
return nodes.stream().noneMatch(node -> node.isProcessAlive() == false);
}

View File

@ -42,6 +42,7 @@ import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.util.PatternFilterable;
@ -171,6 +172,8 @@ public class ElasticsearchNode implements TestClusterConfiguration {
setVersion(VersionProperties.getElasticsearch());
}
@Input
@Optional
public String getName() {
return nameCustomization.apply(name);
}
@ -346,6 +349,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
jvmArgs.addAll(Arrays.asList(values));
}
@Internal
public Path getConfigDir() {
return configFile.getParent();
}
@ -368,6 +372,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
this.javaHome = javaHome;
}
@Internal
public File getJavaHome() {
return javaHome;
}
@ -701,31 +706,37 @@ public class ElasticsearchNode implements TestClusterConfiguration {
}
@Override
@Internal
public String getHttpSocketURI() {
return getHttpPortInternal().get(0);
}
@Override
@Internal
public String getTransportPortURI() {
return getTransportPortInternal().get(0);
}
@Override
@Internal
public List<String> getAllHttpSocketURI() {
waitForAllConditions();
return getHttpPortInternal();
}
@Override
@Internal
public List<String> getAllTransportPortURI() {
waitForAllConditions();
return getTransportPortInternal();
}
@Internal
public File getServerLog() {
return confPathLogs.resolve(defaultConfig.get("cluster.name") + "_server.json").toFile();
}
@Internal
public File getAuditLog() {
return confPathLogs.resolve(defaultConfig.get("cluster.name") + "_audit.json").toFile();
}
@ -1096,30 +1107,30 @@ public class ElasticsearchNode implements TestClusterConfiguration {
}
@Input
private Set<URI> getRemotePlugins() {
public Set<URI> getRemotePlugins() {
Set<URI> file = plugins.stream().filter(uri -> uri.getScheme().equalsIgnoreCase("file") == false).collect(Collectors.toSet());
return file;
}
@Classpath
private List<File> getInstalledClasspath() {
public List<File> getInstalledClasspath() {
return getInstalledFileSet(filter -> filter.include("**/*.jar"));
}
@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
private List<File> getInstalledFiles() {
public List<File> getInstalledFiles() {
return getInstalledFileSet(filter -> filter.exclude("**/*.jar"));
}
@Classpath
private Set<File> getDistributionClasspath() {
public Set<File> getDistributionClasspath() {
return getDistributionFiles(filter -> filter.include("**/*.jar"));
}
@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
private Set<File> getDistributionFiles() {
public Set<File> getDistributionFiles() {
return getDistributionFiles(filter -> filter.exclude("**/*.jar"));
}
@ -1136,41 +1147,42 @@ public class ElasticsearchNode implements TestClusterConfiguration {
}
@Nested
private Map<String, CharSequence> getKeystoreSettings() {
return keystoreSettings;
public List<?> getKeystoreSettings() {
return keystoreSettings.getNormalizedCollection();
}
@Nested
private Map<String, File> getKeystoreFiles() {
return keystoreFiles;
public List<?> getKeystoreFiles() {
return keystoreFiles.getNormalizedCollection();
}
@Nested
private Map<String, CharSequence> getSettings() {
return settings;
public List<?> getSettings() {
return settings.getNormalizedCollection();
}
@Nested
private Map<String, CharSequence> getSystemProperties() {
return systemProperties;
public List<?> getSystemProperties() {
return systemProperties.getNormalizedCollection();
}
@Nested
private Map<String, CharSequence> getEnvironment() {
return environment;
public List<?> getEnvironment() {
return environment.getNormalizedCollection();
}
@Nested
private List<CharSequence> getJvmArgs() {
return jvmArgs;
public List<?> getJvmArgs() {
return jvmArgs.getNormalizedCollection();
}
@Nested
private Map<String, File> getExtraConfigFiles() {
return extraConfigFiles;
public List<?> getExtraConfigFiles() {
return extraConfigFiles.getNormalizedCollection();
}
@Override
@Internal
public boolean isProcessAlive() {
requireNonNull(
esProcess,
@ -1236,6 +1248,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
return Files.exists(httpPortsFile) && Files.exists(transportPortFile);
}
@Internal
public boolean isHttpSslEnabled() {
return Boolean.valueOf(
settings.getOrDefault("xpack.security.http.ssl.enabled", "false").toString()