mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-28 20:02:16 +01:00
Autocloseable
This commit is contained in:
@@ -55,7 +55,7 @@ import static org.owasp.dependencycheck.analyzer.AnalysisPhase.*;
|
|||||||
*
|
*
|
||||||
* @author Jeremy Long
|
* @author Jeremy Long
|
||||||
*/
|
*/
|
||||||
public class Engine implements FileFilter {
|
public class Engine implements FileFilter, AutoCloseable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Engine} execution modes.
|
* {@link Engine} execution modes.
|
||||||
@@ -193,6 +193,11 @@ public class Engine implements FileFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the analyzers specified in the configuration file (or system
|
* Loads the analyzers specified in the configuration file (or system
|
||||||
* properties).
|
* properties).
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.owasp.dependencycheck;
|
package org.owasp.dependencycheck;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -26,21 +25,15 @@ public class EngineModeTest extends BaseTest {
|
|||||||
public TemporaryFolder tempDir = new TemporaryFolder();
|
public TemporaryFolder tempDir = new TemporaryFolder();
|
||||||
@Rule
|
@Rule
|
||||||
public TestName testName = new TestName();
|
public TestName testName = new TestName();
|
||||||
private Engine engine;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Settings.setString(Settings.KEYS.DATA_DIRECTORY, tempDir.newFolder().getAbsolutePath());
|
Settings.setString(Settings.KEYS.DATA_DIRECTORY, tempDir.newFolder().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
engine.cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvidenceCollectionMode() throws Exception {
|
public void testEvidenceCollectionMode() throws Exception {
|
||||||
engine = new Engine(Engine.Mode.EVIDENCE_COLLECTION);
|
try (Engine engine = new Engine(Engine.Mode.EVIDENCE_COLLECTION)) {
|
||||||
assertDatabase(false);
|
assertDatabase(false);
|
||||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
|
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
|
||||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||||
@@ -49,10 +42,11 @@ public class EngineModeTest extends BaseTest {
|
|||||||
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvidenceProcessingMode() throws Exception {
|
public void testEvidenceProcessingMode() throws Exception {
|
||||||
engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING);
|
try (Engine engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING)) {
|
||||||
assertDatabase(true);
|
assertDatabase(true);
|
||||||
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
|
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
|
||||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||||
@@ -61,15 +55,17 @@ public class EngineModeTest extends BaseTest {
|
|||||||
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
assertThat(engine.getAnalyzers(phase), is(nullValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStandaloneMode() throws Exception {
|
public void testStandaloneMode() throws Exception {
|
||||||
engine = new Engine(Engine.Mode.STANDALONE);
|
try (Engine engine = new Engine(Engine.Mode.STANDALONE)) {
|
||||||
assertDatabase(true);
|
assertDatabase(true);
|
||||||
for (AnalysisPhase phase : Engine.Mode.STANDALONE.phases) {
|
for (AnalysisPhase phase : Engine.Mode.STANDALONE.phases) {
|
||||||
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertDatabase(boolean exists) throws Exception {
|
private void assertDatabase(boolean exists) throws Exception {
|
||||||
Path directory = Settings.getDataDirectory().toPath();
|
Path directory = Settings.getDataDirectory().toPath();
|
||||||
|
|||||||
Reference in New Issue
Block a user