1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-21 20:45:10 +00:00

fix: improve error management for non-GPL version

This commit is contained in:
Arnaud Roques 2023-10-20 15:29:27 +02:00
parent 2bb375b7ba
commit 4adacbabe5
6 changed files with 136 additions and 34 deletions

View File

@ -66,6 +66,7 @@ import net.sourceforge.plantuml.eggs.PSystemColorsFactory;
import net.sourceforge.plantuml.eggs.PSystemEggFactory; import net.sourceforge.plantuml.eggs.PSystemEggFactory;
import net.sourceforge.plantuml.eggs.PSystemPathFactory; import net.sourceforge.plantuml.eggs.PSystemPathFactory;
import net.sourceforge.plantuml.eggs.PSystemRIPFactory; import net.sourceforge.plantuml.eggs.PSystemRIPFactory;
import net.sourceforge.plantuml.eggs.PSystemUnsupported;
import net.sourceforge.plantuml.eggs.PSystemWelcomeFactory; import net.sourceforge.plantuml.eggs.PSystemWelcomeFactory;
import net.sourceforge.plantuml.emoji.PSystemListEmojiFactory; import net.sourceforge.plantuml.emoji.PSystemListEmojiFactory;
import net.sourceforge.plantuml.error.PSystemError; import net.sourceforge.plantuml.error.PSystemError;
@ -146,6 +147,9 @@ public class PSystemBuilder {
} }
final DiagramType diagramType = umlSource.getDiagramType(); final DiagramType diagramType = umlSource.getDiagramType();
if (diagramType == DiagramType.UNKNOWN)
return new PSystemUnsupported(umlSource);
final List<PSystemError> errors = new ArrayList<>(); final List<PSystemError> errors = new ArrayList<>();
for (PSystemFactory systemFactory : factories) { for (PSystemFactory systemFactory : factories) {
if (diagramType != systemFactory.getDiagramType()) if (diagramType != systemFactory.getDiagramType())
@ -159,6 +163,8 @@ public class PSystemBuilder {
} }
errors.add((PSystemError) sys); errors.add((PSystemError) sys);
} }
if (errors.size() == 0)
return new PSystemUnsupported(umlSource);
result = PSystemErrorUtils.merge(errors); result = PSystemErrorUtils.merge(errors);
return result; return result;

View File

@ -39,7 +39,7 @@ import net.sourceforge.plantuml.utils.StartUtils;
public enum DiagramType { public enum DiagramType {
// ::remove folder when __HAXE__ // ::remove folder when __HAXE__
UML, BPM, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, JUNGLE, CUTE, MATH, LATEX, DEFINITION, GANTT, NW, UML, BPM, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, MATH, LATEX, DEFINITION, GANTT, NW,
MINDMAP, WBS, WIRE, JSON, GIT, BOARD, YAML, HCL, EBNF, REGEX, FILES, UNKNOWN; MINDMAP, WBS, WIRE, JSON, GIT, BOARD, YAML, HCL, EBNF, REGEX, FILES, UNKNOWN;
static public DiagramType getTypeFromArobaseStart(String s) { static public DiagramType getTypeFromArobaseStart(String s) {
@ -59,11 +59,15 @@ public enum DiagramType {
if (StartUtils.startsWithSymbolAnd("startdot", s)) if (StartUtils.startsWithSymbolAnd("startdot", s))
return DOT; return DOT;
// ::comment when __CORE__ or __MIT__ or __EPL__ or __BSD__ or __ASL__ or __LGPL__
if (StartUtils.startsWithSymbolAnd("startjcckit", s)) if (StartUtils.startsWithSymbolAnd("startjcckit", s))
return JCCKIT; return JCCKIT;
// ::done
// ::comment when __CORE__ or __MIT__ or __EPL__ or __BSD__ or __ASL__
if (StartUtils.startsWithSymbolAnd("startditaa", s)) if (StartUtils.startsWithSymbolAnd("startditaa", s))
return DITAA; return DITAA;
// ::done
if (StartUtils.startsWithSymbolAnd("startproject", s)) if (StartUtils.startsWithSymbolAnd("startproject", s))
return PROJECT; return PROJECT;
@ -77,12 +81,6 @@ public enum DiagramType {
if (StartUtils.startsWithSymbolAnd("startcreole", s)) if (StartUtils.startsWithSymbolAnd("startcreole", s))
return CREOLE; return CREOLE;
if (StartUtils.startsWithSymbolAnd("starttree", s))
return JUNGLE;
if (StartUtils.startsWithSymbolAnd("startcute", s))
return CUTE;
if (StartUtils.startsWithSymbolAnd("startmath", s)) if (StartUtils.startsWithSymbolAnd("startmath", s))
return MATH; return MATH;

View File

@ -45,7 +45,6 @@ import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.regex.Matcher2; import net.sourceforge.plantuml.regex.Matcher2;
import net.sourceforge.plantuml.regex.MyPattern; import net.sourceforge.plantuml.regex.MyPattern;
import net.sourceforge.plantuml.regex.Pattern2; import net.sourceforge.plantuml.regex.Pattern2;
import net.sourceforge.plantuml.text.BackSlash;
import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.StringLocated;
import net.sourceforge.plantuml.utils.LineLocation; import net.sourceforge.plantuml.utils.LineLocation;
import net.sourceforge.plantuml.utils.StartUtils; import net.sourceforge.plantuml.utils.StartUtils;

View File

@ -0,0 +1,76 @@
/* ========================================================================
* 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.eggs;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.PlainDiagram;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.klimt.shape.GraphicStrings;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.UDrawable;
import net.sourceforge.plantuml.version.License;
import net.sourceforge.plantuml.version.Version;
public class PSystemUnsupported extends PlainDiagram {
private final List<String> strings = new ArrayList<>();
public PSystemUnsupported(UmlSource source) {
super(source);
strings.add("<b>Diagram not supported by this release of PlantUML");
strings.add(Version.fullDescription());
strings.add("License " + new License().toString());
}
@Override
protected UDrawable getRootDrawable(FileFormatOption fileFormatOption) throws IOException {
return getGraphicStrings();
}
public TextBlock getGraphicStrings() {
return GraphicStrings.createBlackOnWhite(strings);
}
public DiagramDescription getDescription() {
return new DiagramDescription("(Unsupported)");
}
}

View File

@ -55,14 +55,14 @@ public class StartUtils {
boolean inside = false; boolean inside = false;
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
final String tmp = s.substring(i, s.length()); final String tmp = s.substring(i, s.length());
if (startsWithSymbolAnd("start", tmp)) { if (startsWithSymbolAnd("start", tmp))
return s.substring(0, i); return s.substring(0, i);
}
final String single = s.substring(i, i + 1); final String single = s.substring(i, i + 1);
if (inside) { if (inside) {
if (single.equals(">")) { if (single.equals(">"))
inside = false; inside = false;
}
continue; continue;
} }
if (single.equals("<")) { if (single.equals("<")) {
@ -81,9 +81,9 @@ public class StartUtils {
public static boolean isArobaseStartDiagram(String s) { public static boolean isArobaseStartDiagram(String s) {
final String s2 = StringUtils.trinNoTrace(s); final String s2 = StringUtils.trinNoTrace(s);
if (s2.startsWith("@") == false && s2.startsWith("\\") == false) { if (s2.startsWith("@") == false && s2.startsWith("\\") == false)
return false; return false;
}
return DiagramType.getTypeFromArobaseStart(s2) != DiagramType.UNKNOWN; return DiagramType.getTypeFromArobaseStart(s2) != DiagramType.UNKNOWN;
} }
@ -97,9 +97,9 @@ public class StartUtils {
public static boolean startOrEnd(final StringLocated s) { public static boolean startOrEnd(final StringLocated s) {
final String s2 = StringUtils.trinNoTrace(s.getString()); final String s2 = StringUtils.trinNoTrace(s.getString());
if (s2.startsWith("@") == false && s2.startsWith("\\") == false) { if (s2.startsWith("@") == false && s2.startsWith("\\") == false)
return false; return false;
}
return startsWithSymbolAnd("end", s2) || DiagramType.getTypeFromArobaseStart(s2) != DiagramType.UNKNOWN; return startsWithSymbolAnd("end", s2) || DiagramType.getTypeFromArobaseStart(s2) != DiagramType.UNKNOWN;
} }

View File

@ -58,7 +58,7 @@ public class License {
@Override @Override
public String toString() { public String toString() {
// ::comment when __CORE__ or __MIT__ or __EPL__ or __BSD__ or __ASL__ or __LGPL__ // ::comment when __CORE__ or __MIT__ or __EPL__ or __BSD__ or __ASL__ or __LGPL__ or __GPLV2__
return "GPL"; return "GPL";
// ::done // ::done
// ::uncomment when __CORE__ or __MIT__ // ::uncomment when __CORE__ or __MIT__
@ -76,6 +76,9 @@ public class License {
// ::uncomment when __LGPL__ // ::uncomment when __LGPL__
// return "LGPL"; // return "LGPL";
// ::done // ::done
// ::uncomment when __GPLV2__
// return "GPLv2";
// ::done
} }
public static License getCurrent() { public static License getCurrent() {
@ -155,7 +158,7 @@ public class License {
} }
private void end3(final LicenseInfo licenseInfo, final List<String> text) { private void end3(final LicenseInfo licenseInfo, final List<String> text) {
// ::comment when __CORE__ or __MIT__ or __EPL__ or __BSD__ or __ASL__ or __LGPL__ // ::comment when __CORE__ or __MIT__ or __EPL__ or __BSD__ or __ASL__ or __LGPL__ or __GPLV2__
text.add("PlantUML is free software; you can redistribute it and/or modify it"); text.add("PlantUML is free software; you can redistribute it and/or modify it");
text.add("under the terms of the GNU General Public License as published by"); text.add("under the terms of the GNU General Public License as published by");
text.add("the Free Software Foundation, either version 3 of the License, or"); text.add("the Free Software Foundation, either version 3 of the License, or");
@ -188,6 +191,9 @@ public class License {
// ::uncomment when __LGPL__ // ::uncomment when __LGPL__
// addLgpl(licenseInfo, text); // addLgpl(licenseInfo, text);
// ::done // ::done
// ::uncomment when __GPLV2__
// addGplv2(licenseInfo, text);
// ::done
text.add(" "); text.add(" ");
if (licenseInfo.isValid() == false) { if (licenseInfo.isValid() == false) {
@ -370,22 +376,39 @@ public class License {
// } // }
// ::done // ::done
// ::uncomment when __LGPL__ // ::uncomment when __LGPL__
// private void addLgpl(final LicenseInfo licenseInfo, final List<String> text) { // private void addLgpl(final LicenseInfo licenseInfo, final List<String> text) {
// text.add("PlantUML is free software; you can redistribute it and/or modify it"); // text.add("PlantUML is free software; you can redistribute it and/or modify it");
// text.add("under the terms of the GNU Lesser General Public License as published by"); // text.add("under the terms of the GNU Lesser General Public License as published by");
// text.add("the Free Software Foundation, either version 3 of the License, or"); // text.add("the Free Software Foundation, either version 3 of the License, or");
// text.add("(at your option) any later version."); // text.add("(at your option) any later version.");
// text.add(" "); // text.add(" ");
// text.add("PlantUML distributed in the hope that it will be useful, but"); // text.add("PlantUML distributed in the hope that it will be useful, but");
// text.add("WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY"); // text.add("WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY");
// text.add("or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public"); // text.add("or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public");
// text.add("License for more details."); // text.add("License for more details.");
// text.add(" "); // text.add(" ");
// text.add("You should have received a copy of the GNU Lesser General Public License"); // text.add("You should have received a copy of the GNU Lesser General Public License");
// text.add("along with this library. If not, see <https://www.gnu.org/licenses/>."); // text.add("along with this library. If not, see <https://www.gnu.org/licenses/>.");
// } // }
// ::done // ::done
// ::uncomment when __GPLV2__
// private void addGplv2(final LicenseInfo licenseInfo, final List<String> text) {
// text.add("PlantUML is free software; you can redistribute it and/or modify it");
// text.add("under the terms of the GNU General Public License V2 as published by");
// text.add("the Free Software Foundation, either version 2 of the License, or");
// text.add("(at your option) any later version.");
// text.add(" ");
// text.add("PlantUML distributed in the hope that it will be useful, but");
// text.add("WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY");
// text.add("or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public");
// text.add("License for more details.");
// text.add(" ");
// text.add("You should have received a copy of the GNU Lesser General Public License");
// text.add("along with this library. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.");
// }
// ::done
public static void addLicenseInfo(final List<String> text, LicenseInfo licenseInfo) { public static void addLicenseInfo(final List<String> text, LicenseInfo licenseInfo) {
if (licenseInfo.getLicenseType() == LicenseType.NAMED) { if (licenseInfo.getLicenseType() == LicenseType.NAMED) {