From e47c04d13a4dbf7c8d9be320d48f2590f3061f8a Mon Sep 17 00:00:00 2001 From: "Textor Andreas (BCI/ESW17)" Date: Tue, 10 Dec 2024 11:08:54 +0100 Subject: [PATCH] Provide API to get SPDX license identifier for AspectModelFile --- .../eclipse/esmf/aspectmodel/AspectModelFile.java | 12 ++++++++++++ .../resolver/AspectModelResolverTest.java | 1 + 2 files changed, 13 insertions(+) diff --git a/core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelFile.java b/core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelFile.java index fd5864962..5d7a696f5 100644 --- a/core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelFile.java +++ b/core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelFile.java @@ -46,6 +46,18 @@ default List headerComment() { return List.of(); } + /** + * Returns the SPDX license identifier for this file, if one exists + * + * @return the SPDX identifier + */ + default Optional 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. diff --git a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelResolverTest.java b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelResolverTest.java index f63318752..ca41be38a 100644 --- a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelResolverTest.java +++ b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelResolverTest.java @@ -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(); }