Skip to content

Commit 20cda27

Browse files
authored
NebulaResolutionRulesExtension: override setters to avoid losing include/exclude/optional rules (#148)
1 parent f01b01e commit 20cda27

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/main/kotlin/nebula/plugin/resolutionrules/plugin.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,19 @@ abstract class NebulaResolutionRulesService : BuildService<NebulaResolutionRules
203203

204204
open class NebulaResolutionRulesExtension @Inject constructor(private val project: Project) {
205205
var include = ArrayList<String>()
206+
set(value) {
207+
field.addAll(value)
208+
}
209+
206210
var optional = ArrayList<String>()
211+
set(value) {
212+
field.addAll(value)
213+
}
207214
var exclude = ArrayList<String>()
215+
// Setter should add to the existing array rather than replacing all values
216+
set(value) {
217+
field.addAll(value)
218+
}
208219

209220
fun ruleSet(): RuleSet {
210221
val service = NebulaResolutionRulesService.registerService(project).get()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package nebula.plugin.resolutionrules
2+
3+
import org.gradle.api.Project
4+
import spock.lang.Specification
5+
6+
class NebulaResolutionRulesExtensionTest extends Specification {
7+
8+
Project project = Mock(Project)
9+
10+
def 'can assign values'() {
11+
given:
12+
def extension = new NebulaResolutionRulesExtension(project)
13+
14+
when:
15+
extension.include = ['something']
16+
extension.optional = ['some-rule']
17+
extension.exclude = ['foo']
18+
19+
then:
20+
extension.include.contains('something')
21+
extension.optional.contains('some-rule')
22+
extension.exclude.contains('foo')
23+
}
24+
25+
def 'can assign and append to exclude value'() {
26+
given:
27+
def extension = new NebulaResolutionRulesExtension(project)
28+
29+
when:
30+
extension.include = ['something']
31+
extension.include.add('else')
32+
33+
extension.exclude = ['foo']
34+
extension.exclude.add('bar')
35+
36+
extension.optional = ['some-rule']
37+
extension.optional.add('another-rule')
38+
39+
40+
then:
41+
extension.include.contains('something')
42+
extension.include.contains('else')
43+
extension.exclude.contains('foo')
44+
extension.exclude.contains('bar')
45+
extension.optional.contains('some-rule')
46+
extension.optional.contains('another-rule')
47+
}
48+
49+
def 'can assign and setter does not override existing values'() {
50+
given:
51+
def extension = new NebulaResolutionRulesExtension(project)
52+
53+
when:
54+
55+
extension.include = ['something']
56+
extension.include = ['else']
57+
58+
extension.exclude = ['foo']
59+
extension.exclude = ['bar']
60+
61+
extension.optional = ['some-rule']
62+
extension.optional = ['another-rule']
63+
64+
then:
65+
extension.include.contains('something')
66+
extension.include.contains('else')
67+
extension.exclude.contains('foo')
68+
extension.exclude.contains('bar')
69+
extension.optional.contains('some-rule')
70+
extension.optional.contains('another-rule')
71+
}
72+
}

0 commit comments

Comments
 (0)