mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 10:01:35 +01:00
re-loading of properties/settings resolved by sharing the settings object amongst tasks
This commit is contained in:
@@ -29,8 +29,8 @@ import java.util.List;
|
|||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task to support parallelism of dependency-check analysis.
|
* Task to support parallelism of dependency-check analysis. Analyses a single
|
||||||
* Analyses a single {@link Dependency} by a specific {@link Analyzer}.
|
* {@link Dependency} by a specific {@link Analyzer}.
|
||||||
*
|
*
|
||||||
* @author Stefan Neuhaus
|
* @author Stefan Neuhaus
|
||||||
*/
|
*/
|
||||||
@@ -57,6 +57,10 @@ class AnalysisTask implements Callable<Void> {
|
|||||||
* The list of exceptions that may occur during analysis.
|
* The list of exceptions that may occur during analysis.
|
||||||
*/
|
*/
|
||||||
private final List<Throwable> exceptions;
|
private final List<Throwable> exceptions;
|
||||||
|
/**
|
||||||
|
* A reference to the global settings object.
|
||||||
|
*/
|
||||||
|
private final Settings settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new analysis task.
|
* Creates a new analysis task.
|
||||||
@@ -66,12 +70,16 @@ class AnalysisTask implements Callable<Void> {
|
|||||||
* @param engine the dependency-check engine
|
* @param engine the dependency-check engine
|
||||||
* @param exceptions exceptions that occur during analysis will be added to
|
* @param exceptions exceptions that occur during analysis will be added to
|
||||||
* this collection of exceptions
|
* this collection of exceptions
|
||||||
|
* @param settings a reference to the global settings object; this is
|
||||||
|
* necessary so that when the thread is started the dependencies have a
|
||||||
|
* correct reference to the global settings.
|
||||||
*/
|
*/
|
||||||
AnalysisTask(Analyzer analyzer, Dependency dependency, Engine engine, List<Throwable> exceptions) {
|
AnalysisTask(Analyzer analyzer, Dependency dependency, Engine engine, List<Throwable> exceptions, Settings settings) {
|
||||||
this.analyzer = analyzer;
|
this.analyzer = analyzer;
|
||||||
this.dependency = dependency;
|
this.dependency = dependency;
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.exceptions = exceptions;
|
this.exceptions = exceptions;
|
||||||
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +90,8 @@ class AnalysisTask implements Callable<Void> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Void call() {
|
public Void call() {
|
||||||
Settings.initialize();
|
try {
|
||||||
|
Settings.setInstance(settings);
|
||||||
|
|
||||||
if (shouldAnalyze()) {
|
if (shouldAnalyze()) {
|
||||||
LOGGER.debug("Begin Analysis of '{}' ({})", dependency.getActualFilePath(), analyzer.getName());
|
LOGGER.debug("Begin Analysis of '{}' ({})", dependency.getActualFilePath(), analyzer.getName());
|
||||||
@@ -99,7 +108,9 @@ class AnalysisTask implements Callable<Void> {
|
|||||||
exceptions.add(ex);
|
exceptions.add(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
Settings.cleanup(false);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ public class Engine implements FileFilter {
|
|||||||
final List<AnalysisTask> result = new ArrayList<AnalysisTask>();
|
final List<AnalysisTask> result = new ArrayList<AnalysisTask>();
|
||||||
synchronized (dependencies) {
|
synchronized (dependencies) {
|
||||||
for (final Dependency dependency : dependencies) {
|
for (final Dependency dependency : dependencies) {
|
||||||
final AnalysisTask task = new AnalysisTask(analyzer, dependency, this, exceptions);
|
final AnalysisTask task = new AnalysisTask(analyzer, dependency, this, exceptions, Settings.getInstance());
|
||||||
result.add(task);
|
result.add(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ import java.io.File;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
public class AnalysisTaskTest {
|
public class AnalysisTaskTest extends BaseTest {
|
||||||
|
|
||||||
@Mocked
|
@Mocked
|
||||||
FileTypeAnalyzer fileTypeAnalyzer;
|
FileTypeAnalyzer fileTypeAnalyzer;
|
||||||
@@ -27,7 +28,7 @@ public class AnalysisTaskTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldAnalyzeReturnsTrueForNonFileTypeAnalyzers() {
|
public void shouldAnalyzeReturnsTrueForNonFileTypeAnalyzers() {
|
||||||
AnalysisTask instance = new AnalysisTask(new HintAnalyzer(), null, null, null);
|
AnalysisTask instance = new AnalysisTask(new HintAnalyzer(), null, null, null, null);
|
||||||
boolean shouldAnalyze = instance.shouldAnalyze();
|
boolean shouldAnalyze = instance.shouldAnalyze();
|
||||||
assertTrue(shouldAnalyze);
|
assertTrue(shouldAnalyze);
|
||||||
}
|
}
|
||||||
@@ -43,7 +44,7 @@ public class AnalysisTaskTest {
|
|||||||
result = true;
|
result = true;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, null, null);
|
AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, null, null, Settings.getInstance());
|
||||||
|
|
||||||
boolean shouldAnalyze = analysisTask.shouldAnalyze();
|
boolean shouldAnalyze = analysisTask.shouldAnalyze();
|
||||||
assertTrue(shouldAnalyze);
|
assertTrue(shouldAnalyze);
|
||||||
@@ -60,7 +61,7 @@ public class AnalysisTaskTest {
|
|||||||
result = false;
|
result = false;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, null, null);
|
AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, null, null, Settings.getInstance());
|
||||||
|
|
||||||
boolean shouldAnalyze = analysisTask.shouldAnalyze();
|
boolean shouldAnalyze = analysisTask.shouldAnalyze();
|
||||||
assertFalse(shouldAnalyze);
|
assertFalse(shouldAnalyze);
|
||||||
@@ -68,7 +69,7 @@ public class AnalysisTaskTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void taskAnalyzes() throws Exception {
|
public void taskAnalyzes() throws Exception {
|
||||||
final AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, engine, null);
|
final AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, engine, null, Settings.getInstance());
|
||||||
new Expectations(analysisTask) {{
|
new Expectations(analysisTask) {{
|
||||||
analysisTask.shouldAnalyze();
|
analysisTask.shouldAnalyze();
|
||||||
result = true;
|
result = true;
|
||||||
@@ -84,7 +85,7 @@ public class AnalysisTaskTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void taskDoesNothingIfItShouldNotAnalyze() throws Exception {
|
public void taskDoesNothingIfItShouldNotAnalyze() throws Exception {
|
||||||
final AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, engine, null);
|
final AnalysisTask analysisTask = new AnalysisTask(fileTypeAnalyzer, dependency, engine, null, Settings.getInstance());
|
||||||
new Expectations(analysisTask) {{
|
new Expectations(analysisTask) {{
|
||||||
analysisTask.shouldAnalyze();
|
analysisTask.shouldAnalyze();
|
||||||
result = false;
|
result = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user