Skip to content

Commit

Permalink
Merge pull request #26 from scanoss/v0.10.1
Browse files Browse the repository at this point in the history
V0.10.1
  • Loading branch information
isasmendiagus authored Feb 20, 2025
2 parents c7a815d + e9264cb commit 0ec8201
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 25 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Upcoming changes...

## [0.10.1] - 2025-02-20
### Added
- Add support to custom filtering rules
- Change logic on remove rule. Mark file as non match instead of deleting the key.

## [0.10.0] - 2025-02-17
### Added
- Add support to skip rule
Expand Down Expand Up @@ -109,4 +114,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.8.0]: https://github.com/scanoss/scanoss.java/compare/v0.7.1...v0.8.0
[0.8.1]: https://github.com/scanoss/scanoss.java/compare/v0.8.0...v0.8.1
[0.9.0]: https://github.com/scanoss/scanoss.java/compare/v0.8.1...v0.9.0
[0.10.0]: https://github.com/scanoss/scanoss.java/compare/v0.9.0...v0.10.0
[0.10.0]: https://github.com/scanoss/scanoss.java/compare/v0.9.0...v0.10.0
[0.10.1]: https://github.com/scanoss/scanoss.java/compare/v0.10.0...v0.10.1
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.scanoss</groupId>
<artifactId>scanoss</artifactId>
<version>0.10.0</version>
<version>0.10.1</version>
<packaging>jar</packaging>
<name>scanoss.java</name>
<url>https://github.com/scanoss/scanoss.java</url>
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/scanoss/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ public class Scanner {
private Predicate<Path> fileFilter;
private Predicate<Path> folderFilter;

//TODO: Once this Lombok PR is merged https://github.com/projectlombok/lombok/pull/3723#pullrequestreview-2617412643
// Update Lombok dependency
public static class ScannerBuilder {
private ScannerBuilder folderFilter(Predicate<Path> folderFilter) {
return this;
}
private ScannerBuilder fileFilter(Predicate<Path> fileFilter) {
return this;
}
}

@SuppressWarnings("unused")
private Scanner(Boolean skipSnippets, Boolean allExtensions, Boolean obfuscate, Boolean hpsm,
Boolean hiddenFilesFolders, Boolean allFolders, Integer numThreads, Duration timeout,
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/scanoss/ScannerPostProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ private ScanFileDetails createUpdatedResultDetails(ScanFileDetails existingCompo
.build();
}

/**
* 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
* Modifies the input list in place using List.replaceAll().
*
* @param components List of scan file details to be marked as non-matching
*/
private void markComponentsAsNonMatch(List<ScanFileDetails> components) {
components.replaceAll(component ->
ScanFileDetails.builder()
.matchType(MatchType.none)
.serverDetails(component.getServerDetails())
.build()
);
}

/**
* Applies remove rules to scan results, filtering out matches based on certain criteria.
* <p>
Expand All @@ -281,7 +297,9 @@ private ScanFileDetails createUpdatedResultDetails(ScanFileDetails existingCompo
*/
public void applyRemoveRules(@NonNull List<ScanFileResult> results, @NonNull List<RemoveRule> rules) {
log.debug("Starting remove rules application to {} results", results.size());
results.removeIf(result -> matchesRemovalCriteria(result, rules));
results.stream()
.filter(result -> matchesRemovalCriteria(result, rules))
.forEach(result -> markComponentsAsNonMatch(result.getFileDetails()));
log.debug("Remove rules application completed. Results remaining: {}", results.size());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/scanoss/filters/BaseFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ protected BaseFilter(FilterConfig config) {
this.config = config;
this.gitIgnoreFilter = GitIgnoreFilter.builder().patterns(config.getGitIgnorePatterns()).build();
this.antFilter = AntFilter.builder().patterns(config.getAntPatterns()).build();
this.baseSkipFilter = this.antFilter.get().or(this.gitIgnoreFilter.get());
this.baseSkipFilter = this.antFilter.get().or(this.gitIgnoreFilter.get()).or(this.config.getCustomFilter());
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/scanoss/filters/FilterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

import lombok.Builder;
import lombok.Getter;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
* Configuration class for the SCANOSS filtering system that defines various filtering rules and patterns.
Expand All @@ -51,4 +54,7 @@ public class FilterConfig {

@Builder.Default
private final Boolean allExtensions = false;

@Builder.Default
private final Predicate<Path> customFilter = path -> false;
}
23 changes: 23 additions & 0 deletions src/test/java/com/scanoss/TestScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,27 @@ public void TestScannerSkipAntPattern() {

log.info("Finished {} -->", methodName);
}

@Test
public void TestScannerCustomFilterConfig() {
String methodName = new Object() {
}.getClass().getEnclosingMethod().getName();
log.info("<-- Starting {}", methodName);

String f;
List<String> wfps;

log.info("Testing GitIgnore Pattern: ");
f = "testing/data/folder-ends-with-nbproject";

FilterConfig filterConfig = FilterConfig.builder()
.customFilter(p -> true)
.build();

Scanner scanner = Scanner.builder().filterConfig(filterConfig).build();
wfps = scanner.wfpFolder(f);
assertTrue("There is no fingerprint since custom filter it's always true", wfps.isEmpty());

log.info("Finished {} -->", methodName);
}
}
25 changes: 15 additions & 10 deletions src/test/java/com/scanoss/TestScannerPostProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.google.gson.JsonObject;
import com.scanoss.dto.ScanFileResult;
import com.scanoss.dto.enums.MatchType;
import com.scanoss.settings.Bom;
import com.scanoss.settings.RemoveRule;
import com.scanoss.settings.ReplaceRule;
Expand Down Expand Up @@ -73,6 +74,16 @@ public void Setup() throws URISyntaxException, IOException {

}

private Boolean hasOnlyNonMatchingDetailsForPath(List<ScanFileResult> results, String path) {
Optional<ScanFileResult> r = results.stream().filter(result -> result.getFilePath().matches(path)).findFirst();

if (r.isEmpty()) {
fail(String.format("Should have found file %s", path));
}

return r.get().getFileDetails().stream().noneMatch(c -> c.getMatchType() != MatchType.none);

}

/**
* TESTING REMOVE RULES
Expand All @@ -94,7 +105,7 @@ public void TestRemoveRuleWithPathAndPurl() {
List<ScanFileResult> results = scannerPostProcessor.process(sampleScanResults, bom);

// Verify
assertEquals("Should have one result less after removal", sampleScanResults.size() - 1, results.size());
assertTrue(hasOnlyNonMatchingDetailsForPath(results, "CMSsite/admin/js/npm.js"));
log.info("Finished {} -->", methodName);
}

Expand All @@ -116,13 +127,7 @@ public void TestRemoveRuleWithPurlOnly() {
// Process results
List<ScanFileResult> results = scannerPostProcessor.process(sampleScanResults, bom);

// Verify
assertEquals("Size should decrease by 1 after removal",
sampleScanResults.size() - 1,
results.size());

assertFalse("Should remove file CMSsite/admin/js/npm.js",
results.stream().anyMatch(r -> r.getFilePath().matches("CMSsite/admin/js/npm.js")));
assertTrue(hasOnlyNonMatchingDetailsForPath(results, "CMSsite/admin/js/npm.js"));

log.info("Finished {} -->", methodName);
}
Expand Down Expand Up @@ -258,7 +263,7 @@ public void testRemoveRuleWithOverlappingLineRanges() {
List<ScanFileResult> results = scannerPostProcessor.process(sampleScanResults, bom);

// Verify - should remove because lines overlap
assertEquals("Should have one result less after removal", sampleScanResults.size() - 1, results.size());
assertTrue(hasOnlyNonMatchingDetailsForPath(results, "src/spdx.c"));

log.info("Finished {} -->", methodName);
}
Expand Down Expand Up @@ -289,7 +294,7 @@ public void testMultipleRemoveRulesWithMixedLineRanges() {
// Process results
List<ScanFileResult> results = scannerPostProcessor.process(sampleScanResults, bom);

assertEquals("Should have one result less after removal", sampleScanResults.size() - 1, results.size());
assertTrue(hasOnlyNonMatchingDetailsForPath(results, "src/spdx.c"));

log.info("Finished {} -->", methodName);
}
Expand Down

0 comments on commit 0ec8201

Please sign in to comment.