Merge remote branch 'origin/master'

This commit is contained in:
irengrig
2011-12-27 13:35:00 +04:00
3 changed files with 91 additions and 10 deletions
@@ -15,16 +15,26 @@
*/
package com.intellij.compiler.actions;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListSeparator;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
@@ -37,9 +47,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.io.File;
import java.util.*;
/**
* @author nik
@@ -102,10 +111,9 @@ public class BuildArtifactAction extends AnAction {
}
protected static void doBuild(@NotNull Project project, final @NotNull ArtifactPopupItem item, boolean rebuild) {
final Artifact artifact = item.getArtifact();
final List<Artifact> artifacts = artifact != null ? Collections.singletonList(artifact) : ArtifactUtil.getArtifactWithOutputPaths(project);
final List<Artifact> artifacts = item.getArtifacts(project);
final CompileScope scope = ArtifactCompileScope.createArtifactsScope(project, artifacts);
ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(ContainerUtil.createMaybeSingletonList(artifact));
ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(ContainerUtil.createMaybeSingletonList(item.getArtifact()));
if (!rebuild) {
CompilerManager.getInstance(project).make(scope, null);
}
@@ -125,6 +133,70 @@ public class BuildArtifactAction extends AnAction {
}
}
private static class CleanArtifactItem extends ArtifactActionItem {
private CleanArtifactItem(@NotNull ArtifactPopupItem item, @NotNull Project project) {
super(item, project, "Clean");
}
@Override
public void run() {
Set<VirtualFile> parents = new HashSet<VirtualFile>();
final VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentSourceRoots();
for (VirtualFile root : roots) {
VirtualFile parent = root;
while (parent != null && !parents.contains(parent)) {
parents.add(parent);
parent = parent.getParent();
}
}
Map<String, String> outputPathContainingSourceRoots = new HashMap<String, String>();
final List<File> files = new ArrayList<File>();
for (Artifact artifact : myArtifactPopupItem.getArtifacts(myProject)) {
String outputPath = artifact.getOutputFilePath();
if (outputPath != null) {
files.add(new File(FileUtil.toSystemDependentName(outputPath)));
final VirtualFile outputFile = LocalFileSystem.getInstance().findFileByPath(outputPath);
if (parents.contains(outputFile)) {
outputPathContainingSourceRoots.put(artifact.getName(), outputPath);
}
}
}
if (!outputPathContainingSourceRoots.isEmpty()) {
final String message;
if (outputPathContainingSourceRoots.size() == 1 && outputPathContainingSourceRoots.values().size() == 1) {
final String name = ContainerUtil.getFirstItem(outputPathContainingSourceRoots.keySet());
final String output = outputPathContainingSourceRoots.get(name);
message = "The output directory '" + output + "' of '" + name + "' artifact contains source roots of the project. Do you want to continue and clear it?";
}
else {
StringBuilder info = new StringBuilder();
for (String name : outputPathContainingSourceRoots.keySet()) {
info.append(" '").append(name).append("' artifact ('").append(outputPathContainingSourceRoots.get(name)).append("')\n");
}
message = "The output directories of the following artifacts contains source roots:\n" +
info + "Do you want to continue and clear these directories?";
}
final int answer = Messages.showYesNoDialog(myProject, message, "Clean Artifacts", null);
if (answer != 0) {
return;
}
}
new Task.Backgroundable(myProject, "Cleaning artifacts...", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
for (File file : files) {
indicator.checkCanceled();
FileUtil.delete(file);
}
LocalFileSystem.getInstance().refreshIoFiles(files, true, true, null);
}
}.queue();
}
}
private static class RebuildArtifactItem extends ArtifactActionItem {
private RebuildArtifactItem(ArtifactPopupItem item, Project project) {
super(item, project, "Rebuild");
@@ -189,6 +261,11 @@ public class BuildArtifactAction extends AnAction {
public Icon getIcon() {
return myIcon;
}
public List<Artifact> getArtifacts(Project project) {
final Artifact artifact = getArtifact();
return artifact != null ? Collections.singletonList(artifact) : ArtifactUtil.getArtifactWithOutputPaths(project);
}
}
private static class ChooseArtifactStep extends BaseListPopupStep<ArtifactPopupItem> {
@@ -244,6 +321,7 @@ public class BuildArtifactAction extends AnAction {
final List<ArtifactActionItem> actions = new ArrayList<ArtifactActionItem>();
actions.add(new BuildArtifactItem(selectedValue, myProject));
actions.add(new RebuildArtifactItem(selectedValue, myProject));
actions.add(new CleanArtifactItem(selectedValue, myProject));
if (mySettingsService != null) {
actions.add(new EditArtifactItem(selectedValue, myProject, mySettingsService));
}
@@ -78,8 +78,7 @@ public class BasicSentUsagesPersistenceComponent extends SentUsagesPersistence {
@NotNull
public Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages
() {
public Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages () {
return mySentDescriptors;
}
}
@@ -79,7 +79,11 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
String valueData = groupElement.getAttributeValue(DATA_ATTR);
if (!StringUtil.isEmptyOrSpaces(groupId) && !StringUtil.isEmptyOrSpaces(valueData)) {
getSentUsages().putAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
try {
getSentUsages().putAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
} catch (AssertionError e) {
//don't load incorrect groups
}
}
}