Skip to content

Commit b75f08d

Browse files
committed
CLIS-111 Adds dir extension filter
1 parent c448f11 commit b75f08d

File tree

6 files changed

+1954
-5
lines changed

6 files changed

+1954
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Changed
1616
- Update file and winnowing filters
1717
- Remove filter for '.whl' file extensions
18+
- Added dir extension filter
1819

1920
## [0.7.0] - 2024-04-04
2021
### Added

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,29 @@ public String wfpFile(@NonNull String filename) throws ScannerException, Winnowi
156156
* @return <code>true</code> if the folder should be skipped, <code>false</code> otherwise
157157
*/
158158
private Boolean filterFolder(String name) {
159+
String nameLower = name.toLowerCase();
159160
if (!hiddenFilesFolders && name.startsWith(".") && !name.equals(".")) {
160161
log.trace("Skipping hidden folder: {}", name);
161162
return true;
162163
}
164+
boolean ignore = false;
163165
if (!allFolders) { // skip this check if all folders is selected
164166
for (String ending : ScanossConstants.FILTERED_DIRS) {
165-
if (name.endsWith(ending)) {
167+
if (nameLower.endsWith(ending)) {
166168
log.trace("Skipping folder due to ending: {} - {}", name, ending);
167-
return true;
169+
ignore = true;
170+
}
171+
}
172+
if(!ignore){
173+
for (String ending : ScanossConstants.FILTERED_DIR_EXT) {
174+
if (nameLower.endsWith(ending)) {
175+
log.trace("Skipping folder due to ending: {} - {}", name, ending);
176+
ignore = true;
177+
}
168178
}
169179
}
170180
}
171-
return false;
181+
return ignore;
172182
}
173183

174184
/**

src/main/java/com/scanoss/ScanossConstants.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ScanossConstants {
3636
".o", ".a", ".so", ".obj", ".dll", ".lib", ".out", ".app", ".bin",
3737
".lst", ".dat", ".json", ".htm", ".html", ".xml", ".md", ".txt",
3838
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".ods", ".odp", ".pages", ".key", ".numbers",
39-
".pdf", ".min.js", ".mf", ".sum", ".woff", ".woff2", ".xsd", ".pom"
39+
".pdf", ".min.js", ".mf", ".sum", ".woff", ".woff2", ".xsd", ".pom", ".whl"
4040
);
4141

4242
// Folders to skip
@@ -45,6 +45,10 @@ public class ScanossConstants {
4545
"__pypackages__", "target"
4646
);
4747

48+
// Folder endings to skip
49+
static final List<String> FILTERED_DIR_EXT = List.of(".egg-info");
50+
51+
4852
// File extensions to skip
4953
static final List<String> FILTERED_EXTENSIONS = Arrays.asList(
5054
".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".9", ".ac", ".adoc", ".am",

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,30 @@ public void TestScannerScanFileListNegative() {
242242
log.info("Finished {} -->", methodName);
243243
}
244244

245-
@Test
245+
@Test
246246
public void TestScannerTemplate() {
247247
String methodName = new Object() {
248248
}.getClass().getEnclosingMethod().getName();
249249
log.info("<-- Starting {}", methodName);
250250

251251
log.info("Finished {} -->", methodName);
252252
}
253+
254+
@Test
255+
public void TestIgnoreFolderExtension() {
256+
String methodName = new Object() {
257+
}.getClass().getEnclosingMethod().getName();
258+
log.info("<-- Starting {}", methodName);
259+
260+
Scanner scanner = Scanner.builder().build();
261+
String folder = "testing/data/test-folder-ignore";
262+
List<String> results = scanner.scanFolder(folder);
263+
log.info("Received {} results", results.size());
264+
assertFalse("Scan results should be empty", results.isEmpty());
265+
assertEquals("Results should be one", results.size() , 1);
266+
267+
log.info("Finished {} -->", methodName);
268+
}
269+
270+
253271
}

0 commit comments

Comments
 (0)