diff --git a/apache-rat-core/src/main/java/org/apache/rat/analysis/TikaProcessor.java b/apache-rat-core/src/main/java/org/apache/rat/analysis/TikaProcessor.java index 8534eac2c..46f7e96c0 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/analysis/TikaProcessor.java +++ b/apache-rat-core/src/main/java/org/apache/rat/analysis/TikaProcessor.java @@ -106,6 +106,7 @@ public final class TikaProcessor { DOCUMENT_TYPE_MAP.put("application/x-xliff+zip", Document.Type.ARCHIVE); // org.apache.tika.parser.xml.DcXMLParser DOCUMENT_TYPE_MAP.put("application/xml", Document.Type.STANDARD); + DOCUMENT_TYPE_MAP.put("application/rls-services+xml", Document.Type.STANDARD); DOCUMENT_TYPE_MAP.put("application/xslt+xml", Document.Type.STANDARD); DOCUMENT_TYPE_MAP.put("image/svg+xml", Document.Type.STANDARD); // org.apache.tika.parser.xml.FictionBookParser diff --git a/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java b/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java index f4ef0792c..fee6ba4f6 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java +++ b/apache-rat-core/src/test/java/org/apache/rat/analysis/AnalyserFactoryTest.java @@ -25,6 +25,7 @@ import java.io.StringWriter; import java.net.URISyntaxException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -44,8 +45,10 @@ import org.assertj.core.util.Files; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; /** @@ -106,6 +109,55 @@ public void binaryTypeAnalyser() throws Exception { assertThat(document.getMetaData().getMediaType().toString()).isEqualTo("image/png"); } + @ParameterizedTest + @CsvSource({ + "Apache-2.0, AL2.0, true", + "GPL-3.0-only, GPL3, false", + "LicenseRef-Proprietary, ?????, false", + "'', ?????, false" + }) + void rustSourceLicenses(String spdx, String licenseId, boolean approved, @TempDir Path directory) throws Exception { + Path source = directory.resolve("main.rs"); + String header = spdx.isEmpty() ? "" : "// SPDX-License-Identifier: " + spdx + "\n"; + java.nio.file.Files.writeString(source, header + "fn main() {}\n"); + ReportConfiguration config = new ReportConfiguration(); + config.setFrom(Defaults.builder().build()); + Document document = new FileDocument(source.toFile(), DocumentNameMatcher.MATCHES_ALL); + + AnalyserFactory.createConfiguredAnalyser(config).analyse(document); + + assertThat(document.getMetaData().getDocumentType()).isEqualTo(Document.Type.STANDARD); + assertThat(document.getMetaData().licenses()).singleElement().satisfies(license -> { + assertThat(license.getId()).isEqualTo(licenseId); + assertThat(document.getMetaData().isApproved(license)).isEqualTo(approved); + }); + } + + @Test + void rlsServicesXmlIsScanned(@TempDir Path directory) throws Exception { + Path source = directory.resolve("services.rs"); + java.nio.file.Files.writeString(source, "\n" + + "\n"); + Document document = new FileDocument(source.toFile(), DocumentNameMatcher.MATCHES_ALL); + + analyser.analyse(document); + + assertThat(document.getMetaData().getDocumentType()).isEqualTo(Document.Type.STANDARD); + assertThat(document.getMetaData().licenses()).containsExactly(UnknownLicense.INSTANCE); + } + + @Test + void binaryWithRustExtensionIsNotScanned(@TempDir Path directory) throws Exception { + Path source = directory.resolve("image.rs"); + java.nio.file.Files.copy(Resources.getResourceFile("/binaries/Image-png.not").toPath(), source); + Document document = new FileDocument(source.toFile(), DocumentNameMatcher.MATCHES_ALL); + + analyser.analyse(document); + + assertThat(document.getMetaData().getDocumentType()).isEqualTo(Document.Type.BINARY); + assertThat(document.getMetaData().licenses()).isEmpty(); + } + @Test public void archiveTypeAnalyserTest() throws Exception { final Document document = new FileDocument(basedir, diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bf4c02095..c904f852d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -68,6 +68,9 @@ in order to be properly linked in site reports. --> + + Add ability to check license headers in Rust files properly. + Generate cycloneDX BOMs upon each build.