Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix header comment parsing #719

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

package org.eclipse.esmf.aspectmodel.resolver;

import static org.apache.commons.lang3.StringUtils.isBlank;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -92,12 +90,10 @@ private static String content( final InputStream inputStream ) {
private static List<String> headerComment( final String content ) {
final List<String> list = content.lines()
.dropWhile( String::isBlank )
.takeWhile( line -> line.startsWith( "#" ) || isBlank( line ) )
.map( line -> line.startsWith( "#" ) ? line.substring( 1 ).trim() : line )
.takeWhile( line -> line.startsWith( "#" ) )
.map( line -> line.substring( 1 ).trim() )
.toList();
return !list.isEmpty() && list.get( list.size() - 1 ).isEmpty()
? list.subList( 0, list.size() - 1 )
: list;
return list;
}

public static RawAspectModelFile load( final InputStream inputStream ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,44 @@ void testLoadDataModelExpectSuccess() throws URISyntaxException {
} ).doesNotThrowAnyException();
}

@Test
void testLoadModelWithNoEmptyLineAfterHeaderCommentBlock() {
assertThat( AspectModelFileLoader.load( """
#
# Test copyright
#
@prefix : <urn:samm:com.xyz:0.0.1#> .
""" ) )
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
assertThat( AspectModelFileLoader.load( """
#
# Test copyright
#

@prefix : <urn:samm:com.xyz:0.0.1#> .
""" ) )
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
assertThat( AspectModelFileLoader.load( """
#
# Test copyright
#

# Another comment
@prefix : <urn:samm:com.xyz:0.0.1#> .
""" ) )
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
assertThat( AspectModelFileLoader.load( """
#
# Test copyright
#

# Another comment

@prefix : <urn:samm:com.xyz:0.0.1#> .
""" ) )
.headerComment().hasSize( 3 ).matches( list -> list.get( 1 ).contains( "Test copyright" ) );
}

@Test
void testLoadLegacyBammModelWithoutPrefixesExpectSuccess() throws URISyntaxException {
final File aspectModelsRootDirectory = new File(
Expand Down
Loading