Search in sources :

Example 11 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testResolvingProject.

public void _testResolvingProject() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>junit</groupId>" + "    <artifactId>junit</artifactId>" + "    <version>4.0</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);
    MavenModel project = result.projectData.mavenModel;
    assertNotNull(project);
    assertEquals("project", project.getMavenId().getArtifactId());
    assertEquals(1, project.getDependencies().size());
}
Also used : MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenModel(org.jetbrains.idea.maven.model.MavenModel) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole)

Example 12 with MavenServerExecutionResult

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

the class MavenServerEmbedderTest method _testExecutionGoals.

public void _testExecutionGoals() throws Exception {
    createProjectSubFile("src/main/java/A.java", "public class A {}");
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    myEmbedder.customizeForResolve(new SoutMavenConsole(), EMPTY_MAVEN_PROCESS);
    MavenServerExecutionResult result = myEmbedder.execute(myProjectPom, Collections.<String>emptyList(), Collections.<String>emptyList(), Arrays.asList("compile"));
    assertNotNull(result.projectData);
    assertNotNull(new File(getProjectPath(), "target").exists());
    assertOrderedElementsAreEqual(result.unresolvedArtifacts);
    MavenModel project = result.projectData.mavenModel;
    assertNotNull(project);
    assertEquals("project", project.getMavenId().getArtifactId());
}
Also used : MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenModel(org.jetbrains.idea.maven.model.MavenModel) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 13 with MavenServerExecutionResult

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

the class Flexmojos3GenerateConfigTask method perform.

public void perform(final Project project, final MavenEmbeddersManager embeddersManager, final MavenConsole console, final MavenProgressIndicator indicator) throws MavenProcessCanceledException {
    if (myModule.isDisposed())
        return;
    indicator.setText(FlexBundle.message("generating.flex.config.for", myMavenProject.getDisplayName()));
    final MavenProjectsTree.EmbedderTask task = new MavenProjectsTree.EmbedderTask() {

        public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
            List<VirtualFile> temporaryFiles = null;
            final IgnoredFileBean[] filesToIgnoreOriginal = ChangeListManager.getInstance(project).getFilesToIgnore();
            try {
                MavenWorkspaceMap workspaceMap = new MavenWorkspaceMap();
                temporaryFiles = mavenIdToOutputFileMapping(workspaceMap, project, myTree.getProjects());
                embedder.customizeForStrictResolve(workspaceMap, console, indicator);
                final String generateConfigGoal = FlexmojosImporter.FLEXMOJOS_GROUP_ID + ":" + FlexmojosImporter.FLEXMOJOS_ARTIFACT_ID + ":generate-config-" + myMavenProject.getPackaging();
                final MavenExplicitProfiles profilesIds = myMavenProject.getActivatedProfilesIds();
                MavenServerExecutionResult result = embedder.execute(myMavenProject.getFile(), profilesIds.getEnabledProfiles(), profilesIds.getDisabledProfiles(), Collections.singletonList(generateConfigGoal));
                if (result.projectData == null) {
                    myFlexConfigInformer.showFlexConfigWarningIfNeeded(project);
                }
                MavenUtil.invokeAndWaitWriteAction(project, () -> {
                    // need to refresh externally created file
                    final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(myConfigFilePath);
                    if (file != null) {
                        file.refresh(false, false);
                        updateMainClass(myModule, file);
                    }
                });
            } catch (MavenProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                myFlexConfigInformer.showFlexConfigWarningIfNeeded(project);
                console.printException(e);
                MavenLog.LOG.warn(e);
            } finally {
                ChangeListManager.getInstance(project).setFilesToIgnore(filesToIgnoreOriginal);
                if (temporaryFiles != null && !temporaryFiles.isEmpty()) {
                    removeTemporaryFiles(project, temporaryFiles);
                }
            }
        }
    };
    myTree.executeWithEmbedder(myMavenProject, embeddersManager, MavenEmbeddersManager.FOR_POST_PROCESSING, console, indicator, task);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) IgnoredFileBean(com.intellij.openapi.vcs.changes.IgnoredFileBean) MavenWorkspaceMap(org.jetbrains.idea.maven.model.MavenWorkspaceMap)

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