Search in sources :

Example 11 with MavenProjectsManager

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

the class RemoveManagedFilesAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final DataContext context = e.getDataContext();
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return;
    List<VirtualFile> selectedFiles = MavenActionUtil.getMavenProjectsFiles(context);
    List<VirtualFile> removableFiles = new ArrayList<>();
    for (VirtualFile pomXml : selectedFiles) {
        if (projectsManager.isManagedFile(pomXml)) {
            removableFiles.add(pomXml);
        } else {
            notifyUserIfNeeded(context, projectsManager, selectedFiles, pomXml);
        }
    }
    projectsManager.removeManagedFiles(removableFiles);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) ArrayList(java.util.ArrayList)

Example 12 with MavenProjectsManager

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

the class RunBuildAction method checkOrPerform.

private static boolean checkOrPerform(DataContext context, boolean perform) {
    final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
    if (goals == null || goals.isEmpty())
        return false;
    final Project project = MavenActionUtil.getProject(context);
    if (project == null)
        return false;
    final MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
    if (mavenProject == null)
        return false;
    if (!perform)
        return true;
    final MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return false;
    MavenExplicitProfiles explicitProfiles = projectsManager.getExplicitProfiles();
    final MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), goals, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
    MavenRunConfigurationType.runConfiguration(project, params, null);
    return true;
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 13 with MavenProjectsManager

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

the class ToggleIgnoredProjectsAction method isAvailable.

@Override
protected boolean isAvailable(AnActionEvent e) {
    if (!super.isAvailable(e))
        return false;
    final DataContext context = e.getDataContext();
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return false;
    List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
    if (projects == null || projects.isEmpty())
        return false;
    int ignoredStatesCount = 0;
    int ignoredCount = 0;
    for (MavenProject each : projects) {
        if (projectsManager.getIgnoredState(each)) {
            ignoredStatesCount++;
        }
        if (projectsManager.isIgnored(each)) {
            ignoredCount++;
        }
    }
    return (ignoredCount == 0 || ignoredCount == projects.size()) && (ignoredStatesCount == 0 || ignoredStatesCount == projects.size());
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 14 with MavenProjectsManager

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

the class MavenPropertyCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiFile psiFile = parameters.getOriginalFile();
    Project project = psiFile.getProject();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    if (!manager.isMavenizedProject())
        return;
    MavenProject projectFile = MavenDomUtil.findContainingProject(psiFile);
    if (projectFile == null)
        return;
    if (!MavenDomUtil.isMavenFile(psiFile) && !MavenDomUtil.isFilteredResourceFile(psiFile))
        return;
    String text = psiFile.getText();
    int offset = parameters.getOffset();
    int braceOffset = findOpenBrace(text, offset);
    if (braceOffset == -1)
        return;
    TextRange range = TextRange.create(braceOffset, offset);
    String prefix = range.substring(text);
    MavenFilteredPropertyPsiReference ref = new MavenFilteredPropertyPsiReference(projectFile, psiFile, prefix, range);
    addVariants(Arrays.asList(ref.getVariants()), result.withPrefixMatcher(prefix));
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange)

Example 15 with MavenProjectsManager

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

the class MavenPropertyPsiReferenceProvider method findMavenProject.

@Nullable
private static MavenProject findMavenProject(PsiElement element) {
    VirtualFile virtualFile = MavenDomUtil.getVirtualFile(element);
    if (virtualFile == null)
        return null;
    MavenProjectsManager manager = MavenProjectsManager.getInstance(element.getProject());
    return manager.findProject(virtualFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)52 MavenProject (org.jetbrains.idea.maven.project.MavenProject)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Project (com.intellij.openapi.project.Project)13 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 Nullable (org.jetbrains.annotations.Nullable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)6 PsiFile (com.intellij.psi.PsiFile)6 Notification (com.intellij.notification.Notification)4 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)4 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)4 NotificationListener (com.intellij.notification.NotificationListener)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 XmlElement (com.intellij.psi.xml.XmlElement)2 List (java.util.List)2