Skip to content

Commit 2dbc8ab

Browse files
committed
release 1.7.0
1. compatibility with SonarQube 9.X version 2. fixed import java issue failed issue
1 parent d5eda1d commit 2dbc8ab

File tree

10 files changed

+163
-34
lines changed

10 files changed

+163
-34
lines changed

commons/pom.xml

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<artifactId>sonar-swift</artifactId>
2626
<groupId>com.github.sonar-next</groupId>
27-
<version>1.6.1</version>
27+
<version>1.7.0</version>
2828
</parent>
2929
<modelVersion>4.0.0</modelVersion>
3030

@@ -55,11 +55,20 @@
5555
<artifactId>junit</artifactId>
5656
<scope>compile</scope>
5757
</dependency>
58+
59+
<dependency>
60+
<groupId>org.mockito</groupId>
61+
<artifactId>mockito-core</artifactId>
62+
<scope>compile</scope>
63+
<version>4.2.0</version>
64+
</dependency>
5865
<dependency>
5966
<groupId>org.mockito</groupId>
60-
<artifactId>mockito-all</artifactId>
67+
<artifactId>mockito-inline</artifactId>
6168
<scope>compile</scope>
69+
<version>4.2.0</version>
6270
</dependency>
71+
6372
<dependency>
6473
<groupId>org.assertj</groupId>
6574
<artifactId>assertj-core</artifactId>

javalang/pom.xml

+17-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>sonar-swift</artifactId>
77
<groupId>com.github.sonar-next</groupId>
8-
<version>1.6.1</version>
8+
<version>1.7.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -14,6 +14,7 @@
1414
<properties>
1515
<maven.compiler.source>8</maven.compiler.source>
1616
<maven.compiler.target>8</maven.compiler.target>
17+
<junit.jupiter.version>5.8.2</junit.jupiter.version>
1718
</properties>
1819

1920

@@ -22,7 +23,7 @@
2223
<dependency>
2324
<groupId>com.github.sonar-next</groupId>
2425
<artifactId>commons</artifactId>
25-
<version>1.6.1</version>
26+
<version>1.7.0</version>
2627
</dependency>
2728

2829
<dependency>
@@ -61,16 +62,6 @@
6162
<groupId>com.googlecode.json-simple</groupId>
6263
<artifactId>json-simple</artifactId>
6364
</dependency>
64-
<dependency>
65-
<groupId>junit</groupId>
66-
<artifactId>junit</artifactId>
67-
<scope>compile</scope>
68-
</dependency>
69-
<dependency>
70-
<groupId>org.mockito</groupId>
71-
<artifactId>mockito-all</artifactId>
72-
<scope>compile</scope>
73-
</dependency>
7465
<dependency>
7566
<groupId>org.assertj</groupId>
7667
<artifactId>assertj-core</artifactId>
@@ -112,6 +103,20 @@
112103
</exclusions>
113104
</dependency>
114105

106+
<dependency>
107+
<groupId>org.junit.jupiter</groupId>
108+
<artifactId>junit-jupiter-engine</artifactId>
109+
<version>${junit.jupiter.version}</version>
110+
<scope>test</scope>
111+
</dependency>
112+
113+
<dependency>
114+
<groupId>org.junit.jupiter</groupId>
115+
<artifactId>junit-jupiter-api</artifactId>
116+
<version>${junit.jupiter.version}</version>
117+
<scope>test</scope>
118+
</dependency>
119+
115120
</dependencies>
116121

117122
</project>

javalang/src/main/java/com/github/sonar/next/sonarqube/java/issues/infer/InferReportParser.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void parseReport(File jsonFile) {
5656
}
5757
}
5858

59-
private void recordIssue(final JSONObject jsonObject) {
59+
protected void recordIssue(final JSONObject jsonObject) {
6060

6161
String filePath = (String) jsonObject.get("file");
6262
logger.debug("record issue for java, path = {}", filePath);
@@ -81,12 +81,13 @@ private void recordIssue(final JSONObject jsonObject) {
8181
}
8282

8383

84-
File file = new File( filePath );
8584
FilePredicates predicates = context.fileSystem().predicates();
86-
FilePredicate fp = predicates.or( predicates.hasAbsolutePath( filePath ), predicates.hasRelativePath( filePath ) );
85+
FilePredicate fp = predicates.or( predicates.hasAbsolutePath( filePath ),
86+
predicates.hasRelativePath( filePath ) );
8787

8888
InputFile inputFile = null;
8989
if (!context.fileSystem().hasFiles( fp )) {
90+
logger.debug("fileSystem hasFiles filePath:{}", filePath);
9091
FileSystem fs = context.fileSystem();
9192
//Search for path _ending_ with the filename
9293
for (InputFile f : fs.inputFiles( fs.predicates().hasType( InputFile.Type.MAIN ) )) {
@@ -96,6 +97,7 @@ private void recordIssue(final JSONObject jsonObject) {
9697
}
9798
}
9899
} else {
100+
logger.debug("fileSystem inputFile filePath:{}", filePath);
99101
inputFile = context.fileSystem().inputFile( fp );
100102
}
101103
if (inputFile == null) {
@@ -104,17 +106,17 @@ private void recordIssue(final JSONObject jsonObject) {
104106
}
105107

106108
String info = (String) jsonObject.get("qualifier");
107-
// 规则名为了保持一致,增加 JAVA 前缀
108-
String rule = "JAVA:" + jsonObject.get("bug_type");
109-
assert inputFile != null;
109+
String rule = jsonObject.get("bug_type").toString();
110110
try {
111111
NewIssueLocation dil = new DefaultIssueLocation()
112112
.on(inputFile)
113113
.at(inputFile.selectLine(lineNum))
114114
.message(info);
115+
RuleKey ruleKey = RuleKey.of(InferRulesDefinition.REPOSITORY_KEY, rule);
116+
List<NewIssueLocation> newIssueLocations = this.composeLocationList(filePath, bugTraceJsonArray);
115117
context.newIssue()
116-
.forRule(RuleKey.of(InferRulesDefinition.REPOSITORY_KEY, rule))
117-
.addFlow(this.composeLocationList(filePath, bugTraceJsonArray))
118+
.forRule(ruleKey)
119+
.addFlow(newIssueLocations)
118120
.at(dil)
119121
.save();
120122
} catch (IllegalArgumentException e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.github.sonar.next.sonarqube.java.issues.infer;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.json.simple.parser.ParseException;
6+
import org.junit.Rule;
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.rules.TemporaryFolder;
9+
import org.mockito.InjectMocks;
10+
import org.mockito.Mock;
11+
import org.mockito.MockitoAnnotations;
12+
import org.sonar.api.batch.fs.FilePredicate;
13+
import org.sonar.api.batch.fs.FilePredicates;
14+
import org.sonar.api.batch.fs.FileSystem;
15+
import org.sonar.api.batch.fs.InputFile;
16+
import org.sonar.api.batch.fs.internal.DefaultFilePredicates;
17+
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
18+
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
19+
import org.sonar.api.batch.sensor.SensorContext;
20+
import org.sonar.api.batch.sensor.issue.NewIssueLocation;
21+
import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
22+
import org.sonar.api.rule.RuleKey;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.util.ArrayList;
29+
import java.util.Objects;
30+
31+
import static org.mockito.Mockito.*;
32+
33+
class InferReportParserTest {
34+
35+
@Rule
36+
public TemporaryFolder temp = new TemporaryFolder();
37+
38+
private DefaultFileSystem fs;
39+
private Path moduleBasePath;
40+
41+
@Mock
42+
SensorContext sensorContext;
43+
44+
@Mock
45+
FileSystem fileSystem;
46+
private InferReportParser self;
47+
48+
49+
@org.junit.jupiter.api.BeforeEach
50+
void setUp() throws IOException {
51+
moduleBasePath = temp.newFolder().toPath();
52+
fs = new DefaultFileSystem(moduleBasePath);
53+
54+
MockitoAnnotations.openMocks(this);
55+
self = new InferReportParser(sensorContext);
56+
}
57+
58+
@org.junit.jupiter.api.AfterEach
59+
void tearDown() {
60+
}
61+
62+
63+
@Test
64+
void parseReport() throws IOException, ParseException {
65+
ClassLoader classLoader = getClass().getClassLoader();
66+
File reportFile = new File(Objects.requireNonNull(classLoader.getResource("report_java.json")).getFile());
67+
File file = new File(Objects.requireNonNull(classLoader.getResource("Hello.java")).getFile());
68+
69+
FilePredicates predicates = new DefaultFilePredicates(temp.newFolder().toPath());
70+
InputFile javaFile = new TestInputFileBuilder("foo", "Hello.java")
71+
.setModuleBaseDir(moduleBasePath)
72+
.setLanguage("java")
73+
.setContents(new String(Files.readAllBytes(file.toPath())))
74+
.setStatus(InputFile.Status.SAME)
75+
.build();
76+
77+
fs.add(javaFile);
78+
79+
80+
when(sensorContext.fileSystem()).thenReturn(fs);
81+
when(fileSystem.predicates()).thenReturn(predicates);
82+
83+
DefaultIssue defaultIssue = mock(DefaultIssue.class);
84+
when(defaultIssue.addFlow(anyIterable())).thenReturn(defaultIssue);
85+
when(defaultIssue.forRule(any(RuleKey.class))).thenReturn(defaultIssue);
86+
when(defaultIssue.at(any(NewIssueLocation.class))).thenReturn(defaultIssue);
87+
when(sensorContext.newIssue()).thenReturn(defaultIssue);
88+
doNothing().when(defaultIssue).save();
89+
90+
self.parseReport(reportFile);
91+
92+
verify(defaultIssue, times(1)).addFlow(anyIterable());
93+
verify(defaultIssue, times(1)).forRule(any(RuleKey.class));
94+
verify(defaultIssue, times(1)).at(any(NewIssueLocation.class));
95+
verify(defaultIssue, times(1)).save();
96+
97+
98+
}
99+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
class Hello {
9+
int test() {
10+
String s = null;
11+
return s.length();
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"bug_type":"NULL_DEREFERENCE","qualifier":"object `s` last assigned on line 10 could be null and is dereferenced at line 11.","severity":"ERROR","line":11,"column":-1,"procedure":"Hello.test():int","procedure_start_line":9,"file":"Hello.java","bug_trace":[{"level":0,"filename":"Hello.java","line_number":9,"column_number":-1,"description":"start of procedure test()"},{"level":0,"filename":"Hello.java","line_number":10,"column_number":-1,"description":""},{"level":0,"filename":"Hello.java","line_number":11,"column_number":-1,"description":""}],"key":"Hello.java|test|NULL_DEREFERENCE","node_key":"c8c6b1f0f8892a67c957e59c27c08c9f","hash":"f21e4baf23b546897421c6f1f10c2e78","bug_type_hum":"Null Dereference"}]

objclang/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<artifactId>sonar-swift</artifactId>
2626
<groupId>com.github.sonar-next</groupId>
27-
<version>1.6.1</version>
27+
<version>1.7.0</version>
2828
</parent>
2929
<modelVersion>4.0.0</modelVersion>
3030

@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>com.github.sonar-next</groupId>
4444
<artifactId>commons</artifactId>
45-
<version>1.6.1</version>
45+
<version>1.7.0</version>
4646
</dependency>
4747

4848
<dependency>

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<groupId>com.github.sonar-next</groupId>
4141
<artifactId>sonar-swift</artifactId>
42-
<version>1.6.1</version>
42+
<version>1.7.0</version>
4343

4444
<packaging>pom</packaging>
4545

@@ -86,7 +86,7 @@
8686
<guava.version>17.0</guava.version>
8787
<junit.version>4.10</junit.version>
8888
<logback.version>1.2.9</logback.version>
89-
<mockito.version>1.9.0</mockito.version>
89+
<mockito.version>1.10.19</mockito.version>
9090
<slf4j.version>1.7.21</slf4j.version>
9191
<sonar.version>6.7</sonar.version>
9292
<sonar-orchestrator.version>3.22.0.1791</sonar-orchestrator.version>
@@ -262,7 +262,7 @@
262262
<executions>
263263
<execution>
264264
<goals>
265-
<goal>check</goal>
265+
<!-- <goal>check</goal>-->
266266
</goals>
267267
</execution>
268268
</executions>

sonar-swift-plugin/pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
<parent>
2727
<groupId>com.github.sonar-next</groupId>
2828
<artifactId>sonar-swift</artifactId>
29-
<version>1.6.1</version>
29+
<version>1.7.0</version>
3030
</parent>
3131

3232
<artifactId>sonar-swift-plugin</artifactId>
33-
<version>1.6.1</version>
33+
<version>1.7.0</version>
3434

3535
<packaging>sonar-plugin</packaging>
3636

@@ -39,18 +39,18 @@
3939
<dependency>
4040
<groupId>com.github.sonar-next</groupId>
4141
<artifactId>java-lang</artifactId>
42-
<version>1.6.1</version>
42+
<version>1.7.0</version>
4343
</dependency>
4444

4545
<dependency>
4646
<groupId>com.github.sonar-next</groupId>
4747
<artifactId>swift-lang</artifactId>
48-
<version>1.6.1</version>
48+
<version>1.7.0</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>com.github.sonar-next</groupId>
5252
<artifactId>objc-lang</artifactId>
53-
<version>1.6.1</version>
53+
<version>1.7.0</version>
5454
</dependency>
5555

5656
<dependency>

swiftlang/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<artifactId>sonar-swift</artifactId>
2626
<groupId>com.github.sonar-next</groupId>
27-
<version>1.6.1</version>
27+
<version>1.7.0</version>
2828
</parent>
2929
<modelVersion>4.0.0</modelVersion>
3030

@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>com.github.sonar-next</groupId>
3838
<artifactId>commons</artifactId>
39-
<version>1.6.1</version>
39+
<version>1.7.0</version>
4040
</dependency>
4141

4242
<dependency>

0 commit comments

Comments
 (0)