From 87383539d10226fb9839b3a071c244ece43741f0 Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Wed, 9 Apr 2025 11:37:02 +0200 Subject: [PATCH 1/7] Remove usage of Lombok Lombok was introduced before certain Java features, such as records, were available. Removing it simplifies build setup and reduces cognitive load when reading code. --- CONVENTIONS.md | 6 +- core/esmf-aspect-meta-model-interface/pom.xml | 4 - core/esmf-aspect-meta-model-java/pom.xml | 5 - .../esmf/aspectmodel/generator/Generator.java | 11 +- .../resolver/NamespacePackage.java | 7 +- .../exceptions/ModelResolutionException.java | 7 +- .../modelfile/DefaultAspectModelFile.java | 11 +- .../resolver/modelfile/MetaModelFile.java | 11 +- .../resolver/services/DataTypeTest.java | 16 ++- .../pom.xml | 5 - core/esmf-aspect-model-java-generator/pom.xml | 10 -- .../java/ValueExpressionVisitor.java | 17 ++- .../StaticCodeGenerationContext.java | 16 +-- .../metamodel/StaticMetaModelVisitor.java | 115 +++++++++--------- core/esmf-aspect-model-validator/pom.xml | 18 --- .../java/org/eclipse/esmf/aas/AasCommand.java | 2 - .../esmf/namespacepackage/PackageCommand.java | 1 - 17 files changed, 115 insertions(+), 147 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index a243c3d7f..c4e83d542 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -55,10 +55,8 @@ if (someOptional != null && someOptional.isPresent()) ... * You should be using Objects.requireNonNull() for those sort of checks (or Guava's Preconditions if you're having more types of assertions than non-null and aim for a maximum of consistency). ### Lombok -We use Lombok in the ESMF SDK. Project Lombok is a Java library that automatically plugs into your -editor and build tools. It removes the burden to write getter or equals methods, adds fully featured -builders to a class with one annotation, automates logging variables, and much more. Consider using -its features if you are in the need to do something like that. +Lombok was used in the past, but is not used anymore in the ESMF SDK. Instead of the `@Value` or +`@Data` annotations, consider using Java records. ## Documentation diff --git a/core/esmf-aspect-meta-model-interface/pom.xml b/core/esmf-aspect-meta-model-interface/pom.xml index 9bf86321c..89dc63282 100644 --- a/core/esmf-aspect-meta-model-interface/pom.xml +++ b/core/esmf-aspect-meta-model-interface/pom.xml @@ -48,10 +48,6 @@ jakarta.xml.bind jakarta.xml.bind-api - - org.projectlombok - lombok - org.junit.jupiter diff --git a/core/esmf-aspect-meta-model-java/pom.xml b/core/esmf-aspect-meta-model-java/pom.xml index 6fe5b756f..5e938a839 100644 --- a/core/esmf-aspect-meta-model-java/pom.xml +++ b/core/esmf-aspect-meta-model-java/pom.xml @@ -180,11 +180,6 @@ maven-compiler-plugin - - org.projectlombok - lombok - ${lombok-version} - io.soabase.record-builder record-builder-processor diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/generator/Generator.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/generator/Generator.java index 2f9855432..71380c201 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/generator/Generator.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/generator/Generator.java @@ -22,7 +22,6 @@ import org.eclipse.esmf.functions.ThrowingFunction; import org.eclipse.esmf.metamodel.ModelElement; -import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,10 +40,8 @@ public abstract class Generator uniqueByModelElementIdentifier = ( modelElementOne, modelElementTwo ) -> { final String modelElementOneIdentifier = modelElementOne.urn().toString(); @@ -135,4 +132,12 @@ protected void writeThrowing( final Artifact artifac LOG.error( "Failure during writing of generated artifact", exception ); } } + + public F getFocus() { + return focus; + } + + public C getConfig() { + return config; + } } diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java index 04655eb1c..d7d35842a 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java @@ -46,7 +46,6 @@ import org.eclipse.esmf.metamodel.Namespace; import com.google.common.collect.ImmutableList; -import lombok.Getter; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +62,6 @@ public class NamespacePackage implements ResolutionStrategy, Artifact files; @@ -314,8 +312,11 @@ public byte[] serialize() { * * @return the location if set, or null */ - @SuppressWarnings( { "LombokGetterMayBeUsed", "RedundantSuppression" } ) public URI getLocation() { return location; } + + public String getModelsRoot() { + return modelsRoot; + } } diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/exceptions/ModelResolutionException.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/exceptions/ModelResolutionException.java index 542995ec4..8a03dd349 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/exceptions/ModelResolutionException.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/exceptions/ModelResolutionException.java @@ -18,9 +18,6 @@ import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; -import lombok.Getter; - -@Getter public class ModelResolutionException extends RuntimeException { public record LoadingFailure( AspectModelUrn element, @@ -56,4 +53,8 @@ public ModelResolutionException( final String message, final Throwable cause ) { super( message, cause ); checkedLocations = List.of(); } + + public List getCheckedLocations() { + return checkedLocations; + } } diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/DefaultAspectModelFile.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/DefaultAspectModelFile.java index b143f0ca1..463df18f2 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/DefaultAspectModelFile.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/DefaultAspectModelFile.java @@ -22,7 +22,6 @@ import org.eclipse.esmf.metamodel.ModelElement; import org.eclipse.esmf.metamodel.Namespace; -import lombok.Setter; import org.apache.jena.rdf.model.Model; /** @@ -33,9 +32,7 @@ public final class DefaultAspectModelFile implements AspectModelFile { private final Model sourceModel; private final List headerComment; private final Optional sourceLocation; - @Setter private List elements; - @Setter private Namespace namespace = null; public DefaultAspectModelFile( final Model sourceModel, final List headerComment, final Optional sourceLocation ) { @@ -99,4 +96,12 @@ public int hashCode() { public String toString() { return sourceLocation().map( URI::toString ).orElse( "(unknown file)" ); } + + public void setElements( final List elements ) { + this.elements = elements; + } + + public void setNamespace( final Namespace namespace ) { + this.namespace = namespace; + } } diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/MetaModelFile.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/MetaModelFile.java index 0aa7d7f20..7d2cf8e5d 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/MetaModelFile.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/MetaModelFile.java @@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; import io.vavr.Tuple2; -import lombok.Getter; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Property; @@ -71,9 +70,7 @@ public enum MetaModelFileType { SHAPE_DEFINITION } - @Getter private final RdfNamespace rdfNamespace; - @Getter private final MetaModelFileType metaModelFileType; private final Model sourceModel; private final String filename; @@ -226,4 +223,12 @@ private URL url( final String section, final String filename ) { throw new AspectLoadingException( "Could not resolve meta model file: " + filename ); } } + + public RdfNamespace getRdfNamespace() { + return rdfNamespace; + } + + public MetaModelFileType getMetaModelFileType() { + return metaModelFileType; + } } diff --git a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/services/DataTypeTest.java b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/services/DataTypeTest.java index ef74e768f..32029bdf9 100644 --- a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/services/DataTypeTest.java +++ b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/services/DataTypeTest.java @@ -29,7 +29,6 @@ import org.eclipse.esmf.metamodel.datatype.SammType; import org.eclipse.esmf.metamodel.datatype.SammXsdType; -import lombok.Value; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -60,7 +59,7 @@ public void testSerialization( final TestConfiguration testConfiguration @ParameterizedTest @MethodSource( value = "getTestConfigurationsWithLexicalErrors" ) public void testConfigurableParserChecks( final TestConfiguration testConfiguration ) { - testConfiguration.predicates.keySet().forEach( testValue -> { + testConfiguration.predicates().keySet().forEach( testValue -> { SammXsdType.setChecking( false ); final Object parsedUntypedObject = testConfiguration.type.parse( testValue ); assertThat( parsedUntypedObject ).isEqualTo( testValue ); @@ -81,11 +80,10 @@ public void testConfigurableParserChecks( final TestConfiguration testCon } ); } - @Value - private static class TestConfiguration { - SammType type; - Map> predicates; - + private record TestConfiguration( + SammType type, + Map> predicates + ) { @Override public String toString() { return type.toString(); @@ -322,8 +320,8 @@ static Stream> getValidTestConfigurations() { && dataType.getJavaClass().equals( Curie.class ) ) .map( dataType -> (SammType) dataType ) .map( curieType -> new TestConfiguration<>( curieType, Map.of( - "xsd:string", v -> ((Curie) v).value().equals( "xsd:string" ), - "unit:hectopascal", v -> ((Curie) v).value().equals( "unit:hectopascal" ) + "xsd:string", v -> ( (Curie) v ).value().equals( "xsd:string" ), + "unit:hectopascal", v -> ( (Curie) v ).value().equals( "unit:hectopascal" ) ) ) ); return Stream.concat( extendedXsdTypes, curieTypes ); diff --git a/core/esmf-aspect-model-document-generators/pom.xml b/core/esmf-aspect-model-document-generators/pom.xml index b8b422b28..d68c6d24b 100644 --- a/core/esmf-aspect-model-document-generators/pom.xml +++ b/core/esmf-aspect-model-document-generators/pom.xml @@ -177,11 +177,6 @@ maven-compiler-plugin - - org.projectlombok - lombok - ${lombok-version} - io.soabase.record-builder record-builder-processor diff --git a/core/esmf-aspect-model-java-generator/pom.xml b/core/esmf-aspect-model-java-generator/pom.xml index d22084059..3bd44f6a4 100644 --- a/core/esmf-aspect-model-java-generator/pom.xml +++ b/core/esmf-aspect-model-java-generator/pom.xml @@ -65,11 +65,6 @@ com.fasterxml.jackson.core jackson-databind - - org.projectlombok - lombok - provided - @@ -184,11 +179,6 @@ maven-compiler-plugin - - org.projectlombok - lombok - ${lombok-version} - io.soabase.record-builder record-builder-processor diff --git a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/ValueExpressionVisitor.java b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/ValueExpressionVisitor.java index f497775c0..b464dd349 100644 --- a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/ValueExpressionVisitor.java +++ b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/ValueExpressionVisitor.java @@ -46,11 +46,10 @@ public class ValueExpressionVisitor implements AspectVisitor { private final ValueInitializer valueInitializer = new ValueInitializer(); - @lombok.Value - public static class Context { - JavaCodeGenerationConfig codeGenerationConfig; - boolean isOptional; - } + public record Context( + JavaCodeGenerationConfig codeGenerationConfig, + boolean isOptional + ) {} @Override public String visitBase( final ModelElement modelElement, final Context context ) { @@ -69,8 +68,8 @@ public String visitScalarValue( final ScalarValue value, final Context context ) private String generateValueExpression( final ScalarValue value, final Context context ) { final String typeUri = value.getType().as( Scalar.class ).getUrn(); if ( typeUri.equals( RDF.langString.getURI() ) ) { - context.getCodeGenerationConfig().importTracker().importExplicit( LangString.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Locale.class ); + context.codeGenerationConfig().importTracker().importExplicit( LangString.class ); + context.codeGenerationConfig().importTracker().importExplicit( Locale.class ); final LangString langStringValue = (LangString) value.as( ScalarValue.class ).getValue(); return String.format( "new LangString(\"%s\", Locale.forLanguageTag(\"%s\"))", AspectModelJavaUtil.escapeForLiteral( langStringValue.getValue() ), @@ -79,14 +78,14 @@ private String generateValueExpression( final ScalarValue value, final Context c final Resource typeResource = ResourceFactory.createResource( typeUri ); final Class javaType = SammXsdType.getJavaTypeForMetaModelType( typeResource ); - context.getCodeGenerationConfig().importTracker().importExplicit( javaType ); + context.codeGenerationConfig().importTracker().importExplicit( javaType ); return valueInitializer.apply( typeResource, javaType, AspectModelJavaUtil.createLiteral( value.getValue().toString() ) ); } @Override public String visitCollectionValue( final CollectionValue collection, final Context context ) { final Class collectionClass = collection.getValues().getClass(); - context.getCodeGenerationConfig().importTracker().importExplicit( collectionClass ); + context.codeGenerationConfig().importTracker().importExplicit( collectionClass ); final StringBuilder result = new StringBuilder(); result.append( "new " ); result.append( collectionClass.getSimpleName() ); diff --git a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticCodeGenerationContext.java b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticCodeGenerationContext.java index b0e4568e4..179ed78c7 100644 --- a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticCodeGenerationContext.java +++ b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticCodeGenerationContext.java @@ -16,11 +16,13 @@ import org.eclipse.esmf.aspectmodel.java.JavaCodeGenerationConfig; import org.eclipse.esmf.metamodel.Characteristic; -@lombok.Value -@lombok.With -public class StaticCodeGenerationContext { - JavaCodeGenerationConfig codeGenerationConfig; - String modelUrnPrefix; - String characteristicBaseUrn; - Characteristic currentCharacteristic; +public record StaticCodeGenerationContext( + JavaCodeGenerationConfig codeGenerationConfig, + String modelUrnPrefix, + String characteristicBaseUrn, + Characteristic currentCharacteristic +) { + public StaticCodeGenerationContext withCurrentCharacteristic( final Characteristic characteristic ) { + return new StaticCodeGenerationContext( codeGenerationConfig(), modelUrnPrefix(), characteristicBaseUrn(), characteristic ); + } } diff --git a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java index a076d4d9c..b55796eb0 100644 --- a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java +++ b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java @@ -27,7 +27,6 @@ import org.eclipse.esmf.aspectmodel.java.ValueExpressionVisitor; import org.eclipse.esmf.aspectmodel.java.ValueInitializer; import org.eclipse.esmf.aspectmodel.java.exception.CodeGenerationException; -import org.eclipse.esmf.aspectmodel.loader.MetaModelBaseAttributes; import org.eclipse.esmf.aspectmodel.visitor.AspectVisitor; import org.eclipse.esmf.metamodel.AbstractEntity; import org.eclipse.esmf.metamodel.BoundDefinition; @@ -110,8 +109,8 @@ public String visitBase( final ModelElement modelElement, final StaticCodeGenera @Override public String visitScalarValue( final ScalarValue value, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultScalarValue.class ); - final ValueExpressionVisitor.Context valueContext = new ValueExpressionVisitor.Context( context.getCodeGenerationConfig(), false ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultScalarValue.class ); + final ValueExpressionVisitor.Context valueContext = new ValueExpressionVisitor.Context( context.codeGenerationConfig(), false ); final String metaModelAttributes = ( !value.getSee().isEmpty() && !value.getPreferredNames().isEmpty() ) ? getMetaModelBaseAttributes( value, context ) : "MetaModelBaseAttributes.builder().build()"; @@ -127,8 +126,8 @@ public String visitScalarValue( final ScalarValue value, final StaticCodeGenerat @Override public String visitCollectionValue( final CollectionValue collection, final StaticCodeGenerationContext context ) { final Class collectionClass = collection.getValues().getClass(); - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultCollectionValue.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( collectionClass ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultCollectionValue.class ); + context.codeGenerationConfig().importTracker().importExplicit( collectionClass ); final StringBuilder result = new StringBuilder(); result.append( "new DefaultCollectionValue(" ); // Collection values @@ -153,11 +152,11 @@ public String visitCollectionValue( final CollectionValue collection, final Stat @Override public String visitEntityInstance( final EntityInstance instance, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultEntityInstance.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Map.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( HashMap.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Property.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Value.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultEntityInstance.class ); + context.codeGenerationConfig().importTracker().importExplicit( Map.class ); + context.codeGenerationConfig().importTracker().importExplicit( HashMap.class ); + context.codeGenerationConfig().importTracker().importExplicit( Property.class ); + context.codeGenerationConfig().importTracker().importExplicit( Value.class ); final Entity entity = instance.getEntityType(); final StringBuilder builder = new StringBuilder(); builder.append( "new DefaultEntityInstance(" ); @@ -188,7 +187,7 @@ public String visitEntityInstance( final EntityInstance instance, final StaticCo @Override public String visitSingleEntity( final SingleEntity singleEntity, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultSingleEntity.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultSingleEntity.class ); return "new DefaultSingleEntity(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( singleEntity, context ) + ", " @@ -205,7 +204,7 @@ public String visitCollection( final Collection collection, final StaticCodeGene default -> DefaultCollection.class; }; - context.getCodeGenerationConfig().importTracker().importExplicit( implementationClass ); + context.codeGenerationConfig().importTracker().importExplicit( implementationClass ); final String optionalType = collection.getDataType().map( type -> type.accept( this, context ) ) .map( type -> "Optional.of(" + type + ")" ) .orElse( "Optional.empty()" ); @@ -219,7 +218,7 @@ public String visitCollection( final Collection collection, final StaticCodeGene @Override public String visitCode( final Code code, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultCode.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultCode.class ); return "new DefaultCode(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( code, context ) + "," @@ -243,8 +242,8 @@ public String visitQuantifiable( final Quantifiable quantifiable, final StaticCo } private String generateForQuantifiable( final T quantifiable, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( quantifiable.getClass() ); - context.getCodeGenerationConfig().importTracker().importExplicit( Units.class ); + context.codeGenerationConfig().importTracker().importExplicit( quantifiable.getClass() ); + context.codeGenerationConfig().importTracker().importExplicit( Units.class ); return "new " + quantifiable.getClass().getSimpleName() + "(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( quantifiable, context ) + "," @@ -262,13 +261,13 @@ private String optionalString( final Optional optionalString ) { public String visitUnit( final Unit unit, final StaticCodeGenerationContext context ) { final Optional unitFromCatalog = Units.fromName( unit.getName() ); if ( unitFromCatalog.isPresent() ) { - context.getCodeGenerationConfig().importTracker().importExplicit( Units.class ); + context.codeGenerationConfig().importTracker().importExplicit( Units.class ); return "Units.fromName(\"" + unit.getName() + "\")"; } - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultUnit.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( HashSet.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Optional.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultUnit.class ); + context.codeGenerationConfig().importTracker().importExplicit( HashSet.class ); + context.codeGenerationConfig().importTracker().importExplicit( Optional.class ); return "Optional.of(new DefaultUnit(" + getMetaModelBaseAttributes( unit, context ) + "," + optionalString( unit.getSymbol() ) + "," @@ -288,12 +287,12 @@ public String visitUnit( final Unit unit, final StaticCodeGenerationContext cont public String visitQuantityKind( final QuantityKind quantityKind, final StaticCodeGenerationContext context ) { // The quantity kind is one of the default ones defined in the QuantityKinds enum? if ( QuantityKinds.fromName( quantityKind.getName() ).isPresent() ) { - context.getCodeGenerationConfig().importTracker().importExplicit( QuantityKinds.class ); + context.codeGenerationConfig().importTracker().importExplicit( QuantityKinds.class ); return "QuantityKinds." + AspectModelJavaUtil.toConstant( quantityKind.getName() ); } // If not, create a new instance of the default implementation - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultQuantityKind.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultQuantityKind.class ); return "new DefaultQuantityKind(" + getMetaModelBaseAttributes( quantityKind, context ) + "," + "\"" + StringEscapeUtils.escapeJava( quantityKind.getLabel() ) + "\"" @@ -302,9 +301,9 @@ public String visitQuantityKind( final QuantityKind quantityKind, final StaticCo @Override public String visitState( final State state, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultState.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( ArrayList.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Value.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultState.class ); + context.codeGenerationConfig().importTracker().importExplicit( ArrayList.class ); + context.codeGenerationConfig().importTracker().importExplicit( Value.class ); return "new DefaultState(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( state, context ) + "," @@ -320,9 +319,9 @@ public String visitState( final State state, final StaticCodeGenerationContext c @Override public String visitEnumeration( final Enumeration enumeration, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultEnumeration.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( ArrayList.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Value.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultEnumeration.class ); + context.codeGenerationConfig().importTracker().importExplicit( ArrayList.class ); + context.codeGenerationConfig().importTracker().importExplicit( Value.class ); return "new DefaultEnumeration(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( enumeration, context ) + "," @@ -336,8 +335,8 @@ public String visitEnumeration( final Enumeration enumeration, final StaticCodeG @Override public String visitStructuredValue( final StructuredValue structuredValue, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultStructuredValue.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( ArrayList.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultStructuredValue.class ); + context.codeGenerationConfig().importTracker().importExplicit( ArrayList.class ); return "new DefaultStructuredValue(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( structuredValue, context ) + "," @@ -353,8 +352,8 @@ public String visitStructuredValue( final StructuredValue structuredValue, final @Override public String visitTrait( final Trait trait, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultTrait.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( ArrayList.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultTrait.class ); + context.codeGenerationConfig().importTracker().importExplicit( ArrayList.class ); return "new DefaultTrait(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( trait, context ) + "," @@ -368,7 +367,7 @@ public String visitTrait( final Trait trait, final StaticCodeGenerationContext c @Override public String visitCharacteristic( final Characteristic characteristic, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultCharacteristic.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultCharacteristic.class ); return "new DefaultCharacteristic(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( characteristic, context ) + "," @@ -379,7 +378,7 @@ public String visitCharacteristic( final Characteristic characteristic, final St @Override public String visitLengthConstraint( final LengthConstraint lengthConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultLengthConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultLengthConstraint.class ); final Scalar nonNegativeInteger = new DefaultScalar( XSD.nonNegativeInteger.getURI() ); return "new DefaultLengthConstraint(" // MetaModelBaseAttributes @@ -392,9 +391,9 @@ public String visitLengthConstraint( final LengthConstraint lengthConstraint, fi @Override public String visitRangeConstraint( final RangeConstraint rangeConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultRangeConstraint.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( BoundDefinition.class ); - final Type characteristicType = context.getCurrentCharacteristic().getDataType().orElseThrow( noTypeException ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultRangeConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( BoundDefinition.class ); + final Type characteristicType = context.currentCharacteristic().getDataType().orElseThrow( noTypeException ); return "new DefaultRangeConstraint(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( rangeConstraint, context ) + "," @@ -411,7 +410,7 @@ public String visitRangeConstraint( final RangeConstraint rangeConstraint, final @Override public String visitRegularExpressionConstraint( final RegularExpressionConstraint regularExpressionConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultRegularExpressionConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultRegularExpressionConstraint.class ); return "new DefaultRegularExpressionConstraint(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( regularExpressionConstraint, context ) + "," @@ -421,8 +420,8 @@ public String visitRegularExpressionConstraint( final RegularExpressionConstrain @Override public String visitEncodingConstraint( final EncodingConstraint encodingConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultEncodingConstraint.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Charset.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultEncodingConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( Charset.class ); return "new DefaultEncodingConstraint(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( encodingConstraint, context ) + "," @@ -432,8 +431,8 @@ public String visitEncodingConstraint( final EncodingConstraint encodingConstrai @Override public String visitLanguageConstraint( final LanguageConstraint languageConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultLanguageConstraint.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Locale.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultLanguageConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( Locale.class ); return "new DefaultLanguageConstraint(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( languageConstraint, context ) + "," @@ -443,8 +442,8 @@ public String visitLanguageConstraint( final LanguageConstraint languageConstrai @Override public String visitLocaleConstraint( final LocaleConstraint localeConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultLocaleConstraint.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( Locale.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultLocaleConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( Locale.class ); return "new DefaultLanguageConstraint(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( localeConstraint, context ) + "," @@ -454,7 +453,7 @@ public String visitLocaleConstraint( final LocaleConstraint localeConstraint, fi @Override public String visitFixedPointConstraint( final FixedPointConstraint fixedPointConstraint, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultFixedPointConstraint.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultFixedPointConstraint.class ); return "new DefaultFixedPointConstraint(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( fixedPointConstraint, context ) + "," @@ -471,7 +470,7 @@ public String visitConstraint( final Constraint constraint, final StaticCodeGene @Override public String visitEntity( final Entity entity, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultEntity.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultEntity.class ); return "DefaultEntity.createDefaultEntity(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( entity, context ) + "," @@ -483,7 +482,7 @@ public String visitEntity( final Entity entity, final StaticCodeGenerationContex @Override public String visitAbstractEntity( final AbstractEntity abstractEntity, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultAbstractEntity.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultAbstractEntity.class ); return "DefaultAbstractEntity.createDefaultAbstractEntity(" // MetaModelBaseAttributes + getMetaModelBaseAttributes( abstractEntity, context ) + "," @@ -499,7 +498,7 @@ public String visitAbstractEntity( final AbstractEntity abstractEntity, final St @Override public String visitScalar( final Scalar scalar, final StaticCodeGenerationContext context ) { - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultScalar.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultScalar.class ); return "new DefaultScalar(\"" + scalar.getUrn() + "\" )"; } @@ -511,13 +510,13 @@ private String extendsComplexType( final ComplexType complexType, final StaticCo final ComplexType type = complexType.getExtends().get(); if ( type.is( Entity.class ) ) { final Entity entity = type.as( Entity.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultEntity.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultEntity.class ); return "Optional.of(DefaultEntity.createDefaultEntity(" + getMetaModelBaseAttributes( complexType, context ) + "," + "Meta" + entity.getName() + ".INSTANCE.getProperties()," + extendsComplexType( entity, context ) + "))"; } // AbstractEntity final AbstractEntity abstractEntity = type.as( AbstractEntity.class ); - context.getCodeGenerationConfig().importTracker().importExplicit( DefaultAbstractEntity.class ); + context.codeGenerationConfig().importTracker().importExplicit( DefaultAbstractEntity.class ); return "Optional.of(DefaultAbstractEntity.createDefaultAbstractEntity(" + getMetaModelBaseAttributes( abstractEntity, context ) + "," + "Meta" + abstractEntity.getName() + ".INSTANCE.getProperties()," + extendsComplexType( abstractEntity, context ) + "," + "List.of(" @@ -532,11 +531,11 @@ private String getOptionalStaticDeclarationValue( final Type type, final Opt return "Optional.empty()"; } - if ( optionalValue.get() instanceof ScalarValue scalarValue ) { - return "Optional.of(" + (scalarValue).accept( this, context ) + ")"; + if ( optionalValue.get() instanceof final ScalarValue scalarValue ) { + return "Optional.of(" + ( scalarValue ).accept( this, context ) + ")"; } - context.getCodeGenerationConfig().importTracker().importExplicit( AspectModelJavaUtil.getDataTypeClass( type ) ); + context.codeGenerationConfig().importTracker().importExplicit( AspectModelJavaUtil.getDataTypeClass( type ) ); final Resource xsdType = ResourceFactory.createResource( type.getUrn() ); String valueExpression = optionalValue.get().toString(); if ( type.getUrn().endsWith( "#float" ) ) { @@ -553,10 +552,10 @@ private String getOptionalStaticDeclarationValue( final Type type, final Opt public String exampleValue( final Property property, final StaticCodeGenerationContext context ) { return property.getExampleValue() .map( exampleValue -> { - if ( exampleValue instanceof ScalarValue scalarValue ) { - return "Optional.of(" + this.visitScalarValue( scalarValue, context ) + ")"; - } else if ( exampleValue instanceof Value value ) { - return "Optional.of(" + this.visitValue( value, context ) + ")"; + if ( exampleValue instanceof final ScalarValue scalarValue ) { + return "Optional.of(" + visitScalarValue( scalarValue, context ) + ")"; + } else if ( exampleValue instanceof final Value value ) { + return "Optional.of(" + visitValue( value, context ) + ")"; } else { throw new IllegalArgumentException( "Unexpected exampleValue type: " + exampleValue.getClass() ); } @@ -600,10 +599,10 @@ public String getMetaModelBaseAttributes( final ModelElement element, final Stat } public String elementUrn( final ModelElement element, final StaticCodeGenerationContext context ) { - if ( element.urn().toString().startsWith( context.getModelUrnPrefix() ) ) { + if ( element.urn().toString().startsWith( context.modelUrnPrefix() ) ) { return "AspectModelUrn.fromUrn( NAMESPACE + \"" + element.getName() + "\" )"; } - if ( element.urn().toString().startsWith( context.getCharacteristicBaseUrn() ) ) { + if ( element.urn().toString().startsWith( context.characteristicBaseUrn() ) ) { return "AspectModelUrn.fromUrn( CHARACTERISTIC_NAMESPACE + \"#" + element.getName() + "\" )"; } return "AspectModelUrn.fromUrn( \"" + element.urn() + "\" )"; diff --git a/core/esmf-aspect-model-validator/pom.xml b/core/esmf-aspect-model-validator/pom.xml index 7075f1cf7..d1112dc3f 100644 --- a/core/esmf-aspect-model-validator/pom.xml +++ b/core/esmf-aspect-model-validator/pom.xml @@ -55,11 +55,6 @@ org.graalvm.js js-scriptengine - - org.projectlombok - lombok - provided - org.slf4j slf4j-api @@ -109,19 +104,6 @@ true - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - ${lombok-version} - - - - diff --git a/tools/samm-cli/src/main/java/org/eclipse/esmf/aas/AasCommand.java b/tools/samm-cli/src/main/java/org/eclipse/esmf/aas/AasCommand.java index 767ebe3ba..ee369deb8 100644 --- a/tools/samm-cli/src/main/java/org/eclipse/esmf/aas/AasCommand.java +++ b/tools/samm-cli/src/main/java/org/eclipse/esmf/aas/AasCommand.java @@ -4,7 +4,6 @@ import org.eclipse.esmf.LoggingMixin; import org.eclipse.esmf.exception.SubCommandException; -import lombok.Getter; import picocli.CommandLine; @CommandLine.Command( @@ -35,7 +34,6 @@ public class AasCommand extends AbstractCommand { ) private String input; - @SuppressWarnings( { "LombokGetterMayBeUsed", "RedundantSuppression" } ) public String getInput() { return input; } diff --git a/tools/samm-cli/src/main/java/org/eclipse/esmf/namespacepackage/PackageCommand.java b/tools/samm-cli/src/main/java/org/eclipse/esmf/namespacepackage/PackageCommand.java index f86fd5d53..3eaaea781 100644 --- a/tools/samm-cli/src/main/java/org/eclipse/esmf/namespacepackage/PackageCommand.java +++ b/tools/samm-cli/src/main/java/org/eclipse/esmf/namespacepackage/PackageCommand.java @@ -54,7 +54,6 @@ public void run() { throw new SubCommandException( COMMAND_NAME ); } - @SuppressWarnings( { "LombokGetterMayBeUsed", "RedundantSuppression" } ) public String getInput() { return input; } From a714a622b5d040958f1a47f789c05827b154f895 Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Wed, 9 Apr 2025 11:46:41 +0200 Subject: [PATCH 2/7] Remove unnecessary Maven plugin configuration The esmf-sdk-test-report module has been removed, so the overrides in the modules are not required anymore --- .github/workflows/release-workflow.yml | 2 +- core/esmf-aspect-meta-model-java/pom.xml | 22 ---------- .../pom.xml | 20 --------- core/esmf-aspect-model-generator/pom.xml | 20 --------- core/esmf-aspect-model-jackson/pom.xml | 27 ------------ core/esmf-aspect-model-java-core/pom.xml | 44 ++++--------------- core/esmf-aspect-model-java-generator/pom.xml | 20 --------- core/esmf-aspect-model-validator/pom.xml | 25 ----------- tools/samm-cli/pom.xml | 11 ----- 9 files changed, 10 insertions(+), 181 deletions(-) diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml index e18de3180..eeabf7431 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/release-workflow.yml @@ -471,7 +471,7 @@ jobs: # Milestone release: Maven deploy to Github - name: Publish to Github if: contains( github.event.inputs.release_version, '-M' ) - run: mvn -s ./settings.xml -B clean -pl '!esmf-sdk-test-report,!documentation,!tools/samm-cli' deploy -DskipTests -Pmilestone-build,sign + run: mvn -s ./settings.xml -B clean -pl '!documentation,!tools/samm-cli' deploy -DskipTests -Pmilestone-build,sign env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PGP_KEY_PASSWORD: ${{ secrets.PGP_KEY_PASSWORD }} diff --git a/core/esmf-aspect-meta-model-java/pom.xml b/core/esmf-aspect-meta-model-java/pom.xml index 5e938a839..c553615fd 100644 --- a/core/esmf-aspect-meta-model-java/pom.xml +++ b/core/esmf-aspect-meta-model-java/pom.xml @@ -141,28 +141,6 @@ - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} - - true - true - - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - - org.apache.maven.plugins maven-clean-plugin diff --git a/core/esmf-aspect-model-document-generators/pom.xml b/core/esmf-aspect-model-document-generators/pom.xml index d68c6d24b..33b236953 100644 --- a/core/esmf-aspect-model-document-generators/pom.xml +++ b/core/esmf-aspect-model-document-generators/pom.xml @@ -185,26 +185,6 @@ - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-plugin-version} - - true - true - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - diff --git a/core/esmf-aspect-model-generator/pom.xml b/core/esmf-aspect-model-generator/pom.xml index fa3f07c5f..41c4fdbf6 100644 --- a/core/esmf-aspect-model-generator/pom.xml +++ b/core/esmf-aspect-model-generator/pom.xml @@ -65,26 +65,6 @@ - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} - - true - true - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - diff --git a/core/esmf-aspect-model-jackson/pom.xml b/core/esmf-aspect-model-jackson/pom.xml index 92ebcd6e1..3a7a32871 100644 --- a/core/esmf-aspect-model-jackson/pom.xml +++ b/core/esmf-aspect-model-jackson/pom.xml @@ -83,32 +83,5 @@ esmf-test-resources test - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} - - true - true - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - - - - diff --git a/core/esmf-aspect-model-java-core/pom.xml b/core/esmf-aspect-model-java-core/pom.xml index 2709dd336..3a9ea8dff 100644 --- a/core/esmf-aspect-model-java-core/pom.xml +++ b/core/esmf-aspect-model-java-core/pom.xml @@ -15,39 +15,13 @@ - 4.0.0 - - org.eclipse.esmf - esmf-sdk-parent - DEV-SNAPSHOT - ../../pom.xml - - esmf-aspect-model-java-core - ESMF Aspect Model Java Core - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} - - true - true - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - - - - + 4.0.0 + + org.eclipse.esmf + esmf-sdk-parent + DEV-SNAPSHOT + ../../pom.xml + + esmf-aspect-model-java-core + ESMF Aspect Model Java Core diff --git a/core/esmf-aspect-model-java-generator/pom.xml b/core/esmf-aspect-model-java-generator/pom.xml index 3bd44f6a4..f7b2530e1 100644 --- a/core/esmf-aspect-model-java-generator/pom.xml +++ b/core/esmf-aspect-model-java-generator/pom.xml @@ -154,26 +154,6 @@ - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} - - true - true - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - org.apache.maven.plugins maven-compiler-plugin diff --git a/core/esmf-aspect-model-validator/pom.xml b/core/esmf-aspect-model-validator/pom.xml index d1112dc3f..44ccc8bb3 100644 --- a/core/esmf-aspect-model-validator/pom.xml +++ b/core/esmf-aspect-model-validator/pom.xml @@ -81,29 +81,4 @@ esmf-aspect-meta-model-java - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - ${maven-surefire-report-plugin-version} - - true - true - - - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - - - diff --git a/tools/samm-cli/pom.xml b/tools/samm-cli/pom.xml index d440f733a..8088f83a2 100644 --- a/tools/samm-cli/pom.xml +++ b/tools/samm-cli/pom.xml @@ -192,17 +192,6 @@ - - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin-version} - - true - - - org.apache.maven.plugins From 3738805aefd6b434cb1b63f7375d7eddb54af874 Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Wed, 9 Apr 2025 11:48:43 +0200 Subject: [PATCH 3/7] Enable usage of AspectSerializer for `RawAspectModel`s --- .../org/eclipse/esmf/aspectmodel/RdfUtil.java | 15 +++++++++++++++ .../resolver/AspectModelFileLoader.java | 18 ++++++++++-------- .../aspectmodel/resolver/NamespacePackage.java | 18 ++++++++++++------ .../resolver/modelfile/RawAspectModelFile.java | 1 + .../serializer/AspectSerializer.java | 4 ++++ .../aspectmodel/serializer/RdfComparison.java | 4 ++-- .../java/org/eclipse/esmf/test/TestModel.java | 9 --------- 7 files changed, 44 insertions(+), 25 deletions(-) diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/RdfUtil.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/RdfUtil.java index 3e59a9eec..aa180f2b9 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/RdfUtil.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/RdfUtil.java @@ -23,6 +23,7 @@ import java.util.stream.Stream; import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader; +import org.eclipse.esmf.aspectmodel.serializer.AspectSerializer; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; import org.eclipse.esmf.aspectmodel.urn.ElementType; import org.eclipse.esmf.metamodel.vocabulary.SammNs; @@ -39,6 +40,9 @@ import org.apache.jena.rdf.model.ResIterator; import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.Statement; +import org.apache.jena.riot.RDFFormat; +import org.apache.jena.riot.RDFLanguages; +import org.apache.jena.riot.RDFWriter; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.XSD; @@ -147,6 +151,17 @@ public static Model createModel( final String ttlRepresentation ) { return TurtleLoader.loadTurtle( ttlRepresentation ).get(); } + /** + * Turn a an RDF model to its String representation. Note that this method should only be used where {@link AspectSerializer} can + * not be used since it does not honor Aspect Model formatting rules. + * + * @param model the input model + * @return the rendered model + */ + public static String modelToString( final Model model ) { + return RDFWriter.create().format( RDFFormat.TURTLE ).lang( RDFLanguages.TURTLE ).source( model ).asString(); + } + /** * Returns the List of named resources that transitively point to a given node. Transtively here means that the given node * is reachable from the named resource via any number of anonymous nodes inbetween. diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelFileLoader.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelFileLoader.java index 737afc208..c493d5817 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelFileLoader.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelFileLoader.java @@ -34,6 +34,7 @@ import java.util.Optional; import org.eclipse.esmf.aspectmodel.AspectModelFile; +import org.eclipse.esmf.aspectmodel.RdfUtil; import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader; import org.eclipse.esmf.aspectmodel.resolver.exceptions.ModelResolutionException; import org.eclipse.esmf.aspectmodel.resolver.exceptions.ParserException; @@ -51,8 +52,9 @@ public class AspectModelFileLoader { public static RawAspectModelFile load( final File file ) { try { - final RawAspectModelFile fromString = load( content( new FileInputStream( file ) ) ); - return new RawAspectModelFile( fromString.sourceModel(), fromString.headerComment(), Optional.of( file.toURI() ) ); + final String stringContent = content( new FileInputStream( file ) ); + final RawAspectModelFile fromString = load( stringContent ); + return new RawAspectModelFile( stringContent, fromString.sourceModel(), fromString.headerComment(), Optional.of( file.toURI() ) ); } catch ( final ModelResolutionException exception ) { if ( exception.getMessage().startsWith( "Encountered invalid encoding" ) ) { throw new ModelResolutionException( "Encountered invalid encoding in input file " + file, exception.getCause() ); @@ -71,7 +73,7 @@ public static RawAspectModelFile load( final String rdfTurtle ) { } final Model model = tryModel.getOrElseThrow( () -> new ModelResolutionException( "Can not load model", tryModel.getCause() ) ); - return new RawAspectModelFile( model, headerComment, Optional.empty() ); + return new RawAspectModelFile( rdfTurtle, model, headerComment, Optional.empty() ); } private static String content( final InputStream inputStream ) { @@ -88,12 +90,11 @@ private static String content( final InputStream inputStream ) { } private static List headerComment( final String content ) { - final List list = content.lines() + return content.lines() .dropWhile( String::isBlank ) .takeWhile( line -> line.startsWith( "#" ) ) .map( line -> line.substring( 1 ).trim() ) .toList(); - return list; } public static RawAspectModelFile load( final InputStream inputStream ) { @@ -101,12 +102,13 @@ public static RawAspectModelFile load( final InputStream inputStream ) { } public static RawAspectModelFile load( final InputStream inputStream, final Optional sourceLocation ) { - final AspectModelFile fromString = load( content( inputStream ) ); - return new RawAspectModelFile( fromString.sourceModel(), fromString.headerComment(), sourceLocation ); + final String stringContent = content( inputStream ); + final RawAspectModelFile fromString = load( stringContent ); + return new RawAspectModelFile( stringContent, fromString.sourceModel(), fromString.headerComment(), sourceLocation ); } public static RawAspectModelFile load( final Model model ) { - return new RawAspectModelFile( model, List.of(), Optional.empty() ); + return new RawAspectModelFile( RdfUtil.modelToString( model ), model, List.of(), Optional.empty() ); } public static RawAspectModelFile load( final byte[] content, final Optional sourceLocation ) { diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java index d7d35842a..1eee8d32f 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/NamespacePackage.java @@ -174,7 +174,7 @@ private List loadZipContent() { if ( entry.getName().startsWith( modelsRoot ) && entry.getName().endsWith( ".ttl" ) ) { final RawAspectModelFile rawFile = AspectModelFileLoader.load( inputStream, Optional.of( constructLocationForFile( entry.getName() ) ) ); - builder.add( migrate( rawFile ) ); + builder.add( rawFile ); } } } catch ( final IOException exception ) { @@ -184,10 +184,6 @@ private List loadZipContent() { return builder.build(); } - private AspectModelFile migrate( final AspectModelFile file ) { - return MetaModelVersionMigrator.INSTANCE.apply( file ); - } - @Override public Stream listContents() { if ( content == null ) { @@ -217,9 +213,19 @@ public Stream listContentsForNamespace( final AspectModelUrn namespace ) { uri.toString().contains( pathToFilter ) ); } + /** + * Similar to {@link #loadContents()} except files are not automatically migrated to the latest SAMM version. + * + * @return The stream of files + */ + public Stream loadLiteralFiles() { + return files.stream(); + } + @Override public Stream loadContents() { - return files.stream(); + return files.stream() + .map( MetaModelVersionMigrator.INSTANCE ); } @Override diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/RawAspectModelFile.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/RawAspectModelFile.java index d9836639b..659bb8187 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/RawAspectModelFile.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/modelfile/RawAspectModelFile.java @@ -37,6 +37,7 @@ @SuppressWarnings( "OptionalUsedAsFieldOrParameterType" ) @RecordBuilder public record RawAspectModelFile( + String sourceRepresentation, Model sourceModel, List headerComment, Optional sourceLocation ) diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/serializer/AspectSerializer.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/serializer/AspectSerializer.java index 4942040f8..c8d85b541 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/serializer/AspectSerializer.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/serializer/AspectSerializer.java @@ -32,6 +32,7 @@ import org.eclipse.esmf.aspectmodel.AspectModelFile; import org.eclipse.esmf.aspectmodel.RdfUtil; import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader; +import org.eclipse.esmf.aspectmodel.resolver.modelfile.RawAspectModelFile; import org.eclipse.esmf.aspectmodel.resolver.modelfile.RawAspectModelFileBuilder; import org.eclipse.esmf.metamodel.Aspect; import org.eclipse.esmf.metamodel.AspectModel; @@ -147,6 +148,9 @@ public String aspectToString( final Aspect aspect ) { * @return the String representation in RDF/Turtle */ public String aspectModelFileToString( final AspectModelFile aspectModelFile ) { + if ( aspectModelFile instanceof final RawAspectModelFile rawAspectModelFile ) { + return rawAspectModelFile.sourceRepresentation(); + } final StringWriter stringWriter = new StringWriter(); try ( final PrintWriter printWriter = new PrintWriter( stringWriter ) ) { final PrettyPrinter prettyPrinter = new PrettyPrinter( aspectModelFile, printWriter ); diff --git a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/serializer/RdfComparison.java b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/serializer/RdfComparison.java index 7e6586581..c982baeb6 100644 --- a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/serializer/RdfComparison.java +++ b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/serializer/RdfComparison.java @@ -17,7 +17,7 @@ import java.util.List; import java.util.stream.Collectors; -import org.eclipse.esmf.test.TestModel; +import org.eclipse.esmf.aspectmodel.RdfUtil; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.RDFList; @@ -63,7 +63,7 @@ private static String hashAnonymousResource( final Resource resource ) { } static String modelToString( final Model model ) { - return Arrays.stream( TestModel.modelToString( model ) + return Arrays.stream( RdfUtil.modelToString( model ) .replaceAll( ";", "" ) .replaceAll( "\\.", "" ) .replaceAll( " +", "" ) diff --git a/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestModel.java b/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestModel.java index ab1fc4c97..738243dd8 100644 --- a/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestModel.java +++ b/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestModel.java @@ -15,11 +15,6 @@ import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.riot.RDFFormat; -import org.apache.jena.riot.RDFLanguages; -import org.apache.jena.riot.RDFWriter; - @SuppressWarnings( "squid:S1214" ) // Can not be avoided because enums can't inherit from an abstract class public interface TestModel { String TEST_NAMESPACE = "urn:samm:org.eclipse.esmf.test:1.0.0#"; @@ -29,8 +24,4 @@ public interface TestModel { default AspectModelUrn getUrn() { return AspectModelUrn.fromUrn( TEST_NAMESPACE + getName() ); } - - static String modelToString( final Model model ) { - return RDFWriter.create().format( RDFFormat.TURTLE ).lang( RDFLanguages.TURTLE ).source( model ).asString(); - } } From fb4b637a952124632ca2ec67fc5f44ddd00598a1 Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Wed, 9 Apr 2025 13:21:53 +0200 Subject: [PATCH 4/7] Document usage of esmf-parent as a Maven BOM --- .../modules/ROOT/partials/esmf-bom.adoc | 14 ++++++++++++++ .../examples/LoadAspectModelObjects.java | 2 +- .../tooling-guide/pages/java-aspect-tooling.adoc | 11 +++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 documentation/developer-guide/modules/ROOT/partials/esmf-bom.adoc diff --git a/documentation/developer-guide/modules/ROOT/partials/esmf-bom.adoc b/documentation/developer-guide/modules/ROOT/partials/esmf-bom.adoc new file mode 100644 index 000000000..d197feb0e --- /dev/null +++ b/documentation/developer-guide/modules/ROOT/partials/esmf-bom.adoc @@ -0,0 +1,14 @@ +[source,maven,subs=attributes+] +---- + + + + org.eclipse.esmf + esmf-sdk-parent + {esmf-sdk-version} + pom + import + + + +---- diff --git a/documentation/developer-guide/modules/tooling-guide/examples/LoadAspectModelObjects.java b/documentation/developer-guide/modules/tooling-guide/examples/LoadAspectModelObjects.java index 0eec3206e..2ac13b7ff 100644 --- a/documentation/developer-guide/modules/tooling-guide/examples/LoadAspectModelObjects.java +++ b/documentation/developer-guide/modules/tooling-guide/examples/LoadAspectModelObjects.java @@ -28,7 +28,7 @@ public void loadModel() { // tag::loadModel[] final AspectModel aspectModel = new AspectModelLoader().load( // a File, InputStream or AspectModelUrn - // end::generate[] + // end::loadModel[] new File( "aspect-models/org.eclipse.esmf.examples.movement/1.0.0/Movement.ttl" ) // tag::loadModel[] ); diff --git a/documentation/developer-guide/modules/tooling-guide/pages/java-aspect-tooling.adoc b/documentation/developer-guide/modules/tooling-guide/pages/java-aspect-tooling.adoc index ebb8dff2e..9855bd52c 100644 --- a/documentation/developer-guide/modules/tooling-guide/pages/java-aspect-tooling.adoc +++ b/documentation/developer-guide/modules/tooling-guide/pages/java-aspect-tooling.adoc @@ -8,10 +8,17 @@ In this section, the Java APIs for working with Aspect Models are described. All of the components described in the following subsections can either be included in your project using a dedicated dependency (as described in the -respective subsection), _or_ you can use the `aspect-model-starter` artifact that aggregates all necessary dependencies: +respective subsection), _or_ you can use the `esmf-aspect-model-starter` artifact that aggregates all necessary dependencies: include::esmf-developer-guide:ROOT:partial$esmf-aspect-model-starter-artifact.adoc[] +Alternatively, you can use the `esmf-sdk-parent` artifact as a +https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Bill_of_Materials_.28BOM.29_POMs[Maven +BOM] (Bill of Materials) to enable declaring dependencies to specific modules without an explicit +version. Add the following section to the Maven pom.xml in your project: + +include::esmf-developer-guide:ROOT:partial$esmf-bom.adoc[] + [[versioning]] == Getting the right version @@ -49,7 +56,7 @@ When using esmf-sdk with a GraalVM JDK and you target `native-image` compilation dependency to the `esmf-native-support` module. This will add the necessary configuration for esmf-sdk resources, reflection and initialization that is required by the compiler: -include::esmf-developer-guide:ROOT:partial$esmf-aspect-model-starter-artifact.adoc[] +include::esmf-developer-guide:ROOT:partial$esmf-native-support-artifact.adoc[] ===== [[parsing-aspect-model-urns]] From 8d0e222c56665ba29f3a76db96a0e00b8746f22a Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Wed, 9 Apr 2025 16:23:08 +0200 Subject: [PATCH 5/7] Add convenience constructor methods to AspectModelUrn --- .../esmf/aspectmodel/urn/AspectModelUrn.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java b/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java index d3403ea32..2910fab44 100644 --- a/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java +++ b/core/esmf-aspect-model-urn/src/main/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrn.java @@ -185,6 +185,56 @@ public static Try from( final URI uri ) { } } + /** + * Construct an AspectModelUrn from a namespace main part and a version number + * + * @param namespaceMainPart the namespace main part (e.g., "com.example") + * @param versionNumber the version number (e.g., "1.2.3") + * @return the Aspect Model URN or a {@link UrnSyntaxException} + */ + public static Try from( final String namespaceMainPart, final String versionNumber ) { + return from( "%s:%s:%s%s".formatted( VALID_PROTOCOL, VALID_NAMESPACE_IDENTIFIER, namespaceMainPart, versionNumber ) ); + } + + /** + * Construct an AspectModelUrn from a namespace main part, a version number and a model element name + * + * @param namespaceMainPart the namespace main part (e.g., "com.example") + * @param versionNumber the version number (e.g., "1.2.3") + * @param modelElementName the model element name (e.g., "MyAspect") + * @return the Aspect Model URN or a {@link UrnSyntaxException} + */ + public static Try from( final String namespaceMainPart, final String versionNumber, final String modelElementName ) { + return from( + "%s:%s:%s%s#%s".formatted( VALID_PROTOCOL, VALID_NAMESPACE_IDENTIFIER, namespaceMainPart, versionNumber, modelElementName ) ); + } + + /** + * Construct an AspectModelUrn from a namespace main part and a version number + * + * @param namespaceMainPart the namespace main part (e.g., "com.example") + * @param versionNumber the version number (e.g., "1.2.3") + * @return the Aspect Model URN + * @throws UrnSyntaxException if {@code urn} is not valid + */ + public static AspectModelUrn fromParts( final String namespaceMainPart, final String versionNumber ) { + return fromUrn( "%s:%s:%s%s".formatted( VALID_PROTOCOL, VALID_NAMESPACE_IDENTIFIER, namespaceMainPart, versionNumber ) ); + } + + /** + * Construct an AspectModelUrn from a namespace main part, a version number and a model element name + * + * @param namespaceMainPart the namespace main part (e.g., "com.example") + * @param versionNumber the version number (e.g., "1.2.3") + * @param modelElementName the model element name (e.g., "MyAspect") + * @return the Aspect Model URN + * @throws UrnSyntaxException if {@code urn} is not valid + */ + public static AspectModelUrn fromParts( final String namespaceMainPart, final String versionNumber, final String modelElementName ) { + return fromUrn( + "%s:%s:%s%s#%s".formatted( VALID_PROTOCOL, VALID_NAMESPACE_IDENTIFIER, namespaceMainPart, versionNumber, modelElementName ) ); + } + /** * Retrieves the element type from the Aspect Model URN. * From bb90b52844884dd2bf3b29d136e6476b8c52bdc1 Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Wed, 9 Apr 2025 16:23:30 +0200 Subject: [PATCH 6/7] Skip unnecessary meta model version migration --- .../MetaModelVersionMigrator.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java index cae7c59be..1e6228e6b 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java @@ -19,12 +19,14 @@ import java.util.stream.Collectors; import org.eclipse.esmf.aspectmodel.AspectModelFile; +import org.eclipse.esmf.aspectmodel.RdfUtil; import org.eclipse.esmf.aspectmodel.VersionNumber; import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidVersionException; import org.eclipse.esmf.aspectmodel.resolver.exceptions.ModelResolutionException; import org.eclipse.esmf.aspectmodel.resolver.modelfile.RawAspectModelFile; import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; import org.eclipse.esmf.aspectmodel.urn.ElementType; +import org.eclipse.esmf.metamodel.vocabulary.SammNs; import org.eclipse.esmf.samm.KnownVersion; import com.google.common.collect.ImmutableList; @@ -40,6 +42,7 @@ public class MetaModelVersionMigrator implements UnaryOperator { public static final MetaModelVersionMigrator INSTANCE = new MetaModelVersionMigrator(); private static final Logger LOG = LoggerFactory.getLogger( MetaModelVersionMigrator.class ); + private static final VersionNumber LATEST_SAMM = VersionNumber.parse( KnownVersion.getLatest().toVersionString() ); private MetaModelVersionMigrator() { } @@ -74,6 +77,15 @@ private Model convertBammToSamm( final Model model ) { * @return the meta model versions */ private VersionNumber getUsedMetaModelVersion( final Model model ) { + final String sammUri = model.getNsPrefixURI( SammNs.SAMM.getShortForm() ); + if ( SammNs.SAMM.getNamespace().equals( sammUri ) ) { + return LATEST_SAMM; + } + if ( sammUri != null ) { + return VersionNumber.parse( sammUri.substring( sammUri.lastIndexOf( ":" ) + 1, sammUri.length() - 1 ) ); + } + + // The file does not contain a "@prefix samm:" declaration: Determine the version from the triple URIs final String sammUrnStart = String.format( "%s:%s", AspectModelUrn.VALID_PROTOCOL, AspectModelUrn.VALID_NAMESPACE_IDENTIFIER ); final Set result = model.listObjects() .toList() @@ -110,22 +122,18 @@ private VersionNumber getUsedMetaModelVersion( final Model model ) { public AspectModelFile apply( final AspectModelFile modelFile ) { // Before any semantic migration, perform the mechanical translation of legacy BAMM models final Model input = convertBammToSamm( modelFile.sourceModel() ); - - final VersionNumber latestKnownVersion = VersionNumber.parse( KnownVersion.getLatest().toVersionString() ); final VersionNumber sourceVersion = getUsedMetaModelVersion( input ); - Model migrationModel = modelFile.sourceModel(); - if ( sourceVersion.greaterThan( latestKnownVersion ) ) { - // looks like unreachable - throw new InvalidVersionException( - String.format( "Model version %s can not be updated to version %s", sourceVersion, latestKnownVersion ) ); + if ( sourceVersion.equals( LATEST_SAMM ) ) { + return modelFile; } - - if ( !sourceVersion.equals( latestKnownVersion ) ) { - migrationModel = migrate( migrators, sourceVersion, latestKnownVersion, migrationModel ); + if ( sourceVersion.greaterThan( LATEST_SAMM ) ) { + throw new InvalidVersionException( "Aspect Model version %s in source model is not supported".formatted( sourceVersion ) ); } - return new RawAspectModelFile( migrationModel, modelFile.headerComment(), modelFile.sourceLocation() ); + final Model migratedModel = migrate( migrators, sourceVersion, LATEST_SAMM, modelFile.sourceModel() ); + return new RawAspectModelFile( RdfUtil.modelToString( migratedModel ), migratedModel, modelFile.headerComment(), + modelFile.sourceLocation() ); } private Model migrate( final List migrators, final VersionNumber sourceVersion, final VersionNumber targetVersion, From 3be389d75bdb37c908228b02ed13ff702ad3e2dd Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Thu, 10 Apr 2025 13:40:15 +0200 Subject: [PATCH 7/7] Fix failing test --- .../aspectmodel/versionupdate/MetaModelVersionMigrator.java | 2 +- .../validation/services/AspectModelValidatorTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java index 1e6228e6b..e78433f83 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/versionupdate/MetaModelVersionMigrator.java @@ -128,7 +128,7 @@ public AspectModelFile apply( final AspectModelFile modelFile ) { return modelFile; } if ( sourceVersion.greaterThan( LATEST_SAMM ) ) { - throw new InvalidVersionException( "Aspect Model version %s in source model is not supported".formatted( sourceVersion ) ); + throw new InvalidVersionException( "Aspect Meta Model version %s in source model is not supported".formatted( sourceVersion ) ); } final Model migratedModel = migrate( migrators, sourceVersion, LATEST_SAMM, modelFile.sourceModel() ); diff --git a/core/esmf-aspect-model-validator/src/test/java/org/eclipse/esmf/aspectmodel/validation/services/AspectModelValidatorTest.java b/core/esmf-aspect-model-validator/src/test/java/org/eclipse/esmf/aspectmodel/validation/services/AspectModelValidatorTest.java index a0ff8509d..8e0efebce 100644 --- a/core/esmf-aspect-model-validator/src/test/java/org/eclipse/esmf/aspectmodel/validation/services/AspectModelValidatorTest.java +++ b/core/esmf-aspect-model-validator/src/test/java/org/eclipse/esmf/aspectmodel/validation/services/AspectModelValidatorTest.java @@ -149,7 +149,7 @@ void testAspectWithInvalidMetaModelVersion() { final List violations = service.validateModel( invalidTurtleSyntax ); assertThat( violations ).hasSize( 1 ); final ProcessingViolation violation = (ProcessingViolation) violations.get( 0 ); - assertThat( violation.message() ).contains( "can not be updated to version" ); + assertThat( violation.message() ).contains( "is not supported" ); } @Test