groovy

"public class Foo" v.s. "class Foo" in Groovy domain classes

The following Groovy code creates a GORM-persisted domain class called Foo when written to grails-app/domain/Foo.groovy: class Foo { String someField } However, if I instead write "public class Foo" the class does NOT get GORM-persisted (i.e. no save() method injected, no database table created, etc.): public class Foo { String s...

Where can I find a good example of Open-Flash-Charts and Java

There are a handful of open-flash-charts tutorials on the web, mostly php from what I can see. I know there is a Java helper class, but I haven't found documentation or examples. The helper library is also includes in the ofcharts grails plugin. Java/Groovy or Grails suggestions welcome. thanks! ...

What are the key differences between Scala and Groovy?

On the surface Groovy and Scala look pretty similar, aside from Scala being statically typed, and Groovy dynamic. What are the other key differences, and advantages each have over the other? How similar are they really? Is there competition between the two? If so, who do you think will win in the long run? ...

Troubleshooting Grails/Groovy memory leaks?

I've got a Grails application that does a fairly decent amount of domain object creation and destruction, and it seems to run out of PermGen space at a very, very rapid rate. I've done the usual tweaks (bumped PermGen to 256M, enabled class GC, etc.), but no dice. Would anyone care to recommend some (and hopefully free or very low-cost...

How do I set an embedded Groovy scripts classpath?

I am trying to extend an Eclipse code builder (for generating DTOs from Hibernate VOs) - and it uses Groovy for its template system. The code it uses to create the groovy Script is a little weird (not what I see in the Groovy docs) but it works, mostly: GroovyShell shell = new GroovyShell(); script = shell.parse(source); Then, later...

Sandboxing Java / Groovy / Freemarker Code - Preventing execution of specific methods

I'm developing a system that allows developers to upload custom groovy scripts and freemarker templates. I can provide a certain level of security at a very high level with the default Java security infrastructure - i.e. prevent code from accessing the filesystem or network, however I have a need to restrict access to specific methods. ...

Groovy: How do I sort an ArrayList of String:s in length-of-string order?

How do I sort an ArrayList of String:s in length-of-string order in Groovy? Code: def words = ['groovy', 'is', 'cool'] // your code goes here: // code that sorts words in ascending length-of-word order assert words == ['is', 'cool', 'groovy'] There are certainly more than one way to do it - so I'll grant the answer to the person who ...

Identifying a map in groovy

While porting over a code fragment from python I've stumbled over a trivial problem: if isinstance(v['content'], dict): What would be the most elegant way to port this over to groovy? ...

How can I run the superscript plugin in Jedit?

The superscript plugin provides an environment to run a buffer text in different script engines. I have installed the plugin via the plugin manager -> superscript but now, when I enter in the buffer "2+2" and press "execute script" all I obtain is: bsh.util.BeanShellBSFEngine or org.apache.bsf.engines.activescript.ActiveScriptEngin...

Running a JUnit test from Groovy Console

How can I use the Groovy Console to kick off junit tests? (Currently using Groovy 1.6.0) ...

How can I use Groovy's mock.interceptor package to mock an objects constructor?

In my attempt to mock an object in Groovy using the mock.interceptor package: def mock = new MockFor(TheClass); mock.demand.theMethod{ "return" } mock.use { def underTest = new TheClass() println underTest.theMethod() } The problem I have is when creating TheClass() in the use{ block, it uses the actual constructor which, in t...

How to show a second MVC group as a dialog box in griffon

I can see how to instantiate a second MVC group, e.g. def (loginPaneModel, loginPaneView, loginPaneController) = createMVCGroup('LoginPane', 'LoginPane', [:]); view.loginPanel = loginPaneView.loginPanel But I don't want to show as part of my main window. I want it to pop up over it. What do I call to do that? Thanks...

Correct syntax to add a mime-mapping to web.xml in a grails plugin

I'm trying to add a mime-mapping element to the web.xml. My current best stab is: def doWithWebDescriptor = { xml -> xml + { 'mime-mapping' { 'extension'("htc") 'mime-type'("text/x-component") } } } I know the code is being run as the above actually outputs an invalid web.xml. The follo...

Is there an equivalent to Groovy in C#?

What is the closest thing to groovy/java combo in the C# .net world? If I am writing an app with static and dynamic parts, what's the dynamic part like groovy on the .NET runtime? ...

Jaspergrails problem

Hi! I am testing the jaspergrails plugin for Grails. I am following the tutorial for this plugin. I've created a trivial jasper report and I've put it under web-app\plugins\jasper-0.9.5\reports\all-races.jasper I am getting an exception Error 500: java.lang.Exception: No such report spec: reports\all-races.jasper or .jrxml Any hint wh...

How to override a java method from groovy

I have a groovy class that has the ability to write its output to a StringWriter. (via a setStringWriter method) In java I would use the following code: filter.setStringWriter(new StringWriter(){ @Override public void write(String string){ // do something with the string } }); For Groovy I'm told to use a closure, I...

Best groovy closure idiom replacing java inner classes?

As new to groovy... I'm trying to replace the java idiom for event listeners, filters, etc. My working code in groovy is the following: def find() { ODB odb = ODBFactory.open(files.nodupes); // data nucleus object database Objects<Prospect> src = odb.getObjects(new QProspect()); src.each { println it }; odb.close(); ...

Groovy syntax for regular expression matching

What is the Groovy equivalent of the following Perl code? my $txt = "abc : groovy : def"; if ($txt =~ / : (.+?) : /) { my $match = $1; print "MATCH=$match\n"; # should print "MATCH=groovy\n" } I know that TMTOWTDI (including the regular Java way) - but what is the "Groovy way" of doing it? This is one way of doing it, but it f...

Why would one use Groovy over Java?

What benefits does Groovy offer over the use of Java other than more complicated syntax? ...

How does one return from a groovy closure and stop its execution?

I would like to return from a closure, like one would if using a break statement in a loop. For example: largeListOfElements.each{ element-> if(element == specificElement){ // do some work return // but this will only leave this iteration and start the next } } In the above if statement I would lik...