Skip to content

Commit

Permalink
Merge pull request #407 from bci-oss/406-improve-diagram-generation
Browse files Browse the repository at this point in the history
Improve Aspect Model Diagram generation
  • Loading branch information
atextor authored Oct 11, 2023
2 parents f59f71a + 0fb5572 commit 2599683
Show file tree
Hide file tree
Showing 181 changed files with 2,250 additions and 11,096 deletions.
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/[email protected]
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/[email protected]
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

0 comments on commit 2599683

Please sign in to comment.