public List < Model > getModelsRecursively ( String groupId , String artifactId , String version , File pom ) throws ArtifactResolutionException , ArtifactNotFoundException , IOException , XmlPullParserException { List < Model > models = null ; Model model = getPomModel ( groupId , artifactId , version , pom ) ; Parent parent = model . getParent ( ) ; // recurse into the parent if ( parent != null ) { // get the relative path String relativePath = parent . getRelativePath ( ) ; if ( StringUtils . isEmpty ( relativePath ) ) { relativePath = "../pom.xml" ; } // calculate the recursive path File parentPom = new File ( pom . getParent ( ) , relativePath ) ; // if relative path is a directory, append pom.xml if ( parentPom . isDirectory ( ) ) { parentPom = new File ( parentPom , "pom.xml" ) ; } models = getModelsRecursively ( parent . getGroupId ( ) , parent . getArtifactId ( ) , parent . getVersion ( ) , parentPom ) ; } else { // only create it here since I'm not at the top models = new ArrayList < Model > ( ) ; } models . add ( model ) ; return models ; }
This method loops through all the parents getting each pom model and then its parent .