/** * 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; }
/** * Returns an execution command to launch Maven. If Maven home environment variable isn't set then * 'mvn' will be returned since it's assumed that 'mvn' should be in PATH variable. * * @return an execution command to launch Maven */ public static String getMavenExecCommand() { final java.io.File mvnHome = getMavenHome(); if (mvnHome != null) { final String mvn = "bin" + java.io.File.separatorChar + "mvn"; return new java.io.File(mvnHome, mvn) .getAbsolutePath(); // use Maven home directory if it's set } else { return "mvn"; // otherwise 'mvn' should be in PATH variable } }
/** Get resource directories. */ public static List<String> getResourceDirectories(java.io.File pom) throws IOException { return getResourceDirectories(Model.readFrom(pom)); }
return new Extension( gwtModuleName, MavenUtils.getGroupId(pom), pom.getArtifactId(), MavenUtils.getVersion(pom));
/** Get source directories. */ public static List<String> getSourceDirectories(java.io.File pom) throws IOException { return getSourceDirectories(Model.readFrom(pom)); }
public void close() throws IOException {} }; readMavenVersionInformation(cmdOutput); return versionInfo;
final String[] segments = removeLoggerPrefix(line).split(":"); if (segments.length >= 5) { final String groupId = segments[0];
private static void readMavenVersionInformation(LineConsumer cmdOutput) throws IOException { final CommandLine commandLine = new CommandLine(getMavenExecCommand()).add("-version"); final ProcessBuilder processBuilder = new ProcessBuilder().command(commandLine.toShellCommand()).redirectErrorStream(true); final Process process = processBuilder.start(); ProcessUtil.process(process, cmdOutput, LineConsumer.DEV_NULL); } }
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); } } }