Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2013-11-25 19:24:57 +01:00
2 changed files with 22 additions and 1 deletions
@@ -4,9 +4,11 @@ import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
@@ -26,6 +28,20 @@ public class AttachmentFactory {
file.getFileType().isBinary() ? "File is binary" : LoadTextUtil.loadText(file).toString());
}
public static Attachment createAttachment(@NotNull File file, boolean isBinary) {
byte[] bytes = getBytes(file);
return new Attachment(file.getPath(), bytes, isBinary ? "File is binary" : new String(bytes));
}
private static byte[] getBytes(File file) {
try {
return FileUtil.loadFileBytes(file);
}
catch (IOException e) {
return Attachment.getBytes(MessageFormat.format(ERROR_MESSAGE_PATTERN, e.getMessage()));
}
}
private static byte[] getBytes(VirtualFile file) {
try {
return file.contentsToByteArray();
@@ -33,6 +33,7 @@ import com.intellij.diagnostic.LogMessageEx;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
@@ -344,10 +345,14 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
if (info.myShowLog) {
LOG.error(LogMessageEx.createEvent(info.myDisplayMessage,
info.myMessage + "\n" + ExceptionUtil.getThrowableText(info.myThrowable),
AttachmentFactory.createAttachment(myFile)));
getErrorAttachments(info)));
}
}
protected Attachment[] getErrorAttachments(ErrorInfo info) {
return new Attachment[]{AttachmentFactory.createAttachment(myFile)};
}
protected abstract void configureError(final @NotNull ErrorInfo info);
protected void showErrorPage(final ErrorInfo info) {