/** Default behavior of {@link Errors#dialog} is @{code JOptionPane.showMessageDialog} without a parent. */ static void defaultDialog(Throwable error) { SwingUtilities.invokeLater(() -> { error.printStackTrace(); String title = error.getClass().getSimpleName(); JOptionPane.showMessageDialog(null, error.getMessage() + "\n\n" + StringPrinter.buildString(printer -> { PrintWriter writer = printer.toPrintWriter(); error.printStackTrace(writer); writer.close(); }), title, JOptionPane.ERROR_MESSAGE); }); }
/** Default behavior of {@link Errors#dialog} is @{code JOptionPane.showMessageDialog} without a parent. */ static void defaultDialog(Throwable error) { SwingUtilities.invokeLater(() -> { error.printStackTrace(); String title = error.getClass().getSimpleName(); JOptionPane.showMessageDialog(null, error.getMessage() + "\n\n" + StringPrinter.buildString(printer -> { PrintWriter writer = printer.toPrintWriter(); error.printStackTrace(writer); writer.close(); }), title, JOptionPane.ERROR_MESSAGE); }); }
/** Dumps the given message and exception stack to the system error console */ public static void dump(String message, Throwable exception) { printEmphasized(StringPrinter.buildString(printer -> { printer.println(message); exception.printStackTrace(printer.toPrintWriter()); })); }
/** Dumps the given message and exception stack to the system error console */ public static void dump(String message, Throwable exception) { printEmphasized(StringPrinter.buildString(printer -> { printer.println(message); exception.printStackTrace(printer.toPrintWriter()); })); }
private void needsBoth(Composite parent) { Layouts.setFill(parent); Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP); text.setFont(Fonts.systemLarge()); text.setText(StringPrinter.buildString(printer -> { try { printer.println("Calling NeedsBoth.parse..."); printer.println("parse MAVEN: " + NeedsBoth.parse("MAVEN")); printer.println("parse P2: " + NeedsBoth.parse("P2")); } catch (Throwable e) { e.printStackTrace(printer.toPrintWriter()); } })); } }
@Test public void ensureOverrideWorks() throws IOException { write("build.gradle", "plugins {", " id 'com.diffplug.gradle.oomph.ide'", "}", "ext.goomph_override_p2bootstrapUrl='somewhere'", "com.diffplug.gradle.GoomphCacheLocations.initFromProject(project)", "System.out.println(com.diffplug.gradle.GoomphCacheLocations.p2bootstrapUrl())", // if we leave it, it will muck with future testkit tests "project.afterEvaluate { com.diffplug.gradle.GoomphCacheLocations.override_p2bootstrapUrl=null }"); StringBuilder buffer = new StringBuilder(); StringPrinter printer = new StringPrinter(buffer::append); try (Writer writer = printer.toPrintWriter()) { gradleRunner().forwardStdOutput(writer).build(); } String firstLine = buffer.toString().split(System.getProperty("line.separator"))[0]; Assert.assertEquals("Optional[somewhere]", firstLine); } }