| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck; |
| 19 | |
|
| 20 | |
import org.owasp.dependencycheck.analyzer.Analyzer; |
| 21 | |
import org.owasp.dependencycheck.analyzer.FileTypeAnalyzer; |
| 22 | |
import org.owasp.dependencycheck.analyzer.exception.AnalysisException; |
| 23 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 24 | |
import org.owasp.dependencycheck.utils.Settings; |
| 25 | |
import org.slf4j.Logger; |
| 26 | |
import org.slf4j.LoggerFactory; |
| 27 | |
|
| 28 | |
import java.util.List; |
| 29 | |
import java.util.concurrent.Callable; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 101 | class AnalysisTask implements Callable<Void> { |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | 1 | private static final Logger LOGGER = LoggerFactory.getLogger(AnalysisTask.class); |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
private final Analyzer analyzer; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
private final Dependency dependency; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
private final Engine engine; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
private final List<Throwable> exceptions; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | 107 | AnalysisTask(Analyzer analyzer, Dependency dependency, Engine engine, List<Throwable> exceptions) { |
| 71 | 107 | this.analyzer = analyzer; |
| 72 | 107 | this.dependency = dependency; |
| 73 | 107 | this.engine = engine; |
| 74 | 107 | this.exceptions = exceptions; |
| 75 | 107 | } |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
@Override |
| 84 | |
public Void call() { |
| 85 | 102 | Settings.initialize(); |
| 86 | |
|
| 87 | 102 | if (shouldAnalyze()) { |
| 88 | 39 | LOGGER.debug("Begin Analysis of '{}' ({})", dependency.getActualFilePath(), analyzer.getName()); |
| 89 | |
try { |
| 90 | 39 | analyzer.analyze(dependency, engine); |
| 91 | 0 | } catch (AnalysisException ex) { |
| 92 | 0 | LOGGER.warn("An error occurred while analyzing '{}' ({}).", dependency.getActualFilePath(), analyzer.getName()); |
| 93 | 0 | LOGGER.debug("", ex); |
| 94 | 0 | exceptions.add(ex); |
| 95 | 0 | } catch (Throwable ex) { |
| 96 | 0 | LOGGER.warn("An unexpected error occurred during analysis of '{}' ({}): {}", |
| 97 | 0 | dependency.getActualFilePath(), analyzer.getName(), ex.getMessage()); |
| 98 | 0 | LOGGER.debug("", ex); |
| 99 | 0 | exceptions.add(ex); |
| 100 | 39 | } |
| 101 | |
} |
| 102 | |
|
| 103 | 102 | return null; |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
boolean shouldAnalyze() { |
| 112 | 104 | if (analyzer instanceof FileTypeAnalyzer) { |
| 113 | 70 | final FileTypeAnalyzer fileTypeAnalyzer = (FileTypeAnalyzer) analyzer; |
| 114 | 69 | return fileTypeAnalyzer.accept(dependency.getActualFile()); |
| 115 | |
} |
| 116 | |
|
| 117 | 32 | return true; |
| 118 | |
} |
| 119 | |
} |