Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP 537 update winnowing and file filters #7

Merged
merged 3 commits into from
Apr 12, 2024
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Upcoming changes...

## [0.7.1] - 2024-04-12
### Changed
- Update file and winnowing filters
- Remove filter for '.whl' file extensions
- Added dir extension filter

## [0.7.0] - 2024-04-04
### Added
- Add HPSM support
Expand Down Expand Up @@ -79,3 +85,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.6.0]: https://github.com/scanoss/scanoss.java/compare/v0.5.5...v0.6.0
[0.6.1]: https://github.com/scanoss/scanoss.java/compare/v0.6.0...v0.6.1
[0.7.0]: https://github.com/scanoss/scanoss.java/compare/v0.6.1...v0.7.0
[0.7.1]: https://github.com/scanoss/scanoss.java/compare/v0.7.0...v0.7.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.7.0</version>
<version>0.7.1</version>
<packaging>jar</packaging>
<name>scanoss.java</name>
<url>https://github.com/scanoss/scanoss.java</url>
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/scanoss/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,29 @@ public String wfpFile(@NonNull String filename) throws ScannerException, Winnowi
* @return <code>true</code> if the folder should be skipped, <code>false</code> otherwise
*/
private Boolean filterFolder(String name) {
String nameLower = name.toLowerCase();
if (!hiddenFilesFolders && name.startsWith(".") && !name.equals(".")) {
log.trace("Skipping hidden folder: {}", name);
return true;
}
boolean ignore = false;
if (!allFolders) { // skip this check if all folders is selected
for (String ending : ScanossConstants.FILTERED_DIRS) {
if (name.endsWith(ending)) {
if (nameLower.endsWith(ending)) {
log.trace("Skipping folder due to ending: {} - {}", name, ending);
return true;
ignore = true;
}
}
if(!ignore){
for (String ending : ScanossConstants.FILTERED_DIR_EXT) {
if (nameLower.endsWith(ending)) {
log.trace("Skipping folder due to ending: {} - {}", name, ending);
ignore = true;
}
}
}
}
return false;
return ignore;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/scanoss/ScanossConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ScanossConstants {
".o", ".a", ".so", ".obj", ".dll", ".lib", ".out", ".app", ".bin",
".lst", ".dat", ".json", ".htm", ".html", ".xml", ".md", ".txt",
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".ods", ".odp", ".pages", ".key", ".numbers",
".pdf", ".min.js", ".mf", ".sum", ".woff", ".woff2"
".pdf", ".min.js", ".mf", ".sum", ".woff", ".woff2", ".xsd", ".pom", ".whl"
);

// Folders to skip
Expand All @@ -45,6 +45,10 @@ public class ScanossConstants {
"__pypackages__", "target"
);

// Folder endings to skip
static final List<String> FILTERED_DIR_EXT = List.of(".egg-info");


// File extensions to skip
static final List<String> FILTERED_EXTENSIONS = Arrays.asList(
".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".9", ".ac", ".adoc", ".am",
Expand All @@ -59,7 +63,7 @@ public class ScanossConstants {
".po", ".ppt", ".prefs", ".properties", ".pyc", ".qdoc", ".result", ".rgb",
".rst", ".scss", ".sha", ".sha1", ".sha2", ".sha256", ".sln", ".spec", ".sql",
".sub", ".svg", ".svn-base", ".tab", ".template", ".test", ".tex", ".tiff",
".toml", ".ttf", ".txt", ".utf-8", ".vim", ".wav", ".whl", ".woff", ".woff2", ".xht",
".toml", ".ttf", ".txt", ".utf-8", ".vim", ".wav", ".woff", ".woff2", ".xht",
".xhtml", ".xls", ".xlsx", ".xml", ".xpm", ".xsd", ".xul", ".yaml", ".yml", ".wfp",
".editorconfig", ".dotcover", ".pid", ".lcov", ".egg", ".manifest", ".cache", ".coverage", ".cover",
".gem", ".lst", ".pickle", ".pdb", ".gml", ".pot", ".plt",
Expand Down
20 changes: 19 additions & 1 deletion src/test/java/com/scanoss/TestScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,30 @@ public void TestScannerScanFileListNegative() {
log.info("Finished {} -->", methodName);
}

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

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

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

Scanner scanner = Scanner.builder().build();
String folder = "testing/data/test-folder-ignore";
List<String> results = scanner.scanFolder(folder);
log.info("Received {} results", results.size());
assertFalse("Scan results should be empty", results.isEmpty());
assertEquals("Results should be one", results.size() , 1);

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


}
Loading
Loading