1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-11 08:10:56 +00:00
plantuml/src/net/sourceforge/plantuml/Option.java

460 lines
14 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
* 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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* 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.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
2015-04-07 18:18:37 +00:00
import java.util.Arrays;
2010-11-15 20:35:36 +00:00
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Matcher2;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.command.regex.MyPattern;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Pattern2;
2016-04-04 19:05:10 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.preproc.Defines;
2016-12-01 20:29:25 +00:00
import net.sourceforge.plantuml.stats.StatsUtils;
2010-11-15 20:35:36 +00:00
public class Option {
private final List<String> excludes = new ArrayList<String>();
private final List<String> config = new ArrayList<String>();
private final Map<String, String> defines = new LinkedHashMap<String, String>();
private String charset;
private boolean computeurl = false;
private boolean decodeurl = false;
private boolean pipe = false;
2016-11-04 21:39:29 +00:00
private boolean pipeMap = false;
2010-11-15 20:35:36 +00:00
private boolean syntax = false;
2011-08-08 17:48:29 +00:00
private boolean checkOnly = false;
2015-04-07 18:18:37 +00:00
private boolean failfast = false;
private boolean failfast2 = false;
2011-03-20 21:40:07 +00:00
private boolean pattern = false;
2011-08-08 17:48:29 +00:00
private boolean duration = false;
2016-05-11 21:31:47 +00:00
private boolean debugsvek = false;
2011-08-08 17:48:29 +00:00
private int nbThreads = 0;
private int ftpPort = -1;
2010-11-15 20:35:36 +00:00
private File outputDir = null;
2011-08-08 17:48:29 +00:00
private File outputFile = null;
2013-12-10 19:36:50 +00:00
2010-11-15 20:35:36 +00:00
private final List<String> result = new ArrayList<String>();
public Option() {
}
private FileFormat fileFormat = FileFormat.PNG;
public FileFormat getFileFormat() {
return fileFormat;
}
public void setFileFormat(FileFormat fileFormat) {
this.fileFormat = fileFormat;
}
public Option(String... arg) throws InterruptedException, IOException {
if (arg.length == 0) {
OptionFlags.getInstance().setGui(true);
}
for (int i = 0; i < arg.length; i++) {
String s = arg[i];
if (s.equalsIgnoreCase("-tsvg") || s.equalsIgnoreCase("-svg")) {
setFileFormat(FileFormat.SVG);
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-thtml") || s.equalsIgnoreCase("-html")) {
setFileFormat(FileFormat.HTML);
2016-04-22 20:36:08 +00:00
} else if (s.equalsIgnoreCase("-tscxml") || s.equalsIgnoreCase("-scxml")) {
setFileFormat(FileFormat.SCXML);
2011-01-05 18:23:06 +00:00
} else if (s.equalsIgnoreCase("-txmi") || s.equalsIgnoreCase("-xmi")) {
setFileFormat(FileFormat.XMI_STANDARD);
} else if (s.equalsIgnoreCase("-txmi:argo") || s.equalsIgnoreCase("-xmi:argo")) {
setFileFormat(FileFormat.XMI_ARGO);
} else if (s.equalsIgnoreCase("-txmi:star") || s.equalsIgnoreCase("-xmi:star")) {
setFileFormat(FileFormat.XMI_STAR);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-teps") || s.equalsIgnoreCase("-eps")) {
setFileFormat(FileFormat.EPS);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-teps:text") || s.equalsIgnoreCase("-eps:text")) {
setFileFormat(FileFormat.EPS_TEXT);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-ttxt") || s.equalsIgnoreCase("-txt")) {
setFileFormat(FileFormat.ATXT);
} else if (s.equalsIgnoreCase("-tutxt") || s.equalsIgnoreCase("-utxt")) {
setFileFormat(FileFormat.UTXT);
2016-08-25 20:45:37 +00:00
} else if (s.equalsIgnoreCase("-braille") || s.equalsIgnoreCase("-tbraille")) {
setFileFormat(FileFormat.BRAILLE_PNG);
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-png") || s.equalsIgnoreCase("-tpng")) {
setFileFormat(FileFormat.PNG);
} else if (s.equalsIgnoreCase("-vdx") || s.equalsIgnoreCase("-tvdx")) {
setFileFormat(FileFormat.VDX);
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-latex") || s.equalsIgnoreCase("-tlatex")) {
setFileFormat(FileFormat.LATEX);
2016-03-06 16:47:34 +00:00
} else if (s.equalsIgnoreCase("-latex:nopreamble") || s.equalsIgnoreCase("-tlatex:nopreamble")) {
setFileFormat(FileFormat.LATEX_NO_PREAMBLE);
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-base64") || s.equalsIgnoreCase("-tbase64")) {
setFileFormat(FileFormat.BASE64);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-pdf") || s.equalsIgnoreCase("-tpdf")) {
setFileFormat(FileFormat.PDF);
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-overwrite")) {
OptionFlags.getInstance().setOverwrite(true);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-output") || s.equalsIgnoreCase("-o")) {
i++;
if (i == arg.length) {
continue;
}
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-ofile")) {
i++;
if (i == arg.length) {
continue;
}
outputFile = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-graphvizdot") || s.equalsIgnoreCase("-graphviz_dot")) {
i++;
if (i == arg.length) {
continue;
}
2016-04-04 19:05:10 +00:00
GraphvizUtils.setDotExecutable(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-charset")) {
i++;
if (i == arg.length) {
continue;
}
charset = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]);
} else if (s.startsWith("-o") && s.length() > 3) {
s = s.substring(2);
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.equalsIgnoreCase("-recurse") || s.equalsIgnoreCase("-r")) {
// recurse = true;
} else if (s.equalsIgnoreCase("-exclude") || s.equalsIgnoreCase("-x")) {
i++;
if (i == arg.length) {
continue;
}
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-nbthread") || s.equalsIgnoreCase("-nbthreads")) {
i++;
if (i == arg.length) {
continue;
}
final String nb = arg[i];
if ("auto".equalsIgnoreCase(nb)) {
this.nbThreads = defaultNbThreads();
} else if (nb.matches("\\d+")) {
this.nbThreads = Integer.parseInt(nb);
}
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-failfast")) {
this.failfast = true;
} else if (s.equalsIgnoreCase("-failfast2")) {
this.failfast2 = true;
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-checkonly")) {
this.checkOnly = true;
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-config")) {
i++;
if (i == arg.length) {
continue;
}
initConfig(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-computeurl") || s.equalsIgnoreCase("-encodeurl")) {
this.computeurl = true;
} else if (s.startsWith("-x")) {
s = s.substring(2);
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.equalsIgnoreCase("-verbose") || s.equalsIgnoreCase("-v")) {
OptionFlags.getInstance().setVerbose(true);
} else if (s.equalsIgnoreCase("-pipe") || s.equalsIgnoreCase("-p")) {
pipe = true;
2016-11-04 21:39:29 +00:00
} else if (s.equalsIgnoreCase("-pipemap")) {
pipeMap = true;
2011-03-20 21:40:07 +00:00
} else if (s.equalsIgnoreCase("-pattern")) {
pattern = true;
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-syntax")) {
syntax = true;
OptionFlags.getInstance().setQuiet(true);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-duration")) {
duration = true;
2016-05-11 21:31:47 +00:00
} else if (s.equalsIgnoreCase("-debugsvek") || s.equalsIgnoreCase("-debug_svek")) {
debugsvek = true;
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-keepfiles") || s.equalsIgnoreCase("-keepfile")) {
2016-05-11 21:31:47 +00:00
System.err.println("-keepfiles option has been removed. Please consider -debugsvek instead");
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-metadata")) {
OptionFlags.getInstance().setMetadata(true);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-logdata")) {
i++;
if (i == arg.length) {
continue;
}
OptionFlags.getInstance().setLogData(
new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i])));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-word")) {
OptionFlags.getInstance().setWord(true);
OptionFlags.getInstance().setQuiet(true);
} else if (s.equalsIgnoreCase("-quiet")) {
OptionFlags.getInstance().setQuiet(true);
} else if (s.equalsIgnoreCase("-decodeurl")) {
this.decodeurl = true;
} else if (s.equalsIgnoreCase("-version")) {
OptionPrint.printVersion();
2013-12-10 19:36:50 +00:00
} else if (s.matches("(?i)^-li[sc][ea]n[sc]e\\s*$")) {
OptionPrint.printLicense();
} else if (s.equalsIgnoreCase("-checkversion")) {
OptionPrint.checkVersion();
2010-11-15 20:35:36 +00:00
} else if (s.startsWith("-D")) {
manageDefine(s.substring(2));
2011-04-19 16:50:40 +00:00
} else if (s.startsWith("-S")) {
manageSkinParam(s.substring(2));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-testdot")) {
OptionPrint.printTestDot();
} else if (s.equalsIgnoreCase("-about") || s.equalsIgnoreCase("-author") || s.equalsIgnoreCase("-authors")) {
OptionPrint.printAbout();
} else if (s.equalsIgnoreCase("-help") || s.equalsIgnoreCase("-h") || s.equalsIgnoreCase("-?")) {
OptionPrint.printHelp();
} else if (s.equalsIgnoreCase("-language")) {
OptionPrint.printLanguage();
} else if (s.equalsIgnoreCase("-gui")) {
OptionFlags.getInstance().setGui(true);
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-encodesprite")) {
OptionFlags.getInstance().setEncodesprite(true);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-nosuggestengine")) {
OptionFlags.getInstance().setUseSuggestEngine(false);
} else if (s.equalsIgnoreCase("-printfonts")) {
OptionFlags.getInstance().setPrintFonts(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-dumphtmlstats")) {
OptionFlags.getInstance().setDumpHtmlStats(true);
} else if (s.equalsIgnoreCase("-dumpstats")) {
OptionFlags.getInstance().setDumpStats(true);
} else if (s.equalsIgnoreCase("-loopstats")) {
OptionFlags.getInstance().setLoopStats(true);
2016-12-14 21:01:03 +00:00
} else if (s.equalsIgnoreCase("-enablestats")) {
OptionFlags.getInstance().setEnableStats(true);
} else if (s.equalsIgnoreCase("-disablestats")) {
OptionFlags.getInstance().setEnableStats(false);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-htmlstats")) {
StatsUtils.setHtmlStats(true);
} else if (s.equalsIgnoreCase("-xmlstats")) {
StatsUtils.setXmlStats(true);
} else if (s.equalsIgnoreCase("-realtimestats")) {
StatsUtils.setRealTimeStats(true);
} else if (s.equalsIgnoreCase("-useseparatorminus")) {
OptionFlags.getInstance().setFileSeparator("-");
2015-04-07 18:18:37 +00:00
} else if (StringUtils.goLowerCase(s).startsWith("-ftp")) {
2011-08-08 17:48:29 +00:00
final int x = s.indexOf(':');
if (x == -1) {
this.ftpPort = 4242;
} else {
this.ftpPort = Integer.parseInt(s.substring(x + 1));
}
2013-12-10 19:36:50 +00:00
} else if (s.startsWith("-c")) {
s = s.substring(2);
config.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
2010-11-15 20:35:36 +00:00
} else {
result.add(s);
}
}
}
2011-08-08 17:48:29 +00:00
public int getFtpPort() {
return ftpPort;
}
2010-11-15 20:35:36 +00:00
public void initConfig(String filename) throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(filename));
String s = null;
while ((s = br.readLine()) != null) {
config.add(s);
}
} finally {
if (br != null) {
br.close();
}
}
}
private void manageDefine(String s) {
2016-05-31 19:41:55 +00:00
final Pattern2 p = MyPattern.cmpile("^(\\w+)(?:=(.*))?$");
final Matcher2 m = p.matcher(s);
2010-11-15 20:35:36 +00:00
if (m.find()) {
define(m.group(1), m.group(2));
}
}
2011-04-19 16:50:40 +00:00
private void manageSkinParam(String s) {
2016-05-31 19:41:55 +00:00
final Pattern2 p = MyPattern.cmpile("^(\\w+)(?:=(.*))?$");
final Matcher2 m = p.matcher(s);
2011-04-19 16:50:40 +00:00
if (m.find()) {
skinParam(m.group(1), m.group(2));
}
}
private void skinParam(String var, String value) {
if (var != null && value != null) {
config.add("skinparamlocked " + var + " " + value);
}
}
2010-11-15 20:35:36 +00:00
public final File getOutputDir() {
return outputDir;
}
public final static String getPattern() {
2013-12-10 19:36:50 +00:00
return "(?i)^.*\\.(txt|tex|java|htm|html|c|h|cpp|apt|pu)$";
2010-11-15 20:35:36 +00:00
}
public void setOutputDir(File f) {
outputDir = f;
}
public final List<String> getExcludes() {
return Collections.unmodifiableList(excludes);
}
public Defines getDefaultDefines() {
final Defines result = new Defines();
for (Map.Entry<String, String> ent : defines.entrySet()) {
2015-04-07 18:18:37 +00:00
result.define(ent.getKey(), Arrays.asList(ent.getValue()));
2010-11-15 20:35:36 +00:00
}
return result;
}
public void define(String name, String value) {
defines.put(name, value);
}
public List<String> getConfig() {
return Collections.unmodifiableList(config);
}
public final List<String> getResult() {
return Collections.unmodifiableList(result);
}
public final String getCharset() {
return charset;
}
public void setCharset(String s) {
this.charset = s;
}
public final boolean isComputeurl() {
return computeurl;
}
public final boolean isDecodeurl() {
return decodeurl;
}
public final boolean isPipe() {
return pipe;
}
2016-11-04 21:39:29 +00:00
public final boolean isPipeMap() {
return pipeMap;
}
2010-11-15 20:35:36 +00:00
public final boolean isSyntax() {
return syntax;
}
2011-03-20 21:40:07 +00:00
public final boolean isPattern() {
return pattern;
}
2011-01-05 18:23:06 +00:00
public FileFormatOption getFileFormatOption() {
2016-05-11 21:31:47 +00:00
final FileFormatOption fileFormatOption = new FileFormatOption(getFileFormat());
if (debugsvek) {
fileFormatOption.setDebugSvek(true);
}
return fileFormatOption;
2011-01-05 18:23:06 +00:00
}
2011-08-08 17:48:29 +00:00
public final boolean isDuration() {
return duration;
}
public final int getNbThreads() {
return nbThreads;
}
public final void setNbThreads(int nb) {
this.nbThreads = nb;
}
public static int defaultNbThreads() {
return Runtime.getRuntime().availableProcessors();
}
public final boolean isCheckOnly() {
return checkOnly;
}
public final void setCheckOnly(boolean checkOnly) {
this.checkOnly = checkOnly;
}
2015-04-07 18:18:37 +00:00
public final boolean isFailfastOrFailfast2() {
return failfast || failfast2;
}
public final boolean isFailfast2() {
return failfast2;
}
public final void setFailfast(boolean failfast) {
this.failfast = failfast;
}
public final void setFailfast2(boolean failfast2) {
this.failfast2 = failfast2;
}
2011-08-08 17:48:29 +00:00
public final File getOutputFile() {
return outputFile;
}
2016-05-11 21:31:47 +00:00
public final void setDebugSvek(boolean debugsvek) {
this.debugsvek = debugsvek;
}
boolean isDebugSvek() {
return debugsvek;
}
2010-11-15 20:35:36 +00:00
}