| package aeri.ide; |
| |
| import static org.eclipse.epp.logging.aeri.core.ProblemStatus.NEEDINFO; |
| import static org.eclipse.epp.logging.aeri.core.util.Links.*; |
| |
| import java.io.IOException; |
| import java.util.ArrayList; |
| import java.util.regex.Pattern; |
| |
| import javax.inject.Inject; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.epp.internal.logging.aeri.ide.IServerDescriptor; |
| import org.eclipse.epp.logging.aeri.core.ILink; |
| import org.eclipse.epp.logging.aeri.core.IModelFactory; |
| import org.eclipse.epp.logging.aeri.core.IProblemState; |
| import org.eclipse.epp.logging.aeri.core.IReport; |
| import org.eclipse.epp.logging.aeri.core.ISendOptions; |
| import org.eclipse.epp.logging.aeri.core.IServerConnection; |
| import org.eclipse.epp.logging.aeri.core.ISystemSettings; |
| import org.eclipse.epp.logging.aeri.core.ProblemStatus; |
| import org.eclipse.epp.logging.aeri.core.util.Links; |
| import org.eclipse.epp.logging.aeri.core.util.Reports; |
| |
| public class DemoServerConnection implements IServerConnection { |
| |
| private IServerDescriptor container; |
| private ISystemSettings settings; |
| |
| @Inject |
| public DemoServerConnection(IServerDescriptor container, ISystemSettings settings) { |
| this.container = container; |
| this.settings = settings; |
| } |
| |
| @Override |
| public IProblemState interested(IStatus status, IEclipseContext context, IProgressMonitor monitor) { |
| IProblemState state = IModelFactory.eINSTANCE.createProblemState(); |
| { |
| // let's assume we are interested in all events and need more info. always. |
| state.setStatus(NEEDINFO); |
| } |
| { |
| // let's assume that this is a known issue which has a issue tracker url: |
| ILink bug = Links.createBugLink("http://eclipse.org", "Bug #12345"); |
| state.getLinks().put(REL_BUG, bug); |
| } |
| state.setMessage(status.getMessage()); |
| return state; |
| } |
| |
| @Override |
| public IReport transform(IStatus status, IEclipseContext context) { |
| ISendOptions options = context.get(ISendOptions.class); |
| IReport report = Reports.newReport(status); |
| report.setComment(options.getComment()); |
| report.setAnonymousId(options.getReporterId()); |
| report.setName(options.getReporterName()); |
| report.setEmail(options.getReporterEmail()); |
| report.setSeverity(options.getSeverity()); |
| |
| if (options.isAnonymizeMessages()) { |
| Reports.anonymizeMessages(report); |
| } |
| if (options.isAnonymizeStackTraces()) { |
| ArrayList<Pattern> patterns = new ArrayList<>(); |
| patterns.add(Pattern.compile("org\\.eclipse\\..*")); |
| Reports.anonymizeStackTraces(report, patterns); |
| } |
| return report; |
| } |
| |
| @Override |
| public IProblemState submit(IStatus status, IEclipseContext context, IProgressMonitor monitor) throws IOException { |
| // here we usually do some kind of IO and communicate with a remote service... |
| |
| // for simiplicity we hardcode the server response... |
| IProblemState response = IModelFactory.eINSTANCE.createProblemState(); |
| { |
| // let's assume that problem was confirmed as bug |
| response.setStatus(ProblemStatus.CONFIRMED); |
| } |
| { |
| addLink(response, Links.REL_BUG, "http://eclipse.org", "Bug #12345"); |
| } |
| { |
| // append the url where the reporter can review and modify his submission: |
| addLink(response, Links.REL_SUBMISSION, "http://localhost/does-not-exist", "Submission"); |
| } |
| return response; |
| } |
| |
| @Override |
| public void discarded(IStatus status, IEclipseContext context) { |
| // well, we may store the information that the user did not want to send this error - up to the server connection to decide... |
| } |
| } |