Search in sources :

Example 6 with MavenServerExecutionResult

use of org.jetbrains.idea.maven.server.MavenServerExecutionResult in project intellij-plugins by JetBrains.

the class Flexmojos3ImporterTest method testTransitiveDepsOnPartialProjectImport.

public void testTransitiveDepsOnPartialProjectImport() throws IOException, MavenProcessCanceledException {
    createProjectPom(mavenProjectDescription("aggregator", "pom") + "  <modules>\n" + "    <module>app</module>\n" + "    <module>libA</module>\n" + "    <module>libB</module>\n" + "  </modules>\n");
    final VirtualFile app = createModulePom("app", parent() + "  <artifactId>ttApp</artifactId>\n" + "  <packaging>jar</packaging>\n" + "\n" + dependencies("A", "jar"));
    createModulePom("libA", parent() + "  <artifactId>A</artifactId>\n" + "  <packaging>jar</packaging>\n" + "  \n" + dependencies("B", "jar"));
    createModulePom("libB", parent() + "  <artifactId>B</artifactId>\n" + "  <packaging>jar</packaging>");
    importProject();
    MavenProjectsTree.EmbedderTask task = new MavenProjectsTree.EmbedderTask() {

        @Override
        public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
            MavenWorkspaceMap workspaceMap = new MavenWorkspaceMap();
            for (MavenProject mavenProject : myProjectsTree.getProjects()) {
                if (MavenConstants.TYPE_JAR.equalsIgnoreCase(mavenProject.getPackaging())) {
                    workspaceMap.register(mavenProject.getMavenId(), new File(mavenProject.getFile().getPath()), new File(mavenProject.getMavenId().getArtifactId() + ".jar"));
                } else {
                    workspaceMap.register(mavenProject.getMavenId(), new File(mavenProject.getFile().getPath()));
                }
            }
            embedder.customizeForStrictResolve(workspaceMap, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
            MavenServerExecutionResult result = embedder.execute(app, Collections.emptyList(), Collections.emptyList(), Collections.singletonList("compile"));
            assertEmpty(result.problems);
            assertNotNull(result);
            // test find all transitive deps (MavenWorkspaceMap filler is responsible for)
            MavenModel mavenModel = result.projectData.mavenModel;
            assertTransitiveDeps(TEST_GROUP_ID, TEST_VERSION, mavenModel.getDependencies());
            // test correct artifact file (must be SWC/JAR (project product), but not POM) (CustomArtifactResolver is responsible for)
            MavenArtifact resolve = embedder.resolve(new MavenArtifactInfo(TEST_GROUP_ID, "B", TEST_VERSION, MavenConstants.TYPE_JAR, null), mavenModel.getRemoteRepositories());
            assertNotNull(resolve);
            assertEquals("B.jar", resolve.getFile().getPath());
        }
    };
    MavenProject appProject = myProjectsTree.findProject(new MavenId(TEST_GROUP_ID, "ttApp", TEST_VERSION));
    assertNotNull(appProject);
    myProjectsTree.executeWithEmbedder(appProject, myProjectsManager.getEmbeddersManager(), MavenEmbeddersManager.FOR_POST_PROCESSING, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS, task);
    List<MavenArtifact> appSubProjectDeps = appProject.getDependencies();
    assertTransitiveDeps(TEST_GROUP_ID, TEST_VERSION, appSubProjectDeps);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsTree(org.jetbrains.idea.maven.project.MavenProjectsTree) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testDependencyWithUnresolvedParent.

public void _testDependencyWithUnresolvedParent() throws Exception {
    File repo = new File(myDir, "/repo");
    setRepositoryPath(repo.getPath());
    initEmbedder();
    VirtualFile m = createModulePom("foo-parent", "<groupId>test</groupId>" + "<artifactId>foo-parent</artifactId>" + "<version>1</version>" + "<packaging>pom</packaging>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    myEmbedder.execute(m, Collections.<String>emptyList(), Collections.<String>emptyList(), Arrays.asList("install"));
    myEmbedder.reset();
    File fooParentFile = new File(repo, "test/foo-parent/1/foo-parent-1.pom");
    assertTrue(fooParentFile.exists());
    m = createModulePom("foo", "<artifactId>foo</artifactId>" + "<version>1</version>" + "<parent>" + "  <groupId>test</groupId>" + "  <artifactId>foo-parent</artifactId>" + "  <version>1</version>" + "</parent>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    myEmbedder.execute(m, Collections.<String>emptyList(), Collections.<String>emptyList(), Arrays.asList("install"));
    myEmbedder.reset();
    assertTrue(new File(repo, "test/foo/1/foo-1.pom").exists());
    FileUtil.delete(fooParentFile);
    // reset all caches
    initEmbedder();
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>test</groupId>" + "    <artifactId>foo</artifactId>" + "    <version>1</version>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result.projectData);
    assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("test", "foo-parent", "1"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testResolvingProjectWithRegisteredExtensions.

public void _testResolvingProjectWithRegisteredExtensions() throws Exception {
    ComponentDescriptor desc = new ComponentDescriptor();
    desc.setRole(ArtifactHandler.ROLE);
    desc.setRoleHint("foo");
    desc.setImplementation(MyArtifactHandler.class.getName());
    myEmbedderImpl.getContainer().addComponentDescriptor(desc);
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>junit</groupId>" + "    <artifactId>junit</artifactId>" + "    <version>3.8.1</version>" + "    <scope>test</scope>" + "    <type>foo</type>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result.projectData);
    assertOrderedElementsAreEqual(result.unresolvedArtifacts);
    MavenModel p = result.projectData.mavenModel;
    assertEquals(1, p.getDependencies().size());
    assertEquals("pom", p.getDependencies().get(0).getExtension());
}
Also used : MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenModel(org.jetbrains.idea.maven.model.MavenModel) ComponentDescriptor(org.codehaus.plexus.component.repository.ComponentDescriptor) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole)

Example 9 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testResolvingProjectPropertiesInFolders.

public void _testResolvingProjectPropertiesInFolders() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    MavenModel project = result.projectData.mavenModel;
    assertNotNull(project);
    assertEquals("project", project.getMavenId().getArtifactId());
    PlatformTestUtil.assertPathsEqual(myProjectRoot.getPath() + "/target", project.getBuild().getDirectory());
    PlatformTestUtil.assertPathsEqual(myProjectRoot.getPath() + "/src/main/java", project.getBuild().getSources().get(0));
}
Also used : MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenModel(org.jetbrains.idea.maven.model.MavenModel) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole)

Example 10 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testUnresolvedSystemArtifacts.

public void _testUnresolvedSystemArtifacts() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>fff</groupId>" + "    <artifactId>zzz</artifactId>" + "    <version>666</version>" + "    <scope>system</scope>" + "    <systemPath>" + myProjectRoot.getPath() + "/foo.jar</systemPath>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result.projectData);
    assertOrderedElementsAreEqual(result.unresolvedArtifacts, new MavenId("fff", "zzz", "666"));
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole)

Aggregations

MavenServerExecutionResult (org.jetbrains.idea.maven.server.MavenServerExecutionResult)13 SoutMavenConsole (org.jetbrains.idea.maven.execution.SoutMavenConsole)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 MavenModel (org.jetbrains.idea.maven.model.MavenModel)5 File (java.io.File)4 MavenId (org.jetbrains.idea.maven.model.MavenId)4 MavenEmbedderWrapper (org.jetbrains.idea.maven.server.MavenEmbedderWrapper)3 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 MavenProcessCanceledException (org.jetbrains.idea.maven.utils.MavenProcessCanceledException)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 Comparing (com.intellij.openapi.util.Comparing)1 Pair (com.intellij.openapi.util.Pair)1 StringUtil.isEmptyOrSpaces (com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces)1 IgnoredFileBean (com.intellij.openapi.vcs.changes.IgnoredFileBean)1 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1