Chris Broadfoot | 1 Sep 2009 02:05
Picon
Gravatar

Re: [groovy-user] Regular Expression Evaluates Null As True?

agreed. I was simply explaining the 'why' - but I also think this is a bug. I think either returning false or throwing NPE is appropriate. Whether always returning null when matching against null is correct, I don't know.

2009/9/1 Jochen Theodorou <blackdrag-BA+cFGlbTmA@public.gmane.org>
Aaron Smith schrieb:
[...] [...]

Jochen - Just curious if you believe this behavior of null as a parameter is a bug when evaluated against a regular expression?  Seems to be at least one other person's belief.  Based on what I read about Groovy's use of the Null Object Pattern, seems the behavior is expected and just something that must be accounted for in my situation?

just because there exists such a pattern does not mean it was the intention to use it here. null.toString() is valid in Groovy, that I don't have a problem with. But in case of giving a null for the pattern it should either throw a NPE or handle the null object. This strange match on null.toString() looks plain wrong.


bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/


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

  http://xircles.codehaus.org/manage_email



Behrang Saeedzadeh | 1 Sep 2009 05:21
Picon
Gravatar

[groovy-user] Building Groovy 1.6.2 and 1.6.4 fails on Snow Leopard

Hi,

The other day I tried to install Groovy 1.6.4 via MacPorts on my SL but it failed as described here:


However, looks like the problem is that in the build.xml the "memorymaximumsize" is not set for a
javac call:


Modifying the build.xml as stated above should fix the problem. Only if someone could fix the
problem in the SVN...

Cheers,
Behrang Saeedzadeh
-------------------------------
http://my.opera.com/behrangsa
http://twitter.com/behrangsa
Roshan Dawrani | 1 Sep 2009 06:19
Picon

Re: [groovy-user] Regular Expression Evaluates Null As True?

Since it was something obviously wrong and had to be fixed, I took the liberty to fix it under GROOVY-3718. Pattern check against null now throws NPE and is consistent with Java.

rgds,
Roshan

On Tue, Sep 1, 2009 at 5:35 AM, Chris Broadfoot <chris <at> chrisbroadfoot.id.au> wrote:
agreed. I was simply explaining the 'why' - but I also think this is a bug. I think either returning false or throwing NPE is appropriate. Whether always returning null when matching against null is correct, I don't know.

2009/9/1 Jochen Theodorou <blackdrag-PsS3Ro0a8GY@public.gmane.orgg>

Aaron Smith schrieb:
[...] [...]

Jochen - Just curious if you believe this behavior of null as a parameter is a bug when evaluated against a regular expression?  Seems to be at least one other person's belief.  Based on what I read about Groovy's use of the Null Object Pattern, seems the behavior is expected and just something that must be accounted for in my situation?

just because there exists such a pattern does not mean it was the intention to use it here. null.toString() is valid in Groovy, that I don't have a problem with. But in case of giving a null for the pattern it should either throw a NPE or handle the null object. This strange match on null.toString() looks plain wrong.


bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/


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

  http://xircles.codehaus.org/manage_email




Roshan Dawrani | 1 Sep 2009 08:26
Picon

Re: [groovy-user] AST transformation to exit loops

I guess it means you should do it as :

class CustomSourceOperation extends CompilationUnit.PrimaryClassNodeOperation {
........
            public void visitForLoop(ForStatement forStatement) {
                Statement loopStmt = forStatement.getLoopBlock();
                if(!(loopStmt instanceof BlockStatement)) {
                    BlockStatement newBlock = new BlockStatement();
                    newBlock.addStatement(loopStmt);
                    forStatement.setLoopBlock(newBlock);
                }
                ((BlockStatement) forStatement.getLoopBlock())
                        .addStatement(buildInterruptNode());
            }
........
}

HTH.
Roshan

On Mon, Aug 31, 2009 at 8:36 PM, melix <cedric.champeau-kwIsuXZtyu5BDgjK7y7TUQ@public.gmane.org> wrote:

Thanks,

What do you mean exactly by stepping back one level ? I mean I see the idea,
but I'm not sure on how I can do that with a visitor...


HamletDRC wrote:
>
> My first thought is to just create a new process. In the times in the
> past when I've considered spawning a thread vs. spawning a process,
> I've almost always regreted choosing threads instead of processes.
>
> Anyway, if the original loopblock is not an expression then you need
> to step back one level and wrap that statement in a BlockExpression
> and then put your interrupt handling in that same new block statement.
>
>
> --
> Hamlet D'Arcy
> hamletdrc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
>
>
>
>
> On Wed, Aug 26, 2009 at 4:29 PM, melix<cedric.champeau-kwIsuXZtyu5BDgjK7y7TUQ@public.gmane.org> wrote:
>> Hi,
>>
>> I have written a DSL which is mostly used by non programmers. They write
>> "scripts" which are compiled at runtime and given some time to run. To do
>> this, each script is run in its own thread. If a timeout is reached, then
>> the thread is interrupted. However, you must know that Java does not
>> allow
>> "killing" a thread, so the elegant (and safe) way to interrupt a thread
>> is
>> to send the interrupt signal. The thread should periodically check if it
>> is
>> interrupted and stop.
>>
>> However, for my users, such considerations are far too difficult to
>> understand, and they may not intentionnaly write loops which never exit.
>> The
>> result is that even if the script timed out, the thread keeps running in
>> background.
>>
>> So I'm trying to use the AST transformations capabilities of Groovy 1.6
>> to
>> add safe exit conditions at compile time. Basically, for every loop :
>>
>> for (;;) { ... }
>>
>> I'd like to add the following statement :
>>
>> if (Thread.currentThread().isInterrupted()) break;
>>
>> It doesn't matter if the early exit of a loop triggers some exception,
>> the
>> idea is to kill the thread.
>>
>> Same thing should be done on while loops. I managed to write a simple
>> test
>> case which demonstrates this :
>>
>> public class InterruptASTTransform {
>>     public static Statement buildInterruptNode() {
>>         return new BlockStatement(new Statement[]{
>>                 new IfStatement(
>>                         new BooleanExpression(new
>> MethodCallExpression(new
>> StaticMethodCallExpression(new ClassNode(Thread.class), "currentThread",
>> new
>> ArgumentListExpression()), "isInterrupted", new
>> ArgumentListExpression())),
>>                         new BreakStatement(), new EmptyStatement())}, new
>> VariableScope());
>>     }
>>
>>     public static void main(String[] args) throws NoSuchMethodException,
>> InvocationTargetException, IllegalAccessException, InstantiationException
>> {
>>         MyClassLoader cl = new MyClassLoader();
>>         Class c = cl.parseClass(
>>                 "def t = new Thread({for (;;) {println 'ok'}} as
>> Runnable);"
>> +
>>                         "t.start();"
>>                         + "t.interrupt();"
>>         );
>>         ((Script) c.newInstance()).run();
>>     }
>>
>>     private static class MyClassLoader extends GroovyClassLoader {
>>         <at> Override
>>         protected CompilationUnit
>> createCompilationUnit(CompilerConfiguration config, CodeSource source) {
>>             CompilationUnit cu = super.createCompilationUnit(config,
>> source);
>>             cu.addPhaseOperation(new CustomSourceOperation(),
>> Phases.SEMANTIC_ANALYSIS);
>>             return cu;
>>         }
>>     }
>>
>>     private final static class CustomSourceOperation extends
>> CompilationUnit.PrimaryClassNodeOperation {
>>
>>         public void call(final SourceUnit source, GeneratorContext
>> context,
>> ClassNode classNode) throws CompilationFailedException {
>>             classNode.visitContents(new ClassCodeVisitorSupport() {
>>                 <at> Override
>>                 protected SourceUnit getSourceUnit() {
>>                     return source;
>>                 }
>>
>>                 <at> Override
>>                 public void visitForLoop(ForStatement forStatement) {
>>                     ((BlockStatement)
>> forStatement.getLoopBlock()).addStatement(
>>                             buildInterruptNode());
>>                 }
>>             });
>>         }
>>     }
>>
>> }
>>
>> However, I do have a problem. I can't see how I can add a statement if
>> the
>> original "loop block" from the for statement is not an expression
>> statement.
>> For example, the test case will fail with the following loop :
>>
>> for (;;) println 'ok'
>>
>> Is there any way to "replace" the loop block ? If not, how could I
>> proceed ?
>>
>> Thanks,
>>
>> Cedric
>>
>> ________________________________
>> View this message in context: AST transformation to exit loops
>> Sent from the groovy - user mailing list archive at Nabble.com.
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>
>
> -----
> --
> Hamlet D'Arcy
>
>

--
View this message in context: http://www.nabble.com/AST-transformation-to-exit-loops-tp25159084p25225055.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

   http://xircles.codehaus.org/manage_email



Jason Dillon | 1 Sep 2009 08:31
Gravatar

Re: [groovy-user] Executing multiple scripts with gmaven plugin

I suggest you read:

http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag

Specifically, executions is a child of plugin, not configuration.

--jason

On Sep 1, 2009, at 12:47 AM, Eduardo Leiva wrote:

>
> I try this with no luck:
> Can you post an example?
> Thanx
>            <plugin>
>                <groupId>org.codehaus.groovy.maven</groupId>
>                <artifactId>gmaven-plugin</artifactId>
>                <configuration>
>                    <executions>
>                        <execution>
>                            <source>
>                       ${pom.basedir}/src/main/script/testScript.groovy
>                            </source>
>                        </execution>
>                        <execution>
>                            <source>
>                       ${pom.basedir}/src/main/script/ 
> anotherScript.groovy
>                            </source>
>                        </execution>
>                    </executions>
>                </configuration>
>            </plugin>
>
> Jason Dillon wrote:
>>
>> Setup more than one execution.
>>
>> --jason
>>
>>
>> On Aug 29, 2009, at 3:49 AM, Eduardo Leiva wrote:
>>
>>>
>>> I am running one script by setting:
>>>           <plugin>
>>>               <groupId>org.codehaus.groovy.maven</groupId>
>>>               <artifactId>gmaven-plugin</artifactId>
>>>               <configuration>
>>>                   <source>
>>>
>>> ${pom.basedir}/src/main/groovy/script/testScript.groovy
>>>                   </source>
>>>               </configuration>
>>>           </plugin>
>>> in my pom.xml.
>>>
>>> How i can execute multiple scripts?
>>> Thanxs
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/Executing-multiple-scripts-with-gmaven-plugin-tp25196761p25196761.html
>>> Sent from the groovy - user mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>   http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Executing-multiple-scripts-with-gmaven-plugin-tp25196761p25227499.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

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

    http://xircles.codehaus.org/manage_email

Nocia | 1 Sep 2009 09:12
Picon

Re: [groovy-user] Hudson and groovydoc


Yes sorry.
I would like to know if anybody uses Sun Hudson and knows how to put a
groovy link in the menu or use the javadoc link in the Hudson project menu
to point on groovydoc.

This is the last link of the Hudson menu :
http://www.nabble.com/file/p25235411/Capture.png 
--

-- 
View this message in context: http://www.nabble.com/Hudson-and-groovydoc-tp25223375p25235411.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email

melix | 1 Sep 2009 09:27
Favicon

Re: [groovy-user] AST transformation to exit loops


Oh. Indeed, I missed the setter ;)

Roshan Dawrani wrote:
> 
> I guess it means you should do it as :
> 
> class CustomSourceOperation extends
> CompilationUnit.PrimaryClassNodeOperation {
> ........
>             public void visitForLoop(ForStatement forStatement) {
>                 Statement loopStmt = forStatement.getLoopBlock();
>                 if(!(loopStmt instanceof BlockStatement)) {
>                     BlockStatement newBlock = new BlockStatement();
>                     newBlock.addStatement(loopStmt);
>                     forStatement.setLoopBlock(newBlock);
>                 }
>                 ((BlockStatement) forStatement.getLoopBlock())
>                         .addStatement(buildInterruptNode());
>             }
> ........
> }
> 
> HTH.
> Roshan
> 
> On Mon, Aug 31, 2009 at 8:36 PM, melix <cedric.champeau@...>
> wrote:
> 
>>
>> Thanks,
>>
>> What do you mean exactly by stepping back one level ? I mean I see the
>> idea,
>> but I'm not sure on how I can do that with a visitor...
>>
>>
>> HamletDRC wrote:
>> >
>> > My first thought is to just create a new process. In the times in the
>> > past when I've considered spawning a thread vs. spawning a process,
>> > I've almost always regreted choosing threads instead of processes.
>> >
>> > Anyway, if the original loopblock is not an expression then you need
>> > to step back one level and wrap that statement in a BlockExpression
>> > and then put your interrupt handling in that same new block statement.
>> >
>> >
>> > --
>> > Hamlet D'Arcy
>> > hamletdrc@...
>> >
>> >
>> >
>> >
>> > On Wed, Aug 26, 2009 at 4:29 PM, melix<cedric.champeau@...>
>> wrote:
>> >> Hi,
>> >>
>> >> I have written a DSL which is mostly used by non programmers. They
>> write
>> >> "scripts" which are compiled at runtime and given some time to run. To
>> do
>> >> this, each script is run in its own thread. If a timeout is reached,
>> then
>> >> the thread is interrupted. However, you must know that Java does not
>> >> allow
>> >> "killing" a thread, so the elegant (and safe) way to interrupt a
>> thread
>> >> is
>> >> to send the interrupt signal. The thread should periodically check if
>> it
>> >> is
>> >> interrupted and stop.
>> >>
>> >> However, for my users, such considerations are far too difficult to
>> >> understand, and they may not intentionnaly write loops which never
>> exit.
>> >> The
>> >> result is that even if the script timed out, the thread keeps running
>> in
>> >> background.
>> >>
>> >> So I'm trying to use the AST transformations capabilities of Groovy
>> 1.6
>> >> to
>> >> add safe exit conditions at compile time. Basically, for every loop :
>> >>
>> >> for (;;) { ... }
>> >>
>> >> I'd like to add the following statement :
>> >>
>> >> if (Thread.currentThread().isInterrupted()) break;
>> >>
>> >> It doesn't matter if the early exit of a loop triggers some exception,
>> >> the
>> >> idea is to kill the thread.
>> >>
>> >> Same thing should be done on while loops. I managed to write a simple
>> >> test
>> >> case which demonstrates this :
>> >>
>> >> public class InterruptASTTransform {
>> >>     public static Statement buildInterruptNode() {
>> >>         return new BlockStatement(new Statement[]{
>> >>                 new IfStatement(
>> >>                         new BooleanExpression(new
>> >> MethodCallExpression(new
>> >> StaticMethodCallExpression(new ClassNode(Thread.class),
>> "currentThread",
>> >> new
>> >> ArgumentListExpression()), "isInterrupted", new
>> >> ArgumentListExpression())),
>> >>                         new BreakStatement(), new EmptyStatement())},
>> new
>> >> VariableScope());
>> >>     }
>> >>
>> >>     public static void main(String[] args) throws
>> NoSuchMethodException,
>> >> InvocationTargetException, IllegalAccessException,
>> InstantiationException
>> >> {
>> >>         MyClassLoader cl = new MyClassLoader();
>> >>         Class c = cl.parseClass(
>> >>                 "def t = new Thread({for (;;) {println 'ok'}} as
>> >> Runnable);"
>> >> +
>> >>                         "t.start();"
>> >>                         + "t.interrupt();"
>> >>         );
>> >>         ((Script) c.newInstance()).run();
>> >>     }
>> >>
>> >>     private static class MyClassLoader extends GroovyClassLoader {
>> >>          <at> Override
>> >>         protected CompilationUnit
>> >> createCompilationUnit(CompilerConfiguration config, CodeSource source)
>> {
>> >>             CompilationUnit cu = super.createCompilationUnit(config,
>> >> source);
>> >>             cu.addPhaseOperation(new CustomSourceOperation(),
>> >> Phases.SEMANTIC_ANALYSIS);
>> >>             return cu;
>> >>         }
>> >>     }
>> >>
>> >>     private final static class CustomSourceOperation extends
>> >> CompilationUnit.PrimaryClassNodeOperation {
>> >>
>> >>         public void call(final SourceUnit source, GeneratorContext
>> >> context,
>> >> ClassNode classNode) throws CompilationFailedException {
>> >>             classNode.visitContents(new ClassCodeVisitorSupport() {
>> >>                  <at> Override
>> >>                 protected SourceUnit getSourceUnit() {
>> >>                     return source;
>> >>                 }
>> >>
>> >>                  <at> Override
>> >>                 public void visitForLoop(ForStatement forStatement) {
>> >>                     ((BlockStatement)
>> >> forStatement.getLoopBlock()).addStatement(
>> >>                             buildInterruptNode());
>> >>                 }
>> >>             });
>> >>         }
>> >>     }
>> >>
>> >> }
>> >>
>> >> However, I do have a problem. I can't see how I can add a statement if
>> >> the
>> >> original "loop block" from the for statement is not an expression
>> >> statement.
>> >> For example, the test case will fail with the following loop :
>> >>
>> >> for (;;) println 'ok'
>> >>
>> >> Is there any way to "replace" the loop block ? If not, how could I
>> >> proceed ?
>> >>
>> >> Thanks,
>> >>
>> >> Cedric
>> >>
>> >> ________________________________
>> >> View this message in context: AST transformation to exit loops
>> >> Sent from the groovy - user mailing list archive at Nabble.com.
>> >>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe from this list, please visit:
>> >
>> >     http://xircles.codehaus.org/manage_email
>> >
>> >
>> >
>> >
>> > -----
>> > --
>> > Hamlet D'Arcy
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/AST-transformation-to-exit-loops-tp25159084p25225055.html
>> Sent from the groovy - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
> 
> 

--

-- 
View this message in context: http://www.nabble.com/AST-transformation-to-exit-loops-tp25159084p25235556.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email

Guillaume Laforge | 1 Sep 2009 11:31
Gravatar

Re: [groovy-user] Building Groovy 1.6.2 and 1.6.4 fails on Snow Leopard

Hi Behrang,

I've not upgraded to Snow Leopard yet, so I cannot really test that yet...
But just adding memorymaximumsize="${groovycMain_mx}" to the javac
call is enough to make Groovy build well with MacPorts?

Guillaume

On Tue, Sep 1, 2009 at 05:21, Behrang
Saeedzadeh<behrangsa@...> wrote:
> Hi,
> The other day I tried to install Groovy 1.6.4 via MacPorts on my SL but it
> failed as described here:
> http://lists.macosforge.org/pipermail/macports-users/2009-August/016398.html
> However, looks like the problem is that in the build.xml the
> "memorymaximumsize" is not set for a
> javac call:
> http://blog.jayway.com/2009/04/29/upgrading-groovy-to-162-fails-on-mac/
> Modifying the build.xml as stated above should fix the problem. Only if
> someone could fix the
> problem in the SVN...
> Cheers,
> Behrang Saeedzadeh
> -------------------------------
> http://my.opera.com/behrangsa
> http://twitter.com/behrangsa
>

--

-- 
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

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

    http://xircles.codehaus.org/manage_email

Behrang Saeedzadeh | 1 Sep 2009 14:26
Picon
Gravatar

Re: [groovy-user] Building Groovy 1.6.2 and 1.6.4 fails on Snow Leopard

Hi Guillaume,

After MacPorts failed to build Groovy on SL, I downloaded the Groovy 1.6.4 source bundle from the Groovy's website to build it on my machine and it threw an OOM exception but after adding the memorymaximumsize="${groovycMain-mx}" to the javac call I was able to build it successfully. But I am not %100 sure that the MacPorts problem is the same.

Best,
Behrang Saeedzadeh
-------------------------------
http://my.opera.com/behrangsa
http://twitter.com/behrangsa


On Tue, Sep 1, 2009 at 7:31 PM, Guillaume Laforge <glaforge-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org> wrote:
Hi Behrang,

I've not upgraded to Snow Leopard yet, so I cannot really test that yet...
But just adding memorymaximumsize="${groovycMain_mx}" to the javac
call is enough to make Groovy build well with MacPorts?

Guillaume

On Tue, Sep 1, 2009 at 05:21, Behrang Saeedzadeh<behrangsa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi,
> The other day I tried to install Groovy 1.6.4 via MacPorts on my SL but it
> failed as described here:
> http://lists.macosforge.org/pipermail/macports-users/2009-August/016398.html
> However, looks like the problem is that in the build.xml the
> "memorymaximumsize" is not set for a
> javac call:
> http://blog.jayway.com/2009/04/29/upgrading-groovy-to-162-fails-on-mac/
> Modifying the build.xml as stated above should fix the problem. Only if
> someone could fix the
> problem in the SVN...
> Cheers,
> Behrang Saeedzadeh
> -------------------------------
> http://my.opera.com/behrangsa
> http://twitter.com/behrangsa
>



--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

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

   http://xircles.codehaus.org/manage_email



Roger Studner | 1 Sep 2009 15:18
Picon
Gravatar

[groovy-user] setting properties on an object

I know i'm missing something obvious, so maybe this is an easy one.

I have a class:

class Example {
  def someProp
  def anotherProp
}

I have a map
def dataMapper = ["someProp":1, "anotherProp":2]

I was to do something like this:
def exampleObj = new Example()

dataMapper.each {key, value ->
   def getSomething = someFunc(value)
   exampleObj.key = getSomething
}

Now, this of course doesn't work since "key" doesn't exist on Example.

but I can't recall a syntax way to do this ${key} etc

Anyone :)?

Much thanks,
Roger

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

    http://xircles.codehaus.org/manage_email


Gmane