@@ -5,6 +5,8 @@ import com.google.errorprone.ErrorProneOptions.Severity
5
5
import com.google.errorprone.InvalidCommandLineOptionException
6
6
import org.gradle.api.InvalidUserDataException
7
7
import org.gradle.api.model.ObjectFactory
8
+ import org.gradle.api.provider.ProviderFactory
9
+ import org.gradle.kotlin.dsl.property
8
10
import org.gradle.process.CommandLineArgumentProvider
9
11
import org.gradle.testfixtures.ProjectBuilder
10
12
import org.junit.Assert.fail
@@ -18,9 +20,13 @@ class ErrorProneOptionsTest {
18
20
@JvmField @ClassRule val projectDir = TemporaryFolder ()
19
21
20
22
lateinit var objects: ObjectFactory
23
+ lateinit var providers: ProviderFactory
21
24
22
25
@JvmStatic @BeforeClass fun setup () {
23
- objects = ProjectBuilder .builder().withProjectDir(projectDir.root).build().objects
26
+ ProjectBuilder .builder().withProjectDir(projectDir.root).build().let { project ->
27
+ objects = project.objects
28
+ providers = project.providers
29
+ }
24
30
}
25
31
}
26
32
@@ -40,12 +46,12 @@ class ErrorProneOptionsTest {
40
46
doTestOptions { error(" ArrayEquals" ) }
41
47
doTestOptions { check(" ArrayEquals" to CheckSeverity .OFF ) }
42
48
doTestOptions { check(" ArrayEquals" , CheckSeverity .WARN ) }
43
- doTestOptions { checks[ " ArrayEquals" ] = CheckSeverity .ERROR }
44
- doTestOptions { checks = mutableMapOf (" ArrayEquals" to CheckSeverity .DEFAULT ) }
49
+ doTestOptions { checks.put( " ArrayEquals" , CheckSeverity .ERROR ) }
50
+ doTestOptions { checks.set( mutableMapOf (" ArrayEquals" to CheckSeverity .DEFAULT ) ) }
45
51
doTestOptions { option(" Foo" ) }
46
52
doTestOptions { option(" Foo" , " Bar" ) }
47
- doTestOptions { checkOptions[ " Foo" ] = " Bar" }
48
- doTestOptions { checkOptions = mutableMapOf (" Foo" to " Bar" ) }
53
+ doTestOptions { checkOptions.put( " Foo" , " Bar" ) }
54
+ doTestOptions { checkOptions.set( mutableMapOf (" Foo" to " Bar" ) ) }
49
55
50
56
doTestOptions {
51
57
disableAllChecks.set(true )
@@ -93,6 +99,31 @@ class ErrorProneOptionsTest {
93
99
})
94
100
}
95
101
102
+ @Test
103
+ fun `correctly allows lazy configuration` () {
104
+ doTestOptions({
105
+ check(" NullAway" , isCompilingTestOnlyCode.map { if (it) CheckSeverity .WARN else CheckSeverity .ERROR })
106
+ }, {
107
+ error(" NullAway" )
108
+ })
109
+
110
+ doTestOptions({
111
+ check(" NullAway" , isCompilingTestOnlyCode.map { if (it) CheckSeverity .WARN else CheckSeverity .ERROR })
112
+ isCompilingTestOnlyCode.set(providers.provider { true })
113
+ }, {
114
+ isCompilingTestOnlyCode.set(true )
115
+ warn(" NullAway" )
116
+ })
117
+
118
+ doTestOptions({
119
+ val annotatedPackages = objects.property<String >()
120
+ option(" NullAway:AnnotatedPackages" , annotatedPackages)
121
+ annotatedPackages.set(providers.provider { " net.ltgt.gradle.errorprone" })
122
+ }, {
123
+ option(" NullAway:AnnotatedPackages" , " net.ltgt.gradle.errorprone" )
124
+ })
125
+ }
126
+
96
127
private fun doTestOptions (configure : ErrorProneOptions .() -> Unit , reference : ErrorProneOptions .() -> Unit ) {
97
128
val options = ErrorProneOptions (objects).apply (reference)
98
129
val parsedOptions = parseOptions(ErrorProneOptions (objects).apply (configure))
@@ -162,8 +193,8 @@ class ErrorProneOptionsTest {
162
193
assertThat(parsedOptions.isIgnoreSuppressionAnnotations).isEqualTo(options.ignoreSuppressionAnnotations.get())
163
194
assertThat(parsedOptions.isTestOnlyTarget).isEqualTo(options.isCompilingTestOnlyCode.get())
164
195
assertThat(parsedOptions.excludedPattern?.pattern()).isEqualTo(options.excludedPaths.orNull)
165
- assertThat(parsedOptions.severityMap).containsExactlyEntriesIn(options.checks.mapValues { it.value.toSeverity() })
166
- assertThat(parsedOptions.flags.flagsMap).containsExactlyEntriesIn(options.checkOptions)
196
+ assertThat(parsedOptions.severityMap).containsExactlyEntriesIn(options.checks.get(). mapValues { it.value.toSeverity() })
197
+ assertThat(parsedOptions.flags.flagsMap).containsExactlyEntriesIn(options.checkOptions.get() )
167
198
assertThat(parsedOptions.remainingArgs).isEmpty()
168
199
}
169
200
0 commit comments