Skip to content

Commit

Permalink
Fix Custom lib path is not added to the classpath #1213
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Jul 3, 2019
1 parent aed407e commit 8cef0e3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ class ScriptParser {

ScriptParser(Session session) {
this.session = session
}

ScriptParser(ClassLoader loader) {
this.classLoader = loader
this.classLoader = session.getClassLoader()
}

ScriptParser setSession( Session session ) {
Expand All @@ -80,6 +77,10 @@ class ScriptParser {
return this
}

protected ClassLoader getClassLoader() { classLoader }

protected Session getSession() { session }

ScriptBinding getBinding() { binding }

Object getResult() { result }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,18 @@ class ScriptParserTest extends Specification {
result == 'Script_01af1441'
}

def 'should set classpath' () {

given:
def CL = Mock(ClassLoader)
def SESS = Mock(Session) { getClassLoader() >> CL }

when:
def parser = new ScriptParser(SESS)
then:
parser.getSession() == SESS
parser.getClassLoader() == CL

}

}
23 changes: 23 additions & 0 deletions tests/checks/custom-lib.nf/.checks
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# check the ability to load custom script/classes in the
# local `lib` directory
#
set -e

# copy the test script in this directory
cp ${NXF_SCRIPT:-../../custom-lib.nf} test.nf

# crate a library class
mkdir -p lib
cat >lib/Foo.groovy <<EOL
class Foo {

static String hello() { "Hello world!" }

}
EOL

${NXF_CMD:-nextflow} run test.nf | tee stdout

[[ `< stdout grep -c 'Hello world!'` == 1 ]] || false

1 change: 1 addition & 0 deletions tests/custom-lib.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
println Foo.hello()

0 comments on commit 8cef0e3

Please sign in to comment.