2525import groovy.io.FileType
2626import org.apache.commons.cli.Option
2727
28- println " = IntellIJ IDEA Code Analysis Wrapper - v1.0 - @bentolor"
28+ println " = IntellIJ IDEA Code Analysis Wrapper - v1.1 - @bentolor"
2929
3030// Defaults
3131def resultDir = " target/inspection-results"
3232def acceptedLeves = [" [WARNING]" , " [ERROR]" ]
33- def skipFiles = []
33+ def skipResults = []
34+ def skipIssueFilesRegex = []
3435def ideaTimeout = 20 // broken - has no effect
3536
3637
@@ -47,11 +48,10 @@ if (opt.l) {
4748 acceptedLeves. clear()
4849 opt. ls. each { level -> acceptedLeves << " [" + level + " ]" }
4950}
50- // Skip files
51- if (opt. s) {
52- skipFiles. clear()
53- opt. ss. each { skipFile -> skipFiles << skipFile. replace(" .xml" , " " ) }
54- }
51+ // Skip result XML files
52+ if (opt. s) opt. ss. each { skipFile -> skipResults << skipFile. replace(" .xml" , " " ) }
53+ // Skip issues affecting given file name regex
54+ if (opt. sf) opt. sfs. each { skipRegex -> skipIssueFilesRegex << skipRegex }
5555// target directory
5656if (opt. t) resultDir = opt. t
5757// timeout
@@ -102,7 +102,7 @@ if (exitValue != 0) fail("IDEA Process returned with an unexpected return code o
102102//
103103// --- Now lets look on the results
104104//
105- analyzeResult(resultPath, acceptedLeves, skipFiles )
105+ analyzeResult(resultPath, acceptedLeves, skipResults, skipIssueFilesRegex )
106106
107107
108108//
@@ -125,13 +125,15 @@ void fail(String message) {
125125
126126
127127private OptionAccessor parseCli () {
128- def cliBuilder = new CliBuilder (usage : ' groovy ideainspect.groovy -i <IDEA_HOME> -p <PROFILEXML> -r <PROJDIR>' )
128+ def cliBuilder = new CliBuilder (usage : ' groovy ideainspect.groovy\n -i <IDEA_HOME> -p <PROFILEXML> -r <PROJDIR>' )
129129 cliBuilder. with {
130130 h argName : ' help' , longOpt : ' help' , ' Show usage information and quit'
131131 l argName : ' level' , longOpt : ' levels' , args : Option . UNLIMITED_VALUES , valueSeparator : ' ,' ,
132132 ' Levels to look for. Default: WARNING,ERROR'
133133 s argName : ' file' , longOpt : ' skip' , args : Option . UNLIMITED_VALUES , valueSeparator : ' ,' ,
134- ' Analysis result files to skip. For example "TodoComment" or "TodoComment.xml". \n Default: <empty>'
134+ ' Analysis result files to skip. For example "TodoComment" or "TodoComment.xml".'
135+ sf argName : ' regex' , longOpt : ' skipfile' , args : Option . UNLIMITED_VALUES , valueSeparator : ' ,' ,
136+ ' Ignore issues affecting source files matching given regex. Example ".*/generated/.*".'
135137 t argName : ' dir' , longOpt : ' resultdir' , args : 1 ,
136138 ' Target directory to place the IDEA inspection XML result files. Default: target/inspection-results'
137139 i argName : ' dir' , longOpt : ' ideahome' , args : 1 , required : true ,
@@ -163,13 +165,15 @@ private OptionAccessor parseCli() {
163165}
164166
165167
166- private analyzeResult (File resultPath , List<String > acceptedLeves , List skipFiles ) {
168+ private analyzeResult (File resultPath , List<String > acceptedLeves ,
169+ List skipResults , List skipIssueFilesRegex ) {
167170 println " "
168171 println " #"
169172 println " # Inspecting produced result files in $resultPath "
170173 println " #"
171- println " # Looking for: $acceptedLeves "
172- println " # Ignoring : $skipFiles "
174+ println " # Looking for levels : $acceptedLeves "
175+ println " # Ignoring result files : $skipResults "
176+ println " # Ignoring source files : $skipIssueFilesRegex "
173177
174178 def allGood = true ;
175179
@@ -186,15 +190,17 @@ private analyzeResult(File resultPath, List<String> acceptedLeves, List skipFile
186190 def fileIssues = []
187191 def xmlFileName = file. name
188192
189- if (skipFiles . contains(xmlFileName. replace(" .xml" , " " ))) {
193+ if (skipResults . contains(xmlFileName. replace(" .xml" , " " ))) {
190194 println " --- Skipping $xmlFileName "
191195 return
192196 }
193197
194198 xmlDocument. problem. each { problem ->
195199 String severity = problem. problem_class. @severity
196- if (acceptedLeves. contains(severity)) {
197- String affectedFile = problem. file. text()
200+ String affectedFile = problem. file. text()
201+ boolean fileShouldBeIgnored = false
202+ skipIssueFilesRegex. each { regex -> fileShouldBeIgnored = (fileShouldBeIgnored || affectedFile. matches(regex)) }
203+ if (acceptedLeves. contains(severity) && ! fileShouldBeIgnored) {
198204 String problemDesc = problem. description. text()
199205 String line = problem. line. text()
200206 fileIssues << " $severity $affectedFile :$line -- $problemDesc " ;
0 commit comments