Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ abstract class ClojureRun extends ClojureSourceTask {
@Classpath
abstract ConfigurableFileCollection getClasspath()

private final Property<String> fn

@Input
@Optional
abstract Property<String> getFn()
Property<String> getFn() {
return fn
}

@Option(option = "fn", description = "The clojure function (and optional args) to execute.")
public void setFn(String fn) {
this.getFn().set(fn)
this.fn.set(fn)
}

private final ExecOperations execOperations
Expand All @@ -39,6 +43,7 @@ abstract class ClojureRun extends ClojureSourceTask {
ClojureRun(ExecOperations execOperations, ObjectFactory objects) {
this.execOperations = execOperations
this.objects = objects
this.fn = objects.property(String)
}

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

def options = [
fn: fn.getOrNull()
fn: getFn().getOrNull()
]

def runtime = [
Expand Down
136 changes: 136 additions & 0 deletions src/test/groovy/nebula/plugin/clojure/ClojureRunSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package nebula.plugin.clojure

class ClojureRunSpec extends BaseIntegrationTestKitSpec {

private final APP_CLJ = '''\
(ns test.nebula.app)

(defn hello
[name]
(println "Hello," name))

(defn greet-world
[]
(println "Hello, World!"))
'''.stripIndent()

def 'clojureRun task can be created and registered'() {
given:
buildFile << '''\
plugins {
id 'com.netflix.nebula.clojure'
}

repositories { mavenCentral() }

dependencies {
implementation 'org.clojure:clojure:1.10.3'
}
'''.stripIndent()

settingsFile << 'rootProject.name="clojure-run-test"'

def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
clojurefiles.mkdirs()
new File(clojurefiles, 'app.clj').text = APP_CLJ

when:
def result = runTasks('tasks', '--all')

then:
noExceptionThrown()
result.output.contains('clojureRun')
}

def 'clojureRun task accepts --fn command line option'() {
given:
buildFile << '''\
plugins {
id 'com.netflix.nebula.clojure'
}

repositories { mavenCentral() }

dependencies {
implementation 'org.clojure:clojure:1.10.3'
}
'''.stripIndent()

settingsFile << 'rootProject.name="clojure-run-with-fn"'

def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
clojurefiles.mkdirs()
new File(clojurefiles, 'app.clj').text = APP_CLJ

when:
def result = runTasks('clojureRun', '--fn=test.nebula.app/greet-world')

then:
noExceptionThrown()
result.output.contains('Hello, World!')
}

def 'clojureRun task can be configured with fn property'() {
given:
buildFile << '''\
plugins {
id 'com.netflix.nebula.clojure'
}

repositories { mavenCentral() }

dependencies {
implementation 'org.clojure:clojure:1.10.3'
}

tasks.named('clojureRun') {
fn = 'test.nebula.app/greet-world'
}
'''.stripIndent()

settingsFile << 'rootProject.name="clojure-run-configured"'

def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
clojurefiles.mkdirs()
new File(clojurefiles, 'app.clj').text = APP_CLJ

when:
def result = runTasks('clojureRun')

then:
noExceptionThrown()
result.output.contains('Hello, World!')
}

def 'clojureRun task works with fn property using Provider API'() {
given:
buildFile << '''\
plugins {
id 'com.netflix.nebula.clojure'
}

repositories { mavenCentral() }

dependencies {
implementation 'org.clojure:clojure:1.10.3'
}

tasks.named('clojureRun') {
fn.set('test.nebula.app/greet-world')
}
'''.stripIndent()

settingsFile << 'rootProject.name="clojure-run-provider-api"'

def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula')
clojurefiles.mkdirs()
new File(clojurefiles, 'app.clj').text = APP_CLJ

when:
def result = runTasks('clojureRun')

then:
noExceptionThrown()
result.output.contains('Hello, World!')
}
}