|
34 | 34 | import java.util.Map;
|
35 | 35 |
|
36 | 36 | import com.puppycrawl.tools.checkstyle.DefaultLogger;
|
| 37 | +import com.puppycrawl.tools.checkstyle.SarifLogger; |
37 | 38 | import com.puppycrawl.tools.checkstyle.XMLLogger;
|
38 | 39 | import com.puppycrawl.tools.checkstyle.api.AuditListener;
|
39 | 40 | import com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions;
|
@@ -92,7 +93,7 @@ public class CheckstyleViolationCheckMojo extends AbstractMojo {
|
92 | 93 |
|
93 | 94 | /**
|
94 | 95 | * Specifies the format of the output to be used when writing to the output
|
95 |
| - * file. Valid values are "<code>plain</code>" and "<code>xml</code>". |
| 96 | + * file. Valid values are "<code>plain</code>", "<code>sarif</code>" and "<code>xml</code>". |
96 | 97 | */
|
97 | 98 | @Parameter(property = "checkstyle.output.format", defaultValue = "xml")
|
98 | 99 | private String outputFileFormat;
|
@@ -802,6 +803,21 @@ private AuditListener getListener() throws MojoFailureException, MojoExecutionEx
|
802 | 803 | } catch (IOException e) {
|
803 | 804 | throw new MojoExecutionException("Unable to create temporary file", e);
|
804 | 805 | }
|
| 806 | + } else if ("sarif".equals(outputFileFormat)) { |
| 807 | + try { |
| 808 | + // Write a sarif output file to the standard output file, |
| 809 | + // and write an XML output file to the temp directory that can be used to count violations |
| 810 | + outputXmlFile = |
| 811 | + Files.createTempFile("checkstyle-result", ".xml").toFile(); |
| 812 | + outputXmlFile.deleteOnExit(); |
| 813 | + OutputStream xmlOut = getOutputStream(outputXmlFile); |
| 814 | + CompositeAuditListener compoundListener = new CompositeAuditListener(); |
| 815 | + compoundListener.addListener(new XMLLogger(xmlOut, OutputStreamOptions.CLOSE)); |
| 816 | + compoundListener.addListener(new SarifLogger(out, OutputStreamOptions.CLOSE)); |
| 817 | + listener = compoundListener; |
| 818 | + } catch (IOException e) { |
| 819 | + throw new MojoExecutionException("Unable to create temporary file", e); |
| 820 | + } |
805 | 821 | } else {
|
806 | 822 | throw new MojoFailureException(
|
807 | 823 | "Invalid output file format: (" + outputFileFormat + "). Must be 'plain' or 'xml'.");
|
|
0 commit comments