use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class PomManagementServiceImplTest method testGetPomsOfMultiModuleProjectWhenParentAndChildAreDirty.
@Test
public void testGetPomsOfMultiModuleProjectWhenParentAndChildAreDirty() throws Exception {
// Set up
setUpWorkingDirectory("multi");
final String rootPom = "multi/pom.xml";
final String rootPomCanonicalPath = getCanonicalPath(rootPom);
final String childPom = "multi/foo-child/pom.xml";
final String childPomCanonicalPath = getCanonicalPath(childPom);
final Collection<String> dirtyFiles = Arrays.asList(rootPomCanonicalPath, childPomCanonicalPath);
when(mockFileMonitorService.getDirtyFiles(PomManagementServiceImpl.class.getName())).thenReturn(dirtyFiles);
final Pom mockRootPom = getMockPom(ROOT_MODULE_NAME, rootPomCanonicalPath);
final String childModuleName = "foo-child";
final Pom mockChildPom = getMockPom(childModuleName, childPomCanonicalPath);
when(mockFileManager.getInputStream(rootPomCanonicalPath)).thenReturn(getClass().getResourceAsStream(rootPom));
when(mockFileManager.getInputStream(childPomCanonicalPath)).thenReturn(getClass().getResourceAsStream(childPom));
// Invoke
final Collection<Pom> poms = service.getPoms();
// Check
final Collection<Pom> expectedPoms = Arrays.asList(mockRootPom, mockChildPom);
assertEquals(expectedPoms.size(), poms.size());
assertTrue(poms.containsAll(expectedPoms));
verifyProjectMetadataNotification(ROOT_MODULE_NAME, childModuleName);
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class PomManagementServiceImplTest method testGetPomsOfMultiModuleProjectWhenChildIsDirty.
@Test
public void testGetPomsOfMultiModuleProjectWhenChildIsDirty() throws Exception {
// Set up
setUpWorkingDirectory("multi");
final String rootPom = FileUtils.getSystemDependentPath("multi", "pom.xml");
final String rootPomCanonicalPath = getCanonicalPath(rootPom);
final String childPom = FileUtils.getSystemDependentPath("multi", "foo-child", "pom.xml");
final String childPomCanonicalPath = getCanonicalPath(childPom);
final Collection<String> dirtyFiles = Arrays.asList(childPomCanonicalPath);
when(mockFileMonitorService.getDirtyFiles(PomManagementServiceImpl.class.getName())).thenReturn(dirtyFiles);
final Pom mockRootPom = getMockPom(ROOT_MODULE_NAME, rootPomCanonicalPath);
final String childModuleName = "foo-child";
final Pom mockChildPom = getMockPom(childModuleName, childPomCanonicalPath);
when(mockFileManager.getInputStream(rootPomCanonicalPath)).thenReturn(getClass().getResourceAsStream(rootPom));
when(mockFileManager.getInputStream(childPomCanonicalPath)).thenReturn(getClass().getResourceAsStream(childPom));
service.addPom(mockRootPom);
// Invoke
final Collection<Pom> poms = service.getPoms();
// Check
final Collection<Pom> expectedPoms = Arrays.asList(mockRootPom, mockChildPom);
assertEquals(expectedPoms.size(), poms.size());
assertTrue(poms.containsAll(expectedPoms));
verifyProjectMetadataNotification(childModuleName);
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class AbstractProjectOperations method getProjectName.
public String getProjectName(final String moduleName) {
final Pom pom = getPomFromModuleName(moduleName);
Validate.notNull(pom, "A pom with module name '%s' could not be found", moduleName);
return pom.getDisplayName();
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class AbstractProjectOperations method removeDependency.
/**
* Removes an element identified by the given dependency, whenever it occurs
* at the given path
*
* @param moduleName the name of the module to remove the dependency from
* @param dependency the dependency to remove
* @param containingPath the path to the dependencies element
* @param path the path to the individual dependency elements
*/
private void removeDependency(final String moduleName, final Dependency dependency, final String containingPath, final String path) {
Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited at this time");
Validate.notNull(dependency, "Dependency to remove required");
final Pom pom = getPomFromModuleName(moduleName);
Validate.notNull(pom, "The pom is not available, so dependency removal cannot be performed");
if (!pom.isDependencyRegistered(dependency, false)) {
return;
}
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath()));
final Element root = document.getDocumentElement();
String descriptionOfChange = "";
final Element dependenciesElement = XmlUtils.findFirstElement(containingPath, root);
for (final Element candidate : XmlUtils.findElements(path, root)) {
if (dependency.equals(new Dependency(candidate))) {
dependenciesElement.removeChild(candidate);
descriptionOfChange = highlight(REMOVED + " dependency") + " " + dependency.getSimpleDescription();
// Stay in the loop, just in case it was in the POM more than
// once
}
}
DomUtils.removeTextNodes(dependenciesElement);
fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false);
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class AbstractProjectOperations method updateDependencyScope.
public void updateDependencyScope(final String moduleName, final Dependency dependency, final DependencyScope dependencyScope) {
Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited at this time");
Validate.notNull(dependency, "Dependency to update required");
final Pom pom = getPomFromModuleName(moduleName);
Validate.notNull(pom, "The pom is not available, so updating a dependency cannot be performed");
if (!pom.isDependencyRegistered(dependency, false)) {
return;
}
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath()));
final Element root = document.getDocumentElement();
final Element dependencyElement = XmlUtils.findFirstElement("/project/dependencies/dependency[groupId = '" + dependency.getGroupId() + "' and artifactId = '" + dependency.getArtifactId() + "' and version = '" + dependency.getVersion() + "']", root);
if (dependencyElement == null) {
return;
}
final Element scopeElement = XmlUtils.findFirstElement("scope", dependencyElement);
final String descriptionOfChange;
if (scopeElement == null) {
if (dependencyScope != null) {
dependencyElement.appendChild(new XmlElementBuilder("scope", document).setText(dependencyScope.name().toLowerCase()).build());
descriptionOfChange = highlight(ADDED + " scope") + " " + dependencyScope.name().toLowerCase() + " to dependency " + dependency.getSimpleDescription();
} else {
descriptionOfChange = null;
}
} else {
if (dependencyScope != null) {
scopeElement.setTextContent(dependencyScope.name().toLowerCase());
descriptionOfChange = highlight(CHANGED + " scope") + " to " + dependencyScope.name().toLowerCase() + " in dependency " + dependency.getSimpleDescription();
} else {
dependencyElement.removeChild(scopeElement);
descriptionOfChange = highlight(REMOVED + " scope") + " from dependency " + dependency.getSimpleDescription();
}
}
if (descriptionOfChange != null) {
fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false);
}
}
Aggregations