Search in sources :

Example 1 with MavenEmbeddersManager

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

the class MavenProjectsTreeReadingTest method testOutputPathsAreBasedOnTargetPathWhenResolving.

public void testOutputPathsAreBasedOnTargetPathWhenResolving() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + "  <directory>my-target</directory>" + "</build>");
    updateAll(myProjectPom);
    MavenProject project = myTree.getRootProjects().get(0);
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target"), project.getBuildDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/classes"), project.getOutputDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/test-classes"), project.getTestOutputDirectory());
    MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
    try {
        myTree.resolve(myProject, project, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
    } finally {
        embeddersManager.releaseInTests();
    }
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target"), project.getBuildDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/classes"), project.getOutputDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("my-target/test-classes"), project.getTestOutputDirectory());
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager)

Example 2 with MavenEmbeddersManager

use of org.jetbrains.idea.maven.project.MavenEmbeddersManager 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)

Example 3 with MavenEmbeddersManager

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

the class MavenProjectsTreeReadingTest method testCollectingProfilesFromParentsAfterResolve.

public void testCollectingProfilesFromParentsAfterResolve() throws Exception {
    MavenServerManager.getInstance().setUseMaven2(true);
    createModulePom("parent1", "<groupId>test</groupId>" + "<artifactId>parent1</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<profiles>" + "  <profile>" + "    <id>parent1Profile</id>" + "  </profile>" + "</profiles>");
    createProfilesXml("parent1", "<profile>" + "  <id>parent1ProfileXml</id>" + "</profile>");
    createModulePom("parent2", "<groupId>test</groupId>" + "<artifactId>parent2</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent1</artifactId>" + " <version>1</version>" + " <relativePath>../parent1/pom.xml</relativePath>" + "</parent>" + "<profiles>" + "  <profile>" + "    <id>parent2Profile</id>" + "  </profile>" + "</profiles>");
    createProfilesXml("parent2", "<profile>" + "  <id>parent2ProfileXml</id>" + "</profile>");
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<parent>" + " <groupId>test</groupId>" + " <artifactId>parent2</artifactId>" + " <version>1</version>" + " <relativePath>parent2/pom.xml</relativePath>" + "</parent>" + "<profiles>" + "  <profile>" + "    <id>projectProfile</id>" + "  </profile>" + "</profiles>");
    createProfilesXml("<profile>" + "  <id>projectProfileXml</id>" + "</profile>");
    updateSettingsXml("<profiles>" + "  <profile>" + "    <id>settings</id>" + "  </profile>" + "</profiles>");
    updateAll(Arrays.asList("projectProfileXml", "projectProfile", "parent1Profile", "parent1ProfileXml", "parent2Profile", "parent2ProfileXml", "settings", "xxx"), myProjectPom);
    MavenProject project = myTree.findProject(myProjectPom);
    assertUnorderedElementsAreEqual(project.getActivatedProfilesIds().getEnabledProfiles(), "projectProfileXml", "projectProfile", "parent1Profile", "parent1ProfileXml", "parent2Profile", "parent2ProfileXml", "settings");
    MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
    try {
        myTree.resolve(myProject, project, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
    } finally {
        embeddersManager.releaseInTests();
    }
    assertUnorderedElementsAreEqual(project.getActivatedProfilesIds().getEnabledProfiles(), "projectProfileXml", "projectProfile", "parent1Profile", "parent1ProfileXml", "parent2Profile", "parent2ProfileXml", "settings");
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager)

Example 4 with MavenEmbeddersManager

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

the class MavenProjectsTreeReadingTest method testDoNotUpdateChildAfterParentWasResolved.

public void testDoNotUpdateChildAfterParentWasResolved() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>parent</artifactId>" + "<version>1</version>");
    VirtualFile child = createModulePom("child", "<groupId>test</groupId>" + "<artifactId>child</artifactId>" + "<version>1</version>" + "<parent>" + "  <groupId>test</groupId>" + "  <artifactId>parent</artifactId>" + "  <version>1</version>" + "</parent>");
    MyLoggingListener listener = new MyLoggingListener();
    myTree.addListener(listener);
    updateAll(myProjectPom, child);
    MavenProject parentProject = myTree.findProject(myProjectPom);
    MavenEmbeddersManager embeddersManager = new MavenEmbeddersManager(myProject);
    try {
        final NativeMavenProjectHolder[] nativeProject = new NativeMavenProjectHolder[1];
        myTree.addListener(new MavenProjectsTree.Listener() {

            @Override
            public void projectResolved(Pair<MavenProject, MavenProjectChanges> projectWithChanges, NativeMavenProjectHolder nativeMavenProject) {
                nativeProject[0] = nativeMavenProject;
            }
        });
        myTree.resolve(myProject, parentProject, getMavenGeneralSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
        myTree.resolvePlugins(parentProject, nativeProject[0], embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
        myTree.resolveFolders(parentProject, getMavenImporterSettings(), embeddersManager, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
    } finally {
        embeddersManager.releaseInTests();
    }
    assertEquals("updated: parent child deleted: <none> resolved: parent plugins: parent folders: parent ", listener.log);
    myTree.updateAll(false, getMavenGeneralSettings(), EMPTY_MAVEN_PROCESS);
    assertEquals("updated: parent child deleted: <none> resolved: parent plugins: parent folders: parent ", listener.log);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectChanges(org.jetbrains.idea.maven.project.MavenProjectChanges) MavenProject(org.jetbrains.idea.maven.project.MavenProject) NativeMavenProjectHolder(org.jetbrains.idea.maven.server.NativeMavenProjectHolder) MavenProjectsTree(org.jetbrains.idea.maven.project.MavenProjectsTree) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager)

Example 5 with MavenEmbeddersManager

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

the class MavenVersionsRemoteManager method execute.

@NotNull
@Override
public List<String> execute(@NotNull RepositoryLibraryDescription repositoryLibraryDescription, ProgressIndicator indicator) {
    MavenEmbeddersManager manager = MavenProjectsManager.getInstance(myProject).getEmbeddersManager();
    MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_GET_VERSIONS, null, null);
    embedder.customizeForGetVersions();
    try {
        List<MavenRemoteRepository> remoteRepositories = convertRepositories(repositoryLibraryDescription.getRemoteRepositories());
        List<String> versions = embedder.retrieveVersions(repositoryLibraryDescription.getGroupId(), repositoryLibraryDescription.getArtifactId(), remoteRepositories);
        Collections.sort(versions, (o1, o2) -> {
            MavenVersionComparable v1 = new MavenVersionComparable(o1);
            MavenVersionComparable v2 = new MavenVersionComparable(o2);
            return v2.compareTo(v1);
        });
        return versions;
    } catch (MavenProcessCanceledException e) {
        return Collections.emptyList();
    } finally {
        manager.release(embedder);
    }
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenVersionComparable(org.jetbrains.idea.maven.dom.MavenVersionComparable) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)9 MavenProject (org.jetbrains.idea.maven.project.MavenProject)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 MavenEmbedderWrapper (org.jetbrains.idea.maven.server.MavenEmbedderWrapper)3 NotNull (org.jetbrains.annotations.NotNull)2 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)2 MavenProjectsTree (org.jetbrains.idea.maven.project.MavenProjectsTree)2 MavenProcessCanceledException (org.jetbrains.idea.maven.utils.MavenProcessCanceledException)2 CommonBundle (com.intellij.CommonBundle)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 WriteAction (com.intellij.openapi.application.WriteAction)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1