You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Andres Almiray <aa...@gmail.com> on 2018/12/08 17:09:07 UTC

Parsing pom.xml

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?

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.

Re: Parsing pom.xml

Posted by Elliotte Rusty Harold <el...@ibiblio.org>.
On Sat, Dec 8, 2018 at 12:58 PM Oliver Drotbohm <og...@pivotal.io> wrote:
>
> If it's about pure XML parsing and tweaking the information and building the model is not required, XmlBeam [0] is a lightweight alternative to map the entire file to a Java object. We use that in the Spring Data release automation. Declare an interface containing accessors backed by XPath expressions, use the API to create instances and read and write data from and to the XML file.
>

I've tried using pure XML parsing to work with pom.xml before and it's
more challenging than it should be. Parent POMs are one issue, but
that's expected. What may not be obvious is that many real world
pom.xml files omit the namespace declarations. This require s lot of
contortions in your code to handle cases both with and without
namespaces.

-- 
Elliotte Rusty Harold
elharo@ibiblio.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Andres Almiray <aa...@gmail.com>.
HI Oliver,

Nice! However that approach may require mapping all possible elements,
including plugins and more. The ModelBuilder should take care of that,
isn't it?

Cheers,
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:58 PM Oliver Drotbohm <og...@pivotal.io> wrote:

> If it's about pure XML parsing and tweaking the information and building
> the model is not required, XmlBeam [0] is a lightweight alternative to map
> the entire file to a Java object. We use that in the Spring Data release
> automation. Declare an interface containing accessors backed by XPath
> expressions, use the API to create instances and read and write data from
> and to the XML file.
>
> Here [1] is the interface we use to access the parts of the POM relevant
> to our use case.
>
> Cheers,
> Ollie
>
> [0] https://xmlbeam.org/
> [1]
> https://github.com/spring-projects/spring-data-dev-tools/blob/82252be5d7c11a137a68c7fe985b53e04d91cb18/release-tools/src/main/java/org/springframework/data/release/build/Pom.java
>
> > Am 08.12.2018 um 18:47 schrieb Andres Almiray <aa...@gmail.com>:
> >
> > 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
> >
> https://urldefense.proofpoint.com/v2/url?u=http-3A__andresalmiray.com&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=pWrsdUJpQnH-DJXIDk-VNgy7wfo1-h6nGxVaeazNdJI&e=
> >
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_in_aalmiray&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=UGKJpSnO9O4VH5cvMfn7ZTk5m9sFXqHsplwnlS1nbpk&e=
> > --
> > 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 <rf...@apache.org>
> 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://urldefense.proofpoint.com/v2/url?u=https-3A__maven.apache.org_ref_3.6.0_maven-2Dmodel-2Dbuilder_&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=nOkaCJH3dSvCiihbxfBQKXKE-I2GunCrdaIK9gjbVJs&e=
> >>
> >> On Sat, 08 Dec 2018 18:20:51 +0100, Andres Almiray <aa...@gmail.com>
> >> 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
> >>>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__andresalmiray.com&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=pWrsdUJpQnH-DJXIDk-VNgy7wfo1-h6nGxVaeazNdJI&e=
> >>>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_in_aalmiray&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=UGKJpSnO9O4VH5cvMfn7ZTk5m9sFXqHsplwnlS1nbpk&e=
> >>> --
> >>> 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 <eo...@gmail.com>
> >>> wrote:
> >>>
> >>>> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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
> >>>>>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__andresalmiray.com&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=pWrsdUJpQnH-DJXIDk-VNgy7wfo1-h6nGxVaeazNdJI&e=
> >>>>>
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_in_aalmiray&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=UGKJpSnO9O4VH5cvMfn7ZTk5m9sFXqHsplwnlS1nbpk&e=
> >>>>> --
> >>>>> 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: dev-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: dev-help@maven.apache.org
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Parsing pom.xml

Posted by Oliver Drotbohm <og...@pivotal.io>.
If it's about pure XML parsing and tweaking the information and building the model is not required, XmlBeam [0] is a lightweight alternative to map the entire file to a Java object. We use that in the Spring Data release automation. Declare an interface containing accessors backed by XPath expressions, use the API to create instances and read and write data from and to the XML file.

Here [1] is the interface we use to access the parts of the POM relevant to our use case.

Cheers,
Ollie

[0] https://xmlbeam.org/
[1] https://github.com/spring-projects/spring-data-dev-tools/blob/82252be5d7c11a137a68c7fe985b53e04d91cb18/release-tools/src/main/java/org/springframework/data/release/build/Pom.java

> Am 08.12.2018 um 18:47 schrieb Andres Almiray <aa...@gmail.com>:
> 
> 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
> https://urldefense.proofpoint.com/v2/url?u=http-3A__andresalmiray.com&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=pWrsdUJpQnH-DJXIDk-VNgy7wfo1-h6nGxVaeazNdJI&e=
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_in_aalmiray&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=UGKJpSnO9O4VH5cvMfn7ZTk5m9sFXqHsplwnlS1nbpk&e=
> --
> 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 <rf...@apache.org> 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://urldefense.proofpoint.com/v2/url?u=https-3A__maven.apache.org_ref_3.6.0_maven-2Dmodel-2Dbuilder_&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=nOkaCJH3dSvCiihbxfBQKXKE-I2GunCrdaIK9gjbVJs&e=
>> 
>> On Sat, 08 Dec 2018 18:20:51 +0100, Andres Almiray <aa...@gmail.com>
>> 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
>>> https://urldefense.proofpoint.com/v2/url?u=http-3A__andresalmiray.com&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=pWrsdUJpQnH-DJXIDk-VNgy7wfo1-h6nGxVaeazNdJI&e=
>>> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_in_aalmiray&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=UGKJpSnO9O4VH5cvMfn7ZTk5m9sFXqHsplwnlS1nbpk&e=
>>> --
>>> 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 <eo...@gmail.com>
>>> wrote:
>>> 
>>>> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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
>>>>> https://urldefense.proofpoint.com/v2/url?u=http-3A__andresalmiray.com&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=pWrsdUJpQnH-DJXIDk-VNgy7wfo1-h6nGxVaeazNdJI&e=
>>>>> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_in_aalmiray&d=DwIBaQ&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=7iLfhC17FN-CWhuzo2HX1g0LRD1P0huXh9Zkd3m6MZ0&m=IxYdo3ScIXOSlnfw8tbvEDuE1wDPwLfKRtL_lYOz0zs&s=UGKJpSnO9O4VH5cvMfn7ZTk5m9sFXqHsplwnlS1nbpk&e=
>>>>> --
>>>>> 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: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Robert Scholte <rf...@apache.org>.
Hi Andres,

this is what you need to do:

@Inject
private ModelBuilder builder;

(or with @Requiment when using only plexus annotations)

This means you need your code to run in a CDI container. If you use  
Sisu[1] you can mix Plexus and JSR330 annotations.

Maven & JSR-330[2] Should explain most details and get you started. It has  
chapters for plugins and extensions, since these are the main areas where  
to use it. Standalone should be possible. The Sisu page[1] is a good  
start, and ensure to include org.eclipse.sisu.inject and  
org.eclipse.sisu.plexus.
(I could point you to how Maven initializes the container, but it does  
much, much more due to the need for isolated classloaders, etc.)

thanks
Robert

[1] https://www.eclipse.org/sisu/docs/tutorials/index.html
[2] https://maven.apache.org/maven-jsr330.html


On Sat, 08 Dec 2018 18:47:21 +0100, Andres Almiray <aa...@gmail.com>  
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 <rf...@apache.org>  
> 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 <aa...@gmail.com>
>> 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 <eo...@gmail.com>
>> > wrote:
>> >
>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Robert Scholte <rf...@apache.org>.
On Sun, 09 Dec 2018 13:44:52 +0100, Andres Almiray <aa...@gmail.com>  
wrote:

> Hi Laird,
>
> Thanks, this all is very useful :-)
>
> One more thing, if I needed to read the contents of a settings.xml file,  
> I
> suppose there's a similar API that make this work?

Of course, better give you the complete overview :) :
https://maven.apache.org/ref/3.6.0/

Robert


>
> 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 11:10 PM Laird Nelson <lj...@gmail.com> wrote:
>
>> I forgot to mention: if you want to do this all "by hand", i.e. not  
>> rely on
>> JSR 330 containers, you want to look here (
>>
>> https://maven.apache.org/resolver/apidocs/index.html?org/eclipse/aether/impl/DefaultServiceLocator.html
>> )
>> and work backwards.
>>
>> Best,
>> Laird
>> --
>> https://about.me/lairdnelson
>>
>> On Sat, Dec 8, 2018 at 2:05 PM Laird Nelson <lj...@gmail.com> wrote:
>>
>> > 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
>> >

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Andres Almiray <aa...@gmail.com>.
Hi Laird,

Thanks, this all is very useful :-)

One more thing, if I needed to read the contents of a settings.xml file, I
suppose there's a similar API that make this 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 11:10 PM Laird Nelson <lj...@gmail.com> wrote:

> I forgot to mention: if you want to do this all "by hand", i.e. not rely on
> JSR 330 containers, you want to look here (
>
> https://maven.apache.org/resolver/apidocs/index.html?org/eclipse/aether/impl/DefaultServiceLocator.html
> )
> and work backwards.
>
> Best,
> Laird
> --
> https://about.me/lairdnelson
>
> On Sat, Dec 8, 2018 at 2:05 PM Laird Nelson <lj...@gmail.com> wrote:
>
> > 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
> >
>

Re: Parsing pom.xml

Posted by Laird Nelson <lj...@gmail.com>.
I forgot to mention: if you want to do this all "by hand", i.e. not rely on
JSR 330 containers, you want to look here (
https://maven.apache.org/resolver/apidocs/index.html?org/eclipse/aether/impl/DefaultServiceLocator.html)
and work backwards.

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

On Sat, Dec 8, 2018 at 2:05 PM Laird Nelson <lj...@gmail.com> wrote:

> 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
>

Re: Parsing pom.xml

Posted by Laird Nelson <lj...@gmail.com>.
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

Re: Parsing pom.xml

Posted by Robert Scholte <rf...@apache.org>.
On Sat, 08 Dec 2018 21:52:16 +0100, Andres Almiray <aa...@gmail.com>  
wrote:

> 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?

I don't know. I can always assume there's a CDI container, so that code  
looks quite simple.
I never have to use the DefaultModelBuilderFactory, I actually wasn't  
aware of this class.
I'm not sure everything works for standalone, but docs suggest it should.
If not, we'll need to have a closer look at it.

Robert

>
> 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 <rf...@apache.org>  
> wrote:
>
>> Ah, you might be lucky with this solution :)
>>
>> On Sat, 08 Dec 2018 19:20:59 +0100, Andres Almiray <aa...@gmail.com>
>> 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 <aa...@gmail.com>
>> 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 <rf...@apache.org>
>> >> 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  
>> <aalmiray@gmail.com
>> >
>> >>> 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  
>> <eo...@gmail.com>
>> >>> > wrote:
>> >>> >
>> >>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
>> >>> For additional commands, e-mail: dev-help@maven.apache.org
>> >>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Andres Almiray <aa...@gmail.com>.
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 <rf...@apache.org> wrote:

> Ah, you might be lucky with this solution :)
>
> On Sat, 08 Dec 2018 19:20:59 +0100, Andres Almiray <aa...@gmail.com>
> 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 <aa...@gmail.com>
> 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 <rf...@apache.org>
> >> 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 <aalmiray@gmail.com
> >
> >>> 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 <eo...@gmail.com>
> >>> > wrote:
> >>> >
> >>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
> >>> For additional commands, e-mail: dev-help@maven.apache.org
> >>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Parsing pom.xml

Posted by Robert Scholte <rf...@apache.org>.
Ah, you might be lucky with this solution :)

On Sat, 08 Dec 2018 19:20:59 +0100, Andres Almiray <aa...@gmail.com>  
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 <aa...@gmail.com> 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 <rf...@apache.org>
>> 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 <aa...@gmail.com>
>>> 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 <eo...@gmail.com>
>>> > wrote:
>>> >
>>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: dev-help@maven.apache.org
>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Andres Almiray <aa...@gmail.com>.
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 <aa...@gmail.com> 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 <rf...@apache.org>
> 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 <aa...@gmail.com>
>> 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 <eo...@gmail.com>
>> > wrote:
>> >
>> >> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>>

Re: Parsing pom.xml

Posted by Andres Almiray <aa...@gmail.com>.
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 <rf...@apache.org> 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 <aa...@gmail.com>
> 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 <eo...@gmail.com>
> > wrote:
> >
> >> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

Re: Parsing pom.xml

Posted by Robert Scholte <rf...@apache.org>.
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 <aa...@gmail.com>  
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 <eo...@gmail.com>  
> wrote:
>
>> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: Parsing pom.xml

Posted by Andres Almiray <aa...@gmail.com>.
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 <eo...@gmail.com> wrote:

> Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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
>

Re: Parsing pom.xml

Posted by Enrico Olivelli <eo...@gmail.com>.
Il sab 8 dic 2018, 18:09 Andres Almiray <aa...@gmail.com> 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