Skip to content

Experimental feature: Create smaller UMLDoclet.jar by filtering PlantUML resources #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<!-- Artifact identification -->
<groupId>nl.talsmasoftware</groupId>
<artifactId>umldoclet</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1-smaller-SNAPSHOT</version>
<packaging>jar</packaging>

<!-- Project information -->
Expand Down Expand Up @@ -127,12 +127,25 @@
<filter>
<artifact>*:*</artifact>
<excludes>
<!-- TODO exclude more unused packages and resources to save space. -->
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>**/plantuml/bpm/**.*</exclude>
<exclude>**/plantuml/dedication/**.*</exclude>
<exclude>**/plantuml/directdot/**.*</exclude>
<exclude>**/plantuml/eggs/**.*</exclude>
<exclude>**/plantuml/math/**.*</exclude>
<exclude>**/plantuml/mindmap/**.*</exclude>
<exclude>**/plantuml/nwdiag/**.*</exclude>
<exclude>**/plantuml/openiconic/**.*</exclude>
<exclude>**/plantuml/salt/**.*</exclude>
<exclude>**/plantuml/wbs/**.*</exclude>
<exclude>**/plantuml/windowsdot/**.*</exclude>
<exclude>sprites/archimate/**.*</exclude>
<exclude>stdlib/**.*</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
<!-- TODO exclude unused packages and resources to save space. -->
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -205,6 +218,7 @@
<exclude>**/*.md</exclude>
<exclude>**/*.puml</exclude>
<exclude>**/*.svg</exclude>
<exclude>**/net/sourceforge/plantuml/**.*</exclude>
</excludes>
<strictCheck>true</strictCheck>
</configuration>
Expand Down
301 changes: 301 additions & 0 deletions src/main/java/net/sourceforge/plantuml/PSystemBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
/* +=======================================================================
* |
* | PlantUML : a free UML diagram generator
* |
* +=======================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/liberapay (only 1€ per month!)
* https://plantuml.com/paypal
*
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the Apache Software License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PlantUML can occasionally display sponsored or advertising messages. Those
* messages are usually generated on welcome or error images and never on
* functional diagrams.
* See https://plantuml.com/professional if you want to remove them
*
* Images (whatever their format : PNG, SVG, EPS...) generated by running PlantUML
* are owned by the author of their corresponding sources code (that is, their
* textual description in PlantUML language). Those images are not covered by
* this APACHE license.
*
* The generated images can then be used without any reference to the APACHE license.
* It is not even necessary to stipulate that they have been generated with PlantUML,
* although this will be appreciated by the PlantUML team.
*
* There is an exception : if the textual description in PlantUML language is also covered
* by any license, then the generated images are logically covered
* by the very same license.
*
* This is the IGY distribution (Install GraphViz by Yourself).
* You have to install GraphViz and to setup the GRAPHVIZ_DOT environment variable
* (see https://plantuml.com/graphviz-dot )
*
* Icons provided by OpenIconic : https://useiconic.com/open
* Archimate sprites provided by Archi : http://www.archimatetool.com
* Stdlib AWS provided by https://github.com/milo-minderbinder/AWS-PlantUML
* Stdlib Icons provided https://github.com/tupadr3/plantuml-icon-font-sprites
* ASCIIMathML (c) Peter Jipsen http://www.chapman.edu/~jipsen
* ASCIIMathML (c) David Lippman http://www.pierce.ctc.edu/dlippman
* CafeUndZopfli ported by Eugene Klyuchnikov https://github.com/eustas/CafeUndZopfli
* Brotli (c) by the Brotli Authors https://github.com/google/brotli
* Themes (c) by Brett Schwarz https://github.com/bschwarz/puml-themes
* Twemoji (c) by Twitter at https://twemoji.twitter.com/
*
*/
package net.sourceforge.plantuml;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.plantuml.api.cheerpj.WasmLog;

import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory;
import net.sourceforge.plantuml.activitydiagram3.ActivityDiagramFactory3;
import net.sourceforge.plantuml.api.PSystemFactory;
import net.sourceforge.plantuml.board.BoardDiagramFactory;
import net.sourceforge.plantuml.bpm.BpmDiagramFactory;
import net.sourceforge.plantuml.cheneer.ChenEerDiagramFactory;
import net.sourceforge.plantuml.chronology.ChronologyDiagramFactory;
import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.dedication.PSystemDedicationFactory;
import net.sourceforge.plantuml.definition.PSystemDefinitionFactory;
import net.sourceforge.plantuml.descdiagram.DescriptionDiagramFactory;
import net.sourceforge.plantuml.directdot.PSystemDotFactory;
import net.sourceforge.plantuml.donors.PSystemDonorsFactory;
import net.sourceforge.plantuml.donors.PSystemSkinparameterListFactory;
import net.sourceforge.plantuml.ebnf.PSystemEbnfFactory;
import net.sourceforge.plantuml.eggs.PSystemAppleTwoFactory;
import net.sourceforge.plantuml.eggs.PSystemCharlieFactory;
import net.sourceforge.plantuml.eggs.PSystemColorsFactory;
import net.sourceforge.plantuml.eggs.PSystemEggFactory;
import net.sourceforge.plantuml.eggs.PSystemPathFactory;
import net.sourceforge.plantuml.eggs.PSystemRIPFactory;
import net.sourceforge.plantuml.eggs.PSystemWelcomeFactory;
import net.sourceforge.plantuml.emoji.PSystemListEmojiFactory;
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.error.PSystemErrorUtils;
import net.sourceforge.plantuml.error.PSystemUnsupported;
import net.sourceforge.plantuml.filesdiagram.FilesDiagramFactory;
import net.sourceforge.plantuml.flowdiagram.FlowDiagramFactory;
import net.sourceforge.plantuml.font.PSystemListFontsFactory;
import net.sourceforge.plantuml.gitlog.GitDiagramFactory;
import net.sourceforge.plantuml.hcl.HclDiagramFactory;
import net.sourceforge.plantuml.help.HelpFactory;
import net.sourceforge.plantuml.jsondiagram.JsonDiagramFactory;
//import net.sourceforge.plantuml.klimt.creole.legacy.PSystemCreoleFactory;
//import net.sourceforge.plantuml.klimt.sprite.ListSpriteDiagramFactory;
//import net.sourceforge.plantuml.klimt.sprite.PSystemListInternalSpritesFactory;
//import net.sourceforge.plantuml.klimt.sprite.StdlibDiagramFactory;
import net.sourceforge.plantuml.math.PSystemLatexFactory;
import net.sourceforge.plantuml.math.PSystemMathFactory;
import net.sourceforge.plantuml.mindmap.MindMapDiagramFactory;
import net.sourceforge.plantuml.nwdiag.NwDiagramFactory;
import net.sourceforge.plantuml.openiconic.PSystemListOpenIconicFactory;
import net.sourceforge.plantuml.openiconic.PSystemOpenIconicFactory;
import net.sourceforge.plantuml.oregon.PSystemOregonFactory;
import net.sourceforge.plantuml.project.GanttDiagramFactory;
import net.sourceforge.plantuml.regex.RegexConcat;
import net.sourceforge.plantuml.regexdiagram.PSystemRegexFactory;
import net.sourceforge.plantuml.salt.PSystemSaltFactory;
import net.sourceforge.plantuml.security.SecurityProfile;
import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
import net.sourceforge.plantuml.statediagram.StateDiagramFactory;
import net.sourceforge.plantuml.stats.StatsUtilsIncrement;
import net.sourceforge.plantuml.text.StringLocated;
import net.sourceforge.plantuml.timingdiagram.TimingDiagramFactory;
import net.sourceforge.plantuml.utils.Log;
import net.sourceforge.plantuml.version.PSystemLicenseFactory;
import net.sourceforge.plantuml.version.PSystemVersionFactory;
import net.sourceforge.plantuml.wbs.WBSDiagramFactory;
import net.sourceforge.plantuml.wire.WireDiagramFactory;
import net.sourceforge.plantuml.yaml.YamlDiagramFactory;

/**
* Builds a diagram from pre-processed PlantUML source.
*
* <p>
* Tries each of the factories (enumerated in the static block below) until one
* succeeds.
*
* @see AbstractPSystem
*/
public class PSystemBuilder {
// ::remove file when __HAXE__

public static final long startTime = System.currentTimeMillis();

final public Diagram createPSystem(List<StringLocated> source, List<StringLocated> rawSource,
Map<String, String> skinParam) {

WasmLog.log("..compiling diagram...");

final long now = System.currentTimeMillis();

Diagram result = null;
try {
final DiagramType type = DiagramType.getTypeFromArobaseStart(source.get(0).getString());
final UmlSource umlSource = UmlSource.createWithRaw(source, type == DiagramType.UML, rawSource);

for (StringLocated s : source) {
if (s.getPreprocessorError() != null) {
// Dead code : should not append
assert false;
Log.error("Preprocessor Error: " + s.getPreprocessorError());
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, s.getPreprocessorError(), 0,
s.getLocation());
return PSystemErrorUtils.buildV2(umlSource, err, Collections.<String>emptyList(), source);
}
}

final DiagramType diagramType = umlSource.getDiagramType();
if (diagramType == DiagramType.UNKNOWN)
return new PSystemUnsupported(umlSource);

final List<PSystemError> errors = new ArrayList<>();
for (PSystemFactory systemFactory : factories) {
if (diagramType != systemFactory.getDiagramType())
continue;

// WasmLog.log("...trying " + systemFactory.getClass().getName() + " ...");
final Diagram sys = systemFactory.createSystem(umlSource, skinParam);
if (isOk(sys)) {
result = sys;
return sys;
}
errors.add((PSystemError) sys);
}
if (errors.size() == 0)
return new PSystemUnsupported(umlSource);

result = PSystemErrorUtils.merge(errors);
return result;
} finally {
WasmLog.log("...parsing ok...");
// ::comment when __CORE__
if (result != null && OptionFlags.getInstance().isEnableStats()) {
StatsUtilsIncrement.onceMoreParse(System.currentTimeMillis() - now, result.getClass());
}
Log.info("Compilation duration " + (System.currentTimeMillis() - now));
RegexConcat.printCacheInfo();
}
}

private static final List<PSystemFactory> factories = new ArrayList<>();

static {
// factories.add(new PSystemWelcomeFactory());
// factories.add(new PSystemColorsFactory());
factories.add(new SequenceDiagramFactory());
factories.add(new ClassDiagramFactory());
factories.add(new ActivityDiagramFactory());
factories.add(new DescriptionDiagramFactory());
factories.add(new StateDiagramFactory());
factories.add(new ActivityDiagramFactory3());

// ::comment when __CORE__
// factories.add(new BpmDiagramFactory(DiagramType.BPM));

// factories.add(new PostIdDiagramFactory());
factories.add(new PSystemLicenseFactory());
factories.add(new PSystemVersionFactory());
// ::comment when __CORE__
factories.add(new PSystemDonorsFactory());
factories.add(new PSystemSkinparameterListFactory());
factories.add(new PSystemListFontsFactory());
factories.add(new PSystemListEmojiFactory());
// factories.add(new PSystemOpenIconicFactory());
// factories.add(new PSystemListOpenIconicFactory());
// factories.add(new PSystemListInternalSpritesFactory());
// factories.add(new PSystemSaltFactory(DiagramType.UML));
// factories.add(new PSystemSaltFactory(DiagramType.SALT));
// ::comment when __CORE__
// factories.add(new PSystemDotFactory(DiagramType.DOT));
// factories.add(new PSystemDotFactory(DiagramType.UML));
// factories.add(new NwDiagramFactory(DiagramType.UML));
// factories.add(new NwDiagramFactory(DiagramType.NW));
// factories.add(new MindMapDiagramFactory());
// factories.add(new WBSDiagramFactory());

// ::uncomment when __CORE__
// factories.add(new PSystemSudokuFactory());


// ::comment when __CORE__
factories.add(new PSystemDefinitionFactory());
// factories.add(new ListSpriteDiagramFactory());
// factories.add(new StdlibDiagramFactory());
// factories.add(new PSystemMathFactory(DiagramType.MATH));
// factories.add(new PSystemLatexFactory(DiagramType.LATEX));
// factories.add(new PSystemCreoleFactory());
// factories.add(new PSystemEggFactory());
// factories.add(new PSystemAppleTwoFactory());
// factories.add(new PSystemRIPFactory());
// if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE)
// factories.add(new PSystemPathFactory());
factories.add(new PSystemOregonFactory());

// factories.add(new PSystemCharlieFactory());

factories.add(new GanttDiagramFactory());
factories.add(new ChronologyDiagramFactory());
factories.add(new FlowDiagramFactory());

// ::comment when __CORE__
// factories.add(new PSystemDedicationFactory());

factories.add(new TimingDiagramFactory());

// ::comment when __CORE__
factories.add(new HelpFactory());
factories.add(new WireDiagramFactory());

factories.add(new JsonDiagramFactory());
factories.add(new GitDiagramFactory());
// ::comment when __CORE__
factories.add(new FilesDiagramFactory());
factories.add(new BoardDiagramFactory());
factories.add(new YamlDiagramFactory());
factories.add(new HclDiagramFactory());
factories.add(new PSystemEbnfFactory());
factories.add(new PSystemRegexFactory());

factories.add(new ChenEerDiagramFactory());
}

private boolean isOk(Diagram ps) {
if (ps == null || ps instanceof PSystemError)
return false;

return true;
}

}