Skip to content

Commit 5f798ec

Browse files
committed
Maven configuration to run preview sonar run in interactive use shell and verify is there are no new errors
1 parent 5845c34 commit 5f798ec

File tree

2 files changed

+152
-1
lines changed

2 files changed

+152
-1
lines changed

pom.xml

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
<properties>
2323
<netbeans.hint.license>apache20</netbeans.hint.license>
2424
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
<sonar.working.directory>${project.build.directory}/sonar</sonar.working.directory>
26+
<sonar.host.url>https://sonar.wavesoftware.pl</sonar.host.url>
27+
<sonar.analysis.mode>preview</sonar.analysis.mode>
28+
<sonar.issuesReport.console.enable>true</sonar.issuesReport.console.enable>
29+
<sonar.issuesReport.html.enable>true</sonar.issuesReport.html.enable>
30+
<sonar.report.export.path>issues.json</sonar.report.export.path>
2531
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
2632
<java.source.version>6</java.source.version>
2733
<maven.compiler.source>1.${java.source.version}</maven.compiler.source>
@@ -100,7 +106,48 @@
100106
</execution>
101107
<execution>
102108
<id>jacoco-site</id>
103-
<phase>verify</phase>
109+
<phase>post-integration-test</phase>
110+
<goals>
111+
<goal>report</goal>
112+
<goal>report-integration</goal>
113+
</goals>
114+
</execution>
115+
</executions>
116+
<configuration>
117+
<includes>
118+
<include>pl/wavesoftware/**</include>
119+
</includes>
120+
</configuration>
121+
</plugin>
122+
</plugins>
123+
</build>
124+
</profile>
125+
126+
<profile>
127+
<id>sonar</id>
128+
<activation>
129+
<property>
130+
<!-- tries to determine is interactive user session -->
131+
<name>env.GDMSESSION</name>
132+
</property>
133+
</activation>
134+
<build>
135+
<plugins>
136+
<plugin>
137+
<groupId>org.jacoco</groupId>
138+
<artifactId>jacoco-maven-plugin</artifactId>
139+
<version>0.7.5.201505241946</version>
140+
<executions>
141+
<execution>
142+
<id>jacoco-initialize</id>
143+
<goals>
144+
<goal>prepare-agent</goal>
145+
<goal>prepare-agent-integration</goal>
146+
</goals>
147+
</execution>
148+
<execution>
149+
<id>jacoco-site</id>
150+
<phase>post-integration-test</phase>
104151
<goals>
105152
<goal>report</goal>
106153
<goal>report-integration</goal>
@@ -113,6 +160,48 @@
113160
</includes>
114161
</configuration>
115162
</plugin>
163+
164+
<plugin>
165+
<groupId>org.codehaus.mojo</groupId>
166+
<artifactId>sonar-maven-plugin</artifactId>
167+
<executions>
168+
<execution>
169+
<id>default</id>
170+
<phase>post-integration-test</phase>
171+
<goals>
172+
<goal>sonar</goal>
173+
</goals>
174+
</execution>
175+
</executions>
176+
</plugin>
177+
178+
<plugin>
179+
<groupId>org.codehaus.gmaven</groupId>
180+
<artifactId>groovy-maven-plugin</artifactId>
181+
<version>2.0</version>
182+
<dependencies>
183+
<dependency>
184+
<groupId>org.codehaus.groovy</groupId>
185+
<artifactId>groovy-all</artifactId>
186+
<version>2.0.6</version>
187+
</dependency>
188+
</dependencies>
189+
<configuration>
190+
<defaults>
191+
<sonar.issues.file>${sonar.working.directory}/${sonar.report.export.path}</sonar.issues.file>
192+
</defaults>
193+
<source>${project.basedir}/src/test/groovy/verify-sonar-issues.groovy</source>
194+
</configuration>
195+
<executions>
196+
<execution>
197+
<id>verify-sonar-issues</id>
198+
<phase>verify</phase>
199+
<goals>
200+
<goal>execute</goal>
201+
</goals>
202+
</execution>
203+
</executions>
204+
</plugin>
116205
</plugins>
117206
</build>
118207
</profile>
@@ -198,6 +287,16 @@
198287
</executions>
199288
</plugin>
200289
</plugins>
290+
291+
<pluginManagement>
292+
<plugins>
293+
<plugin>
294+
<groupId>org.codehaus.mojo</groupId>
295+
<artifactId>sonar-maven-plugin</artifactId>
296+
<version>2.7.1</version>
297+
</plugin>
298+
</plugins>
299+
</pluginManagement>
201300
</build>
202301

203302
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import groovy.json.JsonSlurper
2+
3+
propertyName = 'sonar.issues.file'
4+
filepath = new File(properties.getAt(propertyName))
5+
log.info('Sonar Issues file: ' + filepath)
6+
7+
def slurper = new JsonSlurper()
8+
def contents = filepath.getText('UTF-8')
9+
def json = slurper.parseText(contents)
10+
11+
def major = 0
12+
def critical = 0
13+
def blocker = 0
14+
def report = []
15+
16+
json.issues.each {
17+
issue = it
18+
if (issue.isNew && issue.status == "OPEN") {
19+
switch (issue.severity) {
20+
case 'MAJOR':
21+
major++
22+
report << issue
23+
break
24+
case 'CRITICAL':
25+
critical++
26+
report << issue
27+
break
28+
case 'BLOCKER':
29+
blocker++
30+
report << issue
31+
break
32+
}
33+
}
34+
}
35+
red = major + critical + blocker
36+
if (red > 0) {
37+
msg = 'There are ' + red + ' new issue(s) that have severity of MAJOR or above (BLOCKER or CRITICAL)!'
38+
log.error(msg)
39+
log.error('')
40+
if (blocker) {
41+
log.error('Blocker: +' + blocker)
42+
}
43+
if (critical) {
44+
log.error('Critical: +' + critical)
45+
}
46+
if (major) {
47+
log.error('Major: +' + major)
48+
}
49+
fail(msg)
50+
} else {
51+
log.info('No new issues have been found')
52+
}

0 commit comments

Comments
 (0)