Repository: groovy
Updated Branches:
  refs/heads/master 91406a76c -> 819161770


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/81916177
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/81916177
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/81916177

Branch: refs/heads/master
Commit: 81916177000349b0991019dfd2f0c744410fb80d
Parents: 91406a7
Author: John Wagenleitner <jwagenleit...@apache.org>
Authored: Mon Mar 21 18:22:53 2016 -0700
Committer: John Wagenleitner <jwagenleit...@apache.org>
Committed: Tue Mar 22 21:43:11 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/81916177/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 baac9e9..30833f4 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/81916177/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/81916177/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

Reply via email to