Ignore:
Timestamp:
2017-09-07T21:10:49+02:00 (2 years ago)
Author:
bastiK
Message:

see #15229 - remove GUI references from BugReport and BugReportQueue

signature of BugReport#getReportText changed without deprecation
(probably not used by any external plugin)

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  
    77import java.util.concurrent.CopyOnWriteArrayList;
    88import java.util.function.Predicate;
    9 
    10 import org.openstreetmap.josm.actions.ShowStatusReportAction;
    119
    1210/**
     
    2119 * <p>
    2220 * 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 excpetions may occur while computing the values. It is best to send plain local variables to
     21 * or other local variables. Make sure that no exceptions may occur while computing the values. It is best to send plain local variables to
    2422 * put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report.
    2523 * The global exception handler will do the rest.
     
    117115    /**
    118116     * Gets the full string that should be send as error report.
     117     * @param header header text for the error report
    119118     * @return The string.
    120119     * @since 10585
    121120     */
    122     public String getReportText() {
     121    public String getReportText(String header) {
    123122        StringWriter stringWriter = new StringWriter();
    124123        PrintWriter out = new PrintWriter(stringWriter);
    125124        if (isIncludeStatusReport()) {
    126125            try {
    127                 out.println(ShowStatusReportAction.getReportHeader());
     126                out.println(header);
    128127            } catch (RuntimeException e) { // NOPMD
    129128                out.println("Could not generate status report: " + e.getMessage());
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportQueue.java

    r12649 r12770  
    22package org.openstreetmap.josm.tools.bugreport;
    33
    4 import java.awt.GraphicsEnvironment;
    54import java.util.ArrayList;
    65import java.util.LinkedList;
    76import java.util.concurrent.CopyOnWriteArrayList;
    8 import java.util.function.BiFunction;
    97import java.util.function.Predicate;
    108
    11 import org.openstreetmap.josm.gui.bugreport.BugReportDialog;
    129import org.openstreetmap.josm.tools.Logging;
    1310
     
    2118    private static final BugReportQueue INSTANCE = new BugReportQueue();
    2219
     20    public static final BugReportHandler FALLBACK_BUGREPORT_HANDLER = (e, index) -> {
     21        e.printStackTrace();
     22        return BugReportQueue.SuppressionMode.NONE;
     23    };
     24
    2325    private final LinkedList<ReportedException> reportsToDisplay = new LinkedList<>();
    2426    private boolean suppressAllMessages;
    2527    private final ArrayList<ReportedException> suppressFor = new ArrayList<>();
    2628    private Thread displayThread;
    27     private final BiFunction<ReportedException, Integer, SuppressionMode> bugReportHandler = getBestHandler();
     29    private BugReportHandler bugReportHandler = FALLBACK_BUGREPORT_HANDLER;
    2830    private final CopyOnWriteArrayList<Predicate<ReportedException>> handlers = new CopyOnWriteArrayList<>();
    2931    private int displayedErrors;
    3032
    3133    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    }
    3247
    3348    /**
     
    112127            return SuppressionMode.NONE;
    113128        }
    114         return bugReportHandler.apply(e, getDisplayedErrors());
     129        return bugReportHandler.handle(e, getDisplayedErrors());
    115130    }
    116131
     
    127142    }
    128143
    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;
    138146    }
    139147
    140148    /**
    141      * Allows you to peek or even intersect the bug reports.
     149     * Allows you to peek or even intercept the bug reports.
    142150     * @param handler The handler. It can return false to stop all further handling of the exception.
    143151     * @since 10886
Note: See TracChangeset for help on using the changeset viewer.