aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2021-03-11 20:52:24 +0100
committersonartech <sonartech@sonarsource.com>2021-03-17 20:08:34 +0000
commit4e76eae61a9cc708dde1e71d1895dfbb810f63ce (patch)
tree1b268245f8ebfb51e23f00e2588e87ed2661690b /sonar-scanner-engine
parentb65f41e7553d520a095509d3db7fca15302547f3 (diff)
downloadsonarqube-4e76eae61a9cc708dde1e71d1895dfbb810f63ce.tar.gz
sonarqube-4e76eae61a9cc708dde1e71d1895dfbb810f63ce.zip
SONAR-14192 Add optional return field 'deprecatedKeys' to /api/rules/search
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java12
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java2
3 files changed, 12 insertions, 4 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
index 192ddf208ad..6404d8184dc 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
@@ -25,12 +25,13 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
-import org.sonar.scanner.bootstrap.ScannerWsClient;
-import org.sonar.api.impl.utils.ScannerUtils;
import org.sonar.api.batch.rule.LoadedActiveRule;
+import org.sonar.api.impl.utils.ScannerUtils;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.DateUtils;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonarqube.ws.Rules;
import org.sonarqube.ws.Rules.Active;
import org.sonarqube.ws.Rules.Active.Param;
@@ -40,7 +41,8 @@ import org.sonarqube.ws.Rules.SearchResponse;
import org.sonarqube.ws.client.GetRequest;
public class DefaultActiveRulesLoader implements ActiveRulesLoader {
- private static final String RULES_SEARCH_URL = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt&activation=true";
+ private static final String RULES_SEARCH_URL = "/api/rules/search.protobuf?" +
+ "f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt,deprecatedKeys&activation=true";
private final ScannerWsClient wsClient;
@@ -125,6 +127,10 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
params.put(param.getKey(), param.getValue());
}
loadedRule.setParams(params);
+ loadedRule.setDeprecatedKeys(r.getDeprecatedKeys().getDeprecatedKeyList()
+ .stream()
+ .map(RuleKey::parse)
+ .collect(Collectors.toSet()));
loadedRules.add(loadedRule);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java
index 77536daacaa..0f1aef9124d 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java
@@ -21,6 +21,7 @@ package org.sonar.scanner.rule;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -116,6 +117,7 @@ public class ActiveRulesProviderTest {
LoadedActiveRule r = new LoadedActiveRule();
r.setName(name);
r.setRuleKey(RuleKey.of(name, name));
+ r.setDeprecatedKeys(ImmutableSet.of(RuleKey.of(name + "old", name + "old")));
return r;
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java
index cdc32114402..e823ddf3bfa 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java
@@ -91,7 +91,7 @@ public class DefaultActiveRulesLoaderTest {
}
private String urlOfPage(int page) {
- return "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt&activation=true"
+ return "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt,updatedAt,deprecatedKeys&activation=true"
+ ("") + "&qprofile=c%2B-test_c%2B-values-17445&ps=500&p=" + page + "";
}