Gant scripts, java task and nested classpath element

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Gant scripts, java task and nested classpath element

Daniel Henrique Alves Lima
    Hi.

    I've written a comment about this newbie mistake/gotcha (???):
http://techdm.com/grails/?p=585&lang=en (item 3)
    Now I'm trying to understand if this is a bug or a limitation and
who I should blame: Gant, Grails or myself (for my lack of knowledge) :-)

// TestJava.groovy
    println 'classpath ' + classpath
// (...)
    //ant.path(id: 'defClasspath', { pathelement(location:
"${dir}/def.jar" )})

    ant.java(classname: 'def.Def', fork: true, dir: dir/*,
classpathref:'defClasspath'*/) {
        classpath {
            pathelement(location: "${dir}/def.jar")
        }
    }

    classpath seems a closure (println is outputing "classpath
org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16@5baa8241")
    So I can write anything inside the nested classpath and ant.java
task just fails because def.jar was not added to the classpath.

    Of course, If i use classpathref instead, everything works as
expected. It also works using ant.classpath or ant.java(classpath: ).

http://ant.apache.org/manual/Tasks/java.html

    Thanks in advance.

          Best regards,

                Daniel.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

def.jar (1K) Download Attachment
test-script.tar.bz2 (17K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Russel Winder
Daniel,

I am not totally sure how to quickly construct a small example of a Gant
script that exhibits the problem behaviour you are finding.  I have not
seen an example of a nested classpath failing in a Gant script, so my
initial hypothesis is that the problem is not with Gant per se.

Basically, If I create

+build.gant
+Material
| + def.jar

and extract the build script to be:

        import org.codehaus.gant.GantState
        target(main: "The description of the script goes here!") {
            def dir = new File('Material')
            GantState.verbosity = GantState.VERBOSE
            ant.logger.setMessageOutputLevel(GantState.verbosity)
            ant.java(classname: 'def.Def', fork: true, dir: dir) {
                classpath {
                    pathelement(location: "${dir}/def.jar")
                }
            }
        }
        setDefaultTarget(main)

Then I get:

        > gant
        main:
             [java] Executing '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
             [java] '-classpath'
             [java] '/home/users/russel/Progs/OddsByLanguage/Gant/DanielHenriqueAlvesLima_2011-08-11/Material/def.jar'
             [java] 'def.Def'
             [java]
             [java] The ' characters around the executable and arguments are
             [java] not part of the command.
             [java] def
        ------ main
       
        BUILD SUCCESSFUL
        Total time: 1.80 seconds




On Wed, 2011-08-10 at 18:44 -0300, Daniel Henrique Alves Lima wrote:

> Hi.
>
>     I've written a comment about this newbie mistake/gotcha (???):
> http://techdm.com/grails/?p=585&lang=en (item 3)
>     Now I'm trying to understand if this is a bug or a limitation and
> who I should blame: Gant, Grails or myself (for my lack of knowledge) :-)
>
> // TestJava.groovy
>     println 'classpath ' + classpath
> // (...)
>     //ant.path(id: 'defClasspath', { pathelement(location:
> "${dir}/def.jar" )})
>
>     ant.java(classname: 'def.Def', fork: true, dir: dir/*,
> classpathref:'defClasspath'*/) {
>         classpath {
>             pathelement(location: "${dir}/def.jar")
>         }
>     }
>
>     classpath seems a closure (println is outputing "classpath
> org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16@5baa8241")
>     So I can write anything inside the nested classpath and ant.java
> task just fails because def.jar was not added to the classpath.
>
>     Of course, If i use classpathref instead, everything works as
> expected. It also works using ant.classpath or ant.java(classpath: ).
>
> http://ant.apache.org/manual/Tasks/java.html
>
>     Thanks in advance.
>
>           Best regards,
>
>                 Daniel.
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[hidden email]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [hidden email]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Daniel Henrique Alves Lima
    Hi Russel. Thanks for your answers.
    I think the problem is the "classpath" closure defined somewhere in
Grails. Try this in your pure Gant script:

        import org.codehaus.gant.GantState
        target(main: "The description of the script goes here!") {
            classpath = {}
            def dir = new File('Material')
            GantState.verbosity = GantState.VERBOSE
            ant.logger.setMessageOutputLevel(GantState.verbosity)
            ant.java(classname: 'def.Def', fork: true, dir: dir) {
                classpath {
                    pathelement(location: "${dir}/def.jar")
                }
            }
        }
        setDefaultTarget(main)

 
    You will probably get:

     [java] Executing '/usr/local/jdk1.6.0_23/jre/bin/java' with arguments:
     [java] 'def.Def'
     [java]
     [java] The ' characters around the executable and arguments are
     [java] not part of the command.
     [java] Exception in thread "main" java.lang.NoClassDefFoundError:
def/Def
     [java] Caused by: java.lang.ClassNotFoundException: def.Def
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
     [java]     at java.security.AccessController.doPrivileged(Native
Method)
     [java]     at
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
     [java]     at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
     [java] Could not find the main class: def.Def.  Program will exit.
     [java] Java Result: 1


    If I set the classpath to null (in the Gant script inside my Grails
project), before calling ant.java, everything works fine.

    Thanks in advance.

          Best regards,

             Daniel.
   

Russel Winder wrote:

> Daniel,
>
> I am not totally sure how to quickly construct a small example of a Gant
> script that exhibits the problem behaviour you are finding.  I have not
> seen an example of a nested classpath failing in a Gant script, so my
> initial hypothesis is that the problem is not with Gant per se.
>
> Basically, If I create
>
> +build.gant
> +Material
> | + def.jar
>
> and extract the build script to be:
>
>         import org.codehaus.gant.GantState
>         target(main: "The description of the script goes here!") {
>             def dir = new File('Material')
>             GantState.verbosity = GantState.VERBOSE
>             ant.logger.setMessageOutputLevel(GantState.verbosity)
>             ant.java(classname: 'def.Def', fork: true, dir: dir) {
>                 classpath {
>                     pathelement(location: "${dir}/def.jar")
>                 }
>             }
>         }
>         setDefaultTarget(main)
>
> Then I get:
>
>         > gant
>         main:
>              [java] Executing '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
>              [java] '-classpath'
>              [java] '/home/users/russel/Progs/OddsByLanguage/Gant/DanielHenriqueAlvesLima_2011-08-11/Material/def.jar'
>              [java] 'def.Def'
>              [java]
>              [java] The ' characters around the executable and arguments are
>              [java] not part of the command.
>              [java] def
>         ------ main
>        
>         BUILD SUCCESSFUL
>         Total time: 1.80 seconds
>
>
>
>
> On Wed, 2011-08-10 at 18:44 -0300, Daniel Henrique Alves Lima wrote:
>  
>> Hi.
>>
>>     I've written a comment about this newbie mistake/gotcha (???):
>> http://techdm.com/grails/?p=585&lang=en (item 3)
>>     Now I'm trying to understand if this is a bug or a limitation and
>> who I should blame: Gant, Grails or myself (for my lack of knowledge) :-)
>>
>> // TestJava.groovy
>>     println 'classpath ' + classpath
>> // (...)
>>     //ant.path(id: 'defClasspath', { pathelement(location:
>> "${dir}/def.jar" )})
>>
>>     ant.java(classname: 'def.Def', fork: true, dir: dir/*,
>> classpathref:'defClasspath'*/) {
>>         classpath {
>>             pathelement(location: "${dir}/def.jar")
>>         }
>>     }
>>
>>     classpath seems a closure (println is outputing "classpath
>> org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16@5baa8241")
>>     So I can write anything inside the nested classpath and ant.java
>> task just fails because def.jar was not added to the classpath.
>>
>>     Of course, If i use classpathref instead, everything works as
>> expected. It also works using ant.classpath or ant.java(classpath: ).
>>
>> http://ant.apache.org/manual/Tasks/java.html
>>
>>     Thanks in advance.
>>
>>           Best regards,
>>
>>                 Daniel.
>>    
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Russel Winder
On Thu, 2011-08-11 at 00:14 -0300, Daniel Henrique Alves Lima wrote:

> Hi Russel. Thanks for your answers.
>     I think the problem is the "classpath" closure defined somewhere in
> Grails. Try this in your pure Gant script:
>
>         import org.codehaus.gant.GantState
>         target(main: "The description of the script goes here!") {
>             classpath = {}
>             def dir = new File('Material')
>             GantState.verbosity = GantState.VERBOSE
>             ant.logger.setMessageOutputLevel(GantState.verbosity)
>             ant.java(classname: 'def.Def', fork: true, dir: dir) {
>                 classpath {
>                     pathelement(location: "${dir}/def.jar")
>                 }
>             }
>         }
>         setDefaultTarget(main)
>
>  
>     You will probably get:
I did indeed :-)

But that is to be expected due to Groovy symbol look up and the way in
which builders are realized using the Groovy meta-object protocol.   The
meaning of classpath as a builder constructor only works so long as
there is no definition of the symbol classpath earlier in the lookup
than the meta-object protocol trigger that realizes the builder.

Looking at that last sentence I know what I mean, but I am not sure it
will transfer that meaning to you.  Rather than go into some long
ramble, I'll await a DoNotUnderstand exception.

The summary is that this may turn out to be a very deep (but not
necessarily meaningful :-) issue to put right, involving Grails, Gant,
and the Groovy AntBuilder.

>
>      [java] Executing '/usr/local/jdk1.6.0_23/jre/bin/java' with arguments:
>      [java] 'def.Def'
>      [java]
>      [java] The ' characters around the executable and arguments are
>      [java] not part of the command.
>      [java] Exception in thread "main" java.lang.NoClassDefFoundError:
> def/Def
>      [java] Caused by: java.lang.ClassNotFoundException: def.Def
>      [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>      [java]     at java.security.AccessController.doPrivileged(Native
> Method)
>      [java]     at
> java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>      [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>      [java]     at
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>      [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>      [java] Could not find the main class: def.Def.  Program will exit.
>      [java] Java Result: 1
--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[hidden email]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [hidden email]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Daniel Henrique Alves Lima
In reply to this post by Daniel Henrique Alves Lima
    And another way of reproducing the issue:

       import org.codehaus.gant.GantState

       target(name: 'classpath') {
           println 'Executing this target'
      }

       target(main: "The description of the script goes here!") {
           def dir = new File('Material')
           GantState.verbosity = GantState.VERBOSE
           ant.logger.setMessageOutputLevel(GantState.verbosity)
           ant.java(classname: 'def.Def', fork: true, dir: dir) {
               classpath {
                   pathelement(location: "${dir}/def.jar")
               }
           }
       }
       setDefaultTarget(main)

===
Executing this target
     [java] Executing '/usr/local/jdk1.6.0_23/jre/bin/java' with arguments:
     [java] 'def.Def'
     [java]
     [java] The ' characters around the executable and arguments are
     [java] not part of the command.
     [java] Exception in thread "main" java.lang.NoClassDefFoundError:
def/Def
     [java] Caused by: java.lang.ClassNotFoundException: def.Def
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
     [java]     at java.security.AccessController.doPrivileged(Native
Method)
     [java]     at
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
     [java]     at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
     [java] Could not find the main class: def.Def.  Program will exit.
     [java] Java Result: 1
===

    BTW, _GrailsClasspath.groovy has a target named as classpath.

    So
                classpath {
                   pathelement(location: "${dir}/def.jar")
               }

    Is invoking the 'classpath' closure (or target) passing another
closure as argument.
    So basically any nested element can be shadowed, right? Is this a
Groovy Builder thing and/or a desired/intentional feature?


    Thanks in advance.

          Best regards,

                Daniel.

Daniel Henrique Alves Lima wrote:

>    Hi Russel. Thanks for your answers.
>    I think the problem is the "classpath" closure defined somewhere in
> Grails. Try this in your pure Gant script:
>
>        import org.codehaus.gant.GantState
>        target(main: "The description of the script goes here!") {
>            classpath = {}
>            def dir = new File('Material')
>            GantState.verbosity = GantState.VERBOSE
>            ant.logger.setMessageOutputLevel(GantState.verbosity)
>            ant.java(classname: 'def.Def', fork: true, dir: dir) {
>                classpath {
>                    pathelement(location: "${dir}/def.jar")
>                }
>            }
>        }
>        setDefaultTarget(main)
>
>  
>    You will probably get:
>
>     [java] Executing '/usr/local/jdk1.6.0_23/jre/bin/java' with
> arguments:
>     [java] 'def.Def'
>     [java]
>     [java] The ' characters around the executable and arguments are
>     [java] not part of the command.
>     [java] Exception in thread "main" java.lang.NoClassDefFoundError:
> def/Def
>     [java] Caused by: java.lang.ClassNotFoundException: def.Def
>     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>     [java]     at java.security.AccessController.doPrivileged(Native
> Method)
>     [java]     at
> java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>     [java]     at
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>     [java] Could not find the main class: def.Def.  Program will exit.
>     [java] Java Result: 1
>
>
>    If I set the classpath to null (in the Gant script inside my Grails
> project), before calling ant.java, everything works fine.
>
>    Thanks in advance.
>
>          Best regards,
>
>             Daniel.
>  
> Russel Winder wrote:
>> Daniel,
>>
>> I am not totally sure how to quickly construct a small example of a Gant
>> script that exhibits the problem behaviour you are finding.  I have not
>> seen an example of a nested classpath failing in a Gant script, so my
>> initial hypothesis is that the problem is not with Gant per se.
>>
>> Basically, If I create
>>
>> +build.gant
>> +Material
>> |    + def.jar
>>
>> and extract the build script to be:
>>
>>         import org.codehaus.gant.GantState
>>         target(main: "The description of the script goes here!") {
>>             def dir = new File('Material')
>>             GantState.verbosity = GantState.VERBOSE
>>             ant.logger.setMessageOutputLevel(GantState.verbosity)
>>             ant.java(classname: 'def.Def', fork: true, dir: dir) {
>>                 classpath {
>>                     pathelement(location: "${dir}/def.jar")
>>                 }
>>             }
>>         }
>>         setDefaultTarget(main)
>>
>> Then I get:
>>
>>         > gant
>>         main:
>>              [java] Executing
>> '/usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java' with arguments:
>>              [java] '-classpath'
>>              [java]
>> '/home/users/russel/Progs/OddsByLanguage/Gant/DanielHenriqueAlvesLima_2011-08-11/Material/def.jar'
>>
>>              [java] 'def.Def'
>>              [java]              [java] The ' characters around the
>> executable and arguments are
>>              [java] not part of the command.
>>              [java] def
>>         ------ main
>>                 BUILD SUCCESSFUL
>>         Total time: 1.80 seconds
>>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Daniel Henrique Alves Lima
In reply to this post by Russel Winder
    Ignore my last message. I've sent it before reading your message :-)

    Thanks.

Russel Winder wrote:

> On Thu, 2011-08-11 at 00:14 -0300, Daniel Henrique Alves Lima wrote:
>  
>> Hi Russel. Thanks for your answers.
>>     I think the problem is the "classpath" closure defined somewhere in
>> Grails. Try this in your pure Gant script:
>>
>>         import org.codehaus.gant.GantState
>>         target(main: "The description of the script goes here!") {
>>             classpath = {}
>>             def dir = new File('Material')
>>             GantState.verbosity = GantState.VERBOSE
>>             ant.logger.setMessageOutputLevel(GantState.verbosity)
>>             ant.java(classname: 'def.Def', fork: true, dir: dir) {
>>                 classpath {
>>                     pathelement(location: "${dir}/def.jar")
>>                 }
>>             }
>>         }
>>         setDefaultTarget(main)
>>
>>  
>>     You will probably get:
>>    
>
> I did indeed :-)
>
> But that is to be expected due to Groovy symbol look up and the way in
> which builders are realized using the Groovy meta-object protocol.   The
> meaning of classpath as a builder constructor only works so long as
> there is no definition of the symbol classpath earlier in the lookup
> than the meta-object protocol trigger that realizes the builder.
>
> Looking at that last sentence I know what I mean, but I am not sure it
> will transfer that meaning to you.  Rather than go into some long
> ramble, I'll await a DoNotUnderstand exception.
>
> The summary is that this may turn out to be a very deep (but not
> necessarily meaningful :-) issue to put right, involving Grails, Gant,
> and the Groovy AntBuilder.
>
>  
>>      [java] Executing '/usr/local/jdk1.6.0_23/jre/bin/java' with arguments:
>>      [java] 'def.Def'
>>      [java]
>>      [java] The ' characters around the executable and arguments are
>>      [java] not part of the command.
>>      [java] Exception in thread "main" java.lang.NoClassDefFoundError:
>> def/Def
>>      [java] Caused by: java.lang.ClassNotFoundException: def.Def
>>      [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>>      [java]     at java.security.AccessController.doPrivileged(Native
>> Method)
>>      [java]     at
>> java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>>      [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>>      [java]     at
>> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>>      [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>>      [java] Could not find the main class: def.Def.  Program will exit.
>>      [java] Java Result: 1
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Jochen Theodorou
In reply to this post by Daniel Henrique Alves Lima
Am 11.08.2011 05:57, schrieb Daniel Henrique Alves Lima:

> And another way of reproducing the issue:
>
> import org.codehaus.gant.GantState
>
> target(name: 'classpath') {
> println 'Executing this target'
> }
>
> target(main: "The description of the script goes here!") {
> def dir = new File('Material')
> GantState.verbosity = GantState.VERBOSE
> ant.logger.setMessageOutputLevel(GantState.verbosity)
> ant.java(classname: 'def.Def', fork: true, dir: dir) {
> classpath {
> pathelement(location: "${dir}/def.jar")
> }
> }
> }
> setDefaultTarget(main)
[...]

how about replacing "classapth{" with "ant.classpath{" ?

bye blackdrag


--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Daniel Henrique Alves Lima
    Hi Jochen.

    I think you have missed this part of my explanation:

>     classpath seems a closure (println is outputing "classpath
> org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16@5baa8241")
>     So I can write anything inside the nested classpath and ant.java
> task just fails because def.jar was not added to the classpath.
>
>     Of course, If i use classpathref instead, everything works as
> expected. It also works using ant.classpath or ant.java(classpath: ).
>

    So it does work using classpathref, ant.classpath or
ant.java(classpath:). I'm now aware this behavior isn't bug, but we must
agree it may be very trick (for newcomers?) :-)

    Thanks.

    Best regards,

          Daniel.

Jochen Theodorou wrote:

> Am 11.08.2011 05:57, schrieb Daniel Henrique Alves Lima:
>> And another way of reproducing the issue:
>>
>> import org.codehaus.gant.GantState
>>
>> target(name: 'classpath') {
>> println 'Executing this target'
>> }
>>
>> target(main: "The description of the script goes here!") {
>> def dir = new File('Material')
>> GantState.verbosity = GantState.VERBOSE
>> ant.logger.setMessageOutputLevel(GantState.verbosity)
>> ant.java(classname: 'def.Def', fork: true, dir: dir) {
>> classpath {
>> pathelement(location: "${dir}/def.jar")
>> }
>> }
>> }
>> setDefaultTarget(main)
> [...]
>
> how about replacing "classapth{" with "ant.classpath{" ?
>
> bye blackdrag
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [groovy-user] Gant scripts, java task and nested classpath element

Daniel Henrique Alves Lima
http://jira.grails.org/browse/GRAILS-7879

Thanks.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email