Search in sources :

Example 1 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testUnresolvedArtifacts.

public void _testUnresolvedArtifacts() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>fff</groupId>" + "    <artifactId>zzz</artifactId>" + "    <version>666</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("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)

Example 2 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testUnresolvedSystemArtifactsWithoutPath.

public void _testUnresolvedSystemArtifactsWithoutPath() throws Exception {
    // need to repair model before resolving
    if (ignore())
        return;
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>fff</groupId>" + "    <artifactId>zzz</artifactId>" + "    <version>666</version>" + "    <scope>system</scope>" + "  </dependency>" + "</dependencies>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.resolveProject(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertNotNull(result);
    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)

Example 3 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testResolvingProjectWithExtensions.

public void _testResolvingProjectWithExtensions() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>com.adobe.flex.framework</groupId>" + "    <artifactId>framework</artifactId>" + "    <version>3.2.0.3958</version>" + "    <type>resource-bundle</type>" + "    <classifier>en_US</classifier>" + "  </dependency>" + "</dependencies>" + "<build>" + "  <plugins>" + "    <plugin>" + "      <groupId>org.sonatype.flexmojos</groupId>" + "      <artifactId>flexmojos-maven-plugin</artifactId>" + "      <version>3.5.0</version>" + "      <extensions>true</extensions>" + "    </plugin>" + "  </plugins>" + "</build>");
    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("rb.swc", p.getDependencies().get(0).getExtension());
}
Also used : MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenModel(org.jetbrains.idea.maven.model.MavenModel) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole)

Example 4 with MavenServerExecutionResult

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

the class MavenProjectReader method generateSources.

@Nullable
public static MavenProjectReaderResult generateSources(MavenEmbedderWrapper embedder, MavenImportingSettings importingSettings, VirtualFile file, MavenExplicitProfiles profiles, MavenConsole console) throws MavenProcessCanceledException {
    try {
        List<String> goals = Collections.singletonList(importingSettings.getUpdateFoldersOnImportPhase());
        MavenServerExecutionResult result = embedder.execute(file, profiles.getEnabledProfiles(), profiles.getDisabledProfiles(), goals);
        MavenServerExecutionResult.ProjectData projectData = result.projectData;
        if (projectData == null)
            return null;
        return new MavenProjectReaderResult(projectData.mavenModel, projectData.mavenModelMap, new MavenExplicitProfiles(projectData.activatedProfiles, profiles.getDisabledProfiles()), projectData.nativeMavenProject, result.problems, result.unresolvedArtifacts);
    } catch (Throwable e) {
        console.printException(e);
        MavenLog.LOG.warn(e);
        return null;
    }
}
Also used : MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with MavenServerExecutionResult

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

the class MavenProjectReader method resolveProject.

public Collection<MavenProjectReaderResult> resolveProject(final MavenGeneralSettings generalSettings, MavenEmbedderWrapper embedder, Collection<VirtualFile> files, final MavenExplicitProfiles explicitProfiles, final MavenProjectReaderProjectLocator locator) throws MavenProcessCanceledException {
    try {
        Collection<MavenServerExecutionResult> executionResults = embedder.resolveProject(files, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
        Collection<MavenProjectReaderResult> readerResults = ContainerUtil.newArrayList();
        for (MavenServerExecutionResult result : executionResults) {
            MavenServerExecutionResult.ProjectData projectData = result.projectData;
            if (projectData == null) {
                if (files.size() == 1) {
                    final VirtualFile file = files.iterator().next();
                    MavenProjectReaderResult temp = readProject(generalSettings, file, explicitProfiles, locator);
                    temp.readingProblems.addAll(result.problems);
                    temp.unresolvedArtifactIds.addAll(result.unresolvedArtifacts);
                    readerResults.add(temp);
                }
            } else {
                readerResults.add(new MavenProjectReaderResult(projectData.mavenModel, projectData.mavenModelMap, new MavenExplicitProfiles(projectData.activatedProfiles, explicitProfiles.getDisabledProfiles()), projectData.nativeMavenProject, result.problems, result.unresolvedArtifacts));
            }
        }
        return readerResults;
    } catch (MavenProcessCanceledException e) {
        throw e;
    } catch (final Throwable e) {
        MavenLog.LOG.info(e);
        // print exception since we need to know if something wrong with our logic
        MavenLog.printInTests(e);
        return ContainerUtil.mapNotNull(files, file -> {
            MavenProjectReaderResult result = readProject(generalSettings, file, explicitProfiles, locator);
            String message = e.getMessage();
            if (message != null) {
                result.readingProblems.add(MavenProjectProblem.createStructureProblem(file.getPath(), message));
            } else {
                result.readingProblems.add(MavenProjectProblem.createSyntaxProblem(file.getPath(), MavenProjectProblem.ProblemType.SYNTAX));
            }
            return result;
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProfileApplicationResult(org.jetbrains.idea.maven.server.ProfileApplicationResult) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenLog(org.jetbrains.idea.maven.utils.MavenLog) THashSet(gnu.trove.THashSet) MavenServerManager(org.jetbrains.idea.maven.server.MavenServerManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) Comparing(com.intellij.openapi.util.Comparing) Project(com.intellij.openapi.project.Project) MavenUtil.getBaseDir(org.jetbrains.idea.maven.utils.MavenUtil.getBaseDir) StringUtil.isEmptyOrSpaces(com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces) org.jetbrains.idea.maven.model(org.jetbrains.idea.maven.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenUtil(org.jetbrains.idea.maven.utils.MavenUtil) IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) MavenJDOMUtil(org.jetbrains.idea.maven.utils.MavenJDOMUtil) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult)

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