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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.owasp.dependencycheck.analyzer;

import java.io.FileFilter;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
Expand All @@ -27,8 +28,10 @@
import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.dependency.Evidence;
import org.owasp.dependencycheck.dependency.EvidenceType;
import org.owasp.dependencycheck.exception.InitializationException;
import org.owasp.dependencycheck.utils.DependencyVersion;
import org.owasp.dependencycheck.utils.DependencyVersionUtil;
import org.owasp.dependencycheck.utils.FileFilterBuilder;
import org.owasp.dependencycheck.utils.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -42,7 +45,7 @@
* @author Jeremy Long
*/
@ThreadSafe
public class VersionFilterAnalyzer extends AbstractAnalyzer {
public class VersionFilterAnalyzer extends AbstractFileTypeAnalyzer {

/**
* The Logger for use throughout the class
Expand Down Expand Up @@ -87,6 +90,10 @@ public class VersionFilterAnalyzer extends AbstractAnalyzer {
* The phase that this analyzer is intended to run in.
*/
private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.POST_INFORMATION_COLLECTION3;
/**
* The file filter used to determine which files this analyzer supports.
*/
private static final FileFilter FILTER = FileFilterBuilder.newInstance().addExtensions("jar").build();

//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Standard implementation of Analyzer">
Expand Down Expand Up @@ -119,6 +126,29 @@ public AnalysisPhase getAnalysisPhase() {
protected String getAnalyzerEnabledSettingKey() {
return Settings.KEYS.ANALYZER_VERSION_FILTER_ENABLED;
}

/**
* Returns the FileFilter used to determine which files this analyzer
* supports (JAR files only).
*
* @return the file filter for JAR files
*/
@Override
protected FileFilter getFileFilter() {
return FILTER;
}

/**
* No initialization required for this analyzer.
*
* @param engine a reference to the dependency-check engine
* @throws InitializationException thrown if there is an exception during
* initialization
*/
@Override
public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
//nothing to initialize
}
//</editor-fold>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.owasp.dependencycheck.analyzer;

import java.io.File;
import org.junit.jupiter.api.Test;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.dependency.Confidence;
Expand All @@ -25,14 +26,30 @@
import org.owasp.dependencycheck.utils.Settings;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
*
* @author Jeremy Long
*/
class VersionFilterAnalyzerTest extends BaseTest {

/**
* Test that the analyzer only accepts JAR files.
*/
@Test
void testAcceptOnlyJarFiles() {
VersionFilterAnalyzer instance = new VersionFilterAnalyzer();
instance.initialize(getSettings());
assertTrue(instance.accept(new File("example-1.2.3.jar")));
assertFalse(instance.accept(new File("example-1.2.3.war")));
assertFalse(instance.accept(new File("example-1.2.3.dll")));
assertFalse(instance.accept(new File("example-1.2.3.exe")));
assertFalse(instance.accept(new File("pom.xml")));
}

/**
* Test of getName method, of class VersionFilterAnalyzer.
*/
Expand Down
Loading