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

217 lines
9.4 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, 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;
2019-07-14 20:09:26 +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
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;
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-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.command.UmlDiagramFactory;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.command.regex.RegexConcat;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.compositediagram.CompositeDiagramFactory;
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;
import net.sourceforge.plantuml.creole.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;
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;
import net.sourceforge.plantuml.eggs.PSystemRIPFactory;
2017-03-21 21:37:59 +00:00
import net.sourceforge.plantuml.eggs.PSystemWelcomeFactory;
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;
2019-03-01 22:16:29 +00:00
import net.sourceforge.plantuml.help.HelpFactory;
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;
2017-02-01 18:55:51 +00:00
import net.sourceforge.plantuml.project3.GanttDiagramFactory;
2011-09-07 20:41:58 +00:00
import net.sourceforge.plantuml.salt.PSystemSaltFactory;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
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;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.ugraphic.sprite.PSystemListInternalSpritesFactory;
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;
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();
2019-03-29 22:14:07 +00:00
final public Diagram createPSystem(ISkinSimple skinParam, final List<StringLocated> strings2) {
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 {
2019-03-29 22:14:07 +00:00
final DiagramType type = DiagramType.getTypeFromArobaseStart(strings2.get(0).getString());
2018-09-23 12:15:14 +00:00
final UmlSource umlSource = new UmlSource(strings2, type == DiagramType.UML);
2017-03-15 19:13:31 +00:00
2019-03-29 22:14:07 +00:00
for (StringLocated s : strings2) {
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
2017-04-19 18:30:16 +00:00
Log.error("Preprocessor Error: " + s.getPreprocessorError());
2017-06-05 11:27:21 +00:00
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, s.getPreprocessorError(), /* cpt */
s.getLocation());
2019-05-24 19:59:31 +00:00
// return PSystemErrorUtils.buildV1(umlSource, err, Collections.<String> emptyList());
return PSystemErrorUtils.buildV2(umlSource, err, Collections.<String> emptyList(), strings2);
2017-03-15 19:13:31 +00:00
}
}
2016-11-18 21:12:09 +00:00
final DiagramType diagramType = umlSource.getDiagramType();
final List<PSystemError> errors = new ArrayList<PSystemError>();
2019-03-01 22:16:29 +00:00
final List<PSystemFactory> factories = getAllFactories(skinParam);
2016-11-18 21:12:09 +00:00
for (PSystemFactory systemFactory : factories) {
if (diagramType != systemFactory.getDiagramType()) {
continue;
}
final Diagram sys = systemFactory.createSystem(umlSource);
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
2019-05-24 19:59:31 +00:00
final PSystemError err = PSystemErrorUtils.merge(errors);
2016-11-18 21:12:09 +00:00
result = err;
return err;
} finally {
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();
2011-08-08 17:48:29 +00:00
}
}
2019-07-14 20:09:26 +00:00
private static List<PSystemFactory> getAllFactories(ISkinSimple skinParam) {
2010-11-15 20:35:36 +00:00
final List<PSystemFactory> factories = new ArrayList<PSystemFactory>();
2017-03-15 19:13:31 +00:00
factories.add(new PSystemWelcomeFactory());
2017-03-12 17:22:02 +00:00
factories.add(new PSystemColorsFactory());
2019-03-01 22:16:29 +00:00
factories.add(new SequenceDiagramFactory(skinParam));
2019-06-26 19:24:49 +00:00
factories.add(new ClassDiagramFactory(skinParam));
factories.add(new ActivityDiagramFactory(skinParam));
factories.add(new DescriptionDiagramFactory(skinParam));
factories.add(new StateDiagramFactory(skinParam));
factories.add(new ActivityDiagramFactory3(skinParam));
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());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemListFontsFactory());
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());
2011-09-07 20:41:58 +00:00
factories.add(new PSystemSaltFactory(DiagramType.SALT));
factories.add(new PSystemSaltFactory(DiagramType.UML));
2011-04-19 16:50:40 +00:00
factories.add(new PSystemDotFactory(DiagramType.DOT));
factories.add(new PSystemDotFactory(DiagramType.UML));
2018-11-26 18:46:22 +00:00
factories.add(new NwDiagramFactory());
2019-03-01 22:16:29 +00:00
factories.add(new MindMapDiagramFactory());
2019-03-29 22:14:07 +00:00
factories.add(new WBSDiagramFactory());
factories.add(new PSystemDitaaFactory(DiagramType.DITAA));
factories.add(new PSystemDitaaFactory(DiagramType.UML));
2016-07-04 19:06:50 +00:00
if (License.getCurrent() == License.GPL || License.getCurrent() == License.GPLV2) {
2019-07-14 20:09:26 +00:00
// factories.add(new PSystemJcckitFactory(DiagramType.JCCKIT));
// factories.add(new PSystemJcckitFactory(DiagramType.UML));
2019-03-29 22:14:07 +00:00
// factories.add(new PSystemLogoFactory());
2013-12-10 19:36:50 +00:00
factories.add(new PSystemSudokuFactory());
}
2017-04-05 17:37:42 +00:00
factories.add(new PSystemDefinitionFactory());
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));
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());
// factories.add(new PSystemPathFactory());
2010-11-15 20:35:36 +00:00
factories.add(new PSystemOregonFactory());
2015-04-07 18:18:37 +00:00
factories.add(new PSystemCharlieFactory());
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());
}
2017-11-20 16:10:36 +00:00
factories.add(new GanttDiagramFactory(DiagramType.GANTT));
factories.add(new GanttDiagramFactory(DiagramType.UML));
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());
2011-08-08 17:48:29 +00:00
return factories;
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private boolean isOk(Diagram ps) {
2010-11-15 20:35:36 +00:00
if (ps == null || ps instanceof PSystemError) {
return false;
}
return true;
}
}