Skip to content

Commit f64fd9e

Browse files
authored
Merge pull request #688 from bci-oss/687-add-api-for-spdx-identifier
Provide API to get SPDX license identifier for AspectModelFile
2 parents ecbe2de + d28af35 commit f64fd9e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelFile.java

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ default List<String> headerComment() {
4646
return List.of();
4747
}
4848

49+
/**
50+
* Returns the SPDX license identifier for this file, if one exists
51+
*
52+
* @return the SPDX identifier
53+
*/
54+
default Optional<String> spdxLicenseIdentifier() {
55+
return headerComment().stream()
56+
.filter( line -> line.startsWith( "SPDX-License-Identifier:" ) )
57+
.map( line -> line.split( ":" )[1].trim() )
58+
.findFirst();
59+
}
60+
4961
/**
5062
* The URI that denominates the source location, if present. It can be a file:// or https:// URL, but it
5163
* could for example also be an Aspect Model URN, if it refers to a file that is part of the SAMM specification.

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

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void testLoadDataModelExpectSuccess() throws URISyntaxException {
5353
assertThat( result.files().get( 0 ).headerComment() ).isNotNull();
5454
assertThat( result.files().get( 0 ).headerComment().get( 0 ) ).contains(
5555
"Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH" );
56+
assertThat( result.files().get( 0 ).spdxLicenseIdentifier() ).contains( "MPL-2.0" );
5657
} ).doesNotThrowAnyException();
5758
}
5859

0 commit comments

Comments
 (0)