/** * Get description of maven project and all its modules if any as plain list. * * @param sources maven project directory. Note: Must contains pom.xml file. * @return description of maven project * @throws IOException if an i/o error occurs */ public static List<Model> getModules(java.io.File sources) throws IOException { final LinkedList<Model> modules = new LinkedList<>(); addModules(Model.readFrom(sources), modules); return modules; }
private static void addModules(Model model, List<Model> modules) throws IOException { if (!"pom".equals(model.getPackaging())) return; for (String module : model.getModules()) { final Path modulePom = model.getProjectDirectory().toPath().resolve(module).resolve("pom.xml"); if (exists(modulePom)) { final Model child = Model.readFrom(modulePom); final String relativePath = modulePom.getParent().relativize(model.getPomFile().toPath()).toString(); child.setParent( new Parent(model.getGroupId(), model.getArtifactId(), model.getVersion()) .setRelativePath(relativePath)); modules.add(child); addModules(child, modules); } } }