Sorry but it is fully in the subject of the thread.
Andres wants a way to programatically load a POM object. I guess he wants a
way to load a correctly resolved POM not a partially resolved one.

On Fri, Apr 17, 2020 at 11:02 AM Olivier Lamy <[email protected]> wrote:

> yes maybe some stuff to fix (feel free to send a PR :P )
> But it's not the subject of the thread.... :)
> But did you try without all the Jenkins but only the mentioned library?
> It's not too hard to fix (the code pointed in this thread may have the same
> issue)
>
>
> On Fri, 17 Apr 2020 at 18:49, Matthieu BROUILLARD <[email protected]>
> wrote:
>
> > Olivier,
> >
> > If the project you are pointing is what is behind "Maven Integration" in
> > Jenkins then it does things wrong by not taking into account maven
> > core-extensions.
> >
> > I just retested now:
> > - download Jenkins.war 2.232
> > - launch as java -jar
> > - default installation
> > - add plugin "Maven integration"
> > - in settings add a local JDK 11
> > - in settings add a default maven 3.6.3
> > - create new job "jgitver in jenkins"
> > - set git url : https://github.com/jgitver/jgitver.git
> > - set goal : validate
> > - run the job
> >
> > You will see in the output that the version of the project is 0 whereas
> it
> > should have been computed by a core extension.
> >
> > ...
> > [INFO] ---------------------< fr.brouillard.oss:jgitver
> > >----------------------
> > [INFO] Building GIT versioning using jgit 0
> > [INFO] --------------------------------[ jar
> > ]---------------------------------
> > ...
> >
> >
> > If you do the same in CMD/sh you should see the automatic computation
> >
> > [INFO] Using jgitver configuration file:
> > C:\workspace\projects\oss\jgitver\jgitver-lib\.mvn\jgitver.config.xml
> > [INFO] Using jgitver-maven-plugin [1.5.1] (sha1:
> > e45d1669b39cedb98720dd33cc14d0185b455ca1)
> > [INFO]     version '0.12.1-SNAPSHOT' computed in 15595 ms
> > [INFO]
> > [INFO] Scanning for projects...
> > [INFO] jgitver-maven-plugin is about to change project(s) version(s)
> > [INFO]     fr.brouillard.oss::jgitver::0 -> 0.12.1-SNAPSHOT
> > [INFO]
> > [INFO] ---------------------< fr.brouillard.oss:jgitver
> > >----------------------
> > [INFO] Building GIT versioning using jgit 0.12.1-SNAPSHOT
> > [INFO] --------------------------------[ jar
> > ]---------------------------------
> > ...
> >
> > This is not particular to jgitver but to any core extension (takari
> > polyglot, tycho pom less, ...).
> > The way this jenkins project loads the Maven Project Object Model is
> > somehow wrong or at least not complete.
> >
> > IMO the POM loading is better done in maven-flatten-plugin.
> >
> > Matthieu
> >
> > On Fri, Apr 17, 2020 at 6:00 AM Olivier Lamy <[email protected]> wrote:
> >
> > > Hi,
> > >
> > > That's the way to do it
> > > There is a library to ease that here
> > > https://github.com/jenkinsci/lib-jenkins-maven-embedder/tree/master
> > >
> > > cheers
> > > Olivier
> > >
> > >
> > > On Fri, 17 Apr 2020 at 13:04, Tomo Suzuki <[email protected]>
> > > wrote:
> > >
> > > > I'm interested in that problem too. In the project below, we use
> > > > PlexusContainer to instantiate MavenProject class from pom file:
> > > >
> > > >
> > >
> >
> https://github.com/GoogleCloudPlatform/cloud-opensource-java/blob/master/dependencies/src/main/java/com/google/cloud/tools/opensource/dependencies/RepositoryUtility.java#L209
> > > >
> > > > I hope there's a better way to achieve this.
> > > >
> > > > On Thu, Apr 16, 2020 at 6:55 AM Andres Almiray <[email protected]>
> > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I'm looking for a way to launch Maven programmatically in such a
> way
> > > > that I
> > > > > can get access to fully resolved Model and MavenProject instances,
> > and
> > > > not
> > > > > just for a single project but also for all projects that belong to
> a
> > > > > Reactor.
> > > > >
> > > > > At first I used this code
> > > > >
> > > > > try {
> > > > >     FileReader reader = new FileReader(pom);
> > > > >     MavenXpp3Reader mavenReader = new MavenXpp3Reader();
> > > > >     return new MavenProject(mavenReader.read(reader));
> > > > > } catch (Exception e) {
> > > > >     throw new IllegalArgumentException(e);
> > > > > }
> > > > >
> > > > > But of course that's not enough. Next I tried using the
> > > > maven-model-builder
> > > > > APIs directly but not all references get resolved (such as parent
> > POMs)
> > > > as
> > > > > a custom ModelResolver is required and the default one is not
> > intended
> > > to
> > > > > be used in standalone fashion.
> > > > >
> > > > > Ideally I would call some sort of embeddable Maven API that can
> give
> > me
> > > > the
> > > > > answers I seek, something like this
> > > > >
> > > > > MavenProject project =
> > > > EmbeddableMaven.launch(propsOrFlags).file(pomFile);
> > > > >
> > > > > or alternatively something like
> > > > >
> > > > > MavenReactor reactor =
> > > > EmbeddableMaven.launch(propsOrFlags).file(pomFile);
> > > > > for(MavenProject project : reactor.getProjects()) { /* do stuff */
> }
> > > > >
> > > > > Of course I'm making up these types and method names as I do not
> know
> > > if
> > > > > something like this exist or not, hence why I'm asking here.
> > > > >
> > > > > Thanks in advance.
> > > > >
> > > > > Cheers
> > > > > Andres
> > > > >
> > > >
> > > >
> > > > --
> > > > Regards,
> > > > Tomo
> > > >
> > >
> > >
> > > --
> > > Olivier Lamy
> > > http://twitter.com/olamy | http://linkedin.com/in/olamy
> > >
> >
>
>
> --
> Olivier Lamy
> http://twitter.com/olamy | http://linkedin.com/in/olamy
>

Reply via email to