mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-20 08:14:44 +01:00
patch to resolve issue #137 - the output path can be a file name if the format is not ALL
Former-commit-id: 05c638b21f09842781e105259ff58819e4bd3e8c
This commit is contained in:
@@ -135,16 +135,29 @@ public final class CliParser {
|
|||||||
*/
|
*/
|
||||||
private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
|
private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
isValid = false;
|
||||||
final String msg = String.format("Invalid '%s' argument: null", argumentName);
|
final String msg = String.format("Invalid '%s' argument: null", argumentName);
|
||||||
throw new FileNotFoundException(msg);
|
throw new FileNotFoundException(msg);
|
||||||
} else if (!path.contains("*") && !path.contains("?")) {
|
} else if (!path.contains("*") && !path.contains("?")) {
|
||||||
final File f = new File(path);
|
final File f = new File(path);
|
||||||
if (!f.exists()) {
|
if ("o".equals(argumentName.substring(0, 1).toLowerCase()) && !"ALL".equals(this.getReportFormat().toUpperCase())) {
|
||||||
isValid = false;
|
final String checkPath = path.toLowerCase();
|
||||||
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
|
if (checkPath.endsWith(".html") || checkPath.endsWith(".xml") || checkPath.endsWith(".htm")) {
|
||||||
throw new FileNotFoundException(msg);
|
if (!f.getParentFile().isDirectory()) {
|
||||||
|
isValid = false;
|
||||||
|
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
|
||||||
|
throw new FileNotFoundException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!f.exists()) {
|
||||||
|
isValid = false;
|
||||||
|
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
|
||||||
|
throw new FileNotFoundException(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (path.startsWith("//") || path.startsWith("\\\\")) {
|
} else if (path.startsWith("//") || path.startsWith("\\\\")) {
|
||||||
|
isValid = false;
|
||||||
final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
|
final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
|
||||||
throw new FileNotFoundException(msg);
|
throw new FileNotFoundException(msg);
|
||||||
}
|
}
|
||||||
@@ -202,8 +215,9 @@ public final class CliParser {
|
|||||||
.withDescription("A property file to load.")
|
.withDescription("A property file to load.")
|
||||||
.create(ARGUMENT.PROP_SHORT);
|
.create(ARGUMENT.PROP_SHORT);
|
||||||
|
|
||||||
final Option out = OptionBuilder.withArgName("folder").hasArg().withLongOpt(ARGUMENT.OUT)
|
final Option out = OptionBuilder.withArgName("path").hasArg().withLongOpt(ARGUMENT.OUT)
|
||||||
.withDescription("The folder to write reports to. This defaults to the current directory.")
|
.withDescription("The folder to write reports to. This defaults to the current directory. "
|
||||||
|
+ "It is possible to set this to a specific file name if the format argument is not set to ALL.")
|
||||||
.create(ARGUMENT.OUT_SHORT);
|
.create(ARGUMENT.OUT_SHORT);
|
||||||
|
|
||||||
final Option outputFormat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ARGUMENT.OUTPUT_FORMAT)
|
final Option outputFormat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ARGUMENT.OUTPUT_FORMAT)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Short | Argument Name | Parameter | Description | Requir
|
|||||||
\-a | \-\-app | \<name\> | The name of the application being scanned. This is a required argument. | Required
|
\-a | \-\-app | \<name\> | The name of the application being scanned. This is a required argument. | Required
|
||||||
\-s | \-\-scan | \<path\> | The path to scan \- this option can be specified multiple times. It is also possible to specify Ant style paths (e.g. directory/**/*.jar). | Required
|
\-s | \-\-scan | \<path\> | The path to scan \- this option can be specified multiple times. It is also possible to specify Ant style paths (e.g. directory/**/*.jar). | Required
|
||||||
| \-\-exclude | \<pattern\> | The path patterns to exclude from the scan \- this option can be specified multiple times. This accepts Ant style path patterns (e.g. **/exclude/**) . | Optional
|
| \-\-exclude | \<pattern\> | The path patterns to exclude from the scan \- this option can be specified multiple times. This accepts Ant style path patterns (e.g. **/exclude/**) . | Optional
|
||||||
\-o | \-\-out | \<folder\> | The folder to write reports to. This defaults to the current directory. | Optional
|
\-o | \-\-out | \<path\> | The folder to write reports to. This defaults to the current directory. If the format is not set to ALL one could specify a specific file name. | Optional
|
||||||
\-f | \-\-format | \<format\> | The output format to write to (XML, HTML, VULN, ALL). The default is HTML. | Required
|
\-f | \-\-format | \<format\> | The output format to write to (XML, HTML, VULN, ALL). The default is HTML. | Required
|
||||||
\-l | \-\-log | \<file\> | The file path to write verbose logging information. | Optional
|
\-l | \-\-log | \<file\> | The file path to write verbose logging information. | Optional
|
||||||
\-n | \-\-noupdate | | Disables the automatic updating of the CPE data. | Optional
|
\-n | \-\-noupdate | | Disables the automatic updating of the CPE data. | Optional
|
||||||
|
|||||||
@@ -167,15 +167,28 @@ public class ReportGenerator {
|
|||||||
*/
|
*/
|
||||||
public void generateReports(String outputDir, String outputFormat) throws IOException, Exception {
|
public void generateReports(String outputDir, String outputFormat) throws IOException, Exception {
|
||||||
final String format = outputFormat.toUpperCase();
|
final String format = outputFormat.toUpperCase();
|
||||||
|
final String pathToCheck = outputDir.toLowerCase();
|
||||||
if (format.matches("^(XML|HTML|VULN|ALL)$")) {
|
if (format.matches("^(XML|HTML|VULN|ALL)$")) {
|
||||||
if ("XML".equalsIgnoreCase(format)) {
|
if ("XML".equalsIgnoreCase(format)) {
|
||||||
generateReports(outputDir, Format.XML);
|
if (pathToCheck.endsWith(".xml")) {
|
||||||
|
generateReport("XmlReport", outputDir);
|
||||||
|
} else {
|
||||||
|
generateReports(outputDir, Format.XML);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("HTML".equalsIgnoreCase(format)) {
|
if ("HTML".equalsIgnoreCase(format)) {
|
||||||
generateReports(outputDir, Format.HTML);
|
if (pathToCheck.endsWith(".html") || pathToCheck.endsWith(".htm")) {
|
||||||
|
generateReport("HtmlReport", outputDir);
|
||||||
|
} else {
|
||||||
|
generateReports(outputDir, Format.HTML);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("VULN".equalsIgnoreCase(format)) {
|
if ("VULN".equalsIgnoreCase(format)) {
|
||||||
generateReports(outputDir, Format.VULN);
|
if (pathToCheck.endsWith(".html") || pathToCheck.endsWith(".htm")) {
|
||||||
|
generateReport("VulnReport", outputDir);
|
||||||
|
} else {
|
||||||
|
generateReports(outputDir, Format.VULN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ("ALL".equalsIgnoreCase(format)) {
|
if ("ALL".equalsIgnoreCase(format)) {
|
||||||
generateReports(outputDir, Format.ALL);
|
generateReports(outputDir, Format.ALL);
|
||||||
|
|||||||
Reference in New Issue
Block a user