Changeset 12770 in josm for trunk/src/org/openstreetmap/josm/tools/bugreport
- Timestamp:
- 2017-09-07T21:10:49+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools/bugreport
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java
r12649 r12770 7 7 import java.util.concurrent.CopyOnWriteArrayList; 8 8 import java.util.function.Predicate; 9 10 import org.openstreetmap.josm.actions.ShowStatusReportAction;11 9 12 10 /** … … 21 19 * <p> 22 20 * You should then add some debug information there. This can be the OSM ids that caused the error, information on the data you were working on 23 * or other local variables. Make sure that no exc petions may occur while computing the values. It is best to send plain local variables to21 * or other local variables. Make sure that no exceptions may occur while computing the values. It is best to send plain local variables to 24 22 * put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report. 25 23 * The global exception handler will do the rest. … … 117 115 /** 118 116 * Gets the full string that should be send as error report. 117 * @param header header text for the error report 119 118 * @return The string. 120 119 * @since 10585 121 120 */ 122 public String getReportText( ) {121 public String getReportText(String header) { 123 122 StringWriter stringWriter = new StringWriter(); 124 123 PrintWriter out = new PrintWriter(stringWriter); 125 124 if (isIncludeStatusReport()) { 126 125 try { 127 out.println( ShowStatusReportAction.getReportHeader());126 out.println(header); 128 127 } catch (RuntimeException e) { // NOPMD 129 128 out.println("Could not generate status report: " + e.getMessage()); -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportQueue.java
r12649 r12770 2 2 package org.openstreetmap.josm.tools.bugreport; 3 3 4 import java.awt.GraphicsEnvironment;5 4 import java.util.ArrayList; 6 5 import java.util.LinkedList; 7 6 import java.util.concurrent.CopyOnWriteArrayList; 8 import java.util.function.BiFunction;9 7 import java.util.function.Predicate; 10 8 11 import org.openstreetmap.josm.gui.bugreport.BugReportDialog;12 9 import org.openstreetmap.josm.tools.Logging; 13 10 … … 21 18 private static final BugReportQueue INSTANCE = new BugReportQueue(); 22 19 20 public static final BugReportHandler FALLBACK_BUGREPORT_HANDLER = (e, index) -> { 21 e.printStackTrace(); 22 return BugReportQueue.SuppressionMode.NONE; 23 }; 24 23 25 private final LinkedList<ReportedException> reportsToDisplay = new LinkedList<>(); 24 26 private boolean suppressAllMessages; 25 27 private final ArrayList<ReportedException> suppressFor = new ArrayList<>(); 26 28 private Thread displayThread; 27 private final BiFunction<ReportedException, Integer, SuppressionMode> bugReportHandler = getBestHandler();29 private BugReportHandler bugReportHandler = FALLBACK_BUGREPORT_HANDLER; 28 30 private final CopyOnWriteArrayList<Predicate<ReportedException>> handlers = new CopyOnWriteArrayList<>(); 29 31 private int displayedErrors; 30 32 31 33 private boolean inReportDialog; 34 35 /** 36 * Class that handles reporting a bug to the user. 37 */ 38 public interface BugReportHandler { 39 /** 40 * Handle the bug report for a given exception 41 * @param e The exception to display 42 * @param exceptionCounter A counter of how many exceptions have already been worked on 43 * @return The new suppression status 44 */ 45 SuppressionMode handle(ReportedException e, int exceptionCounter); 46 } 32 47 33 48 /** … … 112 127 return SuppressionMode.NONE; 113 128 } 114 return bugReportHandler. apply(e, getDisplayedErrors());129 return bugReportHandler.handle(e, getDisplayedErrors()); 115 130 } 116 131 … … 127 142 } 128 143 129 private static BiFunction<ReportedException, Integer, SuppressionMode> getBestHandler() { 130 if (GraphicsEnvironment.isHeadless()) { 131 return (e, index) -> { 132 e.printStackTrace(); 133 return SuppressionMode.NONE; 134 }; 135 } else { 136 return BugReportDialog::showFor; 137 } 144 public void setBugReportHandler(BugReportHandler bugReportHandler) { 145 this.bugReportHandler = bugReportHandler; 138 146 } 139 147 140 148 /** 141 * Allows you to peek or even inter sect the bug reports.149 * Allows you to peek or even intercept the bug reports. 142 150 * @param handler The handler. It can return false to stop all further handling of the exception. 143 151 * @since 10886
Note:
See TracChangeset
for help on using the changeset viewer.