Re: Using MarkupBuilder as a closure argument

[email protected] Tue, 20 May 2025 13:35:56 +0200
Newsgroups gmane.comp.lang.groovy.user
Message-ID <1d6f2e72-93a9-4e85-931d-27b28cf3db29@Spark>
Hi again Per,

Have you seen Gradle ? I believe that Gradle might provide what you are trying to do. Personally I'm not a Gradle fan, but many are.

Tommy Svensson
On 20 May 2025 at 10:38 +0200, Per Nyfelt <[email protected]>, wrote:
> Thanks Tommy,
> My problem was in the context of a custom ant task. I found that if I let go of the idea of "arbitrary additional content" and defined what the different additional sections could be, it was quite easy to do. My solution is here: https://github.com/Alipsa/uso/blob/main/uso-tasks/src/main/groovy/se/alipsa/uso/tasks/CreatePom.groovy in case anyone is interested.
>
> Best regards,
> Per
>
> On Mon, 19 May 2025 at 14:01, <[email protected]> wrote:
> > Hello Per,
> >
> > I don't know of anything existing that does what you want. But, in Groovy you can easily define structures like JSON or XML (which both give you a structure but does so using different formats.
> >
> > Example: Map<String, Object> root = [ "id": "QAZ",  "name" : "Nisse", ... ]
> >
> > This is a java.util.Map structure. Your code can then take this Map<String, Object> and convert to JSON or XML. But I don't know of anything existing that takes such a Map structure to XML. I would not be entirely 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 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,
> >
> > Tommy Svensson
> > On 18 May 2025 at 20:38 +0200, Per Nyfelt <[email protected]>, wrote:
> > > 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 arbitrary, it can be any structure that
> > > can be converted to XML
> > >
> > > I want the closure to behave as if it would be statements to a
> > > MarkupBuilder but I am unable to figure out how to do it. Can i convert
> > > the closure to a MarkupBuilder or process it with a MarkupBuilder
> > > somehow? Any ideas?
> > >
> > > Best regards
> > >
> > > Per
> > >