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;
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
import java.awt.Font;
|
2016-09-29 19:51:18 +00:00
|
|
|
import java.awt.FontMetrics;
|
|
|
|
import java.awt.Graphics2D;
|
2010-11-15 20:35:36 +00:00
|
|
|
import java.awt.GraphicsEnvironment;
|
2016-09-29 19:51:18 +00:00
|
|
|
import java.awt.geom.Rectangle2D;
|
2013-12-10 19:36:50 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
2010-11-15 20:35:36 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2018-07-27 21:56:46 +00:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.net.URL;
|
2017-03-12 17:22:02 +00:00
|
|
|
import java.util.ArrayList;
|
2010-11-15 20:35:36 +00:00
|
|
|
import java.util.List;
|
2011-08-08 17:48:29 +00:00
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
import javax.swing.UIManager;
|
|
|
|
|
2020-05-07 14:12:08 +00:00
|
|
|
import net.sourceforge.plantuml.code.NoPlantumlCompressionException;
|
2010-11-15 20:35:36 +00:00
|
|
|
import net.sourceforge.plantuml.code.Transcoder;
|
2011-01-05 18:23:06 +00:00
|
|
|
import net.sourceforge.plantuml.code.TranscoderUtil;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.ftp.FtpServer;
|
2020-10-12 20:56:58 +00:00
|
|
|
import net.sourceforge.plantuml.picoweb.PicoWebServer;
|
2010-11-15 20:35:36 +00:00
|
|
|
import net.sourceforge.plantuml.png.MetadataTag;
|
2018-06-12 20:50:45 +00:00
|
|
|
import net.sourceforge.plantuml.preproc.Stdlib;
|
2020-05-30 15:20:23 +00:00
|
|
|
import net.sourceforge.plantuml.security.SFile;
|
2021-12-02 17:39:20 +00:00
|
|
|
import net.sourceforge.plantuml.security.SImageIO;
|
2020-05-30 15:20:23 +00:00
|
|
|
import net.sourceforge.plantuml.security.SecurityUtils;
|
2019-08-26 17:07:21 +00:00
|
|
|
import net.sourceforge.plantuml.sprite.SpriteGrayLevel;
|
|
|
|
import net.sourceforge.plantuml.sprite.SpriteUtils;
|
2016-12-01 20:29:25 +00:00
|
|
|
import net.sourceforge.plantuml.stats.StatsUtils;
|
2021-08-02 10:11:47 +00:00
|
|
|
import net.sourceforge.plantuml.swing.MainWindow;
|
2018-07-27 21:56:46 +00:00
|
|
|
import net.sourceforge.plantuml.syntax.LanguageDescriptor;
|
|
|
|
import net.sourceforge.plantuml.utils.Cypher;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.version.Version;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
public class Run {
|
|
|
|
|
2018-07-27 21:56:46 +00:00
|
|
|
private static Cypher cypher;
|
|
|
|
|
2020-05-30 15:20:23 +00:00
|
|
|
public static void main(String[] argsArray)
|
|
|
|
throws NoPlantumlCompressionException, IOException, InterruptedException {
|
2018-06-12 20:50:45 +00:00
|
|
|
System.setProperty("log4j.debug", "false");
|
2011-08-08 17:48:29 +00:00
|
|
|
final long start = System.currentTimeMillis();
|
2018-06-12 20:50:45 +00:00
|
|
|
if (argsArray.length > 0 && argsArray[0].equalsIgnoreCase("-headless")) {
|
|
|
|
System.setProperty("java.awt.headless", "true");
|
|
|
|
}
|
2021-12-02 17:39:20 +00:00
|
|
|
// if (argsArray.length > 0 && argsArray[0].equalsIgnoreCase("--de")) {
|
|
|
|
// debugGantt();
|
|
|
|
// return;
|
|
|
|
// }
|
2017-04-05 17:37:42 +00:00
|
|
|
saveCommandLine(argsArray);
|
2010-11-15 20:35:36 +00:00
|
|
|
final Option option = new Option(argsArray);
|
2017-03-12 17:22:02 +00:00
|
|
|
ProgressBar.setEnable(option.isTextProgressBar());
|
2018-06-12 20:50:45 +00:00
|
|
|
if (OptionFlags.getInstance().isClipboardLoop()) {
|
|
|
|
ClipboardLoop.runLoop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (OptionFlags.getInstance().isClipboard()) {
|
|
|
|
ClipboardLoop.runOnce();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (OptionFlags.getInstance().isExtractStdLib()) {
|
|
|
|
Stdlib.extractStdLib();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (OptionFlags.getInstance().isStdLib()) {
|
|
|
|
Stdlib.printStdLib();
|
2017-12-11 21:02:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-12-01 20:29:25 +00:00
|
|
|
if (OptionFlags.getInstance().isDumpStats()) {
|
|
|
|
StatsUtils.dumpStats();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (OptionFlags.getInstance().isLoopStats()) {
|
|
|
|
StatsUtils.loopStats();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (OptionFlags.getInstance().isDumpHtmlStats()) {
|
|
|
|
StatsUtils.outHtml();
|
|
|
|
return;
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
if (OptionFlags.getInstance().isEncodesprite()) {
|
|
|
|
encodeSprite(option.getResult());
|
|
|
|
return;
|
|
|
|
}
|
2020-05-30 15:20:23 +00:00
|
|
|
Log.info("SecurityProfile " + SecurityUtils.getSecurityProfile());
|
2010-11-15 20:35:36 +00:00
|
|
|
if (OptionFlags.getInstance().isVerbose()) {
|
2013-12-10 19:36:50 +00:00
|
|
|
Log.info("PlantUML Version " + Version.versionString());
|
2010-11-15 20:35:36 +00:00
|
|
|
Log.info("GraphicsEnvironment.isHeadless() " + GraphicsEnvironment.isHeadless());
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
if (GraphicsEnvironment.isHeadless()) {
|
|
|
|
Log.info("Forcing -Djava.awt.headless=true");
|
|
|
|
System.setProperty("java.awt.headless", "true");
|
|
|
|
Log.info("java.awt.headless set as true");
|
2015-04-07 18:18:37 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
if (OptionFlags.getInstance().isPrintFonts()) {
|
|
|
|
printFonts();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (option.getFtpPort() != -1) {
|
|
|
|
goFtp(option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-12 20:56:58 +00:00
|
|
|
if (option.getPicowebPort() != -1) {
|
|
|
|
goPicoweb(option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:51:18 +00:00
|
|
|
forceOpenJdkResourceLoad();
|
2018-07-27 21:56:46 +00:00
|
|
|
if (option.getPreprocessorOutputMode() == OptionPreprocOutputMode.CYPHER) {
|
|
|
|
cypher = new LanguageDescriptor().getCypher();
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
final ErrorStatus error = ErrorStatus.init();
|
2013-12-10 19:36:50 +00:00
|
|
|
boolean forceQuit = false;
|
2021-05-23 15:35:13 +00:00
|
|
|
if (OptionFlags.getInstance().isGui()) {
|
2010-11-15 20:35:36 +00:00
|
|
|
try {
|
|
|
|
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
final List<String> list = option.getResult();
|
|
|
|
File dir = null;
|
|
|
|
if (list.size() == 1) {
|
|
|
|
final File f = new File(list.get(0));
|
|
|
|
if (f.exists() && f.isDirectory()) {
|
|
|
|
dir = f;
|
|
|
|
}
|
|
|
|
}
|
2021-03-09 18:02:38 +00:00
|
|
|
try {
|
2021-08-02 10:11:47 +00:00
|
|
|
new MainWindow(option, dir);
|
2021-03-09 18:02:38 +00:00
|
|
|
} catch (java.awt.HeadlessException e) {
|
|
|
|
System.err.println("There is an issue with your server. You will find some tips here:");
|
|
|
|
System.err.println("https://forum.plantuml.net/3399/problem-with-x11-and-headless-exception");
|
|
|
|
System.err.println("https://plantuml.com/en/faq#239d64f675c3e515");
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2016-11-04 21:39:29 +00:00
|
|
|
} else if (option.isPipe() || option.isPipeMap() || option.isSyntax()) {
|
2018-12-22 11:11:40 +00:00
|
|
|
managePipe(option, error);
|
2013-12-10 19:36:50 +00:00
|
|
|
forceQuit = true;
|
2015-04-07 18:18:37 +00:00
|
|
|
} else if (option.isFailfast2()) {
|
2017-03-12 17:22:02 +00:00
|
|
|
if (option.isSplash()) {
|
|
|
|
Splash.createSplash();
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
final long start2 = System.currentTimeMillis();
|
|
|
|
option.setCheckOnly(true);
|
2018-12-22 11:11:40 +00:00
|
|
|
manageAllFiles(option, error);
|
2015-04-07 18:18:37 +00:00
|
|
|
option.setCheckOnly(false);
|
|
|
|
if (option.isDuration()) {
|
|
|
|
final double duration = (System.currentTimeMillis() - start2) / 1000.0;
|
|
|
|
Log.error("Check Duration = " + duration + " seconds");
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
if (error.hasError() == false) {
|
|
|
|
manageAllFiles(option, error);
|
2015-04-07 18:18:37 +00:00
|
|
|
}
|
|
|
|
forceQuit = true;
|
2010-11-15 20:35:36 +00:00
|
|
|
} else {
|
2017-03-12 17:22:02 +00:00
|
|
|
if (option.isSplash()) {
|
|
|
|
Splash.createSplash();
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
manageAllFiles(option, error);
|
2013-12-10 19:36:50 +00:00
|
|
|
forceQuit = true;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (option.isDuration()) {
|
2015-04-07 18:18:37 +00:00
|
|
|
final double duration = (System.currentTimeMillis() - start) / 1000.0;
|
|
|
|
Log.error("Duration = " + duration + " seconds");
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 18:34:41 +00:00
|
|
|
if (OptionFlags.getInstance().isGui() == false) {
|
2020-08-25 17:24:17 +00:00
|
|
|
if (error.hasError() || error.isNoData()) {
|
|
|
|
option.getStdrpt().finalMessage(error);
|
2021-04-02 17:26:59 +00:00
|
|
|
}
|
|
|
|
if (error.hasError()) {
|
2019-01-16 18:34:41 +00:00
|
|
|
System.exit(error.getExitCode());
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2019-01-16 18:34:41 +00:00
|
|
|
if (forceQuit && OptionFlags.getInstance().isSystemExit()) {
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
private static String commandLine = "";
|
|
|
|
|
|
|
|
public static final String getCommandLine() {
|
|
|
|
return commandLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void saveCommandLine(String[] argsArray) {
|
|
|
|
final StringBuilder sb = new StringBuilder();
|
|
|
|
for (String s : argsArray) {
|
|
|
|
sb.append(s);
|
|
|
|
sb.append(" ");
|
|
|
|
}
|
|
|
|
commandLine = sb.toString();
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:51:18 +00:00
|
|
|
public static void forceOpenJdkResourceLoad() {
|
2018-05-21 13:07:09 +00:00
|
|
|
if (isOpenJdkRunning()) {
|
|
|
|
// see https://github.com/plantuml/plantuml/issues/123
|
|
|
|
Log.info("Forcing resource load on OpenJdk");
|
|
|
|
final BufferedImage imDummy = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
|
|
|
|
final Graphics2D gg = imDummy.createGraphics();
|
|
|
|
final String text = "Alice";
|
|
|
|
final Font font = new Font("SansSerif", Font.PLAIN, 12);
|
|
|
|
final FontMetrics fm = gg.getFontMetrics(font);
|
|
|
|
final Rectangle2D rect = fm.getStringBounds(text, gg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isOpenJdkRunning() {
|
|
|
|
final String jvmName = System.getProperty("java.vm.name");
|
|
|
|
if (jvmName != null && jvmName.toLowerCase().contains("openjdk")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-09-29 19:51:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:56:46 +00:00
|
|
|
static private final String httpProtocol = "http://";
|
|
|
|
static private final String httpsProtocol = "https://";
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private static void encodeSprite(List<String> result) throws IOException {
|
|
|
|
SpriteGrayLevel level = SpriteGrayLevel.GRAY_16;
|
|
|
|
boolean compressed = false;
|
2018-07-27 21:56:46 +00:00
|
|
|
final String path;
|
2013-12-10 19:36:50 +00:00
|
|
|
if (result.size() > 1 && result.get(0).matches("(4|8|16)z?")) {
|
|
|
|
if (result.get(0).startsWith("8")) {
|
|
|
|
level = SpriteGrayLevel.GRAY_8;
|
|
|
|
}
|
|
|
|
if (result.get(0).startsWith("4")) {
|
|
|
|
level = SpriteGrayLevel.GRAY_4;
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
compressed = StringUtils.goLowerCase(result.get(0)).endsWith("z");
|
2018-07-27 21:56:46 +00:00
|
|
|
path = result.get(1);
|
|
|
|
} else {
|
|
|
|
path = result.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
final String fileName;
|
|
|
|
final URL source;
|
|
|
|
final String lowerPath = StringUtils.goLowerCase(path);
|
|
|
|
if (lowerPath.startsWith(httpProtocol) || lowerPath.startsWith(httpsProtocol)) {
|
2020-05-30 15:20:23 +00:00
|
|
|
source = new java.net.URL(path);
|
2018-07-27 21:56:46 +00:00
|
|
|
final String p = source.getPath();
|
|
|
|
fileName = p.substring(p.lastIndexOf('/') + 1, p.length());
|
2013-12-10 19:36:50 +00:00
|
|
|
} else {
|
2020-05-30 15:20:23 +00:00
|
|
|
final SFile f = new SFile(path);
|
2018-07-27 21:56:46 +00:00
|
|
|
source = f.toURI().toURL();
|
|
|
|
fileName = f.getName();
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2018-07-27 21:56:46 +00:00
|
|
|
|
2020-05-30 15:20:23 +00:00
|
|
|
if (source == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 21:56:46 +00:00
|
|
|
final BufferedImage im;
|
2021-09-10 14:52:29 +00:00
|
|
|
try (InputStream stream = source.openStream()) {
|
2021-10-27 13:36:42 +00:00
|
|
|
im = SImageIO.read(stream);
|
2018-07-27 21:56:46 +00:00
|
|
|
}
|
|
|
|
final String name = getSpriteName(fileName);
|
2020-03-18 10:50:02 +00:00
|
|
|
final String s = compressed ? SpriteUtils.encodeCompressed(im, name, level)
|
|
|
|
: SpriteUtils.encode(im, name, level);
|
2013-12-10 19:36:50 +00:00
|
|
|
System.out.println(s);
|
|
|
|
}
|
|
|
|
|
2018-07-27 21:56:46 +00:00
|
|
|
private static String getSpriteName(String fileName) {
|
|
|
|
final String s = getSpriteNameInternal(fileName);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (s.length() == 0) {
|
|
|
|
return "test";
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-07-27 21:56:46 +00:00
|
|
|
private static String getSpriteNameInternal(String fileName) {
|
2013-12-10 19:36:50 +00:00
|
|
|
final StringBuilder sb = new StringBuilder();
|
2018-07-27 21:56:46 +00:00
|
|
|
for (char c : fileName.toCharArray()) {
|
2013-12-10 19:36:50 +00:00
|
|
|
if (("" + c).matches("[\\p{L}0-9_]")) {
|
|
|
|
sb.append(c);
|
|
|
|
} else {
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb.toString();
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void goFtp(Option option) throws IOException {
|
|
|
|
final int ftpPort = option.getFtpPort();
|
|
|
|
System.err.println("ftpPort=" + ftpPort);
|
2017-04-05 17:37:42 +00:00
|
|
|
final FtpServer ftpServer = new FtpServer(ftpPort, option.getFileFormatOption().getFileFormat());
|
2011-08-08 17:48:29 +00:00
|
|
|
ftpServer.go();
|
|
|
|
}
|
|
|
|
|
2020-10-12 20:56:58 +00:00
|
|
|
private static void goPicoweb(Option option) throws IOException {
|
2021-02-12 06:19:03 +00:00
|
|
|
PicoWebServer.startServer(option.getPicowebPort(), option.getPicowebBindAddress());
|
2020-10-12 20:56:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 19:45:13 +00:00
|
|
|
public static void printFonts() {
|
2011-08-08 17:48:29 +00:00
|
|
|
final Font fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
|
|
|
for (Font f : fonts) {
|
2020-03-18 10:50:02 +00:00
|
|
|
System.out.println(
|
|
|
|
"f=" + f + "/" + f.getPSName() + "/" + f.getName() + "/" + f.getFontName() + "/" + f.getFamily());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
final String name[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
|
|
|
for (String n : name) {
|
|
|
|
System.out.println("n=" + n);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 11:11:40 +00:00
|
|
|
private static void managePipe(Option option, ErrorStatus error) throws IOException {
|
2010-11-15 20:35:36 +00:00
|
|
|
final String charset = option.getCharset();
|
2018-12-22 11:11:40 +00:00
|
|
|
new Pipe(option, System.out, System.in, charset).managePipe(error);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 15:20:23 +00:00
|
|
|
private static void manageAllFiles(Option option, ErrorStatus error)
|
|
|
|
throws NoPlantumlCompressionException, InterruptedException {
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2020-05-30 15:20:23 +00:00
|
|
|
SFile lockFile = null;
|
2010-11-15 20:35:36 +00:00
|
|
|
try {
|
|
|
|
if (OptionFlags.getInstance().isWord()) {
|
2020-05-30 15:20:23 +00:00
|
|
|
final SFile dir = new SFile(option.getResult().get(0));
|
|
|
|
final SFile javaIsRunningFile = dir.file("javaisrunning.tmp");
|
2010-11-15 20:35:36 +00:00
|
|
|
javaIsRunningFile.delete();
|
2020-05-30 15:20:23 +00:00
|
|
|
lockFile = dir.file("javaumllock.tmp");
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
processArgs(option, error);
|
2010-11-15 20:35:36 +00:00
|
|
|
} finally {
|
|
|
|
if (lockFile != null) {
|
|
|
|
lockFile.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-30 15:20:23 +00:00
|
|
|
private static void processArgs(Option option, ErrorStatus error)
|
|
|
|
throws NoPlantumlCompressionException, InterruptedException {
|
2017-03-12 17:22:02 +00:00
|
|
|
if (option.isDecodeurl() == false && option.getNbThreads() > 1 && option.isCheckOnly() == false
|
2017-04-19 18:30:16 +00:00
|
|
|
&& OptionFlags.getInstance().isExtractFromMetadata() == false) {
|
2018-12-22 11:11:40 +00:00
|
|
|
multithread(option, error);
|
|
|
|
return;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2021-05-14 08:42:57 +00:00
|
|
|
final List<File> files = new ArrayList<>();
|
2010-11-15 20:35:36 +00:00
|
|
|
for (String s : option.getResult()) {
|
|
|
|
if (option.isDecodeurl()) {
|
2019-06-26 19:24:49 +00:00
|
|
|
error.goOk();
|
2011-01-05 18:23:06 +00:00
|
|
|
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
|
2010-11-15 20:35:36 +00:00
|
|
|
System.out.println("@startuml");
|
|
|
|
System.out.println(transcoder.decode(s));
|
|
|
|
System.out.println("@enduml");
|
|
|
|
} else {
|
|
|
|
final FileGroup group = new FileGroup(s, option.getExcludes(), option);
|
2017-03-12 17:22:02 +00:00
|
|
|
incTotal(group.getFiles().size());
|
|
|
|
files.addAll(group.getFiles());
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
foundNbFiles(files.size());
|
2017-03-12 17:22:02 +00:00
|
|
|
for (File f : files) {
|
|
|
|
try {
|
2018-12-22 11:11:40 +00:00
|
|
|
manageFileInternal(f, option, error);
|
|
|
|
incDone(error.hasError());
|
|
|
|
if (error.hasError() && option.isFailfastOrFailfast2()) {
|
|
|
|
return;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2017-03-12 17:22:02 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-22 11:11:40 +00:00
|
|
|
private static void multithread(final Option option, final ErrorStatus error) throws InterruptedException {
|
2011-08-08 17:48:29 +00:00
|
|
|
Log.info("Using several threads: " + option.getNbThreads());
|
|
|
|
final ExecutorService executor = Executors.newFixedThreadPool(option.getNbThreads());
|
2018-12-22 11:11:40 +00:00
|
|
|
|
|
|
|
int nb = 0;
|
2011-08-08 17:48:29 +00:00
|
|
|
for (String s : option.getResult()) {
|
|
|
|
final FileGroup group = new FileGroup(s, option.getExcludes(), option);
|
|
|
|
for (final File f : group.getFiles()) {
|
2017-03-12 17:22:02 +00:00
|
|
|
incTotal(1);
|
2018-12-22 11:11:40 +00:00
|
|
|
nb++;
|
2013-12-10 19:36:50 +00:00
|
|
|
executor.submit(new Runnable() {
|
2011-08-08 17:48:29 +00:00
|
|
|
public void run() {
|
2018-12-22 11:11:40 +00:00
|
|
|
if (error.hasError() && option.isFailfastOrFailfast2()) {
|
2011-08-08 17:48:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2018-12-22 11:11:40 +00:00
|
|
|
manageFileInternal(f, option, error);
|
2011-08-08 17:48:29 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
incDone(error.hasError());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
foundNbFiles(nb);
|
2011-08-08 17:48:29 +00:00
|
|
|
executor.shutdown();
|
|
|
|
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
2018-12-22 11:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void foundNbFiles(int nb) {
|
|
|
|
Log.info("Found " + nb + " files");
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 17:22:02 +00:00
|
|
|
private static void incDone(boolean error) {
|
|
|
|
Splash.incDone(error);
|
|
|
|
ProgressBar.incDone(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void incTotal(int nb) {
|
|
|
|
Splash.incTotal(nb);
|
|
|
|
ProgressBar.incTotal(nb);
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private static void manageFileInternal(File f, Option option, ErrorStatus error)
|
|
|
|
throws IOException, InterruptedException {
|
2020-05-30 15:20:23 +00:00
|
|
|
Log.info("Working on " + f.getPath());
|
2017-04-19 18:30:16 +00:00
|
|
|
if (OptionFlags.getInstance().isExtractFromMetadata()) {
|
2011-08-08 17:48:29 +00:00
|
|
|
System.out.println("------------------------");
|
|
|
|
System.out.println(f);
|
|
|
|
// new Metadata().readAndDisplayMetadata(f);
|
|
|
|
System.out.println();
|
2019-06-26 19:24:49 +00:00
|
|
|
error.goOk();
|
2018-10-21 19:44:14 +00:00
|
|
|
final String data = new MetadataTag(f, "plantuml").getData();
|
2020-05-30 15:20:23 +00:00
|
|
|
// File file = SecurityUtils.File("tmp.txt");
|
|
|
|
// PrintWriter pw = SecurityUtils.PrintWriter(file, "UTF-8");
|
2018-10-21 19:44:14 +00:00
|
|
|
// pw.println(NastyEncoder.fromISO_8859_1(data));
|
|
|
|
// pw.close();
|
|
|
|
|
|
|
|
System.out.println(data);
|
2011-08-08 17:48:29 +00:00
|
|
|
System.out.println("------------------------");
|
2018-12-22 11:11:40 +00:00
|
|
|
return;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
final ISourceFileReader sourceFileReader;
|
|
|
|
if (option.getOutputFile() == null) {
|
2019-08-26 17:07:21 +00:00
|
|
|
File outputDir = option.getOutputDir();
|
|
|
|
if (outputDir != null && outputDir.getPath().endsWith("$")) {
|
|
|
|
final String path = outputDir.getPath();
|
|
|
|
outputDir = new File(path.substring(0, path.length() - 1)).getAbsoluteFile();
|
|
|
|
sourceFileReader = new SourceFileReaderCopyCat(option.getDefaultDefines(f), f, outputDir,
|
|
|
|
option.getConfig(), option.getCharset(), option.getFileFormatOption());
|
|
|
|
} else {
|
2020-06-07 10:03:18 +00:00
|
|
|
sourceFileReader = new SourceFileReader(option.getDefaultDefines(f), f, outputDir, option.getConfig(),
|
2019-08-26 17:07:21 +00:00
|
|
|
option.getCharset(), option.getFileFormatOption());
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
} else {
|
2019-08-26 17:07:21 +00:00
|
|
|
sourceFileReader = new SourceFileReaderHardFile(option.getDefaultDefines(f), f, option.getOutputFile(),
|
2013-12-10 19:36:50 +00:00
|
|
|
option.getConfig(), option.getCharset(), option.getFileFormatOption());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2018-05-01 17:26:04 +00:00
|
|
|
sourceFileReader.setCheckMetadata(option.isCheckMetadata());
|
2021-06-27 16:50:40 +00:00
|
|
|
((SourceFileReaderAbstract) sourceFileReader).setNoerror(option.isNoerror());
|
2018-07-27 21:56:46 +00:00
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
if (option.isComputeurl()) {
|
2019-06-26 19:24:49 +00:00
|
|
|
error.goOk();
|
2017-06-05 11:27:21 +00:00
|
|
|
for (BlockUml s : sourceFileReader.getBlocks()) {
|
|
|
|
System.out.println(s.getEncodedUrl());
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
return;
|
2015-04-07 18:18:37 +00:00
|
|
|
}
|
|
|
|
if (option.isCheckOnly()) {
|
2019-06-26 19:24:49 +00:00
|
|
|
error.goOk();
|
2015-04-07 18:18:37 +00:00
|
|
|
final boolean hasError = sourceFileReader.hasError();
|
2018-12-22 11:11:40 +00:00
|
|
|
if (hasError) {
|
|
|
|
error.goWithError();
|
|
|
|
}
|
|
|
|
// final List<GeneratedImage> result = sourceFileReader.getGeneratedImages();
|
|
|
|
// hasErrors(f, result, error);
|
|
|
|
return;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
2018-07-27 21:56:46 +00:00
|
|
|
if (option.getPreprocessorOutputMode() != null) {
|
|
|
|
extractPreproc(option, sourceFileReader);
|
2018-12-22 11:11:40 +00:00
|
|
|
error.goOk();
|
|
|
|
return;
|
2018-07-27 21:56:46 +00:00
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
final List<GeneratedImage> result = sourceFileReader.getGeneratedImages();
|
2018-12-22 11:11:40 +00:00
|
|
|
final Stdrpt rpt = option.getStdrpt();
|
2018-11-26 18:46:22 +00:00
|
|
|
if (result.size() == 0) {
|
2020-05-30 15:20:23 +00:00
|
|
|
Log.error("Warning: no image in " + f.getPath());
|
2018-12-22 11:11:40 +00:00
|
|
|
rpt.printInfo(System.err, null);
|
|
|
|
// error.goNoData();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (BlockUml s : sourceFileReader.getBlocks()) {
|
|
|
|
rpt.printInfo(System.err, s.getDiagram());
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
2018-07-27 21:56:46 +00:00
|
|
|
|
2020-08-25 17:24:17 +00:00
|
|
|
hasErrors(f, result, error, rpt);
|
2015-04-07 18:18:37 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:56:46 +00:00
|
|
|
private static void extractPreproc(Option option, final ISourceFileReader sourceFileReader) throws IOException {
|
|
|
|
final String charset = option.getCharset();
|
|
|
|
for (BlockUml blockUml : sourceFileReader.getBlocks()) {
|
|
|
|
final SuggestedFile suggested = ((SourceFileReaderAbstract) sourceFileReader).getSuggestedFile(blockUml)
|
|
|
|
.withPreprocFormat();
|
2020-05-30 15:20:23 +00:00
|
|
|
final SFile file = suggested.getFile(0);
|
|
|
|
Log.info("Export preprocessing source to " + file.getPrintablePath());
|
2021-09-10 14:52:29 +00:00
|
|
|
try (final PrintWriter pw = charset == null ? file.createPrintWriter() : file.createPrintWriter(charset)) {
|
|
|
|
int level = 0;
|
|
|
|
for (CharSequence cs : blockUml.getDefinition(true)) {
|
|
|
|
String s = cs.toString();
|
|
|
|
if (cypher != null) {
|
|
|
|
if (s.contains("skinparam") && s.contains("{")) {
|
|
|
|
level++;
|
|
|
|
}
|
|
|
|
if (level == 0 && s.contains("skinparam") == false) {
|
|
|
|
s = cypher.cypher(s);
|
|
|
|
}
|
|
|
|
if (level > 0 && s.contains("}")) {
|
|
|
|
level--;
|
|
|
|
}
|
2020-03-18 10:50:02 +00:00
|
|
|
}
|
2021-09-10 14:52:29 +00:00
|
|
|
pw.println(s);
|
2018-07-27 21:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:24:17 +00:00
|
|
|
private static void hasErrors(File file, final List<GeneratedImage> list, ErrorStatus error, Stdrpt stdrpt)
|
|
|
|
throws IOException {
|
2018-12-22 11:11:40 +00:00
|
|
|
if (list.size() == 0) {
|
|
|
|
// error.goNoData();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-25 17:24:17 +00:00
|
|
|
for (GeneratedImage image : list) {
|
|
|
|
final int lineError = image.lineErrorRaw();
|
2015-04-07 18:18:37 +00:00
|
|
|
if (lineError != -1) {
|
2020-08-25 17:24:17 +00:00
|
|
|
stdrpt.errorLine(lineError, file);
|
2018-12-22 11:11:40 +00:00
|
|
|
error.goWithError();
|
|
|
|
return;
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
error.goOk();
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 17:39:20 +00:00
|
|
|
// public static void debugGantt() {
|
|
|
|
// final Locale locale = Locale.GERMAN;
|
|
|
|
// for (java.time.Month month : java.time.Month.values()) {
|
|
|
|
// System.err.println("Testing locale " + locale + " " + month);
|
|
|
|
// for (TextStyle style : TextStyle.values()) {
|
|
|
|
// final String s = month.getDisplayName(style, locale);
|
|
|
|
// System.err.println(style + " --> '" + s + "'");
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2021-07-25 10:41:36 +00:00
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|