Skip to content

Commit 454a4ae

Browse files
authored
Merge pull request #334 from bci-oss/bugfix/301-wrong-number-of-generated-artifacts
Fix calculation of languages reachable via an aspect.
2 parents 7e16ed4 + 4dd9161 commit 454a4ae

File tree

3 files changed

+91
-12
lines changed

3 files changed

+91
-12
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/metamodel/visitor/LanguageCollectorModelVisitor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@
1919
import java.util.stream.Collectors;
2020
import java.util.stream.Stream;
2121

22-
import com.google.common.collect.Sets;
23-
22+
import org.eclipse.esmf.characteristic.Collection;
23+
import org.eclipse.esmf.characteristic.Trait;
2424
import org.eclipse.esmf.metamodel.Aspect;
25-
import org.eclipse.esmf.metamodel.ModelElement;
2625
import org.eclipse.esmf.metamodel.Entity;
26+
import org.eclipse.esmf.metamodel.ModelElement;
2727
import org.eclipse.esmf.metamodel.NamedElement;
2828
import org.eclipse.esmf.metamodel.Operation;
2929
import org.eclipse.esmf.metamodel.Property;
3030
import org.eclipse.esmf.metamodel.QuantityKind;
31-
import org.eclipse.esmf.characteristic.Trait;
3231
import org.eclipse.esmf.metamodel.Unit;
3332
import org.eclipse.esmf.metamodel.datatypes.LangString;
3433

34+
import com.google.common.collect.Sets;
35+
3536
/**
3637
* Aspect Model Visitor that retrieves all used Locales in an Aspect Model
3738
*/
@@ -101,4 +102,10 @@ public Set<Locale> visitUnit( final Unit unit, final Set<Locale> context ) {
101102
public Set<Locale> visitQuantityKind( final QuantityKind quantityKind, final Set<Locale> context ) {
102103
return Collections.emptySet();
103104
}
105+
106+
@Override
107+
public Set<Locale> visitCollection( final Collection collection, final Set<Locale> context ) {
108+
return collection.getElementCharacteristic().isPresent() ? collection.getElementCharacteristic().get().accept( this, Collections.emptySet() ) :
109+
collection.getDataType().get().accept( this, Collections.emptySet() );
110+
}
104111
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.eclipse.esmf.metamodel.visitor;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.io.ByteArrayInputStream;
6+
import java.io.InputStream;
7+
import java.nio.charset.StandardCharsets;
8+
import java.util.HashSet;
9+
import java.util.Locale;
10+
import java.util.Set;
11+
12+
import org.apache.jena.rdf.model.Model;
13+
import org.apache.jena.rdf.model.ModelFactory;
14+
import org.apache.jena.riot.RDFLanguages;
15+
import org.eclipse.esmf.aspectmodel.resolver.services.SammAspectMetaModelResourceResolver;
16+
import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel;
17+
import org.eclipse.esmf.metamodel.Aspect;
18+
import org.eclipse.esmf.metamodel.loader.AspectModelLoader;
19+
import org.eclipse.esmf.samm.KnownVersion;
20+
import org.junit.jupiter.api.Test;
21+
22+
class LanguageCollectorModelVisitorTest {
23+
24+
@Test
25+
void testLanguageCollector() {
26+
final VersionedModel versionedModel = model( """
27+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#> .
28+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.0.0#> .
29+
@prefix : <urn:samm:test:0.0.1#> .
30+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
31+
32+
:Reference a samm:Aspect ;
33+
samm:preferredName "Reference"@en ;
34+
samm:description "Beschreibung."@de ;
35+
samm:properties ( :items ) ;
36+
samm:operations ( ) .
37+
38+
:items a samm:Property ;
39+
samm:preferredName "Items"@es ;
40+
samm:description "Items."@it ;
41+
samm:characteristic [
42+
a samm-c:Set ;
43+
samm:dataType :AEntity
44+
] .
45+
46+
:AEntity a samm:Entity ;
47+
samm:preferredName "A name"@pt ;
48+
samm:preferredName "Ein Name"@de ;
49+
samm:properties ( :AProperty ) .
50+
51+
:AProperty a samm:Property ;
52+
samm:preferredName "Common Property"@en ;
53+
samm:description "Descriptif de l'objet"@fr ;
54+
samm:characteristic :ACharacteristic .
55+
56+
:ACharacteristic a samm-c:Code ;
57+
samm:dataType xsd:string .
58+
""" );
59+
final Aspect aspect = AspectModelLoader.getSingleAspectUnchecked( versionedModel );
60+
final Set<Locale> reachableLocales = new LanguageCollectorModelVisitor().visitAspect( aspect, new HashSet<>() );
61+
assertThat( reachableLocales ).containsExactlyInAnyOrder( Locale.ENGLISH, Locale.GERMAN, Locale.ITALIAN, Locale.FRENCH, Locale.forLanguageTag( "es" ),
62+
Locale.forLanguageTag( "pt" ) );
63+
}
64+
65+
private VersionedModel model( final String ttlRepresentation ) {
66+
final Model model = ModelFactory.createDefaultModel();
67+
final InputStream in = new ByteArrayInputStream( ttlRepresentation.getBytes( StandardCharsets.UTF_8 ) );
68+
model.read( in, "", RDFLanguages.strLangTurtle );
69+
return new SammAspectMetaModelResourceResolver().mergeMetaModelIntoRawModel( model, KnownVersion.SAMM_2_0_0 )
70+
.get();
71+
}
72+
}

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/docu/AspectModelDocumentationGeneratorTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
package org.eclipse.esmf.aspectmodel.generator.docu;
1515

16-
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.assertj.core.api.Assertions.assertThatCode;
16+
import static org.assertj.core.api.Assertions.*;
1817
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1918

2019
import java.io.BufferedWriter;
@@ -27,22 +26,23 @@
2726
import java.util.Collections;
2827

2928
import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel;
30-
import org.junit.jupiter.params.ParameterizedTest;
31-
import org.junit.jupiter.params.provider.EnumSource;
32-
import org.junit.jupiter.params.provider.MethodSource;
33-
34-
import org.eclipse.esmf.samm.KnownVersion;
3529
import org.eclipse.esmf.metamodel.Aspect;
3630
import org.eclipse.esmf.metamodel.AspectContext;
3731
import org.eclipse.esmf.metamodel.loader.AspectModelLoader;
32+
import org.eclipse.esmf.samm.KnownVersion;
3833
import org.eclipse.esmf.test.MetaModelVersions;
3934
import org.eclipse.esmf.test.TestAspect;
4035
import org.eclipse.esmf.test.TestResources;
36+
import org.junit.jupiter.params.ParameterizedTest;
37+
import org.junit.jupiter.params.provider.EnumSource;
38+
import org.junit.jupiter.params.provider.MethodSource;
4139

4240
public class AspectModelDocumentationGeneratorTest extends MetaModelVersions {
4341

4442
@ParameterizedTest
45-
@EnumSource( value = TestAspect.class )
43+
@EnumSource( value = TestAspect.class, mode = EnumSource.Mode.EXCLUDE,
44+
names = { "MODEL_WITH_CYCLES" // contains cycles, the calculation of used languages would run into an infinite loop
45+
} )
4646
public void testGeneration( final TestAspect testAspect ) {
4747
assertThatCode( () -> {
4848
final String html = generateHtmlDocumentation( testAspect, KnownVersion.getLatest() );

0 commit comments

Comments
 (0)