Skip to content

Commit ff705e4

Browse files
committed
fix(SP-2588): Intellij inspect cleanup
1 parent 0da24ab commit ff705e4

File tree

12 files changed

+31
-39
lines changed

12 files changed

+31
-39
lines changed

src/main/java/com/scanoss/Scanner.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,19 @@ public List<String> processFolder(@NonNull String folder, FileProcessor processo
223223
List<Future<String>> futures = new ArrayList<>();
224224
try {
225225
Files.walkFileTree(Paths.get(folder), new SimpleFileVisitor<>() {
226+
@NonNull
226227
@Override
227-
public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) {
228+
public FileVisitResult preVisitDirectory(Path file, @NonNull BasicFileAttributes attrs) {
228229
if(folderFilter.test(file)) {
229230
log.debug("Processing file: {}", file.getFileName().toString());
230231
return FileVisitResult.SKIP_SUBTREE; // Skip the rest of this directory tree
231232
}
232233
return FileVisitResult.CONTINUE;
233234
}
234235

236+
@NonNull
235237
@Override
236-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
238+
public FileVisitResult visitFile(Path file, @NonNull BasicFileAttributes attrs) {
237239
if (attrs.isRegularFile() && !fileFilter.test(file) && attrs.size() > 0) {
238240
String filename = file.toString();
239241
Future<String> future = executorService.submit(() -> processor.process(filename, stripDirectory(folder, filename)));
@@ -292,7 +294,7 @@ public List<String> processFileList(@NonNull String root, @NonNull List<String>
292294
if (skipDir) {
293295
continue; // skip this file as the folder is not allowed
294296
}
295-
String nameLower = path.getFileName().toString().toLowerCase();
297+
296298
if (!this.fileFilter.test(path)) {
297299
Path fullPath = Path.of(root, file);
298300
File f = fullPath.toFile();

src/main/java/com/scanoss/ScannerPostProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ private void buildPurl2ComponentDetailsMap(@NonNull List<ScanFileResult> scanFil
146146
*
147147
* @param results The list of scan results to process and modify
148148
* @param rules The list of replacement rules to apply
149-
* @return The modified input list of scan results with updated PURLs
150149
*/
151150
private void applyReplaceRules(@NonNull List<ScanFileResult> results, @NonNull List<ReplaceRule> rules) {
152151
log.debug("Starting replace rules application for {} results with {} rules", results.size(), rules.size());
@@ -268,7 +267,7 @@ private ScanFileDetails createUpdatedResultDetails(ScanFileDetails existingCompo
268267

269268
/**
270269
* Marks all components in the list as non-matching by replacing each component
271-
* with a new instance that has MatchType.NONE while preserving the serverDetails
270+
* with a new instance that has MatchType. NONE while preserving the serverDetails
272271
* Modifies the input list in place using List.replaceAll().
273272
*
274273
* @param components List of scan file details to be marked as non-matching
@@ -451,7 +450,7 @@ private boolean isPurlMatch(String rulePurl, String[] resultPurls) {
451450
* 1. The result has a valid file path identifier
452451
* 2. The result contains a non-empty list of scan details
453452
* 3. The primary scan detail entry (first in the list) exists
454-
*
453+
* <p>
455454
* This structural validation is a prerequisite for any further processing of scan results,
456455
* such as match analysis or rule processing. Without these basic elements, the scan result
457456
* cannot be meaningfully processed.

src/main/java/com/scanoss/Winnowing.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.tika.Tika;
3333
import org.apache.tika.mime.MediaType;
3434
import org.apache.tika.mime.MediaTypeRegistry;
35-
import org.jetbrains.annotations.NotNull;
3635

3736
import java.io.ByteArrayInputStream;
3837
import java.io.File;
@@ -91,7 +90,7 @@ public class Winnowing {
9190
* @param obfuscatedPath the obfuscated path
9291
* @return the real file path corresponding to the provided obfuscated path, or the original path if no mapping exists
9392
*/
94-
public String deobfuscateFilePath(@NotNull String obfuscatedPath) {
93+
public String deobfuscateFilePath(@NonNull String obfuscatedPath) {
9594
String originalPath = obfuscationMap.get(obfuscatedPath);
9695
return originalPath != null ? originalPath : obfuscatedPath;
9796
}
@@ -229,7 +228,7 @@ public String wfpForContents(@NonNull String filename, Boolean binFile, byte[] c
229228
* @param originalPath the original file path to be obfuscated; must not be null
230229
* @return the obfuscated file path with a unique identifier and the original file extension
231230
*/
232-
private String obfuscateFilePath(@NotNull String originalPath) {
231+
private String obfuscateFilePath(@NonNull String originalPath) {
233232
final String extension = extractExtension(originalPath);
234233

235234
// Generate a unique identifier for the obfuscated file using a thread-safe approach
@@ -244,7 +243,7 @@ private String obfuscateFilePath(@NotNull String originalPath) {
244243
* @param path the file path or name (must not be null)
245244
* @return the file extension with leading dot (e.g., ".txt") or empty string if no extension
246245
*/
247-
private String extractExtension(@NotNull String path) {
246+
private String extractExtension(@NonNull String path) {
248247
try {
249248
String extractedExtension = FilenameUtils.getExtension(path).trim();
250249
return extractedExtension.isEmpty() ? "" : "." + extractedExtension;

src/main/java/com/scanoss/cli/ScanCommandLine.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ public void run() {
121121
throw new RuntimeException("Error: No file or folder specified to scan");
122122
}
123123

124-
//TODO: Deprecate options
125-
String sbomType = null;
126-
String sbom = null;
127-
128124
String caCertPem = null;
129125
if (caCert != null && !caCert.isEmpty()) {
130126
caCertPem = loadFileToString(caCert);
@@ -167,7 +163,7 @@ public void run() {
167163
scanner = Scanner.builder().skipSnippets(skipSnippets).allFolders(allFolders).allExtensions(allExtensions)
168164
.hiddenFilesFolders(allHidden).numThreads(numThreads).url(apiUrl).apiKey(apiKey)
169165
.retryLimit(retryLimit).timeout(Duration.ofSeconds(timeoutLimit)).scanFlags(scanFlags)
170-
.sbomType(sbomType).sbom(sbom).snippetLimit(snippetLimit).customCert(caCertPem).proxy(proxy).hpsm(enableHpsm)
166+
.snippetLimit(snippetLimit).customCert(caCertPem).proxy(proxy).hpsm(enableHpsm)
171167
.settings(settings).obfuscate(obfuscate)
172168
.build();
173169

src/main/java/com/scanoss/filters/AntFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
package com.scanoss.filters;
2424

2525
import lombok.Builder;
26+
import lombok.NonNull;
2627
import org.apache.tools.ant.types.selectors.SelectorUtils;
27-
import org.jetbrains.annotations.NotNull;
28+
2829
import java.nio.file.Path;
2930
import java.util.List;
3031
import java.util.function.Predicate;
@@ -47,7 +48,7 @@ public class AntFilter {
4748
* @param patterns a non-null list of Ant-style patterns to match against paths
4849
*/
4950
@Builder
50-
public AntFilter(@NotNull List<String> patterns) {
51+
public AntFilter(@NonNull List<String> patterns) {
5152
this.patterns = patterns;
5253
}
5354

src/main/java/com/scanoss/filters/GitIgnoreFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525
import lombok.AccessLevel;
2626
import lombok.Builder;
27+
import lombok.NonNull;
2728
import lombok.Setter;
2829
import org.eclipse.jgit.ignore.FastIgnoreRule;
2930
import org.eclipse.jgit.ignore.IgnoreNode;
3031
import org.eclipse.jgit.ignore.IgnoreNode.MatchResult;
31-
import org.jetbrains.annotations.NotNull;
3232
import java.nio.file.Path;
3333
import java.util.ArrayList;
3434
import java.util.List;
@@ -45,7 +45,7 @@ public class GitIgnoreFilter {
4545
private List<FastIgnoreRule> rules;
4646

4747
@Builder
48-
public GitIgnoreFilter(@NotNull List<String> patterns) {
48+
public GitIgnoreFilter(@NonNull List<String> patterns) {
4949
this.rules = new ArrayList<>();
5050
patterns.forEach(pattern -> rules.add(new FastIgnoreRule(pattern)));
5151
this.node = new IgnoreNode(rules);

src/main/java/com/scanoss/rest/HttpStatusCode.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package com.scanoss.rest;
2424

25+
import lombok.Getter;
26+
2527
/**
2628
* Enum list of standard HTTP Status Codes
2729
*/
@@ -281,6 +283,10 @@ public enum HttpStatusCode {
281283
*/
282284
NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required");
283285

286+
/**
287+
* Get the Integer value of the HTTP Status Code
288+
*/
289+
@Getter
284290
private final int value;
285291
private final String description;
286292

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

313-
/**
314-
* Get the Integer value of the HTTP Status Code
315-
*
316-
* @return HTTP status integer value
317-
*/
318-
public int getValue() {
319-
return value;
320-
}
321-
322319
/**
323320
* String friendly version of the HTTP Status Code
324321
*

src/main/java/com/scanoss/utils/Hpsm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Hpsm {
3939
private static final int CRC8_MAXIM_DOW_POLYNOMIAL = 0x8C; // 0x31 reflected
4040
private static final int CRC8_MAXIM_DOW_INITIAL = 0x00; // 0x00 reflected
4141
private static final int CRC8_MAXIM_DOW_FINAL = 0x00; // 0x00 reflected
42-
private static int[] crc8MaximDowTable = new int[CRC8_MAXIM_DOW_TABLE_SIZE];
42+
private static final int[] crc8MaximDowTable = new int[CRC8_MAXIM_DOW_TABLE_SIZE];
4343

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

src/main/java/com/scanoss/utils/WinnowingUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
package com.scanoss.utils;
2424

25-
import org.jetbrains.annotations.NotNull;
25+
import lombok.NonNull;
2626

2727
import java.util.HashSet;
2828
import java.util.Set;
@@ -63,7 +63,7 @@ public static char normalize(char c) {
6363
* @param wfpBlock the WFP block containing file entries
6464
* @return the first extracted file path, or null if none found
6565
*/
66-
public static String extractFilePathFromWFPBlock(@NotNull String wfpBlock) {
66+
public static String extractFilePathFromWFPBlock(@NonNull String wfpBlock) {
6767
Set<String> paths = extractFilePathsFromWFPBlock(wfpBlock);
6868
return paths.isEmpty() ? null : paths.iterator().next();
6969
}
@@ -76,7 +76,7 @@ public static String extractFilePathFromWFPBlock(@NotNull String wfpBlock) {
7676
* @param wfpBlock the WFP block containing multiple file entries
7777
* @return a Set of extracted file paths, empty if none found
7878
*/
79-
public static Set<String> extractFilePathsFromWFPBlock(@NotNull String wfpBlock) {
79+
public static Set<String> extractFilePathsFromWFPBlock(@NonNull String wfpBlock) {
8080
Set<String> paths = new HashSet<>();
8181

8282
// Pattern to match file=<md5>,<size>,<path> format and capture the path

src/test/java/com/scanoss/TestBom.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ public void testReplaceRulesSortingWithDuplicatePaths() {
110110

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

116115
log.info("Finished testReplaceRulesSortingWithDuplicatePaths -->");
117116
}

src/test/java/com/scanoss/TestScanner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
import com.scanoss.settings.ScanossSettings;
3333
import com.scanoss.utils.JsonUtils;
3434
import com.scanoss.utils.WinnowingUtils;
35+
import lombok.NonNull;
3536
import lombok.extern.slf4j.Slf4j;
3637
import okhttp3.mockwebserver.Dispatcher;
3738
import okhttp3.mockwebserver.MockResponse;
3839
import okhttp3.mockwebserver.MockWebServer;
3940
import okhttp3.mockwebserver.RecordedRequest;
40-
import org.jetbrains.annotations.NotNull;
4141
import org.junit.After;
4242
import org.junit.Before;
4343
import org.junit.Test;
@@ -341,7 +341,7 @@ public void TestScannerFiltering() {
341341
f = "testing/data/folder-ends-with-nbproject";
342342
Scanner scanner = Scanner.builder().build();
343343
List<String> wfps = scanner.wfpFolder(f);
344-
assertTrue("WFP should NOT be empty", !wfps.isEmpty());
344+
assertFalse("WFP should NOT be empty", wfps.isEmpty());
345345

346346
log.info("Testing filtering: file nbproject should not be filtered... ");
347347
f = "testing/data";
@@ -464,9 +464,9 @@ private List<String> collectFilePaths(String directory) throws IOException {
464464
*/
465465
private Dispatcher createNoMatchDispatcher(Set<String> receivedPaths) {
466466
return new Dispatcher() {
467-
@NotNull
467+
@NonNull
468468
@Override
469-
public MockResponse dispatch(@NotNull RecordedRequest request) {
469+
public MockResponse dispatch(@NonNull RecordedRequest request) {
470470
// Extract the WFP from the request and parse all obfuscated paths
471471
String requestBody = request.getBody().readUtf8();
472472
Set<String> paths = WinnowingUtils.extractFilePathsFromWFPBlock(requestBody);

src/test/java/com/scanoss/TestSettings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.nio.file.Files;
3333
import java.nio.file.Path;
3434
import java.nio.file.Paths;
35-
import java.util.ArrayList;
3635
import java.util.List;
3736

3837
import static org.junit.Assert.*;

0 commit comments

Comments
 (0)