Skip to content

Commit b4aab32

Browse files
authored
Merge branch 'main' into groovy_rules_nomenclature
2 parents 12c2bf6 + 0eaf2a6 commit b4aab32

17 files changed

+55
-59
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Build
2+
23
on:
34
push:
45
branches:
@@ -10,39 +11,57 @@ on:
1011
- '[0-9]+.[0-9]+.[0-9]+'
1112
pull_request:
1213
types: [ opened, synchronize, reopened ]
14+
1315
jobs:
1416
build:
1517
name: Build
1618
runs-on: ubuntu-latest
19+
permissions:
20+
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
1721
steps:
18-
- uses: actions/checkout@v3
22+
- name: Checkout
23+
uses: actions/checkout@v4
1924
with:
2025
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
26+
2127
- name: Set up JDK 11
22-
uses: actions/setup-java@v1
28+
uses: actions/setup-java@v3
2329
with:
30+
distribution: 'temurin'
2431
java-version: 11
25-
- name: Cache SonarCloud packages
26-
uses: actions/cache@v1
27-
with:
28-
path: ~/.sonar/cache
29-
key: ${{ runner.os }}-sonar
30-
restore-keys: ${{ runner.os }}-sonar
32+
3133
- name: Cache Maven packages
32-
uses: actions/cache@v1
34+
uses: actions/cache@v3
3335
with:
3436
path: ~/.m2
3537
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
3638
restore-keys: ${{ runner.os }}-m2
39+
3740
- name: Setup Gradle
3841
uses: gradle/gradle-build-action@v2
42+
3943
- name: Prepare CodeNarc dependency
4044
working-directory: .
41-
run: |
42-
./tool_prepare-codenarc.sh
43-
- name: Build and analyze
44-
working-directory: .
45+
run: ./tool_prepare-codenarc.sh
46+
47+
- name: Verify
48+
run: mvn -e -B verify
49+
50+
- name: Set up JDK 17
51+
uses: actions/setup-java@v3
52+
with:
53+
distribution: 'temurin'
54+
java-version: 17
55+
56+
- name: Cache SonarQube packages
57+
uses: actions/cache@v3
58+
with:
59+
path: ~/.sonar/cache
60+
key: ${{ runner.os }}-sonar
61+
restore-keys: ${{ runner.os }}-sonar
62+
63+
- name: SonarQube Scan
4564
env:
4665
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4766
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
48-
run: mvn -e -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecocode-android
67+
run: mvn -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecocode-android

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.batch;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import org.sonar.check.Rule;
2221
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
2322
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -58,7 +57,7 @@ public JobCoalesceRule() {
5857

5958
@Override
6059
public List<Tree.Kind> nodesToVisit() {
61-
return ImmutableList.of(Tree.Kind.METHOD_INVOCATION);
60+
return List.of(Tree.Kind.METHOD_INVOCATION);
6261
}
6362

6463
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.batch;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import io.ecocode.java.checks.helpers.CheckArgumentComplexTypeUtils;
2221
import org.sonar.check.Rule;
2322
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
@@ -47,7 +46,7 @@ public SensorCoalesceRule() {
4746

4847
@Override
4948
public List<Tree.Kind> nodesToVisit() {
50-
return ImmutableList.of(Tree.Kind.METHOD_INVOCATION);
49+
return List.of(Tree.Kind.METHOD_INVOCATION);
5150
}
5251

5352
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.bottleneck;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import org.sonar.check.Rule;
2221
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
2322
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -42,7 +41,7 @@ public class InternetInTheLoopRule extends IssuableSubscriptionVisitor {
4241

4342
@Override
4443
public List<Tree.Kind> nodesToVisit() {
45-
return ImmutableList.of(Tree.Kind.METHOD_INVOCATION);
44+
return List.of(Tree.Kind.METHOD_INVOCATION);
4645
}
4746

4847
@Override

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.sonar.plugins.java.api.tree.Tree;
3333
import org.sonar.plugins.java.api.tree.VariableTree;
3434

35-
import com.google.common.collect.ImmutableList;
36-
3735
import io.ecocode.java.checks.helpers.CheckArgumentComplexTypeUtils;
3836
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
3937

@@ -54,7 +52,7 @@ public class UncompressedDataTransmissionRule extends IssuableSubscriptionVisito
5452

5553
@Override
5654
public List<Tree.Kind> nodesToVisit() {
57-
return ImmutableList.of(Tree.Kind.VARIABLE);
55+
return List.of(Tree.Kind.VARIABLE);
5856
}
5957

6058
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.idleness;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import org.sonar.check.Rule;
2221
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
2322
import org.sonar.plugins.java.api.semantic.MethodMatchers;
@@ -41,7 +40,7 @@ public class DurableWakeLockRule extends IssuableSubscriptionVisitor {
4140

4241
@Override
4342
public List<Tree.Kind> nodesToVisit() {
44-
return ImmutableList.of(Tree.Kind.METHOD_INVOCATION);
43+
return List.of(Tree.Kind.METHOD_INVOCATION);
4544
}
4645

4746
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.idleness;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import io.ecocode.java.checks.helpers.CheckArgumentComplexTypeUtils;
2221
import org.sonar.api.utils.log.Logger;
2322
import org.sonar.api.utils.log.Loggers;
@@ -57,7 +56,7 @@ public class KeepVoiceAwakeRule extends IssuableSubscriptionVisitor {
5756

5857
@Override
5958
public List<Tree.Kind> nodesToVisit() {
60-
return ImmutableList.of(Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION);
59+
return List.of(Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION);
6160
}
6261

6362
@Override

android-plugin/src/main/java/io/ecocode/java/checks/environment/optimized_api/FusedLocationRule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.optimized_api;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import io.ecocode.java.checks.helpers.TreeHelper;
2221
import org.sonar.check.Rule;
2322
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
@@ -47,7 +46,7 @@ public class FusedLocationRule extends IssuableSubscriptionVisitor {
4746

4847
@Override
4948
public List<Tree.Kind> nodesToVisit() {
50-
return ImmutableList.of(Tree.Kind.IMPORT);
49+
return List.of(Tree.Kind.IMPORT);
5150
}
5251

5352
@Override

android-plugin/src/main/java/io/ecocode/java/checks/environment/power/ChargeAwarenessRule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.sonar.plugins.java.api.tree.NewClassTree;
3232
import org.sonar.plugins.java.api.tree.Tree;
3333

34-
import com.google.common.collect.ImmutableList;
3534
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
3635

3736
/**
@@ -58,7 +57,7 @@ public class ChargeAwarenessRule extends IssuableSubscriptionVisitor {
5857

5958
@Override
6059
public List<Tree.Kind> nodesToVisit() {
61-
return ImmutableList.of(Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION);
60+
return List.of(Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION);
6261
}
6362

6463
@Override

android-plugin/src/main/java/io/ecocode/java/checks/environment/power/SaveModeAwarenessRule.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package io.ecocode.java.checks.environment.power;
1919

20-
import com.google.common.collect.ImmutableList;
2120
import org.sonar.api.utils.log.Logger;
2221
import org.sonar.api.utils.log.Loggers;
2322
import org.sonar.check.Rule;
@@ -48,7 +47,7 @@ public class SaveModeAwarenessRule extends IssuableSubscriptionVisitor {
4847

4948
@Override
5049
public List<Tree.Kind> nodesToVisit() {
51-
return ImmutableList.of(Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION);
50+
return List.of(Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION);
5251
}
5352

5453
@Override
@@ -72,10 +71,8 @@ public void visitNode(Tree tree) {
7271
if ((addActionMatcher.matches(mit) || createIntentFilterMatcher.matches(mit))
7372
&& !mit.arguments().isEmpty()) {
7473
mit.arguments().get(0).asConstant().ifPresentOrElse(o -> {
75-
if (o instanceof String) {
76-
if (o.equals(ACTION_BATTERY_CHANGED)) {
77-
reportIssue(mit.arguments().get(0), ADVICE_MESSAGE);
78-
}
74+
if (o instanceof String && o.equals(ACTION_BATTERY_CHANGED)) {
75+
reportIssue(mit.arguments().get(0), ADVICE_MESSAGE);
7976
}
8077
}, () -> {
8178
if (isPowerSaveModeMatcher.matches(mit)) {

0 commit comments

Comments
 (0)