Search in sources :

Example 66 with MavenProject

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

the class MiscImportingTest method testExceptionsFromMavenExtensionsAreReportedAsProblems.

public void testExceptionsFromMavenExtensionsAreReportedAsProblems() throws Exception {
    MavenCustomRepositoryHelper helper = new MavenCustomRepositoryHelper(myDir, "plugins");
    setRepositoryPath(helper.getTestDataPath("plugins"));
    getMavenGeneralSettings().setWorkOffline(true);
    importProjectWithMaven3("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<description>throw!</description>" + "" + "<build>" + "  <extensions>" + "    <extension>" + "      <groupId>intellij.test</groupId>" + "      <artifactId>maven-extension</artifactId>" + "      <version>1.0</version>" + "    </extension>" + "  </extensions>" + "</build>");
    List<MavenProject> projects = myProjectsTree.getProjects();
    assertEquals(1, projects.size());
    MavenProject mavenProject = projects.get(0);
    assertEquals(mavenProject.getProblems().toString(), 1, mavenProject.getProblems().size());
    assertEquals("throw!", mavenProject.getProblems().get(0).getDescription());
}
Also used : MavenCustomRepositoryHelper(org.jetbrains.idea.maven.MavenCustomRepositoryHelper) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 67 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject 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 68 with MavenProject

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

the class ToggleBeforeRunTaskAction method doIsSelected.

@Override
protected boolean doIsSelected(AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final Pair<MavenProject, String> desc = getTaskDesc(context);
    if (desc != null) {
        final RunManagerEx runManager = getRunManager(context);
        if (runManager == null)
            return false;
        for (MavenBeforeRunTask each : runManager.getBeforeRunTasks(MavenBeforeRunTasksProvider.ID)) {
            if (each.isFor(desc.first, desc.second))
                return true;
        }
    }
    return false;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProject(org.jetbrains.idea.maven.project.MavenProject) RunManagerEx(com.intellij.execution.RunManagerEx) MavenBeforeRunTask(org.jetbrains.idea.maven.tasks.MavenBeforeRunTask)

Example 69 with MavenProject

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

the class ToggleBeforeRunTaskAction method setSelected.

@Override
public void setSelected(final AnActionEvent e, boolean state) {
    final DataContext context = e.getDataContext();
    final Pair<MavenProject, String> desc = getTaskDesc(context);
    if (desc != null) {
        new MavenExecuteBeforeRunDialog(MavenActionUtil.getProject(context), desc.first, desc.second).show();
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 70 with MavenProject

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

the class ToggleBeforeRunTaskAction method getTaskDesc.

@Nullable
protected static Pair<MavenProject, String> getTaskDesc(DataContext context) {
    List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
    if (goals == null || goals.size() != 1)
        return null;
    MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
    if (mavenProject == null)
        return null;
    return Pair.create(mavenProject, goals.get(0));
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

MavenProject (org.jetbrains.idea.maven.project.MavenProject)132 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)20 MavenId (org.jetbrains.idea.maven.model.MavenId)16 Project (com.intellij.openapi.project.Project)10 Nullable (org.jetbrains.annotations.Nullable)9 Bombed (com.intellij.idea.Bombed)8 Module (com.intellij.openapi.module.Module)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Result (com.intellij.openapi.application.Result)4 MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)4 MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 TextRange (com.intellij.openapi.util.TextRange)3 NotNull (org.jetbrains.annotations.NotNull)3 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)3 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)3 MavenProjectsTree (org.jetbrains.idea.maven.project.MavenProjectsTree)3