Skip to content

Commit

Permalink
fix: data races on stdout and threads
Browse files Browse the repository at this point in the history
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
stevenh committed Dec 16, 2023
1 parent a03ca17 commit 7800918
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 385 deletions.
79 changes: 6 additions & 73 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,6 @@
"language": "en",
"version": "0.2",
"words": [
"Affero",
"Appender",
"Autofixable",
"Behl",
"Behl\u00fcl",
"Blablabla",
"CLASSNAME",
"CLASSPATH",
"CODENARC",
"COPYPASTE",
"Charsets",
"Cloneable",
"Codacy",
"Codenarc",
"Commandline",
"Creds",
"Dlogging",
"Dorg",
"ECONNREFUSED",
"ENTRYPOINT",
"ETIMEOUT",
"FILEIO",
"Finalizers",
"Fixrules",
"Fresources",
"Ftest",
"Gorm",
"Hartland",
"Hashtable",
"Inet",
"Instanceof",
"Intall",
"Javadoc",
"Jdbc",
"Jenkinsfile",
"Jenkinsfiles",
"Kopka",
"Korolik",
"Loopback",
"MYOTHERVAR",
"MYVAR",
"Metadatas",
"Microbundle",
"Misordered",
"NEWLINECLOSINGBRACE",
"Nuxt",
"OPTIONNAME",
"Objs",
"PARAMNAME",
"PROSELINT",
"Pawel",
"Println",
"Ruleset",
"Rulesets",
"SARIF",
"SEMGREP",
"Sarif",
"Serhii",
"Serv",
"Servlet",
"Slctn",
"Slurper",
"Sublicensing",
"TRIVY",
"Tablesort",
"U\u00e7ar",
"VARNAME",
"Vuillamy",
"WIPO",
"WORKDIR",
"Whitespaces",
"aestasit",
"Affero",
"agorapulse",
Expand Down Expand Up @@ -127,6 +56,7 @@
"COPYPASTE",
"Creds",
"cvfm",
"databind",
"decamelize",
"dfsg",
"Dlogging",
Expand All @@ -151,6 +81,7 @@
"failonerror",
"failoninfo",
"failonwarning",
"fasterxml",
"favicon",
"filechooser",
"FILEIO",
Expand Down Expand Up @@ -192,6 +123,7 @@
"groovyx",
"grooylintrc",
"hadolint",
"Hartland",
"hasha",
"Hashtable",
"hostedtoolcache",
Expand Down Expand Up @@ -232,6 +164,7 @@
"killserver",
"kisswebframework",
"Kopka",
"Korolik",
"lcov",
"lelama",
"lelamanul",
Expand Down Expand Up @@ -305,6 +238,7 @@
"Sarif",
"SARIF",
"SEMGREP",
"Serhii",
"Serv",
"serverhost",
"serverport",
Expand Down Expand Up @@ -367,7 +301,6 @@
"yallist",
"yessss",
"zalgo",
"zpars",
"\u00ecnfo"
"zpars"
]
}
5 changes: 3 additions & 2 deletions groovy/src/main/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class-Path: CodeNarc-3.4.0-alpha+3346775f.jar GMetrics-2.1.0.jar groov
commons-cli-1.4.jar groovy/lib/groovy-3.0.9.jar groovy/lib/groovy-ant
-3.0.9.jar groovy/lib/groovy-cli-commons-3.0.9.jar groovy/lib/groovy-
dateutil-3.0.9.jar groovy/lib/groovy-json-3.0.9.jar groovy/lib/groovy
-templates-3.0.9.jar groovy/lib/groovy-xml-3.0.9.jar logback-classic-
1.4.14.jar logback-core-1.4.14.jar slf4j-api-2.0.9.jar
-templates-3.0.9.jar groovy/lib/groovy-xml-3.0.9.jar jackson-annotati
ons-2.16.0.jar jackson-core-2.16.0.jar jackson-databind-2.16.0.jar lo
gback-classic-1.4.14.jar logback-core-1.4.14.jar slf4j-api-2.0.9.jar
Created-By: 1.8.0_144 (Oracle Corporation)
Main-Class: com.nvuillam.CodeNarcServer
33 changes: 33 additions & 0 deletions groovy/src/main/com/nvuillam/CapturePlugin.groovy
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)
}
}
}
}

}
59 changes: 59 additions & 0 deletions groovy/src/main/com/nvuillam/CapturedReportWriter.groovy
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()
}

}
Loading

0 comments on commit 7800918

Please sign in to comment.