groovy

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.6-rc-2
  • Component/s: None
  • Labels:
    None
  • Environment:
    ubuntu linux, sun-java-6; also duplicated on windows/cygwin java1.5
  • Number of attachments :
    0

Description

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!

Issue Links

Activity

Hide
Russel Winder added a comment - - 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.

Show
Russel Winder added a comment - - 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.
Hide
Russel Winder added a comment - - edited

Is this just another version of GROOVY-569 ?

Show
Russel Winder added a comment - - edited Is this just another version of GROOVY-569 ?
Hide
blackdrag blackdrag added a comment -

if it is you can check it easily by giving the script any extension like .groovy

Show
blackdrag blackdrag added a comment - if it is you can check it easily by giving the script any extension like .groovy
Hide
Russel Winder added a comment -

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.

Show
Russel Winder added a comment - 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.
Hide
Russel Winder added a comment -

This is a duplicate and so being closed.

Show
Russel Winder added a comment - This is a duplicate and so being closed.
Hide
Russel Winder added a comment -

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.

Show
Russel Winder added a comment - 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.
Hide
Paul King added a comment -

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.

Show
Paul King added a comment - 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.
Hide
Russel Winder added a comment -

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.

Show
Russel Winder added a comment - 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.
Hide
Paul King added a comment - - edited

Correct fix version to 1.6 for now, needs 1.5.2 added after merge.

Show
Paul King added a comment - - edited Correct fix version to 1.6 for now, needs 1.5.2 added after merge.
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: