Skip to content

Commit 6a47363

Browse files
authored
Merge pull request #773 from bci-oss/767-fix-error-reporting
767 fix error reporting
2 parents c215cdc + 5dbe5db commit 6a47363

File tree

144 files changed

+2355
-1350
lines changed

Some content is hidden

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

144 files changed

+2355
-1350
lines changed

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelFile.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public interface AspectModelFile extends ModelElementGroup {
3737
*/
3838
Model sourceModel();
3939

40+
/**
41+
* Returns the RDF/Turtle representation of this Aspect Model File
42+
*
43+
* @return the source representation
44+
*/
45+
String sourceRepresentation();
46+
4047
/**
4148
* The list of Strings that are contained as a comment block at the start of the file. This is often used
4249
* for copyright and license information.
@@ -69,6 +76,16 @@ default Optional<String> spdxLicenseIdentifier() {
6976
*/
7077
Optional<URI> sourceLocation();
7178

79+
/**
80+
* Convenience method to help printing the location of a file: It returns its source location URI if present, or "unknown file"
81+
* if the file does not have a source location.
82+
*
83+
* @return the human readable source location
84+
*/
85+
default String humanReadableLocation() {
86+
return sourceLocation().map( URI::toString ).orElse( "(unknown file)" );
87+
}
88+
7289
/**
7390
* Returns the local file name ("something.ttl") of this AspectModelFile, based on its source location.
7491
*

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/ValueParsingException.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,33 @@
1313

1414
package org.eclipse.esmf.aspectmodel;
1515

16+
import java.net.URI;
17+
18+
import org.apache.jena.rdf.model.Resource;
19+
20+
/**
21+
* Failure to parse a RDF literal
22+
*/
1623
public class ValueParsingException extends RuntimeException {
17-
private final String type;
24+
private final Resource type;
1825
private final Object value;
1926
private long line;
2027
private long column;
28+
private URI sourceLocation;
29+
private String sourceDocument;
2130

22-
public ValueParsingException( final String type, final Object value ) {
31+
public ValueParsingException( final Resource type, final Object value ) {
2332
this.type = type;
2433
this.value = value;
2534
}
2635

27-
public ValueParsingException( final String type, final Object value, final Throwable cause ) {
36+
public ValueParsingException( final Resource type, final Object value, final Throwable cause ) {
2837
super( cause );
2938
this.type = type;
3039
this.value = value;
3140
}
3241

33-
public String getType() {
42+
public Resource getType() {
3443
return type;
3544
}
3645

@@ -55,4 +64,20 @@ public long getLine() {
5564
public long getColumn() {
5665
return column;
5766
}
67+
68+
public String getSourceDocument() {
69+
return sourceDocument;
70+
}
71+
72+
public URI getSourceLocation() {
73+
return sourceLocation;
74+
}
75+
76+
public void setSourceDocument( final String sourceDocument ) {
77+
this.sourceDocument = sourceDocument;
78+
}
79+
80+
public void setSourceLocation( final URI sourceLocation ) {
81+
this.sourceLocation = sourceLocation;
82+
}
5883
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/VersionNumber.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ public static Try<VersionNumber> tryParse( final String versionString ) {
113113
}
114114
final VersionNumberParser parser = new VersionNumberParser( versionString );
115115

116-
int major = 0;
117-
int minor = 0;
118-
int micro = 0;
116+
int major;
117+
int minor;
118+
int micro;
119119

120120
major = parser.parseNextDigit();
121121
minor = parser.parseNextDigit();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for additional
5+
* information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
package org.eclipse.esmf.aspectmodel.validation;
15+
16+
import java.util.Collection;
17+
import java.util.function.Supplier;
18+
19+
import org.eclipse.esmf.metamodel.AspectModel;
20+
21+
import io.vavr.control.Either;
22+
import io.vavr.control.Try;
23+
import org.apache.jena.rdf.model.Model;
24+
25+
/**
26+
* Generic validator for Aspect Models, either on the raw RDF input or on the already loaded Aspect Model
27+
*
28+
* @param <P> the "problem" type that describes loading or validation failures
29+
* @param <C> the "collection of problem" type that constitutes a validation report
30+
*/
31+
public interface Validator<P, C extends Collection<? super P>> {
32+
/**
33+
* Validates a complete RDF input (i.e., this model is expected to contain all necessary definitions, including meta model definitions)
34+
*
35+
* @param model the input model
36+
* @return the validation report
37+
*/
38+
C validateModel( Model model );
39+
40+
/**
41+
* Validates a loaded Aspect Model
42+
*
43+
* @param aspectModel the Aspect Model
44+
* @return the validation report
45+
*/
46+
C validateModel( AspectModel aspectModel );
47+
48+
/**
49+
* Convenience function that takes an Aspect Model loading function as an input and returns the resulting Aspect Model on success,
50+
* or a validation report describing the loading failures on failure
51+
*
52+
* @param aspectModelLoader the Aspect Model loading function
53+
* @return the validation report on failure ({@link Try.Failure}) or the Aspect Model on success ({@link Try.Success})
54+
*/
55+
Either<C, AspectModel> loadModel( Supplier<AspectModel> aspectModelLoader );
56+
57+
/**
58+
* If {@link #loadModel(Supplier)} is called with a loading function that itself makes use of the Validator, the loading function can
59+
* short-circuit the loading-and-validation process and directly return validation results by throwing the exception returned by this
60+
* method.
61+
*
62+
* @param violations the results to return from the loading-and-validation process
63+
* @param <E> the type of exception that is thrown
64+
* @return the exception
65+
*/
66+
<E extends RuntimeException> E cancelValidation( C violations );
67+
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/ModelElement.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.eclipse.esmf.aspectmodel.AspectModelFile;
2020
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
2121
import org.eclipse.esmf.aspectmodel.visitor.AspectVisitor;
22-
import org.eclipse.esmf.samm.KnownVersion;
2322

2423
/**
2524
* The ModelElement interface provides all facilities that all Aspect Model elements have.

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/characteristic/StructuredValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.util.List;
1717

1818
import org.eclipse.esmf.metamodel.Characteristic;
19-
import org.eclipse.esmf.metamodel.Property;
2019

2120
/**
2221
* @since SAMM 1.0.0

0 commit comments

Comments
 (0)