1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*******************************************************************************
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.bugs;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IBundleGroup;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.internal.provisional.tasks.bugs.AbstractTaskContributor;
import org.eclipse.mylyn.internal.tasks.bugs.wizards.ErrorLogStatus;
import org.eclipse.mylyn.internal.tasks.bugs.wizards.FeatureStatus;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.osgi.framework.Bundle;
/**
* @author Steffen Pingel
*/
public class DefaultTaskContributor extends AbstractTaskContributor {
public void appendErrorDetails(StringBuilder sb, IStatus status, Date date) {
sb.append("\n\n-- Error Details --");
if (date != null) {
sb.append("\nDate: ");
sb.append(date);
}
sb.append("\nMessage: ");
sb.append(status.getMessage());
sb.append("\nSeverity: ");
sb.append(getSeverityText(status.getSeverity()));
sb.append("\nPlugin: ");
sb.append(status.getPlugin());
}
@Override
public Map<String, String> getAttributes(IStatus status) {
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(IRepositoryConstants.DESCRIPTION, getDescription(status));
return attributes;
}
public String getDescription(IStatus status) {
if (status instanceof FeatureStatus) {
StringBuilder sb = new StringBuilder();
sb.append("\n\n\n");
sb.append("-- Installed Features and Plug-ins --\n");
IBundleGroup[] bundleGroups = ((FeatureStatus) status).getBundleGroup();
for (IBundleGroup bundleGroup : bundleGroups) {
sb.append(bundleGroup.getIdentifier());
sb.append(" ");
sb.append(bundleGroup.getVersion());
sb.append("\n");
Bundle[] bundles = bundleGroup.getBundles();
if (bundles != null) {
for (Bundle bundle : bundles) {
sb.append(" ");
sb.append(bundle.getSymbolicName());
String version = (String) bundle.getHeaders().get("Bundle-Version");
if (version != null) {
sb.append(" ");
sb.append(version);
}
sb.append("\n");
}
}
}
return sb.toString();
} else if (status instanceof ErrorLogStatus) {
ErrorLogStatus errorLogStatus = (ErrorLogStatus) status;
StringBuilder sb = new StringBuilder();
appendErrorDetails(sb, errorLogStatus, errorLogStatus.getDate());
if (errorLogStatus.getLogSessionData() != null) {
sb.append("\nSession Data:\n");
sb.append(errorLogStatus.getLogSessionData());
}
if (errorLogStatus.getStack() != null) {
sb.append("\nException Stack Trace:\n");
sb.append(errorLogStatus.getStack());
}
return sb.toString();
} else {
StringBuilder sb = new StringBuilder();
appendErrorDetails(sb, status, new Date());
if (status.getException() != null) {
sb.append("\nException Stack Trace:\n");
StringWriter writer = new StringWriter();
status.getException().printStackTrace(new PrintWriter(writer));
sb.append(writer.getBuffer());
}
return sb.toString();
}
}
@Override
public String getEditorId(IStatus status) {
return TaskEditor.ID_EDITOR;
}
private String getSeverityText(int severity) {
switch (severity) {
case IStatus.ERROR:
return "Error";
case IStatus.WARNING:
return "Warning";
case IStatus.INFO:
return "Info";
case IStatus.OK:
return "OK";
}
return "?"; //$NON-NLS-1$
}
}
|