From 6e5ea0bc4dfc5b7181172acfbe51729f19b312a7 Mon Sep 17 00:00:00 2001 From: Danny Kirchmeier Date: Sat, 9 Jan 2016 23:09:13 -0600 Subject: [PATCH] Rename reallyExecutable.trampoline to trampolining Added tests to assert the correct script is used fixes #20 --- DOCUMENTATION.md | 4 +- .../capsule/spec/ReallyExecutableSpec.groovy | 11 +++++ src/test/gradle/build.gradle | 45 ++++++++++++++----- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 4003632..e6aa81e 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -234,7 +234,7 @@ task beautifulCapsule(type:MavenCapsule){ `reallyExecutable` will make a capsule executable as a script in unix environments. `reallyExecutable.regular()` is the default and uses a plan execution script. -`reallyExecutable.trampoline()` will use the trompoline script. +`reallyExecutable.trampolining()` will use the trompoline script. `reallyExecutable.script(file)` may be set to define your own script. See More: [Capsule: Really Executable](http://www.capsule.io/user-guide/#really-executable-capsules) @@ -247,7 +247,7 @@ task executableCapsule(type:FatCapsule){ task trampolineCapsule(type:MavenCapsule){ applicationClass 'com.foo.CoolCalculator' - reallyExecutable { trampoline() } + reallyExecutable { trampolining() } } task myExecutableCapsule(type:FatCapsule){ diff --git a/src/main/groovy/us/kirchmeier/capsule/spec/ReallyExecutableSpec.groovy b/src/main/groovy/us/kirchmeier/capsule/spec/ReallyExecutableSpec.groovy index 820fdfb..e648f08 100644 --- a/src/main/groovy/us/kirchmeier/capsule/spec/ReallyExecutableSpec.groovy +++ b/src/main/groovy/us/kirchmeier/capsule/spec/ReallyExecutableSpec.groovy @@ -15,7 +15,18 @@ class ReallyExecutableSpec { return this } + /** + * Deprecated because this conflicts with the closure method 'trampoline()' + * + * @deprecated Use trampolining() instead + * @return + */ + @Deprecated ReallyExecutableSpec trampoline() { + return this.trampolining() + } + + ReallyExecutableSpec trampolining() { _regular = false _trampoline = true script = null diff --git a/src/test/gradle/build.gradle b/src/test/gradle/build.gradle index 9309668..1ae85f8 100644 --- a/src/test/gradle/build.gradle +++ b/src/test/gradle/build.gradle @@ -39,25 +39,25 @@ ext.selfTest = task('self-test') task fatCapsule(type: FatCapsule) { applicationClass 'com.foo.Main' classifier 'fat' - buildTests(delegate, executable: false, fat: true) + buildTests(delegate, executableScript: null, fat: true) } task fatCapsuleExecutable(type: FatCapsule) { applicationClass 'com.foo.Main' classifier 'fatExec' reallyExecutable - buildTests(delegate, executable: true, fat: true) + buildTests(delegate, executableScript: 'regular', fat: true) } task mavenCapsule(type: MavenCapsule) { applicationClass 'com.foo.Main' classifier 'maven' - buildTests(delegate, executable: false, maven: true) + buildTests(delegate, executableScript: null, maven: true) } task mavenCapsuleExecutable(type: MavenCapsule) { applicationClass 'com.foo.Main' classifier 'mavenExec' - reallyExecutable { trampoline() } - buildTests(delegate, executable: true, maven: true) + reallyExecutable { trampolining() } + buildTests(delegate, executableScript: 'trampoline', maven: true) } task platformCapsule(type: FatCapsule) { @@ -67,7 +67,7 @@ task platformCapsule(type: FatCapsule) { platform('linux') { applicationClass 'com.foo.Main' } } classifier 'platform' - buildTests(delegate, executable: false, fat: true) + buildTests(delegate, executableScript: null, fat: true) } task recreatedMavenCapsule(type: Capsule){ @@ -79,7 +79,7 @@ task recreatedMavenCapsule(type: Capsule){ dependencyConfiguration configurations.runtime caplets << 'MavenCapsule' } - buildTests(delegate, executable: false, maven: true) + buildTests(delegate, executableScript: null, maven: true) } project('subproject') { @@ -99,7 +99,7 @@ project('subproject') { manifest { //Tests issue #13, where this broke subprojects attributes('Main-Class': 'Capsule') } - buildTests(delegate, executable: false, fat: true, additionalContents: ['subproject.jar']) + buildTests(delegate, executableScript: null, fat: true, additionalContents: ['subproject.jar']) } } @@ -121,7 +121,7 @@ private void buildTests(Map options, task) { } private void testOutput(f, options) { - def cmd = options.executable ? [f.absolutePath] : ['java', '-Dcapsule.log2=ALL', '-jar', f.absolutePath] + def cmd = options.executableScript ? [f.absolutePath] : ['java', '-Dcapsule.log2=ALL', '-jar', f.absolutePath] def env = System.getenv().collect{ k,v -> "$k=$v" } env << "CAPSULE_CACHE_DIR=${Files.createTempDirectory("gradle_capsule_test")}"; def proc = cmd.execute(env, null) @@ -133,7 +133,7 @@ private void testOutput(f, options) { assert exitCode == 0 } -private void testContents(file, options) { +private void testContents(File file, options) { def f = new JarFile(file, false) def projectFiles = new ArrayList() f.entries().each { @@ -181,4 +181,29 @@ private void testContents(file, options) { assert jm.size() == 7 } + if(options.executableScript){ + def expectedReallyExecutableHeader = getExecutableScriptContents(options.executableScript) + def expectedLines = expectedReallyExecutableHeader.split(System.lineSeparator()).length + def actualReallyExecutableHeader = file.readLines()[0..