Skip to content

Commit

Permalink
Provide API to get SPDX license identifier for AspectModelFile
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor committed Dec 10, 2024
1 parent 7d94def commit e47c04d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ default List<String> headerComment() {
return List.of();
}

/**
* Returns the SPDX license identifier for this file, if one exists
*
* @return the SPDX identifier
*/
default Optional<String> spdxLicenseIdentifier() {
return headerComment().stream()
.filter( line -> line.startsWith( "SPDX-License-Identifier:" ) )
.map( line -> line.split( ":" )[1].trim() )
.findFirst();
}

/**
* The URI that denominates the source location, if present. It can be a file:// or https:// URL, but it
* could for example also be an Aspect Model URN, if it refers to a file that is part of the SAMM specification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void testLoadDataModelExpectSuccess() throws URISyntaxException {
assertThat( result.files().get( 0 ).headerComment() ).isNotNull();
assertThat( result.files().get( 0 ).headerComment().get( 0 ) ).contains(
"Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH" );
assertThat( result.files().get( 0 ).spdxLicenseIdentifier() ).contains( "MPL-2.0" );
} ).doesNotThrowAnyException();
}

Expand Down

0 comments on commit e47c04d

Please sign in to comment.