/** * Stores the ID of this {@link PackagingProvider} as a POM property called * {@value #ROO_PACKAGING_PROVIDER_PROPERTY}. Subclasses can override this * method, but be aware that Roo needs some way of working out from a given * <code>pom.xml</code> file which {@link PackagingProvider} should be used. * * @param pom the DOM document for the POM being created */ protected void setPackagingProviderId(final Document pom) { final Node propertiesElement = DomUtils.createChildIfNotExists("properties", pom.getDocumentElement(), pom); DomUtils.createChildIfNotExists(ROO_PACKAGING_PROVIDER_PROPERTY, propertiesElement, pom) .setTextContent(getId()); }
final Element parentPomElement = DomUtils.createChildIfNotExists("parent", root, pom); final Element projectGroupIdElement = DomUtils.createChildIfNotExists("groupId", root, pom); DomUtils.createChildIfNotExists("groupId", parentPomElement, pom).setTextContent( parentPom.getGroupId()); DomUtils.createChildIfNotExists("artifactId", parentPomElement, pom).setTextContent( parentPom.getArtifactId()); DomUtils.createChildIfNotExists(VERSION_ELEMENT, parentPomElement, pom).setTextContent( parentPom.getVersion());
public void updateProjectType(final String moduleName, final ProjectType projectType) { Validate.notNull(projectType, "Project type required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so the project type cannot be changed"); final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element packaging = DomUtils.createChildIfNotExists("packaging", document.getDocumentElement(), document); if (packaging.getTextContent().equals(projectType.getType())) { return; } packaging.setTextContent(projectType.getType()); final String descriptionOfChange = highlight(UPDATED + " project type") + " to " + projectType.getType(); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
private void updateParentModulePom(final String moduleName) { final String parentPomPath = pomManagementService.getFocusedModule().getPath(); final Document parentPomDocument = XmlUtils.readXml(fileManager.getInputStream(parentPomPath)); final Element parentPomRoot = parentPomDocument.getDocumentElement(); DomUtils.createChildIfNotExists("packaging", parentPomRoot, parentPomDocument).setTextContent( "pom"); addModuleDeclaration(moduleName, parentPomDocument, parentPomRoot); final String addModuleMessage = getDescriptionOfChange(ADDED, Collections.singleton(moduleName), "module", "modules"); fileManager.createOrUpdateTextFileIfRequired(getFocusedModule().getPath(), XmlUtils.nodeToString(parentPomDocument), addModuleMessage, false); }
public void addResource(final String moduleName, final Resource resource) { Validate .isTrue(isProjectAvailable(moduleName), "Resource modification prohibited at this time"); Validate.notNull(resource, "Resource to add required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so resource addition cannot be performed"); if (pom.isResourceRegistered(resource)) { return; } final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element buildElement = XmlUtils.findFirstElement("/project/build", document.getDocumentElement()); final Element resourcesElement = DomUtils.createChildIfNotExists("resources", buildElement, document); resourcesElement.appendChild(resource.getElement(document)); final String descriptionOfChange = highlight(ADDED + " resource") + " " + resource.getSimpleDescription(); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
DomUtils.createChildIfNotExists("name", root, pom).setTextContent(mavenName.trim()); } else { DomUtils.removeElements("name", root); DomUtils.createChildIfNotExists("artifactId", root, pom).setTextContent(artifactId.trim()); DomUtils.createChildIfNotExists("packaging", root, pom).setTextContent(name); setPackagingProviderId(pom);
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element repositoriesElement = DomUtils.createChildIfNotExists(containingPath, document.getDocumentElement(), document);
if (addToPluginManagement) { pluginsElement = DomUtils.createChildIfNotExists("build/pluginManagement/plugins", parentRoot, parentDocument); } else { pluginsElement = DomUtils.createChildIfNotExists("/project/build/plugins", root, document); DomUtils.createChildIfNotExists(parentElementName, execution.getConfiguration() .getConfiguration(), document); if (newParentElement == null) { newParentElement = DomUtils.createChildIfNotExists(elementName, execution.getConfiguration() .getConfiguration(), parentDocument); elementsElement.appendChild(newParentElement); if (newParentElement == null) { newParentElement = DomUtils.createChildIfNotExists(elementName, execution.getConfiguration() .getConfiguration(), document); elementsElement.appendChild(newParentElement);
public void addFilter(final String moduleName, final Filter filter) { Validate.isTrue(isProjectAvailable(moduleName), "Filter modification prohibited at this time"); Validate.notNull(filter, "Filter required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so filter addition cannot be performed"); if (filter == null || pom.isFilterRegistered(filter)) { return; } final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element root = document.getDocumentElement(); final String descriptionOfChange; final Element buildElement = XmlUtils.findFirstElement("/project/build", root); final Element existingFilter = XmlUtils.findFirstElement("filters/filter['" + filter.getValue() + "']", buildElement); if (existingFilter == null) { // No such filter; add it final Element filtersElement = DomUtils.createChildIfNotExists("filters", buildElement, document); filtersElement.appendChild(XmlUtils.createTextElement(document, "filter", filter.getValue())); descriptionOfChange = highlight(ADDED + " filter") + " '" + filter.getValue() + "'"; } else { existingFilter.setTextContent(filter.getValue()); descriptionOfChange = highlight(UPDATED + " filter") + " '" + filter.getValue() + "'"; } fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
DomUtils.createChildIfNotExists("properties", document.getDocumentElement(), document); properties.appendChild(XmlUtils.createTextElement(document, property.getName(), property.getValue()));
DomUtils.createChildIfNotExists("dependencyManagement/dependencies", parentElement, parentDocument); final List<Element> existingDependencyManagementElements = DomUtils.createChildIfNotExists("dependencies", element, document); final List<Element> existingDependencyElements = XmlUtils.findElements("dependency", dependenciesElement);
DomUtils.createChildIfNotExists("build/pluginManagement/plugins", parentElement, parentDocument); final List<Element> existingPluginManagementElements = final Element pluginsElement = DomUtils.createChildIfNotExists("build/plugins", root, document); final List<Element> existingPluginElements = XmlUtils.findElements("plugin", pluginsElement); for (final Plugin newPlugin : newPlugins) {
final Element configurationElement = DomUtils.createChildIfNotExists( "configuration", warPluginElement, document); final Element webResourcesElement = DomUtils.createChildIfNotExists( "webResources", configurationElement, document); final Element resourceElement = DomUtils.createChildIfNotExists( "resource", webResourcesElement, document); final Element excludesElement = DomUtils.createChildIfNotExists( "excludes", resourceElement, document); excludeElement = DomUtils.createChildIfNotExists("exclude", excludesElement, document); final Element directoryElement = DomUtils.createChildIfNotExists( "directory", resourceElement, document);