Skip to content

Commit 6dd0a6c

Browse files
author
Rob Tjalma
authored
Merge pull request #21 from com-pas/integrate-riseclipse
Integrate RiseClipse as Validator in CoMPAS SCL Validator
2 parents 5fb4164 + c848414 commit 6dd0a6c

File tree

51 files changed

+1672
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1672
-152
lines changed

.github/workflows/build-project.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v3
25+
with:
26+
submodules: 'true'
2527
- name: Set up Docker Buildx
2628
id: buildx
2729
uses: docker/setup-buildx-action@v1
@@ -48,9 +50,5 @@ jobs:
4850
with:
4951
output_file: custom_maven_settings.xml
5052
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
51-
- name: Build Native with Maven
52-
if: ${{ github.event_name == 'pull_request' }}
53-
run: ./mvnw -s custom_maven_settings.xml -B -Pnative clean verify
5453
- name: Build with Maven
55-
if: ${{ github.event_name == 'push' }}
5654
run: ./mvnw -s custom_maven_settings.xml -B clean verify

.github/workflows/release-project.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v3
19+
with:
20+
submodules: 'true'
1921
- name: Set up Docker Buildx
2022
id: buildx
2123
uses: docker/setup-buildx-action@v1
@@ -57,6 +59,6 @@ jobs:
5759
env:
5860
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5961
- name: Deploy with Maven to GitHub Packages and Docker Hub
60-
run: ./mvnw -B -s custom_maven_settings.xml -Prelease,native clean deploy
62+
run: ./mvnw -B -s custom_maven_settings.xml -Prelease clean deploy
6163
env:
6264
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/sonarcloud-analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
uses: actions/checkout@v3
3030
with:
3131
fetch-depth: 0
32+
submodules: 'true'
3233

3334
- name: Set up JDK 1.11
3435
uses: actions/setup-java@v3

.gitmodules

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2022 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
#
6+
# Remark: the option to ignore 'untracked' files is needed, because the submodules don't contain a file '.gitignore'.
7+
# This cause the target directories to be untracked.
8+
#
9+
[submodule "riseclipse/riseclipse-developer"]
10+
path = riseclipse/riseclipse-developer
11+
url = [email protected]:riseclipse/riseclipse-developer.git
12+
ignore = dirty
13+
[submodule "riseclipse/riseclipse-main"]
14+
path = riseclipse/riseclipse-main
15+
url = [email protected]:riseclipse/riseclipse-main.git
16+
ignore = dirty
17+
[submodule "riseclipse/riseclipse-metamodel-scl2003"]
18+
path = riseclipse/riseclipse-metamodel-scl2003
19+
url = [email protected]:riseclipse/riseclipse-metamodel-scl2003.git
20+
ignore = dirty
21+
[submodule "riseclipse/riseclipse-ocl-constraints-scl2003"]
22+
path = riseclipse/riseclipse-ocl-constraints-scl2003
23+
url = [email protected]:riseclipse/riseclipse-ocl-constraints-scl2003.git
24+
ignore = dirty

DEVELOPMENT.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2022 Alliander N.V.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
# Development
8+
9+
## Git
10+
11+
If the project is already cloned and a submodule is added use the following commands, first `git submodule init` and
12+
next `git submodule update`.
13+
14+
More about Git Submodules can be found [here](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
15+
16+
**Remark**: The URLs to the submodules are configured in the file `.gitmodules`, but these are using the SSH URLs. There
17+
is a way described [here](https://git-scm.com/book/en/v2/Git-Tools-Submodules) that the URL can be overwritten locally
18+
with an HTTPS URL of the GIT Repository. Because of the subdirectory where the submodules are in, this doesn't work
19+
exactly that way. Use the following commands to update the URLs locally to HTTPS.
20+
21+
```
22+
git config submodule.riseclipse/riseclipse-developer.url https://github.com/riseclipse/riseclipse-developer.git
23+
git config submodule.riseclipse/riseclipse-main.url https://github.com/riseclipse/riseclipse-main.git
24+
git config submodule.riseclipse/riseclipse-metamodel-scl2003.url https://github.com/riseclipse/riseclipse-metamodel-scl2003.git
25+
git config submodule.riseclipse/riseclipse-ocl-constraints-scl2003.url https://github.com/riseclipse/riseclipse-ocl-constraints-scl2003.git
26+
27+
git submodule init
28+
git submodule update
29+
```
30+
31+
## IntelliJ
32+
33+
Importing the project is a bit harder for the SCL Validator then normal. It's caused because of the submodules that are
34+
needed from RiseClipse. These projects are Eclipse projects using Eclipse Tycho to build and Eclipse project structure.
35+
36+
A way to make everything work in IntelliJ is importing the project in the following way.
37+
38+
- First step is to just import everything like it are Maven projects;
39+
- Next step is to re-import the RiseClipse Submodule as Eclipse;
40+
- In IntelliJ select "File" -> "New" -> "Module from Existing Sources...";
41+
- Select one of the RiseClipse Submodules, for instance "riseclipse-metamodel-scl2003";
42+
- Next select "Eclipse" by "Import module from External Model";
43+
- Follow the rest of the wizard, only to remember to select all subprojects that are available in the directory;
44+
45+
Now the module should be correctly imported in IntelliJ to be used. Check the Module Settings of one of the subprojects
46+
to check if the directory "src" is a Java Source Directory, for instance the module
47+
"riseclipse/riseclipse-metamodel-scl2003/fr.centralesupelec.edf.riseclipse.iec61850.scl.utilities".
48+
49+
## Eclipse
50+
51+
Example about how to use Eclipse OCL was found
52+
[here](https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FPivotStandalone.html).
53+
54+
## Running the application in dev mode
55+
56+
You can run your application in dev mode that enables live coding using:
57+
58+
```shell script
59+
./mvnw package io.quarkus:quarkus-maven-plugin::dev
60+
```
61+
62+
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
63+
64+
## Packaging and running the application
65+
66+
The application can be packaged using:
67+
68+
```shell script
69+
./mvnw package
70+
```
71+
72+
It produces the `quarkus-run.jar` file in the `app/target/quarkus-app/` directory. Be aware that it’s not an _über-jar_
73+
as the dependencies are copied into the `app/target/quarkus-app/lib/` directory.
74+
75+
If you want to build an _über-jar_, execute the following command:
76+
77+
```shell script
78+
./mvnw package -Dquarkus.package.type=uber-jar
79+
```
80+
81+
The application is now runnable using `java -jar app/target/quarkus-app/quarkus-run.jar`.
82+

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,38 @@ SPDX-License-Identifier: Apache-2.0
1414

1515
Service to validate SCL Files.
1616

17+
## Development
18+
19+
For the RiseClipse implementation of the validator parts of the RiseClipse project are being used. Currently, these
20+
parts aren't distributed to any Maven Repository, so the Git Repositories need to be included. This is done using Git
21+
Submodules.
22+
23+
To clone the project or update the project this means that the Git commands are sometimes a little different. To clone
24+
the project use the following command `git clone --recurse-submodules [email protected]:com-pas/compas-scl-validator.git`.
25+
This will also clone the submodules.
26+
27+
Tip: The URL to the submodules are configured in the file `.gitmodules`, but these are using the SSH URL. There is a way
28+
described in the URL above that the URL can be overwritten locally with an HTTPS URL of the GIT Repository.
29+
30+
Check the [Development](DEVELOPMENT.md) page for more detail information how to work with this repository, because of
31+
the mixture with RiseClipse.
1732

1833
## Common Environment variables
1934

20-
Below environment variable(s) can be used to configure which claims and information are used to fill the UserInfo
21-
response.
35+
Below environment variable(s) can be used to configure the validator.
2236

23-
| Environment variable | Java Property | Description | Example |
24-
| -------------------------------- | ------------------------------- | ----------------------------------------------------------- | ---------------- |
25-
| USERINFO_NAME_CLAIMNAME | compas.userinfo.name.claimname | The Name of the user logged in. | name |
26-
| USERINFO_WHO_CLAIMNAME | compas.userinfo.who.claimname | The Name of the user used in the Who History. | name |
27-
| USERINFO_SESSION_WARNING | compas.userinfo.session.warning | Number of minutes a Session Warning can be displayed. | 20 |
28-
| USERINFO_SESSION_EXPIRES | compas.userinfo.session.expires | Number of minutes a Session Expires to display in Frontend. | 30 |
37+
| Environment variable | Java Property | Description | Example |
38+
|---------------------------------------|---------------------------------------|---------------------------------------------------|-----------|
39+
| COMPAS_VALIDATOR_OCL_CUSTOM_DIRECTORY | compas.validator.ocl.custom.directory | Reference to a directory to load custom OCL Files | /data/ocl |
2940

3041
## Security
3142

3243
To use most of the endpoints the users needs to be authenticated using JWT in the authorization header. There are 4
3344
environment variables that can be set in the container to configure the validation/processing of the JWT.
3445

35-
| Environment variable | Java Property | Description | Example |
36-
| -------------------------------- | -------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------- |
37-
| JWT_VERIFY_KEY | smallrye.jwt.verify.key.location | Location of certificates to verify the JWT. | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs |
38-
| JWT_VERIFY_ISSUER | mp.jwt.verify.issuer | The issuer of the JWT. | http://localhost:8089/auth/realms/compas |
39-
| JWT_VERIFY_CLIENT_ID | mp.jwt.verify.audiences | The Client ID that should be in the "aud" claim. | scl-validator |
40-
| JWT_GROUPS_PATH | smallrye.jwt.path.groups | The JSON Path where to find the roles of the user. | resource_access/scl-validator/roles |
46+
| Environment variable | Java Property | Description | Example |
47+
|----------------------|----------------------------------|----------------------------------------------------|------------------------------------------------------------------------|
48+
| JWT_VERIFY_KEY | smallrye.jwt.verify.key.location | Location of certificates to verify the JWT. | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs |
49+
| JWT_VERIFY_ISSUER | mp.jwt.verify.issuer | The issuer of the JWT. | http://localhost:8089/auth/realms/compas |
50+
| JWT_VERIFY_CLIENT_ID | mp.jwt.verify.audiences | The Client ID that should be in the "aud" claim. | scl-validator |
51+
| JWT_GROUPS_PATH | smallrye.jwt.path.groups | The JSON Path where to find the roles of the user. | resource_access/scl-validator/roles |

app/pom.xml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ SPDX-License-Identifier: Apache-2.0
8686
<type>test-jar</type>
8787
<scope>test</scope>
8888
</dependency>
89+
<dependency>
90+
<groupId>org.lfenergy.compas.scl.validator</groupId>
91+
<artifactId>validator-riseclipse</artifactId>
92+
<type>test-jar</type>
93+
<scope>test</scope>
94+
</dependency>
8995

9096
<dependency>
9197
<groupId>io.quarkus</groupId>
@@ -112,6 +118,11 @@ SPDX-License-Identifier: Apache-2.0
112118
<artifactId>quarkus-jacoco</artifactId>
113119
<scope>test</scope>
114120
</dependency>
121+
<dependency>
122+
<groupId>org.mockito</groupId>
123+
<artifactId>mockito-junit-jupiter</artifactId>
124+
<scope>test</scope>
125+
</dependency>
115126
<dependency>
116127
<groupId>com.openpojo</groupId>
117128
<artifactId>openpojo</artifactId>
@@ -156,8 +167,13 @@ SPDX-License-Identifier: Apache-2.0
156167

157168
<properties>
158169
<quarkus.package.type>native</quarkus.package.type>
159-
<quarkus.native.container-build>true</quarkus.native.container-build> <!-- Allows for creating a Linux executable without GraalVM being installed -->
160-
<quarkus.container-image.build>true</quarkus.container-image.build> <!-- Also make a Docker Image, so the native test will be executed against the container -->
170+
<!-- Allows for creating a Linux executable without GraalVM being installed -->
171+
<quarkus.native.container-build>true</quarkus.native.container-build>
172+
<!-- Also make a Docker Image, so the native test will be executed against the container -->
173+
<quarkus.container-image.build>true</quarkus.container-image.build>
174+
<quarkus.native.additional-build-args>
175+
--allow-incomplete-classpath
176+
</quarkus.native.additional-build-args>
161177
</properties>
162178

163179
<build>
@@ -174,8 +190,12 @@ SPDX-License-Identifier: Apache-2.0
174190
</goals>
175191
<configuration>
176192
<systemPropertyVariables>
177-
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
178-
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
193+
<native.image.path>
194+
${project.build.directory}/${project.build.finalName}-runner
195+
</native.image.path>
196+
<java.util.logging.manager>
197+
org.jboss.logmanager.LogManager
198+
</java.util.logging.manager>
179199
<maven.home>${maven.home}</maven.home>
180200
</systemPropertyVariables>
181201
</configuration>
@@ -201,8 +221,8 @@ SPDX-License-Identifier: Apache-2.0
201221
<id>release</id>
202222

203223
<properties>
204-
<!-- Properties only used for publishing a native docker image (default to Docker Hub) -->
205224
<quarkus.container-image.build>true</quarkus.container-image.build>
225+
<!-- Properties only used for publishing a native docker image (default to Docker Hub) -->
206226
<quarkus.container-image.push>true</quarkus.container-image.push>
207227
<quarkus.container-image.additional-tags>latest</quarkus.container-image.additional-tags>
208228
</properties>

app/src/main/docker/Dockerfile.jvm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ COPY --chown=1001 target/quarkus-app/*.jar /deployments/
4848
COPY --chown=1001 target/quarkus-app/app/ /deployments/app/
4949
COPY --chown=1001 target/quarkus-app/quarkus/ /deployments/quarkus/
5050

51+
RUN mkdir -p /data/ocl \
52+
&& mkdir -p /data/temp \
53+
&& chown -R 1001 /data \
54+
&& chmod -R "g+rwX" /data
55+
VOLUME /data/ocl
56+
5157
EXPOSE 8080
5258
USER 1001
5359

app/src/main/docker/Dockerfile.native

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ RUN chown 1001 /work \
2121
&& chown 1001:root /work
2222
COPY --chown=1001:root target/*-runner /work/application
2323

24+
RUN mkdir -p /data/ocl \
25+
&& mkdir -p /data/temp \
26+
&& chown -R 1001 /data \
27+
&& chmod -R "g+rwX" /data
28+
VOLUME /data/ocl
29+
2430
EXPOSE 8080
2531
USER 1001
2632

app/src/main/java/org/lfenergy/compas/scl/validator/rest/CompasSclValidatorConfiguration.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
package org.lfenergy.compas.scl.validator.rest;
55

66
import org.lfenergy.compas.core.commons.ElementConverter;
7+
import org.lfenergy.compas.scl.validator.collector.CompasOclFileCollector;
8+
import org.lfenergy.compas.scl.validator.collector.OclFileCollector;
9+
import org.lfenergy.compas.scl.validator.impl.SclRiseClipseValidator;
710

811
import javax.enterprise.context.ApplicationScoped;
912
import javax.enterprise.inject.Produces;
@@ -17,4 +20,17 @@ public class CompasSclValidatorConfiguration {
1720
public ElementConverter createElementConverter() {
1821
return new ElementConverter();
1922
}
23+
24+
@Produces
25+
@ApplicationScoped
26+
public OclFileCollector createOclFileCollector(ValidatorProperties properties) {
27+
return new CompasOclFileCollector(properties.oclCustomDirectory());
28+
}
29+
30+
@Produces
31+
@ApplicationScoped
32+
public SclRiseClipseValidator createSclRiseClipseValidator(OclFileCollector oclFileCollector,
33+
ValidatorProperties properties) {
34+
return new SclRiseClipseValidator(oclFileCollector, properties.tempDirectory());
35+
}
2036
}

0 commit comments

Comments
 (0)