Skip to content
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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, "<?xml version=\"1.0\"?>\n"
+ "<rls-services xmlns=\"urn:ietf:params:xml:ns:rls-services\"/>\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,
Expand Down
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ in order to be properly linked in site reports.
</release>
-->
<release version="1.0.0-SNAPSHOT" date="xxxx-yy-zz" description="Current SNAPSHOT - release to be done">
<action issue="RAT-581" type="add" dev="pottlinger" due-to="Zili Chen">
Add ability to check license headers in Rust files properly.
</action>
<action issue="RAT-579" type="add" dev="pottlinger">
Generate cycloneDX BOMs upon each build.
</action>
Expand Down
Loading