Issue Details (XML | Word | Printable)

Key: GROOVY-2081
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Paul King
Reporter: Phil Walker
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

Script executes correctly when called with absolute path, but fails when called with relative path

Created: 25/Aug/07 05:24 PM   Updated: 08/Feb/08 01:26 AM
Component/s: None
Affects Version/s: 1.5.1
Fix Version/s: 1.6-rc-2

Time Tracking:
Not Specified

Environment: ubuntu linux, sun-java-6; also duplicated on windows/cygwin java1.5
Issue Links:
Duplicate
 


 Description  « Hide
The following 2-line script will run if called with an absolute path, but fails if called as ../bin/scriptName

Here's the script:

#!/usr/bin/env groovy
println("Yo!");

This may be an example of GROOVY-569, since renaming the script to have a .gr suffix seems to solve the problem.

I wasn't aware until reading GROOVY-569 that script names must have a dot!

This is very confusing: script names actually don't require a dot except in limited circumstances.
I've been using groovy for a year or so, and this is the first I've encountered this requirement. The "Groovy in Action"
book doesn't seem to mention this requirement, although all their examples seem to use .groovy suffix, so maybe it's in there somewhere.

I'm a keyboard junkie (100+ words per minute) and would like to be able to create short concise names for all my scripts, not
just bash / perl / etc. Scripting languages (at least in unix land).

For the sake of script developers coming from other languages, it would be preferable to strictly enforce this naming requirement in every case (e.g., "illegal script name: filename suffix is mandatory"), since it's very difficult to track down the cause of this problem. A frustrated developer is not likely to be searching for the phrase "script name" if the symptoms are relative to absolute versus relative path used with calling a script.

BTW, groovy rocks!



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Russel Winder added a comment - 29/Oct/07 04:42 AM - edited
I created a small hierarchy:

.
|-- bin
| `-- scriptName
\`-- location

and if scriptName is execute from the directory bin or by absolute path then it works fine. If called using ../bin/scriptName from location then:

> ../bin/scriptName
Caught: java.lang.NoClassDefFoundError: /
at ..class$(scriptName)
at ..<clinit>(scriptName)

I think this should be considered a blocker. I will raise the priority on this. If I have misunderstood or got something wrong, the change can be reverted.


Russel Winder added a comment - 29/Oct/07 04:56 AM - edited
Is this just another version of GROOVY-569 ?

Jochen Theodorou added a comment - 29/Oct/07 06:25 AM
if it is you can check it easily by giving the script any extension like .groovy

Russel Winder added a comment - 29/Oct/07 07:14 AM
Looks like it is then. If I have scriptNameAlt.groovy as a copy then it runs fine with a relative path.

I will mark this as a replica.


Russel Winder added a comment - 29/Oct/07 07:16 AM
This is a duplicate and so being closed.

Russel Winder added a comment - 19/Jan/08 03:00 AM
The script:
#! /usr/bin/env groovy
// -*- mode:groovy encoding:UTF-8 -*-

println ( 'Hello World' )

has the execute bit set so can be executed as a command (on a proper operating system anyway

This script executes fine using the command lines:

GROOVY_569
./GROOVY_569

assuming you are in the directory in which the script is. Even:

/home/users/russel/Progs/OddsByLanguage/Groovy/GROOVY_569

seems to work fine. However:

../Groovy/GROOVY_569

generates the original error:

Caught: java.lang.NoClassDefFoundError: /
        at ..class$(GROOVY_569)
        at ..get$class$$(GROOVY_569)
        at ..<clinit>(GROOVY_569)

I am therefore reopening this bug.


Paul King added a comment - 21/Jan/08 07:39 AM
OK, I committed a potential fix for this. It seems to work locally but if others want to give it a try, that would be great.

Russel Winder added a comment - 21/Jan/08 09:24 AM
Works for me from Subversion r10562. However this would give a fix relaease of 1.6.0. I guess more commit magic is needed to get this into 1.5.2.

Paul King added a comment - 21/Jan/08 04:07 PM - edited
Correct fix version to 1.6 for now, needs 1.5.2 added after merge.

Paul King added a comment - 08/Feb/08 01:26 AM
close off release 1.5.4