groovy

Problem creating JSON with JsonGroovyBuilder in Groovy

I am new to JSON and Groovy. I can make an AJAX call to a groovlet and make it build some HTML codes with MarkupBuilder. Along with the HTML string being returned, I want a JSON string to be filled in one of a input text box. The problem is the use of JsonGroovyBuilder(). I can't even get the simplest example shown in Json-lib to run...

Using the grails Quartz plugin without Hibernate

I am working on a backend Grails application that pulls information periodically from a RESTful service. To do this I installed the Grails Quartz plugin. grails install-plugin quartz I then created a job using grails create-job My which geneates a MyJob file which I configured with a cron trigger static triggers = { cron name...

Array of strings in groovy

In ruby, there is a indiom to create a array of strings like this: names = %w( lucas Fred Mary ) Is there something like that in groovy? ...

Why is this (trivial) unit test failing?

This was taken nearly verbatim from IBM's Mastering Grails series. DateTagLib.groovy: class DateTagLib { def thisYear = { out << Calendar.getInstance().get(Calendar.YEAR) } } DateTagLibTests.groovy: class DateTagLibTests extends TagLibUnitTestCase { def dateTagLib protected void setUp() { super.setUp() ...

Including subprojects using a wildcard in a Gradle settings file

In Gradle you need to define subprojects to be built in a 'settings.gradle' file. To build three child projects, you would do something like this: include "child1", "child2", "child3" The problem I'm having is that I have quite a few projects to include. Is there a way to use a wildcard in this definition? I'm looking for something li...

How to force grails to download csv files ?

In my gsp view, I have this code : <g:each in="${fileResourceInstanceList}" status="i" var="fileResourceInstance"> <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> <td>${fileResourceInstance.decodeURL()}</td> <td><a href="${createLinkTo( dir:"/upload_data/datasets/ds"+signalDataInstance.datasetID , file: fileResourceInstance.decodeURL(),...

populate a comboBox in Griffon App dynamically

I have 2 comboBoxes in my View of Griffon App (or groovy swingBuilder) country = comboBox(items:country(), selectedItem: bind(target:model, 'country', value:model.country), actionPerformed: controller.getStates) state = comboBox(items:bind(source:model, sourceProperty:'states'), selectedItem: bind(targe...

Grails: org.hibernate.TransientObjectException

Simple Groovy\Grails code: def start = { source.save() def result = getJson(hotelSite, eng + index, [:]) parse(JSONObject.fromObject( result.json.text() )) render "OK" } def parse = {JSONObject json -> def cities = json.get("filter").cities println cities def kievHotels...

Groovy Read/Run DSL

I'm looking to create a new DSL using groovy, but I'm having trouble figuring out the best way to have groovy read the dsl. I want users to be able to create a dsl and actually run the dsl, without having to talk to the application code. game.groovy (as the dsl): import com.foo.groovygame.Game go north 10 search find ana turn right ...

Groovy/Grails plugin for Sonar

Sonar is an application for integrating output from several static and test analysis tools into a comprehensive overview of the software's quality. Unfortunately, most of those analysis tools (PDM, FindBugs, etc.) do not support Groovy and, by extension, Grails. We've found tools called CodeNarc and GMetrics which perform some of the a...

Writing tests that use GDB - how to capture output?

I am trying to write tests that interact with GDB but am having trouble capturing the output. I would like for a log file to be generated which looks like what would have been seen in a terminal had the test been executed by hand. GDB is proving to be very stubborn when it comes to capturing its output however. I've been able to write E...

Unable to start processes with options using JDK6

Consider the following script: println "ls -l".execute().text Why do I get the following error when running with JDK 1.6.0_14? Caught: java.io.IOException: Cannot run program "ls": java.io.IOException: error=40, Too many levels of symbolic links at a.run(a.groovy:2) When run with JDK 1.5.0_08 I get the expected output. This...

Which platforms have limited buffer sizes?

The Groovy Process Management page mentions that: Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock This snippet comes from the JDK API. ...

Groovy Prototype Object

I have a method with an incoming variable, which represents a script. e.g. hello.groovy Foo.init(this) Foo.groovy class Foo { static init(app) { } } What is the best way to add a ton of new functionality to the app variable in the init method? Basically, I would like to add all the functionality of another object to t...

Getting list of files

I have a directory named 'import' and would like to get all files and their corresponding date (based on filename). Sample content of the directory is this: input_02202010.xls input_02212010.xls input_02222010.xls I would like to have a Map that contains the path of the file and a Date variable. Can anyone show me how Groovy will s...

What do Groovy assertions look like with parentheses?

The example on this page only shows Groovy assertions without parentheses. assert a != null, 'First parameter must not be null' What would this look like if I wanted to include the parentheses? I presume that this is the closest equivalent to Perl's die() function (print error message and exit in one statement)? ...

What is the equivalent of $0 in a Groovy script?

With Perl and shell scripts, the variable $0 holds the name of the file containing the script. What is the equivalent in a Groovy script? ...

Can't see multiple-friends-selector in an iframe based canvas page

Hi, i have a facebook application running in an iframe canvas page. I connect to facebook with facebook connect and now i want that multiple friends selector. But it doesnt appear. I tried a Facebook fanbox - no problem, the fanbox appears correctly. Here is the code of the multipe friend selector: <fb:serverfbml style="width: 650p...

Clean Stack Traces in Groovy using Eclipse?

I am using Groovy in a Java Swing application as part of my plan to force-feed myself dynamic languages until I like them (which is happening, partly). My stack traces are filled with Groovy stuff like org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor is there a way to get Eclipse to...

groovy: how to simplify/rewrite this method in groovy

protected int xMethod (Integer a, Integer b) { if (a<b) return 1 else if (a>b) return 2 else return 3 } I wonder if there is some way of rewriting above method differently in groovy? as now is very Java style. ...