ocs.cz | 12 Feb 12:20 2016
Picon

dynamically attached object/added ivar

Hello there,

have we in Groovy an API which would serve as a reliable replacement of “dynamically attached objects”
or “dynamically added ivars” of other APIs? I mean a way to reasonably implement something like
"x_attach" and "x_attached" here:

def foo=... // any object of any class, typically some Map, but not necessarily
def tag=... // any object of any class, possibly even a class itself

foo.x_attach(tag)
def bar=foo // just to emphasize the attachment is object's, not variable's property

... throughout the code, "foo" and "bar" can be used normally, all APIs and libraries etc. work with it the
very same way they would without "x_attach" ...

assert bar.x_attached().is(tag) // but later, I can get the attached object

When the object foo/bar gets garbage-collected, it's attachment loses an active link and (presumed it is
not referenced from another place) gets garbage-collected too. Due to this demand, it is rather
inconvenient to simulate the attachments by a static map indexed e.g., by
System.identityHashCode(foo), for -- far as I know at least -- there is no convenient API to determine
when a generic object (whose finalize I cannot override) goes poof (and thus its attachment should be
removed from the map).

Thanks for any advice,
OC

Marcin Erdmann | 11 Feb 22:30 2016
Picon
Gravatar

[ANN] Geb 0.13.0 released

Hi everyone,

Version 0.13.0 of Geb is now available from Maven Central.

The highlights of this version are the ability to take reports on test failures only when using Geb with Spock or JUnit integrations, small performance improvements around setting text input values and general error reporting improvements.

This release also contains a significant breaking change - a number of Navigator methods that would operate on first element of a multi element Navigator now throw an exception when called on a multi element navigator. This has been done to achieve a less surprising behaviour - these methods are hardly ever called on multi element Navigators on purpose and if they need to be called on all elements of a Navigator then it can be simply done by using the spread operator.

A full list of changes is as usual available from the Book of Geb: http://www.gebish.org/manual/current/#0-13-0.

Cheers,
Marcin
Thierry Hanser | 11 Feb 20:13 2016

GroovyShell : Can't modify (reassign) a variable within a script compiled with GroovyShell

Dear fellow Groovy users,

 

I stumbled over this unexpected behaviour. I was trying to access and modify a variable declared in a base script class using the GroovyShell parser. Below is a minimal code illustrating the issue. Although I can access the variable from the compiled script, I can’t seem to change its value!. This was unexpected. I tried all combinations of setters/getters/visibility and can at the best read but never modify the variable ‘x’. The same behaviour occurs with using the GroovyScriptEngine or GroovyClassLoader

 

1.   Am I doing something wrong (stupid?) or is there a bug/limitation in the current parsing/compilation process?

2. Which is as today the preferred compiler class between GroovyScriptEngine, GroovyShell and GroovyClassLoader?

 

Merci/Thank you very much in advance for your help.

 

Thierry

-

 

import org.codehaus.groovy.control.CompilerConfiguration;

import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer;

 

import groovy.lang.Binding;

import groovy.lang.Closure

import groovy.lang.GroovyClassLoader;

import groovy.lang.GroovyShell;

import groovy.transform.CompileStatic;;

 

abstract class GroovyDemoScript extends Script

{

    public String x;

 

    public GroovyDemoScript()

    {

           x='one';

           System.out.println("init x: " + x);

    }

 

     /**

     * Demo main

     * <at> param args

     * <at> throws Throwable

     */

    public static void main(String...args) throws Throwable

    {

           ////

           // Compilation configuration

           CompilerConfiguration configuration = new CompilerConfiguration();

           configuration.addCompilationCustomizers(new ASTTransformationCustomizer(CompileStatic.class));

           configuration.setScriptBaseClass(GroovyDemoScript.class.name);

           GroovyShell shell = new GroovyShell(this.getClass().getClassLoader(), new Binding(), configuration);

 

           // source code

           String scriptSource= "println '1 = ' + x; x = 'two'; println '2 = ' + x\n";

          

           // compile the source code and run the compiled script

           GroovyDemoScript compiledScript = shell.parse(scriptSource);

          compiledScript.run();

    }

}

 

Output:

 

init x: one  <- initial value assignement OK J

1 = one      <- successfully accessing ‘x’ from within the compiled script OK J

2 = one      <- should be ‘two’ as instructed but is unchanged ??? L

 

 

Switchboard: +44 (0)113 394 6020

Technical Support: +44 (0)113 394 6030

Lhasa Limited, a not-for-profit organisation, promotes scientific knowledge & understanding through the development of computer-aided reasoning & information systems in chemistry & the life sciences. Registered Charity Number 290866. Registered Office: Granary Wharf House, 2 Canal Wharf, Leeds, LS11 5PS. Company Registration Number 01765239. Registered in England and Wales.

This communication, including any associated attachments, is intended for the use of the addressee only and may contain confidential, privileged or copyright material. If you are not the intended recipient, you must not copy this message or attachment or disclose the contents to any other person. If you have received this transmission in error, please notify the sender immediately and delete the message and any attachment from your system. Except where specifically stated, any views expressed in this message are those of the individual sender and do not represent the views of Lhasa Limited. Lhasa Limited cannot accept liability for any statements made which are the sender's own. Lhasa Limited does not guarantee that electronic communications, including any attachments, are free of viruses. Virus scanning is recommended and is the responsibility of the recipient.

Melissa Warnkin | 11 Feb 19:23 2016
Picon

ApacheCon NA 2016 - Important Dates!!!

Hello everyone!

I hope this email finds you well.  I hope everyone is as excited about ApacheCon as I am!

I'd like to remind you all of a couple of important dates, as well as ask for your assistance in spreading the word! Please use your social media platform(s) to get the word out! The more visibility, the better ApacheCon will be for all!! :)

CFP Close: February 12, 2016
CFP Notifications: February 29, 2016
Schedule Announced: March 3, 2016



Apache: Big Data North America 2016 Registration Fees:

Attendee Registration Fee: US$599 through March 6, US$799 through April 10, US$999 thereafter
Committer Registration Fee: US$275 through April 10, US$375 thereafter
Student Registration Fee: US$275 through April 10, $375 thereafter

Planning to attend ApacheCon North America 2016 May 11 - 13, 2016? There is an add-on option on the registration form to join the conference for a discounted fee of US$399, available only to Apache: Big Data North America attendees.

So, please tweet away!!

I look forward to seeing you in Vancouver! Have a groovy day!!

~Melissa
on behalf of the ApacheCon Team


Gerald Wiltse | 10 Feb 16:52 2016
Picon
Gravatar

Behavior of .with() inside Trait

This example returns the error inside the with closure: 

      "No such property: cow for class:Bar"

It seems .with() in a trait does not resolve the way it "normally" does.


trait Foo {
    def action() {
        println binding.cow
        binding.with {
            println cow
        }
    }
}

class Bar implements Foo {
  Binding binding = new Binding()
}


def myBar = new Bar()
myBar.binding.cow = "says moo"
myBar.action()


If anyone has any insight, it would be helpful.


David M. Karr | 8 Feb 23:17 2016
Picon
Gravatar

Escaping unicode reference in slashy string

Someone was trying to point out difficulties with various string values 
in slashy strings.  I was able to refute most of his arguments, but he 
pointed out a curious issue involving unicode sequences.

If you have the following:
--------------
def var = /c:\uabc.txt/
---------------

This will fail to compile, as "\uabc." is not a valid unicode sequence.

So, the obvious thing to try is this:
------------------
def var = /c:\\uabc.txt/
------------------

That would fix it, right?  Well, sort of.  It doesn't get a compile 
error.  I expected it to produce "c:\uabc.txt", but instead it produced 
"c:\\uabc.txt".

What are relatively simple workarounds for this?

Strachan, Paul | 8 Feb 15:11 2016
Picon

not sure about Collection.intersect

Groovy 2.4.4 / 2.4.5

 

Hi – I’d like to get a list of objects from collection A that exist in collection B using intersect() but I’m getting no results:

 

def c1 = []// as Set
def c2 = []// as Set
c1 << new TestClass(name: 'mike')
c2 <<
new TestClass(name: 'mike')
println c1.contains(c2[
0])
assert c1.intersect(c2).size() == 1

 

 

Output:

 

true

Assertion failed:

 

assert c1.intersect(c2).size() == 1

       |  |         |   |      |

       |  []        |   0      false

       |            [sample.TestClass <at> 333357]

       [sample.TestClass <at> 333357]

 

 

TestClass.groovy

 

package sample

import groovy.transform.EqualsAndHashCode
<at> EqualsAndHashCode
(includes = 'name')

class TestClass {
    String
name
}

 

 

Is intersect only for simple types?

 

 


**********************************************************************
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**********************************************************************

cyprushelp | 5 Feb 03:13 2016
Picon

Groovysh in non-interactive mode

Hello,

Groovysh no longer works in non-interactive mode.

1) Before Groovy 2.4, you could run groovysh in non-interactive mode. It would execute the action and then quit. This made it useful when embedding in shell scripts etc.
2) Before Groovy 2.4, you could pass arguments to groovysh in non-interactive mode. For example, I had some custom commands which I could execute not only from within the shell, but also outside of the shell.

Both these features seem to be gone in latest Groovy 2.4.5 release. They were useful and a lot of code depended on them. I wonder if someone has any workarounds. I am not sure if the changes in https://issues.apache.org/jira/browse/GROOVY-6754 caused this.

Before (groovy 2.3.9):
user <at> machine:~$ groovysh :show all
No variables defined
No classes have been loaded
No custom imports have been defined
Preferences:
    verbose=false
===> [null, null, null, null]
user <at> machine:~$

After (groovy 2.4.5):
user <at> machine:~/opt/groovy-2.4.5/bin$ ./groovysh :show all
Groovy Shell (2.4.5, JVM: 1.8.0_51)
Type ':help' or ':h' for help.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000> :load :show
File not found: ":show"
groovy:000> :load all
File not found: "all"
groovy:000>
Les Hartzman | 5 Feb 02:01 2016
Picon

<at> Builder and derived clases?

I'm trying to use <at> Builder on a derived class, but it doesn't appear to go through the class tree.

Is there a way around this?

Thanks.

Les

Anton Sarov | 3 Feb 16:24 2016
Picon

GroovyShell Binding with TypeChecked

Hello,

I have the following case where I want to make use of the type checking feature:

http://groovyconsole.appspot.com/script/5121843795066880


Unfortunately I get an error like: "The variable [util] is undeclared".

Why is this happening? I defined a variable in the provided binding but apparently this is somehow not relevant to the Groovy Shell...

Best regards
Anton
startup failed: Script1.groovy: 7: [Static type checking] - The variable [util] is undeclared. <at> line 7, column 17. def a = util.test(); ^ 1 errorstartup failed: Script1.groovy: 7: [Static type checking] - The variable [util] is undeclared. <at> line 7, column 17. def a = util.test(); ^ 1 errorstartup failed: Script1.groovy: 7: [Static type checking] - The variable [util] is undeclared. <at> line 7, column 17. def a = util.test(); ^ 1 errorstartup failed: Script1.groovy: 7: [Static type checking] - The variable [util] is undeclared. <at> line 7, column 17. def a = util.test(); ^ 1 error
startup failed: Script1.groovy: 7: [Static type checking] - The variable [util] is undeclared. <at> line 7, column 17. def a = util.test(); ^ 1 error
David M. Karr | 2 Feb 20:42 2016
Picon
Gravatar

Example of CliBuilder with "optionalArg: true"?

Because someone asked me a question about it, I was looking at 
CliBuilder, for a scenario where "optionalArg" is true, and to get the 
value of the option, or detect that it's not present.  I've looked at 
the groovydoc, and CliBuilderTest, but it's not clear to me how this works.


Gmane