mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 17:19:30 +01:00
updated init logic
This commit is contained in:
@@ -71,7 +71,6 @@ public class HintAnalyzer extends AbstractAnalyzer {
|
|||||||
* The array of vendor duplicating hint rules.
|
* The array of vendor duplicating hint rules.
|
||||||
*/
|
*/
|
||||||
private VendorDuplicatingHintRule[] vendorHints;
|
private VendorDuplicatingHintRule[] vendorHints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the analyzer.
|
* The name of the analyzer.
|
||||||
*/
|
*/
|
||||||
@@ -221,21 +220,20 @@ public class HintAnalyzer extends AbstractAnalyzer {
|
|||||||
* @throws HintParseException thrown if the XML cannot be parsed.
|
* @throws HintParseException thrown if the XML cannot be parsed.
|
||||||
*/
|
*/
|
||||||
private void loadHintRules() throws HintParseException {
|
private void loadHintRules() throws HintParseException {
|
||||||
if (hints == null) {
|
List<HintRule> localHints;
|
||||||
final HintParser parser = new HintParser();
|
List<VendorDuplicatingHintRule> localVendorHints;
|
||||||
File file = null;
|
final HintParser parser = new HintParser();
|
||||||
try {
|
File file = null;
|
||||||
parser.parseHints(FileUtils.getResourceAsStream(HINT_RULE_FILE_NAME));
|
try {
|
||||||
hints = parser.getHintRules();
|
parser.parseHints(FileUtils.getResourceAsStream(HINT_RULE_FILE_NAME));
|
||||||
vendorHints = parser.getVendorDuplicatingHintRules();
|
} catch (SAXException ex) {
|
||||||
} catch (HintParseException | SAXException ex) {
|
throw new HintParseException("Error parsing hinits: " + ex.getMessage(), ex);
|
||||||
LOGGER.error("Unable to parse the base hint data file");
|
}
|
||||||
LOGGER.debug("Unable to parse the base hint data file", ex);
|
localHints = parser.getHintRules();
|
||||||
}
|
localVendorHints = parser.getVendorDuplicatingHintRules();
|
||||||
final String filePath = getSettings().getString(Settings.KEYS.HINTS_FILE);
|
|
||||||
if (filePath == null) {
|
final String filePath = getSettings().getString(Settings.KEYS.HINTS_FILE);
|
||||||
return;
|
if (filePath != null) {
|
||||||
}
|
|
||||||
boolean deleteTempFile = false;
|
boolean deleteTempFile = false;
|
||||||
try {
|
try {
|
||||||
final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
||||||
@@ -269,14 +267,12 @@ public class HintAnalyzer extends AbstractAnalyzer {
|
|||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
parser.parseHints(file);
|
parser.parseHints(file);
|
||||||
if (parser.getHintRules() != null && parser.getHintRules().length > 0) {
|
if (parser.getHintRules() != null && !parser.getHintRules().isEmpty()) {
|
||||||
hints = (HintRule[]) ArrayUtils.addAll(hints, parser.getHintRules());
|
localHints.addAll(parser.getHintRules());
|
||||||
}
|
}
|
||||||
if (parser.getVendorDuplicatingHintRules() != null && parser.getVendorDuplicatingHintRules().length > 0) {
|
if (parser.getVendorDuplicatingHintRules() != null && !parser.getVendorDuplicatingHintRules().isEmpty()) {
|
||||||
vendorHints = (VendorDuplicatingHintRule[]) ArrayUtils.addAll(vendorHints, parser.getVendorDuplicatingHintRules());
|
localVendorHints.addAll(parser.getVendorDuplicatingHintRules());
|
||||||
}
|
}
|
||||||
LOGGER.debug("{} hint rules were loaded.", hints.length);
|
|
||||||
LOGGER.debug("{} duplicating hint rules were loaded.", vendorHints.length);
|
|
||||||
} catch (HintParseException ex) {
|
} catch (HintParseException ex) {
|
||||||
LOGGER.warn("Unable to parse hint rule xml file '{}'", file.getPath());
|
LOGGER.warn("Unable to parse hint rule xml file '{}'", file.getPath());
|
||||||
LOGGER.warn(ex.getMessage());
|
LOGGER.warn(ex.getMessage());
|
||||||
@@ -296,5 +292,9 @@ public class HintAnalyzer extends AbstractAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hints = (HintRule[]) localHints.toArray(new HintRule[localHints.size()]);
|
||||||
|
vendorHints = (VendorDuplicatingHintRule[]) localVendorHints.toArray(new VendorDuplicatingHintRule[localVendorHints.size()]);
|
||||||
|
LOGGER.debug("{} hint rules were loaded.", hints.length);
|
||||||
|
LOGGER.debug("{} duplicating hint rules were loaded.", vendorHints.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ import org.xml.sax.XMLReader;
|
|||||||
*
|
*
|
||||||
* @author Jeremy Long
|
* @author Jeremy Long
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@NotThreadSafe
|
||||||
public class HintParser {
|
public class HintParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,11 +79,11 @@ public class HintParser {
|
|||||||
/**
|
/**
|
||||||
* The hint rules.
|
* The hint rules.
|
||||||
*/
|
*/
|
||||||
private HintRule[] hintRules;
|
private List<HintRule> hintRules;
|
||||||
/**
|
/**
|
||||||
* The vendor duplicating hint rules.
|
* The vendor duplicating hint rules.
|
||||||
*/
|
*/
|
||||||
private VendorDuplicatingHintRule[] vendorDuplicatingHintRules;
|
private List<VendorDuplicatingHintRule> vendorDuplicatingHintRules;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hint rules.
|
* Returns the hint rules.
|
||||||
@@ -91,7 +91,7 @@ public class HintParser {
|
|||||||
* @return the hint rules
|
* @return the hint rules
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
|
@SuppressWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
|
||||||
public HintRule[] getHintRules() {
|
public List<HintRule> getHintRules() {
|
||||||
return hintRules;
|
return hintRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ public class HintParser {
|
|||||||
*
|
*
|
||||||
* @return the vendor duplicating hint rules
|
* @return the vendor duplicating hint rules
|
||||||
*/
|
*/
|
||||||
public VendorDuplicatingHintRule[] getVendorDuplicatingHintRules() {
|
public List<VendorDuplicatingHintRule> getVendorDuplicatingHintRules() {
|
||||||
return vendorDuplicatingHintRules;
|
return vendorDuplicatingHintRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,10 +159,8 @@ public class HintParser {
|
|||||||
try (Reader reader = new InputStreamReader(inputStream, "UTF-8")) {
|
try (Reader reader = new InputStreamReader(inputStream, "UTF-8")) {
|
||||||
final InputSource in = new InputSource(reader);
|
final InputSource in = new InputSource(reader);
|
||||||
xmlReader.parse(in);
|
xmlReader.parse(in);
|
||||||
final List<HintRule> tmpRules = handler.getHintRules();
|
this.hintRules = handler.getHintRules();
|
||||||
this.hintRules = tmpRules.toArray(new HintRule[tmpRules.size()]);
|
this.vendorDuplicatingHintRules = handler.getVendorDuplicatingHintRules();
|
||||||
final List<VendorDuplicatingHintRule> tmpVDR = handler.getVendorDuplicatingHintRules();
|
|
||||||
this.vendorDuplicatingHintRules = tmpVDR.toArray(new VendorDuplicatingHintRule[tmpVDR.size()]);
|
|
||||||
}
|
}
|
||||||
} catch (ParserConfigurationException | FileNotFoundException ex) {
|
} catch (ParserConfigurationException | FileNotFoundException ex) {
|
||||||
LOGGER.debug("", ex);
|
LOGGER.debug("", ex);
|
||||||
|
|||||||
Reference in New Issue
Block a user