Skip to content

Commit cea215c

Browse files
authored
Merge pull request #61 from nebula-plugins/fix-clojureRun-fn-property
Fix ClojureRun task creation: converting the fn property from abstract to a concrete implementation
2 parents 7e00c43 + f08cd2d commit cea215c

2 files changed

Lines changed: 144 additions & 3 deletions

File tree

src/main/groovy/nebula/plugin/clojuresque/tasks/ClojureRun.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ abstract class ClojureRun extends ClojureSourceTask {
1919
@Classpath
2020
abstract ConfigurableFileCollection getClasspath()
2121

22+
private final Property<String> fn
23+
2224
@Input
2325
@Optional
24-
abstract Property<String> getFn()
26+
Property<String> getFn() {
27+
return fn
28+
}
2529

2630
@Option(option = "fn", description = "The clojure function (and optional args) to execute.")
2731
public void setFn(String fn) {
28-
this.getFn().set(fn)
32+
this.fn.set(fn)
2933
}
3034

3135
private final ExecOperations execOperations
@@ -39,6 +43,7 @@ abstract class ClojureRun extends ClojureSourceTask {
3943
ClojureRun(ExecOperations execOperations, ObjectFactory objects) {
4044
this.execOperations = execOperations
4145
this.objects = objects
46+
this.fn = objects.property(String)
4247
}
4348

4449
void jvmOptions(Closure closure) {
@@ -50,7 +55,7 @@ abstract class ClojureRun extends ClojureSourceTask {
5055
void run() {
5156

5257
def options = [
53-
fn: fn.getOrNull()
58+
fn: getFn().getOrNull()
5459
]
5560

5661
def runtime = [
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package nebula.plugin.clojure
2+
3+
class ClojureRunSpec extends BaseIntegrationTestKitSpec {
4+
5+
private final APP_CLJ = '''\
6+
(ns test.nebula.app)
7+
8+
(defn hello
9+
[name]
10+
(println "Hello," name))
11+
12+
(defn greet-world
13+
[]
14+
(println "Hello, World!"))
15+
'''.stripIndent()
16+
17+
def 'clojureRun task can be created and registered'() {
18+
given:
19+
buildFile << '''\
20+
plugins {
21+
id 'com.netflix.nebula.clojure'
22+
}
23+
24+
repositories { mavenCentral() }
25+
26+
dependencies {
27+
implementation 'org.clojure:clojure:1.10.3'
28+
}
29+
'''.stripIndent()
30+
31+
settingsFile << 'rootProject.name="clojure-run-test"'
32+
33+
def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
34+
clojurefiles.mkdirs()
35+
new File(clojurefiles, 'app.clj').text = APP_CLJ
36+
37+
when:
38+
def result = runTasks('tasks', '--all')
39+
40+
then:
41+
noExceptionThrown()
42+
result.output.contains('clojureRun')
43+
}
44+
45+
def 'clojureRun task accepts --fn command line option'() {
46+
given:
47+
buildFile << '''\
48+
plugins {
49+
id 'com.netflix.nebula.clojure'
50+
}
51+
52+
repositories { mavenCentral() }
53+
54+
dependencies {
55+
implementation 'org.clojure:clojure:1.10.3'
56+
}
57+
'''.stripIndent()
58+
59+
settingsFile << 'rootProject.name="clojure-run-with-fn"'
60+
61+
def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
62+
clojurefiles.mkdirs()
63+
new File(clojurefiles, 'app.clj').text = APP_CLJ
64+
65+
when:
66+
def result = runTasks('clojureRun', '--fn=test.nebula.app/greet-world')
67+
68+
then:
69+
noExceptionThrown()
70+
result.output.contains('Hello, World!')
71+
}
72+
73+
def 'clojureRun task can be configured with fn property'() {
74+
given:
75+
buildFile << '''\
76+
plugins {
77+
id 'com.netflix.nebula.clojure'
78+
}
79+
80+
repositories { mavenCentral() }
81+
82+
dependencies {
83+
implementation 'org.clojure:clojure:1.10.3'
84+
}
85+
86+
tasks.named('clojureRun') {
87+
fn = 'test.nebula.app/greet-world'
88+
}
89+
'''.stripIndent()
90+
91+
settingsFile << 'rootProject.name="clojure-run-configured"'
92+
93+
def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
94+
clojurefiles.mkdirs()
95+
new File(clojurefiles, 'app.clj').text = APP_CLJ
96+
97+
when:
98+
def result = runTasks('clojureRun')
99+
100+
then:
101+
noExceptionThrown()
102+
result.output.contains('Hello, World!')
103+
}
104+
105+
def 'clojureRun task works with fn property using Provider API'() {
106+
given:
107+
buildFile << '''\
108+
plugins {
109+
id 'com.netflix.nebula.clojure'
110+
}
111+
112+
repositories { mavenCentral() }
113+
114+
dependencies {
115+
implementation 'org.clojure:clojure:1.10.3'
116+
}
117+
118+
tasks.named('clojureRun') {
119+
fn.set('test.nebula.app/greet-world')
120+
}
121+
'''.stripIndent()
122+
123+
settingsFile << 'rootProject.name="clojure-run-provider-api"'
124+
125+
def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
126+
clojurefiles.mkdirs()
127+
new File(clojurefiles, 'app.clj').text = APP_CLJ
128+
129+
when:
130+
def result = runTasks('clojureRun')
131+
132+
then:
133+
noExceptionThrown()
134+
result.output.contains('Hello, World!')
135+
}
136+
}

0 commit comments

Comments
 (0)