From af4defddbfbf923429e4eb340dc16576bb7a7e41 Mon Sep 17 00:00:00 2001 From: Filipe Esperandio Date: Fri, 15 Sep 2017 14:15:22 -0300 Subject: [PATCH 1/2] Keep stdout/stderr untouched, interception turned out to be more problematic --- pmd.groovy | 38 ++++++------------------------ test.groovy | 8 ------- test/config.problematic_rules.json | 12 ---------- test/problematic_rules.xml | 11 --------- 4 files changed, 7 insertions(+), 62 deletions(-) delete mode 100644 test/config.problematic_rules.json delete mode 100644 test/problematic_rules.xml diff --git a/pmd.groovy b/pmd.groovy index b4da8e1..8934af5 100755 --- a/pmd.groovy +++ b/pmd.groovy @@ -3,7 +3,6 @@ import groovy.json.JsonSlurper import groovy.util.FileNameFinder - class Config { def args def appContext @@ -79,13 +78,12 @@ class Config { } } -def isValid(json) { - try { - new JsonSlurper().parseText(json) - return true - } catch(Exception e) { - return false - } +def execute(command) { + ProcessBuilder builder = new ProcessBuilder(command.split(' ')) + Process process = builder.start() + process.consumeProcessOutput(System.out, System.err) + process.waitFor() + System.exit(process.exitValue()) } /* ********** MAIN ********** */ @@ -95,26 +93,4 @@ if (config.noFiles()) { System.exit(0) } -def command = "/usr/src/app/lib/pmd/bin/run.sh pmd -filelist ${config.filesListPath()} -f codeclimate -R ${config.ruleSet()} -failOnViolation false" - -ProcessBuilder builder = new ProcessBuilder(command.split(' ')) -Process process = builder.start() - -InputStream stdout = process.getInputStream() -BufferedReader reader = new BufferedReader(new InputStreamReader(stdout)) -while ((line = reader.readLine()) != null) { - if(isValid(line)) { - System.out.println(line) - } else { - System.err.println(line) - System.exit(-1) - } -} - -process.waitForProcessOutput() - -if (process.exitValue() != 0) { - System.exit(-1) -} - -System.exit(0) +execute("/usr/src/app/lib/pmd/bin/run.sh pmd -filelist ${config.filesListPath()} -f codeclimate -R ${config.ruleSet()} -failOnViolation false") diff --git a/test.groovy b/test.groovy index ffba1b2..98105f1 100755 --- a/test.groovy +++ b/test.groovy @@ -40,13 +40,6 @@ def abortOnBadConfig() { assert proc.exitValue() != 0 } -def handleBadOutput() { - def (proc, out, err) = execute("/usr/src/app/pmd.groovy --codeFolder=/code/test --configFile=/code/test/config.problematic_rules.json") - - assert !err.toString().isEmpty() - assert proc.exitValue() != 0 -} - def engineCheckList() { def engine = new JsonSlurper().parse(new File("engine.json"), "UTF-8") assert engine.name @@ -81,4 +74,3 @@ dockerfileCheckList() sanityCheck() checkConfigBackwardCompatibility() abortOnBadConfig() -handleBadOutput() diff --git a/test/config.problematic_rules.json b/test/config.problematic_rules.json deleted file mode 100644 index 2438926..0000000 --- a/test/config.problematic_rules.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "enabled": true, - "channel": "beta", - "config": { - "file": "test/problematic_rules.xml", - }, - "include_paths": [ - "Main.java" - ] -} - - diff --git a/test/problematic_rules.xml b/test/problematic_rules.xml deleted file mode 100644 index 8afdc2c..0000000 --- a/test/problematic_rules.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - Every Java Rule in PMD - - - - From 215ee33ff531227cc0113e5156f06da84db8241f Mon Sep 17 00:00:00 2001 From: Filipe Esperandio Date: Fri, 15 Sep 2017 14:17:53 -0300 Subject: [PATCH 2/2] Set a reasonable heap size improved behaviour in bigger repos --- pmd.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.groovy b/pmd.groovy index 8934af5..b6b9f49 100755 --- a/pmd.groovy +++ b/pmd.groovy @@ -80,6 +80,7 @@ class Config { def execute(command) { ProcessBuilder builder = new ProcessBuilder(command.split(' ')) + builder.environment().put("HEAPSIZE", "256m") Process process = builder.start() process.consumeProcessOutput(System.out, System.err) process.waitFor()