1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 10:20:54 +00:00
plantuml/src/net/sourceforge/plantuml/PSystemBuilder.java

261 lines
11 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;
import java.util.ArrayList;
2017-03-15 19:13:31 +00:00
import java.util.Collections;
2010-11-15 20:35:36 +00:00
import java.util.List;
2022-09-20 20:35:41 +00:00
import java.util.Map;
2010-11-15 20:35:36 +00:00
2011-09-07 20:41:58 +00:00
import net.sourceforge.plantuml.acearth.PSystemXearthFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.ActivityDiagramFactory3;
import net.sourceforge.plantuml.api.PSystemFactory;
2020-12-19 21:21:54 +00:00
import net.sourceforge.plantuml.board.BoardDiagramFactory;
2017-03-21 21:37:59 +00:00
import net.sourceforge.plantuml.bpm.BpmDiagramFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.command.regex.RegexConcat;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
2020-05-17 21:15:50 +00:00
import net.sourceforge.plantuml.creole.legacy.PSystemCreoleFactory;
2016-04-22 20:36:08 +00:00
import net.sourceforge.plantuml.dedication.PSystemDedicationFactory;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.definition.PSystemDefinitionFactory;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.descdiagram.DescriptionDiagramFactory;
2011-04-19 16:50:40 +00:00
import net.sourceforge.plantuml.directdot.PSystemDotFactory;
import net.sourceforge.plantuml.ditaa.PSystemDitaaFactory;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.donors.PSystemDonorsFactory;
2017-11-20 16:10:36 +00:00
import net.sourceforge.plantuml.donors.PSystemSkinparameterListFactory;
2022-09-23 16:53:33 +00:00
import net.sourceforge.plantuml.ebnf.PSystemEbnfFactory;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.eggs.PSystemAppleTwoFactory;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.eggs.PSystemCharlieFactory;
2017-03-12 17:22:02 +00:00
import net.sourceforge.plantuml.eggs.PSystemColorsFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.eggs.PSystemEggFactory;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.eggs.PSystemPathFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.eggs.PSystemRIPFactory;
2017-03-21 21:37:59 +00:00
import net.sourceforge.plantuml.eggs.PSystemWelcomeFactory;
2021-12-07 18:15:43 +00:00
import net.sourceforge.plantuml.emoji.PSystemListEmojiFactory;
2019-05-24 19:59:31 +00:00
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.error.PSystemErrorUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.flowdiagram.FlowDiagramFactory;
import net.sourceforge.plantuml.font.PSystemListFontsFactory;
2020-12-06 21:43:09 +00:00
import net.sourceforge.plantuml.gitlog.GitDiagramFactory;
2022-01-28 21:45:34 +00:00
import net.sourceforge.plantuml.hcl.HclDiagramFactory;
2019-03-01 22:16:29 +00:00
import net.sourceforge.plantuml.help.HelpFactory;
2020-04-05 15:13:04 +00:00
import net.sourceforge.plantuml.jcckit.PSystemJcckitFactory;
2020-11-21 17:33:24 +00:00
import net.sourceforge.plantuml.jsondiagram.JsonDiagramFactory;
2016-12-14 21:01:03 +00:00
import net.sourceforge.plantuml.math.PSystemLatexFactory;
2016-11-18 21:12:09 +00:00
import net.sourceforge.plantuml.math.PSystemMathFactory;
2019-03-01 22:16:29 +00:00
import net.sourceforge.plantuml.mindmap.MindMapDiagramFactory;
2018-11-26 18:46:22 +00:00
import net.sourceforge.plantuml.nwdiag.NwDiagramFactory;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.openiconic.PSystemListOpenIconicFactory;
import net.sourceforge.plantuml.openiconic.PSystemOpenIconicFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.oregon.PSystemOregonFactory;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.project.GanttDiagramFactory;
2022-12-13 17:30:41 +00:00
import net.sourceforge.plantuml.regex.PSystemRegexFactory;
2020-09-30 20:57:58 +00:00
import net.sourceforge.plantuml.salt.PSystemSaltFactory2;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SecurityProfile;
import net.sourceforge.plantuml.security.SecurityUtils;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.sprite.ListSpriteDiagramFactory;
import net.sourceforge.plantuml.sprite.PSystemListInternalSpritesFactory;
2020-04-05 15:13:04 +00:00
import net.sourceforge.plantuml.sprite.StdlibDiagramFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.statediagram.StateDiagramFactory;
2016-12-01 20:29:25 +00:00
import net.sourceforge.plantuml.stats.StatsUtilsIncrement;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sudoku.PSystemSudokuFactory;
2017-02-01 18:55:51 +00:00
import net.sourceforge.plantuml.timingdiagram.TimingDiagramFactory;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.Log;
import net.sourceforge.plantuml.utils.StringLocated;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.version.License;
import net.sourceforge.plantuml.version.PSystemLicenseFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.version.PSystemVersionFactory;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.wbs.WBSDiagramFactory;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.wire.WireDiagramFactory;
2021-01-10 20:52:19 +00:00
import net.sourceforge.plantuml.yaml.YamlDiagramFactory;
2010-11-15 20:35:36 +00:00
public class PSystemBuilder {
2015-04-07 18:18:37 +00:00
public static final long startTime = System.currentTimeMillis();
2022-09-23 16:53:33 +00:00
final public Diagram createPSystem(List<StringLocated> source, List<StringLocated> rawSource,
Map<String, String> skinParam) {
2010-11-15 20:35:36 +00:00
2016-11-18 21:12:09 +00:00
final long now = System.currentTimeMillis();
2017-03-15 19:13:31 +00:00
2016-11-18 21:12:09 +00:00
Diagram result = null;
try {
2020-05-17 21:15:50 +00:00
final DiagramType type = DiagramType.getTypeFromArobaseStart(source.get(0).getString());
2022-03-19 12:48:23 +00:00
final UmlSource umlSource = UmlSource.createWithRaw(source, type == DiagramType.UML, rawSource);
2017-03-15 19:13:31 +00:00
2020-05-17 21:15:50 +00:00
for (StringLocated s : source) {
2017-03-15 19:13:31 +00:00
if (s.getPreprocessorError() != null) {
2019-05-24 19:59:31 +00:00
// Dead code : should not append
2020-05-17 21:15:50 +00:00
assert false;
2017-04-19 18:30:16 +00:00
Log.error("Preprocessor Error: " + s.getPreprocessorError());
2021-02-02 10:12:15 +00:00
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, s.getPreprocessorError(), 0,
2020-04-05 15:13:04 +00:00
s.getLocation());
2020-05-17 21:15:50 +00:00
return PSystemErrorUtils.buildV2(umlSource, err, Collections.<String>emptyList(), source);
2017-03-15 19:13:31 +00:00
}
}
2016-11-18 21:12:09 +00:00
final DiagramType diagramType = umlSource.getDiagramType();
2021-05-14 08:42:57 +00:00
final List<PSystemError> errors = new ArrayList<>();
2016-11-18 21:12:09 +00:00
for (PSystemFactory systemFactory : factories) {
2022-02-10 18:16:18 +00:00
if (diagramType != systemFactory.getDiagramType())
2016-11-18 21:12:09 +00:00
continue;
2022-02-10 18:16:18 +00:00
2022-09-18 17:08:06 +00:00
final Diagram sys = systemFactory.createSystem(umlSource, skinParam);
2016-11-18 21:12:09 +00:00
if (isOk(sys)) {
result = sys;
return sys;
}
errors.add((PSystemError) sys);
2011-08-08 17:48:29 +00:00
}
2016-11-18 21:12:09 +00:00
2022-02-10 18:16:18 +00:00
result = PSystemErrorUtils.merge(errors);
return result;
2016-11-18 21:12:09 +00:00
} finally {
// ::comment when WASM
2016-12-14 21:01:03 +00:00
if (result != null && OptionFlags.getInstance().isEnableStats()) {
2016-12-01 20:29:25 +00:00
StatsUtilsIncrement.onceMoreParse(System.currentTimeMillis() - now, result.getClass());
2011-08-08 17:48:29 +00:00
}
2019-06-26 19:24:49 +00:00
Log.info("Compilation duration " + (System.currentTimeMillis() - now));
RegexConcat.printCacheInfo();
// ::done
2011-08-08 17:48:29 +00:00
}
}
2021-05-23 15:35:13 +00:00
private static final List<PSystemFactory> factories = new ArrayList<>();
static {
2017-03-15 19:13:31 +00:00
factories.add(new PSystemWelcomeFactory());
2017-03-12 17:22:02 +00:00
factories.add(new PSystemColorsFactory());
2021-05-23 15:35:13 +00:00
factories.add(new SequenceDiagramFactory());
factories.add(new ClassDiagramFactory());
factories.add(new ActivityDiagramFactory());
factories.add(new DescriptionDiagramFactory());
factories.add(new StateDiagramFactory());
factories.add(new ActivityDiagramFactory3());
2019-09-14 18:12:04 +00:00
// factories.add(new CompositeDiagramFactory(skinParam));
2017-03-21 21:37:59 +00:00
factories.add(new BpmDiagramFactory(DiagramType.BPM));
2019-03-29 22:14:07 +00:00
// factories.add(new PostIdDiagramFactory());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemLicenseFactory());
2010-11-15 20:35:36 +00:00
factories.add(new PSystemVersionFactory());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemDonorsFactory());
2017-11-20 16:10:36 +00:00
factories.add(new PSystemSkinparameterListFactory());
// ::comment when WASM
2013-12-10 19:36:50 +00:00
factories.add(new PSystemListFontsFactory());
// ::done
2021-12-06 18:58:08 +00:00
factories.add(new PSystemListEmojiFactory());
// ::comment when WASM
2015-04-07 18:18:37 +00:00
factories.add(new PSystemOpenIconicFactory());
factories.add(new PSystemListOpenIconicFactory());
2016-01-30 12:20:07 +00:00
factories.add(new PSystemListInternalSpritesFactory());
// ::done
2020-09-30 20:57:58 +00:00
factories.add(new PSystemSaltFactory2(DiagramType.SALT));
factories.add(new PSystemSaltFactory2(DiagramType.UML));
// ::comment when WASM
2011-04-19 16:50:40 +00:00
factories.add(new PSystemDotFactory(DiagramType.DOT));
factories.add(new PSystemDotFactory(DiagramType.UML));
// ::done
2021-05-23 15:35:13 +00:00
factories.add(new NwDiagramFactory(DiagramType.NW));
factories.add(new NwDiagramFactory(DiagramType.UML));
2019-03-01 22:16:29 +00:00
factories.add(new MindMapDiagramFactory());
2019-03-29 22:14:07 +00:00
factories.add(new WBSDiagramFactory());
// ::comment when WASM
2019-03-29 22:14:07 +00:00
factories.add(new PSystemDitaaFactory(DiagramType.DITAA));
factories.add(new PSystemDitaaFactory(DiagramType.UML));
// ::done
2016-07-04 19:06:50 +00:00
if (License.getCurrent() == License.GPL || License.getCurrent() == License.GPLV2) {
// ::comment when WASM
2020-04-05 15:13:04 +00:00
factories.add(new PSystemJcckitFactory(DiagramType.JCCKIT));
factories.add(new PSystemJcckitFactory(DiagramType.UML));
// ::done
2019-03-29 22:14:07 +00:00
// factories.add(new PSystemLogoFactory());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemSudokuFactory());
}
// ::comment when WASM
2017-04-05 17:37:42 +00:00
factories.add(new PSystemDefinitionFactory());
// ::done
2021-05-23 15:35:13 +00:00
factories.add(new ListSpriteDiagramFactory());
// ::comment when WASM
2021-05-23 15:35:13 +00:00
factories.add(new StdlibDiagramFactory());
2016-11-18 21:12:09 +00:00
factories.add(new PSystemMathFactory(DiagramType.MATH));
2016-12-14 21:01:03 +00:00
factories.add(new PSystemLatexFactory(DiagramType.LATEX));
// ::done
2016-12-01 20:29:25 +00:00
// factories.add(new PSystemStatsFactory());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemCreoleFactory());
2010-11-15 20:35:36 +00:00
factories.add(new PSystemEggFactory());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemAppleTwoFactory());
2010-11-15 20:35:36 +00:00
factories.add(new PSystemRIPFactory());
2019-03-29 22:14:07 +00:00
// factories.add(new PSystemLostFactory());
// ::comment when WASM
if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE)
2020-05-30 15:20:23 +00:00
factories.add(new PSystemPathFactory());
// ::done
2010-11-15 20:35:36 +00:00
factories.add(new PSystemOregonFactory());
2015-04-07 18:18:37 +00:00
factories.add(new PSystemCharlieFactory());
// ::comment when WASM
2016-07-04 19:06:50 +00:00
if (License.getCurrent() == License.GPL || License.getCurrent() == License.GPLV2) {
2013-12-10 19:36:50 +00:00
factories.add(new PSystemXearthFactory());
}
// ::done
2022-12-16 16:20:14 +00:00
factories.add(new GanttDiagramFactory());
2013-12-10 19:36:50 +00:00
factories.add(new FlowDiagramFactory());
2019-03-29 22:14:07 +00:00
// factories.add(new PSystemTreeFactory(DiagramType.JUNGLE));
// factories.add(new PSystemCuteFactory(DiagramType.CUTE));
2016-04-22 20:36:08 +00:00
factories.add(new PSystemDedicationFactory());
2017-02-01 18:55:51 +00:00
factories.add(new TimingDiagramFactory());
2019-03-01 22:16:29 +00:00
factories.add(new HelpFactory());
2020-02-18 21:24:31 +00:00
factories.add(new WireDiagramFactory());
2020-11-21 17:33:24 +00:00
factories.add(new JsonDiagramFactory());
2020-12-06 21:43:09 +00:00
factories.add(new GitDiagramFactory());
2020-12-19 21:21:54 +00:00
factories.add(new BoardDiagramFactory());
2021-01-10 20:52:19 +00:00
factories.add(new YamlDiagramFactory());
2022-01-28 21:45:34 +00:00
factories.add(new HclDiagramFactory());
2022-09-23 16:53:33 +00:00
factories.add(new PSystemEbnfFactory());
2022-12-13 17:30:41 +00:00
factories.add(new PSystemRegexFactory());
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private boolean isOk(Diagram ps) {
2022-02-10 18:16:18 +00:00
if (ps == null || ps instanceof PSystemError)
2010-11-15 20:35:36 +00:00
return false;
2022-02-10 18:16:18 +00:00
2010-11-15 20:35:36 +00:00
return true;
}
}