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
8 changes: 5 additions & 3 deletions src/main/java/com/scanoss/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,19 @@ public List<String> processFolder(@NonNull String folder, FileProcessor processo
List<Future<String>> futures = new ArrayList<>();
try {
Files.walkFileTree(Paths.get(folder), new SimpleFileVisitor<>() {
@NonNull
@Override
public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) {
public FileVisitResult preVisitDirectory(Path file, @NonNull BasicFileAttributes attrs) {
if(folderFilter.test(file)) {
log.debug("Processing file: {}", file.getFileName().toString());
return FileVisitResult.SKIP_SUBTREE; // Skip the rest of this directory tree
}
return FileVisitResult.CONTINUE;
}

@NonNull
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
public FileVisitResult visitFile(Path file, @NonNull BasicFileAttributes attrs) {
if (attrs.isRegularFile() && !fileFilter.test(file) && attrs.size() > 0) {
String filename = file.toString();
Future<String> future = executorService.submit(() -> processor.process(filename, stripDirectory(folder, filename)));
Expand Down Expand Up @@ -292,7 +294,7 @@ public List<String> processFileList(@NonNull String root, @NonNull List<String>
if (skipDir) {
continue; // skip this file as the folder is not allowed
}
String nameLower = path.getFileName().toString().toLowerCase();

if (!this.fileFilter.test(path)) {
Path fullPath = Path.of(root, file);
File f = fullPath.toFile();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/scanoss/ScannerPostProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ private void buildPurl2ComponentDetailsMap(@NonNull List<ScanFileResult> scanFil
*
* @param results The list of scan results to process and modify
* @param rules The list of replacement rules to apply
* @return The modified input list of scan results with updated PURLs
*/
private void applyReplaceRules(@NonNull List<ScanFileResult> results, @NonNull List<ReplaceRule> rules) {
log.debug("Starting replace rules application for {} results with {} rules", results.size(), rules.size());
Expand Down Expand Up @@ -268,7 +267,7 @@ private ScanFileDetails createUpdatedResultDetails(ScanFileDetails existingCompo

/**
* Marks all components in the list as non-matching by replacing each component
* with a new instance that has MatchType.NONE while preserving the serverDetails
* with a new instance that has MatchType. NONE while preserving the serverDetails
* Modifies the input list in place using List.replaceAll().
*
* @param components List of scan file details to be marked as non-matching
Expand Down Expand Up @@ -451,7 +450,7 @@ private boolean isPurlMatch(String rulePurl, String[] resultPurls) {
* 1. The result has a valid file path identifier
* 2. The result contains a non-empty list of scan details
* 3. The primary scan detail entry (first in the list) exists
*
* <p>
* This structural validation is a prerequisite for any further processing of scan results,
* such as match analysis or rule processing. Without these basic elements, the scan result
* cannot be meaningfully processed.
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/scanoss/Winnowing.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.tika.Tika;
import org.apache.tika.mime.MediaType;
import org.apache.tika.mime.MediaTypeRegistry;
import org.jetbrains.annotations.NotNull;

import java.io.ByteArrayInputStream;
import java.io.File;
Expand Down Expand Up @@ -91,7 +90,7 @@ public class Winnowing {
* @param obfuscatedPath the obfuscated path
* @return the real file path corresponding to the provided obfuscated path, or the original path if no mapping exists
*/
public String deobfuscateFilePath(@NotNull String obfuscatedPath) {
public String deobfuscateFilePath(@NonNull String obfuscatedPath) {
String originalPath = obfuscationMap.get(obfuscatedPath);
return originalPath != null ? originalPath : obfuscatedPath;
}
Expand Down Expand Up @@ -229,7 +228,7 @@ public String wfpForContents(@NonNull String filename, Boolean binFile, byte[] c
* @param originalPath the original file path to be obfuscated; must not be null
* @return the obfuscated file path with a unique identifier and the original file extension
*/
private String obfuscateFilePath(@NotNull String originalPath) {
private String obfuscateFilePath(@NonNull String originalPath) {
final String extension = extractExtension(originalPath);

// Generate a unique identifier for the obfuscated file using a thread-safe approach
Expand All @@ -244,7 +243,7 @@ private String obfuscateFilePath(@NotNull String originalPath) {
* @param path the file path or name (must not be null)
* @return the file extension with leading dot (e.g., ".txt") or empty string if no extension
*/
private String extractExtension(@NotNull String path) {
private String extractExtension(@NonNull String path) {
try {
String extractedExtension = FilenameUtils.getExtension(path).trim();
return extractedExtension.isEmpty() ? "" : "." + extractedExtension;
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/scanoss/cli/ScanCommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ public void run() {
throw new RuntimeException("Error: No file or folder specified to scan");
}

//TODO: Deprecate options
String sbomType = null;
String sbom = null;

String caCertPem = null;
if (caCert != null && !caCert.isEmpty()) {
caCertPem = loadFileToString(caCert);
Expand Down Expand Up @@ -167,7 +163,7 @@ public void run() {
scanner = Scanner.builder().skipSnippets(skipSnippets).allFolders(allFolders).allExtensions(allExtensions)
.hiddenFilesFolders(allHidden).numThreads(numThreads).url(apiUrl).apiKey(apiKey)
.retryLimit(retryLimit).timeout(Duration.ofSeconds(timeoutLimit)).scanFlags(scanFlags)
.sbomType(sbomType).sbom(sbom).snippetLimit(snippetLimit).customCert(caCertPem).proxy(proxy).hpsm(enableHpsm)
.snippetLimit(snippetLimit).customCert(caCertPem).proxy(proxy).hpsm(enableHpsm)
.settings(settings).obfuscate(obfuscate)
.build();

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/scanoss/filters/AntFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
package com.scanoss.filters;

import lombok.Builder;
import lombok.NonNull;
import org.apache.tools.ant.types.selectors.SelectorUtils;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;
Expand All @@ -47,7 +48,7 @@ public class AntFilter {
* @param patterns a non-null list of Ant-style patterns to match against paths
*/
@Builder
public AntFilter(@NotNull List<String> patterns) {
public AntFilter(@NonNull List<String> patterns) {
this.patterns = patterns;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/scanoss/filters/GitIgnoreFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

import lombok.AccessLevel;
import lombok.Builder;
import lombok.NonNull;
import lombok.Setter;
import org.eclipse.jgit.ignore.FastIgnoreRule;
import org.eclipse.jgit.ignore.IgnoreNode;
import org.eclipse.jgit.ignore.IgnoreNode.MatchResult;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -45,7 +45,7 @@ public class GitIgnoreFilter {
private List<FastIgnoreRule> rules;

@Builder
public GitIgnoreFilter(@NotNull List<String> patterns) {
public GitIgnoreFilter(@NonNull List<String> patterns) {
this.rules = new ArrayList<>();
patterns.forEach(pattern -> rules.add(new FastIgnoreRule(pattern)));
this.node = new IgnoreNode(rules);
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/scanoss/rest/HttpStatusCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
package com.scanoss.rest;

import lombok.Getter;

/**
* Enum list of standard HTTP Status Codes
*/
Expand Down Expand Up @@ -281,6 +283,10 @@ public enum HttpStatusCode {
*/
NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");

/**
* Get the Integer value of the HTTP Status Code
*/
@Getter
private final int value;
private final String description;

Expand Down Expand Up @@ -310,15 +316,6 @@ public static String getByValueToString(int value) {
return value + " Unknown Status Code";
}

/**
* Get the Integer value of the HTTP Status Code
*
* @return HTTP status integer value
*/
public int getValue() {
return value;
}

/**
* String friendly version of the HTTP Status Code
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/scanoss/utils/Hpsm.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Hpsm {
private static final int CRC8_MAXIM_DOW_POLYNOMIAL = 0x8C; // 0x31 reflected
private static final int CRC8_MAXIM_DOW_INITIAL = 0x00; // 0x00 reflected
private static final int CRC8_MAXIM_DOW_FINAL = 0x00; // 0x00 reflected
private static int[] crc8MaximDowTable = new int[CRC8_MAXIM_DOW_TABLE_SIZE];
private static final int[] crc8MaximDowTable = new int[CRC8_MAXIM_DOW_TABLE_SIZE];

private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/scanoss/utils/WinnowingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
package com.scanoss.utils;

import org.jetbrains.annotations.NotNull;
import lombok.NonNull;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -63,7 +63,7 @@ public static char normalize(char c) {
* @param wfpBlock the WFP block containing file entries
* @return the first extracted file path, or null if none found
*/
public static String extractFilePathFromWFPBlock(@NotNull String wfpBlock) {
public static String extractFilePathFromWFPBlock(@NonNull String wfpBlock) {
Set<String> paths = extractFilePathsFromWFPBlock(wfpBlock);
return paths.isEmpty() ? null : paths.iterator().next();
}
Expand All @@ -76,7 +76,7 @@ public static String extractFilePathFromWFPBlock(@NotNull String wfpBlock) {
* @param wfpBlock the WFP block containing multiple file entries
* @return a Set of extracted file paths, empty if none found
*/
public static Set<String> extractFilePathsFromWFPBlock(@NotNull String wfpBlock) {
public static Set<String> extractFilePathsFromWFPBlock(@NonNull String wfpBlock) {
Set<String> paths = new HashSet<>();

// Pattern to match file=<md5>,<size>,<path> format and capture the path
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/scanoss/TestBom.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public void testReplaceRulesSortingWithDuplicatePaths() {

// Verify the rules with same path length maintain original order
assertEquals("Size should be 2", 2, sortedRules.size());
assertTrue("Both rules should have same priority",
new RuleComparator().compare(sortedRules.get(0), sortedRules.get(1)) == 0);
assertEquals("Both rules should have same priority", 0, new RuleComparator().compare(sortedRules.get(0), sortedRules.get(1)));

log.info("Finished testReplaceRulesSortingWithDuplicatePaths -->");
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/scanoss/TestScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import com.scanoss.settings.ScanossSettings;
import com.scanoss.utils.JsonUtils;
import com.scanoss.utils.WinnowingUtils;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -341,7 +341,7 @@ public void TestScannerFiltering() {
f = "testing/data/folder-ends-with-nbproject";
Scanner scanner = Scanner.builder().build();
List<String> wfps = scanner.wfpFolder(f);
assertTrue("WFP should NOT be empty", !wfps.isEmpty());
assertFalse("WFP should NOT be empty", wfps.isEmpty());

log.info("Testing filtering: file nbproject should not be filtered... ");
f = "testing/data";
Expand Down Expand Up @@ -464,9 +464,9 @@ private List<String> collectFilePaths(String directory) throws IOException {
*/
private Dispatcher createNoMatchDispatcher(Set<String> receivedPaths) {
return new Dispatcher() {
@NotNull
@NonNull
@Override
public MockResponse dispatch(@NotNull RecordedRequest request) {
public MockResponse dispatch(@NonNull RecordedRequest request) {
// Extract the WFP from the request and parse all obfuscated paths
String requestBody = request.getBody().readUtf8();
Set<String> paths = WinnowingUtils.extractFilePathsFromWFPBlock(requestBody);
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/scanoss/TestSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;
Expand Down