Re: Parsing pom.xml

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Parsing pom.xml

Andres Almiray
Looks like I found the answer to instantiating the ModelBuilder

    new DefaultModelBuilderFactory().newInstance()

From the javadoc:

 * A factory to create model builder instances when no dependency injection
is available. <em>Note:</em> This class is
 * only meant as a utility for developers that want to employ the model
builder outside of the Maven build system, Maven
 * plugins should always acquire model builder instances via dependency
injection. Developers might want to subclass
 * this factory to provide custom implementations for some of the
components used by the model builder.

Great, I think this will work :-)

Best,
Andres

-------------------------------------------
Java Champion; Groovy Enthusiast
JCP EC Associate Seat
http://andresalmiray.com
http://www.linkedin.com/in/aalmiray
--
What goes up, must come down. Ask any system administrator.
There are 10 types of people in the world: Those who understand binary, and
those who don't.
To understand recursion, we must first understand recursion.


On Sat, Dec 8, 2018 at 6:47 PM Andres Almiray <[hidden email]> wrote:

> Thank you Robert!
>
> It looks like org.apache.maven.model.Model.DefaultModelBuilder provides
> the behavior I need given this method found in its contract
>
>    ModelBuildingResult build( ModelBuildingRequest request )
>         throws ModelBuildingException;
>
> ModelBuildingResult gives me access to the raw model (as read form the
> pom.xml file) and the effective model. This is exactly what I need :-)
>
> Is there a special way to initialize an instance of such type?
> Theoretically I'd like to call something like
>
>     ModelBuildingRequest request = new DefaultModelBuildingRequest();
>     request.setPomFile(...);
>     ModelBuilder builder = ... // instantiate builder (??)
>     ModelBuldingResult result = builder.build(request);
>
> Thanks for your help.
>
> Best,
> Andres
>
> -------------------------------------------
> Java Champion; Groovy Enthusiast
> JCP EC Associate Seat
> http://andresalmiray.com
> http://www.linkedin.com/in/aalmiray
> --
> What goes up, must come down. Ask any system administrator.
> There are 10 types of people in the world: Those who understand binary,
> and those who don't.
> To understand recursion, we must first understand recursion.
>
>
> On Sat, Dec 8, 2018 at 6:33 PM Robert Scholte <[hidden email]>
> wrote:
>
>> The ModelBuilder[1] is what you are looking for, and yes it does a LOT :)
>>
>> Be aware that it is using CDI, so to make use of it you'll need
>> sisu/guice
>> too.
>>
>> Robert
>>
>> [1] https://maven.apache.org/ref/3.6.0/maven-model-builder/
>>
>> On Sat, 08 Dec 2018 18:20:51 +0100, Andres Almiray <[hidden email]>
>> wrote:
>>
>> > Of course.
>> >
>> > This is definitely not a plugin project. My goal is to have an in-memory
>> > representation of the POM as defined by a source pom.xml, to later
>> > transform/enrich it and write it back.
>> > As a side effect this tool can calculate statics on usage patterns and
>> > recommend some others.
>> >
>> > Best,
>> > Andres
>> >
>> > -------------------------------------------
>> > Java Champion; Groovy Enthusiast
>> > JCP EC Associate Seat
>> > http://andresalmiray.com
>> > http://www.linkedin.com/in/aalmiray
>> > --
>> > What goes up, must come down. Ask any system administrator.
>> > There are 10 types of people in the world: Those who understand
>> binary,
>> > and
>> > those who don't.
>> > To understand recursion, we must first understand recursion.
>> >
>> >
>> > On Sat, Dec 8, 2018 at 6:17 PM Enrico Olivelli <[hidden email]>
>> > wrote:
>> >
>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <[hidden email]> ha
>> scritto:
>> >>
>> >> > Hello everyone,
>> >> >
>> >> > I have the need of building a model based on the data defined in a
>> >> pom.xml
>> >> > file.
>> >> > What would be the best way to read, parse, and obtain such model
>> using
>> >> > standard Maven APIs?
>> >> >
>> >>
>> >> Could you given some more context?
>> >>
>> >> I guess you are not writing a plugin.
>> >>
>> >> Using the internal API may be useful depending on your case.
>> >>
>> >> Enrico
>> >>
>> >> >
>> >> > Best,
>> >> > Andres
>> >> >
>> >> > -------------------------------------------
>> >> > Java Champion; Groovy Enthusiast
>> >> > JCP EC Associate Seat
>> >> > http://andresalmiray.com
>> >> > http://www.linkedin.com/in/aalmiray
>> >> > --
>> >> > What goes up, must come down. Ask any system administrator.
>> >> > There are 10 types of people in the world: Those who understand
>> >> binary,
>> >> and
>> >> > those who don't.
>> >> > To understand recursion, we must first understand recursion.
>> >> >
>> >> --
>> >>
>> >>
>> >> -- Enrico Olivelli
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: Parsing pom.xml

Robert Scholte-8
Ah, you might be lucky with this solution :)

On Sat, 08 Dec 2018 19:20:59 +0100, Andres Almiray <[hidden email]>  
wrote:

> Looks like I found the answer to instantiating the ModelBuilder
>
>     new DefaultModelBuilderFactory().newInstance()
>
> From the javadoc:
>
>  * A factory to create model builder instances when no dependency  
> injection
> is available. <em>Note:</em> This class is
>  * only meant as a utility for developers that want to employ the model
> builder outside of the Maven build system, Maven
>  * plugins should always acquire model builder instances via dependency
> injection. Developers might want to subclass
>  * this factory to provide custom implementations for some of the
> components used by the model builder.
>
> Great, I think this will work :-)
>
> Best,
> Andres
>
> -------------------------------------------
> Java Champion; Groovy Enthusiast
> JCP EC Associate Seat
> http://andresalmiray.com
> http://www.linkedin.com/in/aalmiray
> --
> What goes up, must come down. Ask any system administrator.
> There are 10 types of people in the world: Those who understand binary,  
> and
> those who don't.
> To understand recursion, we must first understand recursion.
>
>
> On Sat, Dec 8, 2018 at 6:47 PM Andres Almiray <[hidden email]> wrote:
>
>> Thank you Robert!
>>
>> It looks like org.apache.maven.model.Model.DefaultModelBuilder provides
>> the behavior I need given this method found in its contract
>>
>>    ModelBuildingResult build( ModelBuildingRequest request )
>>         throws ModelBuildingException;
>>
>> ModelBuildingResult gives me access to the raw model (as read form the
>> pom.xml file) and the effective model. This is exactly what I need :-)
>>
>> Is there a special way to initialize an instance of such type?
>> Theoretically I'd like to call something like
>>
>>     ModelBuildingRequest request = new DefaultModelBuildingRequest();
>>     request.setPomFile(...);
>>     ModelBuilder builder = ... // instantiate builder (??)
>>     ModelBuldingResult result = builder.build(request);
>>
>> Thanks for your help.
>>
>> Best,
>> Andres
>>
>> -------------------------------------------
>> Java Champion; Groovy Enthusiast
>> JCP EC Associate Seat
>> http://andresalmiray.com
>> http://www.linkedin.com/in/aalmiray
>> --
>> What goes up, must come down. Ask any system administrator.
>> There are 10 types of people in the world: Those who understand binary,
>> and those who don't.
>> To understand recursion, we must first understand recursion.
>>
>>
>> On Sat, Dec 8, 2018 at 6:33 PM Robert Scholte <[hidden email]>
>> wrote:
>>
>>> The ModelBuilder[1] is what you are looking for, and yes it does a LOT  
>>> :)
>>>
>>> Be aware that it is using CDI, so to make use of it you'll need
>>> sisu/guice
>>> too.
>>>
>>> Robert
>>>
>>> [1] https://maven.apache.org/ref/3.6.0/maven-model-builder/
>>>
>>> On Sat, 08 Dec 2018 18:20:51 +0100, Andres Almiray <[hidden email]>
>>> wrote:
>>>
>>> > Of course.
>>> >
>>> > This is definitely not a plugin project. My goal is to have an  
>>> in-memory
>>> > representation of the POM as defined by a source pom.xml, to later
>>> > transform/enrich it and write it back.
>>> > As a side effect this tool can calculate statics on usage patterns  
>>> and
>>> > recommend some others.
>>> >
>>> > Best,
>>> > Andres
>>> >
>>> > -------------------------------------------
>>> > Java Champion; Groovy Enthusiast
>>> > JCP EC Associate Seat
>>> > http://andresalmiray.com
>>> > http://www.linkedin.com/in/aalmiray
>>> > --
>>> > What goes up, must come down. Ask any system administrator.
>>> > There are 10 types of people in the world: Those who understand
>>> binary,
>>> > and
>>> > those who don't.
>>> > To understand recursion, we must first understand recursion.
>>> >
>>> >
>>> > On Sat, Dec 8, 2018 at 6:17 PM Enrico Olivelli <[hidden email]>
>>> > wrote:
>>> >
>>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <[hidden email]> ha
>>> scritto:
>>> >>
>>> >> > Hello everyone,
>>> >> >
>>> >> > I have the need of building a model based on the data defined in a
>>> >> pom.xml
>>> >> > file.
>>> >> > What would be the best way to read, parse, and obtain such model
>>> using
>>> >> > standard Maven APIs?
>>> >> >
>>> >>
>>> >> Could you given some more context?
>>> >>
>>> >> I guess you are not writing a plugin.
>>> >>
>>> >> Using the internal API may be useful depending on your case.
>>> >>
>>> >> Enrico
>>> >>
>>> >> >
>>> >> > Best,
>>> >> > Andres
>>> >> >
>>> >> > -------------------------------------------
>>> >> > Java Champion; Groovy Enthusiast
>>> >> > JCP EC Associate Seat
>>> >> > http://andresalmiray.com
>>> >> > http://www.linkedin.com/in/aalmiray
>>> >> > --
>>> >> > What goes up, must come down. Ask any system administrator.
>>> >> > There are 10 types of people in the world: Those who understand
>>> >> binary,
>>> >> and
>>> >> > those who don't.
>>> >> > To understand recursion, we must first understand recursion.
>>> >> >
>>> >> --
>>> >>
>>> >>
>>> >> -- Enrico Olivelli
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Parsing pom.xml

Andres Almiray
So far so good, I can parse POM files and read data. This works fine as
long as I don't have to access a parent POM.

@Robert: I suspect your first suggestion may be needed in order to resolve
parent POM files as artifacts, isn't that right?

Best,
Andres

-------------------------------------------
Java Champion; Groovy Enthusiast
JCP EC Associate Seat
http://andresalmiray.com
http://www.linkedin.com/in/aalmiray
--
What goes up, must come down. Ask any system administrator.
There are 10 types of people in the world: Those who understand binary, and
those who don't.
To understand recursion, we must first understand recursion.


On Sat, Dec 8, 2018 at 7:22 PM Robert Scholte <[hidden email]> wrote:

> Ah, you might be lucky with this solution :)
>
> On Sat, 08 Dec 2018 19:20:59 +0100, Andres Almiray <[hidden email]>
> wrote:
>
> > Looks like I found the answer to instantiating the ModelBuilder
> >
> >     new DefaultModelBuilderFactory().newInstance()
> >
> > From the javadoc:
> >
> >  * A factory to create model builder instances when no dependency
> > injection
> > is available. <em>Note:</em> This class is
> >  * only meant as a utility for developers that want to employ the model
> > builder outside of the Maven build system, Maven
> >  * plugins should always acquire model builder instances via dependency
> > injection. Developers might want to subclass
> >  * this factory to provide custom implementations for some of the
> > components used by the model builder.
> >
> > Great, I think this will work :-)
> >
> > Best,
> > Andres
> >
> > -------------------------------------------
> > Java Champion; Groovy Enthusiast
> > JCP EC Associate Seat
> > http://andresalmiray.com
> > http://www.linkedin.com/in/aalmiray
> > --
> > What goes up, must come down. Ask any system administrator.
> > There are 10 types of people in the world: Those who understand binary,
> > and
> > those who don't.
> > To understand recursion, we must first understand recursion.
> >
> >
> > On Sat, Dec 8, 2018 at 6:47 PM Andres Almiray <[hidden email]>
> wrote:
> >
> >> Thank you Robert!
> >>
> >> It looks like org.apache.maven.model.Model.DefaultModelBuilder provides
> >> the behavior I need given this method found in its contract
> >>
> >>    ModelBuildingResult build( ModelBuildingRequest request )
> >>         throws ModelBuildingException;
> >>
> >> ModelBuildingResult gives me access to the raw model (as read form the
> >> pom.xml file) and the effective model. This is exactly what I need :-)
> >>
> >> Is there a special way to initialize an instance of such type?
> >> Theoretically I'd like to call something like
> >>
> >>     ModelBuildingRequest request = new DefaultModelBuildingRequest();
> >>     request.setPomFile(...);
> >>     ModelBuilder builder = ... // instantiate builder (??)
> >>     ModelBuldingResult result = builder.build(request);
> >>
> >> Thanks for your help.
> >>
> >> Best,
> >> Andres
> >>
> >> -------------------------------------------
> >> Java Champion; Groovy Enthusiast
> >> JCP EC Associate Seat
> >> http://andresalmiray.com
> >> http://www.linkedin.com/in/aalmiray
> >> --
> >> What goes up, must come down. Ask any system administrator.
> >> There are 10 types of people in the world: Those who understand binary,
> >> and those who don't.
> >> To understand recursion, we must first understand recursion.
> >>
> >>
> >> On Sat, Dec 8, 2018 at 6:33 PM Robert Scholte <[hidden email]>
> >> wrote:
> >>
> >>> The ModelBuilder[1] is what you are looking for, and yes it does a
> LOT
> >>> :)
> >>>
> >>> Be aware that it is using CDI, so to make use of it you'll need
> >>> sisu/guice
> >>> too.
> >>>
> >>> Robert
> >>>
> >>> [1] https://maven.apache.org/ref/3.6.0/maven-model-builder/
> >>>
> >>> On Sat, 08 Dec 2018 18:20:51 +0100, Andres Almiray <[hidden email]
> >
> >>> wrote:
> >>>
> >>> > Of course.
> >>> >
> >>> > This is definitely not a plugin project. My goal is to have an
> >>> in-memory
> >>> > representation of the POM as defined by a source pom.xml, to later
> >>> > transform/enrich it and write it back.
> >>> > As a side effect this tool can calculate statics on usage patterns
> >>> and
> >>> > recommend some others.
> >>> >
> >>> > Best,
> >>> > Andres
> >>> >
> >>> > -------------------------------------------
> >>> > Java Champion; Groovy Enthusiast
> >>> > JCP EC Associate Seat
> >>> > http://andresalmiray.com
> >>> > http://www.linkedin.com/in/aalmiray
> >>> > --
> >>> > What goes up, must come down. Ask any system administrator.
> >>> > There are 10 types of people in the world: Those who understand
> >>> binary,
> >>> > and
> >>> > those who don't.
> >>> > To understand recursion, we must first understand recursion.
> >>> >
> >>> >
> >>> > On Sat, Dec 8, 2018 at 6:17 PM Enrico Olivelli <[hidden email]>
> >>> > wrote:
> >>> >
> >>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <[hidden email]> ha
> >>> scritto:
> >>> >>
> >>> >> > Hello everyone,
> >>> >> >
> >>> >> > I have the need of building a model based on the data defined in a
> >>> >> pom.xml
> >>> >> > file.
> >>> >> > What would be the best way to read, parse, and obtain such model
> >>> using
> >>> >> > standard Maven APIs?
> >>> >> >
> >>> >>
> >>> >> Could you given some more context?
> >>> >>
> >>> >> I guess you are not writing a plugin.
> >>> >>
> >>> >> Using the internal API may be useful depending on your case.
> >>> >>
> >>> >> Enrico
> >>> >>
> >>> >> >
> >>> >> > Best,
> >>> >> > Andres
> >>> >> >
> >>> >> > -------------------------------------------
> >>> >> > Java Champion; Groovy Enthusiast
> >>> >> > JCP EC Associate Seat
> >>> >> > http://andresalmiray.com
> >>> >> > http://www.linkedin.com/in/aalmiray
> >>> >> > --
> >>> >> > What goes up, must come down. Ask any system administrator.
> >>> >> > There are 10 types of people in the world: Those who understand
> >>> >> binary,
> >>> >> and
> >>> >> > those who don't.
> >>> >> > To understand recursion, we must first understand recursion.
> >>> >> >
> >>> >> --
> >>> >>
> >>> >>
> >>> >> -- Enrico Olivelli
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [hidden email]
> >>> For additional commands, e-mail: [hidden email]
> >>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Parsing pom.xml

ljnelson
This is all near and dear to my heart.

First, some terminology clearing up: the Maven internals rely on a JSR-330
implementation (javax.inject.*), not CDI (javax.enterprise.inject.*).  CDI
is a JSR-330 implementation, but so is Guice, HK2, etc.  I believe that the
internals of Maven rely on Guice, but as Robert says, if you're not
rebuilding the innards of Maven then using the facilities of JSR-330 make
the code really simple.

I did actually put parts of Maven in CDI (
https://microbean.github.io/microbean-maven-cdi/).  You may find some of
the implementation classes in question that you need in there.  Start here:
https://github.com/microbean/microbean-maven-cdi/blob/c5abd2e3c321020c419442c44ef726e48952d983/src/main/java/org/microbean/maven/cdi/MavenExtension.java#L317

Best,
Laird
--
https://about.me/lairdnelson