Search in sources :

Example 36 with MavenProjectsManager

use of org.jetbrains.idea.maven.project.MavenProjectsManager 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)

Example 37 with MavenProjectsManager

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

the class OpenOrCreateSettingsXmlAction method getFiles.

protected List<File> getFiles(AnActionEvent e) {
    final MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
    if (projectsManager == null)
        return Collections.emptyList();
    File file = projectsManager.getGeneralSettings().getEffectiveUserSettingsIoFile();
    return file != null ? Collections.singletonList(file) : Collections.emptyList();
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) File(java.io.File)

Example 38 with MavenProjectsManager

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

the class ToggleIgnoredProjectsAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final DataContext context = e.getDataContext();
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return;
    List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
    final Project project = MavenActionUtil.getProject(context);
    if (project == null)
        return;
    if (isIgnoredInSettings(projectsManager, projects)) {
        ShowSettingsUtil.getInstance().editConfigurable(project, new MavenIgnoredFilesConfigurable(project));
    } else {
        projectsManager.setIgnoredState(projects, !isIgnored(projectsManager, projects));
    }
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenIgnoredFilesConfigurable(org.jetbrains.idea.maven.project.MavenIgnoredFilesConfigurable)

Example 39 with MavenProjectsManager

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

the class ToggleIgnoredProjectsAction method update.

@Override
public void update(AnActionEvent e) {
    super.update(e);
    if (!isAvailable(e))
        return;
    final DataContext context = e.getDataContext();
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return;
    List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
    if (isIgnoredInSettings(projectsManager, projects)) {
        e.getPresentation().setText(ProjectBundle.message("maven.ignore.edit"));
    } else if (isIgnored(projectsManager, projects)) {
        e.getPresentation().setText(ProjectBundle.message("maven.unignore"));
    } else {
        e.getPresentation().setText(ProjectBundle.message("maven.ignore"));
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 40 with MavenProjectsManager

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

the class MavenModuleBuilderHelper method configure.

public void configure(final Project project, final VirtualFile root, final boolean isInteractive) {
    PsiFile[] psiFiles = myAggregatorProject != null ? new PsiFile[] { getPsiFile(project, myAggregatorProject.getFile()) } : PsiFile.EMPTY_ARRAY;
    final VirtualFile pom = new WriteCommandAction<VirtualFile>(project, myCommandName, psiFiles) {

        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
            VirtualFile file;
            try {
                file = root.createChildData(this, MavenConstants.POM_XML);
                MavenUtil.runOrApplyMavenProjectFileTemplate(project, file, myProjectId, isInteractive);
                result.setResult(file);
            } catch (IOException e) {
                showError(project, e);
                return;
            }
            updateProjectPom(project, file);
            if (myAggregatorProject != null) {
                MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, myAggregatorProject.getFile());
                if (model != null) {
                    model.getPackaging().setStringValue("pom");
                    MavenDomModule module = model.getModules().addModule();
                    module.setValue(getPsiFile(project, file));
                }
            }
        }
    }.execute().getResultObject();
    if (pom == null)
        return;
    if (myAggregatorProject == null) {
        MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
        manager.addManagedFilesOrUnignore(Collections.singletonList(pom));
    }
    if (myArchetype == null) {
        try {
            VfsUtil.createDirectories(root.getPath() + "/src/main/java");
            VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
            VfsUtil.createDirectories(root.getPath() + "/src/test/java");
        } catch (IOException e) {
            MavenLog.LOG.info(e);
        }
    }
    // execute when current dialog is closed (e.g. Project Structure)
    MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
        if (!pom.isValid())
            return;
        EditorHelper.openInEditor(getPsiFile(project, pom));
        if (myArchetype != null)
            generateFromArchetype(project, pom);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) MavenDomModule(org.jetbrains.idea.maven.dom.model.MavenDomModule) Result(com.intellij.openapi.application.Result)

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