Repository: groovy Updated Branches: refs/heads/GROOVY_2_4_X 5f911f256 -> 3c0b7e871
GROOVY-7777 - groovysh cannot load script with shebang (closes #297) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3c0b7e87 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3c0b7e87 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3c0b7e87 Branch: refs/heads/GROOVY_2_4_X Commit: 3c0b7e871ef28c2dffd8301174753fb214775e06 Parents: 5f911f2 Author: John Wagenleitner <[email protected]> Authored: Mon Mar 21 18:22:53 2016 -0700 Committer: John Wagenleitner <[email protected]> Committed: Tue Mar 22 21:50:55 2016 -0700 ---------------------------------------------------------------------- .../tools/shell/commands/LoadCommand.groovy | 5 ++++- .../tools/shell/commands/LoadCommandTest.groovy | 6 ++++++ .../src/test/resources/groovy7777script | 21 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/3c0b7e87/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommand.groovy ---------------------------------------------------------------------- diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommand.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommand.groovy index 2383438..2393416 100644 --- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommand.groovy +++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommand.groovy @@ -81,7 +81,10 @@ class LoadCommand io.out.println("Loading: $url") } - url.eachLine { String it -> + url.eachLine { String it, int lineNumber -> + if (lineNumber == 1 && it.startsWith('#!')) { + return + } shell << it as String } } http://git-wip-us.apache.org/repos/asf/groovy/blob/3c0b7e87/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommandTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommandTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommandTest.groovy index e5c1d8b..72de085 100644 --- a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommandTest.groovy +++ b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/LoadCommandTest.groovy @@ -29,4 +29,10 @@ class LoadCommandTest void testLoad() { shell.execute(LoadCommand.COMMAND_NAME) } + + void testLoadScriptWithShebang() { + def script = getClass().getResource('/groovy7777script') + shell.execute("${LoadCommand.COMMAND_NAME} ${script}") + assert lastResult == 42 + } } http://git-wip-us.apache.org/repos/asf/groovy/blob/3c0b7e87/subprojects/groovy-groovysh/src/test/resources/groovy7777script ---------------------------------------------------------------------- diff --git a/subprojects/groovy-groovysh/src/test/resources/groovy7777script b/subprojects/groovy-groovysh/src/test/resources/groovy7777script new file mode 100644 index 0000000..2afa5aa --- /dev/null +++ b/subprojects/groovy-groovysh/src/test/resources/groovy7777script @@ -0,0 +1,21 @@ +#!/usr/bin/env groovy +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +myvar = 42 \ No newline at end of file
