Search in sources :

Example 31 with MavenProjectsManager

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

the class MavenExecuteGoalAction method actionPerformed.

@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    ExecuteMavenGoalHistoryService historyService = ExecuteMavenGoalHistoryService.getInstance(project);
    MavenExecuteGoalDialog dialog = new MavenExecuteGoalDialog(project, historyService.getHistory());
    String lastWorkingDirectory = historyService.getWorkDirectory();
    if (lastWorkingDirectory.length() == 0) {
        lastWorkingDirectory = obtainAppropriateWorkingDirectory(project);
    }
    dialog.setWorkDirectory(lastWorkingDirectory);
    if (StringUtil.isEmptyOrSpaces(historyService.getCanceledCommand())) {
        if (historyService.getHistory().size() > 0) {
            dialog.setGoals(historyService.getHistory().get(0));
        }
    } else {
        dialog.setGoals(historyService.getCanceledCommand());
    }
    if (!dialog.showAndGet()) {
        historyService.setCanceledCommand(dialog.getGoals());
        return;
    }
    historyService.setCanceledCommand(null);
    String goals = dialog.getGoals();
    goals = goals.trim();
    if (goals.startsWith("mvn ")) {
        goals = goals.substring("mvn ".length()).trim();
    }
    String workDirectory = dialog.getWorkDirectory();
    historyService.addCommand(goals, workDirectory);
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
    File mavenHome = MavenUtil.resolveMavenHomeDirectory(projectsManager.getGeneralSettings().getMavenHome());
    if (mavenHome == null) {
        Notification notification = new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Failed to execute goal", RunnerBundle.message("external.maven.home.no.default.with.fix"), NotificationType.ERROR, new NotificationListener.Adapter() {

            @Override
            protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                ShowSettingsUtil.getInstance().showSettingsDialog(project, MavenSettings.DISPLAY_NAME);
            }
        });
        Notifications.Bus.notify(notification, project);
        return;
    }
    MavenRunnerParameters parameters = new MavenRunnerParameters(true, workDirectory, Arrays.asList(ParametersList.parse(goals)), Collections.<String>emptyList());
    MavenGeneralSettings generalSettings = new MavenGeneralSettings();
    generalSettings.setMavenHome(mavenHome.getPath());
    MavenRunnerSettings runnerSettings = MavenRunner.getInstance(project).getSettings().clone();
    runnerSettings.setMavenProperties(new LinkedHashMap<>());
    runnerSettings.setSkipTests(false);
    MavenRunConfigurationType.runConfiguration(project, parameters, generalSettings, runnerSettings, null);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) File(java.io.File) NotificationListener(com.intellij.notification.NotificationListener)

Example 32 with MavenProjectsManager

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

the class MavenFoldersImporter method updateProjectFolders.

public static void updateProjectFolders(final Project project, final boolean updateTargetFoldersOnly) {
    final MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    final MavenImportingSettings settings = manager.getImportingSettings();
    WriteAction.run(() -> {
        List<ModifiableRootModel> rootModels = new ArrayList<>();
        for (Module each : ModuleManager.getInstance(project).getModules()) {
            MavenProject mavenProject = manager.findProject(each);
            if (mavenProject == null)
                continue;
            MavenRootModelAdapter a = new MavenRootModelAdapter(mavenProject, each, new IdeModifiableModelsProviderImpl(project));
            new MavenFoldersImporter(mavenProject, settings, a).config(updateTargetFoldersOnly);
            ModifiableRootModel model = a.getRootModel();
            if (model.isChanged()) {
                rootModels.add(model);
            } else {
                model.dispose();
            }
        }
        if (!rootModels.isEmpty()) {
            ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels.get((0)).getProject()).getModifiableModel());
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ArrayList(java.util.ArrayList) MavenImportingSettings(org.jetbrains.idea.maven.project.MavenImportingSettings) Module(com.intellij.openapi.module.Module)

Example 33 with MavenProjectsManager

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

the class ToggleProfileAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e.getDataContext());
    if (manager == null)
        return;
    Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
    if (selectedProfiles == null)
        return;
    Set<String> selectedProfileIds = selectedProfiles.keySet();
    MavenProfileKind targetState = getTargetState(manager, selectedProfiles);
    if (targetState == null)
        return;
    MavenExplicitProfiles newExplicitProfiles = manager.getExplicitProfiles().clone();
    switch(targetState) {
        case NONE:
            // disable explicitly
            newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getDisabledProfiles().addAll(selectedProfileIds);
            break;
        case EXPLICIT:
            // enable explicitly
            newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getEnabledProfiles().addAll(selectedProfileIds);
            break;
        case IMPLICIT:
        default:
            // reset to default state
            newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
            break;
    }
    manager.setExplicitProfiles(newExplicitProfiles);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles)

Example 34 with MavenProjectsManager

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

the class ToggleProfileAction method getTargetState.

@Nullable
private static MavenProfileKind getTargetState(AnActionEvent e) {
    Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
    if (selectedProfiles == null || selectedProfiles.isEmpty())
        return null;
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
    if (projectsManager == null)
        return null;
    return getTargetState(projectsManager, selectedProfiles);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with MavenProjectsManager

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

the class AddFileAsMavenProjectAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final DataContext context = e.getDataContext();
    MavenProjectsManager manager = MavenActionUtil.getProjectsManager(context);
    if (manager != null) {
        manager.addManagedFilesOrUnignore(Collections.singletonList(getSelectedFile(context)));
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager)

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