Search in sources :

Example 81 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 82 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)

Example 83 with MavenProject

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

the class ToggleCompilerTasksAction method getTasks.

protected static List<MavenCompilerTask> getTasks(DataContext context) {
    final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
    if (goals == null || goals.isEmpty())
        return Collections.emptyList();
    MavenProject project = MavenActionUtil.getMavenProject(context);
    if (project == null)
        return Collections.emptyList();
    List<MavenCompilerTask> result = new ArrayList<>();
    for (String each : goals) {
        result.add(new MavenCompilerTask(project.getPath(), each));
    }
    return result;
}
Also used : MavenCompilerTask(org.jetbrains.idea.maven.tasks.MavenCompilerTask) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ArrayList(java.util.ArrayList)

Example 84 with MavenProject

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

the class MavenAttachSourcesProvider method getMavenProjects.

private static Collection<MavenProject> getMavenProjects(PsiFile psiFile) {
    Project project = psiFile.getProject();
    Collection<MavenProject> result = new ArrayList<>();
    for (OrderEntry each : ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(psiFile.getVirtualFile())) {
        MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(each.getOwnerModule());
        if (mavenProject != null)
            result.add(mavenProject);
    }
    return result;
}
Also used : Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ArrayList(java.util.ArrayList)

Example 85 with MavenProject

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

the class MavenShowEffectivePom method actionPerformed.

public static void actionPerformed(@NotNull final Project project, @NotNull final VirtualFile file) {
    final MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    final MavenProject mavenProject = manager.findProject(file);
    assert mavenProject != null;
    manager.evaluateEffectivePom(mavenProject, s -> ApplicationManager.getApplication().invokeLater(() -> {
        if (project.isDisposed())
            return;
        if (s == null) {
            new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Error", "Failed to evaluate effective pom.", NotificationType.ERROR).notify(project);
            return;
        }
        String fileName = mavenProject.getMavenId().getArtifactId() + "-effective-pom.xml";
        PsiFile file1 = PsiFileFactory.getInstance(project).createFileFromText(fileName, XMLLanguage.INSTANCE, s);
        try {
            file1.getVirtualFile().setWritable(false);
        } catch (IOException e) {
            LOG.error(e);
        }
        file1.navigate(true);
    }));
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) Notification(com.intellij.notification.Notification)

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