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 <aalmi...@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 <rfscho...@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 <aalmi...@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 <eolive...@gmail.com>
> wrote:
>
>> Il sab 8 dic 2018, 18:09 Andres Almiray <aalmi...@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-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org


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

Reply via email to