From 1fd6af362013617a21774fd52bf7757de9b49b7e Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 22 Feb 2023 15:24:54 -0800 Subject: [PATCH 01/65] add printSysml optional to instance model and a CLI option to get started --- src/main/java/org/clafer/cli/Main.java | 1 + src/main/java/org/clafer/cli/Normal.java | 47 +++++++++++-------- .../org/clafer/instance/InstanceModel.java | 15 ++++++ 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/clafer/cli/Main.java b/src/main/java/org/clafer/cli/Main.java index d2d54628..e7489c64 100644 --- a/src/main/java/org/clafer/cli/Main.java +++ b/src/main/java/org/clafer/cli/Main.java @@ -27,6 +27,7 @@ public static void main(String[] args) throws Exception { accepts( "noprint", "Don't print the instances to the console or a file"); accepts( "output", "Output instances to the given file." ).withRequiredArg().ofType( File.class ).describedAs( "text file" ); accepts( "prettify", "Use simple and pretty output format (not formal)." ); + accepts( "sysml", "Print the instances as SysMLv2" ); accepts( "repl", "Run in REPL (interactive) mode." ); accepts( "scope", "Override the default global scope value." ).withRequiredArg().ofType( Integer.class ); accepts( "search", "PreferSmallerInstances/PreferLargerInstances/Random" ).withRequiredArg().ofType( ClaferSearchStrategy.class ); diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 5fafa896..376e70d7 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -39,6 +39,7 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, int index = 0; // instance id boolean prettify = options.has("prettify"); + boolean sysml = options.has("sysml"); boolean printOff = options.has("noprint"); boolean dataTackingOn = options.has("dataFile"); boolean timeOn = options.has("time"); @@ -71,28 +72,34 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, if (printOff) { ++index; } else { - outStream.println("=== Instance " + (++index) + " Begin ===\n"); - InstanceModel instance = solver.instance(); - if (prettify) - instance.print(outStream); - else - for (InstanceClafer c : instance.getTopClafers()) - Utils.printClafer(c, outStream); - outStream.println("\n--- Instance " + (index) + " End ---\n"); + if (sysml) { + InstanceModel instance = solver.instance(); + instance.printSysml(outStream); + } else { + outStream.println("=== Instance " + (++index) + " Begin ===\n"); + InstanceModel instance = solver.instance(); + if (prettify) + instance.print(outStream); + else + for (InstanceClafer c : instance.getTopClafers()) + Utils.printClafer(c, outStream); + outStream.println("\n--- Instance " + (index) + " End ---\n"); + } } } - if (timeOn) { - elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000; - if (objectives.length == 0) - System.out.println("Generated " + index + " instance(s) within the scope in " + elapsedTime + " seconds\n"); - else - System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope in " + elapsedTime + " secondse\n"); - } else { - if (objectives.length == 0) - System.out.println("Generated " + index + " instance(s) within the scope\n"); - else - System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope\n"); + if (!sysml) { + if (timeOn) { + elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000; + if (objectives.length == 0) + System.out.println("Generated " + index + " instance(s) within the scope in " + elapsedTime + " seconds\n"); + else + System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope in " + elapsedTime + " secondse\n"); + } else { + if (objectives.length == 0) + System.out.println("Generated " + index + " instance(s) within the scope\n"); + else + System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope\n"); + } } - } } diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index 906b00ef..2cc0fb18 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -49,6 +49,21 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { return typedTopClafer; } + /** + * Print solution as SysMLv2 + * + * This is the start of exploring an automated product derivation tool + * and the requirements around inferring a system model from clafer are + * still tbd + * @param out + * @throws IOException + */ + public void printSysml(Appendable out) throws IOException { + for (InstanceClafer top : topClafers) { + top.print(out); + } + } + /** * Print solution to stdout. * From 2fcd404f2540e189cc2acd3d3cde1af9671e523b Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 22 Feb 2023 16:42:32 -0800 Subject: [PATCH 02/65] start the sysml ast for compilation --- .../org/clafer/instance/InstanceModel.java | 6 +++++ .../java/org/sysml/SysmlBlockDefElement.java | 4 ++++ .../java/org/sysml/SysmlBlockVisibility.java | 14 +++++++++++ src/main/java/org/sysml/SysmlId.java | 10 ++++++++ src/main/java/org/sysml/SysmlPackage.java | 21 +++++++++++++++++ src/main/java/org/sysml/SysmlPartDef.java | 4 ++++ src/main/java/org/sysml/SysmlProperty.java | 23 +++++++++++++++++++ .../java/org/sysml/SysmlPropertyType.java | 19 +++++++++++++++ .../java/org/sysml/SysmlVisibilityOption.java | 8 +++++++ 9 files changed, 109 insertions(+) create mode 100644 src/main/java/org/sysml/SysmlBlockDefElement.java create mode 100644 src/main/java/org/sysml/SysmlBlockVisibility.java create mode 100644 src/main/java/org/sysml/SysmlId.java create mode 100644 src/main/java/org/sysml/SysmlPackage.java create mode 100644 src/main/java/org/sysml/SysmlPartDef.java create mode 100644 src/main/java/org/sysml/SysmlProperty.java create mode 100644 src/main/java/org/sysml/SysmlPropertyType.java create mode 100644 src/main/java/org/sysml/SysmlVisibilityOption.java diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index 2cc0fb18..11246dcf 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -6,6 +6,7 @@ import java.util.List; import org.clafer.ast.AstConcreteClafer; import org.clafer.common.Check; +import org.sysml.*; /** * @@ -59,6 +60,11 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { * @throws IOException */ public void printSysml(Appendable out) throws IOException { + ArrayList elems = new ArrayList(); + ArrayList elems_inner = new ArrayList(); + elems.add(new SysmlPackage("inner", elems_inner)); + elems.add(new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), "thing")); + SysmlPackage pack = new SysmlPackage("outer", elems); for (InstanceClafer top : topClafers) { top.print(out); } diff --git a/src/main/java/org/sysml/SysmlBlockDefElement.java b/src/main/java/org/sysml/SysmlBlockDefElement.java new file mode 100644 index 00000000..530db1ec --- /dev/null +++ b/src/main/java/org/sysml/SysmlBlockDefElement.java @@ -0,0 +1,4 @@ +package org.sysml; + +public interface SysmlBlockDefElement { +} diff --git a/src/main/java/org/sysml/SysmlBlockVisibility.java b/src/main/java/org/sysml/SysmlBlockVisibility.java new file mode 100644 index 00000000..19f3d68a --- /dev/null +++ b/src/main/java/org/sysml/SysmlBlockVisibility.java @@ -0,0 +1,14 @@ +package org.sysml; + +/** + * Sysml Block Visibility + * ::= | ‘#’ | ‘~’ + */ +public class SysmlBlockVisibility { + public final SysmlVisibilityOption option; + + public SysmlBlockVisibility(SysmlVisibilityOption visOpt) { + this.option = visOpt; + } + +} diff --git a/src/main/java/org/sysml/SysmlId.java b/src/main/java/org/sysml/SysmlId.java new file mode 100644 index 00000000..01d6a621 --- /dev/null +++ b/src/main/java/org/sysml/SysmlId.java @@ -0,0 +1,10 @@ +package org.sysml; + +public interface SysmlId { + /** + * SysML + * + * @return the name of the identifier + */ + String getName(); +} diff --git a/src/main/java/org/sysml/SysmlPackage.java b/src/main/java/org/sysml/SysmlPackage.java new file mode 100644 index 00000000..453036e6 --- /dev/null +++ b/src/main/java/org/sysml/SysmlPackage.java @@ -0,0 +1,21 @@ +package org.sysml; + + +import java.util.ArrayList; + +/** + * TODO: build out the DiagramElement taxonomy better + */ +public class SysmlPackage implements SysmlId, SysmlBlockDefElement { + private final ArrayList elements; + private final String name; + + public SysmlPackage(String name, ArrayList elements){ + this.elements = elements; + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/org/sysml/SysmlPartDef.java b/src/main/java/org/sysml/SysmlPartDef.java new file mode 100644 index 00000000..64be4ea2 --- /dev/null +++ b/src/main/java/org/sysml/SysmlPartDef.java @@ -0,0 +1,4 @@ +package org.sysml; + +public class SysmlPartDef { +} diff --git a/src/main/java/org/sysml/SysmlProperty.java b/src/main/java/org/sysml/SysmlProperty.java new file mode 100644 index 00000000..9ee87b3f --- /dev/null +++ b/src/main/java/org/sysml/SysmlProperty.java @@ -0,0 +1,23 @@ +package org.sysml; + +import org.clafer.common.Check; + +/** + * SysML Property + * + * ::= [] [‘/’] [] + * + * TODO: do the declaration + */ +public class SysmlProperty implements SysmlId, SysmlBlockDefElement { + + private final String name; + + public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name){ + this.name = Check.notNull(name); + } + @Override + public String getName() { + return name; + } +} diff --git a/src/main/java/org/sysml/SysmlPropertyType.java b/src/main/java/org/sysml/SysmlPropertyType.java new file mode 100644 index 00000000..08210295 --- /dev/null +++ b/src/main/java/org/sysml/SysmlPropertyType.java @@ -0,0 +1,19 @@ +package org.sysml; + +/** + * Sysml Property Keyword + * ::= ‘part’ | ‘reference’ | ‘value’ | + * + * TODO: accoutn for special cases + */ +public class SysmlPropertyType implements SysmlId { + private final String name; + public SysmlPropertyType(String name){ + this.name = name; + } + + @Override + public String getName() { + return name; + } +} diff --git a/src/main/java/org/sysml/SysmlVisibilityOption.java b/src/main/java/org/sysml/SysmlVisibilityOption.java new file mode 100644 index 00000000..e4f794ba --- /dev/null +++ b/src/main/java/org/sysml/SysmlVisibilityOption.java @@ -0,0 +1,8 @@ +package org.sysml; + +public enum SysmlVisibilityOption { + PLUS, // namespace-visibility + MINUS, // namespace-visibility + NUMBER, + TILDE +} From 4eb4c88e5b70104d36deebc4651e498298c000ea Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 22 Feb 2023 18:01:07 -0800 Subject: [PATCH 03/65] add visitor for pretty printer --- .../org/clafer/instance/InstanceModel.java | 9 ++- .../java/org/sysml/SysmlBlockDefElement.java | 2 +- src/main/java/org/sysml/SysmlExpr.java | 16 +++++ src/main/java/org/sysml/SysmlExprVisitor.java | 11 ++++ src/main/java/org/sysml/SysmlPackage.java | 13 +++- src/main/java/org/sysml/SysmlProperty.java | 13 +++- .../java/org/sysml/pprinter/SysmlPrinter.java | 63 +++++++++++++++++++ 7 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/sysml/SysmlExpr.java create mode 100644 src/main/java/org/sysml/SysmlExprVisitor.java create mode 100644 src/main/java/org/sysml/pprinter/SysmlPrinter.java diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index 11246dcf..2927fee2 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -7,6 +7,7 @@ import org.clafer.ast.AstConcreteClafer; import org.clafer.common.Check; import org.sysml.*; +import org.sysml.pprinter.SysmlPrinter; /** * @@ -65,9 +66,11 @@ public void printSysml(Appendable out) throws IOException { elems.add(new SysmlPackage("inner", elems_inner)); elems.add(new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), "thing")); SysmlPackage pack = new SysmlPackage("outer", elems); - for (InstanceClafer top : topClafers) { - top.print(out); - } + SysmlPrinter pprinter = new SysmlPrinter(out); + pprinter.visit(pack, ""); + //for (InstanceClafer top : topClafers) { + // top.printSysml(out); + //} } /** diff --git a/src/main/java/org/sysml/SysmlBlockDefElement.java b/src/main/java/org/sysml/SysmlBlockDefElement.java index 530db1ec..051d65b8 100644 --- a/src/main/java/org/sysml/SysmlBlockDefElement.java +++ b/src/main/java/org/sysml/SysmlBlockDefElement.java @@ -1,4 +1,4 @@ package org.sysml; -public interface SysmlBlockDefElement { +public interface SysmlBlockDefElement extends SysmlExpr { } diff --git a/src/main/java/org/sysml/SysmlExpr.java b/src/main/java/org/sysml/SysmlExpr.java new file mode 100644 index 00000000..0d0047e8 --- /dev/null +++ b/src/main/java/org/sysml/SysmlExpr.java @@ -0,0 +1,16 @@ +package org.sysml; + +import java.io.IOException; + +public interface SysmlExpr { + /** + * Dynamic dispatch on the visitor. + * + * @param the parameter type + * @param the return type + * @param visitor the visitor + * @param a the parameter + * @return the return value + */ + B accept(SysmlExprVisitor visitor, A a) throws IOException; +} diff --git a/src/main/java/org/sysml/SysmlExprVisitor.java b/src/main/java/org/sysml/SysmlExprVisitor.java new file mode 100644 index 00000000..f09eae85 --- /dev/null +++ b/src/main/java/org/sysml/SysmlExprVisitor.java @@ -0,0 +1,11 @@ +package org.sysml; + +import org.clafer.ast.AstThis; + +import java.io.IOException; + +public interface SysmlExprVisitor { + B visit(SysmlPackage ast, A a) throws IOException; + + B visit(SysmlProperty ast, A a); +} diff --git a/src/main/java/org/sysml/SysmlPackage.java b/src/main/java/org/sysml/SysmlPackage.java index 453036e6..e074c02e 100644 --- a/src/main/java/org/sysml/SysmlPackage.java +++ b/src/main/java/org/sysml/SysmlPackage.java @@ -1,12 +1,14 @@ package org.sysml; + +import java.io.IOException; import java.util.ArrayList; /** * TODO: build out the DiagramElement taxonomy better */ -public class SysmlPackage implements SysmlId, SysmlBlockDefElement { +public class SysmlPackage implements SysmlId, SysmlBlockDefElement, SysmlExpr { private final ArrayList elements; private final String name; @@ -18,4 +20,13 @@ public SysmlPackage(String name, ArrayList elements){ public String getName() { return name; } + + public ArrayList getElements(){ + return elements; + } + + @Override + public B accept(SysmlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } } diff --git a/src/main/java/org/sysml/SysmlProperty.java b/src/main/java/org/sysml/SysmlProperty.java index 9ee87b3f..2681f6f0 100644 --- a/src/main/java/org/sysml/SysmlProperty.java +++ b/src/main/java/org/sysml/SysmlProperty.java @@ -9,15 +9,26 @@ * * TODO: do the declaration */ -public class SysmlProperty implements SysmlId, SysmlBlockDefElement { +public class SysmlProperty implements SysmlId, SysmlBlockDefElement, SysmlExpr { private final String name; + private final SysmlPropertyType prop; public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name){ this.name = Check.notNull(name); + this.prop = propType; } @Override public String getName() { return name; } + + public SysmlPropertyType getPropertyType(){ + return prop; + } + + @Override + public B accept(SysmlExprVisitor visitor, A a) { + return visitor.visit(this, a); + } } diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java new file mode 100644 index 00000000..8877582d --- /dev/null +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -0,0 +1,63 @@ +package org.sysml.pprinter; + +import org.sysml.SysmlBlockDefElement; +import org.sysml.SysmlExprVisitor; +import org.sysml.SysmlPackage; +import org.sysml.SysmlProperty; + +import java.io.IOException; +import java.lang.Void; + +public class SysmlPrinter implements SysmlExprVisitor { + + private final String indent_base; + private final Appendable out; + + public SysmlPrinter(Appendable out) { + this.out = out; + this.indent_base = " "; + } + + + public void print(String indent, SysmlPackage spackage, Appendable out) throws IOException { + out.append(indent).append("package ").append(spackage.getName()).append(" {").append("\n"); + for (SysmlBlockDefElement elem : spackage.getElements()) { + print(indent + indent_base, elem, out); + out.append('\n'); + } + out.append(indent).append("}"); + } + + public void print(String indent, SysmlBlockDefElement sprop, Appendable out) throws IOException { + } + + @Override + public Void visit(SysmlProperty ast, String indent) { + try { + this.out + .append(indent) + .append(ast.getPropertyType().getName()) + .append(" ") + .append(ast.getName()) + .append(";\n") + ; + } catch (IOException ignored) { + + } + return null; + } + + @Override + public Void visit(SysmlPackage ast, String indent) { + try { + this.out.append(indent).append("package ").append(ast.getName()).append(" {").append("\n"); + for (SysmlBlockDefElement elem : ast.getElements()) { + elem.accept(this, indent + indent_base); + } + this.out.append(indent).append("}\n"); + } catch (IOException ignored) { + + } + return null; + } +} From aaf29a863ef2aed3c8d5423702f59fe3f46b8458 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Thu, 23 Feb 2023 10:19:35 -0800 Subject: [PATCH 04/65] pprint sysml example --- .../org/clafer/instance/InstanceModel.java | 26 ++++++++++++------- .../java/org/sysml/SysmlBlockDefElement.java | 2 +- src/main/java/org/sysml/SysmlPackage.java | 8 +++--- src/main/java/org/sysml/SysmlProperty.java | 17 +++++++++++- .../java/org/sysml/pprinter/SysmlPrinter.java | 10 ++++++- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index 2927fee2..ebbcf093 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; + +import org.clafer.ast.AstClafer; import org.clafer.ast.AstConcreteClafer; import org.clafer.common.Check; import org.sysml.*; @@ -51,6 +53,15 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { return typedTopClafer; } + private SysmlProperty compileInstance(InstanceClafer model) { + String propertyName = model.getType().getName(); + ArrayList children = new ArrayList(); + for (InstanceClafer child : model.getChildren()) { + children.add(compileInstance(child)); + } + return new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), propertyName, children.toArray(new SysmlBlockDefElement[children.size()])); + } + /** * Print solution as SysMLv2 * @@ -61,16 +72,11 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { * @throws IOException */ public void printSysml(Appendable out) throws IOException { - ArrayList elems = new ArrayList(); - ArrayList elems_inner = new ArrayList(); - elems.add(new SysmlPackage("inner", elems_inner)); - elems.add(new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), "thing")); - SysmlPackage pack = new SysmlPackage("outer", elems); - SysmlPrinter pprinter = new SysmlPrinter(out); - pprinter.visit(pack, ""); - //for (InstanceClafer top : topClafers) { - // top.printSysml(out); - //} + for (InstanceClafer top : topClafers) { + SysmlPrinter pprinter = new SysmlPrinter(out); + SysmlProperty model = compileInstance(top); + pprinter.visit(model, ""); + } } /** diff --git a/src/main/java/org/sysml/SysmlBlockDefElement.java b/src/main/java/org/sysml/SysmlBlockDefElement.java index 051d65b8..c5696595 100644 --- a/src/main/java/org/sysml/SysmlBlockDefElement.java +++ b/src/main/java/org/sysml/SysmlBlockDefElement.java @@ -1,4 +1,4 @@ package org.sysml; -public interface SysmlBlockDefElement extends SysmlExpr { +public interface SysmlBlockDefElement extends SysmlExpr, SysmlId { } diff --git a/src/main/java/org/sysml/SysmlPackage.java b/src/main/java/org/sysml/SysmlPackage.java index e074c02e..ab76f75a 100644 --- a/src/main/java/org/sysml/SysmlPackage.java +++ b/src/main/java/org/sysml/SysmlPackage.java @@ -8,11 +8,11 @@ /** * TODO: build out the DiagramElement taxonomy better */ -public class SysmlPackage implements SysmlId, SysmlBlockDefElement, SysmlExpr { - private final ArrayList elements; +public class SysmlPackage implements SysmlBlockDefElement { + private final SysmlBlockDefElement[] elements; private final String name; - public SysmlPackage(String name, ArrayList elements){ + public SysmlPackage(String name, SysmlBlockDefElement[] elements){ this.elements = elements; this.name = name; } @@ -21,7 +21,7 @@ public String getName() { return name; } - public ArrayList getElements(){ + public SysmlBlockDefElement[] getElements(){ return elements; } diff --git a/src/main/java/org/sysml/SysmlProperty.java b/src/main/java/org/sysml/SysmlProperty.java index 2681f6f0..d54ebcd4 100644 --- a/src/main/java/org/sysml/SysmlProperty.java +++ b/src/main/java/org/sysml/SysmlProperty.java @@ -2,6 +2,8 @@ import org.clafer.common.Check; +import java.util.ArrayList; + /** * SysML Property * @@ -9,14 +11,23 @@ * * TODO: do the declaration */ -public class SysmlProperty implements SysmlId, SysmlBlockDefElement, SysmlExpr { +public class SysmlProperty implements SysmlBlockDefElement { private final String name; private final SysmlPropertyType prop; + private final SysmlBlockDefElement[] elements; + + public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name, SysmlBlockDefElement[] elements){ + this.name = Check.notNull(name); + this.prop = propType; + this.elements = elements; + } + public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name){ this.name = Check.notNull(name); this.prop = propType; + this.elements = new SysmlBlockDefElement[0]; } @Override public String getName() { @@ -27,6 +38,10 @@ public SysmlPropertyType getPropertyType(){ return prop; } + public SysmlBlockDefElement[] getElements() { + return elements; + } + @Override public B accept(SysmlExprVisitor visitor, A a) { return visitor.visit(this, a); diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 8877582d..42d91462 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -39,8 +39,16 @@ public Void visit(SysmlProperty ast, String indent) { .append(ast.getPropertyType().getName()) .append(" ") .append(ast.getName()) - .append(";\n") ; + if (ast.getElements().length > 0) { + this.out.append("{\n"); + for (SysmlBlockDefElement elem : ast.getElements()) { + elem.accept(this, indent + indent_base); + } + this.out.append(indent).append("}\n"); + } else { + this.out.append(";\n"); + } } catch (IOException ignored) { } From 3d1870d7d721c02b314af567f9d84c8161507515 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Thu, 23 Feb 2023 10:31:09 -0800 Subject: [PATCH 05/65] restructure for instance compiler, add ast package --- .../org/clafer/instance/InstanceModel.java | 16 ++++------------ .../sysml/{ => ast}/SysmlBlockDefElement.java | 2 +- .../sysml/{ => ast}/SysmlBlockVisibility.java | 2 +- .../java/org/sysml/{ => ast}/SysmlExpr.java | 2 +- .../org/sysml/{ => ast}/SysmlExprVisitor.java | 4 +--- src/main/java/org/sysml/{ => ast}/SysmlId.java | 2 +- .../java/org/sysml/{ => ast}/SysmlPackage.java | 3 +-- .../java/org/sysml/{ => ast}/SysmlPartDef.java | 2 +- .../org/sysml/{ => ast}/SysmlProperty.java | 4 +--- .../org/sysml/{ => ast}/SysmlPropertyType.java | 2 +- .../sysml/{ => ast}/SysmlVisibilityOption.java | 2 +- .../sysml/compiler/InstanceSysmlCompiler.java | 18 ++++++++++++++++++ .../java/org/sysml/pprinter/SysmlPrinter.java | 8 ++++---- 13 files changed, 36 insertions(+), 31 deletions(-) rename src/main/java/org/sysml/{ => ast}/SysmlBlockDefElement.java (75%) rename src/main/java/org/sysml/{ => ast}/SysmlBlockVisibility.java (92%) rename src/main/java/org/sysml/{ => ast}/SysmlExpr.java (94%) rename src/main/java/org/sysml/{ => ast}/SysmlExprVisitor.java (76%) rename src/main/java/org/sysml/{ => ast}/SysmlId.java (86%) rename src/main/java/org/sysml/{ => ast}/SysmlPackage.java (93%) rename src/main/java/org/sysml/{ => ast}/SysmlPartDef.java (57%) rename src/main/java/org/sysml/{ => ast}/SysmlProperty.java (96%) rename src/main/java/org/sysml/{ => ast}/SysmlPropertyType.java (94%) rename src/main/java/org/sysml/{ => ast}/SysmlVisibilityOption.java (84%) create mode 100644 src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index ebbcf093..be0aebb3 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -5,10 +5,10 @@ import java.util.Arrays; import java.util.List; -import org.clafer.ast.AstClafer; import org.clafer.ast.AstConcreteClafer; import org.clafer.common.Check; -import org.sysml.*; +import org.sysml.ast.SysmlProperty; +import org.sysml.compiler.InstanceSysmlCompiler; import org.sysml.pprinter.SysmlPrinter; /** @@ -53,15 +53,6 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { return typedTopClafer; } - private SysmlProperty compileInstance(InstanceClafer model) { - String propertyName = model.getType().getName(); - ArrayList children = new ArrayList(); - for (InstanceClafer child : model.getChildren()) { - children.add(compileInstance(child)); - } - return new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), propertyName, children.toArray(new SysmlBlockDefElement[children.size()])); - } - /** * Print solution as SysMLv2 * @@ -74,7 +65,8 @@ private SysmlProperty compileInstance(InstanceClafer model) { public void printSysml(Appendable out) throws IOException { for (InstanceClafer top : topClafers) { SysmlPrinter pprinter = new SysmlPrinter(out); - SysmlProperty model = compileInstance(top); + InstanceSysmlCompiler compiler = new InstanceSysmlCompiler(); + SysmlProperty model = compiler.compile(top); pprinter.visit(model, ""); } } diff --git a/src/main/java/org/sysml/SysmlBlockDefElement.java b/src/main/java/org/sysml/ast/SysmlBlockDefElement.java similarity index 75% rename from src/main/java/org/sysml/SysmlBlockDefElement.java rename to src/main/java/org/sysml/ast/SysmlBlockDefElement.java index c5696595..6707f189 100644 --- a/src/main/java/org/sysml/SysmlBlockDefElement.java +++ b/src/main/java/org/sysml/ast/SysmlBlockDefElement.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; public interface SysmlBlockDefElement extends SysmlExpr, SysmlId { } diff --git a/src/main/java/org/sysml/SysmlBlockVisibility.java b/src/main/java/org/sysml/ast/SysmlBlockVisibility.java similarity index 92% rename from src/main/java/org/sysml/SysmlBlockVisibility.java rename to src/main/java/org/sysml/ast/SysmlBlockVisibility.java index 19f3d68a..bacb52ed 100644 --- a/src/main/java/org/sysml/SysmlBlockVisibility.java +++ b/src/main/java/org/sysml/ast/SysmlBlockVisibility.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; /** * Sysml Block Visibility diff --git a/src/main/java/org/sysml/SysmlExpr.java b/src/main/java/org/sysml/ast/SysmlExpr.java similarity index 94% rename from src/main/java/org/sysml/SysmlExpr.java rename to src/main/java/org/sysml/ast/SysmlExpr.java index 0d0047e8..2e64882c 100644 --- a/src/main/java/org/sysml/SysmlExpr.java +++ b/src/main/java/org/sysml/ast/SysmlExpr.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; import java.io.IOException; diff --git a/src/main/java/org/sysml/SysmlExprVisitor.java b/src/main/java/org/sysml/ast/SysmlExprVisitor.java similarity index 76% rename from src/main/java/org/sysml/SysmlExprVisitor.java rename to src/main/java/org/sysml/ast/SysmlExprVisitor.java index f09eae85..eeb71e3e 100644 --- a/src/main/java/org/sysml/SysmlExprVisitor.java +++ b/src/main/java/org/sysml/ast/SysmlExprVisitor.java @@ -1,6 +1,4 @@ -package org.sysml; - -import org.clafer.ast.AstThis; +package org.sysml.ast; import java.io.IOException; diff --git a/src/main/java/org/sysml/SysmlId.java b/src/main/java/org/sysml/ast/SysmlId.java similarity index 86% rename from src/main/java/org/sysml/SysmlId.java rename to src/main/java/org/sysml/ast/SysmlId.java index 01d6a621..816d7dad 100644 --- a/src/main/java/org/sysml/SysmlId.java +++ b/src/main/java/org/sysml/ast/SysmlId.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; public interface SysmlId { /** diff --git a/src/main/java/org/sysml/SysmlPackage.java b/src/main/java/org/sysml/ast/SysmlPackage.java similarity index 93% rename from src/main/java/org/sysml/SysmlPackage.java rename to src/main/java/org/sysml/ast/SysmlPackage.java index ab76f75a..d3e478ba 100644 --- a/src/main/java/org/sysml/SysmlPackage.java +++ b/src/main/java/org/sysml/ast/SysmlPackage.java @@ -1,9 +1,8 @@ -package org.sysml; +package org.sysml.ast; import java.io.IOException; -import java.util.ArrayList; /** * TODO: build out the DiagramElement taxonomy better diff --git a/src/main/java/org/sysml/SysmlPartDef.java b/src/main/java/org/sysml/ast/SysmlPartDef.java similarity index 57% rename from src/main/java/org/sysml/SysmlPartDef.java rename to src/main/java/org/sysml/ast/SysmlPartDef.java index 64be4ea2..29793a97 100644 --- a/src/main/java/org/sysml/SysmlPartDef.java +++ b/src/main/java/org/sysml/ast/SysmlPartDef.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; public class SysmlPartDef { } diff --git a/src/main/java/org/sysml/SysmlProperty.java b/src/main/java/org/sysml/ast/SysmlProperty.java similarity index 96% rename from src/main/java/org/sysml/SysmlProperty.java rename to src/main/java/org/sysml/ast/SysmlProperty.java index d54ebcd4..7086a7fb 100644 --- a/src/main/java/org/sysml/SysmlProperty.java +++ b/src/main/java/org/sysml/ast/SysmlProperty.java @@ -1,9 +1,7 @@ -package org.sysml; +package org.sysml.ast; import org.clafer.common.Check; -import java.util.ArrayList; - /** * SysML Property * diff --git a/src/main/java/org/sysml/SysmlPropertyType.java b/src/main/java/org/sysml/ast/SysmlPropertyType.java similarity index 94% rename from src/main/java/org/sysml/SysmlPropertyType.java rename to src/main/java/org/sysml/ast/SysmlPropertyType.java index 08210295..837ef6b0 100644 --- a/src/main/java/org/sysml/SysmlPropertyType.java +++ b/src/main/java/org/sysml/ast/SysmlPropertyType.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; /** * Sysml Property Keyword diff --git a/src/main/java/org/sysml/SysmlVisibilityOption.java b/src/main/java/org/sysml/ast/SysmlVisibilityOption.java similarity index 84% rename from src/main/java/org/sysml/SysmlVisibilityOption.java rename to src/main/java/org/sysml/ast/SysmlVisibilityOption.java index e4f794ba..524c3e68 100644 --- a/src/main/java/org/sysml/SysmlVisibilityOption.java +++ b/src/main/java/org/sysml/ast/SysmlVisibilityOption.java @@ -1,4 +1,4 @@ -package org.sysml; +package org.sysml.ast; public enum SysmlVisibilityOption { PLUS, // namespace-visibility diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java new file mode 100644 index 00000000..d6d9952d --- /dev/null +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -0,0 +1,18 @@ +package org.sysml.compiler; + +import org.clafer.instance.InstanceClafer; +import org.sysml.ast.*; + +import java.util.ArrayList; + +public class InstanceSysmlCompiler { + public SysmlProperty compile(InstanceClafer model) { + String propertyName = model.getType().getName(); + ArrayList children = new ArrayList(); + for (InstanceClafer child : model.getChildren()) { + children.add(compile(child)); + } + return new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), propertyName, children.toArray(new SysmlBlockDefElement[children.size()])); + } + +} diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 42d91462..3fc8b848 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -1,9 +1,9 @@ package org.sysml.pprinter; -import org.sysml.SysmlBlockDefElement; -import org.sysml.SysmlExprVisitor; -import org.sysml.SysmlPackage; -import org.sysml.SysmlProperty; +import org.sysml.ast.SysmlBlockDefElement; +import org.sysml.ast.SysmlExprVisitor; +import org.sysml.ast.SysmlPackage; +import org.sysml.ast.SysmlProperty; import java.io.IOException; import java.lang.Void; From 34e9de6d2007a0a38a556a4e2eca56ab039ccd9a Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Mon, 27 Feb 2023 17:28:08 -0800 Subject: [PATCH 06/65] change compiler to use multiplicity, part def --- .../org/clafer/instance/InstanceModel.java | 4 +- .../java/org/sysml/ast/SysmlProperty.java | 19 +++- .../sysml/compiler/InstanceSysmlCompiler.java | 87 ++++++++++++++++++- .../java/org/sysml/pprinter/SysmlPrinter.java | 8 +- 4 files changed, 111 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index be0aebb3..95020a24 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -63,10 +63,12 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { * @throws IOException */ public void printSysml(Appendable out) throws IOException { + + for (InstanceClafer top : topClafers) { SysmlPrinter pprinter = new SysmlPrinter(out); InstanceSysmlCompiler compiler = new InstanceSysmlCompiler(); - SysmlProperty model = compiler.compile(top); + SysmlProperty model = compiler.compile(top, top); pprinter.visit(model, ""); } } diff --git a/src/main/java/org/sysml/ast/SysmlProperty.java b/src/main/java/org/sysml/ast/SysmlProperty.java index 7086a7fb..abdb738e 100644 --- a/src/main/java/org/sysml/ast/SysmlProperty.java +++ b/src/main/java/org/sysml/ast/SysmlProperty.java @@ -12,21 +12,30 @@ public class SysmlProperty implements SysmlBlockDefElement { private final String name; + private final SysmlPropertyType prop; private final SysmlBlockDefElement[] elements; + private final String[] superTypes; + + private int multiplicity; - public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name, SysmlBlockDefElement[] elements){ + public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name, SysmlBlockDefElement[] elements, String[] superTypes, int multiplicity){ this.name = Check.notNull(name); this.prop = propType; this.elements = elements; + this.superTypes = superTypes; + this.multiplicity = multiplicity; } public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name){ this.name = Check.notNull(name); this.prop = propType; this.elements = new SysmlBlockDefElement[0]; + this.superTypes = new String[0]; + this.multiplicity = 1; } + @Override public String getName() { return name; @@ -40,6 +49,14 @@ public SysmlBlockDefElement[] getElements() { return elements; } + public String[] getSupers(){ + return superTypes; + } + + public int getMultiplicity(){ + return multiplicity; + } + @Override public B accept(SysmlExprVisitor visitor, A a) { return visitor.visit(this, a); diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java index d6d9952d..bf5994c4 100644 --- a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -1,18 +1,97 @@ package org.sysml.compiler; +import org.clafer.ast.AstClafer; +import org.clafer.ast.AstRef; import org.clafer.instance.InstanceClafer; import org.sysml.ast.*; +import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class InstanceSysmlCompiler { - public SysmlProperty compile(InstanceClafer model) { - String propertyName = model.getType().getName(); + + private ArrayList processedClafers; + + public InstanceSysmlCompiler(){ + this.processedClafers = new ArrayList(); + } + + public String getPropertyId(String name){ + if (name.startsWith("c0_")){ + return name.substring(3); + } else { + return name; + } + } + + int getMultiplicity(InstanceClafer model, AstClafer clafer){ + int count = 0; + if (model.getType().getName().equals(clafer.getName())){ + count++; + } + for (InstanceClafer child : model.getChildren()) { + count += getMultiplicity(child, clafer); + } + return count; + } + + ArrayList _getSuperClafers(AstClafer clafer, ArrayList hier){ + if (clafer.getSuperClafer() == null) { + return hier; + } else { + hier.add(getPropertyId(clafer.getSuperClafer().getName())); + return _getSuperClafers(clafer.getSuperClafer(), hier); + } + } + + public String[] getSuperClafers(AstClafer clafer){ + ArrayList clafers = _getSuperClafers(clafer, new ArrayList()); + String[] clafers_arr = new String[clafers.size()]; + return clafers.toArray(clafers_arr); + } + + public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) { + String propertyName = getPropertyId(model.getType().getName()); + String[] superClafers = getSuperClafers(model.getType()); + List hierarchy = Arrays.asList(superClafers); ArrayList children = new ArrayList(); for (InstanceClafer child : model.getChildren()) { - children.add(compile(child)); + if (!processedClafers.contains(child.getType().getName())) { + SysmlProperty cchild = compile(child, topLevelModel); + if (!cchild.getPropertyType().getName().equals("")) { + children.add(compile(child, topLevelModel)); + } else { + SysmlBlockDefElement[] schildren = cchild.getElements(); + children.addAll(new ArrayList(Arrays.asList(schildren))); + } + } + } + + //Object ref = model.getType().getRef(); + //if (ref instanceof AstRef){ + // System.out.println(((AstRef) ref).getTargetType().getName()); + //} + + String propName = ""; + String[] superTypes = new String[0]; + if (hierarchy.contains("Part")) { + propName = "part"; + superTypes = Arrays.copyOfRange(superClafers, 0, superClafers.length-2); + } else { + propName = ""; } - return new SysmlProperty(new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType("part"), propertyName, children.toArray(new SysmlBlockDefElement[children.size()])); + int multiplicity = getMultiplicity(topLevelModel, model.getType()); + processedClafers.add(model.getType().getName()); + return new SysmlProperty( + new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), + new SysmlPropertyType(propName), + propertyName, + children.toArray(new SysmlBlockDefElement[children.size()]), + superTypes, + multiplicity + ); } } diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 3fc8b848..66ac3d04 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -40,8 +40,14 @@ public Void visit(SysmlProperty ast, String indent) { .append(" ") .append(ast.getName()) ; + if (ast.getMultiplicity() > 1) { + this.out.append("[").append(String.valueOf(ast.getMultiplicity())).append("]"); + } + for (String s: ast.getSupers()){ + this.out.append(" :> ").append(s); + } if (ast.getElements().length > 0) { - this.out.append("{\n"); + this.out.append(" {\n"); for (SysmlBlockDefElement elem : ast.getElements()) { elem.accept(this, indent + indent_base); } From e527bbdea5db89ad082c75cdca13c50b58641b06 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Mon, 27 Feb 2023 18:39:08 -0800 Subject: [PATCH 07/65] add SysmlAnnotation and pretty print annotations from the CLaferInstance --- .../java/org/sysml/ast/SysmlAnnotation.java | 29 +++++++++++++ .../java/org/sysml/ast/SysmlExprVisitor.java | 2 + .../java/org/sysml/ast/SysmlProperty.java | 20 ++++++++- .../sysml/compiler/InstanceSysmlCompiler.java | 41 +++++++++++++------ .../java/org/sysml/pprinter/SysmlPrinter.java | 15 ++++--- 5 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/sysml/ast/SysmlAnnotation.java diff --git a/src/main/java/org/sysml/ast/SysmlAnnotation.java b/src/main/java/org/sysml/ast/SysmlAnnotation.java new file mode 100644 index 00000000..74ef24d1 --- /dev/null +++ b/src/main/java/org/sysml/ast/SysmlAnnotation.java @@ -0,0 +1,29 @@ +package org.sysml.ast; + +import org.clafer.common.Check; + +import java.io.IOException; + +public class SysmlAnnotation implements SysmlExpr, SysmlId { + private String name; + + private Object ref; + + public SysmlAnnotation(String name, Object ref) { + this.name = name; + this.ref = ref; + } + + @Override + public String getName() { + return name; + } + + public String getRef() { + return ref.toString(); + } + @Override + public B accept(SysmlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } +} diff --git a/src/main/java/org/sysml/ast/SysmlExprVisitor.java b/src/main/java/org/sysml/ast/SysmlExprVisitor.java index eeb71e3e..78af8c5e 100644 --- a/src/main/java/org/sysml/ast/SysmlExprVisitor.java +++ b/src/main/java/org/sysml/ast/SysmlExprVisitor.java @@ -6,4 +6,6 @@ public interface SysmlExprVisitor { B visit(SysmlPackage ast, A a) throws IOException; B visit(SysmlProperty ast, A a); + + B visit(SysmlAnnotation ast, A a) throws IOException; } diff --git a/src/main/java/org/sysml/ast/SysmlProperty.java b/src/main/java/org/sysml/ast/SysmlProperty.java index abdb738e..3604e516 100644 --- a/src/main/java/org/sysml/ast/SysmlProperty.java +++ b/src/main/java/org/sysml/ast/SysmlProperty.java @@ -16,16 +16,29 @@ public class SysmlProperty implements SysmlBlockDefElement { private final SysmlPropertyType prop; private final SysmlBlockDefElement[] elements; + + private final SysmlAnnotation[] annotations; private final String[] superTypes; private int multiplicity; - public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name, SysmlBlockDefElement[] elements, String[] superTypes, int multiplicity){ + + + public SysmlProperty( + SysmlBlockVisibility blockVis, + SysmlPropertyType propType, + String name, + SysmlBlockDefElement[] elements, + SysmlAnnotation[] annotations, + String[] superTypes, + int multiplicity + ){ this.name = Check.notNull(name); this.prop = propType; this.elements = elements; this.superTypes = superTypes; this.multiplicity = multiplicity; + this.annotations = annotations; } public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name){ @@ -33,6 +46,7 @@ public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, this.prop = propType; this.elements = new SysmlBlockDefElement[0]; this.superTypes = new String[0]; + this.annotations = new SysmlAnnotation[0]; this.multiplicity = 1; } @@ -57,6 +71,10 @@ public int getMultiplicity(){ return multiplicity; } + public SysmlAnnotation[] getAnnotations(){ + return annotations; + } + @Override public B accept(SysmlExprVisitor visitor, A a) { return visitor.visit(this, a); diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java index bf5994c4..8ca2a658 100644 --- a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -5,7 +5,6 @@ import org.clafer.instance.InstanceClafer; import org.sysml.ast.*; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -53,15 +52,20 @@ public String[] getSuperClafers(AstClafer clafer){ } public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) { + // collect the identifier String propertyName = getPropertyId(model.getType().getName()); + + // get its supers String[] superClafers = getSuperClafers(model.getType()); List hierarchy = Arrays.asList(superClafers); + + // process the children ArrayList children = new ArrayList(); for (InstanceClafer child : model.getChildren()) { if (!processedClafers.contains(child.getType().getName())) { SysmlProperty cchild = compile(child, topLevelModel); - if (!cchild.getPropertyType().getName().equals("")) { - children.add(compile(child, topLevelModel)); + if (!cchild.getPropertyType().getName().equals("unk")) { + children.add(cchild); } else { SysmlBlockDefElement[] schildren = cchild.getElements(); children.addAll(new ArrayList(Arrays.asList(schildren))); @@ -69,26 +73,39 @@ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) } } - //Object ref = model.getType().getRef(); - //if (ref instanceof AstRef){ - // System.out.println(((AstRef) ref).getTargetType().getName()); - //} - + // get the property name String propName = ""; String[] superTypes = new String[0]; - if (hierarchy.contains("Part")) { - propName = "part"; - superTypes = Arrays.copyOfRange(superClafers, 0, superClafers.length-2); + if (hierarchy.contains("SysmlProperty")) { + propName = ((String) hierarchy.get(hierarchy.indexOf("SysmlProperty") - 1)).toLowerCase(); + superTypes = Arrays.copyOfRange(superClafers, 0, hierarchy.indexOf("SysmlProperty")-1); } else { - propName = ""; + propName = "unk"; } + + // get the clafer multiplicity and mark as processed int multiplicity = getMultiplicity(topLevelModel, model.getType()); processedClafers.add(model.getType().getName()); + + // collect the annotations + ArrayList annots = new ArrayList(); + for (InstanceClafer child : model.getChildren()) { + Object ref = child.getType().getRef(); + if (ref != null) { + AstRef aref = (AstRef) ref; + String aname = getPropertyId(aref.getSourceType().getName()); + Object refv = child.getRef(); + annots.add(new SysmlAnnotation(aname, refv)); + } + } + + // build a property object return new SysmlProperty( new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), new SysmlPropertyType(propName), propertyName, children.toArray(new SysmlBlockDefElement[children.size()]), + annots.toArray(new SysmlAnnotation[annots.size()]), superTypes, multiplicity ); diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 66ac3d04..0699058a 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -1,9 +1,6 @@ package org.sysml.pprinter; -import org.sysml.ast.SysmlBlockDefElement; -import org.sysml.ast.SysmlExprVisitor; -import org.sysml.ast.SysmlPackage; -import org.sysml.ast.SysmlProperty; +import org.sysml.ast.*; import java.io.IOException; import java.lang.Void; @@ -31,6 +28,11 @@ public void print(String indent, SysmlPackage spackage, Appendable out) throws I public void print(String indent, SysmlBlockDefElement sprop, Appendable out) throws IOException { } + public Void visit(SysmlAnnotation ast, String indent) throws IOException { + this.out.append(indent).append(":>> ").append(ast.getName()).append(" = ").append(ast.getRef()).append(";\n"); + return null; + } + @Override public Void visit(SysmlProperty ast, String indent) { try { @@ -46,8 +48,11 @@ public Void visit(SysmlProperty ast, String indent) { for (String s: ast.getSupers()){ this.out.append(" :> ").append(s); } - if (ast.getElements().length > 0) { + if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { this.out.append(" {\n"); + for (SysmlAnnotation annot: ast.getAnnotations()){ + annot.accept(this, indent + indent_base); + } for (SysmlBlockDefElement elem : ast.getElements()) { elem.accept(this, indent + indent_base); } From 9d872f859702ef5514083399db5696c67bf3c508 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 09:39:33 -0800 Subject: [PATCH 08/65] add a Clafer AST -> Sysml compiler --- src/main/java/org/clafer/cli/Normal.java | 18 +++- .../org/clafer/instance/InstanceModel.java | 4 +- ...smlAnnotation.java => SysmlAttribute.java} | 6 +- .../java/org/sysml/ast/SysmlExprVisitor.java | 4 +- src/main/java/org/sysml/ast/SysmlPartDef.java | 4 - .../java/org/sysml/ast/SysmlProperty.java | 8 +- .../java/org/sysml/ast/SysmlPropertyDef.java | 63 ++++++++++++++ .../org/sysml/compiler/AstSysmlCompiler.java | 84 +++++++++++++++++++ .../sysml/compiler/InstanceSysmlCompiler.java | 6 +- .../java/org/sysml/pprinter/SysmlPrinter.java | 37 +++++++- 10 files changed, 212 insertions(+), 22 deletions(-) rename src/main/java/org/sysml/ast/{SysmlAnnotation.java => SysmlAttribute.java} (75%) delete mode 100644 src/main/java/org/sysml/ast/SysmlPartDef.java create mode 100644 src/main/java/org/sysml/ast/SysmlPropertyDef.java create mode 100644 src/main/java/org/sysml/compiler/AstSysmlCompiler.java diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 376e70d7..50778f46 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -12,6 +12,11 @@ import org.clafer.javascript.JavascriptFile; import org.clafer.objective.Objective; import org.clafer.scope.Scope; +import org.clafer.ast.AstModel; +import org.sysml.ast.SysmlProperty; +import org.sysml.ast.SysmlPropertyDef; +import org.sysml.compiler.AstSysmlCompiler; +import org.sysml.pprinter.SysmlPrinter; public class Normal { @@ -73,8 +78,19 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, ++index; } else { if (sysml) { + outStream.append("package Architecture {\n"); + outStream.append(" import ScalarValues::*;\n"); + AstModel top = javascriptFile.getModel(); + SysmlPrinter pprinter = new SysmlPrinter(outStream); + AstSysmlCompiler compiler = new AstSysmlCompiler(); + SysmlPropertyDef[] models = compiler.compile(top, top); + for (SysmlPropertyDef model: models){ + pprinter.visit(model, " "); + } + InstanceModel instance = solver.instance(); - instance.printSysml(outStream); + instance.printSysml(outStream, " "); + outStream.append("}\n"); } else { outStream.println("=== Instance " + (++index) + " Begin ===\n"); InstanceModel instance = solver.instance(); diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index 95020a24..a8ca3ccd 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -62,14 +62,14 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { * @param out * @throws IOException */ - public void printSysml(Appendable out) throws IOException { + public void printSysml(Appendable out, String indent) throws IOException { for (InstanceClafer top : topClafers) { SysmlPrinter pprinter = new SysmlPrinter(out); InstanceSysmlCompiler compiler = new InstanceSysmlCompiler(); SysmlProperty model = compiler.compile(top, top); - pprinter.visit(model, ""); + pprinter.visit(model, indent); } } diff --git a/src/main/java/org/sysml/ast/SysmlAnnotation.java b/src/main/java/org/sysml/ast/SysmlAttribute.java similarity index 75% rename from src/main/java/org/sysml/ast/SysmlAnnotation.java rename to src/main/java/org/sysml/ast/SysmlAttribute.java index 74ef24d1..3d6a7f0f 100644 --- a/src/main/java/org/sysml/ast/SysmlAnnotation.java +++ b/src/main/java/org/sysml/ast/SysmlAttribute.java @@ -1,15 +1,13 @@ package org.sysml.ast; -import org.clafer.common.Check; - import java.io.IOException; -public class SysmlAnnotation implements SysmlExpr, SysmlId { +public class SysmlAttribute implements SysmlExpr, SysmlId { private String name; private Object ref; - public SysmlAnnotation(String name, Object ref) { + public SysmlAttribute(String name, Object ref) { this.name = name; this.ref = ref; } diff --git a/src/main/java/org/sysml/ast/SysmlExprVisitor.java b/src/main/java/org/sysml/ast/SysmlExprVisitor.java index 78af8c5e..f6e8cf3b 100644 --- a/src/main/java/org/sysml/ast/SysmlExprVisitor.java +++ b/src/main/java/org/sysml/ast/SysmlExprVisitor.java @@ -7,5 +7,7 @@ public interface SysmlExprVisitor { B visit(SysmlProperty ast, A a); - B visit(SysmlAnnotation ast, A a) throws IOException; + B visit(SysmlAttribute ast, A a) throws IOException; + + B visit(SysmlPropertyDef sysmlPropertyDef, A a); } diff --git a/src/main/java/org/sysml/ast/SysmlPartDef.java b/src/main/java/org/sysml/ast/SysmlPartDef.java deleted file mode 100644 index 29793a97..00000000 --- a/src/main/java/org/sysml/ast/SysmlPartDef.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sysml.ast; - -public class SysmlPartDef { -} diff --git a/src/main/java/org/sysml/ast/SysmlProperty.java b/src/main/java/org/sysml/ast/SysmlProperty.java index 3604e516..8011d590 100644 --- a/src/main/java/org/sysml/ast/SysmlProperty.java +++ b/src/main/java/org/sysml/ast/SysmlProperty.java @@ -17,7 +17,7 @@ public class SysmlProperty implements SysmlBlockDefElement { private final SysmlBlockDefElement[] elements; - private final SysmlAnnotation[] annotations; + private final SysmlAttribute[] annotations; private final String[] superTypes; private int multiplicity; @@ -29,7 +29,7 @@ public SysmlProperty( SysmlPropertyType propType, String name, SysmlBlockDefElement[] elements, - SysmlAnnotation[] annotations, + SysmlAttribute[] annotations, String[] superTypes, int multiplicity ){ @@ -46,7 +46,7 @@ public SysmlProperty(SysmlBlockVisibility blockVis, SysmlPropertyType propType, this.prop = propType; this.elements = new SysmlBlockDefElement[0]; this.superTypes = new String[0]; - this.annotations = new SysmlAnnotation[0]; + this.annotations = new SysmlAttribute[0]; this.multiplicity = 1; } @@ -71,7 +71,7 @@ public int getMultiplicity(){ return multiplicity; } - public SysmlAnnotation[] getAnnotations(){ + public SysmlAttribute[] getAnnotations(){ return annotations; } diff --git a/src/main/java/org/sysml/ast/SysmlPropertyDef.java b/src/main/java/org/sysml/ast/SysmlPropertyDef.java new file mode 100644 index 00000000..4589bb12 --- /dev/null +++ b/src/main/java/org/sysml/ast/SysmlPropertyDef.java @@ -0,0 +1,63 @@ +package org.sysml.ast; + +import org.clafer.common.Check; + +public class SysmlPropertyDef implements SysmlBlockDefElement { + private final String name; + + private final SysmlPropertyType prop; + + private final SysmlBlockDefElement[] elements; + + private final SysmlAttribute[] annotations; + private final String[] superTypes; + + public SysmlPropertyDef( + SysmlBlockVisibility blockVis, + SysmlPropertyType propType, + String name, + SysmlBlockDefElement[] elements, + SysmlAttribute[] annotations, + String[] superTypes + ){ + this.name = Check.notNull(name); + this.prop = propType; + this.elements = elements; + this.superTypes = superTypes; + this.annotations = annotations; + } + + public SysmlPropertyDef(SysmlBlockVisibility blockVis, SysmlPropertyType propType, String name){ + this.name = Check.notNull(name); + this.prop = propType; + this.elements = new SysmlBlockDefElement[0]; + this.superTypes = new String[0]; + this.annotations = new SysmlAttribute[0]; + } + + @Override + public String getName() { + return name; + } + + public SysmlPropertyType getPropertyType(){ + return prop; + } + + public SysmlBlockDefElement[] getElements() { + return elements; + } + + public String[] getSupers(){ + return superTypes; + } + + public SysmlAttribute[] getAnnotations(){ + return annotations; + } + + @Override + public B accept(SysmlExprVisitor visitor, A a) { + return visitor.visit(this, a); + } +} diff --git a/src/main/java/org/sysml/compiler/AstSysmlCompiler.java b/src/main/java/org/sysml/compiler/AstSysmlCompiler.java new file mode 100644 index 00000000..58de7113 --- /dev/null +++ b/src/main/java/org/sysml/compiler/AstSysmlCompiler.java @@ -0,0 +1,84 @@ +package org.sysml.compiler; + +import org.clafer.ast.AstAbstractClafer; +import org.clafer.ast.AstClafer; +import org.clafer.ast.AstModel; +import org.clafer.ast.AstRef; +import org.clafer.instance.InstanceClafer; +import org.sysml.ast.*; + +import java.util.*; + +public class AstSysmlCompiler { + private Map typeMap; + + public AstSysmlCompiler(){ + this.typeMap = new HashMap<>(); + this.typeMap.put("int", "Integer"); + this.typeMap.put("real", "Real"); + this.typeMap.put("double", "Real"); + this.typeMap.put("string", "String"); + } + + public String getPropertyId(String name){ + if (name.startsWith("c0_")){ + return name.substring(3); + } else { + return name; + } + } + + public String[] getSuperClafers(AstClafer model){ + Object spr = model.getSuperClafer(); + if (spr == null){ + return new String[0]; + } else { + String[] rem = getSuperClafers((AstClafer) spr); + String[] sprs = Arrays.copyOf(rem, rem.length + 1); + sprs[0] = getPropertyId(((AstClafer) spr).getName()); + System.arraycopy(rem, 0, sprs, 1, rem.length); + return sprs; + } + } + public SysmlPropertyDef[] compile(AstModel model, AstModel topLevelModel) { + ArrayList propDefs = new ArrayList(); + + for (AstAbstractClafer child: model.getAbstractRoot().getAbstractChildren()){ + String name = getPropertyId(child.getName()); + + ArrayList attrs = new ArrayList(); + for (AstClafer sub: child.getChildren()) { + Object sref = sub.getRef(); + if (sref instanceof AstRef){ + AstRef ref = (AstRef) sref; + Object tgt = typeMap.get(ref.getTargetType().toString()); + String propName = getPropertyId(ref.getSourceType().getName()); + attrs.add(new SysmlAttribute(propName, tgt)); + } + } + + String[] superClafers = getSuperClafers(child); + List hierarchy = Arrays.asList(superClafers); + if (hierarchy.size() < 3){ + continue; + } + + String[] superTypes = new String[0]; + if (hierarchy.contains("SysmlProperty")) { + superTypes = Arrays.copyOfRange(superClafers, 0, hierarchy.indexOf("SysmlProperty")-1); + } + + propDefs.add(new SysmlPropertyDef( + new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), + new SysmlPropertyType("part"), + name, + new SysmlBlockDefElement[0], + attrs.toArray(new SysmlAttribute[attrs.size()]), + superTypes + )); + + } + + return propDefs.toArray(new SysmlPropertyDef[propDefs.size()]); + } +} diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java index 8ca2a658..91970f13 100644 --- a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -88,14 +88,14 @@ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) processedClafers.add(model.getType().getName()); // collect the annotations - ArrayList annots = new ArrayList(); + ArrayList annots = new ArrayList(); for (InstanceClafer child : model.getChildren()) { Object ref = child.getType().getRef(); if (ref != null) { AstRef aref = (AstRef) ref; String aname = getPropertyId(aref.getSourceType().getName()); Object refv = child.getRef(); - annots.add(new SysmlAnnotation(aname, refv)); + annots.add(new SysmlAttribute(aname, refv)); } } @@ -105,7 +105,7 @@ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) new SysmlPropertyType(propName), propertyName, children.toArray(new SysmlBlockDefElement[children.size()]), - annots.toArray(new SysmlAnnotation[annots.size()]), + annots.toArray(new SysmlAttribute[annots.size()]), superTypes, multiplicity ); diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 0699058a..7f4c2aed 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -28,7 +28,7 @@ public void print(String indent, SysmlPackage spackage, Appendable out) throws I public void print(String indent, SysmlBlockDefElement sprop, Appendable out) throws IOException { } - public Void visit(SysmlAnnotation ast, String indent) throws IOException { + public Void visit(SysmlAttribute ast, String indent) throws IOException { this.out.append(indent).append(":>> ").append(ast.getName()).append(" = ").append(ast.getRef()).append(";\n"); return null; } @@ -46,11 +46,11 @@ public Void visit(SysmlProperty ast, String indent) { this.out.append("[").append(String.valueOf(ast.getMultiplicity())).append("]"); } for (String s: ast.getSupers()){ - this.out.append(" :> ").append(s); + this.out.append(" : ").append(s); } if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { this.out.append(" {\n"); - for (SysmlAnnotation annot: ast.getAnnotations()){ + for (SysmlAttribute annot: ast.getAnnotations()){ annot.accept(this, indent + indent_base); } for (SysmlBlockDefElement elem : ast.getElements()) { @@ -66,6 +66,37 @@ public Void visit(SysmlProperty ast, String indent) { return null; } + @Override + public Void visit(SysmlPropertyDef ast, String indent) { + try { + this.out + .append(indent) + .append(ast.getPropertyType().getName()) + .append(" def ") + .append(ast.getName()) + ; + for (String s: ast.getSupers()){ + this.out.append(" :> ").append(s); + } + if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { + this.out.append(" {\n"); + for (SysmlAttribute annot: ast.getAnnotations()){ + this.out.append(indent + indent_base).append("attribute ").append(annot.getName()).append(": ").append(annot.getRef()).append(";\n"); + ///annot.accept(this, indent + indent_base); + } + for (SysmlBlockDefElement elem : ast.getElements()) { + elem.accept(this, indent + indent_base); + } + this.out.append(indent).append("}\n"); + } else { + this.out.append(";\n"); + } + } catch (IOException ignored) { + + } + return null; + } + @Override public Void visit(SysmlPackage ast, String indent) { try { From 83531fa9f70caf95bdb60d3c494a6382b68bf972 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 10:39:04 -0800 Subject: [PATCH 09/65] allow Instance compiler to return null if no Sysml concepts are referenced, make a SysmlCompilerUtils for shared code between the Sysml compilers --- .../org/clafer/instance/InstanceModel.java | 6 ++- .../org/sysml/compiler/AstSysmlCompiler.java | 14 ++--- .../sysml/compiler/InstanceSysmlCompiler.java | 53 ++++++++++--------- .../sysml/compiler/SysmlCompilerUtils.java | 19 +++++++ 4 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 src/main/java/org/sysml/compiler/SysmlCompilerUtils.java diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index a8ca3ccd..f2c44a21 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -68,8 +68,10 @@ public void printSysml(Appendable out, String indent) throws IOException { for (InstanceClafer top : topClafers) { SysmlPrinter pprinter = new SysmlPrinter(out); InstanceSysmlCompiler compiler = new InstanceSysmlCompiler(); - SysmlProperty model = compiler.compile(top, top); - pprinter.visit(model, indent); + // model can be null as the clafer model might not reference sysml concepts + Object _model = compiler.compile(top, top); + if (_model != null) + pprinter.visit((SysmlProperty) _model, indent); } } diff --git a/src/main/java/org/sysml/compiler/AstSysmlCompiler.java b/src/main/java/org/sysml/compiler/AstSysmlCompiler.java index 58de7113..1ba73850 100644 --- a/src/main/java/org/sysml/compiler/AstSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/AstSysmlCompiler.java @@ -20,14 +20,6 @@ public AstSysmlCompiler(){ this.typeMap.put("string", "String"); } - public String getPropertyId(String name){ - if (name.startsWith("c0_")){ - return name.substring(3); - } else { - return name; - } - } - public String[] getSuperClafers(AstClafer model){ Object spr = model.getSuperClafer(); if (spr == null){ @@ -35,7 +27,7 @@ public String[] getSuperClafers(AstClafer model){ } else { String[] rem = getSuperClafers((AstClafer) spr); String[] sprs = Arrays.copyOf(rem, rem.length + 1); - sprs[0] = getPropertyId(((AstClafer) spr).getName()); + sprs[0] = SysmlCompilerUtils.getPropertyId(((AstClafer) spr).getName()); System.arraycopy(rem, 0, sprs, 1, rem.length); return sprs; } @@ -44,7 +36,7 @@ public SysmlPropertyDef[] compile(AstModel model, AstModel topLevelModel) { ArrayList propDefs = new ArrayList(); for (AstAbstractClafer child: model.getAbstractRoot().getAbstractChildren()){ - String name = getPropertyId(child.getName()); + String name = SysmlCompilerUtils.getPropertyId(child.getName()); ArrayList attrs = new ArrayList(); for (AstClafer sub: child.getChildren()) { @@ -52,7 +44,7 @@ public SysmlPropertyDef[] compile(AstModel model, AstModel topLevelModel) { if (sref instanceof AstRef){ AstRef ref = (AstRef) sref; Object tgt = typeMap.get(ref.getTargetType().toString()); - String propName = getPropertyId(ref.getSourceType().getName()); + String propName = SysmlCompilerUtils.getPropertyId(ref.getSourceType().getName()); attrs.add(new SysmlAttribute(propName, tgt)); } } diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java index 91970f13..9c09f2cc 100644 --- a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -8,6 +8,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class InstanceSysmlCompiler { @@ -17,14 +19,6 @@ public InstanceSysmlCompiler(){ this.processedClafers = new ArrayList(); } - public String getPropertyId(String name){ - if (name.startsWith("c0_")){ - return name.substring(3); - } else { - return name; - } - } - int getMultiplicity(InstanceClafer model, AstClafer clafer){ int count = 0; if (model.getType().getName().equals(clafer.getName())){ @@ -40,7 +34,7 @@ ArrayList _getSuperClafers(AstClafer clafer, ArrayList hier){ if (clafer.getSuperClafer() == null) { return hier; } else { - hier.add(getPropertyId(clafer.getSuperClafer().getName())); + hier.add(SysmlCompilerUtils.getPropertyId(clafer.getSuperClafer().getName())); return _getSuperClafers(clafer.getSuperClafer(), hier); } } @@ -53,7 +47,7 @@ public String[] getSuperClafers(AstClafer clafer){ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) { // collect the identifier - String propertyName = getPropertyId(model.getType().getName()); + String propertyName =SysmlCompilerUtils.getPropertyId(model.getType().getName()); // get its supers String[] superClafers = getSuperClafers(model.getType()); @@ -63,12 +57,15 @@ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) ArrayList children = new ArrayList(); for (InstanceClafer child : model.getChildren()) { if (!processedClafers.contains(child.getType().getName())) { - SysmlProperty cchild = compile(child, topLevelModel); - if (!cchild.getPropertyType().getName().equals("unk")) { - children.add(cchild); - } else { - SysmlBlockDefElement[] schildren = cchild.getElements(); - children.addAll(new ArrayList(Arrays.asList(schildren))); + Object _cchild = compile(child, topLevelModel); + if (_cchild != null) { + SysmlProperty cchild = (SysmlProperty) _cchild; + if (!cchild.getPropertyType().getName().equals("unk")) { + children.add(cchild); + } else { + SysmlBlockDefElement[] schildren = cchild.getElements(); + children.addAll(new ArrayList(Arrays.asList(schildren))); + } } } } @@ -93,22 +90,26 @@ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) Object ref = child.getType().getRef(); if (ref != null) { AstRef aref = (AstRef) ref; - String aname = getPropertyId(aref.getSourceType().getName()); + String aname = SysmlCompilerUtils.getPropertyId(aref.getSourceType().getName()); Object refv = child.getRef(); annots.add(new SysmlAttribute(aname, refv)); } } // build a property object - return new SysmlProperty( - new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), - new SysmlPropertyType(propName), - propertyName, - children.toArray(new SysmlBlockDefElement[children.size()]), - annots.toArray(new SysmlAttribute[annots.size()]), - superTypes, - multiplicity - ); + if (propName.equals("unk") && children.size() == 0){ + return null; + } else { + return new SysmlProperty( + new SysmlBlockVisibility(SysmlVisibilityOption.PLUS), + new SysmlPropertyType(propName), + propertyName, + children.toArray(new SysmlBlockDefElement[children.size()]), + annots.toArray(new SysmlAttribute[annots.size()]), + superTypes, + multiplicity + ); + } } } diff --git a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java new file mode 100644 index 00000000..dd803cff --- /dev/null +++ b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java @@ -0,0 +1,19 @@ +package org.sysml.compiler; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class SysmlCompilerUtils { + public static String getPropertyId(String name){ + Pattern pattern = Pattern.compile("(c[0-9]+_).*", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(name); + boolean matchFound = matcher.find(); + //matcher.group() + if (matchFound){ + return name.substring(matcher.group(1).length()); + } else { + return name; + } + } + +} From 8c878d67b6272d3536b26b018a9c03e00b1ae73e Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 10:42:18 -0800 Subject: [PATCH 10/65] hoist getSuperClafers to the compiler utils --- .../org/sysml/compiler/AstSysmlCompiler.java | 14 +------------- .../sysml/compiler/InstanceSysmlCompiler.java | 17 +---------------- .../org/sysml/compiler/SysmlCompilerUtils.java | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/sysml/compiler/AstSysmlCompiler.java b/src/main/java/org/sysml/compiler/AstSysmlCompiler.java index 1ba73850..3ecfdb39 100644 --- a/src/main/java/org/sysml/compiler/AstSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/AstSysmlCompiler.java @@ -20,18 +20,6 @@ public AstSysmlCompiler(){ this.typeMap.put("string", "String"); } - public String[] getSuperClafers(AstClafer model){ - Object spr = model.getSuperClafer(); - if (spr == null){ - return new String[0]; - } else { - String[] rem = getSuperClafers((AstClafer) spr); - String[] sprs = Arrays.copyOf(rem, rem.length + 1); - sprs[0] = SysmlCompilerUtils.getPropertyId(((AstClafer) spr).getName()); - System.arraycopy(rem, 0, sprs, 1, rem.length); - return sprs; - } - } public SysmlPropertyDef[] compile(AstModel model, AstModel topLevelModel) { ArrayList propDefs = new ArrayList(); @@ -49,7 +37,7 @@ public SysmlPropertyDef[] compile(AstModel model, AstModel topLevelModel) { } } - String[] superClafers = getSuperClafers(child); + String[] superClafers = SysmlCompilerUtils.getSuperClafers(child); List hierarchy = Arrays.asList(superClafers); if (hierarchy.size() < 3){ continue; diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java index 9c09f2cc..dafd3ce6 100644 --- a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -30,27 +30,12 @@ int getMultiplicity(InstanceClafer model, AstClafer clafer){ return count; } - ArrayList _getSuperClafers(AstClafer clafer, ArrayList hier){ - if (clafer.getSuperClafer() == null) { - return hier; - } else { - hier.add(SysmlCompilerUtils.getPropertyId(clafer.getSuperClafer().getName())); - return _getSuperClafers(clafer.getSuperClafer(), hier); - } - } - - public String[] getSuperClafers(AstClafer clafer){ - ArrayList clafers = _getSuperClafers(clafer, new ArrayList()); - String[] clafers_arr = new String[clafers.size()]; - return clafers.toArray(clafers_arr); - } - public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) { // collect the identifier String propertyName =SysmlCompilerUtils.getPropertyId(model.getType().getName()); // get its supers - String[] superClafers = getSuperClafers(model.getType()); + String[] superClafers = SysmlCompilerUtils.getSuperClafers(model.getType()); List hierarchy = Arrays.asList(superClafers); // process the children diff --git a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java index dd803cff..40afe812 100644 --- a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java +++ b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java @@ -1,5 +1,8 @@ package org.sysml.compiler; +import org.clafer.ast.AstClafer; + +import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,4 +19,16 @@ public static String getPropertyId(String name){ } } + public static String[] getSuperClafers(AstClafer model){ + Object spr = model.getSuperClafer(); + if (spr == null){ + return new String[0]; + } else { + String[] rem = getSuperClafers((AstClafer) spr); + String[] sprs = Arrays.copyOf(rem, rem.length + 1); + sprs[0] = SysmlCompilerUtils.getPropertyId(((AstClafer) spr).getName()); + System.arraycopy(rem, 0, sprs, 1, rem.length); + return sprs; + } + } } From d02d62df12cef2cf6e7966c298d05b80f64d2848 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 16:53:09 -0800 Subject: [PATCH 11/65] address emptyblocktag --- src/main/java/org/clafer/instance/InstanceModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/clafer/instance/InstanceModel.java b/src/main/java/org/clafer/instance/InstanceModel.java index f2c44a21..fd97bcad 100644 --- a/src/main/java/org/clafer/instance/InstanceModel.java +++ b/src/main/java/org/clafer/instance/InstanceModel.java @@ -59,8 +59,8 @@ public InstanceClafer getTopClafer(AstConcreteClafer type) { * This is the start of exploring an automated product derivation tool * and the requirements around inferring a system model from clafer are * still tbd - * @param out - * @throws IOException + * + * */ public void printSysml(Appendable out, String indent) throws IOException { From 9c97f20d31e4a5182887ae7285353dc59b510e14 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 16:54:51 -0800 Subject: [PATCH 12/65] remove the bad exception handling --- src/main/java/org/sysml/pprinter/SysmlPrinter.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 7f4c2aed..31fbdffe 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -98,16 +98,12 @@ public Void visit(SysmlPropertyDef ast, String indent) { } @Override - public Void visit(SysmlPackage ast, String indent) { - try { - this.out.append(indent).append("package ").append(ast.getName()).append(" {").append("\n"); - for (SysmlBlockDefElement elem : ast.getElements()) { - elem.accept(this, indent + indent_base); - } - this.out.append(indent).append("}\n"); - } catch (IOException ignored) { - + public Void visit(SysmlPackage ast, String indent) throws IOException { + this.out.append(indent).append("package ").append(ast.getName()).append(" {").append("\n"); + for (SysmlBlockDefElement elem : ast.getElements()) { + elem.accept(this, indent + indent_base); } + this.out.append(indent).append("}\n"); return null; } } From 95b84d774f5dcdb3a7be71fe56612aca37a36ee3 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 16:57:31 -0800 Subject: [PATCH 13/65] allow visit to throw IOException --- .../java/org/sysml/ast/SysmlExprVisitor.java | 2 +- .../java/org/sysml/ast/SysmlProperty.java | 4 +- .../java/org/sysml/pprinter/SysmlPrinter.java | 49 +++++++++---------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/sysml/ast/SysmlExprVisitor.java b/src/main/java/org/sysml/ast/SysmlExprVisitor.java index f6e8cf3b..30320a6b 100644 --- a/src/main/java/org/sysml/ast/SysmlExprVisitor.java +++ b/src/main/java/org/sysml/ast/SysmlExprVisitor.java @@ -5,7 +5,7 @@ public interface SysmlExprVisitor { B visit(SysmlPackage ast, A a) throws IOException; - B visit(SysmlProperty ast, A a); + B visit(SysmlProperty ast, A a) throws IOException; B visit(SysmlAttribute ast, A a) throws IOException; diff --git a/src/main/java/org/sysml/ast/SysmlProperty.java b/src/main/java/org/sysml/ast/SysmlProperty.java index 8011d590..5f8f9747 100644 --- a/src/main/java/org/sysml/ast/SysmlProperty.java +++ b/src/main/java/org/sysml/ast/SysmlProperty.java @@ -2,6 +2,8 @@ import org.clafer.common.Check; +import java.io.IOException; + /** * SysML Property * @@ -76,7 +78,7 @@ public SysmlAttribute[] getAnnotations(){ } @Override - public B accept(SysmlExprVisitor visitor, A a) { + public B accept(SysmlExprVisitor visitor, A a) throws IOException { return visitor.visit(this, a); } } diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 31fbdffe..1d662ad4 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -34,35 +34,32 @@ public Void visit(SysmlAttribute ast, String indent) throws IOException { } @Override - public Void visit(SysmlProperty ast, String indent) { - try { - this.out - .append(indent) - .append(ast.getPropertyType().getName()) - .append(" ") - .append(ast.getName()) - ; - if (ast.getMultiplicity() > 1) { - this.out.append("[").append(String.valueOf(ast.getMultiplicity())).append("]"); + public Void visit(SysmlProperty ast, String indent) throws IOException { + this.out + .append(indent) + .append(ast.getPropertyType().getName()) + .append(" ") + .append(ast.getName()) + ; + if (ast.getMultiplicity() > 1) { + this.out.append("[").append(String.valueOf(ast.getMultiplicity())).append("]"); + } + for (String s: ast.getSupers()){ + this.out.append(" : ").append(s); + } + if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { + this.out.append(" {\n"); + for (SysmlAttribute annot: ast.getAnnotations()){ + annot.accept(this, indent + indent_base); } - for (String s: ast.getSupers()){ - this.out.append(" : ").append(s); + for (SysmlBlockDefElement elem : ast.getElements()) { + elem.accept(this, indent + indent_base); } - if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { - this.out.append(" {\n"); - for (SysmlAttribute annot: ast.getAnnotations()){ - annot.accept(this, indent + indent_base); - } - for (SysmlBlockDefElement elem : ast.getElements()) { - elem.accept(this, indent + indent_base); - } - this.out.append(indent).append("}\n"); - } else { - this.out.append(";\n"); - } - } catch (IOException ignored) { - + this.out.append(indent).append("}\n"); + } else { + this.out.append(";\n"); } + return null; } From 3d8f35210dcc2174c3f362a85a5e78042a685913 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:14:36 -0800 Subject: [PATCH 14/65] add maven CI/CD --- .github/workflows/maven.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000..2e6ecf07 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,30 @@ +name: Maven CI + +on: + push: + branches: [ $default-branch ] + pull_request: + branches: [ $default-branch ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + - name: Set up Maven + uses: stCarolas/setup-maven@v4.5 + with: + maven-version: 3.8.2 + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From a48271d0a13fcbd5dd96fb4894780e4bc577556c Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:19:59 -0800 Subject: [PATCH 15/65] fix unhandled exception catching and null dereference issue --- .../ast/analysis/PartialIntAnalyzer.java | 4 ++ .../java/org/sysml/ast/SysmlExprVisitor.java | 2 +- .../java/org/sysml/ast/SysmlPropertyDef.java | 4 +- .../java/org/sysml/pprinter/SysmlPrinter.java | 44 +++++++++---------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/clafer/ast/analysis/PartialIntAnalyzer.java b/src/main/java/org/clafer/ast/analysis/PartialIntAnalyzer.java index 877cc0a6..2ae4c3e4 100644 --- a/src/main/java/org/clafer/ast/analysis/PartialIntAnalyzer.java +++ b/src/main/java/org/clafer/ast/analysis/PartialIntAnalyzer.java @@ -184,6 +184,10 @@ private Map partialInts(Oracle oracle) { AstRef ref = AstUtil.getInheritedRef(clafer); if (ref != null) { Path[][] paths = pathsToClafers.get(clafer); + // NULL_DEREFERENCE + if (paths == null){ + return partialInts; + } Domain[] domains = new Domain[paths.length]; for (int i = 0; i < paths.length; i++) { Domain domain = Domains.EmptyDomain; diff --git a/src/main/java/org/sysml/ast/SysmlExprVisitor.java b/src/main/java/org/sysml/ast/SysmlExprVisitor.java index 30320a6b..7cb6f748 100644 --- a/src/main/java/org/sysml/ast/SysmlExprVisitor.java +++ b/src/main/java/org/sysml/ast/SysmlExprVisitor.java @@ -9,5 +9,5 @@ public interface SysmlExprVisitor { B visit(SysmlAttribute ast, A a) throws IOException; - B visit(SysmlPropertyDef sysmlPropertyDef, A a); + B visit(SysmlPropertyDef sysmlPropertyDef, A a) throws IOException; } diff --git a/src/main/java/org/sysml/ast/SysmlPropertyDef.java b/src/main/java/org/sysml/ast/SysmlPropertyDef.java index 4589bb12..dd61de05 100644 --- a/src/main/java/org/sysml/ast/SysmlPropertyDef.java +++ b/src/main/java/org/sysml/ast/SysmlPropertyDef.java @@ -2,6 +2,8 @@ import org.clafer.common.Check; +import java.io.IOException; + public class SysmlPropertyDef implements SysmlBlockDefElement { private final String name; @@ -57,7 +59,7 @@ public SysmlAttribute[] getAnnotations(){ } @Override - public B accept(SysmlExprVisitor visitor, A a) { + public B accept(SysmlExprVisitor visitor, A a) throws IOException { return visitor.visit(this, a); } } diff --git a/src/main/java/org/sysml/pprinter/SysmlPrinter.java b/src/main/java/org/sysml/pprinter/SysmlPrinter.java index 1d662ad4..459419b7 100644 --- a/src/main/java/org/sysml/pprinter/SysmlPrinter.java +++ b/src/main/java/org/sysml/pprinter/SysmlPrinter.java @@ -64,32 +64,28 @@ public Void visit(SysmlProperty ast, String indent) throws IOException { } @Override - public Void visit(SysmlPropertyDef ast, String indent) { - try { - this.out - .append(indent) - .append(ast.getPropertyType().getName()) - .append(" def ") - .append(ast.getName()) - ; - for (String s: ast.getSupers()){ - this.out.append(" :> ").append(s); + public Void visit(SysmlPropertyDef ast, String indent) throws IOException { + this.out + .append(indent) + .append(ast.getPropertyType().getName()) + .append(" def ") + .append(ast.getName()) + ; + for (String s: ast.getSupers()){ + this.out.append(" :> ").append(s); + } + if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { + this.out.append(" {\n"); + for (SysmlAttribute annot: ast.getAnnotations()){ + this.out.append(indent + indent_base).append("attribute ").append(annot.getName()).append(": ").append(annot.getRef()).append(";\n"); + ///annot.accept(this, indent + indent_base); } - if (ast.getElements().length > 0 || ast.getAnnotations().length > 0) { - this.out.append(" {\n"); - for (SysmlAttribute annot: ast.getAnnotations()){ - this.out.append(indent + indent_base).append("attribute ").append(annot.getName()).append(": ").append(annot.getRef()).append(";\n"); - ///annot.accept(this, indent + indent_base); - } - for (SysmlBlockDefElement elem : ast.getElements()) { - elem.accept(this, indent + indent_base); - } - this.out.append(indent).append("}\n"); - } else { - this.out.append(";\n"); + for (SysmlBlockDefElement elem : ast.getElements()) { + elem.accept(this, indent + indent_base); } - } catch (IOException ignored) { - + this.out.append(indent).append("}\n"); + } else { + this.out.append(";\n"); } return null; } From 487755b0b89c29e7698231476855b114107b6129 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:26:08 -0800 Subject: [PATCH 16/65] remove travis CI/CD --- .travis.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 334c5e23..00000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: java -sudo: false - -jdk: - - oraclejdk8 - -install: - - cd $HOME - - git clone --depth=50 https://github.com/chocoteam/choco3.git chocoteam/choco3 - - cd chocoteam/choco3 - - mvn install -DskipTests - - rm -rf $HOME/chocoteam/choco3 - -before_script: cd $TRAVIS_BUILD_DIR - -script: mvn test -DargLine="-Xmx1024m" From e79d0db9667c149691c2a103e88cdfffcecbd0de Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:27:30 -0800 Subject: [PATCH 17/65] run maven CI/CD on push --- .github/workflows/maven.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2e6ecf07..52a31242 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,10 +1,6 @@ name: Maven CI -on: - push: - branches: [ $default-branch ] - pull_request: - branches: [ $default-branch ] +on: [push] jobs: build: From f739f184daf37a96fc34ee319a5fce522f5d4d4b Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:32:54 -0800 Subject: [PATCH 18/65] bump Maven Dependency Tree Dependency Submission action --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 52a31242..a2453ff7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,4 +23,4 @@ jobs: # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + uses: advanced-security/maven-dependency-submission-action@v3.0.0 From f54dd1701fc12d0a7184e461d9bb24e8f0f1c16f Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:36:55 -0800 Subject: [PATCH 19/65] remove dependency graph upload for now --- .github/workflows/maven.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a2453ff7..48d5ff56 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,6 +21,3 @@ jobs: - name: Build with Maven run: mvn -B package --file pom.xml - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@v3.0.0 From 29bd949082fc774bafe813cdfeec837dbb225e87 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 28 Feb 2023 17:42:10 -0800 Subject: [PATCH 20/65] update CI/CD badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 137c3003..d2fec28f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://secure.travis-ci.org/gsdlab/chocosolver.svg)](http://travis-ci.org/gsdlab/chocosolver) +[![Build Status](https://github.com/EthanJamesLew/chocosolver-sysml/actions/workflows/maven.yml/badge.svg)](https://github.com/EthanJamesLew/chocosolver-sysml/actions/workflows/maven.yml) # chocosolver From 3c70b75dbcedc9731d8c04f9e6d5efa64b6fe44e Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 12:53:08 -0700 Subject: [PATCH 21/65] add plantuml package and start adding the ast classes / interfaces --- src/main/java/org/plantuml/ast/PlantumlConnection.java | 4 ++++ src/main/java/org/plantuml/ast/PlantumlExpr.java | 4 ++++ src/main/java/org/plantuml/ast/PlantumlExprVisitor.java | 4 ++++ src/main/java/org/plantuml/ast/PlantumlId.java | 4 ++++ src/main/java/org/plantuml/ast/PlantumlObject.java | 4 ++++ src/main/java/org/plantuml/ast/PlantumlProgram.java | 4 ++++ src/main/java/org/plantuml/ast/PlantumlProperty.java | 4 ++++ 7 files changed, 28 insertions(+) create mode 100644 src/main/java/org/plantuml/ast/PlantumlConnection.java create mode 100644 src/main/java/org/plantuml/ast/PlantumlExpr.java create mode 100644 src/main/java/org/plantuml/ast/PlantumlExprVisitor.java create mode 100644 src/main/java/org/plantuml/ast/PlantumlId.java create mode 100644 src/main/java/org/plantuml/ast/PlantumlObject.java create mode 100644 src/main/java/org/plantuml/ast/PlantumlProgram.java create mode 100644 src/main/java/org/plantuml/ast/PlantumlProperty.java diff --git a/src/main/java/org/plantuml/ast/PlantumlConnection.java b/src/main/java/org/plantuml/ast/PlantumlConnection.java new file mode 100644 index 00000000..c503c6ee --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlConnection.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public class PlantumlConnection { +} diff --git a/src/main/java/org/plantuml/ast/PlantumlExpr.java b/src/main/java/org/plantuml/ast/PlantumlExpr.java new file mode 100644 index 00000000..1b254527 --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlExpr.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public interface PlantumlExpr { +} diff --git a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java new file mode 100644 index 00000000..b7d5ffb4 --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public interface PlantumlExprVisitor { +} diff --git a/src/main/java/org/plantuml/ast/PlantumlId.java b/src/main/java/org/plantuml/ast/PlantumlId.java new file mode 100644 index 00000000..dc9e335a --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlId.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public interface PlantumlId { +} diff --git a/src/main/java/org/plantuml/ast/PlantumlObject.java b/src/main/java/org/plantuml/ast/PlantumlObject.java new file mode 100644 index 00000000..ce8278f1 --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlObject.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public class PlantumlObject { +} diff --git a/src/main/java/org/plantuml/ast/PlantumlProgram.java b/src/main/java/org/plantuml/ast/PlantumlProgram.java new file mode 100644 index 00000000..66df6f30 --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlProgram.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public class PlantumlProgram { +} diff --git a/src/main/java/org/plantuml/ast/PlantumlProperty.java b/src/main/java/org/plantuml/ast/PlantumlProperty.java new file mode 100644 index 00000000..0e1fad62 --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlProperty.java @@ -0,0 +1,4 @@ +package org.plantuml.ast; + +public class PlantumlProperty { +} From 1044332e57bb0b0b081489000f3610f95f6abfaf Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 13:32:08 -0700 Subject: [PATCH 22/65] add plantuml to cli inputs and check for conflicting options --- src/main/java/org/clafer/cli/Main.java | 3 ++- src/main/java/org/clafer/cli/Normal.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/clafer/cli/Main.java b/src/main/java/org/clafer/cli/Main.java index e7489c64..90f72721 100644 --- a/src/main/java/org/clafer/cli/Main.java +++ b/src/main/java/org/clafer/cli/Main.java @@ -26,11 +26,12 @@ public static void main(String[] args) throws Exception { accepts( "n", "Specify the maximum number of instances." ).withRequiredArg().ofType( Integer.class ); accepts( "noprint", "Don't print the instances to the console or a file"); accepts( "output", "Output instances to the given file." ).withRequiredArg().ofType( File.class ).describedAs( "text file" ); + accepts( "plantuml", "Print the clafer model as PlantUML" ); accepts( "prettify", "Use simple and pretty output format (not formal)." ); - accepts( "sysml", "Print the instances as SysMLv2" ); accepts( "repl", "Run in REPL (interactive) mode." ); accepts( "scope", "Override the default global scope value." ).withRequiredArg().ofType( Integer.class ); accepts( "search", "PreferSmallerInstances/PreferLargerInstances/Random" ).withRequiredArg().ofType( ClaferSearchStrategy.class ); + accepts( "sysml", "Print the instances as SysMLv2" ); accepts( "time", "Time how long it takes to find all instances (and print if it is turned on"); accepts( "v", "Run in validation mode; checks all assertions." ); accepts( "version", "Display the tool version" ); diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 50778f46..6caa4cbd 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -45,9 +45,17 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, int index = 0; // instance id boolean prettify = options.has("prettify"); boolean sysml = options.has("sysml"); + boolean plantuml = options.has("plantuml"); boolean printOff = options.has("noprint"); boolean dataTackingOn = options.has("dataFile"); boolean timeOn = options.has("time"); + + // check for conflicting options + if (plantuml && sysml) { + System.err.println("Bad CLI config: both plantuml and sysml are selected"); + return; + } + File dataFile; PrintStream dataStream = null; if (dataTackingOn) { @@ -65,6 +73,8 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, else n = -1; + + while (solver.find()) { if (dataTackingOn) { elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000; From 9205f45d38f0e861e9396d5a975fbef488ed01b0 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 13:56:11 -0700 Subject: [PATCH 23/65] flesh out compile and pprinter interfaces --- src/main/java/org/clafer/cli/Normal.java | 14 +++++++-- .../java/org/plantuml/ast/PlantumlExpr.java | 12 ++++++++ .../org/plantuml/ast/PlantumlExprVisitor.java | 11 ++++++- .../java/org/plantuml/ast/PlantumlId.java | 6 ++++ .../org/plantuml/ast/PlantumlProgram.java | 23 ++++++++++++++- .../compiler/AstPlantumlCompiler.java | 16 ++++++++++ .../plantuml/pprinter/PlantumlPrinter.java | 29 +++++++++++++++++++ 7 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java create mode 100644 src/main/java/org/plantuml/pprinter/PlantumlPrinter.java diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 6caa4cbd..8502c3b2 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -13,6 +13,9 @@ import org.clafer.objective.Objective; import org.clafer.scope.Scope; import org.clafer.ast.AstModel; +import org.plantuml.ast.PlantumlProgram; +import org.plantuml.compiler.AstPlantumlCompiler; +import org.plantuml.pprinter.PlantumlPrinter; import org.sysml.ast.SysmlProperty; import org.sysml.ast.SysmlPropertyDef; import org.sysml.compiler.AstSysmlCompiler; @@ -63,6 +66,15 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, dataStream = new PrintStream(dataFile); } + if (plantuml) { + AstModel top = javascriptFile.getModel(); + AstPlantumlCompiler compiler = new AstPlantumlCompiler(); + PlantumlProgram prog = compiler.compile(top); + PlantumlPrinter pprinter = new PlantumlPrinter(outStream); + pprinter.visit(prog, ""); + return; + } + double elapsedTime; long startTime = System.nanoTime(); @@ -73,8 +85,6 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, else n = -1; - - while (solver.find()) { if (dataTackingOn) { elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000; diff --git a/src/main/java/org/plantuml/ast/PlantumlExpr.java b/src/main/java/org/plantuml/ast/PlantumlExpr.java index 1b254527..c32e48da 100644 --- a/src/main/java/org/plantuml/ast/PlantumlExpr.java +++ b/src/main/java/org/plantuml/ast/PlantumlExpr.java @@ -1,4 +1,16 @@ package org.plantuml.ast; +import java.io.IOException; + public interface PlantumlExpr { + /** + * Dynamic dispatch on the visitor. + * + * @param the parameter type + * @param the return type + * @param visitor the visitor + * @param a the parameter + * @return the return value + */ + B accept(PlantumlExprVisitor visitor, A a) throws IOException; } diff --git a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java index b7d5ffb4..ec1e1b14 100644 --- a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java +++ b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java @@ -1,4 +1,13 @@ package org.plantuml.ast; -public interface PlantumlExprVisitor { +import java.io.IOException; + +/** + * AST Visitor + * + * We make AST visitors capable of throwing IOExecptions as it's convenient for pretty printers + * However, we could likely get rid of this throw some type of interface conversion. + */ +public interface PlantumlExprVisitor { + B visit(PlantumlProgram plantumlProgram, A a) throws IOException; } diff --git a/src/main/java/org/plantuml/ast/PlantumlId.java b/src/main/java/org/plantuml/ast/PlantumlId.java index dc9e335a..f1be4665 100644 --- a/src/main/java/org/plantuml/ast/PlantumlId.java +++ b/src/main/java/org/plantuml/ast/PlantumlId.java @@ -1,4 +1,10 @@ package org.plantuml.ast; public interface PlantumlId { + /** + * PlantUML + * + * @return the name of the identifier + */ + String getName(); } diff --git a/src/main/java/org/plantuml/ast/PlantumlProgram.java b/src/main/java/org/plantuml/ast/PlantumlProgram.java index 66df6f30..e7f097c4 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProgram.java +++ b/src/main/java/org/plantuml/ast/PlantumlProgram.java @@ -1,4 +1,25 @@ package org.plantuml.ast; -public class PlantumlProgram { +import org.sysml.ast.SysmlExpr; +import org.sysml.ast.SysmlExprVisitor; + +import java.io.IOException; + +/** + * Main PlantUML Program Element + * + * This is likely quite wrong. For our use case, we consider a PlantUML program as a collection + * of objects and connections. + */ +public class PlantumlProgram implements PlantumlExpr { + private PlantumlObject[] objects; + private PlantumlConnection[] connections; + + public PlantumlProgram() { + } + + @Override + public B accept(PlantumlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } } diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java new file mode 100644 index 00000000..e778d975 --- /dev/null +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -0,0 +1,16 @@ +package org.plantuml.compiler; + +import org.clafer.ast.AstModel; +import org.plantuml.ast.PlantumlProgram; + +/** + * Clafer AST to PlantUML + * + * Note that this compilation doesn't require instances, so we don't need to run the solver + * to compile. + */ +public class AstPlantumlCompiler { + public PlantumlProgram compile(AstModel model) { + return new PlantumlProgram(); + } +} diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java new file mode 100644 index 00000000..68a871e9 --- /dev/null +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -0,0 +1,29 @@ +package org.plantuml.pprinter; + +import org.plantuml.ast.PlantumlExprVisitor; +import org.plantuml.ast.PlantumlProgram; + +import java.io.IOException; + +/** + * PlantUML -> Text + * + * Visits the PlantUML AST and generates text output to an Appendable stream + */ +public class PlantumlPrinter implements PlantumlExprVisitor { + private final String indentBase; + private final Appendable out; + + public PlantumlPrinter(Appendable out) { + this.out = out; + this.indentBase = " "; + } + + // implement the visitor + @Override + public Void visit(PlantumlProgram ast, String indent) throws IOException { + this.out.append(indent).append("@startuml").append("\n"); + this.out.append(indent).append("@enduml").append("\n"); + return null; + } +} From 204c10251a10d5f9ed74629f52cc8aba6038707e Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 14:09:32 -0700 Subject: [PATCH 24/65] add fields to the plantuml ast --- .../org/plantuml/ast/PlantumlExprVisitor.java | 6 ++++ .../java/org/plantuml/ast/PlantumlObject.java | 25 ++++++++++++++++- .../org/plantuml/ast/PlantumlProgram.java | 8 ++++++ .../org/plantuml/ast/PlantumlProperty.java | 18 +++++++++++- .../plantuml/ast/PlantumlPropertyGroup.java | 28 +++++++++++++++++++ .../plantuml/pprinter/PlantumlPrinter.java | 18 ++++++++++-- 6 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/plantuml/ast/PlantumlPropertyGroup.java diff --git a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java index ec1e1b14..abc29980 100644 --- a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java +++ b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java @@ -10,4 +10,10 @@ */ public interface PlantumlExprVisitor { B visit(PlantumlProgram plantumlProgram, A a) throws IOException; + + B visit(PlantumlObject plantumlObject, A a) throws IOException; + + B visit(PlantumlPropertyGroup plantumlPropertyGroup, A a) throws IOException; + + B visit(PlantumlProperty plantumlProperty, A a) throws IOException; } diff --git a/src/main/java/org/plantuml/ast/PlantumlObject.java b/src/main/java/org/plantuml/ast/PlantumlObject.java index ce8278f1..24bebce8 100644 --- a/src/main/java/org/plantuml/ast/PlantumlObject.java +++ b/src/main/java/org/plantuml/ast/PlantumlObject.java @@ -1,4 +1,27 @@ package org.plantuml.ast; -public class PlantumlObject { +import java.io.IOException; + +public class PlantumlObject implements PlantumlExpr, PlantumlId { + private final String name; + private final PlantumlPropertyGroup[] propertyGroups; + + public PlantumlObject(String name, PlantumlPropertyGroup[] propertyGroups) { + this.name = name; + this.propertyGroups = propertyGroups; + } + + public PlantumlPropertyGroup[] getPropertyGroups() { + return propertyGroups; + } + + @Override + public String getName() { + return name; + } + + @Override + public B accept(PlantumlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } } diff --git a/src/main/java/org/plantuml/ast/PlantumlProgram.java b/src/main/java/org/plantuml/ast/PlantumlProgram.java index e7f097c4..9d3da6ee 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProgram.java +++ b/src/main/java/org/plantuml/ast/PlantumlProgram.java @@ -16,6 +16,14 @@ public class PlantumlProgram implements PlantumlExpr { private PlantumlConnection[] connections; public PlantumlProgram() { + this.objects = new PlantumlObject[0]; + this.connections = new PlantumlConnection[0]; + } + + public PlantumlProgram(PlantumlObject[] objects, PlantumlConnection[] connections) { + this.objects = objects; + this.connections = connections; + } @Override diff --git a/src/main/java/org/plantuml/ast/PlantumlProperty.java b/src/main/java/org/plantuml/ast/PlantumlProperty.java index 0e1fad62..ba85b23d 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProperty.java +++ b/src/main/java/org/plantuml/ast/PlantumlProperty.java @@ -1,4 +1,20 @@ package org.plantuml.ast; -public class PlantumlProperty { +import java.io.IOException; + +public class PlantumlProperty implements PlantumlExpr { + private final String prop; + + public PlantumlProperty(String prop) { + this.prop = prop; + } + + public String getProp(){ + return prop; + } + + @Override + public B accept(PlantumlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } } diff --git a/src/main/java/org/plantuml/ast/PlantumlPropertyGroup.java b/src/main/java/org/plantuml/ast/PlantumlPropertyGroup.java new file mode 100644 index 00000000..87b8fe47 --- /dev/null +++ b/src/main/java/org/plantuml/ast/PlantumlPropertyGroup.java @@ -0,0 +1,28 @@ +package org.plantuml.ast; + +import java.io.IOException; + +public class PlantumlPropertyGroup implements PlantumlId, PlantumlExpr { + + private final String name; + private PlantumlProperty[] properties; + + public PlantumlPropertyGroup(String name, PlantumlProperty[] properties) { + this.properties = properties; + this.name = name; + } + + public PlantumlProperty[] getProperties() { + return this.properties; + } + + @Override + public String getName() { + return name; + } + + @Override + public B accept(PlantumlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } +} diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index 68a871e9..8dbc2e7a 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -1,7 +1,6 @@ package org.plantuml.pprinter; -import org.plantuml.ast.PlantumlExprVisitor; -import org.plantuml.ast.PlantumlProgram; +import org.plantuml.ast.*; import java.io.IOException; @@ -26,4 +25,19 @@ public Void visit(PlantumlProgram ast, String indent) throws IOException { this.out.append(indent).append("@enduml").append("\n"); return null; } + + @Override + public Void visit(PlantumlObject plantumlObject, String s) throws IOException { + return null; + } + + @Override + public Void visit(PlantumlPropertyGroup plantumlPropertyGroup, String s) throws IOException { + return null; + } + + @Override + public Void visit(PlantumlProperty plantumlProperty, String s) throws IOException { + return null; + } } From 3ff20d6489ece636c0299eb8af50be1d25828dd9 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 17:15:36 -0700 Subject: [PATCH 25/65] pretty print objects --- .../org/plantuml/ast/PlantumlProgram.java | 4 + .../compiler/AstPlantumlCompiler.java | 97 ++++++++++++++++++- .../plantuml/pprinter/PlantumlPrinter.java | 18 ++++ 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/plantuml/ast/PlantumlProgram.java b/src/main/java/org/plantuml/ast/PlantumlProgram.java index 9d3da6ee..94991ba1 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProgram.java +++ b/src/main/java/org/plantuml/ast/PlantumlProgram.java @@ -26,6 +26,10 @@ public PlantumlProgram(PlantumlObject[] objects, PlantumlConnection[] connection } + public PlantumlObject[] getObjects(){ + return objects; + } + @Override public B accept(PlantumlExprVisitor visitor, A a) throws IOException { return visitor.visit(this, a); diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index e778d975..307d8b08 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -1,7 +1,14 @@ package org.plantuml.compiler; +import org.clafer.ast.AstAbstractClafer; +import org.clafer.ast.AstConcreteClafer; +import org.clafer.ast.AstConstraint; import org.clafer.ast.AstModel; -import org.plantuml.ast.PlantumlProgram; +import org.plantuml.ast.*; +import org.sysml.compiler.SysmlCompilerUtils; + +import java.util.ArrayList; +import java.util.List; /** * Clafer AST to PlantUML @@ -10,7 +17,93 @@ * to compile. */ public class AstPlantumlCompiler { + /** + * collect all concrete clafers + * @param concreteClafers concreteClafers held in a claferModel + * @return ArrayList of all nested clafers (abstract included) + */ + private ArrayList getConcreteObjects(List concreteClafers) { + ArrayList objs = new ArrayList(); + + for (AstConcreteClafer ast: concreteClafers) { + ArrayList pgs = new ArrayList(); + + ArrayList constrs = new ArrayList(); + for (AstConstraint constr: ast.getConstraints()) { + constrs.add(new PlantumlProperty(constr.toString())); + } + + if (constrs.size() > 0){ + pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); + } + + // create an object and add it + PlantumlObject obj = new PlantumlObject( + SysmlCompilerUtils.getPropertyId(ast.getName()), + pgs.toArray(new PlantumlPropertyGroup[0]) + ); + objs.add(obj); + + // add all of its children + // TODO: check for collisions? + //objs.addAll(getAbstractObjects(ast.getAbstractChildren())); + objs.addAll(getConcreteObjects(ast.getChildren())); + } + return objs; + } + + /** + * collect all abstract clafers (give them an abstract attribute) + * @param abstractClafers abstractClafers held in a claferModel + * @return ArrayList of all nested clafers (concrete included) + */ + private ArrayList getAbstractObjects(List abstractClafers) { + ArrayList objs = new ArrayList(); + + for (AstAbstractClafer ast: abstractClafers) { + ArrayList pgs = new ArrayList(); + + ArrayList constrs = new ArrayList(); + for (AstConstraint constr: ast.getConstraints()) { + constrs.add(new PlantumlProperty(constr.toString())); + } + + if (constrs.size() > 0){ + pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); + } + + // create an object and add it + PlantumlObject obj = new PlantumlObject( + SysmlCompilerUtils.getPropertyId(ast.getName()), + pgs.toArray(new PlantumlPropertyGroup[0]) + ); + objs.add(obj); + + // add all of its children + // TODO: check for collisions? + objs.addAll(getAbstractObjects(ast.getAbstractChildren())); + objs.addAll(getConcreteObjects(ast.getChildren())); + } + return objs; + } + + /** + * top-level object collector + * @param model the root clafer model + * @return ArrayList of all clafers (abstract and concrete) suitable for PlantUML objects + */ + private ArrayList getObjects(AstModel model) { + ArrayList objs = getAbstractObjects(model.getAbstracts()); + objs.addAll(getConcreteObjects(model.getChildren())); + return objs; + } + public PlantumlProgram compile(AstModel model) { - return new PlantumlProgram(); + ArrayList objs = getObjects(model); + + return new PlantumlProgram( + objs.toArray(new PlantumlObject[0]), + new PlantumlConnection[0] + ); } } diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index 8dbc2e7a..39f497a9 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -22,22 +22,40 @@ public PlantumlPrinter(Appendable out) { @Override public Void visit(PlantumlProgram ast, String indent) throws IOException { this.out.append(indent).append("@startuml").append("\n"); + for (PlantumlObject obj: ast.getObjects()){ + obj.accept(this, indent + indentBase); + } this.out.append(indent).append("@enduml").append("\n"); return null; } @Override public Void visit(PlantumlObject plantumlObject, String s) throws IOException { + this.out.append(s).append("object ").append(plantumlObject.getName()); + if (plantumlObject.getPropertyGroups().length > 0) { + this.out.append(" {\n"); + for (PlantumlPropertyGroup grp: plantumlObject.getPropertyGroups()){ + grp.accept(this, s + indentBase); + } + this.out.append(s).append("}\n"); + } else { + this.out.append("\n"); + } return null; } @Override public Void visit(PlantumlPropertyGroup plantumlPropertyGroup, String s) throws IOException { + this.out.append(s).append(".. ").append(plantumlPropertyGroup.getName()).append(" ..").append("\n"); + for (PlantumlProperty prop: plantumlPropertyGroup.getProperties()){ + prop.accept(this, s); + } return null; } @Override public Void visit(PlantumlProperty plantumlProperty, String s) throws IOException { + this.out.append(s).append(plantumlProperty.getProp()).append('\n'); return null; } } From 25138b5b615cfcc8e79fc1a31b38f693059fa451 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 17:49:30 -0700 Subject: [PATCH 26/65] add basic connections compilation --- .../org/plantuml/ast/PlantumlConnection.java | 43 +++++++++++- .../org/plantuml/ast/PlantumlExprVisitor.java | 2 + .../org/plantuml/ast/PlantumlProgram.java | 4 ++ .../compiler/AstPlantumlCompiler.java | 70 +++++++++++++++++-- .../plantuml/pprinter/PlantumlPrinter.java | 20 ++++++ 5 files changed, 134 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/plantuml/ast/PlantumlConnection.java b/src/main/java/org/plantuml/ast/PlantumlConnection.java index c503c6ee..cdf15c73 100644 --- a/src/main/java/org/plantuml/ast/PlantumlConnection.java +++ b/src/main/java/org/plantuml/ast/PlantumlConnection.java @@ -1,4 +1,45 @@ package org.plantuml.ast; -public class PlantumlConnection { +import java.io.IOException; + +public class PlantumlConnection implements PlantumlExpr { + private final String fromObj; + private final String toObj; + private final char fromConn; + private final char toConn; + + private final String label; + + public PlantumlConnection(String fromObj, String toObj, char fromConn, char toConn, String label){ + this.fromObj = fromObj; + this.toObj = toObj; + this.fromConn = fromConn; + this.toConn = toConn; + this.label = label; + } + + public String getFromObj(){ + return fromObj; + } + + public String getToObj(){ + return toObj; + } + + public char getToConn(){ + return toConn; + } + + public char getFromConn(){ + return fromConn; + } + + public String getLabel(){ + return label; + } + + @Override + public B accept(PlantumlExprVisitor visitor, A a) throws IOException { + return visitor.visit(this, a); + } } diff --git a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java index abc29980..115ef7f1 100644 --- a/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java +++ b/src/main/java/org/plantuml/ast/PlantumlExprVisitor.java @@ -16,4 +16,6 @@ public interface PlantumlExprVisitor { B visit(PlantumlPropertyGroup plantumlPropertyGroup, A a) throws IOException; B visit(PlantumlProperty plantumlProperty, A a) throws IOException; + + B visit(PlantumlConnection plantumlConnection, A a) throws IOException; } diff --git a/src/main/java/org/plantuml/ast/PlantumlProgram.java b/src/main/java/org/plantuml/ast/PlantumlProgram.java index 94991ba1..0cfad97d 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProgram.java +++ b/src/main/java/org/plantuml/ast/PlantumlProgram.java @@ -30,6 +30,10 @@ public PlantumlObject[] getObjects(){ return objects; } + public PlantumlConnection[] getConnections(){ + return connections; + } + @Override public B accept(PlantumlExprVisitor visitor, A a) throws IOException { return visitor.visit(this, a); diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 307d8b08..6dc1bc6c 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.WeakHashMap; /** * Clafer AST to PlantUML @@ -42,7 +43,10 @@ private ArrayList getConcreteObjects(List con SysmlCompilerUtils.getPropertyId(ast.getName()), pgs.toArray(new PlantumlPropertyGroup[0]) ); - objs.add(obj); + + if (!obj.getName().startsWith("#")) { + objs.add(obj); + } // add all of its children // TODO: check for collisions? @@ -77,7 +81,10 @@ private ArrayList getAbstractObjects(List abs SysmlCompilerUtils.getPropertyId(ast.getName()), pgs.toArray(new PlantumlPropertyGroup[0]) ); - objs.add(obj); + + if (!obj.getName().startsWith("#")){ + objs.add(obj); + } // add all of its children // TODO: check for collisions? @@ -98,12 +105,67 @@ private ArrayList getObjects(AstModel model) { return objs; } + private ArrayList getConcreteConnections(List abstractClafers) { + ArrayList connections = new ArrayList(); + + for (AstConcreteClafer ast: abstractClafers) { + String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); + String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); + if (!(fromObj.startsWith("#") || toObj.startsWith("#"))) { + connections.add( + new PlantumlConnection( + fromObj, + toObj, + '-', + '*', + "" + ) + ); + } + + connections.addAll(getConcreteConnections(ast.getChildren())); + } + + return connections; + } + + private ArrayList getAbstractConnections(List abstractClafers) { + ArrayList connections = new ArrayList(); + + for (AstAbstractClafer ast: abstractClafers) { + String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); + String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); + if (!(fromObj.startsWith("#") || toObj.startsWith("#"))) { + connections.add( + new PlantumlConnection( + fromObj, + toObj, + '-', + '*', + "" + ) + ); + } + + connections.addAll(getAbstractConnections(ast.getAbstractChildren())); + connections.addAll(getConcreteConnections(ast.getChildren())); + } + + return connections; + } + + private ArrayList getConnections(AstModel model) { + ArrayList connections = getAbstractConnections(model.getAbstracts()); + connections.addAll(getConcreteConnections(model.getChildren())); + return connections; + } + public PlantumlProgram compile(AstModel model) { ArrayList objs = getObjects(model); + ArrayList conns = getConnections(model); return new PlantumlProgram( - objs.toArray(new PlantumlObject[0]), - new PlantumlConnection[0] + objs.toArray(new PlantumlObject[0]), conns.toArray(new PlantumlConnection[0]) ); } } diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index 39f497a9..bc6684e5 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -25,6 +25,10 @@ public Void visit(PlantumlProgram ast, String indent) throws IOException { for (PlantumlObject obj: ast.getObjects()){ obj.accept(this, indent + indentBase); } + this.out.append('\n'); + for (PlantumlConnection conn: ast.getConnections()){ + conn.accept(this, indent + indentBase); + } this.out.append(indent).append("@enduml").append("\n"); return null; } @@ -58,4 +62,20 @@ public Void visit(PlantumlProperty plantumlProperty, String s) throws IOExceptio this.out.append(s).append(plantumlProperty.getProp()).append('\n'); return null; } + + @Override + public Void visit(PlantumlConnection plantumlConnection, String s) throws IOException { + this.out.append(s) + .append(plantumlConnection.getFromObj()) + .append(" ").append(plantumlConnection.getFromConn()).append("-").append(plantumlConnection.getToConn()) + .append(" ") + .append(plantumlConnection.getToObj()); + if (plantumlConnection.getLabel().length() > 0){ + this.out.append(" ") + .append(": ") + .append(plantumlConnection.getLabel()); + } + this.out.append('\n'); + return null; + } } From b912367c28d55c171290ec229767d65af2ccf78a Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 18:11:37 -0700 Subject: [PATCH 27/65] add labels, support or and xor --- .../compiler/AstPlantumlCompiler.java | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 6dc1bc6c..935e960e 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -1,9 +1,6 @@ package org.plantuml.compiler; -import org.clafer.ast.AstAbstractClafer; -import org.clafer.ast.AstConcreteClafer; -import org.clafer.ast.AstConstraint; -import org.clafer.ast.AstModel; +import org.clafer.ast.*; import org.plantuml.ast.*; import org.sysml.compiler.SysmlCompilerUtils; @@ -105,20 +102,40 @@ private ArrayList getObjects(AstModel model) { return objs; } - private ArrayList getConcreteConnections(List abstractClafers) { + private ArrayList getConcreteConnections(List concreteClafers) { ArrayList connections = new ArrayList(); - for (AstConcreteClafer ast: abstractClafers) { + for (AstConcreteClafer ast: concreteClafers) { String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); + String label = ""; + char toConn = '*'; + char fromConn = '-'; + if (ast.getParent().hasGroupCard()){ + if (ast.getParent().getGroupCard().toString().equals("1")){ + fromConn = '+'; + } else if (ast.getParent().getGroupCard().toString().equals("1..*")) { + fromConn = 'o'; + } + } + if (ast.getCard().toString().equals("0..1")){ + toConn = 'o'; + } else if (ast.getCard().toString().equals("1")) { + toConn = '-'; + } else { + if (ast.getCard().toString().startsWith("0")) { + toConn = 'o'; + } + label = ast.getCard().toString(); + } if (!(fromObj.startsWith("#") || toObj.startsWith("#"))) { connections.add( new PlantumlConnection( fromObj, toObj, - '-', - '*', - "" + fromConn, + toConn, + label ) ); } @@ -135,14 +152,24 @@ private ArrayList getAbstractConnections(List Date: Sun, 12 Mar 2023 18:15:11 -0700 Subject: [PATCH 28/65] close dataStream to properly handle dynamic allocation --- src/main/java/org/clafer/cli/Normal.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 8502c3b2..436a2777 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -72,6 +72,9 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, PlantumlProgram prog = compiler.compile(top); PlantumlPrinter pprinter = new PlantumlPrinter(outStream); pprinter.visit(prog, ""); + if (dataStream != null){ + dataStream.close(); + } return; } @@ -137,5 +140,10 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, System.out.println("Generated " + (n == -1 ? "all " : "") + index + " optimal instance(s) within the scope\n"); } } + + // make sure to close this resource + if (dataStream != null){ + dataStream.close(); + } } } From 1eaae9407092c4df31f0a596f8d4382c6fb689e4 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 18:19:47 -0700 Subject: [PATCH 29/65] make or arrowhead a filled shape --- src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 935e960e..7ae2679e 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -115,7 +115,7 @@ private ArrayList getConcreteConnections(List getAbstractConnections(List Date: Sun, 12 Mar 2023 18:21:39 -0700 Subject: [PATCH 30/65] make mandatory arrowhead for multiplicity one features --- src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 7ae2679e..ab8eddc9 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -121,7 +121,7 @@ private ArrayList getConcreteConnections(List Date: Sun, 12 Mar 2023 19:54:33 -0700 Subject: [PATCH 31/65] fold refs into object attributes --- .../org/plantuml/ast/PlantumlConnection.java | 16 +++++ .../compiler/AstPlantumlCompiler.java | 72 +++++++++++++++++-- .../plantuml/pprinter/PlantumlPrinter.java | 4 +- 3 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/plantuml/ast/PlantumlConnection.java b/src/main/java/org/plantuml/ast/PlantumlConnection.java index cdf15c73..c1fed20d 100644 --- a/src/main/java/org/plantuml/ast/PlantumlConnection.java +++ b/src/main/java/org/plantuml/ast/PlantumlConnection.java @@ -8,6 +8,8 @@ public class PlantumlConnection implements PlantumlExpr { private final char fromConn; private final char toConn; + private final char lineChar; + private final String label; public PlantumlConnection(String fromObj, String toObj, char fromConn, char toConn, String label){ @@ -16,6 +18,16 @@ public PlantumlConnection(String fromObj, String toObj, char fromConn, char toCo this.fromConn = fromConn; this.toConn = toConn; this.label = label; + this.lineChar = '-'; + } + + public PlantumlConnection(String fromObj, String toObj, char fromConn, char toConn, String label, char lineChar){ + this.fromObj = fromObj; + this.toObj = toObj; + this.fromConn = fromConn; + this.toConn = toConn; + this.label = label; + this.lineChar = lineChar; } public String getFromObj(){ @@ -38,6 +50,10 @@ public String getLabel(){ return label; } + public char getLineChar(){ + return lineChar; + } + @Override public B accept(PlantumlExprVisitor visitor, A a) throws IOException { return visitor.visit(this, a); diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index ab8eddc9..6c648c1f 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.WeakHashMap; /** @@ -13,6 +14,8 @@ * * Note that this compilation doesn't require instances, so we don't need to run the solver * to compile. + * + * TODO: this should be refactored to cut down the code re-use. */ public class AstPlantumlCompiler { /** @@ -24,6 +27,9 @@ private ArrayList getConcreteObjects(List con ArrayList objs = new ArrayList(); for (AstConcreteClafer ast: concreteClafers) { + if (ast.getRef() != null) { + continue; + } ArrayList pgs = new ArrayList(); ArrayList constrs = new ArrayList(); @@ -62,6 +68,9 @@ private ArrayList getAbstractObjects(List abs ArrayList objs = new ArrayList(); for (AstAbstractClafer ast: abstractClafers) { + if (ast.getRef() != null) { + continue; + } ArrayList pgs = new ArrayList(); ArrayList constrs = new ArrayList(); @@ -69,6 +78,18 @@ private ArrayList getAbstractObjects(List abs constrs.add(new PlantumlProperty(constr.toString())); } + ArrayList refs = new ArrayList(); + for (AstConcreteClafer clafer: ast.getChildren()){ + AstRef ref = clafer.getRef(); + if (ref != null) { + refs.add(new PlantumlProperty(ref.toString())); + } + } + + if (refs.size() > 0){ + pgs.add(new PlantumlPropertyGroup("Attributes", refs.toArray(new PlantumlProperty[0]))); + } + if (constrs.size() > 0){ pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); } @@ -106,8 +127,12 @@ private ArrayList getConcreteConnections(List connections = new ArrayList(); for (AstConcreteClafer ast: concreteClafers) { + if (ast.getRef() != null) { + continue; + } String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); + Card card = ast.getCard(); String label = ""; char toConn = '*'; char fromConn = '-'; @@ -118,15 +143,15 @@ private ArrayList getConcreteConnections(List getConcreteConnections(List', + "", + '.' + ) + ); + } + } + connections.addAll(getConcreteConnections(ast.getChildren())); } @@ -150,6 +193,9 @@ private ArrayList getAbstractConnections(List connections = new ArrayList(); for (AstAbstractClafer ast: abstractClafers) { + if (ast.getRef() != null) { + continue; + } String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); String label = ""; @@ -174,6 +220,24 @@ private ArrayList getAbstractConnections(List', + "", + '.' + ) + ); + } + } + connections.addAll(getAbstractConnections(ast.getAbstractChildren())); connections.addAll(getConcreteConnections(ast.getChildren())); } diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index bc6684e5..be64cfc5 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -59,7 +59,7 @@ public Void visit(PlantumlPropertyGroup plantumlPropertyGroup, String s) throws @Override public Void visit(PlantumlProperty plantumlProperty, String s) throws IOException { - this.out.append(s).append(plantumlProperty.getProp()).append('\n'); + this.out.append(s).append("* ").append(plantumlProperty.getProp()).append('\n'); return null; } @@ -67,7 +67,7 @@ public Void visit(PlantumlProperty plantumlProperty, String s) throws IOExceptio public Void visit(PlantumlConnection plantumlConnection, String s) throws IOException { this.out.append(s) .append(plantumlConnection.getFromObj()) - .append(" ").append(plantumlConnection.getFromConn()).append("-").append(plantumlConnection.getToConn()) + .append(" ").append(plantumlConnection.getFromConn()).append(plantumlConnection.getLineChar()).append(plantumlConnection.getToConn()) .append(" ") .append(plantumlConnection.getToObj()); if (plantumlConnection.getLabel().length() > 0){ From ab5bea8b02a479eefee28ad01f4bc5147d2c4344 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 20:09:07 -0700 Subject: [PATCH 32/65] remove Optimizing message for plantuml (which does not optimize) --- src/main/java/org/clafer/cli/Normal.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 436a2777..4b528bb1 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -25,12 +25,16 @@ public class Normal { // Running the model itself(instantiating or optimizing) public static void runNormal(JavascriptFile javascriptFile, OptionSet options, PrintStream outStream) throws Exception { + //do this first to cut irrelevant optimizing message + boolean plantuml = options.has("plantuml"); Objective[] objectives = javascriptFile.getObjectives(); - if (objectives.length == 0) - System.out.println("Instantiating..."); - else - System.out.println("Optimizing..."); + if (!plantuml){ + if (objectives.length == 0) + System.out.println("Instantiating..."); + else + System.out.println("Optimizing..."); + } // handle scopes Scope scope = Utils.resolveScopes(javascriptFile, options); @@ -48,7 +52,6 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, int index = 0; // instance id boolean prettify = options.has("prettify"); boolean sysml = options.has("sysml"); - boolean plantuml = options.has("plantuml"); boolean printOff = options.has("noprint"); boolean dataTackingOn = options.has("dataFile"); boolean timeOn = options.has("time"); From 71e9e85788024c1c149b5cb947920c2f34945e99 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Sun, 12 Mar 2023 20:12:48 -0700 Subject: [PATCH 33/65] fix confusing renaming assignment --- .../org/plantuml/compiler/AstPlantumlCompiler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 6c648c1f..359dde4a 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -169,11 +169,12 @@ private ArrayList getConcreteConnections(List', "", @@ -224,11 +225,12 @@ private ArrayList getAbstractConnections(List', "", From a81d95182e14e68686b4fa8f678a3ab580996f13 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Wed, 15 Mar 2023 13:45:11 -0800 Subject: [PATCH 34/65] Minor tweaks for prettier diagrams --- .../org/plantuml/ast/PlantumlProperty.java | 8 ++++ .../compiler/AstPlantumlCompiler.java | 38 +++++++++++++------ .../plantuml/pprinter/PlantumlPrinter.java | 2 + 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/plantuml/ast/PlantumlProperty.java b/src/main/java/org/plantuml/ast/PlantumlProperty.java index ba85b23d..690f10f0 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProperty.java +++ b/src/main/java/org/plantuml/ast/PlantumlProperty.java @@ -6,6 +6,14 @@ public class PlantumlProperty implements PlantumlExpr { private final String prop; public PlantumlProperty(String prop) { + prop = prop.replace("c0_", ""); // Remove "c0_" prefix (instances) + prop = prop.replace("this . ", ""); // Remove "this ." prefix (self attributes) + prop = prop.replace(" . ref", ""); // Remove "ref ." prefix (type defs) + prop = prop.replace(" ", " "); // Only single space + prop = prop.replace(" . ", "."); // Remove spaces between names + prop = prop.replace("[", ""); // Remove square brackets + prop = prop.replace("]", ""); // Remove square brackets + prop = prop.replace("parent.", ""); // Remove `parent.` from the fully qualified name this.prop = prop; } diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 359dde4a..ca5d86fe 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -36,14 +36,20 @@ private ArrayList getConcreteObjects(List con for (AstConstraint constr: ast.getConstraints()) { constrs.add(new PlantumlProperty(constr.toString())); } - if (constrs.size() > 0){ pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); } + // Display inheritance as a style notation + AstClafer superClafer = ast.getSuperClafer(); + String scName = ""; + if (superClafer != null & !SysmlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#")) { + scName = " <<" + SysmlCompilerUtils.getPropertyId(superClafer.getName()) + ">>"; + } + // create an object and add it PlantumlObject obj = new PlantumlObject( - SysmlCompilerUtils.getPropertyId(ast.getName()), + SysmlCompilerUtils.getPropertyId(ast.getName() + scName), pgs.toArray(new PlantumlPropertyGroup[0]) ); @@ -138,20 +144,29 @@ private ArrayList getConcreteConnections(List getConcreteConnections(List Date: Wed, 15 Mar 2023 14:02:11 -0800 Subject: [PATCH 35/65] Added annotations for the TOML config file --- pom.xml | 5 +++++ src/main/java/org/clafer/cli/Main.java | 1 + src/main/java/org/plantuml/ast/PlantumlProperty.java | 1 + src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java | 3 +++ src/main/java/org/plantuml/pprinter/PlantumlPrinter.java | 4 ++-- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 465dc443..9f34d6ac 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,11 @@ 4.11 test + + org.tomlj + tomlj + 1.1.0 + diff --git a/src/main/java/org/clafer/cli/Main.java b/src/main/java/org/clafer/cli/Main.java index 90f72721..a7735d13 100644 --- a/src/main/java/org/clafer/cli/Main.java +++ b/src/main/java/org/clafer/cli/Main.java @@ -20,6 +20,7 @@ public static void main(String[] args) throws Exception { accepts( "file", "Input file in .cfr or .js format" ).withRequiredArg().ofType( File.class ) .describedAs( "Clafer model file (.cfr) or Clafer Javascript file (.js)." ); accepts( "help", "Show help.").forHelp(); + accepts( "config", "Config file in .toml format" ).withRequiredArg().ofType( File.class ); accepts( "maxint", "Specify maximum integer value." ).withRequiredArg().ofType( Integer.class ); accepts( "minint", "Specify minimum integer value." ).withRequiredArg().ofType( Integer.class ); accepts( "moo", "Run in multi-objective optimization mode." ); diff --git a/src/main/java/org/plantuml/ast/PlantumlProperty.java b/src/main/java/org/plantuml/ast/PlantumlProperty.java index 690f10f0..4c741d5d 100644 --- a/src/main/java/org/plantuml/ast/PlantumlProperty.java +++ b/src/main/java/org/plantuml/ast/PlantumlProperty.java @@ -6,6 +6,7 @@ public class PlantumlProperty implements PlantumlExpr { private final String prop; public PlantumlProperty(String prop) { + // NOTE: do you want to make this configurable though the TOML file? That might be a stretch... prop = prop.replace("c0_", ""); // Remove "c0_" prefix (instances) prop = prop.replace("this . ", ""); // Remove "this ." prefix (self attributes) prop = prop.replace(" . ref", ""); // Remove "ref ." prefix (type defs) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index ca5d86fe..d427d468 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -41,6 +41,7 @@ private ArrayList getConcreteObjects(List con } // Display inheritance as a style notation + // NOTE: this could be made optional AstClafer superClafer = ast.getSuperClafer(); String scName = ""; if (superClafer != null & !SysmlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#")) { @@ -142,6 +143,7 @@ private ArrayList getConcreteConnections(List getConcreteConnections(List Date: Wed, 15 Mar 2023 15:33:51 -0700 Subject: [PATCH 36/65] add config toml to input argparse, create builder that can be built from the toml --- src/main/java/org/clafer/cli/Main.java | 1 + src/main/java/org/clafer/cli/Normal.java | 5 +- .../compiler/AstPlantumlCompiler.java | 53 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/clafer/cli/Main.java b/src/main/java/org/clafer/cli/Main.java index a7735d13..d3c86e68 100644 --- a/src/main/java/org/clafer/cli/Main.java +++ b/src/main/java/org/clafer/cli/Main.java @@ -28,6 +28,7 @@ public static void main(String[] args) throws Exception { accepts( "noprint", "Don't print the instances to the console or a file"); accepts( "output", "Output instances to the given file." ).withRequiredArg().ofType( File.class ).describedAs( "text file" ); accepts( "plantuml", "Print the clafer model as PlantUML" ); + accepts( "plantuml-config", "TOML configuration file for Clafer->PlantUML compiler" ); accepts( "prettify", "Use simple and pretty output format (not formal)." ); accepts( "repl", "Run in REPL (interactive) mode." ); accepts( "scope", "Override the default global scope value." ).withRequiredArg().ofType( Integer.class ); diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index 4b528bb1..deb10ed8 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -70,8 +70,11 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, } if (plantuml) { + File plantumlConfigFile = (File) options.valueOf("plantuml-config"); AstModel top = javascriptFile.getModel(); - AstPlantumlCompiler compiler = new AstPlantumlCompiler(); + AstPlantumlCompiler compiler = AstPlantumlCompiler + .AstPlantumlCompilerBuilder + .buildFromToml(plantumlConfigFile); PlantumlProgram prog = compiler.compile(top); PlantumlPrinter pprinter = new PlantumlPrinter(outStream); pprinter.visit(prog, ""); diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index d427d468..575e3442 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -3,7 +3,13 @@ import org.clafer.ast.*; import org.plantuml.ast.*; import org.sysml.compiler.SysmlCompilerUtils; +import org.tomlj.Toml; +import org.tomlj.TomlParseResult; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -18,6 +24,13 @@ * TODO: this should be refactored to cut down the code re-use. */ public class AstPlantumlCompiler { + public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder){ + } + + public AstPlantumlCompiler(){ + } + + /** * collect all concrete clafers * @param concreteClafers concreteClafers held in a claferModel @@ -280,4 +293,44 @@ public PlantumlProgram compile(AstModel model) { objs.toArray(new PlantumlObject[0]), conns.toArray(new PlantumlConnection[0]) ); } + + + /** + * builder class to configure the Compiler + * we anticipate a lot of options here, so we use a builder + */ + public static class AstPlantumlCompilerBuilder{ + + private final boolean includeConstraints; + private final boolean includeSuperClafers; + private final int printLevels; + + public AstPlantumlCompilerBuilder(){ + this.includeConstraints = true; + this.includeSuperClafers = true; + this.printLevels = -1; + } + + public AstPlantumlCompiler build(){ + return new AstPlantumlCompiler(this); + } + + + /** + * read builder from an input toml file (null returns defaults) + * @param tomlFile config file + * @return a compiler object + * @throws IOException + */ + static public AstPlantumlCompiler buildFromToml(File tomlFile) throws IOException { + if (tomlFile == null) { + return new AstPlantumlCompiler(); + } else { + Path source = Paths.get(tomlFile.toURI()); + TomlParseResult result = Toml.parse(source); + result.errors().forEach(error -> System.err.println(error.toString())); + return new AstPlantumlCompiler(); + } + } + } } From 57fc8a5ec10fd9a1ff5ae79e4bfc6e21fb10b6bb Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 15 Mar 2023 16:14:04 -0700 Subject: [PATCH 37/65] add levels, superClafers, constraints include fields --- src/main/java/org/clafer/cli/Main.java | 2 +- .../compiler/AstPlantumlCompiler.java | 127 +++++++++++------- 2 files changed, 81 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/clafer/cli/Main.java b/src/main/java/org/clafer/cli/Main.java index d3c86e68..4a7c8f4e 100644 --- a/src/main/java/org/clafer/cli/Main.java +++ b/src/main/java/org/clafer/cli/Main.java @@ -28,7 +28,7 @@ public static void main(String[] args) throws Exception { accepts( "noprint", "Don't print the instances to the console or a file"); accepts( "output", "Output instances to the given file." ).withRequiredArg().ofType( File.class ).describedAs( "text file" ); accepts( "plantuml", "Print the clafer model as PlantUML" ); - accepts( "plantuml-config", "TOML configuration file for Clafer->PlantUML compiler" ); + accepts( "plantuml-config", "TOML configuration file for Clafer->PlantUML compiler" ).withRequiredArg().ofType( File.class ).describedAs("toml file"); accepts( "prettify", "Use simple and pretty output format (not formal)." ); accepts( "repl", "Run in REPL (interactive) mode." ); accepts( "scope", "Override the default global scope value." ).withRequiredArg().ofType( Integer.class ); diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 575e3442..ff9384ad 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.WeakHashMap; /** * Clafer AST to PlantUML @@ -24,13 +23,16 @@ * TODO: this should be refactored to cut down the code re-use. */ public class AstPlantumlCompiler { - public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder){ - } + private final boolean includeConstraints; + private final boolean includeSuperClafers; + private final int includeLevels; - public AstPlantumlCompiler(){ + public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder){ + this.includeConstraints = builder.includeConstraints; + this.includeSuperClafers = builder.includeSuperClafers; + this.includeLevels = builder.includeLevels; } - /** * collect all concrete clafers * @param concreteClafers concreteClafers held in a claferModel @@ -49,7 +51,7 @@ private ArrayList getConcreteObjects(List con for (AstConstraint constr: ast.getConstraints()) { constrs.add(new PlantumlProperty(constr.toString())); } - if (constrs.size() > 0){ + if (constrs.size() > 0 && this.includeConstraints){ pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); } @@ -110,7 +112,7 @@ private ArrayList getAbstractObjects(List abs pgs.add(new PlantumlPropertyGroup("Attributes", refs.toArray(new PlantumlProperty[0]))); } - if (constrs.size() > 0){ + if (constrs.size() > 0 && this.includeConstraints){ pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); } @@ -195,24 +197,26 @@ private ArrayList getConcreteConnections(List', - "", - '.' - ) - ); + if (this.includeSuperClafers) { + AstClafer superClafer = ast.getSuperClafer(); + if (superClafer != null) { + String scName = SysmlCompilerUtils.getPropertyId(superClafer.getName()); + // NOTE: a little hack to ignore the basic abstract clafers + // this should be configurable + if (!scName.startsWith("#") & (!scName.equals("PowerFeature")) & (!scName.equals("WaveformFeature"))) { + fromObj = toObj; + toObj = scName; + connections.add( + new PlantumlConnection( + fromObj, + toObj, + '.', + '>', + "", + '.' + ) + ); + } } } @@ -253,22 +257,24 @@ private ArrayList getAbstractConnections(List', - "", - '.' - ) - ); + if (this.includeSuperClafers) { + AstClafer superClafer = ast.getSuperClafer(); + if (superClafer != null) { + String scName = SysmlCompilerUtils.getPropertyId(superClafer.getName()); + if (!scName.startsWith("#")) { + fromObj = toObj; + toObj = scName; + connections.add( + new PlantumlConnection( + fromObj, + toObj, + '.', + '>', + "", + '.' + ) + ); + } } } @@ -301,20 +307,34 @@ public PlantumlProgram compile(AstModel model) { */ public static class AstPlantumlCompilerBuilder{ - private final boolean includeConstraints; - private final boolean includeSuperClafers; - private final int printLevels; + private boolean includeConstraints; + private boolean includeSuperClafers; + private int includeLevels; public AstPlantumlCompilerBuilder(){ this.includeConstraints = true; this.includeSuperClafers = true; - this.printLevels = -1; + this.includeLevels = -1; } public AstPlantumlCompiler build(){ return new AstPlantumlCompiler(this); } + public AstPlantumlCompilerBuilder setIncludeConstraints(boolean includeConstraints){ + this.includeConstraints = includeConstraints; + return this; + } + + public AstPlantumlCompilerBuilder setIncludeSuperClafers(boolean includeSuperClafers){ + this.includeSuperClafers = includeSuperClafers; + return this; + } + + public AstPlantumlCompilerBuilder setLevels(int levels){ + this.includeLevels = levels; + return this; + } /** * read builder from an input toml file (null returns defaults) @@ -324,12 +344,25 @@ public AstPlantumlCompiler build(){ */ static public AstPlantumlCompiler buildFromToml(File tomlFile) throws IOException { if (tomlFile == null) { - return new AstPlantumlCompiler(); + return new AstPlantumlCompiler(new AstPlantumlCompilerBuilder()); } else { + // TODO: Toml4J seems to do better error checking than this Path source = Paths.get(tomlFile.toURI()); TomlParseResult result = Toml.parse(source); result.errors().forEach(error -> System.err.println(error.toString())); - return new AstPlantumlCompiler(); + + AstPlantumlCompilerBuilder build = new AstPlantumlCompilerBuilder(); + + String field = "include.super_clafers"; + if (result.contains(field)) build.setIncludeSuperClafers(Boolean.TRUE.equals(result.getBoolean(field))); + + field = "include.constraints"; + if (result.contains(field)) build.setIncludeConstraints(Boolean.TRUE.equals(result.getBoolean(field))); + + field = "include.levels"; + if (result.contains(field)) build.setLevels(Objects.requireNonNull(result.getLong(field)).intValue()); + + return build.build(); } } } From 9152193b63a41f078c28fbbe4e4a659e608ed6ca Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 15 Mar 2023 16:44:23 -0700 Subject: [PATCH 38/65] implement level, blacklist--update tomlj --- pom.xml | 4 +- .../compiler/AstPlantumlCompiler.java | 76 ++++++++++++++----- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 9f34d6ac..6838c139 100644 --- a/pom.xml +++ b/pom.xml @@ -89,8 +89,8 @@ maven-compiler-plugin 3.5.1 - 1.8 - 1.8 + 16 + 16 diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index ff9384ad..e6f9cf5a 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -4,6 +4,7 @@ import org.plantuml.ast.*; import org.sysml.compiler.SysmlCompilerUtils; import org.tomlj.Toml; +import org.tomlj.TomlArray; import org.tomlj.TomlParseResult; import java.io.File; @@ -13,6 +14,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Clafer AST to PlantUML @@ -27,10 +30,23 @@ public class AstPlantumlCompiler { private final boolean includeSuperClafers; private final int includeLevels; + private final List clafersBlacklist; + public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder){ this.includeConstraints = builder.includeConstraints; this.includeSuperClafers = builder.includeSuperClafers; this.includeLevels = builder.includeLevels; + this.clafersBlacklist = builder.clafersBlacklist; + } + + boolean checkBlacklist(String name){ + for (String regex: this.clafersBlacklist){ + Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(name); + boolean matchFound = matcher.find(); + if (matchFound) return true; + } + return false; } /** @@ -38,7 +54,7 @@ public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder){ * @param concreteClafers concreteClafers held in a claferModel * @return ArrayList of all nested clafers (abstract included) */ - private ArrayList getConcreteObjects(List concreteClafers) { + private ArrayList getConcreteObjects(List concreteClafers, int level) { ArrayList objs = new ArrayList(); for (AstConcreteClafer ast: concreteClafers) { @@ -69,14 +85,14 @@ private ArrayList getConcreteObjects(List con pgs.toArray(new PlantumlPropertyGroup[0]) ); - if (!obj.getName().startsWith("#")) { + if (!obj.getName().startsWith("#") && !checkBlacklist(obj.getName())) { objs.add(obj); } // add all of its children // TODO: check for collisions? //objs.addAll(getAbstractObjects(ast.getAbstractChildren())); - objs.addAll(getConcreteObjects(ast.getChildren())); + if (level < this.includeLevels) objs.addAll(getConcreteObjects(ast.getChildren(), level + 1)); } return objs; } @@ -86,7 +102,7 @@ private ArrayList getConcreteObjects(List con * @param abstractClafers abstractClafers held in a claferModel * @return ArrayList of all nested clafers (concrete included) */ - private ArrayList getAbstractObjects(List abstractClafers) { + private ArrayList getAbstractObjects(List abstractClafers, int level) { ArrayList objs = new ArrayList(); for (AstAbstractClafer ast: abstractClafers) { @@ -122,14 +138,14 @@ private ArrayList getAbstractObjects(List abs pgs.toArray(new PlantumlPropertyGroup[0]) ); - if (!obj.getName().startsWith("#")){ + if (!obj.getName().startsWith("#") && !checkBlacklist(obj.getName())){ objs.add(obj); } // add all of its children // TODO: check for collisions? - objs.addAll(getAbstractObjects(ast.getAbstractChildren())); - objs.addAll(getConcreteObjects(ast.getChildren())); + if (level < this.includeLevels) objs.addAll(getAbstractObjects(ast.getAbstractChildren(), level + 1)); + if (level < this.includeLevels) objs.addAll(getConcreteObjects(ast.getChildren(), level + 1)); } return objs; } @@ -140,12 +156,12 @@ private ArrayList getAbstractObjects(List abs * @return ArrayList of all clafers (abstract and concrete) suitable for PlantUML objects */ private ArrayList getObjects(AstModel model) { - ArrayList objs = getAbstractObjects(model.getAbstracts()); - objs.addAll(getConcreteObjects(model.getChildren())); + ArrayList objs = getAbstractObjects(model.getAbstracts(), 0); + objs.addAll(getConcreteObjects(model.getChildren(), 0)); return objs; } - private ArrayList getConcreteConnections(List concreteClafers) { + private ArrayList getConcreteConnections(List concreteClafers, int level) { ArrayList connections = new ArrayList(); for (AstConcreteClafer ast: concreteClafers) { @@ -185,7 +201,7 @@ private ArrayList getConcreteConnections(List getConcreteConnections(List getConcreteConnections(List getAbstractConnections(List abstractClafers) { + private ArrayList getAbstractConnections(List abstractClafers, int level) { ArrayList connections = new ArrayList(); for (AstAbstractClafer ast: abstractClafers) { @@ -245,7 +261,7 @@ private ArrayList getAbstractConnections(List getAbstractConnections(List getAbstractConnections(List getConnections(AstModel model) { - ArrayList connections = getAbstractConnections(model.getAbstracts()); - connections.addAll(getConcreteConnections(model.getChildren())); + ArrayList connections = getAbstractConnections(model.getAbstracts(), 0); + connections.addAll(getConcreteConnections(model.getChildren(), 0)); return connections; } @@ -311,10 +327,13 @@ public static class AstPlantumlCompilerBuilder{ private boolean includeSuperClafers; private int includeLevels; + private List clafersBlacklist; + public AstPlantumlCompilerBuilder(){ this.includeConstraints = true; this.includeSuperClafers = true; - this.includeLevels = -1; + this.includeLevels = Integer.MAX_VALUE; + this.clafersBlacklist = new ArrayList(); } public AstPlantumlCompiler build(){ @@ -336,6 +355,11 @@ public AstPlantumlCompilerBuilder setLevels(int levels){ return this; } + public AstPlantumlCompilerBuilder setClafersBlacklist(List bl){ + this.clafersBlacklist = bl; + return this; + } + /** * read builder from an input toml file (null returns defaults) * @param tomlFile config file @@ -362,6 +386,16 @@ static public AstPlantumlCompiler buildFromToml(File tomlFile) throws IOExceptio field = "include.levels"; if (result.contains(field)) build.setLevels(Objects.requireNonNull(result.getLong(field)).intValue()); + field = "blacklist.clafers"; + if (result.contains(field)) { + List blacklist = result.getArrayOrEmpty(field) + .toList() + .stream() + .map(o -> Objects.toString(o, null)) + .toList(); + build.setClafersBlacklist(blacklist); + } + return build.build(); } } From 04fcb3bcd3901f3f3e4d743e3fcd12736197d2c1 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 15 Mar 2023 18:06:11 -0700 Subject: [PATCH 39/65] clean up the label, arrowhead code, add super_clafers_components to optionally print superClafer information --- .../compiler/AstPlantumlCompiler.java | 222 +++++++++++------- 1 file changed, 131 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index e6f9cf5a..9abf8415 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -4,7 +4,6 @@ import org.plantuml.ast.*; import org.sysml.compiler.SysmlCompilerUtils; import org.tomlj.Toml; -import org.tomlj.TomlArray; import org.tomlj.TomlParseResult; import java.io.File; @@ -19,28 +18,36 @@ /** * Clafer AST to PlantUML - * + *

* Note that this compilation doesn't require instances, so we don't need to run the solver * to compile. - * + *

* TODO: this should be refactored to cut down the code re-use. */ public class AstPlantumlCompiler { private final boolean includeConstraints; - private final boolean includeSuperClafers; + private final boolean includeSuperClafersConnections; + private final boolean includeSuperClafersComponents; private final int includeLevels; private final List clafersBlacklist; - public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder){ + public AstPlantumlCompiler(AstPlantumlCompilerBuilder builder) { this.includeConstraints = builder.includeConstraints; - this.includeSuperClafers = builder.includeSuperClafers; + this.includeSuperClafersConnections = builder.includeSuperClafersConnections; + this.includeSuperClafersComponents = builder.includeSuperClafersComponents; this.includeLevels = builder.includeLevels; this.clafersBlacklist = builder.clafersBlacklist; } - boolean checkBlacklist(String name){ - for (String regex: this.clafersBlacklist){ + /** + * Check that a clafer name matches an entry in the blacklist + * + * @param name + * @return whether name should be blacklisted + */ + boolean checkBlacklist(String name) { + for (String regex : this.clafersBlacklist) { Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(name); boolean matchFound = matcher.find(); @@ -49,25 +56,39 @@ boolean checkBlacklist(String name){ return false; } + /** + * Check that a clafer is allowed + *

+ * Note that we ignore all names beginning with # because they are + * generated by the clafer compiler and implicit to the user's code. + * + * @param name + * @return whether name should be compiled + */ + private boolean checkClaferName(String name) { + return !checkBlacklist(name) && !name.startsWith("#"); + } + /** * collect all concrete clafers + * * @param concreteClafers concreteClafers held in a claferModel * @return ArrayList of all nested clafers (abstract included) */ private ArrayList getConcreteObjects(List concreteClafers, int level) { ArrayList objs = new ArrayList(); - for (AstConcreteClafer ast: concreteClafers) { - if (ast.getRef() != null) { - continue; - } + for (AstConcreteClafer ast : concreteClafers) { + if (ast.getRef() != null) continue; + + // build the property groups ArrayList pgs = new ArrayList(); ArrayList constrs = new ArrayList(); - for (AstConstraint constr: ast.getConstraints()) { + for (AstConstraint constr : ast.getConstraints()) { constrs.add(new PlantumlProperty(constr.toString())); } - if (constrs.size() > 0 && this.includeConstraints){ + if (constrs.size() > 0 && this.includeConstraints) { pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); } @@ -75,7 +96,7 @@ private ArrayList getConcreteObjects(List con // NOTE: this could be made optional AstClafer superClafer = ast.getSuperClafer(); String scName = ""; - if (superClafer != null & !SysmlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#")) { + if (superClafer != null && !SysmlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#") && this.includeSuperClafersComponents) { scName = " <<" + SysmlCompilerUtils.getPropertyId(superClafer.getName()) + ">>"; } @@ -85,13 +106,10 @@ private ArrayList getConcreteObjects(List con pgs.toArray(new PlantumlPropertyGroup[0]) ); - if (!obj.getName().startsWith("#") && !checkBlacklist(obj.getName())) { - objs.add(obj); - } + if (checkClaferName(obj.getName())) objs.add(obj); // add all of its children // TODO: check for collisions? - //objs.addAll(getAbstractObjects(ast.getAbstractChildren())); if (level < this.includeLevels) objs.addAll(getConcreteObjects(ast.getChildren(), level + 1)); } return objs; @@ -99,36 +117,39 @@ private ArrayList getConcreteObjects(List con /** * collect all abstract clafers (give them an abstract attribute) + * * @param abstractClafers abstractClafers held in a claferModel * @return ArrayList of all nested clafers (concrete included) */ private ArrayList getAbstractObjects(List abstractClafers, int level) { ArrayList objs = new ArrayList(); - for (AstAbstractClafer ast: abstractClafers) { + for (AstAbstractClafer ast : abstractClafers) { if (ast.getRef() != null) { continue; } + + // build out the constraints and attributes property groups ArrayList pgs = new ArrayList(); ArrayList constrs = new ArrayList(); - for (AstConstraint constr: ast.getConstraints()) { + for (AstConstraint constr : ast.getConstraints()) { constrs.add(new PlantumlProperty(constr.toString())); } ArrayList refs = new ArrayList(); - for (AstConcreteClafer clafer: ast.getChildren()){ + for (AstConcreteClafer clafer : ast.getChildren()) { AstRef ref = clafer.getRef(); if (ref != null) { refs.add(new PlantumlProperty(ref.toString())); } } - if (refs.size() > 0){ + if (refs.size() > 0) { pgs.add(new PlantumlPropertyGroup("Attributes", refs.toArray(new PlantumlProperty[0]))); } - if (constrs.size() > 0 && this.includeConstraints){ + if (constrs.size() > 0 && this.includeConstraints) { pgs.add(new PlantumlPropertyGroup("Constraints", constrs.toArray(new PlantumlProperty[0]))); } @@ -138,9 +159,7 @@ private ArrayList getAbstractObjects(List abs pgs.toArray(new PlantumlPropertyGroup[0]) ); - if (!obj.getName().startsWith("#") && !checkBlacklist(obj.getName())){ - objs.add(obj); - } + if (checkClaferName(obj.getName())) objs.add(obj); // add all of its children // TODO: check for collisions? @@ -152,6 +171,7 @@ private ArrayList getAbstractObjects(List abs /** * top-level object collector + * * @param model the root clafer model * @return ArrayList of all clafers (abstract and concrete) suitable for PlantUML objects */ @@ -161,47 +181,63 @@ private ArrayList getObjects(AstModel model) { return objs; } + private char getEndArrowhead(boolean hasGroupCard, Card card, Card groupCard) { + char toConn = '*'; + if (hasGroupCard) toConn = '-'; + else { + // No Alternative/OR + if (card.toString().equals("0..1")) toConn = 'o'; + else if (card.toString().equals("1")) toConn = '*'; + else { + if (card.toString().startsWith("0")) toConn = 'o'; + } + } + return toConn; + } + + private char getStartArrowhead(boolean hasGroupCard, Card groupCard) { + char fromConn = '-'; + if (hasGroupCard) { + if (groupCard.toString().equals("1")) { + // This is an OR (exactly one) + fromConn = '+'; + } else if (groupCard.toString().equals("1..*")) { + // This is an Alternative (1 or more) + fromConn = ')'; + } + } + return fromConn; + } + + private String getLabel(boolean hasGroupCard, Card card) { + String label = ""; + if (!hasGroupCard) { + // No Alternative/OR + if (!card.toString().equals("0..1") && !card.toString().equals("1")) { + label = card.toString(); + } + } + return label; + } + private ArrayList getConcreteConnections(List concreteClafers, int level) { ArrayList connections = new ArrayList(); - for (AstConcreteClafer ast: concreteClafers) { + for (AstConcreteClafer ast : concreteClafers) { if (ast.getRef() != null) { continue; } String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); + Card card = ast.getCard(); - String label = ""; - char toConn = '*'; - char fromConn = '-'; - // NOTE: this is pretty ugly - if (ast.getParent().hasGroupCard()){ - if (ast.getParent().getGroupCard().toString().equals("1")){ - // This is an OR (exactly one) - fromConn = '+'; - } else if (ast.getParent().getGroupCard().toString().equals("1..*")) { - // This is an Alternative (1 or more) - fromConn = ')'; - } - // Common setting - toConn = '-'; - if (!card.toString().equals("0..1")){ - label = card.toString(); - } - } else { - // No Alternative/OR - if (card.toString().equals("0..1")){ - toConn = 'o'; - } else if (card.toString().equals("1")) { - toConn = '*'; - } else { - if (card.toString().startsWith("0")) { - toConn = 'o'; - } - label = card.toString(); - } - } - if (!(fromObj.startsWith("#") || toObj.startsWith("#")) && !(checkBlacklist(fromObj) || checkBlacklist(toObj))) { + boolean hasGroupCard = ast.getParent().hasGroupCard(); + + String label = getLabel(hasGroupCard, card); + char fromConn = getStartArrowhead(hasGroupCard, ast.getParent().getGroupCard()); + char toConn = getEndArrowhead(hasGroupCard, card, ast.getParent().getGroupCard()); + + if (checkClaferName(fromObj) && checkClaferName(toObj)) { connections.add( new PlantumlConnection( fromObj, @@ -213,13 +249,11 @@ private ArrayList getConcreteConnections(List getConcreteConnections(List getAbstractConnections(List abstractClafers, int level) { ArrayList connections = new ArrayList(); - for (AstAbstractClafer ast: abstractClafers) { - if (ast.getRef() != null) { - continue; - } + for (AstAbstractClafer ast : abstractClafers) { + if (ast.getRef() != null) continue; + + // collect the connection labels String fromObj = SysmlCompilerUtils.getPropertyId(ast.getParent().getName()); String toObj = SysmlCompilerUtils.getPropertyId(ast.getName()); String label = ""; char toConn = '*'; - char fromConn = '-'; - if (ast.getParent().hasGroupCard()){ - if (ast.getParent().getGroupCard().toString().equals("1")){ - fromConn = '+'; - } else if (ast.getParent().getGroupCard().toString().equals("1..*")) { - fromConn = '*'; - } - } - if (!(fromObj.startsWith("#") || toObj.startsWith("#")) && !(checkBlacklist(fromObj) || checkBlacklist(toObj))) { + char fromConn = getStartArrowhead(ast.getParent().hasGroupCard(), ast.getParent().getGroupCard()); + + if (checkClaferName(fromObj) && checkClaferName(toObj)) { connections.add( new PlantumlConnection( fromObj, @@ -273,7 +301,7 @@ private ArrayList getAbstractConnections(List getAbstractConnections(List conns = getConnections(model); return new PlantumlProgram( - objs.toArray(new PlantumlObject[0]), conns.toArray(new PlantumlConnection[0]) + objs.toArray(new PlantumlObject[0]), conns.toArray(new PlantumlConnection[0]) ); } @@ -321,47 +350,55 @@ public PlantumlProgram compile(AstModel model) { * builder class to configure the Compiler * we anticipate a lot of options here, so we use a builder */ - public static class AstPlantumlCompilerBuilder{ + public static class AstPlantumlCompilerBuilder { private boolean includeConstraints; - private boolean includeSuperClafers; + private boolean includeSuperClafersConnections; + private boolean includeSuperClafersComponents; private int includeLevels; private List clafersBlacklist; - public AstPlantumlCompilerBuilder(){ + public AstPlantumlCompilerBuilder() { this.includeConstraints = true; - this.includeSuperClafers = true; + this.includeSuperClafersConnections = true; + this.includeSuperClafersComponents = true; this.includeLevels = Integer.MAX_VALUE; this.clafersBlacklist = new ArrayList(); } - public AstPlantumlCompiler build(){ + public AstPlantumlCompiler build() { return new AstPlantumlCompiler(this); } - public AstPlantumlCompilerBuilder setIncludeConstraints(boolean includeConstraints){ + public AstPlantumlCompilerBuilder setIncludeConstraints(boolean includeConstraints) { this.includeConstraints = includeConstraints; return this; } - public AstPlantumlCompilerBuilder setIncludeSuperClafers(boolean includeSuperClafers){ - this.includeSuperClafers = includeSuperClafers; + public AstPlantumlCompilerBuilder setIncludeSuperClafersConnections(boolean includeSuperClafers) { + this.includeSuperClafersConnections = includeSuperClafers; return this; } - public AstPlantumlCompilerBuilder setLevels(int levels){ + public AstPlantumlCompilerBuilder setIncludeSuperClafersComponents(boolean includeSuperClafers) { + this.includeSuperClafersComponents = includeSuperClafers; + return this; + } + + public AstPlantumlCompilerBuilder setLevels(int levels) { this.includeLevels = levels; return this; } - public AstPlantumlCompilerBuilder setClafersBlacklist(List bl){ + public AstPlantumlCompilerBuilder setClafersBlacklist(List bl) { this.clafersBlacklist = bl; return this; } /** * read builder from an input toml file (null returns defaults) + * * @param tomlFile config file * @return a compiler object * @throws IOException @@ -377,8 +414,11 @@ static public AstPlantumlCompiler buildFromToml(File tomlFile) throws IOExceptio AstPlantumlCompilerBuilder build = new AstPlantumlCompilerBuilder(); - String field = "include.super_clafers"; - if (result.contains(field)) build.setIncludeSuperClafers(Boolean.TRUE.equals(result.getBoolean(field))); + String field = "include.super_clafers_connections"; + if (result.contains(field)) build.setIncludeSuperClafersConnections(Boolean.TRUE.equals(result.getBoolean(field))); + + field = "include.super_clafers_components"; + if (result.contains(field)) build.setIncludeSuperClafersComponents(Boolean.TRUE.equals(result.getBoolean(field))); field = "include.constraints"; if (result.contains(field)) build.setIncludeConstraints(Boolean.TRUE.equals(result.getBoolean(field))); From 284682ba05db7d83a9c2cab3709c5e736f113676 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 15 Mar 2023 18:09:39 -0700 Subject: [PATCH 40/65] revert pom.xml maven plugins config --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6838c139..9f34d6ac 100644 --- a/pom.xml +++ b/pom.xml @@ -89,8 +89,8 @@ maven-compiler-plugin 3.5.1 - 16 - 16 + 1.8 + 1.8 From 9fcec60e08a5ec21b947130aaa8b9883f0526eab Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 16 Mar 2023 09:00:39 -0800 Subject: [PATCH 41/65] Replace stream API with a loop (recommended by IntelliJ) so it works with OpenJDK 11 --- .../org/plantuml/compiler/AstPlantumlCompiler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 9abf8415..0585d45b 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -428,11 +428,12 @@ static public AstPlantumlCompiler buildFromToml(File tomlFile) throws IOExceptio field = "blacklist.clafers"; if (result.contains(field)) { - List blacklist = result.getArrayOrEmpty(field) - .toList() - .stream() - .map(o -> Objects.toString(o, null)) - .toList(); + List blacklist = new ArrayList<>(); + for (Object o : result.getArrayOrEmpty(field) + .toList()) { + String s = Objects.toString(o, null); + blacklist.add(s); + } build.setClafersBlacklist(blacklist); } From 1a64eb434bc24f781698d0ef87f3507af3cc4be1 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 16 Mar 2023 09:51:34 -0800 Subject: [PATCH 42/65] Add an optional plantuml header --- src/main/java/org/clafer/cli/Normal.java | 2 +- .../plantuml/pprinter/PlantumlPrinter.java | 30 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index deb10ed8..fb1163a2 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -76,7 +76,7 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, .AstPlantumlCompilerBuilder .buildFromToml(plantumlConfigFile); PlantumlProgram prog = compiler.compile(top); - PlantumlPrinter pprinter = new PlantumlPrinter(outStream); + PlantumlPrinter pprinter = new PlantumlPrinter(outStream, plantumlConfigFile); pprinter.visit(prog, ""); if (dataStream != null){ dataStream.close(); diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index 2d7d1070..807c83f5 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -1,8 +1,13 @@ package org.plantuml.pprinter; import org.plantuml.ast.*; +import org.tomlj.Toml; +import org.tomlj.TomlParseResult; +import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; /** * PlantUML -> Text @@ -12,18 +17,35 @@ public class PlantumlPrinter implements PlantumlExprVisitor { private final String indentBase; private final Appendable out; + private String header; - public PlantumlPrinter(Appendable out) { + /** + * Initialize a printer + * @param out appendable stream + * @param tomlFile config file + * @throws IOException + */ + public PlantumlPrinter(Appendable out, File tomlFile) throws IOException { this.out = out; this.indentBase = " "; + if (tomlFile == null) { + this.header = ""; + } else { + // NOTE: silly that we are redoing what is done in AstPlantumlCompilerBuilder to get the header + Path source = Paths.get(tomlFile.toURI()); + TomlParseResult result = Toml.parse(source); + result.errors().forEach(error -> System.err.println(error.toString())); + String field = "include.header"; + if (result.contains(field)) { + this.header = result.getString(field); + } + } } // implement the visitor @Override public Void visit(PlantumlProgram ast, String indent) throws IOException { - this.out.append(indent).append("@startuml").append("\n"); - // @podrmic: here we want to insert an optional string from the config file - // so probably in toml: `plantuml_string = "include sometemplate" etc + this.out.append(indent).append("@startuml").append("\n").append(this.header).append("\n"); for (PlantumlObject obj: ast.getObjects()){ obj.accept(this, indent + indentBase); } From 71dddf8de529733a5cf550e5e0cf63dad6fc1637 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 16 Mar 2023 09:53:07 -0800 Subject: [PATCH 43/65] Handle null header case better --- src/main/java/org/plantuml/pprinter/PlantumlPrinter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index 807c83f5..68470356 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -28,9 +28,8 @@ public class PlantumlPrinter implements PlantumlExprVisitor { public PlantumlPrinter(Appendable out, File tomlFile) throws IOException { this.out = out; this.indentBase = " "; - if (tomlFile == null) { - this.header = ""; - } else { + this.header = ""; + if (tomlFile != null) { // NOTE: silly that we are redoing what is done in AstPlantumlCompilerBuilder to get the header Path source = Paths.get(tomlFile.toURI()); TomlParseResult result = Toml.parse(source); From 2baf043fc27c5ccb4d5a4f9219c3a1147b75ce75 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 16 Mar 2023 10:28:58 -0800 Subject: [PATCH 44/65] Added examples from ClaferMOOVisualizer --- examples/AndroidSampleMoo_2.cfr | 58 +++++++++++++ examples/AndroidSampleMoo_3.cfr | 42 ++++++++++ examples/AndroidSampleMoo_4.cfr | 50 +++++++++++ ...droidSampleMoo_4_existing_product_spec.cfr | 50 +++++++++++ examples/AndroidSampleMoo_5.cfr | 60 ++++++++++++++ examples/ClaferMooVizPaperExample.cfr | 82 ++++++++++++++++++ ...ferMooVizPaperExample_Downgraded_Front.cfr | 83 +++++++++++++++++++ .../ClaferMooVizPaperExample_Existing1.cfr | 83 +++++++++++++++++++ examples/Non-AFM.cfr | 30 +++++++ examples/README.md | 3 + examples/test1.cfr | 22 +++++ 11 files changed, 563 insertions(+) create mode 100644 examples/AndroidSampleMoo_2.cfr create mode 100644 examples/AndroidSampleMoo_3.cfr create mode 100644 examples/AndroidSampleMoo_4.cfr create mode 100644 examples/AndroidSampleMoo_4_existing_product_spec.cfr create mode 100644 examples/AndroidSampleMoo_5.cfr create mode 100644 examples/ClaferMooVizPaperExample.cfr create mode 100644 examples/ClaferMooVizPaperExample_Downgraded_Front.cfr create mode 100644 examples/ClaferMooVizPaperExample_Existing1.cfr create mode 100644 examples/Non-AFM.cfr create mode 100644 examples/README.md create mode 100644 examples/test1.cfr diff --git a/examples/AndroidSampleMoo_2.cfr b/examples/AndroidSampleMoo_2.cfr new file mode 100644 index 00000000..69e3ff2e --- /dev/null +++ b/examples/AndroidSampleMoo_2.cfr @@ -0,0 +1,58 @@ +abstract Component + performance : integer + +abstract ComponentWithEnergy : Component + energy : integer + +abstract androidPhone + hardware : Component + [ performance = 0 ] + screen : Component + [ performance = 0 ] + xor material : Component + [ performance = 0 ] + oled : ComponentWithEnergy + [ energy = 3] + [ performance = -3 ] + amoled : ComponentWithEnergy + [ energy = 2 ] + [ performance = -5 ] + lcd : ComponentWithEnergy + [ energy = 4 ] + [ performance = -2 ] + keyboard : ComponentWithEnergy ? + [ energy = 1 ] + [ performance = 3 ] + keyboardLight : ComponentWithEnergy ? + [ energy = 2 ] + [ performance = -1 ] + [ keyboard ] + cpu : ComponentWithEnergy + [ energy = 10 ] + [ performance = 15 ] + extra_cpu : ComponentWithEnergy ? + [ energy = 2 ] + [ performance = 20 ] + or location : Component ? + [ performance = 0 ] + gps : ComponentWithEnergy + [ energy = 5 ] + [ performance = -1 ] + wifitriangulation : ComponentWithEnergy + [ energy = 10 ] + [ performance = -2 ] + software : Component + [ performance = 0 ] + browser : Component ? + [ performance = -1 ] + [ extra_cpu ] + mediaplayer : Component ? + [ performance = -2 ] + total_performance : integer = sum Component.performance + total_energy : integer = sum ComponentWithEnergy.energy + +aPhone : androidPhone + [ mediaplayer ] + +<< min aPhone.total_energy >> +<< max aPhone.total_performance >> diff --git a/examples/AndroidSampleMoo_3.cfr b/examples/AndroidSampleMoo_3.cfr new file mode 100644 index 00000000..9e4dc2fd --- /dev/null +++ b/examples/AndroidSampleMoo_3.cfr @@ -0,0 +1,42 @@ +abstract Feature + performance : integer + energy : integer + +abstract SecurityFeature : Feature + security : integer + +abstract MobilePhone + or Connectivity : Feature + [ this.performance = 0] + [ this.energy = 0] + Bluetooth : Feature + [ this.performance = 9] + [ this.energy = 10 ] + USB : Feature + [ this.performance = 15] + [ this.energy = 7 ] + Wifi : Feature + [ this.performance = 22] + [ this.energy = 17 ] + PasswordProtection : SecurityFeature ? + [ this.security = 5] + [ this.performance = 1] + [ this.energy = 2 ] + FingerprintProtection : SecurityFeature ? + [ this.security = 5] + [ this.performance = 2] + [ this.energy = 4 ] + total_performance : integer + [ total_performance = sum Feature.performance ] + total_energy : integer + [ total_energy = sum Feature.energy ] + total_security : integer + [ total_security = sum SecurityFeature.security ] + +MyPhone : MobilePhone + [ Connectivity.Bluetooth && !USB ] + +<< min MyPhone.total_energy >> +<< max MyPhone.total_performance >> +<< max MyPhone.total_security >> + diff --git a/examples/AndroidSampleMoo_4.cfr b/examples/AndroidSampleMoo_4.cfr new file mode 100644 index 00000000..d0f071e5 --- /dev/null +++ b/examples/AndroidSampleMoo_4.cfr @@ -0,0 +1,50 @@ +abstract Feature + performance : integer + energy : integer + mass: integer + +abstract SecurityFeature : Feature + security : integer + +abstract MobilePhone + or Connectivity : Feature + [ this.performance = 0] + [ this.energy = 0] + [ this.mass = 0] + Bluetooth : Feature + [ this.performance = 9] + [ this.energy = 10 ] + [ this.mass = 2] + USB : Feature + [ this.performance = 10] + [ this.energy = 5 ] + [ this.mass = 3] + Wifi : Feature + [ this.performance = 22] + [ this.energy = 17 ] + [ this.mass = 6] + PasswordProtection : SecurityFeature ? + [ this.security = 5] + [ this.performance = 1] + [ this.energy = 2 ] + [ this.mass = 0] + FingerprintProtection : SecurityFeature ? + [ this.mass = 0] + [ this.security = 5] + [ this.performance = 2] + [ this.energy = 4 ] + total_performance : integer + [ total_performance = sum Feature.performance ] + total_energy : integer + [ total_energy = sum Feature.energy ] + total_security : integer + [ total_security = sum SecurityFeature.security ] + total_mass : integer + [ total_mass = sum Feature.mass ] + +MyPhone : MobilePhone + +<< min MyPhone.total_energy >> +<< max MyPhone.total_performance >> +<< max MyPhone.total_security >> +<< min MyPhone.total_mass >> \ No newline at end of file diff --git a/examples/AndroidSampleMoo_4_existing_product_spec.cfr b/examples/AndroidSampleMoo_4_existing_product_spec.cfr new file mode 100644 index 00000000..e0126932 --- /dev/null +++ b/examples/AndroidSampleMoo_4_existing_product_spec.cfr @@ -0,0 +1,50 @@ +abstract Feature + performance : integer + energy : integer + mass: integer + +abstract SecurityFeature : Feature + security : integer + +abstract MobilePhone + or Connectivity : Feature + [ this.performance = 0] + [ this.energy = 0] + [ this.mass = 0] + Bluetooth : Feature + [ this.performance = 9] + [ this.energy = 10 ] + [ this.mass = 2] + USB : Feature + [ this.performance = 10] + [ this.energy = 5 ] + [ this.mass = 3] + Wifi : Feature + [ this.performance = 22] + [ this.energy = 17 ] + [ this.mass = 6] + PasswordProtection : SecurityFeature ? + [ this.security = 5] + [ this.performance = 1] + [ this.energy = 2 ] + [ this.mass = 0] + FingerprintProtection : SecurityFeature ? + [ this.mass = 0] + [ this.security = 5] + [ this.performance = 2] + [ this.energy = 4 ] + total_performance : integer + [ total_performance = sum Feature.performance ] + total_energy : integer + [ total_energy = sum Feature.energy ] + total_security : integer + [ total_security = sum SecurityFeature.security ] + total_mass : integer + [ total_mass = sum Feature.mass ] + +MyPhone : MobilePhone + [ no Bluetooth + USB + Wifi + no PasswordProtection + FingerprintProtection] diff --git a/examples/AndroidSampleMoo_5.cfr b/examples/AndroidSampleMoo_5.cfr new file mode 100644 index 00000000..7d3872bb --- /dev/null +++ b/examples/AndroidSampleMoo_5.cfr @@ -0,0 +1,60 @@ +abstract Feature + performance : integer + energy : integer + mass: integer + cost: integer + +abstract SecurityFeature : Feature + security : integer + +abstract MobilePhone + or Connectivity : Feature + [ this.performance = 0] + [ this.energy = 0] + [ this.mass = 0] + [ this.cost = 12] + Bluetooth : Feature + [ this.performance = 9] + [ this.energy = 10 ] + [ this.mass = 2] + [ this.cost = 3] + USB : Feature + [ this.performance = 10] + [ this.energy = 5 ] + [ this.mass = 3] + [ this.cost = 5] + Wifi : Feature + [ this.performance = 22] + [ this.energy = 17 ] + [ this.mass = 6] + [ this.cost = 5] + PasswordProtection : SecurityFeature ? + [ this.security = 5] + [ this.performance = 1] + [ this.energy = 2 ] + [ this.mass = 0] + [ this.cost = 2] + FingerprintProtection : SecurityFeature ? + [ this.mass = 0] + [ this.security = 5] + [ this.performance = 3] + [ this.energy = 1 ] + [ this.cost = 13] + total_performance : integer + [ total_performance = sum Feature.performance ] + total_energy : integer + [ total_energy = sum Feature.energy ] + total_security : integer + [ total_security = sum SecurityFeature.security ] + total_mass : integer + [ total_mass = sum Feature.mass ] + total_cost : integer + [ total_cost = sum Feature.cost ] + +MyPhone : MobilePhone + +<< min MyPhone.total_energy >> +<< max MyPhone.total_performance >> +<< max MyPhone.total_security >> +<< min MyPhone.total_mass >> +<< min MyPhone.total_cost >> \ No newline at end of file diff --git a/examples/ClaferMooVizPaperExample.cfr b/examples/ClaferMooVizPaperExample.cfr new file mode 100644 index 00000000..296bfb73 --- /dev/null +++ b/examples/ClaferMooVizPaperExample.cfr @@ -0,0 +1,82 @@ +abstract Feature + productivity : integer + cost : integer + batterylife : integer + security : integer + +abstract MobilePhone + Connectivity : Feature + [ batterylife = -12] + [ productivity = 14] + [ security = 43] + [ cost = 101] + xor Bluetooth : Feature + [ batterylife = 0] + [ productivity = 0] + [ security = 0] + [ cost = 0] + Bluetooth20EDR : Feature + [ batterylife = -4] + [ productivity = 1] + [ security = -15] + [ cost = 1] + Bluetooth21EDR : Feature + [ batterylife = -2] + [ productivity = 4] + [ security = -10] + [ cost = 1] + Bluetooth40 : Feature + [ batterylife = -1] + [ productivity = 16] + [ security = -2] + [ cost = 2] + GSM : Feature + [ batterylife = -2] + [ productivity = 2] + [ security = -10] + [ cost = 1] + LTE : Feature ? + [ batterylife = -1] + [ productivity = 16] + [ security = -3] + [ cost = 3] + WiFi: Feature ? + [ batterylife = -10] + [ productivity = 20] + [ security = -15] + [ cost = 20] + USB : Feature ? + [ batterylife = 10] + [ productivity = 20] + [ security = 0] + [ cost = 3] + xor Battery : Feature + [ batterylife = 0] + [ productivity = 0] + [ security = 0] + [ cost = 0] + LiBattery1150 : Feature + [ batterylife = 60] + [ productivity = 0] + [ security = 0] + [ cost = 10] + LiBattery1400 : Feature + [ batterylife = 70] + [ productivity = 0] + [ security = 0] + [ cost = 15] + total_productivity : integer + [ total_productivity = sum Feature.productivity ] + total_batterylife : integer + [ total_batterylife = sum Feature.batterylife ] + total_security : integer + [ total_security = sum Feature.security ] + total_cost : integer + [ total_cost = sum Feature.cost ] + +MyPhone : MobilePhone + +<< max MyPhone.total_batterylife >> +<< max MyPhone.total_productivity >> +<< max MyPhone.total_security >> +<< min MyPhone.total_cost >> \ No newline at end of file diff --git a/examples/ClaferMooVizPaperExample_Downgraded_Front.cfr b/examples/ClaferMooVizPaperExample_Downgraded_Front.cfr new file mode 100644 index 00000000..2c7cf9c6 --- /dev/null +++ b/examples/ClaferMooVizPaperExample_Downgraded_Front.cfr @@ -0,0 +1,83 @@ +abstract Feature + productivity : integer + cost : integer + batterylife : integer + security : integer + +abstract MobilePhone + Connectivity : Feature + [this.batterylife = -12] + [this.productivity = 14] + [this.security = 43] + [this.cost = 101] + xor Bluetooth : Feature + [this.batterylife = 0] + [this.productivity = 0] + [this.security = 0] + [this.cost = 0] + Bluetooth20EDR : Feature + [this.batterylife = -4] + [this.productivity = 1] + [this.security = -15] + [this.cost = 1] + Bluetooth21EDR : Feature + [this.batterylife = -2] + [this.productivity = 4] + [this.security = -10] + [this.cost = 1] + Bluetooth40 : Feature + [this.batterylife = -1] + [this.productivity = 16] + [this.security = -2] + [this.cost = 2] + GSM : Feature + [this.batterylife = -2] + [this.productivity = 2] + [this.security = -10] + [this.cost = 1] + LTE : Feature ? + [this.batterylife = -1] + [this.productivity = 16] + [this.security = -3] + [this.cost = 3] + WiFi: Feature ? + [this.batterylife = -10] + [this.productivity = 20] + [this.security = -15] + [this.cost = 20] + USB : Feature ? + [this.batterylife = 10] + [this.productivity = 20] + [this.security = 0] + [this.cost = 3] + xor Battery : Feature + [this.batterylife = 0] + [this.productivity = 0] + [this.security = 0] + [this.cost = 0] + LiBattery1150 : Feature + [this.batterylife = 60] + [this.productivity = 0] + [this.security = 0] + [this.cost = 10] + LiBattery1400 : Feature + [this.batterylife = 70] + [this.productivity = 0] + [this.security = 0] + [this.cost = 15] + total_productivity : integer + [ total_productivity = sum Feature.productivity ] + total_batterylife : integer + [ total_batterylife = sum Feature.batterylife ] + total_security : integer + [ total_security = sum Feature.security ] + total_cost : integer + [ total_cost = sum Feature.cost ] + +MyPhone : MobilePhone + [!LTE] + +<< max MyPhone.total_batterylife >> +<< max MyPhone.total_productivity >> +<< max MyPhone.total_security >> +<< min MyPhone.total_cost >> \ No newline at end of file diff --git a/examples/ClaferMooVizPaperExample_Existing1.cfr b/examples/ClaferMooVizPaperExample_Existing1.cfr new file mode 100644 index 00000000..71440225 --- /dev/null +++ b/examples/ClaferMooVizPaperExample_Existing1.cfr @@ -0,0 +1,83 @@ +abstract Feature + productivity : integer + cost : integer + batterylife : integer + security : integer + +abstract MobilePhone + Connectivity : Feature + [this.batterylife = -12] + [this.productivity = 14] + [this.security = 43] + [this.cost = 101] + xor Bluetooth : Feature + [this.batterylife = 0] + [this.productivity = 0] + [this.security = 0] + [this.cost = 0] + Bluetooth20EDR : Feature + [this.batterylife = -4] + [this.productivity = 1] + [this.security = -15] + [this.cost = 1] + Bluetooth21EDR : Feature + [this.batterylife = -2] + [this.productivity = 4] + [this.security = -10] + [this.cost = 1] + Bluetooth40 : Feature + [this.batterylife = -1] + [this.productivity = 16] + [this.security = -2] + [this.cost = 2] + GSM : Feature + [this.batterylife = -2] + [this.productivity = 2] + [this.security = -10] + [this.cost = 1] + LTE : Feature ? + [this.batterylife = -1] + [this.productivity = 16] + [this.security = -3] + [this.cost = 3] + WiFi: Feature ? + [this.batterylife = -10] + [this.productivity = 20] + [this.security = -15] + [this.cost = 20] + USB : Feature ? + [this.batterylife = 10] + [this.productivity = 20] + [this.security = 0] + [this.cost = 3] + xor Battery : Feature + [this.batterylife = 0] + [this.productivity = 0] + [this.security = 0] + [this.cost = 0] + LiBattery1150 : Feature + [this.batterylife = 60] + [this.productivity = 0] + [this.security = 0] + [this.cost = 10] + LiBattery1400 : Feature + [this.batterylife = 70] + [this.productivity = 0] + [this.security = 0] + [this.cost = 15] + total_productivity : integer + [ total_productivity = sum Feature.productivity ] + total_batterylife : integer + [ total_batterylife = sum Feature.batterylife ] + total_security : integer + [ total_security = sum Feature.security ] + total_cost : integer + [ total_cost = sum Feature.cost ] + +MyPhone : MobilePhone + [Bluetooth20EDR && LiBattery1150 && !USB && !WiFi && !LTE] + +<< max MyPhone.total_batterylife >> +<< max MyPhone.total_productivity >> +<< max MyPhone.total_security >> +<< min MyPhone.total_cost >> \ No newline at end of file diff --git a/examples/Non-AFM.cfr b/examples/Non-AFM.cfr new file mode 100644 index 00000000..5bfe364b --- /dev/null +++ b/examples/Non-AFM.cfr @@ -0,0 +1,30 @@ +abstract Feature + cost: integer + +abstract ComfortFeature : Feature + comfort: integer + +abstract FuelFeature : ComfortFeature + fuel: integer + +abstract Car + ABS : Feature ? + [this.cost = 2] + CC : FuelFeature 2..3 // just to make it non-afm + [this.fuel = 1] + [this.comfort = 3] + [this.cost = 4] + ACC : FuelFeature ? + [this.fuel = 2] + [this.comfort = 6] + [this.cost = 3] + + total_cost : integer = sum Feature.cost + total_comfort : integer = sum ComfortFeature.cost + total_fuel : integer = sum FuelFeature.cost + +aCar : Car + +<< min aCar.total_cost >> +<< min aCar.total_fuel >> +<< max aCar.total_comfort >> \ No newline at end of file diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..1f1a6b0c --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# Examples + +Originally *Talk_Samples* from https://github.com/gsdlab/ClaferMooVisualizer/tree/master/Talk_Samples diff --git a/examples/test1.cfr b/examples/test1.cfr new file mode 100644 index 00000000..fd64653c --- /dev/null +++ b/examples/test1.cfr @@ -0,0 +1,22 @@ +abstract IMeasurable + footprint : integer + +abstract LinkedList + xor Abstract1 : IMeasurable + [ this.footprint = 0] + Option1 : IMeasurable + [ this.footprint = 1] + Option2 : IMeasurable + [ this.footprint = 2] + Option3 : IMeasurable + [ this.footprint = 1] + Option4 : IMeasurable + [ this.footprint = 1] + total_footprint : integer + [ total_footprint = Option1.footprint + Option2.footprint + Option3.footprint + Option4.footprint] + +simpleConfig : LinkedList + +<< min simpleConfig.total_footprint >> + +//Mandatory Features all configurations will have: Base AbstractElement AbstractIterator From 0203d9e9ebc2b2ed3e3d0346c3792b7500c5e9ea Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 16 Mar 2023 11:29:48 -0800 Subject: [PATCH 45/65] Added CI file --- .gitlab-ci.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitlab-ci.yaml diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml new file mode 100644 index 00000000..824dc841 --- /dev/null +++ b/.gitlab-ci.yaml @@ -0,0 +1,10 @@ +stages: + - build + - test + - deploy + +build_image: + stage: build + script: + - docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/chocosolver -w /usr/src/chocosolver maven:3.6-jdk-11 mvn clean install + From 75e8fe0a56295d5e717a44421a1f84dfdb56fda9 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Fri, 17 Mar 2023 11:01:04 -0700 Subject: [PATCH 46/65] Enable CI --- .gitignore | 4 ++++ .gitlab-ci.yaml | 10 ---------- .gitlab-ci.yml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 10 deletions(-) delete mode 100644 .gitlab-ci.yaml create mode 100644 .gitlab-ci.yml diff --git a/.gitignore b/.gitignore index 4df54bb6..1522af68 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ target nb-configuration.xml nbactions.xml src/test/resources/user.properties +.idea +*.plantuml +*.js + diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml deleted file mode 100644 index 824dc841..00000000 --- a/.gitlab-ci.yaml +++ /dev/null @@ -1,10 +0,0 @@ -stages: - - build - - test - - deploy - -build_image: - stage: build - script: - - docker run -it --rm --name my-maven-project -v "$(pwd)":/usr/src/chocosolver -w /usr/src/chocosolver maven:3.6-jdk-11 mvn clean install - diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..5f1286b0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,47 @@ +stages: + - build + - test + - deploy + +image: maven:3.6-jdk-11 + +before_script: + - export PATH="$PWD/clafer-tools-0.4.5:$PATH" + +build_package: + stage: build + tags: ["docker"] + script: + - mvn package -DskipTests + artifacts: + when: always + paths: + - target/chocosolver-0.4.4-jar-with-dependencies.jar + expire_in: 1 week + +test_image: + stage: test + needs: + job: build_package + artifacts: true + script: + - wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip + - unzip clafer-tools-0.4.5-linux-x86_64.zip + - wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar + - apt-get update && apt-get install -y graphviz + - | + for f in examples/*.cfr + do + echo "Processing $f" + java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml + echo "Rendering $f.plantuml" + java -jar plantuml-1.2023.4.jar $f.plantuml + done + artifacts: + when: always + paths: + - ./examples/*.plantuml + - ./examples/*.png + expire_in: 1 week + + From 973ba30bef08c1c2c5d3ecb2db4affdc14c461dd Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 29 Mar 2023 10:45:38 -0400 Subject: [PATCH 47/65] add alias and parent to PlantUML AST, update compiler and pretty printer to use them --- .../java/org/plantuml/ast/PlantumlObject.java | 15 ++++++++++++++- .../plantuml/compiler/AstPlantumlCompiler.java | 8 ++++++-- .../org/plantuml/pprinter/PlantumlPrinter.java | 18 +++++++++++++++++- .../org/sysml/compiler/SysmlCompilerUtils.java | 13 +++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/plantuml/ast/PlantumlObject.java b/src/main/java/org/plantuml/ast/PlantumlObject.java index 24bebce8..6559df95 100644 --- a/src/main/java/org/plantuml/ast/PlantumlObject.java +++ b/src/main/java/org/plantuml/ast/PlantumlObject.java @@ -4,10 +4,15 @@ public class PlantumlObject implements PlantumlExpr, PlantumlId { private final String name; + private final String alias; + private final String parent; + private final PlantumlPropertyGroup[] propertyGroups; - public PlantumlObject(String name, PlantumlPropertyGroup[] propertyGroups) { + public PlantumlObject(String name, String alias, String parent, PlantumlPropertyGroup[] propertyGroups) { this.name = name; + this.alias = alias; + this.parent = parent; this.propertyGroups = propertyGroups; } @@ -20,6 +25,14 @@ public String getName() { return name; } + public String getAlias() { + return alias; + } + + public String getParent() { + return parent; + } + @Override public B accept(PlantumlExprVisitor visitor, A a) throws IOException { return visitor.visit(this, a); diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 0585d45b..3331e28a 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -97,12 +97,14 @@ private ArrayList getConcreteObjects(List con AstClafer superClafer = ast.getSuperClafer(); String scName = ""; if (superClafer != null && !SysmlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#") && this.includeSuperClafersComponents) { - scName = " <<" + SysmlCompilerUtils.getPropertyId(superClafer.getName()) + ">>"; + scName = SysmlCompilerUtils.getPropertyId(superClafer.getName()); } // create an object and add it PlantumlObject obj = new PlantumlObject( - SysmlCompilerUtils.getPropertyId(ast.getName() + scName), + SysmlCompilerUtils.getPropertyId(ast.getName()), + SysmlCompilerUtils.getPropertyAlias(ast.getName()), + scName, pgs.toArray(new PlantumlPropertyGroup[0]) ); @@ -156,6 +158,8 @@ private ArrayList getAbstractObjects(List abs // create an object and add it PlantumlObject obj = new PlantumlObject( SysmlCompilerUtils.getPropertyId(ast.getName()), + SysmlCompilerUtils.getPropertyAlias(ast.getName()), + null, pgs.toArray(new PlantumlPropertyGroup[0]) ); diff --git a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java index 68470356..0f964251 100644 --- a/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java +++ b/src/main/java/org/plantuml/pprinter/PlantumlPrinter.java @@ -58,7 +58,23 @@ public Void visit(PlantumlProgram ast, String indent) throws IOException { @Override public Void visit(PlantumlObject plantumlObject, String s) throws IOException { - this.out.append(s).append("object ").append(plantumlObject.getName()); + this.out.append(s).append("object "); + + String alias = plantumlObject.getAlias(); + String parent = plantumlObject.getParent(); + + if (alias != null) { + this.out.append('"').append(alias).append('"').append(" as "); + } + + this.out.append(plantumlObject.getName()); + + if (parent != null ) { + if (!parent.isEmpty()) { + this.out.append("<<").append(parent).append(">>"); + } + } + if (plantumlObject.getPropertyGroups().length > 0) { this.out.append(" {\n"); for (PlantumlPropertyGroup grp: plantumlObject.getPropertyGroups()){ diff --git a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java index 40afe812..381b75e5 100644 --- a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java +++ b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java @@ -12,6 +12,19 @@ public static String getPropertyId(String name){ Matcher matcher = pattern.matcher(name); boolean matchFound = matcher.find(); //matcher.group() + if (matchFound){ + String idxS = matcher.group(1); + int idx = Integer.parseInt(idxS.substring(1, idxS.length()-1)); + return name.substring(matcher.group(1).length()) + "_" + String.valueOf(idx); + } else { + return name; + } + } + + public static String getPropertyAlias(String name){ + Pattern pattern = Pattern.compile("(c[0-9]+_).*", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(name); + boolean matchFound = matcher.find(); if (matchFound){ return name.substring(matcher.group(1).length()); } else { From 5843cdfa18c887610bd4d09fb3500ede4a102eed Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Wed, 29 Mar 2023 14:01:19 -0700 Subject: [PATCH 48/65] Add sysml output to CI tests --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5f1286b0..59ff8586 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,6 +34,7 @@ test_image: do echo "Processing $f" java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml + java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml echo "Rendering $f.plantuml" java -jar plantuml-1.2023.4.jar $f.plantuml done @@ -41,6 +42,7 @@ test_image: when: always paths: - ./examples/*.plantuml + - ./examples/*.sysml - ./examples/*.png expire_in: 1 week From ea224c1b1e38b4a845873ffc84fac7390fdebf14 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Wed, 29 Mar 2023 17:07:25 -0400 Subject: [PATCH 49/65] switch base sysml clafer name to reflect update in identifier generation --- .../java/org/sysml/compiler/InstanceSysmlCompiler.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java index dafd3ce6..7c55f704 100644 --- a/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java +++ b/src/main/java/org/sysml/compiler/InstanceSysmlCompiler.java @@ -13,6 +13,9 @@ public class InstanceSysmlCompiler { + // it will use the FIRST clafer named SysmlProperty + private final String baseSysmlClafer = "SysmlProperty_0"; + private ArrayList processedClafers; public InstanceSysmlCompiler(){ @@ -58,9 +61,9 @@ public SysmlProperty compile(InstanceClafer model, InstanceClafer topLevelModel) // get the property name String propName = ""; String[] superTypes = new String[0]; - if (hierarchy.contains("SysmlProperty")) { - propName = ((String) hierarchy.get(hierarchy.indexOf("SysmlProperty") - 1)).toLowerCase(); - superTypes = Arrays.copyOfRange(superClafers, 0, hierarchy.indexOf("SysmlProperty")-1); + if (hierarchy.contains(baseSysmlClafer)) { + propName = ((String) hierarchy.get(hierarchy.indexOf(baseSysmlClafer) - 1)).toLowerCase(); + superTypes = Arrays.copyOfRange(superClafers, 0, hierarchy.indexOf(baseSysmlClafer)-1); } else { propName = "unk"; } From 3fdeaed06fefe31b16681cc8c91844404023d673 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Wed, 29 Mar 2023 14:01:19 -0700 Subject: [PATCH 50/65] Add sysml output to CI tests --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5f1286b0..59ff8586 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,6 +34,7 @@ test_image: do echo "Processing $f" java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml + java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml echo "Rendering $f.plantuml" java -jar plantuml-1.2023.4.jar $f.plantuml done @@ -41,6 +42,7 @@ test_image: when: always paths: - ./examples/*.plantuml + - ./examples/*.sysml - ./examples/*.png expire_in: 1 week From 09ffa0b958a03b43aceafba5a05210c37f0034c5 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Thu, 30 Mar 2023 15:03:26 -0700 Subject: [PATCH 51/65] Fix Bad Identifier Generation for SysMLv2 Compiler --- .gitlab-ci.yml | 45 +++++-- examples/sysml-samples/sysmlproperty0.cfr | 5 + examples/sysml-samples/sysmlproperty1.cfr | 5 + examples/sysml-samples/sysmlproperty2.cfr | 8 ++ .../compiler/AstPlantumlCompiler.java | 26 ++-- .../compiler/PlantumlCompilerUtils.java | 31 +++++ .../sysml/compiler/InstanceSysmlCompiler.java | 2 +- .../sysml/compiler/SysmlCompilerUtils.java | 13 -- .../java/org/sysml/SysmlPropertyTest.java | 115 ++++++++++++++++++ 9 files changed, 215 insertions(+), 35 deletions(-) create mode 100644 examples/sysml-samples/sysmlproperty0.cfr create mode 100644 examples/sysml-samples/sysmlproperty1.cfr create mode 100644 examples/sysml-samples/sysmlproperty2.cfr create mode 100644 src/main/java/org/plantuml/compiler/PlantumlCompilerUtils.java create mode 100644 src/test/java/org/sysml/SysmlPropertyTest.java diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 59ff8586..7caa07de 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,17 @@ image: maven:3.6-jdk-11 before_script: - export PATH="$PWD/clafer-tools-0.4.5:$PATH" +prepare_environment: + stage: build + script: + - wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip + - unzip clafer-tools-0.4.5-linux-x86_64.zip + artifacts: + when: always + paths: + - clafer-tools-0.4.5/ + expire_in: 1 hour + build_package: stage: build tags: ["docker"] @@ -19,18 +30,38 @@ build_package: - target/chocosolver-0.4.4-jar-with-dependencies.jar expire_in: 1 week -test_image: +test_sysml_export: + stage: test + needs: + - job: build_package + artifacts: true + - job: prepare_environment + artifacts: true + script: + - | + for f in examples/sysml-samples/*.cfr + do + echo "Processing $f" + java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + done + artifacts: + when: always + paths: + - ./examples/sysml-samples/*.sysml + expire_in: 1 week + +test_plantuml_export: stage: test needs: - job: build_package - artifacts: true + - job: build_package + artifacts: true + - job: prepare_environment + artifacts: true script: - - wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip - - unzip clafer-tools-0.4.5-linux-x86_64.zip - wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar - apt-get update && apt-get install -y graphviz - | - for f in examples/*.cfr + for f in examples/**/*.cfr do echo "Processing $f" java -jar target/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml @@ -45,5 +76,3 @@ test_image: - ./examples/*.sysml - ./examples/*.png expire_in: 1 week - - diff --git a/examples/sysml-samples/sysmlproperty0.cfr b/examples/sysml-samples/sysmlproperty0.cfr new file mode 100644 index 00000000..1d0b1f00 --- /dev/null +++ b/examples/sysml-samples/sysmlproperty0.cfr @@ -0,0 +1,5 @@ +abstract SysmlProperty + +abstract Part: SysmlProperty + +myClafer: Part diff --git a/examples/sysml-samples/sysmlproperty1.cfr b/examples/sysml-samples/sysmlproperty1.cfr new file mode 100644 index 00000000..910cd904 --- /dev/null +++ b/examples/sysml-samples/sysmlproperty1.cfr @@ -0,0 +1,5 @@ +abstract SysmlProperty + +abstract Action: SysmlProperty + +myClafer: Action diff --git a/examples/sysml-samples/sysmlproperty2.cfr b/examples/sysml-samples/sysmlproperty2.cfr new file mode 100644 index 00000000..1305f441 --- /dev/null +++ b/examples/sysml-samples/sysmlproperty2.cfr @@ -0,0 +1,8 @@ +abstract SysmlProperty + +abstract Part: SysmlProperty + +abstract Action: SysmlProperty + +myClafer: Part + myAction: Action diff --git a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java index 3331e28a..fa141a77 100644 --- a/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java +++ b/src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java @@ -2,7 +2,7 @@ import org.clafer.ast.*; import org.plantuml.ast.*; -import org.sysml.compiler.SysmlCompilerUtils; +import org.plantuml.compiler.PlantumlCompilerUtils; import org.tomlj.Toml; import org.tomlj.TomlParseResult; @@ -96,14 +96,14 @@ private ArrayList getConcreteObjects(List con // NOTE: this could be made optional AstClafer superClafer = ast.getSuperClafer(); String scName = ""; - if (superClafer != null && !SysmlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#") && this.includeSuperClafersComponents) { - scName = SysmlCompilerUtils.getPropertyId(superClafer.getName()); + if (superClafer != null && !PlantumlCompilerUtils.getPropertyId(superClafer.getName()).startsWith("#") && this.includeSuperClafersComponents) { + scName = PlantumlCompilerUtils.getPropertyId(superClafer.getName()); } // create an object and add it PlantumlObject obj = new PlantumlObject( - SysmlCompilerUtils.getPropertyId(ast.getName()), - SysmlCompilerUtils.getPropertyAlias(ast.getName()), + PlantumlCompilerUtils.getPropertyId(ast.getName()), + PlantumlCompilerUtils.getPropertyAlias(ast.getName()), scName, pgs.toArray(new PlantumlPropertyGroup[0]) ); @@ -157,8 +157,8 @@ private ArrayList getAbstractObjects(List abs // create an object and add it PlantumlObject obj = new PlantumlObject( - SysmlCompilerUtils.getPropertyId(ast.getName()), - SysmlCompilerUtils.getPropertyAlias(ast.getName()), + PlantumlCompilerUtils.getPropertyId(ast.getName()), + PlantumlCompilerUtils.getPropertyAlias(ast.getName()), null, pgs.toArray(new PlantumlPropertyGroup[0]) ); @@ -231,8 +231,8 @@ private ArrayList getConcreteConnections(List getConcreteConnections(List getAbstractConnections(List getAbstractConnections(List processedClafers; diff --git a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java index 381b75e5..40afe812 100644 --- a/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java +++ b/src/main/java/org/sysml/compiler/SysmlCompilerUtils.java @@ -12,19 +12,6 @@ public static String getPropertyId(String name){ Matcher matcher = pattern.matcher(name); boolean matchFound = matcher.find(); //matcher.group() - if (matchFound){ - String idxS = matcher.group(1); - int idx = Integer.parseInt(idxS.substring(1, idxS.length()-1)); - return name.substring(matcher.group(1).length()) + "_" + String.valueOf(idx); - } else { - return name; - } - } - - public static String getPropertyAlias(String name){ - Pattern pattern = Pattern.compile("(c[0-9]+_).*", Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(name); - boolean matchFound = matcher.find(); if (matchFound){ return name.substring(matcher.group(1).length()); } else { diff --git a/src/test/java/org/sysml/SysmlPropertyTest.java b/src/test/java/org/sysml/SysmlPropertyTest.java new file mode 100644 index 00000000..9345edde --- /dev/null +++ b/src/test/java/org/sysml/SysmlPropertyTest.java @@ -0,0 +1,115 @@ +package org.sysml; + +import org.clafer.ast.AstClafer; +import org.clafer.ast.AstModel; +import org.clafer.cli.Utils; +import org.clafer.compiler.ClaferCompiler; +import org.clafer.compiler.ClaferOption; +import org.clafer.compiler.ClaferSearch; +import org.clafer.instance.InstanceClafer; +import org.clafer.instance.InstanceModel; +import org.clafer.javascript.Javascript; +import org.clafer.javascript.JavascriptFile; +import org.clafer.objective.Objective; +import org.clafer.scope.Scope; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.sysml.ast.SysmlPropertyDef; +import org.sysml.compiler.AstSysmlCompiler; +import org.sysml.compiler.InstanceSysmlCompiler; +import org.sysml.compiler.SysmlCompilerUtils; +import test.OptimizationTest; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertTrue; + +@RunWith(Parameterized.class) +public class SysmlPropertyTest { + @Parameterized.Parameter + public File testFile; + + @Parameterized.Parameters(name = "{0}") + public static List testFiles() throws URISyntaxException { + File dir = new File(OptimizationTest.class.getResource("/sysml-samples/assert-positive").toURI()); + assertTrue(dir.isDirectory()); + List files = new ArrayList<>(); + for (File file : dir.listFiles()) { + if (file.getAbsolutePath().endsWith(".cfr")) { + files.add(new File[]{file}); + } + } + return files; + } + + File getInputFile() throws IOException, InterruptedException { + Process compilerProcess = Runtime.getRuntime().exec("clafer -k -m choco " + testFile); + compilerProcess.waitFor(); + + // replace the extension to .js + String testFileName = testFile.getAbsolutePath(); + int extPos = testFileName.lastIndexOf("."); + if(extPos != -1) { + testFileName = testFileName.substring(0, extPos) + ".js"; + } + + // change the inputFile to the resulting .js file + return new File(testFileName); + } + + SysmlPropertyDef[] getSysmlPropertyDefs(File inputFile) throws IOException { + // compile the example + JavascriptFile jsFile = Javascript.readModel(inputFile); + AstModel top = jsFile.getModel(); + AstSysmlCompiler compiler = new AstSysmlCompiler(); + SysmlPropertyDef[] models = compiler.compile(top, top); + return models; + } + + + /* + * Test that the compiler creates SysML Properties + */ + @Test + public void testSysmlProperty() throws IOException, URISyntaxException, InterruptedException { + File inputFile = getInputFile(); + JavascriptFile jsFile = Javascript.readModel(inputFile); + + Objective[] objectives = jsFile.getObjectives(); + + // handle scopes + /* setting the default int range */ + Scope scope = jsFile.getScope(); + int scopeHighDef = 127; + int scopeLowDef = -(scopeHighDef + 1); + scope = scope.toBuilder().intLow(scopeLowDef).intHigh(scopeHighDef).toScope(); + + // handle search strategy + ClaferOption compilerOption = jsFile.getOption(); + + // pick the right solver + ClaferSearch solver = objectives.length == 0 + ? ClaferCompiler.compile(jsFile.getModel(), scope, compilerOption) + : ClaferCompiler.compile(jsFile.getModel(), scope, objectives, compilerOption); + assertTrue(solver.find()); + InstanceModel instance = solver.instance(); + + // the instance contains something + assertTrue(instance.getTopClafers().length > 0); + + // get its supers + for (InstanceClafer clafer: instance.getTopClafers()) { + String[] superClafers = SysmlCompilerUtils.getSuperClafers(clafer.getType()); + List hierarchy = Arrays.asList(superClafers); + assertTrue(hierarchy.contains(new InstanceSysmlCompiler().baseSysmlClafer)); + } + + System.out.println(testFile); + } +} From ae7ee0373e6539329dd1f8fd15d75ffa839a9b20 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 30 Mar 2023 15:58:23 -0700 Subject: [PATCH 52/65] CI-fixes --- .gitlab-ci.yml | 2 +- src/test/java/org/sysml/SysmlPropertyTest.java | 2 ++ .../sysml-samples/assert-positive/sysmlproperty0.cfr | 5 +++++ .../sysml-samples/assert-positive/sysmlproperty1.cfr | 5 +++++ .../sysml-samples/assert-positive/sysmlproperty2.cfr | 8 ++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/sysml-samples/assert-positive/sysmlproperty0.cfr create mode 100644 src/test/resources/sysml-samples/assert-positive/sysmlproperty1.cfr create mode 100644 src/test/resources/sysml-samples/assert-positive/sysmlproperty2.cfr diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7caa07de..c2e44736 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,7 +23,7 @@ build_package: stage: build tags: ["docker"] script: - - mvn package -DskipTests + - mvn package artifacts: when: always paths: diff --git a/src/test/java/org/sysml/SysmlPropertyTest.java b/src/test/java/org/sysml/SysmlPropertyTest.java index 9345edde..6f138b8e 100644 --- a/src/test/java/org/sysml/SysmlPropertyTest.java +++ b/src/test/java/org/sysml/SysmlPropertyTest.java @@ -13,6 +13,7 @@ import org.clafer.objective.Objective; import org.clafer.scope.Scope; import org.junit.Test; +import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.sysml.ast.SysmlPropertyDef; @@ -30,6 +31,7 @@ import static org.junit.Assert.assertTrue; +@Ignore @RunWith(Parameterized.class) public class SysmlPropertyTest { @Parameterized.Parameter diff --git a/src/test/resources/sysml-samples/assert-positive/sysmlproperty0.cfr b/src/test/resources/sysml-samples/assert-positive/sysmlproperty0.cfr new file mode 100644 index 00000000..1d0b1f00 --- /dev/null +++ b/src/test/resources/sysml-samples/assert-positive/sysmlproperty0.cfr @@ -0,0 +1,5 @@ +abstract SysmlProperty + +abstract Part: SysmlProperty + +myClafer: Part diff --git a/src/test/resources/sysml-samples/assert-positive/sysmlproperty1.cfr b/src/test/resources/sysml-samples/assert-positive/sysmlproperty1.cfr new file mode 100644 index 00000000..910cd904 --- /dev/null +++ b/src/test/resources/sysml-samples/assert-positive/sysmlproperty1.cfr @@ -0,0 +1,5 @@ +abstract SysmlProperty + +abstract Action: SysmlProperty + +myClafer: Action diff --git a/src/test/resources/sysml-samples/assert-positive/sysmlproperty2.cfr b/src/test/resources/sysml-samples/assert-positive/sysmlproperty2.cfr new file mode 100644 index 00000000..1305f441 --- /dev/null +++ b/src/test/resources/sysml-samples/assert-positive/sysmlproperty2.cfr @@ -0,0 +1,8 @@ +abstract SysmlProperty + +abstract Part: SysmlProperty + +abstract Action: SysmlProperty + +myClafer: Part + myAction: Action From b2dc4c721cde6d526eca62bb804b42ed2586be66 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Tue, 4 Apr 2023 11:03:10 -0700 Subject: [PATCH 53/65] increment index inside of sysml loop --- src/main/java/org/clafer/cli/Normal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/clafer/cli/Normal.java b/src/main/java/org/clafer/cli/Normal.java index fb1163a2..ff14cf5c 100644 --- a/src/main/java/org/clafer/cli/Normal.java +++ b/src/main/java/org/clafer/cli/Normal.java @@ -107,7 +107,7 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options, ++index; } else { if (sysml) { - outStream.append("package Architecture {\n"); + outStream.append("package Instance" + (++index) + "{\n"); outStream.append(" import ScalarValues::*;\n"); AstModel top = javascriptFile.getModel(); SysmlPrinter pprinter = new SysmlPrinter(outStream); From f1d678af936462337295d2ebcce3c784b93e0631 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Tue, 24 Oct 2023 14:07:35 -0700 Subject: [PATCH 54/65] Change the runner label from docker to stardust as recommended by the IT --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c2e44736..11fde335 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ prepare_environment: build_package: stage: build - tags: ["docker"] + tags: ["stardust"] script: - mvn package artifacts: From 5a900d9b4dedd19f18b4aa53804ad2e7333d8ec0 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Mon, 8 Jan 2024 13:00:01 -0800 Subject: [PATCH 55/65] add .m2/repository to cache and add a deploy job on tagged commits --- .gitlab-ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 11fde335..702a8714 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,10 @@ stages: image: maven:3.6-jdk-11 +cache: + paths: + - .m2/repository + before_script: - export PATH="$PWD/clafer-tools-0.4.5:$PATH" @@ -76,3 +80,11 @@ test_plantuml_export: - ./examples/*.sysml - ./examples/*.png expire_in: 1 week + +deploy_job: + stage: deploy + script: + - 'echo "Deploying the project..."' + - 'curl --upload-file ./target/your-artifact-name.jar "http://your-deployment-server/upload"' + only: + - tags \ No newline at end of file From 9532e4c4c21748d2628139bcaef8f2c70eeb8b81 Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Mon, 8 Jan 2024 13:14:11 -0800 Subject: [PATCH 56/65] change placeholder name to the correct jar file --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 702a8714..35b4b50c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,7 @@ test_plantuml_export: deploy_job: stage: deploy script: - - 'echo "Deploying the project..."' - - 'curl --upload-file ./target/your-artifact-name.jar "http://your-deployment-server/upload"' + - 'echo "Deploying the project to GitLab Package Registry..."' + - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./target/chocosolver-0.4.4-jar-with-dependencies.jar "https://gitlab-ext.galois.com/api/v4/projects/$CI_PROJECT_ID/packages/maven/"' only: - tags \ No newline at end of file From 8ba10b62b48bb011009a11ebd8b9234395d36e8f Mon Sep 17 00:00:00 2001 From: Ethan Lew Date: Fri, 12 Jan 2024 13:18:51 -0800 Subject: [PATCH 57/65] change deploy to require the build stage, remove non-existent cache path --- .gitlab-ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35b4b50c..6ee3c30a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,10 +5,6 @@ stages: image: maven:3.6-jdk-11 -cache: - paths: - - .m2/repository - before_script: - export PATH="$PWD/clafer-tools-0.4.5:$PATH" @@ -83,8 +79,13 @@ test_plantuml_export: deploy_job: stage: deploy + needs: + - job: build_package + artifacts: true + - job: prepare_environment + artifacts: true script: - 'echo "Deploying the project to GitLab Package Registry..."' - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./target/chocosolver-0.4.4-jar-with-dependencies.jar "https://gitlab-ext.galois.com/api/v4/projects/$CI_PROJECT_ID/packages/maven/"' only: - - tags \ No newline at end of file + - tags From b5b99babbf05e24c3f5662194bdfa1281fd716fd Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 18 Apr 2024 16:40:09 -0700 Subject: [PATCH 58/65] Build MVN package workflow --- .github/workflows/main.yml | 40 +++++++++++++++++++++++++++++++++++++ .github/workflows/maven.yml | 23 --------------------- 2 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..6b1d3ca7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,40 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + push: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + build_package: + runs-on: ubuntu-20.04 + steps: + #### This step is only needed for GHA local runner, act: https://github.com/nektos/act + - name: Install curl (for nektos/act local CI testing) + run: apt-get update && apt-get install build-essential curl pkg-config openssl -y + - name: Download Maven + run: | + curl -sL https://downloads.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.zip -o maven.zip + apt-get update + apt-get -y install unzip + unzip -d /usr/share maven.zip + rm maven.zip + ln -s /usr/share/apache-maven-3.8.8/bin/mvn /usr/bin/mvn + echo "M2_HOME=/usr/share/apache-maven-3.8.8" | tee -a /etc/environment + file /usr/bin/mvn + echo $PATH + # Rest of the actions + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'temurin' + - run: mvn --batch-mode --update-snapshots verify + - run: mkdir staging && cp target/*.jar staging + - uses: actions/upload-artifact@v4 + with: + name: Package + path: staging + \ No newline at end of file diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 48d5ff56..00000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Maven CI - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - - name: Set up Maven - uses: stCarolas/setup-maven@v4.5 - with: - maven-version: 3.8.2 - - name: Build with Maven - run: mvn -B package --file pom.xml - From ceb037a7bce97cc5f48738d77cdcb7ed42f5e363 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 18 Apr 2024 16:42:47 -0700 Subject: [PATCH 59/65] Comment out act specific setup --- .github/workflows/main.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6b1d3ca7..3fc20d03 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,19 +12,19 @@ jobs: runs-on: ubuntu-20.04 steps: #### This step is only needed for GHA local runner, act: https://github.com/nektos/act - - name: Install curl (for nektos/act local CI testing) - run: apt-get update && apt-get install build-essential curl pkg-config openssl -y - - name: Download Maven - run: | - curl -sL https://downloads.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.zip -o maven.zip - apt-get update - apt-get -y install unzip - unzip -d /usr/share maven.zip - rm maven.zip - ln -s /usr/share/apache-maven-3.8.8/bin/mvn /usr/bin/mvn - echo "M2_HOME=/usr/share/apache-maven-3.8.8" | tee -a /etc/environment - file /usr/bin/mvn - echo $PATH + # - name: Install curl (for nektos/act local CI testing) + # run: apt-get update && apt-get install build-essential curl pkg-config openssl -y + # - name: Download Maven + # run: | + # curl -sL https://downloads.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.zip -o maven.zip + # apt-get update + # apt-get -y install unzip + # unzip -d /usr/share maven.zip + # rm maven.zip + # ln -s /usr/share/apache-maven-3.8.8/bin/mvn /usr/bin/mvn + # echo "M2_HOME=/usr/share/apache-maven-3.8.8" | tee -a /etc/environment + # file /usr/bin/mvn + # echo $PATH # Rest of the actions - uses: actions/checkout@v4 - uses: actions/setup-java@v4 From 618d15431b56219e7badbfd39618dbd81a0c7abe Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 18 Apr 2024 16:52:50 -0700 Subject: [PATCH 60/65] Added sysml export test --- .github/workflows/main.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3fc20d03..14bae73d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,12 +6,17 @@ name: CI on: push: +env: + PATH: "/opt/clafer-tools-0.4.5:$PATH" + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: build_package: + name: Builld chocosolver package runs-on: ubuntu-20.04 steps: #### This step is only needed for GHA local runner, act: https://github.com/nektos/act + ### That is because act ubuntu image does not have mvn installed, but the github one does # - name: Install curl (for nektos/act local CI testing) # run: apt-get update && apt-get install build-essential curl pkg-config openssl -y # - name: Download Maven @@ -35,6 +40,28 @@ jobs: - run: mkdir staging && cp target/*.jar staging - uses: actions/upload-artifact@v4 with: - name: Package + name: Chocosolver-0.4.4 path: staging - \ No newline at end of file + + test_sysml_export: + name: Test SysMLv2 export + needs: build_package + runs-on: ubuntu-20.04 + steps: + - name: Install clafer tools + run: | + wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip + unzip clafer-tools-0.4.5-linux-x86_64.zip + mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 + - name: Process SysML examples + run: | + for f in examples/sysml-samples/*.cfr + do + echo "Processing $f" + java -jar staging/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + done + - uses: actions/upload-artifact@v4 + with: + name: SysML_generated + path: examples/sysml-samples + retention-days: 1 From 64faada0700e044b3ea05e78beb825ecc8748824 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 18 Apr 2024 16:57:14 -0700 Subject: [PATCH 61/65] Update system path --- .github/workflows/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 14bae73d..51bf792d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,9 +6,6 @@ name: CI on: push: -env: - PATH: "/opt/clafer-tools-0.4.5:$PATH" - # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: build_package: @@ -53,6 +50,7 @@ jobs: wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip unzip clafer-tools-0.4.5-linux-x86_64.zip mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 + echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH - name: Process SysML examples run: | for f in examples/sysml-samples/*.cfr From a85d627ca58efbcef9287a4ba1b2d3a5e7f72fe7 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Thu, 18 Apr 2024 17:20:55 -0700 Subject: [PATCH 62/65] Add PlantUML job --- .github/workflows/main.yml | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 51bf792d..e61c5a77 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,8 +37,9 @@ jobs: - run: mkdir staging && cp target/*.jar staging - uses: actions/upload-artifact@v4 with: - name: Chocosolver-0.4.4 - path: staging + name: chocosolver + path: staging/*.jar + retention-days: 7 test_sysml_export: name: Test SysMLv2 export @@ -56,10 +57,44 @@ jobs: for f in examples/sysml-samples/*.cfr do echo "Processing $f" - java -jar staging/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + java -jar chocosolver/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml done - uses: actions/upload-artifact@v4 with: name: SysML_generated - path: examples/sysml-samples - retention-days: 1 + path: examples/sysml-samples/*.sysml + retention-days: 7 + + test_plantuml_export: + name: Test PlantUML export + needs: build_package + runs-on: ubuntu-20.04 + steps: + - name: Install clafer tools + run: | + wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip + unzip clafer-tools-0.4.5-linux-x86_64.zip + mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 + echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH + - name: Install PlantUML + run: | + wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar + apt-get update && apt-get install -y graphviz + - name: Process SysML examples + run: | + for f in examples/**/*.cfr + do + echo "Processing $f" + java -jar chocosolver/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml + java -jar chocosolver/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + echo "Rendering $f.plantuml" + java -jar plantuml-1.2023.4.jar $f.plantuml + done + - uses: actions/upload-artifact@v4 + with: + name: SysML_generated + path: | + examples/*.plantuml + examples/*.sysml + examples/*.png + retention-days: 7 From 15b6a36b7c70953808939de18cc2825a3c81a7e0 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Fri, 19 Apr 2024 09:22:29 -0700 Subject: [PATCH 63/65] Attempt to debug the pipeline --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e61c5a77..c3da1968 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,7 +51,7 @@ jobs: wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip unzip clafer-tools-0.4.5-linux-x86_64.zip mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 - echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH +# echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH - name: Process SysML examples run: | for f in examples/sysml-samples/*.cfr From f32c12b4dda6552eac2a30304c58582a25f71b76 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Fri, 19 Apr 2024 09:27:48 -0700 Subject: [PATCH 64/65] Another debugging attempt --- .github/workflows/main.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c3da1968..73902ce4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,7 @@ jobs: - run: mkdir staging && cp target/*.jar staging - uses: actions/upload-artifact@v4 with: - name: chocosolver + name: chocosolver-release path: staging/*.jar retention-days: 7 @@ -51,13 +51,13 @@ jobs: wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip unzip clafer-tools-0.4.5-linux-x86_64.zip mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 -# echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH + echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH - name: Process SysML examples run: | for f in examples/sysml-samples/*.cfr do echo "Processing $f" - java -jar chocosolver/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + java -jar chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml done - uses: actions/upload-artifact@v4 with: @@ -70,23 +70,23 @@ jobs: needs: build_package runs-on: ubuntu-20.04 steps: - - name: Install clafer tools - run: | - wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip - unzip clafer-tools-0.4.5-linux-x86_64.zip - mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 - echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH - - name: Install PlantUML - run: | - wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar - apt-get update && apt-get install -y graphviz + # - name: Install clafer tools + # run: | + # wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip + # unzip clafer-tools-0.4.5-linux-x86_64.zip + # mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 + # echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH + # - name: Install PlantUML + # run: | + # wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar + # apt-get update && apt-get install -y graphviz - name: Process SysML examples run: | for f in examples/**/*.cfr do echo "Processing $f" - java -jar chocosolver/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml - java -jar chocosolver/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + java -jar chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml + java -jar chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml echo "Rendering $f.plantuml" java -jar plantuml-1.2023.4.jar $f.plantuml done From 345c299a0a6049dcf9cf32e1667ae61bce3389d3 Mon Sep 17 00:00:00 2001 From: Michal Podhradsky Date: Fri, 19 Apr 2024 10:54:56 -0700 Subject: [PATCH 65/65] Fix the CI (#2) Various github action fixes --- .github/workflows/main.yml | 53 +++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 73902ce4..5b034430 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,6 +46,12 @@ jobs: needs: build_package runs-on: ubuntu-20.04 steps: + - uses: actions/checkout@v4 + - name: Download Chocosolver package + uses: actions/download-artifact@v4 + with: + name: chocosolver-release + path: /tmp/chocosolver-release - name: Install clafer tools run: | wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip @@ -53,11 +59,12 @@ jobs: mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH - name: Process SysML examples + shell: bash run: | for f in examples/sysml-samples/*.cfr do echo "Processing $f" - java -jar chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + java -jar /tmp/chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml done - uses: actions/upload-artifact@v4 with: @@ -70,31 +77,41 @@ jobs: needs: build_package runs-on: ubuntu-20.04 steps: - # - name: Install clafer tools - # run: | - # wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip - # unzip clafer-tools-0.4.5-linux-x86_64.zip - # mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 - # echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH - # - name: Install PlantUML - # run: | - # wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar - # apt-get update && apt-get install -y graphviz + - uses: actions/checkout@v4 + - name: Download Chocosolver package + uses: actions/download-artifact@v4 + with: + name: chocosolver-release + path: /tmp/chocosolver-release + - name: Install clafer tools + shell: bash + run: | + wget --no-check-certificate https://gsd.uwaterloo.ca/clafer-tools-bin/clafer-tools-0.4.5-linux-x86_64.zip + unzip clafer-tools-0.4.5-linux-x86_64.zip + mv clafer-tools-0.4.5 /opt/clafer-tools-0.4.5 + echo "/opt/clafer-tools-0.4.5" >> $GITHUB_PATH + - name: Install PlantUML + run: | + wget https://github.com/plantuml/plantuml/releases/download/v1.2023.4/plantuml-1.2023.4.jar + - name: Install graphviz + run: | + sudo apt-get update + sudo apt-get install graphviz - name: Process SysML examples run: | - for f in examples/**/*.cfr + for f in examples/**.cfr do echo "Processing $f" - java -jar chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml - java -jar chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml + java -jar /tmp/chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --plantuml --file $f --output $f.plantuml + java -jar /tmp/chocosolver-release/chocosolver-0.4.4-jar-with-dependencies.jar --sysml --file $f --output $f.sysml echo "Rendering $f.plantuml" java -jar plantuml-1.2023.4.jar $f.plantuml done - uses: actions/upload-artifact@v4 with: - name: SysML_generated + name: PlantUML_generated path: | - examples/*.plantuml - examples/*.sysml - examples/*.png + examples/**.plantuml + examples/**.sysml + examples/**.png retention-days: 7