Skip to content

Commit b0aa0c5

Browse files
authored
Merge pull request #719 from bci-oss/701-fix-header-comment-parsing
Fix header comment parsing
2 parents 7122b92 + 24834f5 commit b0aa0c5

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelFileLoader.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
package org.eclipse.esmf.aspectmodel.resolver;
1515

16-
import static org.apache.commons.lang3.StringUtils.isBlank;
17-
1816
import java.io.ByteArrayInputStream;
1917
import java.io.File;
2018
import java.io.FileInputStream;
@@ -92,12 +90,10 @@ private static String content( final InputStream inputStream ) {
9290
private static List<String> headerComment( final String content ) {
9391
final List<String> list = content.lines()
9492
.dropWhile( String::isBlank )
95-
.takeWhile( line -> line.startsWith( "#" ) || isBlank( line ) )
96-
.map( line -> line.startsWith( "#" ) ? line.substring( 1 ).trim() : line )
93+
.takeWhile( line -> line.startsWith( "#" ) )
94+
.map( line -> line.substring( 1 ).trim() )
9795
.toList();
98-
return !list.isEmpty() && list.get( list.size() - 1 ).isEmpty()
99-
? list.subList( 0, list.size() - 1 )
100-
: list;
96+
return list;
10197
}
10298

10399
public static RawAspectModelFile load( final InputStream inputStream ) {

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelResolverTest.java

+38
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,44 @@ void testLoadDataModelExpectSuccess() throws URISyntaxException {
6262
} ).doesNotThrowAnyException();
6363
}
6464

65+
@Test
66+
void testLoadModelWithNoEmptyLineAfterHeaderCommentBlock() {
67+
assertThat( AspectModelFileLoader.load( """
68+
#
69+
# Test copyright
70+
#
71+
@prefix : <urn:samm:com.xyz:0.0.1#> .
72+
""" ) )
73+
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
74+
assertThat( AspectModelFileLoader.load( """
75+
#
76+
# Test copyright
77+
#
78+
79+
@prefix : <urn:samm:com.xyz:0.0.1#> .
80+
""" ) )
81+
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
82+
assertThat( AspectModelFileLoader.load( """
83+
#
84+
# Test copyright
85+
#
86+
87+
# Another comment
88+
@prefix : <urn:samm:com.xyz:0.0.1#> .
89+
""" ) )
90+
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
91+
assertThat( AspectModelFileLoader.load( """
92+
#
93+
# Test copyright
94+
#
95+
96+
# Another comment
97+
98+
@prefix : <urn:samm:com.xyz:0.0.1#> .
99+
""" ) )
100+
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
101+
}
102+
65103
@Test
66104
void testLoadLegacyBammModelWithoutPrefixesExpectSuccess() throws URISyntaxException {
67105
final File aspectModelsRootDirectory = new File(

0 commit comments

Comments
 (0)