fix: Improve line endings in the output files

https://github.com/plantuml/plantuml/pull/1183
This commit is contained in:
Arnaud Roques 2023-03-14 18:46:55 +01:00
parent 44b4051016
commit 534fc27942
15 changed files with 50 additions and 43 deletions

View File

@ -105,14 +105,14 @@ public abstract class AbstractPSystem implements Diagram {
} }
final public String getMetadata() { final public String getMetadata() {
if (source == null) { if (source == null)
return getVersion(); return getVersion();
}
final String rawString = source.getRawString(); final String rawString = source.getRawString("\n");
final String plainString = source.getPlainString(); final String plainString = source.getPlainString("\n");
if (rawString != null && rawString.equals(plainString)) { if (rawString != null && rawString.equals(plainString))
return rawString + BackSlash.NEWLINE + getVersion(); return rawString + BackSlash.NEWLINE + getVersion();
}
return rawString + BackSlash.NEWLINE + plainString + BackSlash.NEWLINE + getVersion(); return rawString + BackSlash.NEWLINE + plainString + BackSlash.NEWLINE + getVersion();
} }
@ -121,9 +121,9 @@ public abstract class AbstractPSystem implements Diagram {
} }
final public long seed() { final public long seed() {
if (source == null) { if (source == null)
return 42; return 42;
}
return getSource().seed(); return getSource().seed();
} }
@ -150,9 +150,9 @@ public abstract class AbstractPSystem implements Diagram {
} }
public DisplayPositionned getTitle() { public DisplayPositionned getTitle() {
if (source == null) { if (source == null)
return DisplayPositioned.single(Display.empty(), HorizontalAlignment.CENTER, VerticalAlignment.TOP); return DisplayPositioned.single(Display.empty(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
}
return DisplayPositioned.single(source.getTitle(), HorizontalAlignment.CENTER, VerticalAlignment.TOP); return DisplayPositioned.single(source.getTitle(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
} }

View File

@ -89,7 +89,7 @@ public class BlockUml {
// ::comment when __CORE__ // ::comment when __CORE__
public String getEncodedUrl() throws IOException { public String getEncodedUrl() throws IOException {
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder(); final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
final String source = getDiagram().getSource().getPlainString(); final String source = getDiagram().getSource().getPlainString("\n");
final String encoded = transcoder.encode(source); final String encoded = transcoder.encode(source);
return encoded; return encoded;
} }

View File

@ -223,7 +223,7 @@ public abstract class UmlDiagram extends TitledDiagram implements Diagram, Annot
if (source == null) if (source == null)
return ""; return "";
return source.getPlainString(); return source.getPlainString("\n");
} }
static private List<String> getFailureText1(Throwable exception, String graphvizVersion, String textDiagram) { static private List<String> getFailureText1(Throwable exception, String graphvizVersion, String textDiagram) {

View File

@ -160,32 +160,30 @@ final public class UmlSource {
// } // }
/** /**
* Return the source as a single String with <code>\n</code> as line separator. * Return the source as a single String.
* *
* @return the whole diagram source * @return the whole diagram source
*/ */
public String getPlainString() { public String getPlainString(String separator) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (StringLocated s : source) { for (StringLocated s : source) {
sb.append(s.getString()); sb.append(s.getString());
sb.append('\r'); sb.append(separator);
sb.append(BackSlash.CHAR_NEWLINE);
} }
return sb.toString(); return sb.toString();
} }
public String getRawString() { public String getRawString(String separator) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (StringLocated s : rawSource) { for (StringLocated s : rawSource) {
sb.append(s.getString()); sb.append(s.getString());
sb.append('\r'); sb.append(separator);
sb.append(BackSlash.CHAR_NEWLINE);
} }
return sb.toString(); return sb.toString();
} }
public long seed() { public long seed() {
return StringUtils.seed(getPlainString()); return StringUtils.seed(getPlainString("\n"));
} }
public String getLine(LineLocation n) { public String getLine(LineLocation n) {

View File

@ -109,7 +109,7 @@ public class PSystemDitaa extends AbstractPSystem {
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat) final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat)
throws IOException { throws IOException {
if (fileFormat.getFileFormat() == FileFormat.ATXT) { if (fileFormat.getFileFormat() == FileFormat.ATXT) {
os.write(getSource().getPlainString().getBytes()); os.write(getSource().getPlainString(BackSlash.lineSeparator()).getBytes());
return ImageDataSimple.ok(); return ImageDataSimple.ok();
} }

View File

@ -113,6 +113,7 @@ import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.svek.GraphvizCrash; import net.sourceforge.plantuml.svek.GraphvizCrash;
import net.sourceforge.plantuml.text.BackSlash;
public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprite { public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprite {
@ -256,7 +257,8 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit
} catch (Throwable t) { } catch (Throwable t) {
Logme.error(t); Logme.error(t);
final UDrawable crash = new GraphvizCrash(getSource().getPlainString(), false, t); final UDrawable crash = new GraphvizCrash(getSource().getPlainString(BackSlash.lineSeparator()),
false, t);
crash.drawU(ug); crash.drawU(ug);
} }

View File

@ -122,6 +122,7 @@ import net.sourceforge.plantuml.svek.image.EntityImageStateEmptyDescription;
import net.sourceforge.plantuml.svek.image.EntityImageSynchroBar; import net.sourceforge.plantuml.svek.image.EntityImageSynchroBar;
import net.sourceforge.plantuml.svek.image.EntityImageTips; import net.sourceforge.plantuml.svek.image.EntityImageTips;
import net.sourceforge.plantuml.svek.image.EntityImageUseCase; import net.sourceforge.plantuml.svek.image.EntityImageUseCase;
import net.sourceforge.plantuml.text.BackSlash;
import net.sourceforge.plantuml.text.Guillemet; import net.sourceforge.plantuml.text.Guillemet;
import net.sourceforge.plantuml.utils.Log; import net.sourceforge.plantuml.utils.Log;
@ -455,11 +456,12 @@ public final class GeneralImageBuilder {
try { try {
svg = dotStringFactory.getSvg(basefile, dotStrings); svg = dotStringFactory.getSvg(basefile, dotStrings);
} catch (IOException e) { } catch (IOException e) {
return new GraphvizCrash(source.getPlainString(), GraphvizUtils.graphviz244onWindows(), e); return new GraphvizCrash(source.getPlainString(BackSlash.lineSeparator()),
GraphvizUtils.graphviz244onWindows(), e);
} }
if (svg.length() == 0) if (svg.length() == 0)
return new GraphvizCrash(source.getPlainString(), GraphvizUtils.graphviz244onWindows(), return new GraphvizCrash(source.getPlainString(BackSlash.lineSeparator()),
new EmptySvgException()); GraphvizUtils.graphviz244onWindows(), new EmptySvgException());
final String graphvizVersion = extractGraphvizVersion(svg); final String graphvizVersion = extractGraphvizVersion(svg);
try { try {
@ -469,7 +471,8 @@ public final class GeneralImageBuilder {
return result; return result;
} catch (Exception e) { } catch (Exception e) {
Log.error("Exception " + e); Log.error("Exception " + e);
throw new UnparsableGraphvizException(e, graphvizVersion, svg, source.getPlainString()); throw new UnparsableGraphvizException(e, graphvizVersion, svg,
source.getPlainString(BackSlash.lineSeparator()));
} }
// ::done // ::done
// ::uncomment when __CORE__ // ::uncomment when __CORE__

View File

@ -47,6 +47,10 @@ public class BackSlash {
public static final String BS_BS_N = "\\n"; public static final String BS_BS_N = "\\n";
public static final String NEWLINE = "\n"; public static final String NEWLINE = "\n";
public static final char CHAR_NEWLINE = '\n'; public static final char CHAR_NEWLINE = '\n';
public static final String lineSeparator() {
return System.lineSeparator();
}
public static char hiddenNewLine() { public static char hiddenNewLine() {
return StringUtils.PRIVATE_BLOCK + BackSlash.CHAR_NEWLINE; return StringUtils.PRIVATE_BLOCK + BackSlash.CHAR_NEWLINE;
@ -67,9 +71,9 @@ public class BackSlash {
} }
public static List<String> getWithNewlines(CharSequence s) { public static List<String> getWithNewlines(CharSequence s) {
if (s == null) { if (s == null)
return null; return null;
}
final List<String> result = new ArrayList<>(); final List<String> result = new ArrayList<>();
final StringBuilder current = new StringBuilder(); final StringBuilder current = new StringBuilder();
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
@ -94,9 +98,9 @@ public class BackSlash {
} }
public static String translateBackSlashes(CharSequence s) { public static String translateBackSlashes(CharSequence s) {
if (s == null) { if (s == null)
return null; return null;
}
// final String tmps = s.toString(); // final String tmps = s.toString();
// if (tmps.indexOf('\\') == -1) { // if (tmps.indexOf('\\') == -1) {
// return tmps; // return tmps;
@ -121,24 +125,24 @@ public class BackSlash {
} }
public static String untranslateBackSlashes(CharSequence s) { public static String untranslateBackSlashes(CharSequence s) {
if (s == null) { if (s == null)
return null; return null;
}
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i); char c = s.charAt(i);
if (c > StringUtils.PRIVATE_BLOCK && c < '\uE07F') { if (c > StringUtils.PRIVATE_BLOCK && c < '\uE07F')
c = (char) (c - StringUtils.PRIVATE_BLOCK); c = (char) (c - StringUtils.PRIVATE_BLOCK);
}
result.append(c); result.append(c);
} }
return result.toString(); return result.toString();
} }
private static char translateChar(char c) { private static char translateChar(char c) {
if (c > 128) { if (c > 128)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
}
return (char) (StringUtils.PRIVATE_BLOCK + c); return (char) (StringUtils.PRIVATE_BLOCK + c);
} }

View File

@ -7,7 +7,7 @@ public class A0000_TestResult {
DPI: 96 DPI: 96
dimension: [ 185.5185 ; 113.0000 ] dimension: [ 185.5185 ; 113.0000 ]
scaleFactor: 1.0000 scaleFactor: 1.0000
seed: 5605069588648637213 seed: 7067927655347766828
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none

View File

@ -7,7 +7,7 @@ public class A0001_TestResult {
DPI: 96 DPI: 96
dimension: [ 296.7331 ; 285.0000 ] dimension: [ 296.7331 ; 285.0000 ]
scaleFactor: 1.0000 scaleFactor: 1.0000
seed: -1212656935193060805 seed: 1230863714434809965
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none

View File

@ -7,7 +7,7 @@ public class A0002_TestResult {
DPI: 96 DPI: 96
dimension: [ 660.1096 ; 994.5000 ] dimension: [ 660.1096 ; 994.5000 ]
scaleFactor: 1.0000 scaleFactor: 1.0000
seed: -9181376250803721714 seed: -2543044357581316352
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none

View File

@ -7,7 +7,7 @@ public class A0003_TestResult {
DPI: 96 DPI: 96
dimension: [ 367.7447 ; 76.0000 ] dimension: [ 367.7447 ; 76.0000 ]
scaleFactor: 2.0000 scaleFactor: 2.0000
seed: -6040919743496430850 seed: 2061842952546013393
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none

View File

@ -7,7 +7,7 @@ public class A0004_TestResult {
DPI: 96 DPI: 96
dimension: [ 550.6156 ; 680.0000 ] dimension: [ 550.6156 ; 680.0000 ]
scaleFactor: 1.0000 scaleFactor: 1.0000
seed: 6985134683589840646 seed: -1093380870564056548
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none

View File

@ -7,7 +7,7 @@ public class A0005_TestResult {
DPI: 96 DPI: 96
dimension: [ 134.0935 ; 286.0000 ] dimension: [ 134.0935 ; 286.0000 ]
scaleFactor: 1.0000 scaleFactor: 1.0000
seed: 1145907385572836867 seed: -2035695693520640443
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none

View File

@ -7,7 +7,7 @@ public class A0006_TestResult {
DPI: 96 DPI: 96
dimension: [ 149.3989 ; 231.0000 ] dimension: [ 149.3989 ; 231.0000 ]
scaleFactor: 1.0000 scaleFactor: 1.0000
seed: -2375783792654745998 seed: -967197275408610478
svgLinkTarget: _top svgLinkTarget: _top
hoverPathColorRGB: null hoverPathColorRGB: null
preserveAspectRatio: none preserveAspectRatio: none