Skip to content

Commit

Permalink
version 2017.09
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Apr 5, 2017
1 parent 091a95b commit e3a5d8f
Show file tree
Hide file tree
Showing 242 changed files with 2,849 additions and 918 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>2017.09-SNAPSHOT</version>
<version>2017.10-SNAPSHOT</version>
<packaging>jar</packaging>

<name>PlantUML</name>
Expand Down
24 changes: 22 additions & 2 deletions src/net/sourceforge/plantuml/BlockUml.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import net.sourceforge.plantuml.code.AsciiEncoder;
import net.sourceforge.plantuml.command.regex.Matcher2;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.utils.StartUtils;
import net.sourceforge.plantuml.version.Version;

Expand All @@ -51,9 +53,10 @@ public class BlockUml {
private final List<CharSequence2> data;
private final int startLine;
private Diagram system;
private final Defines localDefines;

BlockUml(String... strings) {
this(convert(strings), 0);
this(convert(strings), 0, Defines.createEmpty());
}

public String getFlashData() {
Expand All @@ -80,8 +83,9 @@ public static List<CharSequence2> convert(List<String> strings) {
return result;
}

public BlockUml(List<CharSequence2> strings, int startLine) {
public BlockUml(List<CharSequence2> strings, int startLine, Defines defines) {
this.startLine = startLine;
this.localDefines = defines;
final CharSequence2 s0 = strings.get(0).trin();
if (StartUtils.startsWithSymbolAnd("start", s0) == false) {
throw new IllegalArgumentException();
Expand Down Expand Up @@ -156,4 +160,20 @@ public long lastModified() {
return (Version.compileTime() / 1000L / 60) * 1000L * 60 + Version.beta() * 1000L * 3600;
}

public boolean isStartDef(String name) {
final String signature = "@startdef(id=" + name + ")";
return data.get(0).toString().equalsIgnoreCase(signature);
}

public List<? extends CharSequence> getDefinition() {
if (data.get(0).toString().startsWith("@startdef") == false) {
throw new IllegalStateException();
}
return Collections.unmodifiableList(data.subList(1, data.size() - 1));
}

public Defines getLocalDefines() {
return localDefines;
}

}
24 changes: 15 additions & 9 deletions src/net/sourceforge/plantuml/BlockUmlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@
import net.sourceforge.plantuml.preproc.UncommentReadLine;
import net.sourceforge.plantuml.utils.StartUtils;

final public class BlockUmlBuilder {
public final class BlockUmlBuilder implements DefinitionsContainer {

private final List<BlockUml> blocks = new ArrayList<BlockUml>();
private Set<FileWithSuffix> usedFiles = new HashSet<FileWithSuffix>();
private final UncommentReadLine reader2;
private final Defines defines;

public BlockUmlBuilder(List<String> config, String charset, Defines defines, Reader reader, File newCurrentDir,
String desc) throws IOException {
Preprocessor includer = null;
this.defines = defines;
try {
reader2 = new UncommentReadLine(new ReadLineReader(reader, desc));
includer = new Preprocessor(reader2, charset, defines, newCurrentDir);
includer = new Preprocessor(reader2, charset, defines, newCurrentDir, this);
init(includer, config);
} finally {
if (includer != null) {
Expand Down Expand Up @@ -107,7 +109,7 @@ private void init(Preprocessor includer, List<String> config) throws IOException
}
if (StartUtils.isArobaseEndDiagram(s) && current2 != null) {
current2.addAll(1, convert(config, s.getLocation()));
blocks.add(new BlockUml(current2, startLine));
blocks.add(new BlockUml(current2, startLine, defines.cloneMe()));
current2 = null;
reader2.setPaused(false);
}
Expand All @@ -130,10 +132,14 @@ public final Set<FileWithSuffix> getIncludedFiles() {
return Collections.unmodifiableSet(usedFiles);
}

/*
* private List<String> getStrings(Reader reader) throws IOException { final List<String> result = new
* ArrayList<String>(); Preprocessor includer = null; try { includer = new Preprocessor(reader, defines); String s =
* null; while ((s = includer.readLine()) != null) { result.add(s); } } finally { if (includer != null) {
* includer.close(); } } return Collections.unmodifiableList(result); }
*/
public List<? extends CharSequence> getDefinition(String name) {
for (BlockUml block : blocks) {
if (block.isStartDef(name)) {
this.defines.importFrom(block.getLocalDefines());
return block.getDefinition();
}
}
return Collections.emptyList();
}

}
44 changes: 44 additions & 0 deletions src/net/sourceforge/plantuml/DefinitionsContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, 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;

import java.util.List;

public interface DefinitionsContainer {

public List<? extends CharSequence> getDefinition(String name);

}
8 changes: 4 additions & 4 deletions src/net/sourceforge/plantuml/DirWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public List<GeneratedImage> buildCreatedFiles() throws IOException, InterruptedE
final FileWatcher watcher = modifieds.get(f);

if (watcher == null || watcher.hasChanged()) {
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(),
option.getConfig(), option.getCharset(), option.getFileFormatOption());
final SourceFileReader sourceFileReader = new SourceFileReader(Defines.createWithFileName(f), f,
option.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormatOption());
final Set<File> files = FileWithSuffix.convert(sourceFileReader.getIncludedFiles());
files.add(f);
for (GeneratedImage g : sourceFileReader.getGeneratedImages()) {
Expand All @@ -106,8 +106,8 @@ public File getErrorFile() throws IOException, InterruptedException {
final FileWatcher watcher = modifieds.get(f);

if (watcher == null || watcher.hasChanged()) {
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(),
option.getConfig(), option.getCharset(), option.getFileFormatOption());
final SourceFileReader sourceFileReader = new SourceFileReader(Defines.createWithFileName(f), f,
option.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormatOption());
if (sourceFileReader.hasError()) {
return f;
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/DirWatcher2.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Map<File, Future<List<GeneratedImage>>> buildCreatedFiles() throws IOExce
final FileWatcher watcher = modifieds.get(f);

if (watcher == null || watcher.hasChanged()) {
final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f,
final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(f), f,
option.getOutputDir(), option.getConfig(), option.getCharset(),
option.getFileFormatOption());
modifieds.put(f, new FileWatcher(Collections.singleton(f)));
Expand Down
27 changes: 21 additions & 6 deletions src/net/sourceforge/plantuml/FileFormatOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.awt.geom.AffineTransform;
import java.io.Serializable;
import java.util.Random;

import net.sourceforge.plantuml.graphic.StringBounder;

Expand All @@ -55,9 +56,10 @@ public class FileFormatOption implements Serializable {
private final boolean useRedForError;
private final String svgLinkTarget;
private final String hoverColor;
private final Random rnd;

public FileFormatOption(FileFormat fileFormat) {
this(fileFormat, null, true, false, "_top", false, null);
this(fileFormat, null, true, false, "_top", false, null, new Random());
}

public StringBounder getDefaultStringBounder() {
Expand All @@ -72,31 +74,44 @@ public final boolean isWithMetadata() {
return withMetadata;
}

public final Random getRandom() {
return rnd;
}

public FileFormatOption(FileFormat fileFormat, boolean withMetadata) {
this(fileFormat, null, false, false, "_top", false, null);
this(fileFormat, null, false, false, "_top", false, null, new Random());
}

private FileFormatOption(FileFormat fileFormat, AffineTransform at, boolean withMetadata, boolean useRedForError,
String svgLinkTarget, boolean debugsvek, String hoverColor) {
String svgLinkTarget, boolean debugsvek, String hoverColor, Random rnd) {
this.hoverColor = hoverColor;
this.fileFormat = fileFormat;
this.affineTransform = at;
this.withMetadata = withMetadata;
this.useRedForError = useRedForError;
this.svgLinkTarget = svgLinkTarget;
this.debugsvek = debugsvek;
this.rnd = rnd;
}

public FileFormatOption withUseRedForError() {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, true, svgLinkTarget, debugsvek, hoverColor);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, true, svgLinkTarget, debugsvek,
hoverColor, rnd);
}

public FileFormatOption withSvgLinkTarget(String svgLinkTarget) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek, hoverColor);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, rnd);
}

public FileFormatOption withHoverColor(String hoverColor) {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget, debugsvek, hoverColor);
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, rnd);
}

public FileFormatOption withFixedRandom() {
return new FileFormatOption(fileFormat, affineTransform, withMetadata, useRedForError, svgLinkTarget,
debugsvek, hoverColor, new Random(42));
}

@Override
Expand Down
Loading

0 comments on commit e3a5d8f

Please sign in to comment.