Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve Aspect Model Diagram generation #407

Merged
merged 39 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d418c85
Fix file name matching in AspectModelLoader
atextor Aug 4, 2023
608fbf8
Delete SPARQL files from legacy diagram generation
atextor Aug 4, 2023
a76befa
Implement new diagram generator as an AspectModelVisitor
atextor Aug 4, 2023
b7744e8
Adjust modules to API changes
atextor Aug 4, 2023
63cdb32
Update Movement example model to SAMM 2.1.0
atextor Aug 4, 2023
7a8241f
Adapt samm-cli to updated diagram generation
atextor Aug 4, 2023
5fe7afc
Add missing class to reflect-config
atextor Aug 7, 2023
e410cd1
Merge branch 'main' into 406-improve-diagram-generation
atextor Aug 16, 2023
e250c53
Merge branch 'main' into 406-improve-diagram-generation
atextor Sep 14, 2023
92482c4
Adjust GraalVM build
atextor Sep 25, 2023
6ac6912
Merge branch 'main' into 406-improve-diagram-generation
atextor Sep 26, 2023
9542e5e
Limit specific substitution to Linux OS
atextor Sep 26, 2023
65c93b6
Switch to 17.0.8-graal GraalVM distribution in GH actions
atextor Sep 26, 2023
33b02a6
Remove dependencies to SVM in build-time code
atextor Sep 26, 2023
91d3588
Remove debug output in config customization
atextor Sep 26, 2023
c06b78e
Increase page file size on Windows builds
atextor Sep 26, 2023
90bce9d
Update deprecated native-image 'build' goal with 'compile'
atextor Sep 26, 2023
6fe3bb2
Tweak memory management for native build
atextor Sep 26, 2023
4572aef
Remove writing of debugging files in JSON payload generation
atextor Sep 26, 2023
b0d1b4b
Add missing classes to reflection-config
atextor Sep 26, 2023
7abbcd8
Add java.awt.Insets to jni-config
atextor Sep 27, 2023
ab225f7
Add java.awt.event.InputEvent to GraalVM configs
atextor Sep 27, 2023
5acc787
Add java.awt.AWTEvent to GraalVM configs
atextor Sep 27, 2023
e8dfd7d
Add sun.awt.windows.WComponentPeer to GraalVM configs
atextor Sep 27, 2023
3e66bbb
Add sun.awt.windows.WObjectPeer to GraalVM configs
atextor Sep 28, 2023
5e4c06a
Add java.awt.Component to GraalVM configs
atextor Sep 28, 2023
9f17669
Add sun.font.FontDesignMetrics to GraalVM configs
atextor Sep 28, 2023
f91b0f1
Adjust native-image build args: export sun.awt/font modules
atextor Sep 29, 2023
fde5ce5
Use different syntax for --add-exports on native-image call
atextor Sep 29, 2023
8b21d29
Fix PNG generation on Windows
atextor Oct 5, 2023
52d824a
Adjust GraalVM compiler configs
atextor Oct 6, 2023
7ea2792
Add sun.java2d.d3d.D3DGraphicsDevice to GraalVM configs
atextor Oct 6, 2023
3eea99b
Add sun.awt.Win32GraphicsDevice to GraalVM configs
atextor Oct 10, 2023
e7c64e8
Use headless execution on Windows
atextor Oct 10, 2023
60915af
Configure classpath for native-image Maven plugin
atextor Oct 10, 2023
144539b
Exclude spurious GraalVM configs from dependencies
atextor Oct 10, 2023
f3a4538
Fix dependency scope
atextor Oct 10, 2023
c96bcae
Fix scrambled output for PNGs
atextor Oct 11, 2023
0fb5572
Fix diagram text encoding on Windows
atextor Oct 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pull-request-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
java-version: '17.0.8'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
Expand All @@ -42,8 +42,8 @@ jobs:
# https://github.com/actions/virtual-environments/issues/3420#issuecomment-861342418
uses: al-cheb/configure-pagefile-action@v1.3
with:
minimum-size: 16GB
maximum-size: 16GB
minimum-size: 32GB
maximum-size: 32GB
disk-root: "C:"

- name: Set Swap Space (Linux)
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
java-version: '17.0.8'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
Expand Down Expand Up @@ -135,8 +135,8 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
java-version: '17.0.8'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
Expand All @@ -156,8 +156,8 @@ jobs:
# https://github.com/actions/virtual-environments/issues/3420#issuecomment-861342418
uses: al-cheb/configure-pagefile-action@v1.3
with:
minimum-size: 16GB
maximum-size: 16GB
minimum-size: 32GB
maximum-size: 32GB
disk-root: "C:"

- name: Build and run tests
Expand Down Expand Up @@ -211,8 +211,8 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@v1
with:
version: '22.3.1'
java-version: '17'
java-version: '17.0.8'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'false'
Expand All @@ -230,7 +230,7 @@ jobs:
- name: Prepare release
run: |
# Create Windows CLI zip
zip -9 -r samm-cli-windows.zip samm.exe *.dll lib/
zip -9 -r samm-cli-windows.zip samm.exe *.dll

# Full release: Maven Central
# The (apparently) only way to retrieve the staging profile id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.vocabulary.RDF;
import org.eclipse.esmf.aspectmodel.UnsupportedVersionException;
import org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver;
import org.eclipse.esmf.aspectmodel.resolver.FileSystemStrategy;
Expand All @@ -43,18 +38,23 @@
import org.eclipse.esmf.metamodel.NamedElement;
import org.eclipse.esmf.metamodel.impl.DefaultModelNamespace;
import org.eclipse.esmf.samm.KnownVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableSet;

import io.vavr.control.Try;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.vocabulary.RDF;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides functionality to load an Aspect Model from a {@link VersionedModel} and use the correct SAMM resources to
* instantiate it. To load a regular Aspect Model, use {@link #getElements(VersionedModel)} or {@link #getElementsUnchecked(VersionedModel)}.
* instantiate it. To load a regular Aspect Model, use {@link #getElements(VersionedModel)} or
* {@link #getElementsUnchecked(VersionedModel)}.
* To load elements from an RDF model that might contain elements from multiple namespaces, use {@link #getNamespaces(VersionedModel)}.
*
* <p>
* Instances of {@code VersionedModel} are gained through an {@link AspectModelResolver}.
*/
public class AspectModelLoader {
Expand Down Expand Up @@ -91,6 +91,7 @@ private static void validateNamespaceOfCustomUnits( final SAMM samm, final Model
* collection of {@link ModelNamespace}. Use this method only when you expect the RDF model to contain more than
* one namespace (which is not the case when aspect models contain the usual element definitions with one namespace per file),
* otherwise use {@link #getElements(VersionedModel)}.
*
* @param versionedModel The RDF model representation of the Aspect model
* @return the list of namespaces
*/
Expand All @@ -111,6 +112,7 @@ public static Try<List<ModelNamespace>> getNamespaces( final VersionedModel vers

/**
* Creates Java instances for model element classes from the RDF input model
*
* @param versionedModel The RDF model representation of the Aspect model
* @return the list of loaded model elements on success
*/
Expand Down Expand Up @@ -152,9 +154,10 @@ public static Try<List<ModelElement>> getElements( final VersionedModel versione

/**
* Does the same as {@link #getElements(VersionedModel)} but throws an exception in case of failures.
*
* @param versionedModel The RDF model representation of the Aspect model
* @throws AspectLoadingException when elements can not be loaded
* @return the list of model elements
* @throws AspectLoadingException when elements can not be loaded
*/
public static List<ModelElement> getElementsUnchecked( final VersionedModel versionedModel ) {
return getElements( versionedModel ).getOrElseThrow( cause -> {
Expand All @@ -164,7 +167,9 @@ public static List<ModelElement> getElementsUnchecked( final VersionedModel vers
}

/**
* Convenience method that does the same as {@link #getElements(VersionedModel)} except it will return only the aspects contained in the model.
* Convenience method that does the same as {@link #getElements(VersionedModel)} except it will return only the aspects contained in the
* model.
*
* @param versionedModel The RDF model representation of the Aspect model
* @return the list of model aspects
*/
Expand All @@ -177,9 +182,10 @@ public static Try<List<Aspect>> getAspects( final VersionedModel versionedModel

/**
* Does the same as {@link #getAspects(VersionedModel)} but throws an exception in case of failures.
*
* @param versionedModel The RDF model representation of the Aspect model
* @throws AspectLoadingException when elements can not be loaded
* @return the list of model aspects
* @throws AspectLoadingException when elements can not be loaded
*/
public static List<Aspect> getAspectsUnchecked( final VersionedModel versionedModel ) {
return getAspects( versionedModel ).getOrElseThrow( cause -> {
Expand Down Expand Up @@ -217,10 +223,11 @@ public static Aspect getSingleAspectUnchecked( final VersionedModel versionedMod
throw new AspectLoadingException( cause );
} );
}

/**
* Similar to {@link #getSingleAspect(VersionedModel)}, except that a predicate can be provided to select which of potentially
* multiple aspects should be selected
*
* @param versionedModel the RDF model reprensentation of the Aspect model
* @param selector the predicate to select an Aspect
* @return the selected Aspect, or a failure if 0 or more than 1 matching Aspects were found
Expand All @@ -243,14 +250,16 @@ public static Try<Aspect> getSingleAspect( final VersionedModel versionedModel,
* <li>The closure of the loaded model contains exactly one Aspect</li>
* <li>The Aspect has the same name as the file's basename</li>
* </ul>
* The method is intended for use in tests and comparable use cases, not as a general replacement for loading Aspect Models, since it does not
* The method is intended for use in tests and comparable use cases, not as a general replacement for loading Aspect Models, since it
* does not
* handle model files with less or more than one Aspect.
*
* @param input the model file
* @return the loaded Aspect Context
*/
public static Try<AspectContext> getAspectContext( final File input ) {
return AspectModelResolver.loadAndResolveModel( input ).flatMap( versionedModel ->
getSingleAspect( versionedModel, aspect -> aspect.getName().equals( input.getName() ) )
getSingleAspect( versionedModel, aspect -> input.getName().equals( aspect.getName() + ".ttl" ) )
.map( aspect -> new AspectContext( versionedModel, aspect ) ) );
}
}
1 change: 1 addition & 0 deletions core/esmf-aspect-model-aas-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>esmf-test-resources</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
26 changes: 2 additions & 24 deletions core/esmf-aspect-model-document-generators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,13 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java-min-deps</artifactId>
<exclusions>
<exclusion>
<groupId>guru.nidi.com.eclipsesource.j2v8</groupId>
<artifactId>j2v8_linux_x86_64</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Required by graphviz-java -->
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>viz.js-graphviz-java</artifactId>
</dependency>
<!-- Required by graphviz-java -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-rasterizer</artifactId>
</dependency>
<!-- Required by graphviz-java -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
</dependency>
<!-- Required by graphviz-java -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<groupId>org.graphper</groupId>
<artifactId>graph-support</artifactId>
</dependency>
<dependency>
<groupId>com.github.curious-odd-man</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public class DocumentGenerationException extends RuntimeException {
public DocumentGenerationException( final String message ) {
super( message );
}

public DocumentGenerationException( final Throwable cause ) {
super( cause );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.eclipse.esmf.aspectmodel.generator.diagram;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

class AbstractDiagram {
private final Box focusBox;
private final Set<Box> boxes;
private final Set<Edge> edges;

// Used for the special case where a value element is rendered as a string (as part of a parent's attribute)
private String scalarValue = null;

public AbstractDiagram( final Box focusBox ) {
this.focusBox = focusBox;
boxes = new HashSet<>();
addBox( focusBox );
edges = new HashSet<>();
}

static final AbstractDiagram EMPTY = new AbstractDiagram( null );

public void addBox( final Box box ) {
if ( box != null ) {
boxes.add( box );
}
}

public void addEdge( final Edge edge ) {
edges.add( edge );
}

public void addBoxes( final Collection<Box> boxes ) {
for ( final Box box : boxes ) {
addBox( box );
}
}

public void addEdges( final Collection<Edge> edges ) {
this.edges.addAll( edges );
}

public void add( final AbstractDiagram abstractDiagram ) {
addBoxes( abstractDiagram.getBoxes() );
addEdges( abstractDiagram.getEdges() );
}

public void setScalarValue( final String value ) {
scalarValue = value;
}

public Set<Box> getBoxes() {
return boxes;
}

public Set<Edge> getEdges() {
return edges;
}

public Box getFocusBox() {
return focusBox;
}

public String getScalarValue() {
return scalarValue;
}
}
Loading