Search in sources :

Example 6 with Pom

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);
}
Also used : Pom(org.springframework.roo.project.maven.Pom) Test(org.junit.Test)

Example 7 with Pom

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);
}
Also used : Pom(org.springframework.roo.project.maven.Pom) Test(org.junit.Test)

Example 8 with Pom

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();
}
Also used : Pom(org.springframework.roo.project.maven.Pom)

Example 9 with Pom

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Pom(org.springframework.roo.project.maven.Pom)

Example 10 with Pom

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);
    }
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlElementBuilder(org.springframework.roo.support.util.XmlElementBuilder) Pom(org.springframework.roo.project.maven.Pom)

Aggregations

Pom (org.springframework.roo.project.maven.Pom)86 Element (org.w3c.dom.Element)19 JavaType (org.springframework.roo.model.JavaType)16 Document (org.w3c.dom.Document)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)9 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 Dependency (org.springframework.roo.project.Dependency)9 RooJavaType (org.springframework.roo.model.RooJavaType)7 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 ServiceReference (org.osgi.framework.ServiceReference)5 ControllerMVCResponseService (org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService)5 JavaPackage (org.springframework.roo.model.JavaPackage)5 List (java.util.List)4 Plugin (org.springframework.roo.project.Plugin)4 Completion (org.springframework.roo.shell.Completion)4 HashMap (java.util.HashMap)3 DataOnDemandCreatorProvider (org.springframework.roo.addon.test.providers.DataOnDemandCreatorProvider)3