Skip to content

Commit d966e5a

Browse files
committed
Eliminate Gradle task input warnings (#47538)
(cherry picked from commit e86d40f)
1 parent 35ca3d6 commit d966e5a

16 files changed

+112
-70
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/DependenciesInfoTask.groovy

+11-15
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@
2020
package org.elasticsearch.gradle
2121

2222
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
23-
import org.gradle.api.DefaultTask
2423
import org.gradle.api.artifacts.Configuration
2524
import org.gradle.api.artifacts.Dependency
26-
import org.gradle.api.artifacts.DependencyResolutionListener
2725
import org.gradle.api.artifacts.DependencySet
2826
import org.gradle.api.internal.ConventionTask
2927
import org.gradle.api.tasks.Input
3028
import org.gradle.api.tasks.InputDirectory
29+
import org.gradle.api.tasks.InputFiles
3130
import org.gradle.api.tasks.OutputFile
3231
import org.gradle.api.tasks.TaskAction
3332

34-
import java.util.regex.Matcher
35-
import java.util.regex.Pattern
36-
3733
/**
3834
* A task to gather information about the dependencies and export them into a csv file.
3935
*
@@ -46,31 +42,31 @@ import java.util.regex.Pattern
4642
* </ul>
4743
*
4844
*/
49-
public class DependenciesInfoTask extends ConventionTask {
45+
class DependenciesInfoTask extends ConventionTask {
5046

5147
/** Dependencies to gather information from. */
52-
@Input
53-
public Configuration runtimeConfiguration
48+
@InputFiles
49+
Configuration runtimeConfiguration
5450

5551
/** We subtract compile-only dependencies. */
56-
@Input
57-
public Configuration compileOnlyConfiguration
58-
59-
private LinkedHashMap<String, String> mappings
52+
@InputFiles
53+
Configuration compileOnlyConfiguration
6054

6155
/** Directory to read license files */
6256
@InputDirectory
63-
public File licensesDir = new File(project.projectDir, 'licenses')
57+
File licensesDir = new File(project.projectDir, 'licenses')
6458

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

68-
public DependenciesInfoTask() {
62+
private LinkedHashMap<String, String> mappings
63+
64+
DependenciesInfoTask() {
6965
description = 'Create a CSV file with dependencies information.'
7066
}
7167

7268
@TaskAction
73-
public void generateDependenciesInfo() {
69+
void generateDependenciesInfo() {
7470

7571
final DependencySet runtimeDependencies = runtimeConfiguration.getAllDependencies()
7672
// we have to resolve the transitive dependencies and create a group:artifactId:version map

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import java.nio.file.Path
3131
/**
3232
* Generates REST tests for each snippet marked // TEST.
3333
*/
34-
public class RestTestsFromSnippetsTask extends SnippetsTask {
34+
class RestTestsFromSnippetsTask extends SnippetsTask {
3535
/**
3636
* These languages aren't supported by the syntax highlighter so we
3737
* shouldn't use them.
@@ -58,7 +58,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
5858
@OutputDirectory
5959
File testRoot = project.file('build/rest')
6060

61-
public RestTestsFromSnippetsTask() {
61+
RestTestsFromSnippetsTask() {
6262
project.afterEvaluate {
6363
// Wait to set this so testRoot can be customized
6464
project.sourceSets.test.output.dir(testRoot, builtBy: this)

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/SnippetsTask.groovy

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.gradle.api.InvalidUserDataException
2828
import org.gradle.api.file.ConfigurableFileTree
2929
import org.gradle.api.tasks.Input
3030
import org.gradle.api.tasks.InputFiles
31+
import org.gradle.api.tasks.Internal
3132
import org.gradle.api.tasks.TaskAction
3233

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

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

7577
@TaskAction
76-
public void executeTask() {
78+
void executeTask() {
7779
/*
7880
* Walks each line of each file, building snippets as it encounters
7981
* the lines that make up the snippet.

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/AntFixture.groovy

+23-12
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ import org.gradle.api.GradleException
2626
import org.gradle.api.Task
2727
import org.gradle.api.tasks.Exec
2828
import org.gradle.api.tasks.Input
29+
import org.gradle.api.tasks.Internal
2930

3031
/**
3132
* A fixture for integration tests which runs in a separate process launched by Ant.
3233
*/
33-
public class AntFixture extends AntTask implements Fixture {
34+
class AntFixture extends AntTask implements Fixture {
3435

3536
/** The path to the executable that starts the fixture. */
36-
@Input
37+
@Internal
3738
String executable
3839

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

41-
@Input
42-
public void args(Object... args) {
42+
void args(Object... args) {
4343
arguments.addAll(args)
4444
}
4545

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

52-
@Input
53-
public void env(String key, Object value) {
52+
void env(String key, Object value) {
5453
environment.put(key, value)
5554
}
5655

5756
/** A flag to indicate whether the command should be executed from a shell. */
58-
@Input
57+
@Internal
5958
boolean useShell = false
6059

61-
@Input
60+
@Internal
6261
int maxWaitInSeconds = 30
6362

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

8484
private final Task stopTask
8585

86-
public AntFixture() {
86+
AntFixture() {
8787
stopTask = createStopTask()
8888
finalizedBy(stopTask)
8989
}
9090

9191
@Override
92-
public Task getStopTask() {
92+
@Internal
93+
Task getStopTask() {
9394
return stopTask
9495
}
9596

@@ -168,6 +169,7 @@ public class AntFixture extends AntTask implements Fixture {
168169
}
169170

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

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

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

264269
/** Reads the pid file and returns the process' pid */
265-
public int getPid() {
270+
@Internal
271+
int getPid() {
266272
return Integer.parseInt(pidFile.getText('UTF-8').trim())
267273
}
268274

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

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

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

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

289299
/** Returns a file that the wrapper script writes when the command failed. */
300+
@Internal
290301
protected File getRunLog() {
291302
return new File(cwd, 'run.log')
292303
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RunTask.groovy

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package org.elasticsearch.gradle.test
22

33
import org.gradle.api.DefaultTask
44
import org.gradle.api.Task
5+
import org.gradle.api.tasks.Internal
56
import org.gradle.api.tasks.options.Option
67
import org.gradle.util.ConfigureUtil
78

8-
public class RunTask extends DefaultTask {
9+
class RunTask extends DefaultTask {
910

11+
@Internal
1012
ClusterConfiguration clusterConfig
1113

12-
public RunTask() {
14+
RunTask() {
1315
description = "Runs elasticsearch with '${project.path}'"
1416
group = 'Verification'
1517
clusterConfig = new ClusterConfiguration(project)
@@ -26,13 +28,13 @@ public class RunTask extends DefaultTask {
2628
option = "debug-jvm",
2729
description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
2830
)
29-
public void setDebug(boolean enabled) {
31+
void setDebug(boolean enabled) {
3032
clusterConfig.debug = enabled;
3133
}
3234

3335
/** Configure the cluster that will be run. */
3436
@Override
35-
public Task configure(Closure closure) {
37+
Task configure(Closure closure) {
3638
ConfigureUtil.configure(closure, clusterConfig)
3739
return this
3840
}

buildSrc/src/main/java/org/elasticsearch/gradle/AbstractLazyPropertyCollection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public AbstractLazyPropertyCollection(String name, Object owner) {
1616
this.owner = owner;
1717
}
1818

19-
abstract List<? extends Object> getNormalizedCollection();
19+
public abstract List<? extends Object> getNormalizedCollection();
2020

2121
void assertNotNull(Object value, String description) {
2222
if (value == null) {

buildSrc/src/main/java/org/elasticsearch/gradle/EmptyDirTask.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.gradle.api.DefaultTask;
2626
import org.gradle.api.tasks.Input;
27+
import org.gradle.api.tasks.Internal;
2728
import org.gradle.api.tasks.TaskAction;
2829
import org.gradle.internal.file.Chmod;
2930

@@ -49,11 +50,16 @@ public Chmod getChmod() {
4950
throw new UnsupportedOperationException();
5051
}
5152

52-
@Input
53+
@Internal
5354
public File getDir() {
5455
return dir;
5556
}
5657

58+
@Input
59+
public String getDirPath() {
60+
return dir.getPath();
61+
}
62+
5763
/**
5864
* @param dir The directory to create
5965
*/

buildSrc/src/main/java/org/elasticsearch/gradle/ExportElasticsearchBuildResourcesTask.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.gradle.api.tasks.Classpath;
2727
import org.gradle.api.tasks.Input;
2828
import org.gradle.api.tasks.OutputDirectory;
29-
import org.gradle.api.tasks.SkipWhenEmpty;
3029
import org.gradle.api.tasks.StopExecutionException;
3130
import org.gradle.api.tasks.TaskAction;
3231

@@ -66,7 +65,6 @@ public DirectoryProperty getOutputDir() {
6665
}
6766

6867
@Input
69-
@SkipWhenEmpty
7068
public Set<String> getResources() {
7169
return Collections.unmodifiableSet(resources);
7270
}
@@ -78,8 +76,8 @@ public String getResourcesClasspath() {
7876
return System.getProperty("java.class.path");
7977
}
8078

81-
public void setOutputDir(DirectoryProperty outputDir) {
82-
this.outputDir = outputDir;
79+
public void setOutputDir(File outputDir) {
80+
this.outputDir.set(outputDir);
8381
}
8482

8583
public File copy(String resource) {
@@ -95,6 +93,7 @@ public File copy(String resource) {
9593
@TaskAction
9694
public void doExport() {
9795
if (resources.isEmpty()) {
96+
setDidWork(false);
9897
throw new StopExecutionException();
9998
}
10099
resources.stream().parallel()

buildSrc/src/main/java/org/elasticsearch/gradle/LazyPropertyList.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.elasticsearch.gradle;
22

33
import org.gradle.api.tasks.Input;
4-
import org.gradle.api.tasks.Nested;
54

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

173172
@Override
174-
@Nested
175-
List<? extends Object> getNormalizedCollection() {
173+
public List<? extends Object> getNormalizedCollection() {
176174
return delegate.stream()
177175
.peek(this::validate)
178176
.filter(entry -> entry.getNormalization() != PropertyNormalization.IGNORE_VALUE)

buildSrc/src/main/java/org/elasticsearch/gradle/LazyPropertyMap.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.gradle.api.Named;
44
import org.gradle.api.tasks.Input;
5-
import org.gradle.api.tasks.Nested;
65

76
import java.util.Collection;
87
import java.util.LinkedHashMap;
@@ -117,8 +116,7 @@ public Set<Entry<K, V>> entrySet() {
117116
}
118117

119118
@Override
120-
@Nested
121-
List<? extends Object> getNormalizedCollection() {
119+
public List<? extends Object> getNormalizedCollection() {
122120
return delegate.values().stream()
123121
.peek(this::validate)
124122
.filter(entry -> entry.getNormalization() != PropertyNormalization.IGNORE_VALUE)

0 commit comments

Comments
 (0)