File size: 8,677 Bytes
eb67da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2023, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://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.svek;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.BackSlash;
import net.sourceforge.plantuml.OptionPrint;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
import net.sourceforge.plantuml.flashcode.FlashCodeFactory;
import net.sourceforge.plantuml.flashcode.FlashCodeUtils;
import net.sourceforge.plantuml.fun.IconLoader;
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.QuoteUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.ugraphic.AffineTransformType;
import net.sourceforge.plantuml.ugraphic.PixelImage;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
import net.sourceforge.plantuml.version.PSystemVersion;
import net.sourceforge.plantuml.version.Version;
public class GraphvizCrash extends AbstractTextBlock implements IEntityImage {
private final TextBlock text1;
private final BufferedImage flashCode;
private final String text;
private final boolean graphviz244onWindows;
public GraphvizCrash(String text, boolean graphviz244onWindows, Throwable rootCause) {
this.text = text;
this.graphviz244onWindows = graphviz244onWindows;
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
this.flashCode = utils.exportFlashcode(text, Color.BLACK, Color.WHITE);
this.text1 = GraphicStrings.createBlackOnWhite(init(rootCause), IconLoader.getRandom(),
GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT);
}
public static List<String> anErrorHasOccured(Throwable exception, String text) {
final List<String> strings = new ArrayList<>();
if (exception == null) {
strings.add("An error has occured!");
} else {
strings.add("An error has occured : " + exception);
}
final String quote = StringUtils.rot(QuoteUtils.getSomeQuote());
strings.add("<i>" + quote);
strings.add(" ");
strings.add("Diagram size: " + lines(text) + " lines / " + text.length() + " characters.");
strings.add(" ");
return strings;
}
private static int lines(String text) {
int result = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == BackSlash.CHAR_NEWLINE) {
result++;
}
}
return result;
}
public static void checkOldVersionWarning(List<String> strings) {
final long days = (System.currentTimeMillis() - Version.compileTime()) / 1000L / 3600 / 24;
if (days >= 90) {
strings.add(" ");
strings.add("<b>This version of PlantUML is " + days + " days old, so you should");
strings.add("<b>consider upgrading from https://plantuml.com/download");
}
}
public static void pleaseGoTo(List<String> strings) {
strings.add(" ");
strings.add("Please go to https://plantuml.com/graphviz-dot to check your GraphViz version.");
strings.add(" ");
}
public static void youShouldSendThisDiagram(List<String> strings) {
strings.add("You should send this diagram and this image to <b>[email protected]</b> or");
strings.add("post to <b>https://plantuml.com/qa</b> to solve this issue.");
strings.add("You can try to turn arround this issue by simplifing your diagram.");
}
public static void thisMayBeCaused(final List<String> strings) {
strings.add("This may be caused by :");
strings.add(" - a bug in PlantUML");
strings.add(" - a problem in GraphViz");
}
private List<String> init(Throwable rootCause) {
final List<String> strings = anErrorHasOccured(null, text);
strings.add("For some reason, dot/GraphViz has crashed.");
strings.add("");
strings.add("RootCause " + rootCause);
if (rootCause != null) {
strings.addAll(CommandExecutionResult.getStackTrace(rootCause));
}
strings.add("");
strings.add("This has been generated with PlantUML (" + Version.versionString() + ").");
checkOldVersionWarning(strings);
strings.add(" ");
addProperties(strings);
strings.add(" ");
try {
final String dotVersion = GraphvizUtils.dotVersion();
strings.add("Default dot version: " + dotVersion);
} catch (Throwable e) {
strings.add("Cannot determine dot version: " + e.toString());
}
pleaseGoTo(strings);
youShouldSendThisDiagram(strings);
if (flashCode != null) {
addDecodeHint(strings);
}
return strings;
}
private List<String> getText2() {
final List<String> strings = new ArrayList<>();
strings.add(" ");
strings.add("<b>It looks like you are running GraphViz 2.44 under Windows.");
strings.add("If you have just installed GraphViz, you <i>may</i> have to execute");
strings.add("the post-install command <b>dot -c</b> like in the following example:");
return strings;
}
private List<String> getText3() {
final List<String> strings = new ArrayList<>();
strings.add(" ");
strings.add("You may have to have <i>Administrator rights</i> to avoid the following error message:");
return strings;
}
public static void addDecodeHint(final List<String> strings) {
strings.add(" ");
strings.add(" Diagram source: (Use http://zxing.org/w/decode.jspx to decode the qrcode)");
}
public static void addProperties(final List<String> strings) {
strings.addAll(OptionPrint.interestingProperties());
strings.addAll(OptionPrint.interestingValues());
}
public boolean isHidden() {
return false;
}
public HColor getBackcolor() {
return HColorUtils.WHITE;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return getMain().calculateDimension(stringBounder);
}
public void drawU(UGraphic ug) {
getMain().drawU(ug);
}
private TextBlock getMain() {
TextBlock result = text1;
if (flashCode != null) {
final UImage flash = new UImage(new PixelImage(flashCode, AffineTransformType.TYPE_NEAREST_NEIGHBOR))
.scale(3);
result = TextBlockUtils.mergeTB(result, flash, HorizontalAlignment.LEFT);
}
if (graphviz244onWindows) {
final TextBlock text2 = GraphicStrings.createBlackOnWhite(getText2());
result = TextBlockUtils.mergeTB(result, text2, HorizontalAlignment.LEFT);
final UImage dotc = new UImage(new PixelImage(PSystemVersion.getDotc(), AffineTransformType.TYPE_BILINEAR));
result = TextBlockUtils.mergeTB(result, dotc, HorizontalAlignment.LEFT);
final TextBlock text3 = GraphicStrings.createBlackOnWhite(getText3());
result = TextBlockUtils.mergeTB(result, text3, HorizontalAlignment.LEFT);
final UImage dotd = new UImage(new PixelImage(PSystemVersion.getDotd(), AffineTransformType.TYPE_BILINEAR));
result = TextBlockUtils.mergeTB(result, dotd, HorizontalAlignment.LEFT);
}
return result;
}
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
public Margins getShield(StringBounder stringBounder) {
return Margins.NONE;
}
public double getOverscanX(StringBounder stringBounder) {
return 0;
}
}
|