Defining functions in text processed by the StreamingTemplateEngine

2022-07-23 Thread Per Nyfelt
Hi, I am trying to use the StreamingTemplateEngine to create dynamic markdown (similarly to the rmd (r markdown, https://rmarkdown.rstudio.com/authoring_quick_tour.html) but I've encountered a snag: Simple usage such as the following works fine using the StreamingTemplateEngine: def text

Re: Defining functions in text processed by the StreamingTemplateEngine

2022-07-23 Thread Per Nyfelt
her out.println "- " + dayName(day) + ": " + weather.first() } %> """.stripIndent() def engine = new StreamingTemplateEngine() def template = engine.createTemplate(text) println template.make() On 7/23/22 19:59, Per Nyfelt wrote: Hi, I am trying to use t

Re: Defining functions in text processed by the StreamingTemplateEngine

2022-07-24 Thread Per Nyfelt
t;Cloudy", "Windy" ] Const.days.times { out.println "- " + dayName(now + it) + ": " + weather.shuffled()[0] } %> """.stripIndent() def engine =new groovy.text.SimpleTemplateEngine() def template =engine.createTemplate(text) printlntemplate.make

Re: Ginq: combining join and aggregate functions

2024-10-12 Thread Per Nyfelt
/spec/test/org/apache/groovy/ginq/GinqTest.groovy#L4789 Cheers, Daniel Sun On 2024/10/05 17:16:02 Per Nyfelt wrote: Hi, I am trying to learn Ginq and are having problems with joining an aggregation functions. The following example illustrates the issue: import java.time.LocalDate class

Re: Ginq: combining join and aggregate functions

2024-10-06 Thread Per Nyfelt
orderby w.name in desc select w.name, sum(w.price) } assert [['Orange',22.0], ['Banana',4.0]] == q2.toList() I submitted a feature request in Jira to support use of join, groupby and aggregate functions together. Regards, Per On 10/5/24 19:16, Per Nyfelt wrote: Hi, I am trying

Ginq: combining join and aggregate functions

2024-10-05 Thread Per Nyfelt
Hi, I am trying to learn Ginq and are having problems with joining an aggregation functions. The following example illustrates the issue: import java.time.LocalDate class Warehouse {     int id     String name     Double price     int stock     Warehouse(int id, String name, Double price, int

Re: Ginq: combining join and aggregate functions

2024-10-08 Thread Per Nyfelt
can create a nested statement and do it all at once def qSum = GQ { from n in ( from s in sales join w in warehouse on w.id<http://w.id/> == s.item select w.name<http://w.name/>, w.price) groupby n.name<http://n.name/> select n.name<http://n.n

Re: PlusEquals?

2024-10-28 Thread Per Nyfelt
ent=webmail> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail;> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> On Mon, Oct 28, 2024 at 4:02 AM Per Nyfelt mailto:p...@alipsa.se>> wrote: > > Hi, > > I

PlusEquals?

2024-10-27 Thread Per Nyfelt
Hi, Is it possible to override plus equals  (+=)  for a class? I have a class the is want plus to be immutable and plusEquals to be mutable e.g: def newMatrix = myMatrix + additionalRows assert myObj == myMatrix - additionalRows myMatrix += additionalRows assert myMatrix == newMatrix Sinc

Re: How to access global variables from a class?

2024-09-23 Thread Per Nyfelt
You have a scope problem and need to move the logger declaration into your A class. Also if slf4j is not available in your classpath, @Grab is your friend. The following works when running the script in the GroovyScriptEngine: @Grab('org.slf4j:slf4j-simple:2.0.16') import org.slf4j.LoggerFacto

Using NV macro in a method

2024-09-23 Thread Per Nyfelt
Is there a way to use the NV macro to get to the original name when used in a method? ```groovy class Person {   int id   String Name   Person(int id, String name) {     this.id = id     this.name=name   } } def per = new Person(1, 'Per') println "The person object is named ${NV(per).name}" d

Re: How to access global variables from a class?

2024-09-23 Thread Per Nyfelt
ich may or may not be feasible in your case: @Grab('org.slf4j:slf4j-simple:2.0.16') import org.slf4j.LoggerFactory import org.slf4j.Logger logger = LoggerFactory.getLogger("l") def c = {     logger.info("L") } c.call() On 9/23/24 22:17, Per Nyfelt wrote: You h

Bootstrap/pre-processing class?

2025-01-12 Thread Per Nyfelt
Hi, One of the companies i work for has moved to Google Artifact Registry (GAR) which does not work well with @Grab so I am attempting to write an alternative that uses maven (with some extensions handling GAR communication) for dependency resolution. My problem is that in order for this to

Re: Bootstrap/pre-processing class?

2025-01-14 Thread Per Nyfelt
above might also work. The advantage of using Grab is that it is already plumbed into the compilation process (in terms of adding to the classpath when needed). Hopefully I will get back to looking at that again soon. Paul. On Sun, Jan 12, 2025 at 8:45 PM Per Nyfelt mailto:p...@alipsa.se>&

Re: Launching a javafx application from a groovy script

2025-04-08 Thread Per Nyfelt
;$javafxVersion",classifier:"$classifier") Grape.grab(group:'org.openjfx',module:'javafx-web',version:"$javafxVersion",classifier:"$classifier") Grape.grab(group:'org.openjfx',module:'javafx-media',version:"$javafxVersio

Launching a javafx application from a groovy script

2025-04-08 Thread Per Nyfelt
Hi, I have a javafx application published to a nexus server that I want to launch from a groovy script. The application has javafx jar defined as compileOnly (provided in maven lingo) so javafx must be added to the classpath. When i use a full jdk that includes javafx the applicaton works g

Grab and boms

2025-04-22 Thread Per Nyfelt
Hi, is it possible to use boms in @Grab? I tried the following in a groovy script: #!/usr/bin/env groovy @Grab(group='se.alipsa.matrix', module='matrix-bom', version='2.2.0', type='pom') @Grab('se.alipsa.matrix:matrix-core') import se.alipsa.matrix.core.* import java.util.time.* import java.t

Re: Grab and boms

2025-04-22 Thread Per Nyfelt
/jars jars: 0. matrix-core-3.2.0.jar matrix-core-3.1.0.jar was NOT found in /home/per/.groovy/grapes/se.alipsa.matrix/matrix-core/jars So it confirms that not specifying a version causes Grab to fetch whatever latest version it can find in maven central ignoring the bom. On 4/22/25 20:23,

Groovy Markdown 2.2.0 release

2025-04-10 Thread Per Nyfelt
Hi, Maybe this is of interest to people here. I just released a new version of gmd (Groovy Markdown) which is a way to write markdown with executable groovy code snippets very similar to the rmd package for R and an essential part reproducible research. This allows you to do things like this

Re: putAt and @CompileStatic

2025-04-14 Thread Per Nyfelt
I created https://issues.apache.org/jira/browse/GROOVY-11621 for this. On 2025-04-14, 13:09, "Per Nyfelt" mailto:per.nyf...@nordnet.se>> wrote: Oh, and property assignment with null for maps works with @CompileStatic e.g. def map = [a: 'foo', b: 'bar',

putAt and @CompileStatic

2025-04-14 Thread Per Nyfelt
Hi, I was recently experimenting with @CompileStatic for performance improvements and noticed that when using the short notation of putAt to assign a null value I get the following error [Static type checking] - Cannot call org.codehaus.groovy.runtime.DefaultGroovyMethods#putAt(java.util.List,

Re: putAt and @CompileStatic

2025-04-14 Thread Per Nyfelt
Oh, and property assignment with null for maps works with @CompileStatic e.g. def map = [a: 'foo', b: 'bar', c: 'baz'] map.b = null assert map['b'] == null I would assume we want bracket notation and property notation to be functionally equivalent ri

Re: putAt and @CompileStatic

2025-04-14 Thread Per Nyfelt
list[1] = (String) null I don't see why that is needed for null. On GROOVY_4_0_X, the map also needs the cast. On master, only the list needs the cast. I can't explain that either (yet). Paul. On Mon, Apr 14, 2025 at 5:37 PM Per Nyfelt mailto:per.nyf...@nordnet.se>> wrote: > &

Re: [ANNOUNCE] GMavenPlus 4.2.0

2025-04-28 Thread Per Nyfelt
Great news, thank you! /Per From: Keegan Witt Reply to: "users@groovy.apache.org" Date: Monday, 28 April 2025 at 04:34 To: GMavenPlus , "users@groovy.apache.org" Subject: [ANNOUNCE] GMavenPlus 4.2.0 GMavenPlus 4.2.0 has been released and should be in Maven Central shortly. Bugs None. Enhan

Re: Running ginq from a "clean" classloader

2025-04-29 Thread Per Nyfelt
var shell = c.getDeclaredConstructor().newInstance(); c.getMethod("evaluate", String.class).invoke(shell, script); Another way is to use a ProcessBuilder but that is much more involved for my current use case. Regards, Per From: Per Nyfelt Organisation: Alipsa HB Reply to: "users@groovy.apache.org

Running ginq from a "clean" classloader

2025-04-28 Thread Per Nyfelt
Hi, I am experimenting with running groovy scripts in a "clean" environment i.e. in a GroovyClassloader that does not have a parent. Background: One of my OSS projects is an analytics IDE where i want to enable users to run scripts that only has the dependencies of a gradle build script and

GroovyClassLoader in Junit tests

2025-02-28 Thread Per Nyfelt
Hi, Ever so often i find myself wishing that Junit tests in Gradle would use the GradleClassLoader instead of the default system classloader (e.g. to enable use of dynamic (conditional), runtime dependencies without having to run those tests in script blocks) In Junit 5 it is possible to create

Re: Groovy -jar

2025-02-23 Thread Per Nyfelt
ere in their PATH and it’s ready to run.  No groovy install, no database driver installs, no configuration, just go. Hope this helps, Steve *From:*Per Nyfelt *Sent:* Saturday, February 22, 2025 2:34 PM *To:* users@groovy.apache.org *Subject:* Groovy -jar Hi, I find myself missing  a way to ex

Groovy -jar

2025-02-22 Thread Per Nyfelt
Hi, I find myself missing  a way to execute groovy jars e.g: `groovy -jar someapp.jar`.  As a workaround i can do something like the following in bash (error handling etc. omitted) #!/usr/bin/env bash # takes a single parameter (the path to the jar file to execute - it assumes the Main-Class

Re: Groovy -jar

2025-02-24 Thread Per Nyfelt
uild scripts generate them build-time along with JAR creation) at https://ocs.cz/CD/ClassPath.txt. All the best, OC On 23. 2. 2025, at 12:40, Per Nyfelt mailto:p...@alipsa.se>> wrote: Thanks for this! For the use case you mention it makes perfect sense to do it that way. Since I don't

Re: Minor breaking change of chop(Iterator, int...) method for Groovy 5

2025-04-04 Thread Per Nyfelt
I think the change is good and the right one. Consistency of API will bring a much better benefit in the long run compared so the initial discomfort to adapt. Regards, Per On 4/4/25 13:41, Paul King wrote: Hi folks, I am seeking feedback on making a breaking change for the DGM chop method (

withIndex for streams

2025-03-20 Thread Per Nyfelt
Hi , I suggest that the withIndex method in DefaultGroovyMethods is overloaded with an option to support streams as well Given names = ['per', 'karin', 'tage', 'arne', 'sixten', 'ulrik'] I can find the 4:th element with println names[3] or if I only have an iterator with println names.iterato

New release of the Matrix Library

2025-04-02 Thread Per Nyfelt
Maybe this is of interest to some people here. I just released a new version of the Matrix library: https://github.com/Alipsa/matrix. It’s a groovy library for data analysis / data science similar in scope to Tablesaw for java or Pandas for python. With the help of the Manus AI, I recently creat

Re: Using MarkupBuilder as a closure argument

2025-05-20 Thread Per Nyfelt
ON and > potentially other structured formats later. But as long as you have the > information stored in some structured way it should be relatively easy to > convert to XML. Reading both JSON and XML is by far more difficult than > producing them. > > Best Regards, > &g

Using MarkupBuilder as a closure argument

2025-05-18 Thread Per Nyfelt
Hi, I would like to have a user api that can handle the following: createXml(target: xmlFile, name: 'a test') {     description('test xml')     licenses {         license('Apache License, Version 2.0', 'http://www.apache.org/licenses/LICENSE-2.0')     } } // description and licenses are ar

Re: Using MarkupBuilder as a closure argument

2025-05-21 Thread Per Nyfelt
surprised if such exists. >> >> In my current project I'm using the Groovy Map shortcut [ : ] to build >> structured information. In my case it will be converted to JSON and >> potentially other structured formats later. But as long as you have the >> informatio

Using javaVersion for groovydoc in 4.0.27

2025-05-28 Thread Per Nyfelt
Hi, I am keen to use the new javaVersion property added to GroovyDoc in 4.0.27 but cannot figure it out. According to the gradle documentation, "The version of the Groovydoc that is used, is the one from the Groovy dependency defined in the build script." so i did this: add implementation `"

Re: Using MarkupBuilder as a closure argument

2025-05-21 Thread Per Nyfelt
-lang.org/closures.html#_delegation_strategy > > Unless I misunderstood your problem, I think this might help you to > 'delegate' property and method access to a MarkupBuilder instance? > > Maarten > > On May 21, 2025 11:47:39 Per Nyfelt wrote: > >> Gradle

Re: Using javaVersion for groovydoc in 4.0.27

2025-05-29 Thread Per Nyfelt
, sourcepath: sourceSets.main.groovy.srcDirs.join(':'), packagenames: '*', javaVersion: 'JAVA_17') { } } } Cheers, Paul. On Thu, May 29, 2025 at 5:07 AM Per Nyfelt wrote: Hi, I am keen to use the new javaVersion property added to GroovyDoc i

Re: Using javaVersion for groovydoc in 4.0.27

2025-05-29 Thread Per Nyfelt
w groovytask part of the normal build (optional) tasks.named('build'){ dependsOntasks.named('antGroovydoc') } 4. Make sure javadocJar picks up the new location tasks.register('javadocJar', Jar){ dependsOntasks.named('antGroovydoc') archiveClassifier.set(&#

Re: Potential to include java.time.* as a default import for Groovy 5

2025-05-31 Thread Per Nyfelt
+1 Comment: using CompilerConfiguration with a custom ImportCustomizer works but is only applicable to a GroovyShell or GroovyScriptEngine i create myself and @BaseScript is not really transparent. What would be really nice would be to be able to easily adjust default imports in groovy-starte

Re: Ginq enhancement?

2025-06-20 Thread Per Nyfelt
so it would give me the same result as when i explicitly specify each field? Regards, Per On 6/20/25 15:47, Daniel Sun wrote: Hi Per, You can find the `leftjoin` usage here: https://github.com/apache/groovy/blob/b046d1b2bcbbddd59ea3d6abdf5de24a671ce51a/subprojects/groovy-ginq/src/spec/test/org/apache/g

Ginq enhancement?

2025-06-17 Thread Per Nyfelt
Hi, I ran into a a ginq "issue" today. I have two list of rows where each key is the column name (actually List but you can think about it as a List)  collections that looks like this: employees: 3 obs * 5 variables mainSsn    coSsn    firstName    salary    startDate 111

Re: Ginq enhancement?

2025-06-21 Thread Per Nyfelt
ed result of `e.*`, for example, ``` GQ { from e in employees leftjoin mcid in identifiers on e.mainSsn == mcid.lei select e, mcid // the wrapped result for e.*, mcid.* } ``` BTW, I tried to find the `e.*` usage in LINQ of C#, it is not supported either. Cheers, Daniel Sun On 2

using @GrabConfig(systemClassLoader=true) in a ScriptEngine

2025-07-08 Thread Per Nyfelt
Hi, I am trying to figure out a way to use @GrabConfig(systemClassLoader=true) in a ScritpEngine (or GroovyShell, does not matter. The following script works without any problem using the groovy command (.e.g `groovy sqltaskExample.groovy`): @GrabConfig(systemClassLoader=true) @Grab('com.h2datab

Re: using @GrabConfig(systemClassLoader=true) in a ScriptEngine

2025-07-12 Thread Per Nyfelt
s.class.classLoader, [[group:'com.h2database',module:'h2',version:'2.3.232']]as Map[])[0] path(id:'driverPath'){ pathelement(location:new File(h2)) } Best regards, Per On 7/12/25 14:13, Per Nyfelt wrote: Thank you, this is very hel

Re: using @GrabConfig(systemClassLoader=true) in a ScriptEngine

2025-07-11 Thread Per Nyfelt
to load the classpath and start the program. In Groovy we are using RootLoader for this. Or you use GroovyStarter bye Jochen On 7/8/25 12:51, Per Nyfelt wrote: Hi, I am trying to figure out a way to use @GrabConfig(systemClassLoader=true) in a ScritpEngine (or GroovyShell, does not mat

Re: using @GrabConfig(systemClassLoader=true) in a ScriptEngine

2025-07-12 Thread Per Nyfelt
lt; grape_string } *catch*(e) { */log/*.error("grab of [{}] using class loader [{}] failed [{}]",grape_string,classLoader.getClass().getName(),e.message) }     } } *From: *Per Nyfelt *Date: *Friday, July 11, 2025 at 11:54 AM *To: *users@groovy.apache.org *Subject: *[EXT] Re: