Schalk Cronjé | 29 Jun 17:50 2016
Picon

For-loop vs each.

This questions is NOT about style, for if it was I would settle for using 'each' all the time. Np, this time I'm coming from a different angle. I am investigating backwards compatibility of Gradle plugins written in Groovy.

With Gradle 2.8, the embedded version of Groovy is 2.4.4, whereas with earlier 2.x versions it is a Groovy 2.3.x version. This leads to an 'interesting' situation where one might compile a Gradle plugin using Gradle 2.13 and then try to run it with say Gradle 2.1. Let's start with an example first.

Normally one might do the following:

void method(Set<String> collection)  {

collection.each { println it }
}
However if that is compiled with Groovy 2.4.x and then run with Groovy 2.3.x it will fail with NoSuchMethodError. This is usually due to GROOVY-6863. Most people will never see this as they will not usually go backwards. However in the Gradle situation this is real concern. So far in all cases that  I have seen I can work around the problem by writing

void method(Set<String> collection)  {

for( String it in collection)  { println it }
}
This brings me to the question, whether there is any performance problem here or is this a fine solution?

-- Schalk W. Cronjé Twitter / Ello / Toeter : <at> ysb33r
Raviteja Lokineni | 29 Jun 16:01 2016
Picon

How to use spring binding in groovy templates in a spring boot web project

Hi all,

I need help in understanding how to use spring binding in Groovy templates. I wasn't able to find much help in documentation. For example I have a form which has some attributes which needs to be bound on submission.

This example only speaks of Thymeleaf.

======================
FYI, if it helps anyone I got the generated URL for a controller in a groovy template by using the following code:

a (href: MvcUriComponentsBuilder.fromMappingName("SC#index").build()) {
    yield "Sentiment Analysis"
}

The Spring MVC mapping is generated using the capital letters (If the generated capital letters are not unique it uses the full class name) in the controller class name, hash and the method name.
======================

Thanks,
--
Raviteja Lokineni | Business Intelligence Developer
TD Ameritrade


Mario Garcia | 29 Jun 12:50 2016
Picon

Trying to understand why groovydoc task needs groovy-all in Gradle 2.13 / 2.14

I'm trying to execute a project using gradle 2.13 / 2.14 and it fails when executing groovydoc saying:

groovydoc doesn't support the "noTimestamp" attribute

Checking gradle documentation it's saying you should be using groovy-all, but sometimes I may not want to use the whole groovy-all jar.

Does anyone know why is this ? Is this a Gradle bug, it's something that changed in groovydoc ?

Mario
chavan77 | 28 Jun 09:24 2016
Picon

Handling multiple levels of unresolved properties

In my groovy DSL, it is possible to drill down into a piece of data, with
each level being handled dynamically

For example A is an entity that holds B which holds another entity C.

A.B.C.D will get the field D in the C entity. All entities are dynamically
created, meaning A does not have a field B, which does not have a field C
which does not have D. They are all looked up dynamically using getProperty.

a) How do I write a static type checker for this? I added a derived class
from AbstractTypeCheckingExtension. However for every missing property
(namely B, C and D) it calls handleMissingProperty inside this class. This
is cumbersome because only C knows it can contain D, likewise only B knows
about C and only A knows about B.

b) when handleMissingProperty is called for the missing D property, how do I
know that this was from the expression that starts with A, goes through B
and C. Meaning how do I walk the tree of the expression?

Is there a better way to do this?

--
View this message in context: http://groovy.329449.n5.nabble.com/Handling-multiple-levels-of-unresolved-properties-tp5733567.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Søren Martin Kristensen | 27 Jun 13:38 2016
Picon

the groovy *= operator differs in behaviour from that of java

Hello

I have just realized that *= differs in behaviour between groovy and java. The following source snipletsreturns 7 and 0 for groovy and java, respectively. However, I could not find any description of this in the list of differences between the two languages on  http://www.groovy-lang.org/differences.html

//groovy:
int a = 35;
int b = 20;
a *= b/100;
println a;

This script returns 7

//java:
public class test_multiply_operator {
  public static void main(String[] args) throws Exception {
    int a = 35;
    int b = 20;
    a *= b/100;
    System.out.println(Integer.toString(a));
  }
}

This java program returns 0. This is because java evaluates the right-hand expression before multiplication.

In case I have not missed something, I guess this would be nice to have on the list of differences between the two languages.

Best regards,
Søren
--
t.schoellhorn | 25 Jun 08:12 2016
Picon

TemplateEngines and Out of Memory

Hi, we are using Groovy in our web-application. There we create a "lot" of dynamic String and are handling that with the TemplateEngine as we need more complex expressions there. Now we noticed that we are running into a kind of weird OOM situation. I could narrow the problem down to a quite simple reproducible example:

package kos.tools.template; import java.util.HashMap; import java.util.Map; import javax.script.Bindings; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.SimpleBindings; public class Test { public static void main(String[] args) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("groovy"); String template = "step-${i}"; String groovy = "def engine = new groovy.text.GStringTemplateEngine();\n" + "def res = engine.createTemplate(template).make(bindings);\n" + "return res.toString();"; for (int i = 0; i (); vars.put("bindings", templateObjects); templateObjects.put("i", i); Object res = engine.eval(groovy, vars); if (i % 100 == 0) { System.out.println("->" + res); } } } } Running that example with an Oracle JDK 1.8 and a quite small memory (just for keeping the running time small) of 32M leads to an OOM at around 2500 steps. I opened up a disussion on Stackoverflow where John Vint gave me some hints (see here) and it might be also a bug of the GarbageCollector itself. But in essence I think there should be a way to use the TemplateEngine in a stable way. I am happy for any suggestions and examples of how to solve this situation. Tino
View this message in context: TemplateEngines and Out of Memory
Sent from the Groovy Users mailing list archive at Nabble.com.
Paul King | 25 Jun 00:01 2016
Picon
Gravatar

GenericsVisitor change for Groovy 2.5.0

Hi everyone,

I moved the GenericsVisitor earlier in the compilation process. This
means that errors involving class usage but supplying an incorrect
number of type parameters, e.g. List<Integer, Date, String> or
HashMap<Long> or invalid Diamond operator usage will now be flagged
earlier. This is nice because we had other parts of the compiler which
used to run prior to the generics visitor that assumed that such
information was correct and would fail with an
ArrayIndexOutOfBoundsException. In those circumstances we now get a
nicer error message.

The flip side is that if anyone had a DSL that relied on such invalid
syntax and had a transform that corrected the errors that ran in the
early stages of the compiler, then it will likely now run after the
GenericsVisitor which means the error will already be flagged. I am
not aware of any such usage of invalid Groovy syntax being relied upon
but if anyone is in that position, now is the time to let us know. You
can still use a global transform but there might be other workarounds
possible if you let us know the circumstances.

For further details see:

https://issues.apache.org/jira/browse/GROOVY-7865

Cheers, Paul.

Mr Andersson | 22 Jun 19:08 2016
Picon

Re: Is it possible to enable CompileStatic for an entire project



On 06/22/2016 07:02 PM, Mr Andersson wrote:


On 06/22/2016 03:06 PM, Alessio Stalla wrote:
Also good tests help. However I agree that if you prefer the tradeoffs that static languages give you then probably Groovy is not the wisest choice.


It's nice to have good speed in critical sections of the code without having to rewrite them in Java, but a fully static


Groovy IMHO is just a quirkier, slower, less supported Java with some nice syntactic sugar. It just wasn't designed for that.
That's exactly what I need at times. To be able to use Groovy alongside Java when I need to, to a minimal. Writing regexes, multiline strings, inline variable strings, writing sql, use some libraries on occasion, and other things that are really ugly to do in Java.

The static version for me would be a compliment to go the Groovy way when I need to, not replace Java.
To replace Java, I think a new Grooyv language that is written from scratch, has similar syntax as Java + Groovy, and performs equally would be required.

Java features are so slow to be developed that I am sure if the Groovy devs decided to fork the Java compiler and start adding many new features it would develope so much faster.

Basically, the world is crying out for a fork of Java, that can develope the language faster than Oracle. Not a completely new language that runs on the JVM.


I once saw a seminar of someone hacking the Java compiler in 20 minutes to add the elvis operator. Now, consider adding closures ( better syntax than Java lambdas ) and removing all other cludd that Java requires, and we have a hit run.

Many just need to write less code

On 22 June 2016 at 14:50, Thibault Kruse <tibokruse-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
> People want to be able to refactor without risking of the code eventually
> breaking totally, and that's the problem with Groovy. Code will eventually
> become stale and stop working if it is put on layway for a while. No compile
> time checks is a problem for anyone interested in code quality.

For that purpose, it might be sufficient to make <at> TypeChecked the
default, or a compiler option.
That would catch most such problems at compile time.



Mr Andersson | 21 Jun 14:24 2016
Picon

Is it possible to enable CompileStatic for an entire project

Is it possible to enable CompileStatic for an entire project?

Or do you have to do it on a per class basis?

I like Groovy for some of it's features, and mostly for it's close to 
Java syntax but I would really like it to be a static language.

I've heard about Groovy++ but I believe that's dead by now, no?

Question is wether you can tell the Groovy compiler with a flag to treat 
all Groovy classes on certain paths as static?

Preferable doable from ANT too.

Aplomb Chen | 19 Jun 15:00 2016
Picon
Gravatar

Groovy hot deploy in production

Hi Guys, 


Will you use groovy hot deploy in production environment? Is it reliable to do so?


I am worried that it may have issue when you are doing below, 

1, Defined a Array as class attribute, make it has 10000 objects, next time code hot deploy that the array is erased in code, then that must be an memory leak, right?

2, If you execute a periodic timertask in a groovy, next time code hot deployed, if the timetask is no longer needed from your code, but the started timertask will still be running, right?


If we demands developers avoid using class attributes or starting any thread thing as a development rule, will hot deploy still be good for production?


Aplomb

Best regards

Mr Andersson | 18 Jun 13:40 2016
Picon

Integrating Groovy with a Java EE application and Maven

Hi,

I can not find any info on this online that will actually work.

I've tried:

<dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy</artifactId> <version>2.4.7</version> </dependency> as well as <plugin> <inherited>true</inherited> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <!--!!!!!!!!!!!!!!!! ALSO TRIED WITHOUT THESE TWO LINES !!!!!!!!!!!!!!!! --> <compilerId>groovy-eclipse-compiler</compilerId> <verbose>true</verbose> <!-- See: http://stackoverflow.com/questions/17944108/maven-compiler-plugin-always-detecting-a-set-of-sources-as-stale --> <useIncrementalCompilation>false</useIncrementalCompilation> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.9.2-01</version> </dependency> </dependencies> </plugin> but this results in an error when a Java class is referencing a Groovy class in the project. I am not using eclipse. What are the neccesary steps to get Groovy to work seamlessly in a Groovy project in 2016 ? What are the limitations? Thanks!

Gmane