diff --git a/src/net/sourceforge/plantuml/dot/GraphvizFactory.java b/src/net/sourceforge/plantuml/dot/GraphvizFactory.java new file mode 100644 index 00000000000..4299b2615cd --- /dev/null +++ b/src/net/sourceforge/plantuml/dot/GraphvizFactory.java @@ -0,0 +1,54 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://plantuml.com/paypal + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Original Author: Arnaud Roques + * + * + */ +package net.sourceforge.plantuml.dot; + +import net.sourceforge.plantuml.style.ISkinParam; + +/** + * @author Pavel Castornii + */ +public interface GraphvizFactory { + + /** + * Creates a {@link Graphviz} instance if possible with the specified parameters. + * + * @param skinParam + * @param dotString + * @param type + * @return a {@link Graphviz} instance or {@code null}. + */ + Graphviz create(ISkinParam skinParam, String dotString, String... type); +} diff --git a/src/net/sourceforge/plantuml/dot/GraphvizUtils.java b/src/net/sourceforge/plantuml/dot/GraphvizUtils.java index 23261f328b2..71eadf810cd 100644 --- a/src/net/sourceforge/plantuml/dot/GraphvizUtils.java +++ b/src/net/sourceforge/plantuml/dot/GraphvizUtils.java @@ -5,12 +5,12 @@ * (C) Copyright 2009-2024, Arnaud Roques * * Project Info: https://plantuml.com - * + * * If you like this project or if you find it useful, you can support us at: - * + * * https://plantuml.com/patreon (only 1$ per month!) * https://plantuml.com/paypal - * + * * This file is part of PlantUML. * * PlantUML is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ * * * Original Author: Arnaud Roques - * + * * */ package net.sourceforge.plantuml.dot; @@ -38,7 +38,9 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.util.Iterator; import java.util.List; +import java.util.ServiceLoader; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,11 +75,14 @@ public static final void setDotExecutable(String value) { } public static Graphviz createForSystemDot(ISkinParam skinParam, String dotString, String... type) { + Graphviz result = createWithFactory(skinParam, dotString, type); + if (result != null) { + return result; + } if (useVizJs(skinParam)) { Log.info("Using " + VIZJS); return new GraphvizJs(dotString); } - final AbstractGraphviz result; if (isWindows()) result = new GraphvizWindowsOld(skinParam, dotString, type); else @@ -92,11 +97,14 @@ public static Graphviz createForSystemDot(ISkinParam skinParam, String dotString } public static Graphviz create(ISkinParam skinParam, String dotString, String... type) { + Graphviz result = createWithFactory(skinParam, dotString, type); + if (result != null) { + return result; + } if (useVizJs(skinParam)) { Log.info("Using " + VIZJS); return new GraphvizJs(dotString); } - final AbstractGraphviz result; if (isWindows()) result = new GraphvizWindowsLite(skinParam, dotString, type); else @@ -110,6 +118,19 @@ public static Graphviz create(ISkinParam skinParam, String dotString, String... return result; } + private static Graphviz createWithFactory(ISkinParam skinParam, String dotString, String... type) { + Iterator iterator = ServiceLoader.load(GraphvizFactory.class).iterator(); + while (iterator.hasNext()) { + GraphvizFactory factory = iterator.next(); + Graphviz graphviz = factory.create(skinParam, dotString, type); + if (graphviz != null) { + Log.info("Using " + graphviz.getClass().getName() + " created by " + factory.getClass().getName()); + return graphviz; + } + } + return null; + } + private static boolean useVizJs(ISkinParam skinParam) { if (skinParam != null && skinParam.isUseVizJs() && VizJsEngine.isOk()) return true;