From 57b1cde03aa70050572cc17e8da284ea7aa90b02 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Wed, 9 Mar 2022 20:15:12 +0100 Subject: [PATCH] wip --- .../cucadiagram/dot/GraphvizUtils.java | 81 +++++++++---------- .../svek/image/EntityImageObject.java | 26 ++++-- .../plantuml/swing/MainWindow.java | 2 +- .../sourceforge/plantuml/version/Version.java | 2 +- 4 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java index 772a813dd..d5bc7d0e1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java @@ -76,11 +76,11 @@ public class GraphvizUtils { return new GraphvizJs(dotString); } final AbstractGraphviz result; - if (isWindows()) { + if (isWindows()) result = new GraphvizWindowsOld(skinParam, dotString, type); - } else { + else result = new GraphvizLinux(skinParam, dotString, type); - } + if (result.getExeState() != ExeState.OK && VizJsEngine.isOk()) { Log.info("Error with file " + result.getDotExe() + ": " + result.getExeState().getTextMessage()); Log.info("Using " + VIZJS); @@ -95,11 +95,11 @@ public class GraphvizUtils { return new GraphvizJs(dotString); } final AbstractGraphviz result; - if (isWindows()) { + if (isWindows()) result = new GraphvizWindowsLite(skinParam, dotString, type); - } else { + else result = new GraphvizLinux(skinParam, dotString, type); - } + if (result.getExeState() != ExeState.OK && VizJsEngine.isOk()) { Log.info("Error with file " + result.getDotExe() + ": " + result.getExeState().getTextMessage()); Log.info("Using " + VIZJS); @@ -109,12 +109,12 @@ public class GraphvizUtils { } private static boolean useVizJs(ISkinParam skinParam) { - if (skinParam != null && skinParam.isUseVizJs() && VizJsEngine.isOk()) { + if (skinParam != null && skinParam.isUseVizJs() && VizJsEngine.isOk()) return true; - } - if (VIZJS.equalsIgnoreCase(getenvGraphvizDot()) && VizJsEngine.isOk()) { + + if (VIZJS.equalsIgnoreCase(getenvGraphvizDot()) && VizJsEngine.isOk()) return true; - } + return false; } @@ -123,17 +123,17 @@ public class GraphvizUtils { } public static String getenvGraphvizDot() { - if (StringUtils.isNotEmpty(dotExecutable)) { + if (StringUtils.isNotEmpty(dotExecutable)) return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(dotExecutable); - } + final String env = System.getProperty("GRAPHVIZ_DOT"); - if (StringUtils.isNotEmpty(env)) { + if (StringUtils.isNotEmpty(env)) return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(env); - } + final String getenv = System.getenv("GRAPHVIZ_DOT"); - if (StringUtils.isNotEmpty(getenv)) { + if (StringUtils.isNotEmpty(getenv)) return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(getenv); - } + return null; } @@ -149,13 +149,13 @@ public class GraphvizUtils { public static int getenvImageLimit() { final Integer local = limitSize.get(); - if (local != null) { + if (local != null) return local; - } + final String env = SecurityUtils.getenv("PLANTUML_LIMIT_SIZE"); - if (StringUtils.isNotEmpty(env) && env.matches("\\d+")) { + if (StringUtils.isNotEmpty(env) && env.matches("\\d+")) return Integer.parseInt(env); - } + return 4096; } @@ -173,11 +173,11 @@ public class GraphvizUtils { if (dotVersion == null) { final File dotExe = GraphvizUtils.getDotExe(); final ExeState exeState = ExeState.checkFile(dotExe); - if (exeState == ExeState.OK) { + if (exeState == ExeState.OK) dotVersion = create(null, "png").dotVersion(); - } else { + else dotVersion = "Error:" + exeState.getTextMessage(dotExe); - } + } return dotVersion; } @@ -192,15 +192,15 @@ public class GraphvizUtils { } public static int retrieveVersion(String s) { - if (s == null) { + if (s == null) return -1; - } - final Pattern p = Pattern.compile("\\s([12].\\d\\d)\\D"); + + final Pattern p = Pattern.compile("\\s([23])\\.(\\d\\d?)\\D"); final Matcher m = p.matcher(s); - if (m.find() == false) { + if (m.find() == false) return -1; - } - return Integer.parseInt(m.group(1).replaceAll("\\.", "")); + + return 100 * Integer.parseInt(m.group(1)) + Integer.parseInt(m.group(2)); } public static int getDotVersion() throws IOException, InterruptedException { @@ -221,11 +221,11 @@ public class GraphvizUtils { result.add("VizJs library is used!"); try { final String err = getTestCreateSimpleFile(); - if (err == null) { + if (err == null) result.add(bold + "Installation seems OK. File generation OK"); - } else { + else result.add(red + err); - } + } catch (Exception e) { result.add(red + e.toString()); e.printStackTrace(); @@ -237,11 +237,11 @@ public class GraphvizUtils { final File dotExe = GraphvizUtils.getDotExe(); if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) { final String ent = GraphvizUtils.getenvGraphvizDot(); - if (ent == null) { + if (ent == null) result.add("The environment variable GRAPHVIZ_DOT has not been set"); - } else { + else result.add("The environment variable GRAPHVIZ_DOT has been set to " + ent); - } + result.add("Dot executable is " + dotExe); } final ExeState exeState = ExeState.checkFile(dotExe); @@ -285,19 +285,18 @@ public class GraphvizUtils { final Graphviz graphviz2 = GraphvizUtils.create(null, "digraph foo { test; }", "svg"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ProcessState state = graphviz2.createFile3(baos); - if (state.differs(ProcessState.TERMINATED_OK())) { + if (state.differs(ProcessState.TERMINATED_OK())) return "Error: timeout " + state; - } final byte data[] = baos.toByteArray(); - if (data.length == 0) { + if (data.length == 0) return "Error: dot generates empty file. Check you dot installation."; - } + final String s = new String(data); - if (s.indexOf("