| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck.maven; |
| 19 | |
|
| 20 | |
import java.util.logging.Logger; |
| 21 | |
import org.apache.maven.project.MavenProject; |
| 22 | |
import org.owasp.dependencycheck.analyzer.Analyzer; |
| 23 | |
import org.owasp.dependencycheck.analyzer.CPEAnalyzer; |
| 24 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; |
| 25 | |
import org.owasp.dependencycheck.utils.Settings; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public class Engine extends org.owasp.dependencycheck.Engine { |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | private static final transient Logger LOGGER = Logger.getLogger(Engine.class.getName()); |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
private static final String CPE_ANALYZER_KEY = "dependency-check-CPEAnalyzer"; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
private MavenProject currentProject; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | 0 | public Engine(MavenProject project) throws DatabaseException { |
| 55 | 0 | this.currentProject = project; |
| 56 | 0 | final MavenProject parent = getRootParent(); |
| 57 | 0 | if (parent != null && parent.getContextValue("dependency-check-data-was-updated") != null) { |
| 58 | 0 | System.setProperty(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE.toString()); |
| 59 | |
} |
| 60 | 0 | initializeEngine(); |
| 61 | 0 | if (parent != null) { |
| 62 | 0 | parent.setContextValue("dependency-check-data-was-updated", Boolean.valueOf(true)); |
| 63 | |
} |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 0 | private Engine() throws DatabaseException { |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
@Override |
| 82 | |
protected Analyzer initializeAnalyzer(Analyzer analyzer) { |
| 83 | 0 | if ((analyzer instanceof CPEAnalyzer)) { |
| 84 | 0 | CPEAnalyzer cpe = getPreviouslyLoadedAnalyzer(); |
| 85 | 0 | if (cpe != null) { |
| 86 | 0 | return cpe; |
| 87 | |
} |
| 88 | 0 | cpe = (CPEAnalyzer) super.initializeAnalyzer(analyzer); |
| 89 | 0 | storeCPEAnalyzer(cpe); |
| 90 | |
} |
| 91 | 0 | return super.initializeAnalyzer(analyzer); |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
@Override |
| 100 | |
protected void closeAnalyzer(Analyzer analyzer) { |
| 101 | 0 | if ((analyzer instanceof CPEAnalyzer)) { |
| 102 | 0 | if (getPreviouslyLoadedAnalyzer() == null) { |
| 103 | 0 | super.closeAnalyzer(analyzer); |
| 104 | |
} |
| 105 | |
} else { |
| 106 | 0 | super.closeAnalyzer(analyzer); |
| 107 | |
} |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
public void cleanupFinal() { |
| 114 | 0 | final CPEAnalyzer cpe = getPreviouslyLoadedAnalyzer(); |
| 115 | 0 | if (cpe != null) { |
| 116 | 0 | cpe.close(); |
| 117 | |
} |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
private CPEAnalyzer getPreviouslyLoadedAnalyzer() { |
| 126 | 0 | CPEAnalyzer cpe = null; |
| 127 | 0 | final MavenProject project = getRootParent(); |
| 128 | 0 | if (project != null) { |
| 129 | 0 | cpe = (CPEAnalyzer) project.getContextValue(CPE_ANALYZER_KEY); |
| 130 | |
} |
| 131 | 0 | return cpe; |
| 132 | |
} |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
private void storeCPEAnalyzer(CPEAnalyzer cpe) { |
| 140 | 0 | final MavenProject p = getRootParent(); |
| 141 | 0 | if (p != null) { |
| 142 | 0 | p.setContextValue(CPE_ANALYZER_KEY, cpe); |
| 143 | |
} |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
private MavenProject getRootParent() { |
| 152 | 0 | if (this.currentProject == null) { |
| 153 | 0 | return null; |
| 154 | |
} |
| 155 | 0 | MavenProject p = this.currentProject; |
| 156 | 0 | while (p.getParent() != null) { |
| 157 | 0 | p = p.getParent(); |
| 158 | |
} |
| 159 | 0 | return p; |
| 160 | |
} |
| 161 | |
} |