2222import com .fasterxml .jackson .core .JsonParser ;
2323import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
2424import org .apache .commons .io .FilenameUtils ;
25+ import org .apache .commons .lang3 .StringUtils ;
2526import org .apache .commons .text .WordUtils ;
2627import org .apache .velocity .VelocityContext ;
2728import org .apache .velocity .app .VelocityEngine ;
@@ -308,13 +309,14 @@ private VelocityEngine createVelocityEngine() {
308309 * Writes the dependency-check report to the given output location.
309310 *
310311 * @param outputLocation the path where the reports should be written
312+ * @param reportPrefixName the prefix of the report filename
311313 * @param format the format the report should be written in (a valid member
312314 * of {@link Format}) or even the path to a custom velocity template
313315 * (either fully qualified or the template name on the class path).
314316 * @throws ReportException is thrown if there is an error creating out the
315317 * reports
316318 */
317- public void write (String outputLocation , String format ) throws ReportException {
319+ public void write (String outputLocation , String reportPrefixName , String format ) throws ReportException {
318320 Format reportFormat = null ;
319321 try {
320322 reportFormat = Format .valueOf (format .toUpperCase ());
@@ -323,9 +325,9 @@ public void write(String outputLocation, String format) throws ReportException {
323325 }
324326
325327 if (reportFormat != null ) {
326- write (outputLocation , reportFormat );
328+ write (outputLocation , reportPrefixName , reportFormat );
327329 } else {
328- File out = getReportFile (outputLocation , null );
330+ File out = getReportFile (outputLocation , reportPrefixName , null );
329331 if (out .isDirectory ()) {
330332 out = new File (out , FilenameUtils .getBaseName (format ));
331333 LOGGER .warn ("Writing non-standard VSL output to a directory using template name as file name." );
@@ -340,20 +342,21 @@ public void write(String outputLocation, String format) throws ReportException {
340342 * Writes the dependency-check report(s).
341343 *
342344 * @param outputLocation the path where the reports should be written
345+ * @param reportPrefixName the prefix of the report filename
343346 * @param format the format the report should be written in (see
344347 * {@link Format})
345348 * @throws ReportException is thrown if there is an error creating out the
346349 * reports
347350 */
348- public void write (String outputLocation , Format format ) throws ReportException {
351+ public void write (String outputLocation , String reportPrefixName , Format format ) throws ReportException {
349352 if (format == Format .ALL ) {
350353 for (Format f : Format .values ()) {
351354 if (f != Format .ALL ) {
352- write (outputLocation , f );
355+ write (outputLocation , reportPrefixName , f );
353356 }
354357 }
355358 } else {
356- final File out = getReportFile (outputLocation , format );
359+ final File out = getReportFile (outputLocation , reportPrefixName , format );
357360 final String templateName = format .toString ().toLowerCase () + "Report" ;
358361 LOGGER .info ("Writing {} report to: {}" , format , out .getAbsolutePath ());
359362 processTemplate (templateName , out );
@@ -375,38 +378,39 @@ public void write(String outputLocation, Format format) throws ReportException {
375378 * will generate the correct name for the given output format.
376379 *
377380 * @param outputLocation the specified output location
381+ * @param reportPrefixName the prefix of the report filename
378382 * @param format the report format
379383 * @return the report File
380384 */
381- public static File getReportFile (String outputLocation , Format format ) {
385+ public static File getReportFile (String outputLocation , String reportPrefixName , Format format ) {
382386 File outFile = new File (outputLocation );
383387 if (outFile .getParentFile () == null ) {
384388 outFile = new File ("." , outputLocation );
385389 }
386390 final String pathToCheck = outputLocation .toLowerCase ();
387391 if (format == Format .XML && !pathToCheck .endsWith (".xml" )) {
388- return new File (outFile , "dependency-check -report.xml" );
392+ return new File (outFile , reportPrefixName + " -report.xml" );
389393 }
390394 if (format == Format .HTML && !pathToCheck .endsWith (".html" ) && !pathToCheck .endsWith (".htm" )) {
391- return new File (outFile , "dependency-check -report.html" );
395+ return new File (outFile , reportPrefixName + " -report.html" );
392396 }
393397 if (format == Format .JENKINS && !pathToCheck .endsWith (".html" ) && !pathToCheck .endsWith (".htm" )) {
394- return new File (outFile , "dependency-check -jenkins.html" );
398+ return new File (outFile , reportPrefixName + " -jenkins.html" );
395399 }
396400 if (format == Format .JSON && !pathToCheck .endsWith (".json" )) {
397- return new File (outFile , "dependency-check -report.json" );
401+ return new File (outFile , reportPrefixName + " -report.json" );
398402 }
399403 if (format == Format .CSV && !pathToCheck .endsWith (".csv" )) {
400- return new File (outFile , "dependency-check -report.csv" );
404+ return new File (outFile , reportPrefixName + " -report.csv" );
401405 }
402406 if (format == Format .JUNIT && !pathToCheck .endsWith (".xml" )) {
403- return new File (outFile , "dependency-check-junit .xml" );
407+ return new File (outFile , reportPrefixName + "-report .xml" );
404408 }
405409 if (format == Format .SARIF && !pathToCheck .endsWith (".sarif" )) {
406- return new File (outFile , "dependency-check -report.sarif" );
410+ return new File (outFile , reportPrefixName + " -report.sarif" );
407411 }
408412 if (format == Format .GITLAB && !pathToCheck .endsWith (".json" )) {
409- return new File (outFile , "dependency-check -gitlab.json" );
413+ return new File (outFile , reportPrefixName + " -gitlab.json" );
410414 }
411415 return outFile ;
412416 }
0 commit comments