From a40aace4de544dcf2ee8e77317347a7a97e34798 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Sat, 24 Aug 2013 10:52:40 +0200 Subject: [PATCH] Committing version 0.3.4 fixing a couple of bugs --- build.gradle | 2 +- changelog.txt | 4 ++- src/main/groovy/nextflow/Const.groovy | 6 ++-- .../nextflow/executor/LocalExecutor.groovy | 17 ++++++----- .../processor/MergeTaskProcessor.groovy | 4 +-- .../nextflow/processor/TaskProcessor.groovy | 10 +++++++ .../processor/TaskProcessorTest.groovy | 29 ++++++++++++++++--- 7 files changed, 53 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index 4d802b240d..2fe6be40d6 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'groovy' apply plugin: 'codenarc' -version = '0.3.3' +version = '0.3.4' repositories { flatDir(dirs: file('lib')) diff --git a/changelog.txt b/changelog.txt index 11ee9cabbb..d1e5e6960d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,8 +2,10 @@ NEXTFLOW CHANGE-LOG =================== 0.3.4 -- Extending semnatics for method File.copyTo(source,target) so that when 'target' argument +- Extending semantic for method File.copyTo(source,target) so that when 'target' argument is a directory, it copy the 'source' file to that folder, with the same name of the original file. +- Bug: Fixed a ClassCastEx exception when the 'bin' folder is added to the PATH +- Bug: Fixed an issue that raised an error "error=26 Text file busy" on some platforms (CentOS) 0.3.3 - 8 Aug 2013 - Added optional parameters to 'chunkLines' and 'chunkFasta' methods diff --git a/src/main/groovy/nextflow/Const.groovy b/src/main/groovy/nextflow/Const.groovy index 98042c770d..6c41ccf02d 100644 --- a/src/main/groovy/nextflow/Const.groovy +++ b/src/main/groovy/nextflow/Const.groovy @@ -57,17 +57,17 @@ class Const { /** * The application version */ - static final String APP_VER = "0.3.3" + static final String APP_VER = "0.3.4" /** * The app build time as linux/unix timestamp */ - static final long APP_TIMESTAMP = 1376051851359 + static final long APP_TIMESTAMP = 1377297870371 /** * The app build number */ - static final int APP_BUILDNUM = 752 + static final int APP_BUILDNUM = 763 /** * The date time formatter string diff --git a/src/main/groovy/nextflow/executor/LocalExecutor.groovy b/src/main/groovy/nextflow/executor/LocalExecutor.groovy index 4012329221..d67c42a0ce 100644 --- a/src/main/groovy/nextflow/executor/LocalExecutor.groovy +++ b/src/main/groovy/nextflow/executor/LocalExecutor.groovy @@ -34,11 +34,11 @@ class LocalExecutor extends AbstractExecutor { private static final COMMAND_OUT_FILENAME = '.command.out' - private static final COMMAND_RUNNER_FILENAME = '.command.run' + private static final COMMAND_BASH_FILENAME = '.command.sh' private static final COMMAND_ENV_FILENAME = '.command.env' - private static final COMMAND_SCRIPT_FILENAME = '.command.sh' + private static final COMMAND_SCRIPT_FILENAME = '.command.run' /** @@ -64,22 +64,23 @@ class LocalExecutor extends AbstractExecutor { /* * save the main script file */ + def scriptStr = task.processor.normalizeScript(task.script.toString()) def scriptFile = new File(scratch, COMMAND_SCRIPT_FILENAME) - scriptFile.text = task.processor.normalizeScript(task.script.toString()) + scriptFile.text = scriptStr + def interpreter = task.processor.fetchInterpreter(scriptStr) /* * create the runner script which will launch the script */ def runnerText = """ - source ${COMMAND_ENV_FILENAME} - chmod +x ${COMMAND_SCRIPT_FILENAME} - ./${COMMAND_SCRIPT_FILENAME} + source $COMMAND_ENV_FILENAME + $interpreter $COMMAND_SCRIPT_FILENAME """ - def runnerFile = new File(scratch, COMMAND_RUNNER_FILENAME) + def runnerFile = new File(scratch, COMMAND_BASH_FILENAME) runnerFile.text = task.processor.normalizeScript(runnerText) // the cmd list to launch it - List cmd = new ArrayList(taskConfig.shell ?: 'bash' as List ) << COMMAND_RUNNER_FILENAME + List cmd = new ArrayList(taskConfig.shell ?: 'bash' as List ) << COMMAND_BASH_FILENAME log.trace "Launch cmd line: ${cmd.join(' ')}" /* diff --git a/src/main/groovy/nextflow/processor/MergeTaskProcessor.groovy b/src/main/groovy/nextflow/processor/MergeTaskProcessor.groovy index f7f6e8ea12..92d04a9140 100644 --- a/src/main/groovy/nextflow/processor/MergeTaskProcessor.groovy +++ b/src/main/groovy/nextflow/processor/MergeTaskProcessor.groovy @@ -118,6 +118,7 @@ class MergeTaskProcessor extends TaskProcessor { scriptClosure.setResolveStrategy(Closure.DELEGATE_FIRST) def commandToRun = normalizeScript(scriptClosure.call()?.toString()) + def interpreter = fetchInterpreter(commandToRun) /* * create a unique hash-code for this task run and save it into a list @@ -137,7 +138,6 @@ class MergeTaskProcessor extends TaskProcessor { def scriptName = ".merge_command.sh.${index.toString().padLeft(4,'0')}" def scriptFile = new File(mergeTempFolder, scriptName) scriptFile.text = commandToRun - scriptFile.setExecutable(true) // the command to launch this command def scriptCommand = scriptFile.absolutePath @@ -153,7 +153,7 @@ class MergeTaskProcessor extends TaskProcessor { } // create a unique script collecting all the commands - mergeScript << scriptCommand << '\n' + mergeScript << interpreter << ' ' << scriptCommand << '\n' } diff --git a/src/main/groovy/nextflow/processor/TaskProcessor.groovy b/src/main/groovy/nextflow/processor/TaskProcessor.groovy index 2e0615577d..f1d25d0b12 100644 --- a/src/main/groovy/nextflow/processor/TaskProcessor.groovy +++ b/src/main/groovy/nextflow/processor/TaskProcessor.groovy @@ -224,6 +224,16 @@ abstract class TaskProcessor { return result.toString() } + def String fetchInterpreter( String script ) { + assert script != null + + if( script[0] == '#' && script[1] == '!') { + return script.readLines()[0].substring(2) + } + + return null + } + /** * Wraps the target method by a closure declaring as many arguments as many are the user declared inputs * object. diff --git a/src/test/groovy/nextflow/processor/TaskProcessorTest.groovy b/src/test/groovy/nextflow/processor/TaskProcessorTest.groovy index 8f5eee37c4..8be63db049 100644 --- a/src/test/groovy/nextflow/processor/TaskProcessorTest.groovy +++ b/src/test/groovy/nextflow/processor/TaskProcessorTest.groovy @@ -40,7 +40,7 @@ class TaskProcessorTest extends Specification { when: def session = new Session([env: [X:"1", Y:"2"]]) session.setBaseDir(home) - def processor = new DummyProcessor(new NopeExecutor(), session, new DummyScript(), new TaskConfig(), {}) + def processor = new DummyProcessor(new NopeExecutor(), session, new TaskConfig()) def builder = new ProcessBuilder() builder.environment().putAll( processor.getProcessEnvironment() ) @@ -53,7 +53,7 @@ class TaskProcessorTest extends Specification { when: session = new Session([env: [X:"1", Y:"2", PATH:'/some']]) session.setBaseDir(home) - processor = new DummyProcessor(new NopeExecutor(), session, new DummyScript(), new TaskConfig(), {}) + processor = new DummyProcessor(new NopeExecutor(), session, new TaskConfig()) builder = new ProcessBuilder() builder.environment().putAll( processor.getProcessEnvironment() ) @@ -69,11 +69,32 @@ class TaskProcessorTest extends Specification { } + def testFetchInterpreter() { + + when: + def processor = new DummyProcessor(new NopeExecutor(), new Session(), new TaskConfig()) + def script = + ''' + #!/bin/perl + do this + do that + ''' + def i = processor.fetchInterpreter(script.stripIndent().trim()) + then: + i == '/bin/perl' + + when: + processor = new DummyProcessor(new NopeExecutor(), new Session(), new TaskConfig()) + i = processor.fetchInterpreter('do this') + then: + i == null + } + static class DummyProcessor extends TaskProcessor { - DummyProcessor(AbstractExecutor executor, Session session, BaseScript script, TaskConfig taskConfig, Closure taskBlock) { - super(executor, session, script, taskConfig, taskBlock) + DummyProcessor(AbstractExecutor executor, Session session, TaskConfig taskConfig) { + super(executor, session, new DummyScript(), taskConfig, {}) } @Override