Skip to content

Commit 61bec43

Browse files
authored
Merge pull request #72 from jycr/feature/ISSUE-67--Rename-rule-IDs
[#67] rename rule IDs
2 parents 326f09f + 24c7c3f commit 61bec43

File tree

139 files changed

+246
-162
lines changed

Some content is hidden

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

139 files changed

+246
-162
lines changed

android-plugin/src/main/java/io/ecocode/java/Java.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
package io.ecocode.java;
2121

2222
public interface Java { //NOSONAR - we use the interface for constant without inheriting it
23-
String REPOSITORY_NAME = "ecoCode";
24-
String PROFILE_NAME = "ecoCode";
23+
String REPOSITORY_NAME = "ecoCode (Android)";
2524
String KEY = "java";
26-
String REPOSITORY_KEY = "ecoCode-java";
27-
// don't change that because the path is hard coded in CheckVerifier
28-
String JAVA_RESOURCE_PATH = "/org/sonar/l10n/java/rules/squid"; //NOSONAR - tis URI is the same everywhere
29-
String PROFILE_PATH = "org/sonar/l10n/java/rules/squid/ecocode_java_profile.json";
25+
String REPOSITORY_KEY = "ecocode-android-java";
26+
String RULES_SPECIFICATIONS_JAVA_PATH = "/io/ecocode/rules/java"; //NOSONAR - this URI is the same everywhere
27+
String PROFILE_NAME = "ecoCode (Android)";
28+
String PROFILE_PATH = "io/ecocode/android/java/ecocode_java_profile.json";
3029
}

android-plugin/src/main/java/io/ecocode/java/JavaRulesDefinition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.sonar.squidbridge.annotations.RuleTemplate;
3838

3939
/**
40-
* Declare rule metadata in server repository of rules.
40+
* Declare rule metadata in server repository of rules.
4141
* That allows to list the rules in the page "Rules".
4242
*/
4343
public class JavaRulesDefinition implements RulesDefinition {
@@ -84,7 +84,7 @@ private void ruleMetadata(NewRule rule) {
8484
}
8585

8686
private void addMetadata(NewRule rule, String metadataKey) {
87-
URL resource = JavaRulesDefinition.class.getResource(Java.JAVA_RESOURCE_PATH + "/" + metadataKey + "_java.json");
87+
URL resource = JavaRulesDefinition.class.getResource(Java.RULES_SPECIFICATIONS_JAVA_PATH + "/" + metadataKey + ".json");
8888
if (resource != null) {
8989
RuleMetatada metatada = gson.fromJson(readResource(resource), RuleMetatada.class);
9090
rule.setSeverity(metatada.defaultSeverity.toUpperCase(Locale.US));
@@ -100,7 +100,7 @@ private void addMetadata(NewRule rule, String metadataKey) {
100100
}
101101

102102
private static void addHtmlDescription(NewRule rule, String metadataKey) {
103-
URL resource = JavaRulesDefinition.class.getResource(Java.JAVA_RESOURCE_PATH + "/" + metadataKey + "_java.html");
103+
URL resource = JavaRulesDefinition.class.getResource(Java.RULES_SPECIFICATIONS_JAVA_PATH + "/" + metadataKey + ".html");
104104
if (resource != null) {
105105
rule.setHtmlDescription(readResource(resource));
106106
}

android-plugin/src/main/java/io/ecocode/java/checks/environment/batch/JobCoalesceRule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626
import org.sonar.plugins.java.api.semantic.MethodMatchers;
2727
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
2828
import org.sonar.plugins.java.api.tree.Tree;
29+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2930

3031
import java.util.List;
3132

3233
/**
3334
* Checks the call of "set", "setAlarmClock", "setExact", "setInexactRepeating", "setRepeating" & "setWindow" from "android.app.AlarmManager".
3435
* Checks also the call of "onPerformSync" & "getSyncAdapterBinder" from "android.content.AbstractThreadedSyncAdapter".
3536
*/
36-
@Rule(key = "EBAT003", name = "ecocodeJobCoalesce")
37+
@Rule(key = "EC501")
38+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EBAT003")
3739
public class JobCoalesceRule extends IssuableSubscriptionVisitor {
38-
40+
3941
private static final String ALARM_MANAGER_CLASS = "android.app.AlarmManager";
4042

4143
private final MethodMatchers alarmSchedulerMethodMatcher = MethodMatchers.or(

android-plugin/src/main/java/io/ecocode/java/checks/environment/batch/SensorCoalesceRule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.sonar.plugins.java.api.tree.ExpressionTree;
2929
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
3030
import org.sonar.plugins.java.api.tree.Tree;
31+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
3132

3233
import java.util.List;
3334
import java.util.Optional;
@@ -36,7 +37,8 @@
3637
* Check the call of the method "registerListener" of "android.hardware.SensorManager" with 4 parameters (the 4th one being the latency).
3738
* If it isn't present, report issue.
3839
*/
39-
@Rule(key = "EBAT002", name = "ecoCodeSensorCoalesce")
40+
@Rule(key = "EC500")
41+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EBAT002")
4042
public class SensorCoalesceRule extends IssuableSubscriptionVisitor {
4143

4244
private final MethodMatchers sensorListenerMethodMatcher = MethodMatchers.create().ofTypes("android.hardware.SensorManager").names("registerListener").withAnyParameters().build();

android-plugin/src/main/java/io/ecocode/java/checks/environment/bottleneck/InternetInTheLoopRule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
import org.sonar.plugins.java.api.semantic.MethodMatchers;
2626
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
2727
import org.sonar.plugins.java.api.tree.Tree;
28+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2829

2930
import java.util.List;
3031

3132
/**
3233
* Check if the method openConnection of the Url class is called inside a loop.
3334
* Not thrown if openConnection() call is deported into an other method.
3435
*/
35-
@Rule(key = "EBOT001", name = "ecocodeInternetInTheLoop")
36+
@Rule(key = "EC502")
37+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EBOT001")
3638
public class InternetInTheLoopRule extends IssuableSubscriptionVisitor {
3739

3840
private static final String ERROR_MESSAGE = "Internet connection should not be opened in loops to preserve the battery.";
@@ -67,4 +69,4 @@ private void reportIssueIfInLoop(Tree treeToCheck, Tree issueTree) {
6769
reportIssueIfInLoop(treeToCheck.parent(), issueTree);
6870
}
6971
}
70-
}
72+
}

android-plugin/src/main/java/io/ecocode/java/checks/environment/bottleneck/UncompressedDataTransmissionRule.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737
import com.google.common.collect.ImmutableList;
3838

3939
import io.ecocode.java.checks.helpers.CheckArgumentComplexTypeUtils;
40+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
4041

4142
/**
4243
* If an OutputStream class is created:
4344
* - if the method getOutputStream from the URLConnection class is called, reports the issue.
4445
* - if a constructor is called with for parameter getOutputStream, reports the issue if the constructor isn't a GZIPOutputStream.
4546
*/
46-
@Rule(key = "EBOT003", name = "ecoCodeUncompressedDataTransmission")
47+
@Rule(key = "EC504")
48+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EBOT003")
4749
public class UncompressedDataTransmissionRule extends IssuableSubscriptionVisitor {
4850
private static final Logger LOG = Loggers.get(UncompressedDataTransmissionRule.class);
49-
51+
5052
private static final String ERROR_MESSAGE = "Prefer using GzipOutputStream instead of OutputStream to improve energy efficiency.";
5153
private static final MethodMatchers matcherUrlConnection = MethodMatchers.create().ofSubTypes("java.net.URLConnection").names("getOutputStream").addWithoutParametersMatcher().build();
5254
// TODO: 22/03/2022 Change methodMatcher for anything but a "new GZIPOutputStream()", the new being the problem here.
@@ -105,4 +107,4 @@ private void checkMethodInitilization(Tree treeToCheck, Tree treeToReport) {
105107
LOG.error("Error in checkMethodInitilization : {}", e.getMessage(), e);
106108
}
107109
}
108-
}
110+
}

android-plugin/src/main/java/io/ecocode/java/checks/environment/bottleneck/WifiMulticastLockRule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
import io.ecocode.java.checks.helpers.OpeningClosingMethodCheck;
2323
import org.sonar.check.Rule;
24+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2425

2526
/**
2627
* Check that WifiManager.MulticastLock#release() method is closed after WifiManager.MulticastLock#acquire().
2728
*
2829
* @see OpeningClosingMethodCheck
2930
*/
30-
@Rule(key = "EBOT002", name = "ecoCodeWifiMulticastLock")
31+
@Rule(key = "EC503")
32+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EBOT002")
3133
public class WifiMulticastLockRule extends OpeningClosingMethodCheck {
3234
private static final String ERROR_MESSAGE = "Failing to call WifiManager.MulticastLock#release() can cause a noticeable battery drain.";
3335

android-plugin/src/main/java/io/ecocode/java/checks/environment/idleness/ContinuousRenderingRule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import io.ecocode.java.checks.helpers.constant.FlagOnMethodCheck;
2323
import org.sonar.check.Rule;
24+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2425

2526
/**
2627
* Check the call of the method "setRenderMode" of "opengl.GLSurfaceView".
2728
* If argument value is "1" report issue.
2829
*/
29-
@Rule(key = "EIDL008", name = "ecocodeContinuousRendering")
30+
@Rule(key = "EC510")
31+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EIDL008")
3032
public class ContinuousRenderingRule extends FlagOnMethodCheck {
3133

3234
public ContinuousRenderingRule() {

android-plugin/src/main/java/io/ecocode/java/checks/environment/idleness/DurableWakeLockRule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
import org.sonar.plugins.java.api.semantic.MethodMatchers;
2626
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
2727
import org.sonar.plugins.java.api.tree.Tree;
28+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2829

2930
import java.util.List;
3031

3132
/**
3233
* Check the call of the method "acquire" of "android.os.PowerManager$WakeLock".
3334
* Reports an issue if found without any parameters.
3435
*/
35-
@Rule(key = "EIDL006", name = "ecocodeDurableWakeLock")
36+
@Rule(key = "EC508")
37+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EIDL006")
3638
public class DurableWakeLockRule extends IssuableSubscriptionVisitor {
3739
private String methodOwnerType = "android.os.PowerManager$WakeLock";
3840
private String methodName = "acquire";

android-plugin/src/main/java/io/ecocode/java/checks/environment/idleness/KeepCpuOnRule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import io.ecocode.java.checks.helpers.SpecificMethodCheck;
2323
import org.sonar.check.Rule;
24+
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
2425

2526
/**
2627
* Check the call of the method "newWakeLock" of "android.os.PowerManager".
2728
* Reports an issue if found.
2829
*/
29-
@Rule(key = "EIDL004", name = "ecocodeKeepCpuOn")
30+
@Rule(key = "EC507")
31+
@DeprecatedRuleKey(repositoryKey = "ecoCode-java", ruleKey = "EIDL004")
3032
public class KeepCpuOnRule extends SpecificMethodCheck {
3133

3234

0 commit comments

Comments
 (0)