-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: data races on stdout and threads
Fix data race on stdout capture which was corrupting the responses for overlapping requests by using a capturing plugin. Fix data race on threads read and write which could result in missed cancellations and re-enable cancellation processing. Ensure that threads are always removed in the case of write response exception. Switch to jackson to enable efficient JSON encoding and decoding including raw embedding of CodeNarc result to avoid unnecessary processing. Split out HTTP filters to their own files. Use typed variables instead of def per linter recommendation. Add early test for missing base directory to avoid running linter unnecessarily. Fix parse failures for files which contain classes that only non-zero argument constructors. Add gzip compression to reduce size of network traffic to improve performance.
- Loading branch information
Showing
21 changed files
with
631 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.nvuillam | ||
|
||
import groovy.transform.CompileStatic | ||
import org.codenarc.plugin.AbstractCodeNarcPlugin | ||
import org.codenarc.report.AbstractReportWriter | ||
import org.codenarc.report.ReportWriter | ||
|
||
/** | ||
* Wraps reportWriters to capture stdout if needed. | ||
*/ | ||
@CompileStatic | ||
class CapturePlugin extends AbstractCodeNarcPlugin { | ||
|
||
/** | ||
* Process the list of ReportWriters. The List can be modified in-place. | ||
* ReportWriters within the list can be modified, or ReportWriters can | ||
* be added or deleted from the list. | ||
* | ||
* @param reportWriters - the initial List of ReportWrites to be used | ||
*/ | ||
@Override | ||
void processReports(List<ReportWriter> reportWriters) { | ||
reportWriters.eachWithIndex { reportWriter, idx -> | ||
if (reportWriter instanceof AbstractReportWriter) { // groovylint-disable-line Instanceof | ||
AbstractReportWriter abstractReportWriter = (AbstractReportWriter)reportWriter | ||
if (abstractReportWriter.isWriteToStandardOut()) { | ||
reportWriters[idx] = new CapturedReportWriter(abstractReportWriter) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.nvuillam | ||
|
||
import groovy.transform.CompileStatic | ||
import java.nio.charset.StandardCharsets | ||
import org.codenarc.AnalysisContext | ||
import org.codenarc.report.AbstractReportWriter | ||
import org.codenarc.report.ReportWriter | ||
import org.codenarc.results.Results | ||
|
||
/** | ||
* Wraps a ReportWriter to capture of the report which would | ||
* otherwise be written to stdout. | ||
*/ | ||
@CompileStatic | ||
class CapturedReportWriter implements ReportWriter { | ||
|
||
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream() | ||
private final AbstractReportWriter inner | ||
|
||
CapturedReportWriter(AbstractReportWriter inner) { | ||
this.inner = inner | ||
} | ||
|
||
/** | ||
* Returns the generated report as a UTF-8 string. | ||
* | ||
* @return the generated report. | ||
*/ | ||
String report() { | ||
return buffer.toString(StandardCharsets.UTF_8.name()) | ||
} | ||
|
||
/** | ||
* Returns the class name of the captured report writer. | ||
* | ||
* @returns the name of the captured class. | ||
*/ | ||
String capturedClassName() { | ||
return this.inner.class.name | ||
} | ||
|
||
/** | ||
* Write out a report for the specified analysis results | ||
* | ||
* @param analysisContext the AnalysisContext containing the analysis configuration information | ||
* @param results the analysis results | ||
*/ | ||
@Override | ||
void writeReport(AnalysisContext analysisContext, Results results) { | ||
assert analysisContext | ||
assert results | ||
|
||
// Capture the output instead of writing to stdout. | ||
OutputStreamWriter writer = new OutputStreamWriter(buffer) | ||
inner.writeReport(writer, analysisContext, results) | ||
writer.close() | ||
} | ||
|
||
} |
Oops, something went wrong.