mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 17:41:28 +01:00
filter out version from jar filename for name
This commit is contained in:
@@ -93,26 +93,27 @@ public class FileNameAnalyzer extends AbstractAnalyzer implements Analyzer {
|
|||||||
|
|
||||||
//add version evidence
|
//add version evidence
|
||||||
final DependencyVersion version = DependencyVersionUtil.parseVersion(fileName);
|
final DependencyVersion version = DependencyVersionUtil.parseVersion(fileName);
|
||||||
|
final String packageName = DependencyVersionUtil.parsePreVersion(fileName);
|
||||||
if (version != null) {
|
if (version != null) {
|
||||||
// If the version number is just a number like 2 or 23, reduce the confidence
|
// If the version number is just a number like 2 or 23, reduce the confidence
|
||||||
// a shade. This should hopefully correct for cases like log4j.jar or
|
// a shade. This should hopefully correct for cases like log4j.jar or
|
||||||
// struts2-core.jar
|
// struts2-core.jar
|
||||||
if (version.getVersionParts() == null || version.getVersionParts().size() < 2) {
|
if (version.getVersionParts() == null || version.getVersionParts().size() < 2) {
|
||||||
dependency.getVersionEvidence().addEvidence("file", "name",
|
dependency.getVersionEvidence().addEvidence("file", "version",
|
||||||
version.toString(), Confidence.MEDIUM);
|
version.toString(), Confidence.MEDIUM);
|
||||||
} else {
|
} else {
|
||||||
dependency.getVersionEvidence().addEvidence("file", "version",
|
dependency.getVersionEvidence().addEvidence("file", "version",
|
||||||
version.toString(), Confidence.HIGHEST);
|
version.toString(), Confidence.HIGHEST);
|
||||||
}
|
}
|
||||||
dependency.getVersionEvidence().addEvidence("file", "name",
|
dependency.getVersionEvidence().addEvidence("file", "name",
|
||||||
fileName, Confidence.MEDIUM);
|
packageName, Confidence.MEDIUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IGNORED_FILES.accept(f)) {
|
if (!IGNORED_FILES.accept(f)) {
|
||||||
dependency.getProductEvidence().addEvidence("file", "name",
|
dependency.getProductEvidence().addEvidence("file", "name",
|
||||||
fileName, Confidence.HIGH);
|
packageName, Confidence.HIGH);
|
||||||
dependency.getVendorEvidence().addEvidence("file", "name",
|
dependency.getVendorEvidence().addEvidence("file", "name",
|
||||||
fileName, Confidence.HIGH);
|
packageName, Confidence.HIGH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ public final class DependencyVersionUtil {
|
|||||||
*/
|
*/
|
||||||
private static final Pattern RX_SINGLE_VERSION = Pattern.compile("\\d+(\\.?([_-](release|beta|alpha)|[a-zA-Z_-]{1,3}\\d{1,8}))?");
|
private static final Pattern RX_SINGLE_VERSION = Pattern.compile("\\d+(\\.?([_-](release|beta|alpha)|[a-zA-Z_-]{1,3}\\d{1,8}))?");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular expression to extract the part before the version numbers if there are any based on RX_VERSION. In most cases, this part represents a more accurate name.
|
||||||
|
*/
|
||||||
|
private static final Pattern RX_PRE_VERSION = Pattern.compile("^(.+)[_-](\\d+\\.\\d{1,6})+");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private constructor for utility class.
|
* Private constructor for utility class.
|
||||||
*/
|
*/
|
||||||
@@ -95,4 +100,27 @@ public final class DependencyVersionUtil {
|
|||||||
}
|
}
|
||||||
return new DependencyVersion(version);
|
return new DependencyVersion(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* A utility class to extract the part before version numbers from file names (or other strings containing version numbers.
|
||||||
|
* In most cases, this part represents a more accurate name than the full file name.</p>
|
||||||
|
* <pre>
|
||||||
|
* Example:
|
||||||
|
* Give the file name: library-name-1.4.1r2-release.jar
|
||||||
|
* This function would return: library-name</pre>
|
||||||
|
*
|
||||||
|
* @param text the text being analyzed
|
||||||
|
* @return the part before the version numbers if any, otherwise return the text itself.
|
||||||
|
*/
|
||||||
|
public static String parsePreVersion(String text) {
|
||||||
|
if(parseVersion(text) == null)
|
||||||
|
return text;
|
||||||
|
|
||||||
|
Matcher matcher = RX_PRE_VERSION.matcher(text);
|
||||||
|
if (matcher.find()) {
|
||||||
|
return matcher.group(1);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user