Autocloseable

This commit is contained in:
Mark Rekveld
2017-07-10 16:58:08 +02:00
parent 1fe24a2e0c
commit e6ec9d9aa3
2 changed files with 27 additions and 26 deletions

View File

@@ -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).

View File

@@ -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,48 +25,45 @@ 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()));
} }
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) { for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
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()));
} }
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) { for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
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()));
}
} }
} }