groovy

Interactively Run code against Grails Runtime Environment

I am working on some code to load some bootstrapping data into my Grails app. Something is not working with one of the classes I am trying to create, so it would be very convenient to be able to run that code interactively against the grails runtime environment and I am wondering if there is a way to do that. I know about the Grails ...

How do I reference the GroovyObject instance from MetaClass methods in Groovy?

This is a contrived example of what I want to do, but minimally expresses the behavior desired. I want to reference the instance of the object on which the property access is being invoked. I tried 'this' first, but that refers to the enclosing class rather than either the MetaClass or the String instance. String.metaClass.propertyMi...

Is there a way to call server side Groovy object method from client side JavaScript code via AJAX?

There is DWR which satisfies my needs in Java. I'm interested if there is any Groovier way to do the same thing - with convention over configuration, dynamic method invokation, etc. ...

Why is this groovy code throwing a MultipleCompilationErrorsException ?

I have the following groovy code : class FileWalker { private String dir public static void onEachFile(String dir,IAction ia) { new File(dir).eachFileRecurse { ia.perform(it) } } } walker = new FileWalker() walker.onEachFile(args[0],new PrintAction()) I noticed that if I place a def in front of walker , ...

What is your opinion of Groovy?

For your projects, did you have a favorable experience with Groovy? How big was the project? Were there issues with the language? Did you consider Jython, JRuby or Clojure? ...

Minimum JDK for Groovy

I'm looking to write some Groovy code to perform tasks inside of install anywhere but because of the platforms we support I'm restricted to java 1.5. Any idea if this will be sufficient to run the latest groovy? ...

Java Swing Table size problem

Hi, I'm having problems with JTables. I'm adding two tables to a panel, the tables are within a scrollpane, but when the app shows up, the tables always occupy more space than the number of rows, wasting my available space. I'm using groovy and swingbuilder to create the tables, here's the code: scrollPane(){ panel(layout: new Mig...

How do I convert a Groovy String array to a Java String Array?

I'm trying to call a methond on a Java class from a Groovy class. The Java method has a String array as a parameter, and I have a collection of Strings in my Groovy class. How do I convert the Groovy collection to a Java String array? Java Method: public class SomeJavaClass{ public void helpDoSomething(String[] stuff){ } } Gro...

Groovy range with a 0.5 step size

What's the most elgant way in Groovy to specify a range of integers and the 0.5 steps between them? e.g.: 1, 1.5, 2, 2.5, 3, 3.5, 4 Edit: To clarify: As an end result I need a range object for use in a Grails constraint. Though I suppose a list would be OK too. ...

Groovy way to dynamically invoke a Class

I know in Groovy you can invoke a method on a class/object using a string. For example: Foo."get"(1) /* or */ String meth = "get" Foo."$meth"(1) Is there a way to do this with the class? I have the name of the class as a string and would like to be able to dynamically invoke that class. For example, looking to do something like: ...

Unable to call a web service from Groovy

I'm going through the first examples from the new Java Web Services: Up and Running book. I tried to go through the SOAP client example for Java on page 13, but in Groovy. So here is my Groovy shell code: import javax.xml.namespace.QName import javax.xml.ws.Service import java.net.URL url = new URL("http://someURL?wsdl") qname = new Q...

Can you mix the JVM languages? ie: Groovy & Clojure

I understand that you can easily mix groovy&java, clojure&java, whateverJvmLang&java. Does this also mean I can have clojure and groovy code interact as well? If I use Grails or jRoR, can I also make use of clojure in that environment? ...

Can I use map coercion in groovy to mock a class with a constructor that has parameters?

Java example classes under test public class Sample { public void printPie() { System.out.println("Pie."); } } public class SampleCont { String _PIE; public SampleCont() { _PIE = "pie"; } public void printPie() { System.out.println(_PIE); } } public class SampleContArg { String...

Best practice for ignoring year in date for date ranges

I need to model some information about seasons, and need to track them based on start / end date in a year-agnostic way. I.e. I need to allow users to define summer as being between, say, May 15th and September 10th, and do that for all years. I'll need to do a lot of checking of the type isThisDateInSeason). All the date manipulati...

Eclipse Maven Plugin fails to create groovy-maven-archetype project

I have installed the Maven for Eclipse plugin from Sonatype. (update site: http://m2eclipse.sonatype.org/update/) I am creating a Maven project, and choosing to use the groovy-maven-archetype as my starting point. However, halfway through, I am seeing: 04/03/09 12:52:28 GMT: [FATAL ERROR] org.codehaus.mojo.groovy.stubgen.GenerateStu...

o.errors.allErrors.each { println it } by default when failing to save a domain object

When persisting domain objects using Grails/GORM I frequently find myself wondering why a save() call fails. This can easily be solved by adding the logic: if (!o.save()) { o.errors.allErrors.each { println it } } However, adding this everywhere I do a .save() adds a lot of duplicate code. In the spirit of DRY I'd like to configu...

How to make this Groovy string search code more efficient?

I'm using the following groovy code to search a file for a string, an account number. The file I'm reading is about 30MB and contains 80,000-120,000 lines. Is there a more efficient way to find a record in a file that contains the given AcctNum? I'm a novice, so I don't know which area to investigate, the toList() or the for-loop. th...

How can create a Junit4 Suite with Groovy?

I have @RunWith(Suite.class) @Suite.SuiteClasses( [ First.class,Second.class ]) public class MySuite{ } But eclipse doesn't give me a "Run As Junit4 Test". All the individual test classes work fine with GUnit, the groovy unit test runner built into eclipse. Any thoughts? ...

Are there any new Eclipse distributions?

I've been using EasyEclispe for a long time, and I've noticed that they haven't really kept up-to-date with the main Eclipse distro. So I was wondering if anybody knew of an EasyEclipse-like distribution that would contain common things people in different areas of Java/Groovy development might need. ...

Variable Naming Conventions For Maps / Lists

I am getting into Groovy language, which has dynamic typing (as well as optional static typing). It also has native support for Lists, Maps, and Ranges, so I find myself using lists and maps a lot, especially lists of lists, lists of maps, maps of lists, etc. In static languages (esp with Generics) you always have an idea of what yo...