This is an automated email from the ASF dual-hosted git repository. jtulach pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans-html4j.git
commit 8dd6df5d880336cdae7580524e603cc89b296efe Author: Jaroslav Tulach <jaroslav.tul...@apidesign.org> AuthorDate: Sun Dec 27 09:20:53 2020 +0100 Influence default render selection in the browser tests by a property --- browser/pom.xml | 7 +++- .../netbeans/html/presenters/browser/Browser.java | 27 +----------- .../html/presenters/browser/ServerTest.java | 22 +--------- .../org/netbeans/html/presenters/render/Show.java | 48 ++++++++++++++++++---- 4 files changed, 49 insertions(+), 55 deletions(-) diff --git a/browser/pom.xml b/browser/pom.xml index 4647ebd..0cf99e7 100644 --- a/browser/pom.xml +++ b/browser/pom.xml @@ -33,6 +33,7 @@ <main.dir>${project.parent.basedir}</main.dir> <publicPackages>org.netbeans.html.presenters.browser</publicPackages> <sigtestPackages/> + <com.dukescript.presenters.browser>default</com.dukescript.presenters.browser> </properties> <build> <plugins> @@ -58,7 +59,11 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.18.1</version> + <configuration> + <systemPropertyVariables> + <com.dukescript.presenters.browser>${com.dukescript.presenters.browser}</com.dukescript.presenters.browser> + </systemPropertyVariables> + </configuration> </plugin> <plugin> <groupId>org.netbeans.html</groupId> diff --git a/browser/src/main/java/org/netbeans/html/presenters/browser/Browser.java b/browser/src/main/java/org/netbeans/html/presenters/browser/Browser.java index 3f509d1..1892f9b 100644 --- a/browser/src/main/java/org/netbeans/html/presenters/browser/Browser.java +++ b/browser/src/main/java/org/netbeans/html/presenters/browser/Browser.java @@ -153,32 +153,7 @@ Executor, Closeable { if ("none".equalsIgnoreCase(impl)) { // NOI18N return; } - if (impl != null) { - Show.show(impl, page); - } else { - IOException one, two; - try { - String ui = System.getProperty("os.name").contains("Mac") ? - "Cocoa" : "GTK"; - Show.show(ui, page); - return; - } catch (IOException ex) { - one = ex; - } - try { - Show.show("AWT", page); - return; - } catch (IOException ex) { - two = ex; - } - try { - Show.show(impl, page); - } catch (IOException ex) { - two.initCause(one); - ex.initCause(two); - throw ex; - } - } + Show.show(impl, page); } @Override diff --git a/browser/src/test/java/org/netbeans/html/presenters/browser/ServerTest.java b/browser/src/test/java/org/netbeans/html/presenters/browser/ServerTest.java index 331c17c..6d61be3 100644 --- a/browser/src/test/java/org/netbeans/html/presenters/browser/ServerTest.java +++ b/browser/src/test/java/org/netbeans/html/presenters/browser/ServerTest.java @@ -114,27 +114,7 @@ public class ServerTest { ExecutorService background = Executors.newSingleThreadExecutor(); Future<Void> future = background.submit((Callable<Void>) () -> { IOException one, two; - try { - String ui = System.getProperty("os.name").contains("Mac") - ? "Cocoa" : "GTK"; - Show.show(ui, page); - return null; - } catch (IOException ex) { - one = ex; - } - try { - Show.show("AWT", page); - return null; - } catch (IOException ex) { - two = ex; - } - try { - Show.show(null, page); - } catch (IOException ex) { - two.initCause(one); - ex.initCause(two); - throw ex; - } + Show.show(System.getProperty("com.dukescript.presenters.browser"), page); return null; }); diff --git a/renderer/src/main/java/org/netbeans/html/presenters/render/Show.java b/renderer/src/main/java/org/netbeans/html/presenters/render/Show.java index 1a77f9e..d5c5041 100644 --- a/renderer/src/main/java/org/netbeans/html/presenters/render/Show.java +++ b/renderer/src/main/java/org/netbeans/html/presenters/render/Show.java @@ -35,23 +35,53 @@ public abstract class Show { Show() { } - /** Shows a page in a browser. + /** Shows a page in a browser. Select default implementation + * suitable for current system if {@code "default"} or {@code null}. * * @param impl the name of implementation to use, can be <code>null</code> * @param page the page URL * @throws IOException if something goes wrong */ public static void show(String impl, URI page) throws IOException { + if (impl == null || "default".equals(impl)) { // NOI18N + showOneByOne(page); + return; + } + showOne(impl, page); + } + + private static void showOneByOne(URI page) throws IOException { + IOException one, two; + try { + String ui = System.getProperty("os.name").contains("Mac") + ? "Cocoa" : "GTK"; + Show.show(ui, page); + return; + } catch (IOException ex) { + one = ex; + } + try { + Show.show("AWT", page); + return; + } catch (IOException ex) { + two = ex; + } + try { + Show.show("xdg-open", page); + } catch (IOException ex) { + two.initCause(one); + ex.initCause(two); + throw ex; + } + } + + private static void showOne(String impl, URI page) throws IOException { + impl.getClass(); // NPE check try { Class<?> c = Class.forName(Show.class.getPackage().getName() + '.' + impl); Show show = (Show) c.newInstance(); show.show(page); - } catch (IOException ex) { - throw ex; - } catch (LinkageError | Exception ex) { - if (impl == null) { - impl = "xdg-open"; - } + } catch (ClassNotFoundException ex) { LOG.log(Level.INFO, "Trying command line execution of {0}", impl); String[] cmdArr = { impl, page.toString() @@ -63,6 +93,10 @@ public abstract class Show { } catch (InterruptedException ex1) { throw (InterruptedIOException) new InterruptedIOException().initCause(ex1); } + } catch (IOException ex) { + throw ex; + } catch (LinkageError | Exception ex) { + throw new IOException(ex); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists