java - How to get MavenProject in maven3 -


i want automate part of our build system in java. need calculate dependency tree of sources existent in given file tree.

so, want crawl on set of directories , find pom.xml files existent there. works fine. want parse files instances of mavenproject can call getparent() , getdependencies() , such on it.

so, question is: how populated mavenproject maven3 libraries? acceptable me include third party library if necessary prefer solution consists of maven natives.

i have read get mavenproject pom.xml - pom parser? answers there don't work me (the mavenproject not not populated correctly)

my code in java, want have contents of method this:

private mavenproject makeprojectfrompom(file pomxml) {     // here don't know. } 

so can in program:

public list<mavenproject> getallmavenprojectswithparent(file rootdir, mavenproject parent) {    list<file> allpoms = findallpoms(rootdir);    list<mavenproject> result = new arraylist<>();    for(file nextpom : allpoms) {        mavenproject next = makeprojectfrompom(nextpom);        if(next.hasparent() && next.getparent().equals(parent))            result.add(next);    }    return result; } 

this example, 1 not work @ moment me.

in maven2 this:

    string basepath = "somepath";     mavenembedder embedder = new mavenembedder();     file basedir = new file(basepath);     final list<file> alldirswithpomxml = new arraylist<>();     // next line crawls through directory , collects references pom.xml paths.     gatherpomxmlpaths(basedir, alldirswithpomxml);     embedder.setclassloader(this.getclass().getclassloader());     embedder.start();     list<mavenproject> collectedprojects = new arraylist<>();     (file nextdir : alldirswithpomxml) {         collectedprojects.addall(embedder.collectprojects(nextdir, new string[]{"pom.xml"}, new string[0]));     } 

the mavenproject references in collectedprojects contain information parent, dependencies etc.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -