mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-26 02:51:27 +01:00
resolve merge conflict and update test cases
This commit is contained in:
@@ -280,7 +280,7 @@ public class Engine implements FileFilter, AutoCloseable {
|
|||||||
} catch (InvalidSettingException ex) {
|
} catch (InvalidSettingException ex) {
|
||||||
LOGGER.trace("Experimenal setting not configured; defaulting to false");
|
LOGGER.trace("Experimenal setting not configured; defaulting to false");
|
||||||
}
|
}
|
||||||
final AnalyzerService service = new AnalyzerService(serviceClassLoader, loadExperimental);
|
final AnalyzerService service = new AnalyzerService(serviceClassLoader, settings);
|
||||||
final List<Analyzer> iterator = service.getAnalyzers(mode.getPhases());
|
final List<Analyzer> iterator = service.getAnalyzers(mode.getPhases());
|
||||||
for (Analyzer a : iterator) {
|
for (Analyzer a : iterator) {
|
||||||
a.initialize(this.settings);
|
a.initialize(this.settings);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
import org.owasp.dependencycheck.utils.InvalidSettingException;
|
||||||
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Analyzer Service Loader. This class loads all services that implement
|
* The Analyzer Service Loader. This class loads all services that implement
|
||||||
@@ -47,18 +49,18 @@ public class AnalyzerService {
|
|||||||
/**
|
/**
|
||||||
* The configured settings.
|
* The configured settings.
|
||||||
*/
|
*/
|
||||||
private final boolean loadExperimental;
|
private final Settings settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of AnalyzerService.
|
* Creates a new instance of AnalyzerService.
|
||||||
*
|
*
|
||||||
* @param classLoader the ClassLoader to use when dynamically loading
|
* @param classLoader the ClassLoader to use when dynamically loading
|
||||||
* Analyzer and Update services
|
* Analyzer and Update services
|
||||||
* @param loadExperimental whether or not to load the experimental analyzers
|
* @param settings the configured settings
|
||||||
*/
|
*/
|
||||||
public AnalyzerService(ClassLoader classLoader, boolean loadExperimental) {
|
public AnalyzerService(ClassLoader classLoader, Settings settings) {
|
||||||
this.loadExperimental = loadExperimental;
|
|
||||||
service = ServiceLoader.load(Analyzer.class, classLoader);
|
service = ServiceLoader.load(Analyzer.class, classLoader);
|
||||||
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,12 +93,23 @@ public class AnalyzerService {
|
|||||||
private List<Analyzer> getAnalyzers(List<AnalysisPhase> phases) {
|
private List<Analyzer> getAnalyzers(List<AnalysisPhase> phases) {
|
||||||
final List<Analyzer> analyzers = new ArrayList<>();
|
final List<Analyzer> analyzers = new ArrayList<>();
|
||||||
final Iterator<Analyzer> iterator = service.iterator();
|
final Iterator<Analyzer> iterator = service.iterator();
|
||||||
|
boolean experimentalEnabled = false;
|
||||||
|
boolean retiredEnabled = false;
|
||||||
|
try {
|
||||||
|
experimentalEnabled = settings.getBoolean(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, false);
|
||||||
|
retiredEnabled = settings.getBoolean(Settings.KEYS.ANALYZER_RETIRED_ENABLED, false);
|
||||||
|
} catch (InvalidSettingException ex) {
|
||||||
|
LOGGER.error("invalid experimental or retired setting", ex);
|
||||||
|
}
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final Analyzer a = iterator.next();
|
final Analyzer a = iterator.next();
|
||||||
if (!phases.contains(a.getAnalysisPhase())) {
|
if (!phases.contains(a.getAnalysisPhase())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!loadExperimental && a.getClass().isAnnotationPresent(Experimental.class)) {
|
if (!experimentalEnabled && a.getClass().isAnnotationPresent(Experimental.class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!retiredEnabled && a.getClass().isAnnotationPresent(Retired.class)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LOGGER.debug("Loaded Analyzer {}", a.getName());
|
LOGGER.debug("Loaded Analyzer {}", a.getName());
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ import org.owasp.dependencycheck.dependency.EvidenceType;
|
|||||||
*
|
*
|
||||||
* @author Dale Visser
|
* @author Dale Visser
|
||||||
*/
|
*/
|
||||||
@Experimental
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
|
@Retired
|
||||||
public class NodePackageAnalyzer extends AbstractFileTypeAnalyzer {
|
public class NodePackageAnalyzer extends AbstractFileTypeAnalyzer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of dependency-check-core.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 Jeremy Long. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation used to flag an analyzer as retired.
|
||||||
|
*
|
||||||
|
* @author Steve Springett
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface Retired {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -88,7 +88,10 @@ archive.scan.depth=3
|
|||||||
downloader.quick.query.timestamp=true
|
downloader.quick.query.timestamp=true
|
||||||
downloader.tls.protocols=TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
|
downloader.tls.protocols=TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
|
||||||
|
|
||||||
|
# defines if the experimental and retired analyzers can be enabled
|
||||||
analyzer.experimental.enabled=false
|
analyzer.experimental.enabled=false
|
||||||
|
analyzer.retired.enabled=false
|
||||||
|
|
||||||
analyzer.jar.enabled=true
|
analyzer.jar.enabled=true
|
||||||
analyzer.archive.enabled=true
|
analyzer.archive.enabled=true
|
||||||
analyzer.node.package.enabled=true
|
analyzer.node.package.enabled=true
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class AnalyzerServiceTest extends BaseDBTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetAnalyzers() {
|
public void testGetAnalyzers() {
|
||||||
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), false);
|
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), getSettings());
|
||||||
List<Analyzer> result = instance.getAnalyzers();
|
List<Analyzer> result = instance.getAnalyzers();
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
@@ -58,7 +58,7 @@ public class AnalyzerServiceTest extends BaseDBTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetAnalyzers_SpecificPhases() throws Exception {
|
public void testGetAnalyzers_SpecificPhases() throws Exception {
|
||||||
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), false);
|
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), getSettings());
|
||||||
List<Analyzer> result = instance.getAnalyzers(INITIAL, FINAL);
|
List<Analyzer> result = instance.getAnalyzers(INITIAL, FINAL);
|
||||||
|
|
||||||
for (Analyzer a : result) {
|
for (Analyzer a : result) {
|
||||||
@@ -73,25 +73,54 @@ public class AnalyzerServiceTest extends BaseDBTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetExperimentalAnalyzers() {
|
public void testGetExperimentalAnalyzers() {
|
||||||
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), false);
|
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), getSettings());
|
||||||
List<Analyzer> result = instance.getAnalyzers();
|
List<Analyzer> result = instance.getAnalyzers();
|
||||||
String experimental = "CMake Analyzer";
|
String experimental = "CMake Analyzer";
|
||||||
|
String retired = "Node.js Package Analyzer";
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
boolean retiredFound = false;
|
||||||
for (Analyzer a : result) {
|
for (Analyzer a : result) {
|
||||||
if (experimental.equals(a.getName())) {
|
if (experimental.equals(a.getName())) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
if (retired.equals(a.getName())) {
|
||||||
|
retiredFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assertFalse("Experimental analyzer loaded when set to false", found);
|
assertFalse("Experimental analyzer loaded when set to false", found);
|
||||||
|
assertFalse("Retired analyzer loaded when set to false", retiredFound);
|
||||||
|
|
||||||
instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), true);
|
getSettings().setBoolean(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, true);
|
||||||
|
instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), getSettings());
|
||||||
result = instance.getAnalyzers();
|
result = instance.getAnalyzers();
|
||||||
found = false;
|
found = false;
|
||||||
|
retiredFound = false;
|
||||||
for (Analyzer a : result) {
|
for (Analyzer a : result) {
|
||||||
if (experimental.equals(a.getName())) {
|
if (experimental.equals(a.getName())) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
if (retired.equals(a.getName())) {
|
||||||
|
retiredFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assertTrue("Experimental analyzer not loaded when set to true", found);
|
assertTrue("Experimental analyzer not loaded when set to true", found);
|
||||||
|
assertFalse("Retired analyzer loaded when set to false", retiredFound);
|
||||||
|
|
||||||
|
getSettings().setBoolean(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, false);
|
||||||
|
getSettings().setBoolean(Settings.KEYS.ANALYZER_RETIRED_ENABLED, true);
|
||||||
|
instance = new AnalyzerService(Thread.currentThread().getContextClassLoader(), getSettings());
|
||||||
|
result = instance.getAnalyzers();
|
||||||
|
found = false;
|
||||||
|
retiredFound = false;
|
||||||
|
for (Analyzer a : result) {
|
||||||
|
if (experimental.equals(a.getName())) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
if (retired.equals(a.getName())) {
|
||||||
|
retiredFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFalse("Experimental analyzer loaded when set to false", found);
|
||||||
|
assertTrue("Retired analyzer not loaded when set to true", retiredFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,10 @@ archive.scan.depth=3
|
|||||||
downloader.quick.query.timestamp=true
|
downloader.quick.query.timestamp=true
|
||||||
downloader.tls.protocols=TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
|
downloader.tls.protocols=TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
|
||||||
|
|
||||||
analyzer.experimental.enabled=true
|
# defines if the experimental and retired analyzers can be enabled
|
||||||
|
analyzer.experimental.enabled=false
|
||||||
|
analyzer.retired.enabled=false
|
||||||
|
|
||||||
analyzer.jar.enabled=true
|
analyzer.jar.enabled=true
|
||||||
analyzer.archive.enabled=true
|
analyzer.archive.enabled=true
|
||||||
analyzer.node.package.enabled=true
|
analyzer.node.package.enabled=true
|
||||||
|
|||||||
@@ -253,6 +253,10 @@ public final class Settings {
|
|||||||
* The properties key for whether experimental analyzers are loaded.
|
* The properties key for whether experimental analyzers are loaded.
|
||||||
*/
|
*/
|
||||||
public static final String ANALYZER_EXPERIMENTAL_ENABLED = "analyzer.experimental.enabled";
|
public static final String ANALYZER_EXPERIMENTAL_ENABLED = "analyzer.experimental.enabled";
|
||||||
|
/**
|
||||||
|
* The properties key for whether experimental analyzers are loaded.
|
||||||
|
*/
|
||||||
|
public static final String ANALYZER_RETIRED_ENABLED = "analyzer.retired.enabled";
|
||||||
/**
|
/**
|
||||||
* The properties key for whether the Archive analyzer is enabled.
|
* The properties key for whether the Archive analyzer is enabled.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user