mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 01:29:43 +01:00
Refactored the test run of GrokAssembly to avoid double-closing
Former-commit-id: edc5ae7da2cb52900f9eed1cd133c843f161a9aa
This commit is contained in:
@@ -168,32 +168,13 @@ public class AssemblyAnalyzer extends AbstractAnalyzer {
|
|||||||
while ((bread = is.read(buff)) >= 0) {
|
while ((bread = is.read(buff)) >= 0) {
|
||||||
fos.write(buff, 0, bread);
|
fos.write(buff, 0, bread);
|
||||||
}
|
}
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
fos = null;
|
|
||||||
grokAssemblyExe = tempFile;
|
grokAssemblyExe = tempFile;
|
||||||
// Set the temp file to get deleted when we're done
|
// Set the temp file to get deleted when we're done
|
||||||
grokAssemblyExe.deleteOnExit();
|
grokAssemblyExe.deleteOnExit();
|
||||||
LOG.log(Level.INFO, "Extracted GrokAssembly.exe to {0}", grokAssemblyExe.getPath());
|
LOG.log(Level.INFO, "Extracted GrokAssembly.exe to {0}", grokAssemblyExe.getPath());
|
||||||
|
} catch (IOException ioe) {
|
||||||
// Now, need to see if GrokAssembly actually runs from this location.
|
LOG.log(Level.WARNING, "Could not extract GrokAssembly.exe: {0}", ioe.getMessage());
|
||||||
final List<String> args = buildArgumentList();
|
throw new AnalysisException("Could not extract GrokAssembly.exe", ioe);
|
||||||
try {
|
|
||||||
final Process p = new ProcessBuilder(args).start();
|
|
||||||
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(p.getInputStream());
|
|
||||||
final XPath xpath = XPathFactory.newInstance().newXPath();
|
|
||||||
final String error = xpath.evaluate("/assembly/error", doc);
|
|
||||||
if (p.exitValue() != 1 || error == null || "".equals(error)) {
|
|
||||||
LOG.warning("GrokAssembly.exe is not working properly");
|
|
||||||
grokAssemblyExe = null;
|
|
||||||
throw new AnalysisException("Could not execute GrokAssembly");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.warning("Could not execute GrokAssembly " + e.getMessage());
|
|
||||||
throw new AnalysisException("Could not execute GrokAssembly", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
||||||
} finally {
|
} finally {
|
||||||
if (fos != null) {
|
if (fos != null) {
|
||||||
try {
|
try {
|
||||||
@@ -210,6 +191,25 @@ public class AssemblyAnalyzer extends AbstractAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now, need to see if GrokAssembly actually runs from this location.
|
||||||
|
final List<String> args = buildArgumentList();
|
||||||
|
try {
|
||||||
|
final Process p = new ProcessBuilder(args).start();
|
||||||
|
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(p.getInputStream());
|
||||||
|
final XPath xpath = XPathFactory.newInstance().newXPath();
|
||||||
|
final String error = xpath.evaluate("/assembly/error", doc);
|
||||||
|
if (p.exitValue() != 1 || error == null || "".equals(error)) {
|
||||||
|
LOG.warning("GrokAssembly.exe is not working properly");
|
||||||
|
grokAssemblyExe = null;
|
||||||
|
throw new AnalysisException("Could not execute GrokAssembly");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warning("Could not execute GrokAssembly " + e.getMessage());
|
||||||
|
throw new AnalysisException("Could not execute GrokAssembly", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user