Search in sources :

Example 1 with MavenProjectsTree

use of org.jetbrains.idea.maven.project.MavenProjectsTree in project intellij-community by JetBrains.

the class MavenProjectsTreeReadingTest method testSaveLoad.

public void testSaveLoad() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<modules>" + "  <module>m1</module>" + "  <module>m2</module>" + "</modules>" + // stripping down plugins
    "<build>" + "  <plugins>" + "    <plugin>" + "      <groupId>org.apache.maven.plugins</groupId>" + "      <artifactId>maven-compiler-plugin</artifactId>" + "      <configuration>" + "        <source>1.4</source>" + "      </configuration>" + "    </plugin>" + "  </plugins>" + "</build>" + // stripping down Xpp3Dom fields
    "<reports>" + "  <someTag/>" + "</reports>");
    VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>");
    VirtualFile m2 = createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>");
    updateAll(myProjectPom);
    MavenProject parentProject = myTree.findProject(myProjectPom);
    MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
    try {
        myTree.resolve(myProject, parentProject, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
    } finally {
        embeddersManager.releaseInTests();
    }
    Path f = myDir.toPath().resolve("tree.dat");
    myTree.save(f);
    MavenProjectsTree read = MavenProjectsTree.read(myProject, f);
    List<MavenProject> roots = read.getRootProjects();
    assertEquals(1, roots.size());
    MavenProject rootProject = roots.get(0);
    assertEquals(myProjectPom, rootProject.getFile());
    assertEquals(2, read.getModules(rootProject).size());
    assertEquals(m1, read.getModules(rootProject).get(0).getFile());
    assertEquals(m2, read.getModules(rootProject).get(1).getFile());
    assertNull(read.findAggregator(rootProject));
    assertEquals(rootProject, read.findAggregator(read.findProject(m1)));
    assertEquals(rootProject, read.findAggregator(read.findProject(m2)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Path(java.nio.file.Path) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenProjectsTree(org.jetbrains.idea.maven.project.MavenProjectsTree) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Path (java.nio.file.Path)1 MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)1 MavenProject (org.jetbrains.idea.maven.project.MavenProject)1 MavenProjectsTree (org.jetbrains.idea.maven.project.MavenProjectsTree)1