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);
}
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());
}
});
}
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);
}
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);
}
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)));
}
}
Aggregations