/** * Returns list of dependencies or empty list if project doesn't have dependencies. * * <p><b>Note: update methods should not be used on returned list</b> * * @see #dependencies() */ public List<Dependency> getDependencies() { return dependencies().get(); }
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); } } }
/** * Updates associated with model pom file content * * @throws IllegalStateException when there is no pom file associated with model */ public void save() throws IOException { if (pom == null) { throw new IllegalStateException("Model is not associated with any pom file"); } writeTo(pom); }
/** * Adds new property to the project. If property with given key already exists its value going to * be changed with new one. * * @param name property name * @param value property value * @return this model instance * @throws NullPointerException when given {@code name} or {@code value} is {@code null} */ public Model addProperty(String name, String value) { requireNonNull(name, "Property name should not be null"); requireNonNull(value, "Property value should not be null"); addPropertyToXML(name, value); properties().put(name, value); return this; }
/** * Reads model from given file, or if given file is a directory reads model from the * <i>pom.xml</i> which is under the given directory * * <p>After reading from pom file model will be associated with it, so {@link #getPomFile()} and * will return pom file and {@link #getProjectDirectory()} will return pom file parent directory. * * @param file <i>pom.xml</i> to read model from or its parent directory * @return fetched model * @throws IOException if any i/o error occurs * @throws org.eclipse.che.commons.xml.XMLTreeException when input stream contains not valid xml * content * @throws NullPointerException when given {@code file} is {@code null} */ public static Model readFrom(File file) throws IOException { requireNonNull(file, "Required not null file"); if (file.isDirectory()) { return readFrom(new File(file, "pom.xml")); } return fetchModel(XMLTree.from(file)).setPomFile(file); }
for (Extension extension : extensions) { final File pom = extResourcesWorkDirPath.resolve("pom.xml").toFile(); final Model model = Model.readFrom(pom); model .dependencies() .add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion)); model.writeTo(pom);
0, gwtModuleName.length() - GwtXmlUtils.GWT_MODULE_XML_SUFFIX.length()); Model pom = Model.readFrom(zipFile.getInputStream(pomEntry)); return new Extension( gwtModuleName, MavenUtils.getGroupId(pom), pom.getArtifactId(), MavenUtils.getVersion(pom));
/** * Reads model from given path. The behaviour is same to {@link #readFrom(java.io.File)} * * @param path to read from * @return fetched model * @throws NullPointerException when given {@code path} is {@code null} * @throws IOException if any i/o error occurs * @throws org.eclipse.che.commons.xml.XMLTreeException when input stream contains not valid xml * content */ public static Model readFrom(Path path) throws IOException { return readFrom(requireNonNull(path.toFile(), "Required not null model")); }
/** * Sets collection of repositories. * * <p><b>Note: all existing repositories will be removed from model and xml as well</b> * * @param repositories new plugin repositories */ public Model setRepositories(Collection<? extends Repository> repositories) { // remove existing repositories for (Repository repository : repositories()) { repository.remove(); } // add repositories if necessary if (repositories != null && !repositories.isEmpty()) { for (Repository repository : repositories) { addRepository(repository); } } else { root.removeChild("repositories"); this.repositories = null; } return this; }
/** * Sets list of profiles. * * <p><b>Note: all existing profiles will be removed from model and xml as well</b> * * @param profiles new profiles */ public Model setProfiles(Collection<? extends Profile> profiles) { // remove existing profiles for (Profile profile : profiles()) { profile.remove(); } // add profiles if necessary if (profiles != null && !profiles.isEmpty()) { for (Profile profile : profiles) { addProfile(profile); } } else { root.removeChild("profiles"); this.profiles = null; } return this; }
/** * Sets collection of plugin repositories. * * <p><b>Note: all existing plugin repositories will be removed from model and xml as well</b> * * @param pluginRepositories new plugin repositories */ public Model setPluginRepositories(Collection<? extends Repository> pluginRepositories) { // remove existing plugin repositories for (Repository pluginRepository : pluginRepositories()) { pluginRepository.remove(); } // add plugin repositories if necessary if (pluginRepositories != null && !pluginRepositories.isEmpty()) { for (Repository pluginRepository : pluginRepositories) { addPluginRepository(pluginRepository); } } else { root.removeChild("pluginRepositories"); this.pluginRepositories = null; } return this; }
private static Model fetchModel(XMLTree tree) { final Model model = new Model(tree); final Element root = tree.getRoot(); model.modelVersion = root.getChildText("modelVersion"); model.properties = fetchProperties(root.getSingleChild("properties"));
/** * Reads model from input stream. * * <p>Doesn't close the stream * * @param is input stream to read from * @return fetched model * @throws IOException if any i/o error occurs * @throws org.eclipse.che.commons.xml.XMLTreeException when input stream contains not valid xml * content * @throws NullPointerException when given {@code is} is {@code null} */ public static Model readFrom(InputStream is) throws IOException { return fetchModel(XMLTree.from(requireNonNull(is, "Required not null input stream"))); }
/** * Creates new pom xml model with root "project" element. * * @return created model */ public static Model createModel() { final XMLTree tree = XMLTree.create("project"); tree.getRoot() .setAttribute("xmlns", "http://maven.apache.org/POM/4.0.0") .setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") .setAttribute( "xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"); return new Model(tree); }
/** * 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; }
/** Get resource directories. */ public static List<String> getResourceDirectories(java.io.File pom) throws IOException { return getResourceDirectories(Model.readFrom(pom)); }
/** Get source directories. */ public static List<String> getSourceDirectories(java.io.File pom) throws IOException { return getSourceDirectories(Model.readFrom(pom)); }