@@ -6,6 +6,14 @@ import spock.lang.Subject
66@Subject (SpaceAssignmentRule )
77class SpaceAssignmentRuleSpec extends BaseIntegrationTestKitSpec {
88
9+ def setup () {
10+ System . setProperty(" ignoreDeprecations" , " true" )
11+ }
12+
13+ def cleanup () {
14+ System . setProperty(" ignoreDeprecations" , " false" )
15+ }
16+
917 def ' reports and fixes a violation if space assignment syntax is used - simple cases' () {
1018 buildFile << """
1119 import java.util.regex.Pattern;
@@ -182,4 +190,80 @@ class SpaceAssignmentRuleSpec extends BaseIntegrationTestKitSpec {
182190 and :
183191 runTasks(' help' , ' --warning-mode' , ' none' )
184192 }
193+
194+ def ' reports and fixes a violation if space assignment syntax is used as a property getter - simple cases' () {
195+ buildFile << """
196+ plugins {
197+ id 'java'
198+ id 'nebula.lint'
199+ }
200+ gradleLint.rules = ['space-assignment']
201+ tasks.register('task1') {
202+ if (project.hasProperty('myCustomDescription')) {
203+ description = project.property('myCustomDescription')
204+ }
205+ doLast {
206+ logger.warn "myCustomDescription: \$ {description}"
207+ }
208+ }
209+ tasks.register('task2', Exec) {
210+ commandLine "echo"
211+ args ('--task2', project.property("myCustomProperty1"))
212+ doLast {
213+ logger.warn "myCustomProperty1: \$ {project.property('myCustomProperty1')}"
214+ }
215+ }
216+ def a = project.property "myCustomProperty2"
217+
218+ def subA = project(':subA')
219+ subA.afterEvaluate { evaluatedProject ->
220+ def b = project.rootProject.allprojects.find { it.name == "subA"}.property("myCustomPropertySubA1")
221+ def c = rootProject.childProjects.subA.property("myCustomPropertySubA2")
222+ def d = project.findProject(':subA').property("myCustomPropertySubA3")
223+ tasks.register('showProperties') {
224+ doLast {
225+ logger.warn "myCustomProperty2: \$ {a}"
226+ logger.warn "subA.myCustomPropertySubA1: \$ {b}"
227+ logger.warn "subA.myCustomPropertySubA2: \$ {c}"
228+ logger.warn "subA.myCustomPropertySubA3: \$ {d}"
229+ }
230+ }
231+ }
232+ """ . stripIndent()
233+
234+ new File (projectDir, " gradle.properties" ) << """ )
235+ myCustomDescription=This is a custom description
236+ myCustomProperty1=property1
237+ myCustomProperty2=property2
238+ """ . stripIndent()
239+
240+ addSubproject(' subA' , """
241+ ext {
242+ myCustomPropertySubA1 = "subA-one"
243+ myCustomPropertySubA2 = "subA-two"
244+ myCustomPropertySubA3 = "subA-three"
245+ }
246+ """ . stripIndent())
247+
248+ when :
249+ runTasks(' fixLintGradle' , ' --warning-mode' , ' none' )
250+ def results = runTasks(' task1' , ' task2' , ' showProperties' )
251+
252+ then : " fixes are applied correctly"
253+ buildFile. text. contains(" description = project.findProperty('myCustomDescription')" )
254+ buildFile. text. contains(" args ('--task2', project.findProperty(\" myCustomProperty1\" ))" )
255+ buildFile. text. contains(" logger.warn \" myCustomProperty1: \$ {project.findProperty('myCustomProperty1')}\" " )
256+ buildFile. text. contains(" def a = project.findProperty \" myCustomProperty2\" " )
257+ buildFile. text. contains(" def b = project.rootProject.allprojects.find { it.name == \" subA\" }.findProperty(\" myCustomPropertySubA1\" )" )
258+ buildFile. text. contains(" def c = rootProject.childProjects.subA.findProperty(\" myCustomPropertySubA2\" )" )
259+ buildFile. text. contains(" def d = project.findProject(':subA').findProperty(\" myCustomPropertySubA3\" )" )
260+
261+ and : " properties are read and printed correctly"
262+ results. output. contains(" myCustomDescription: This is a custom description" )
263+ results. output. contains(" myCustomProperty1: property1" )
264+ results. output. contains(" myCustomProperty2: property2" )
265+ results. output. contains(" subA.myCustomPropertySubA1: subA-one" )
266+ results. output. contains(" subA.myCustomPropertySubA2: subA-two" )
267+ results. output. contains(" subA.myCustomPropertySubA3: subA-three" )
268+ }
185269}
0 commit comments