1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 18:30:52 +00:00
plantuml/src/net/sourceforge/plantuml/OptionPrint.java

297 lines
14 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, 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
*
2017-03-15 19:13:31 +00:00
* 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
*
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;
2016-11-18 21:12:09 +00:00
import java.net.InetAddress;
2010-11-15 20:35:36 +00:00
import java.nio.charset.Charset;
2016-09-29 19:51:18 +00:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
2016-11-18 21:12:09 +00:00
import java.util.Map;
2010-11-15 20:35:36 +00:00
import java.util.Properties;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SFile;
import net.sourceforge.plantuml.security.SecurityProfile;
import net.sourceforge.plantuml.security.SecurityUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.syntax.LanguageDescriptor;
import net.sourceforge.plantuml.version.License;
import net.sourceforge.plantuml.version.PSystemVersion;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.version.Version;
public class OptionPrint {
//::remove file when WASM
2010-11-15 20:35:36 +00:00
static public void printTestDot() throws InterruptedException {
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2019-07-14 20:09:26 +00:00
final int errorCode = GraphvizUtils.addDotStatus(result, false);
for (String s : result) {
if (errorCode == 0) {
System.out.println(s);
} else {
System.err.println(s);
}
2010-11-15 20:35:36 +00:00
}
2019-07-14 20:09:26 +00:00
exit(errorCode);
2010-11-15 20:35:36 +00:00
}
static public void printHelp() throws InterruptedException {
final String charset = Charset.defaultCharset().displayName();
2013-12-10 19:36:50 +00:00
System.out.println("Usage: java -jar plantuml.jar [options] -gui");
System.out.println("\t(to execute the GUI)");
System.out.println(" or java -jar plantuml.jar [options] [file/dir] [file/dir] [file/dir]");
System.out.println("\t(to process files or directories)");
System.out.println();
System.out.println("You can use the following wildcards in files/dirs:");
2020-05-30 15:20:23 +00:00
System.out.println("\t*\tmeans any characters but '" + SFile.separator + "'");
System.out.println("\t?\tone and only one character but '" + SFile.separator + "'");
2013-12-10 19:36:50 +00:00
System.out.println("\t**\tmeans any characters (used to recurse through directories)");
System.out.println();
System.out.println("where options include:");
2022-09-23 16:53:33 +00:00
System.out.println(" -darkmode\t\tTo use dark mode for diagrams");
2013-12-10 19:36:50 +00:00
System.out.println(" -gui\t\tTo run the graphical user interface");
System.out.println(" -tpng\t\tTo generate images using PNG format (default)");
System.out.println(" -tsvg\t\tTo generate images using SVG format");
System.out.println(" -teps\t\tTo generate images using EPS format");
2015-04-07 18:18:37 +00:00
System.out.println(" -tpdf\t\tTo generate images using PDF format");
System.out.println(" -tvdx\t\tTo generate images using VDX format");
2013-12-10 19:36:50 +00:00
System.out.println(" -txmi\t\tTo generate XMI file for class diagram");
2016-04-22 20:36:08 +00:00
System.out.println(" -tscxml\t\tTo generate SCXML file for state diagram");
System.out.println(" -thtml\t\tTo generate HTML file for class diagram");
2013-12-10 19:36:50 +00:00
System.out.println(" -ttxt\t\tTo generate images with ASCII art");
System.out.println(" -tutxt\t\tTo generate images with ASCII art using Unicode characters");
2016-03-06 16:47:34 +00:00
System.out.println(" -tlatex\t\tTo generate images using LaTeX/Tikz format");
System.out.println(" -tlatex:nopreamble\tTo generate images using LaTeX/Tikz format without preamble");
2013-12-10 19:36:50 +00:00
System.out.println(" -o[utput] \"dir\"\tTo generate images in the specified directory");
System.out.println(" -DVAR1=value\tTo set a preprocessing variable as if '!define VAR1 value' were used");
System.out.println(" -Sparam1=value\tTo set a skin parameter as if 'skinparam param1 value' were used");
2021-07-25 10:41:36 +00:00
System.out.println(" -Ppragma1=value\tTo set pragma as if '!pragma pragma1 value' were used");
2020-05-30 15:20:23 +00:00
// System.out.println(" -config \"file\"\tTo read the provided config file
// before each diagram");
final char separator = SFile.separatorChar;
2017-03-15 19:13:31 +00:00
System.out.println(" -I" + separator + "path" + separator + "to" + separator
+ "file\tTo include file as if '!include file' were used");
2020-05-30 15:20:23 +00:00
System.out.println(
" -I" + separator + "path" + separator + "to" + separator + "*.puml\tTo include files with pattern");
2021-06-27 16:50:40 +00:00
System.out.println(" -theme xxx\t\tTo use a specific theme");
2013-12-10 19:36:50 +00:00
System.out.println(" -charset xxx\tTo use a specific charset (default is " + charset + ")");
System.out.println(" -e[x]clude pattern\tTo exclude files that match the provided pattern");
System.out.println(" -metadata\t\tTo retrieve PlantUML sources from PNG images");
2017-04-19 18:30:16 +00:00
System.out.println(" -nometadata\t\tTo NOT export metadata in PNG/SVG generated files");
2018-05-01 17:26:04 +00:00
System.out.println(" -checkmetadata\t\tSkip PNG files that don't need to be regenerated");
2013-12-10 19:36:50 +00:00
System.out.println(" -version\t\tTo display information about PlantUML and Java versions");
System.out.println(" -v[erbose]\t\tTo have log information");
System.out.println(" -quiet\t\tTo NOT print error message into the console");
2016-05-11 21:31:47 +00:00
System.out.println(" -debugsvek\t\tTo generate intermediate svek files");
2013-12-10 19:36:50 +00:00
System.out.println(" -h[elp]\t\tTo display this help message");
System.out.println(" -testdot\t\tTo test the installation of graphviz");
System.out.println(" -graphvizdot \"exe\"\tTo specify dot executable");
System.out.println(" -p[ipe]\t\tTo use stdin for PlantUML source and stdout for PNG/SVG/EPS generation");
2020-05-30 15:20:23 +00:00
System.out.println(
" -encodesprite 4|8|16[z] \"file\"\tTo encode a sprite at gray level (z for compression) from an image");
2015-04-07 18:18:37 +00:00
System.out.println(" -computeurl|-encodeurl\tTo compute the encoded URL of a PlantUML source file");
2013-12-10 19:36:50 +00:00
System.out.println(" -decodeurl\t\tTo retrieve the PlantUML source from an encoded URL");
System.out.println(" -syntax\t\tTo report any syntax error from standard input without generating images");
System.out.println(" -language\t\tTo print the list of PlantUML keywords");
2020-05-30 15:20:23 +00:00
// System.out.println(" -nosuggestengine\tTo disable the suggest engine when
// errors in diagrams");
2013-12-10 19:36:50 +00:00
System.out.println(" -checkonly\t\tTo check the syntax of files without generating images");
2015-04-07 18:18:37 +00:00
System.out.println(" -failfast\t\tTo stop processing as soon as a syntax error in diagram occurs");
System.out.println(" -failfast2\t\tTo do a first syntax check before processing files, to fail even faster");
2021-06-27 16:50:40 +00:00
System.out.println(" -noerror\t\tTo skip images when error in diagrams");
2013-12-10 19:36:50 +00:00
System.out.println(" -duration\t\tTo print the duration of complete diagrams processing");
System.out.println(" -nbthread N\t\tTo use (N) threads for processing");
System.out.println(" -nbthread auto\tTo use " + Option.defaultNbThreads() + " threads for processing");
2017-04-05 17:37:42 +00:00
System.out
.println(" -timeout N\t\tProcessing timeout in (N) seconds. Defaults to 15 minutes (900 seconds).");
2013-12-10 19:36:50 +00:00
System.out.println(" -author[s]\t\tTo print information about PlantUML authors");
2015-04-07 18:18:37 +00:00
System.out.println(" -overwrite\t\tTo allow to overwrite read only files");
System.out.println(" -printfonts\t\tTo print fonts available on your system");
2016-12-14 21:01:03 +00:00
System.out.println(" -enablestats\tTo enable statistics computation");
System.out.println(" -disablestats\tTo disable statistics computation (default)");
2016-12-01 20:29:25 +00:00
System.out.println(" -htmlstats\t\tTo output general statistics in file plantuml-stats.html");
System.out.println(" -xmlstats\t\tTo output general statistics in file plantuml-stats.xml");
System.out.println(" -realtimestats\tTo generate statistics on the fly rather than at the end");
2016-12-14 21:01:03 +00:00
System.out.println(" -loopstats\t\tTo continuously print statistics about usage");
2017-03-12 17:22:02 +00:00
System.out.println(" -splash\t\tTo display a splash screen with some progress bar");
System.out.println(" -progress\t\tTo display a textual progress bar in console");
2017-07-03 17:59:53 +00:00
System.out.println(" -pipeimageindex N\tTo generate the Nth image with pipe option");
2019-02-09 21:56:24 +00:00
System.out.println(" -stdlib\t\tTo print standard library info");
2017-12-11 21:02:10 +00:00
System.out.println(" -extractstdlib\tTo extract PlantUML Standard Library into stdlib folder");
2021-05-08 01:07:20 +00:00
System.out.println(" -filedir xxx\tTo behave as if the PlantUML source is in this dir (only affects '-pipe' and PicoWeb 'POST /render')");
2017-12-11 21:02:10 +00:00
System.out.println(" -filename \"example.puml\"\tTo override %filename% variable");
2018-07-27 21:56:46 +00:00
System.out.println(" -preproc\t\tTo output preprocessor text of diagrams");
2018-11-26 18:46:22 +00:00
System.out.println(" -cypher\t\tTo cypher texts of diagrams so that you can share them");
2020-10-12 20:56:58 +00:00
System.out.println(" -picoweb\t\tTo start internal HTTP Server. See https://plantuml.com/picoweb");
2013-12-10 19:36:50 +00:00
System.out.println();
System.out.println("If needed, you can setup the environment variable GRAPHVIZ_DOT.");
2019-07-14 20:09:26 +00:00
exit(0);
2010-11-15 20:35:36 +00:00
}
2019-07-14 20:09:26 +00:00
static private void exit(int errorCode) throws InterruptedException {
if (OptionFlags.getInstance().isSystemExit() || errorCode != 0) {
System.exit(errorCode);
2010-11-15 20:35:36 +00:00
}
throw new InterruptedException("exit");
}
2013-12-10 19:36:50 +00:00
public static void printLicense() throws InterruptedException {
2018-12-22 11:11:40 +00:00
for (String s : License.getCurrent().getTextFull()) {
2013-12-10 19:36:50 +00:00
System.out.println(s);
}
2019-07-14 20:09:26 +00:00
exit(0);
2013-12-10 19:36:50 +00:00
}
2010-11-15 20:35:36 +00:00
public static void printVersion() throws InterruptedException {
2019-07-14 20:09:26 +00:00
System.out.println(Version.fullDescription());
2013-12-10 19:36:50 +00:00
System.out.println("(" + License.getCurrent() + " source distribution)");
2016-11-18 21:12:09 +00:00
for (String v : interestingProperties()) {
System.out.println(v);
2016-09-29 19:51:18 +00:00
}
for (String v : interestingValues()) {
System.out.println(v);
}
2013-12-10 19:36:50 +00:00
System.out.println();
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2019-07-14 20:09:26 +00:00
final int errorCode = GraphvizUtils.addDotStatus(result, false);
for (String s : result) {
2013-12-10 19:36:50 +00:00
System.out.println(s);
}
2019-07-14 20:09:26 +00:00
exit(errorCode);
2013-12-10 19:36:50 +00:00
}
2016-09-29 19:51:18 +00:00
public static Collection<String> interestingProperties() {
2016-11-18 21:12:09 +00:00
final Properties p = System.getProperties();
2020-05-30 15:20:23 +00:00
// final List<String> list1 = Arrays.asList("java.runtime.name", "Java Runtime", "java.vm.name", "JVM",
// "java.runtime.version", "Java Version", "os.name", "Operating System", "file.encoding",
// "Default Encoding", "user.language", "Language", "user.country", "Country");
// final List<String> list2 = Arrays.asList("java.runtime.name", "Java Runtime", "java.vm.name", "JVM",
// "java.runtime.version", "Java Version", "os.name", "Operating System", /* "os.version", "OS Version", */
// "file.encoding", "Default Encoding", "user.language", "Language", "user.country", "Country");
// final List<String> all = withIp() ? list1 : list2;
final List<String> all;
if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) {
all = Arrays.asList("java.runtime.name", "Java Runtime", "java.vm.name", "JVM", "java.runtime.version",
"Java Version", "os.name", "Operating System", "os.version", "OS Version", "file.encoding",
"Default Encoding", "user.language", "Language", "user.country", "Country");
} else {
all = Arrays.asList("java.runtime.name", "Java Runtime", "java.vm.name", "JVM", "file.encoding",
"Default Encoding", "user.language", "Language", "user.country", "Country");
}
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2016-11-18 21:12:09 +00:00
for (int i = 0; i < all.size(); i += 2) {
result.add(all.get(i + 1) + ": " + p.getProperty(all.get(i)));
}
return result;
2016-09-29 19:51:18 +00:00
}
public static Collection<String> interestingValues() {
2021-05-14 08:42:57 +00:00
final List<String> strings = new ArrayList<>();
2020-05-30 15:20:23 +00:00
// if (withIp() == false) {
// strings.add("Machine: " + getHostName());
// }
// strings.add(" ");
// strings.add("Current Security Profile: " + SecurityUtils.getSecurityProfile());
// strings.add(SecurityUtils.getSecurityProfile().longDescription());
strings.add(" ");
2016-11-04 21:39:29 +00:00
strings.add("PLANTUML_LIMIT_SIZE: " + GraphvizUtils.getenvImageLimit());
2020-05-30 15:20:23 +00:00
if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) {
strings.add("Processors: " + Runtime.getRuntime().availableProcessors());
final long freeMemory = Runtime.getRuntime().freeMemory();
final long maxMemory = Runtime.getRuntime().maxMemory();
final long totalMemory = Runtime.getRuntime().totalMemory();
final long usedMemory = totalMemory - freeMemory;
final int threadActiveCount = Thread.activeCount();
strings.add("Max Memory: " + format(maxMemory));
strings.add("Total Memory: " + format(totalMemory));
strings.add("Free Memory: " + format(freeMemory));
strings.add("Used Memory: " + format(usedMemory));
strings.add("Thread Active Count: " + threadActiveCount);
}
2016-09-29 19:51:18 +00:00
return Collections.unmodifiableCollection(strings);
}
2020-05-30 15:20:23 +00:00
// private static boolean withIp() {
// return getHostName().startsWith("ip-");
// }
2016-12-01 20:29:25 +00:00
2016-11-18 21:12:09 +00:00
private static String hostname;
public static synchronized String getHostName() {
if (hostname == null) {
hostname = getHostNameSlow();
}
return hostname;
}
private static String getHostNameSlow() {
try {
final InetAddress addr = InetAddress.getLocalHost();
return addr.getHostName();
} catch (Throwable e) {
final Map<String, String> env = System.getenv();
if (env.containsKey("COMPUTERNAME")) {
return env.get("COMPUTERNAME");
} else if (env.containsKey("HOSTNAME")) {
return env.get("HOSTNAME");
}
}
return "Unknown Computer";
}
2016-09-29 19:51:18 +00:00
private static String format(final long value) {
return String.format(Locale.US, "%,d", value);
}
2010-11-15 20:35:36 +00:00
public static void printAbout() throws InterruptedException {
2016-12-14 21:01:03 +00:00
for (String s : PSystemVersion.getAuthorsStrings(false)) {
System.out.println(s);
}
2019-07-14 20:09:26 +00:00
exit(0);
2010-11-15 20:35:36 +00:00
}
public static void printLanguage() throws InterruptedException {
new LanguageDescriptor().print(System.out);
2019-07-14 20:09:26 +00:00
exit(0);
2010-11-15 20:35:36 +00:00
}
}