Skip to content

Commit 8ffbec6

Browse files
Update sonar-analyzer-commons, metadata and RSPEC-s (#242)
1 parent 24f41ed commit 8ffbec6

File tree

73 files changed

+330
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+330
-205
lines changed

its/ruling/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
<version>${analyzerCommons.version}</version>
6060
<scope>test</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>org.sonarsource.sonarqube</groupId>
64+
<artifactId>sonar-ws</artifactId>
65+
<version>${sonarqube.sonar.ws.version}</version>
66+
<scope>test</scope>
67+
</dependency>
6268
</dependencies>
6369

6470
</project>

its/ruling/src/test/java/org/sonar/web/it/WebRulingTest.java

Lines changed: 73 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,38 @@
1717
*/
1818
package org.sonar.web.it;
1919

20-
import com.google.gson.Gson;
2120
import com.sonar.orchestrator.Orchestrator;
2221
import com.sonar.orchestrator.build.BuildResult;
2322
import com.sonar.orchestrator.build.SonarScanner;
24-
import com.sonar.orchestrator.http.HttpMethod;
23+
import com.sonar.orchestrator.container.Server;
2524
import com.sonar.orchestrator.locator.FileLocation;
2625
import com.sonar.orchestrator.locator.MavenLocation;
2726
import java.io.File;
2827
import java.nio.file.Files;
28+
import java.util.Arrays;
2929
import java.util.Collections;
3030
import java.util.List;
31-
import java.util.Map;
3231
import java.util.Optional;
3332
import java.util.stream.Collectors;
3433
import org.apache.commons.lang.StringUtils;
3534
import org.junit.BeforeClass;
3635
import org.junit.ClassRule;
3736
import org.junit.Test;
3837
import org.sonarsource.analyzer.commons.ProfileGenerator;
38+
import org.sonarqube.ws.Qualityprofiles;
39+
import org.sonarqube.ws.client.HttpConnector;
40+
import org.sonarqube.ws.client.WsClient;
41+
import org.sonarqube.ws.client.WsClientFactories;
42+
import org.sonarqube.ws.client.qualityprofiles.ActivateRuleRequest;
43+
import org.sonarqube.ws.client.qualityprofiles.SearchRequest;
44+
import org.sonarqube.ws.client.rules.CreateRequest;
3945

4046
import static org.assertj.core.api.Assertions.assertThat;
4147

4248
public class WebRulingTest {
4349

4450
private static final String LANGUAGE = "web";
4551
private static final String REPOSITORY_KEY = "Web";
46-
private static final Gson GSON = new Gson();
4752

4853
@ClassRule
4954
public static Orchestrator orchestrator = Orchestrator.builderEnv()
@@ -66,7 +71,7 @@ public void ruling() throws Exception {
6671
File litsDifferencesFile = FileLocation.of("target/differences").getFile();
6772
String projectKey = "project";
6873
orchestrator.getServer().provisionProject(projectKey, projectKey);
69-
orchestrator.getServer().associateProjectToQualityProfile(projectKey, "web", "rules");
74+
orchestrator.getServer().associateProjectToQualityProfile(projectKey, LANGUAGE, "rules");
7075
SonarScanner build = SonarScanner.create()
7176
.setProjectDir(FileLocation.of("../sources").getFile())
7277
.setProjectKey(projectKey)
@@ -86,58 +91,78 @@ public void ruling() throws Exception {
8691
// To prevent adding error or exception that may be unseen in the logs
8792
BuildResult result = orchestrator.executeBuild(build);
8893
List<String> errorList = result.getLogs().lines().filter(line -> line.startsWith("ERROR")).collect(Collectors.toList());
89-
assertThat(errorList).hasSize(1);
90-
assertThat(errorList.get(0)).contains("decoder-allow-null-chars.html");
94+
assertThat(errorList).hasSize(0);
9195

9296
String differences = Files.readString(litsDifferencesFile.toPath());
9397
assertThat(differences).isEmpty();
9498
}
9599

96100
private static void instantiateTemplateRule(String ruleTemplateKey, String instantiationKey, String params) {
97-
orchestrator.getServer()
98-
.newHttpCall("/api/rules/create")
99-
.setAdminCredentials()
100-
.setMethod(HttpMethod.POST)
101-
.setParams(
102-
"name", instantiationKey,
103-
"markdown_description", instantiationKey,
104-
"severity", "INFO",
105-
"status", "READY",
106-
"template_key", REPOSITORY_KEY + ":" + ruleTemplateKey,
107-
"custom_key", instantiationKey,
108-
"prevent_reactivation", "true",
109-
"params", "name=\"" + instantiationKey + "\";key=\"" + instantiationKey + "\";markdown_description=\"" + instantiationKey + "\";" + params)
110-
.execute();
101+
newAdminWsClient(orchestrator)
102+
.rules()
103+
.create(
104+
new CreateRequest()
105+
.setName(instantiationKey)
106+
.setMarkdownDescription(instantiationKey)
107+
.setSeverity("INFO")
108+
.setStatus("READY")
109+
.setTemplateKey(REPOSITORY_KEY + ":" + ruleTemplateKey)
110+
.setCustomKey(instantiationKey)
111+
.setPreventReactivation("true")
112+
.setParams(
113+
Arrays.asList(
114+
(
115+
"name=\"" +
116+
instantiationKey +
117+
"\";key=\"" +
118+
instantiationKey +
119+
"\";markdown_description=\"" +
120+
instantiationKey +
121+
"\";" +
122+
params
123+
).split(";", 0)
124+
)
125+
)
126+
);
111127

112-
// check that the rule has been created
113-
String get = orchestrator.getServer()
114-
.newHttpCall("api/qualityprofiles/search")
115-
.execute()
116-
.getBodyAsString();
128+
String profileKey = newAdminWsClient(orchestrator)
129+
.qualityprofiles()
130+
.search(new SearchRequest().setLanguage(LANGUAGE))
131+
.getProfilesList()
132+
.stream()
133+
.filter(qp -> "rules".equals(qp.getName()))
134+
.map(Qualityprofiles.SearchWsResponse.QualityProfile::getKey)
135+
.findFirst()
136+
.orElse(null);
117137

118-
String profileKey = null;
119-
Map map = GSON.fromJson(get, Map.class);
120-
for (Map qp : ((List<Map>) map.get("profiles"))) {
121-
if ("rules".equals(qp.get("name"))) {
122-
profileKey = (String) qp.get("key");
123-
break;
124-
}
138+
if (!StringUtils.isEmpty(profileKey)) {
139+
newAdminWsClient(orchestrator)
140+
.qualityprofiles()
141+
.activateRule(
142+
new ActivateRuleRequest()
143+
.setKey(profileKey)
144+
.setRule(REPOSITORY_KEY + ":" + instantiationKey)
145+
.setSeverity("INFO")
146+
.setParams(Collections.emptyList())
147+
);
148+
} else {
149+
throw new IllegalStateException(
150+
"Could not retrieve profile key : Template rule " +
151+
ruleTemplateKey +
152+
" has not been activated"
153+
);
125154
}
126-
if (StringUtils.isEmpty(profileKey)) {
127-
throw new IllegalStateException("Could not retrieve profile key : Template rule " + ruleTemplateKey + " has not been activated");
128-
}
129-
130-
// activate the rule
131-
orchestrator.getServer()
132-
.newHttpCall("api/qualityprofiles/activate_rule")
133-
.setAdminCredentials()
134-
.setMethod(HttpMethod.POST)
135-
.setParams(
136-
"key", profileKey,
137-
"rule", REPOSITORY_KEY + ":" + instantiationKey,
138-
"severity", "INFO",
139-
"params", "")
140-
.execute();
141155
}
142156

157+
static WsClient newAdminWsClient(Orchestrator orchestrator) {
158+
return WsClientFactories
159+
.getDefault()
160+
.newClient(
161+
HttpConnector
162+
.newBuilder()
163+
.credentials(Server.ADMIN_LOGIN, Server.ADMIN_PASSWORD)
164+
.url(orchestrator.getServer().getUrl())
165+
.build()
166+
);
167+
}
143168
}

its/ruling/src/test/resources/expected/Web-LongJavaScriptCheck.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,8 +2648,6 @@
26482648
'project:external_webkit-jb-mr1/Source/WebCore/manual-tests/submit-form-with-target-twice.html':[
26492649
2,
26502650
],
2651-
'project:external_webkit-jb-mr1/Source/WebCore/manual-tests/subview-click-assertion.html':[
2652-
],
26532651
'project:external_webkit-jb-mr1/Source/WebCore/manual-tests/svg-deep-clone-to-new-doc.html':[
26542652
8,
26552653
],

its/ruling/src/test/resources/expected/Web-PageWithoutTitleCheck.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,9 @@
888888
'project:external_webkit-jb-mr1/LayoutTests/fast/encoding/css-link-charset.html':[
889889
2,
890890
],
891+
'project:external_webkit-jb-mr1/LayoutTests/fast/encoding/decoder-allow-null-chars.html':[
892+
1,
893+
],
891894
'project:external_webkit-jb-mr1/LayoutTests/fast/encoding/default-xhtml-encoding.xhtml':[
892895
1,
893896
],

its/ruling/src/test/resources/expected/Web-UnclosedTagCheck.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@
610610
'project:external_webkit-jb-mr1/LayoutTests/fast/encoding/bracket-in-tag.html':[
611611
3,
612612
],
613+
'project:external_webkit-jb-mr1/LayoutTests/fast/encoding/decoder-allow-null-chars.html':[
614+
12,
615+
],
613616
'project:external_webkit-jb-mr1/LayoutTests/fast/encoding/escaped-bracket.html':[
614617
3,
615618
],

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@
6565

6666
<jakarta.el.version>4.0.2</jakarta.el.version>
6767
<sslr.version>1.24.0.633</sslr.version>
68-
<analyzerCommons.version>2.1.0.1111</analyzerCommons.version>
68+
<analyzerCommons.version>2.5.0.1358</analyzerCommons.version>
6969
<sonar.plugin.api.version>7.9</sonar.plugin.api.version>
7070

7171
<sonarlint.api.impl.version>6.3.0.36253</sonarlint.api.impl.version>
72-
<sonarqube.api.impl.version>9.7.1.62043</sonarqube.api.impl.version>
73-
<sonarqube.sonar.ws.version>9.7.1.62043</sonarqube.sonar.ws.version>
72+
<sonarqube.api.impl.version>9.9.0.65466</sonarqube.api.impl.version>
73+
<sonarqube.sonar.ws.version>9.9.0.65466</sonarqube.sonar.ws.version>
7474
<orchestrator.version>3.40.0.183</orchestrator.version>
7575
<junit.version>4.13.2</junit.version>
7676
<assertj.version>3.23.1</assertj.version>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<h2>Why is this an issue?</h2>
12
<p>Programmers should not comment out code as it bloats programs and reduces readability.</p>
23
<p>Unused code should be deleted and can be retrieved from source control history if required.</p>
34

sonar-html-plugin/src/main/resources/org/sonar/l10n/web/rules/Web/AvoidHtmlCommentCheck.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
},
99
"tags": [
1010
"cwe",
11-
"jsp-jsf",
12-
"owasp-a3"
11+
"jsp-jsf"
1312
],
1413
"defaultSeverity": "Minor",
1514
"ruleSpecification": "RSPEC-1876",

sonar-html-plugin/src/main/resources/org/sonar/l10n/web/rules/Web/BoldAndItalicTagsCheck.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<p>This rule is deprecated, and will eventually be removed.</p>
2+
<h2>Why is this an issue?</h2>
13
<p>The <code>&lt;strong&gt;</code>/<code>&lt;b&gt;</code> and <code>&lt;em&gt;</code>/<code>&lt;i&gt;</code> tags have exactly the same effect in most
24
web browsers, but there is a fundamental difference between them: <code>&lt;strong&gt;</code> and <code>&lt;em&gt;</code> have a semantic meaning
35
whereas <code>&lt;b&gt;</code> and <code>&lt;i&gt;</code> only convey styling information like CSS.</p>
@@ -13,22 +15,20 @@
1315
<li> in order to convey styling information, the <code>&lt;b&gt;</code> and <code>&lt;i&gt;</code> should be avoided and CSS should be used instead.
1416
</li>
1517
</ul>
16-
<h2>Noncompliant Code Example</h2>
18+
<h3>Noncompliant code example</h3>
1719
<pre>
1820
&lt;i&gt;car&lt;/i&gt; &lt;!-- Noncompliant --&gt;
1921
&lt;b&gt;train&lt;/b&gt; &lt;!-- Noncompliant --&gt;
2022
</pre>
21-
<h2>Compliant Solution</h2>
23+
<h3>Compliant solution</h3>
2224
<pre>
2325
&lt;em&gt;car&lt;/em&gt;
2426
&lt;strong&gt;train&lt;/strong&gt;
2527
</pre>
26-
<h2>Exceptions</h2>
28+
<h3>Exceptions</h3>
2729
<p>This rule is relaxed in case of <a href="https://www.w3.org/WAI/GL/wiki/Using_aria-hidden%3Dtrue_on_an_icon_font_that_AT_should_ignore">icon
2830
fonts</a> usage.</p>
2931
<pre>
3032
&lt;i class="..." aria-hidden="true" /&gt; &lt;!-- Compliant icon fonts usage --&gt;
3133
</pre>
32-
<h2>Deprecated</h2>
33-
<p>This rule is deprecated, and will eventually be removed.</p>
3434

sonar-html-plugin/src/main/resources/org/sonar/l10n/web/rules/Web/ChildElementIllegalCheck.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<h2>Why is this an issue?</h2>
12
<p>This rule checks that the specified child tag does not appear as a direct child of the specified parent.</p>
2-
<h2>Noncompliant Code Example</h2>
3+
<h3>Noncompliant code example</h3>
34
<p>Assuming a parent/child combination of <code>head</code>/<code>body</code>:</p>
45
<pre>
56
&lt;head&gt;
@@ -9,7 +10,7 @@ <h2>Noncompliant Code Example</h2>
910
&lt;/body&gt;
1011
&lt;/head&gt;
1112
</pre>
12-
<h2>Compliant Solution</h2>
13+
<h3>Compliant solution</h3>
1314
<pre>
1415
&lt;head&gt;
1516
...

0 commit comments

Comments
 (0)