├── codenarc-converter ├── CodeNarc │ ├── docs │ │ ├── CNAME │ │ ├── _config.yml │ │ ├── images │ │ │ ├── codenarc-logo.png │ │ │ └── forkme_right_red_aa0000.png │ │ ├── _data │ │ │ └── navigation.yml │ │ ├── codenarc-rules-braces.md │ │ └── c.sh │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ ├── SampleInvalidFile.txt │ │ │ │ ├── source │ │ │ │ │ ├── SomeOtherFile.txt │ │ │ │ │ ├── SourceFile1.groovy │ │ │ │ │ └── SourceFile2.groovy │ │ │ │ ├── resource │ │ │ │ │ └── SampleResource.txt │ │ │ │ ├── SampleFile.groovy │ │ │ │ ├── sourcewithdirs │ │ │ │ │ ├── subdir2 │ │ │ │ │ │ ├── subdir2b │ │ │ │ │ │ │ └── NotAGroovyFile.txt │ │ │ │ │ │ ├── Subdir2File1.groovy │ │ │ │ │ │ └── subdir2a │ │ │ │ │ │ │ └── Subdir2aFile1.groovy │ │ │ │ │ ├── SourceFile1.groovy │ │ │ │ │ └── subdir1 │ │ │ │ │ │ ├── Subdir1File1.groovy │ │ │ │ │ │ └── Subdir1File2.groovy │ │ │ │ ├── rule │ │ │ │ │ ├── NotARule.txt │ │ │ │ │ ├── DoNothingRule.txt │ │ │ │ │ ├── DoesNotCompileRule.txt │ │ │ │ │ └── BracesTestSameLine.txt │ │ │ │ ├── rulesets │ │ │ │ │ ├── JsonRuleSet1.json │ │ │ │ │ ├── WeirdCharsRuleSet-,#.txt │ │ │ │ │ ├── GroovyRuleSet_Bad.txt │ │ │ │ │ ├── RuleSet1.xml │ │ │ │ │ ├── GroovyRuleSet2.txt │ │ │ │ │ ├── RuleSet3.xml │ │ │ │ │ ├── GroovyRuleSet1.txt │ │ │ │ │ ├── GroovyRuleSet1.groovy │ │ │ │ │ ├── RuleSet4.xml │ │ │ │ │ ├── CustomRuleSet.groovy │ │ │ │ │ ├── NestedRuleSet1.xml │ │ │ │ │ └── RuleSet2.xml │ │ │ │ ├── disable-rules-in-comments │ │ │ │ │ ├── disabling-rules.ruleset │ │ │ │ │ └── Sample.groovy │ │ │ │ ├── codenarc-messages.properties │ │ │ │ ├── override-codenarc.properties │ │ │ │ ├── codenarc.properties │ │ │ │ ├── sourcewitherrors │ │ │ │ │ ├── SourceFile1.txt │ │ │ │ │ └── SourceFileWithCompileError.txt │ │ │ │ └── RunCodeNarcAgainstProjectSourceCode.properties │ │ │ └── groovy │ │ │ │ └── org │ │ │ │ └── codenarc │ │ │ │ ├── plugin │ │ │ │ ├── TestPlugin1.groovy │ │ │ │ └── TestPlugin2.groovy │ │ │ │ ├── util │ │ │ │ └── CodeNarcVersionTest.groovy │ │ │ │ └── rule │ │ │ │ └── comments │ │ │ │ ├── JavadocEmptySeeTagRuleTest.groovy │ │ │ │ ├── JavadocEmptyParamTagRuleTest.groovy │ │ │ │ ├── JavadocEmptySinceTagRuleTest.groovy │ │ │ │ ├── JavadocEmptyAuthorTagRuleTest.groovy │ │ │ │ ├── JavadocEmptyReturnTagRuleTest.groovy │ │ │ │ ├── JavadocEmptyThrowsTagRuleTest.groovy │ │ │ │ └── JavadocEmptyVersionTagRuleTest.groovy │ │ └── main │ │ │ ├── resources │ │ │ ├── codenarc-version.txt │ │ │ ├── codenarc-rule-extrainfo.properties │ │ │ ├── rulesets │ │ │ │ ├── ecocode.xml │ │ │ │ ├── jdbc.xml │ │ │ │ ├── braces.xml │ │ │ │ ├── dry.xml │ │ │ │ ├── serialization.xml │ │ │ │ ├── unused.xml │ │ │ │ ├── size.xml │ │ │ │ ├── imports.xml │ │ │ │ ├── logging.xml │ │ │ │ ├── enhanced.xml │ │ │ │ ├── generic.xml │ │ │ │ └── security.xml │ │ │ └── templates │ │ │ │ ├── StarterRuleSet-AllRules.groovy.template │ │ │ │ ├── codenarc-rule-index-by-name.md.template │ │ │ │ ├── StarterRuleSet-AllRulesByCategory.groovy.template │ │ │ │ ├── codenarc-rule-index.md.template │ │ │ │ └── codenarc-rule-index.apt.template │ │ │ └── groovy │ │ │ └── org │ │ │ └── codenarc │ │ │ ├── ruleset │ │ │ ├── RuleSetConfigurer.groovy │ │ │ └── RuleSet.groovy │ │ │ ├── ruleregistry │ │ │ ├── RuleRegistryHolder.groovy │ │ │ ├── RuleRegistry.groovy │ │ │ └── RuleRegistryInitializer.groovy │ │ │ ├── report │ │ │ └── BaselineViolation.groovy │ │ │ ├── ant │ │ │ ├── ReportOption.groovy │ │ │ └── Report.groovy │ │ │ ├── util │ │ │ └── GroovyVersion.groovy │ │ │ ├── analyzer │ │ │ └── AnalyzerException.groovy │ │ │ ├── rule │ │ │ ├── comments │ │ │ │ ├── JavadocEmptySeeTagRule.groovy │ │ │ │ ├── JavadocEmptyAuthorTagRule.groovy │ │ │ │ ├── JavadocEmptyParamTagRule.groovy │ │ │ │ ├── JavadocEmptySinceTagRule.groovy │ │ │ │ ├── JavadocEmptyReturnTagRule.groovy │ │ │ │ ├── JavadocEmptyThrowsTagRule.groovy │ │ │ │ ├── JavadocEmptyVersionTagRule.groovy │ │ │ │ ├── JavadocEmptyExceptionTagRule.groovy │ │ │ │ ├── JavadocMissingParamDescriptionRule.groovy │ │ │ │ ├── JavadocMissingThrowsDescriptionRule.groovy │ │ │ │ └── JavadocMissingExceptionDescriptionRule.groovy │ │ │ ├── Violation.groovy │ │ │ └── exceptions │ │ │ │ ├── CatchErrorRule.groovy │ │ │ │ ├── CatchExceptionRule.groovy │ │ │ │ └── CatchThrowableRule.groovy │ │ │ └── AnalysisContext.groovy │ ├── gradle.properties │ ├── settings.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── NOTICE.txt │ ├── .gitignore │ ├── integration-test │ │ └── build.gradle │ ├── docker │ │ ├── README.md │ │ ├── Dockerfile │ │ └── build.gradle.template │ └── templates │ │ └── Rule.groovy └── src │ └── main │ └── java │ └── org │ └── sonar │ └── plugins │ └── groovy │ └── codenarc │ └── ParseResult.java ├── tool_stop.sh ├── tool_start.sh ├── tool_compile.sh ├── tool_docker-logs.sh ├── tool_docker-clean.sh ├── tool_docker-init.sh ├── android-plugin ├── src │ ├── main │ │ ├── resources │ │ │ ├── org │ │ │ │ └── sonar │ │ │ │ │ └── plugins │ │ │ │ │ └── groovy │ │ │ │ │ ├── profile-default.txt │ │ │ │ │ └── cost.csv │ │ │ └── io │ │ │ │ └── ecocode │ │ │ │ ├── android │ │ │ │ ├── xml │ │ │ │ │ └── ecocode_xml_profile.json │ │ │ │ └── java │ │ │ │ │ └── ecocode_java_profile.json │ │ │ │ └── rules │ │ │ │ ├── java │ │ │ │ ├── EC533.json │ │ │ │ ├── EC501.json │ │ │ │ ├── EC532.json │ │ │ │ ├── EC534.json │ │ │ │ ├── EC500.json │ │ │ │ ├── EC507.json │ │ │ │ ├── EC509.json │ │ │ │ ├── EC512.json │ │ │ │ ├── EC513.json │ │ │ │ ├── EC519.json │ │ │ │ ├── EC520.json │ │ │ │ ├── EC508.json │ │ │ │ ├── EC511.json │ │ │ │ ├── EC514.json │ │ │ │ ├── EC528.json │ │ │ │ ├── EC530.json │ │ │ │ ├── EC531.json │ │ │ │ ├── EC510.json │ │ │ │ ├── EC516.json │ │ │ │ ├── EC521.json │ │ │ │ ├── EC522.json │ │ │ │ ├── EC502.json │ │ │ │ ├── EC503.json │ │ │ │ ├── EC505.json │ │ │ │ ├── EC506.json │ │ │ │ ├── EC515.json │ │ │ │ ├── EC517.json │ │ │ │ ├── EC529.json │ │ │ │ ├── EC518.json │ │ │ │ ├── EC523.json │ │ │ │ ├── EC524.json │ │ │ │ ├── EC527.json │ │ │ │ ├── EC504.json │ │ │ │ ├── EC525.json │ │ │ │ ├── EC526.json │ │ │ │ ├── EC533.html │ │ │ │ ├── EC505.html │ │ │ │ ├── README.md │ │ │ │ ├── EC506.html │ │ │ │ ├── EC532.html │ │ │ │ ├── EC522.html │ │ │ │ ├── EC530.html │ │ │ │ ├── EC518.html │ │ │ │ ├── EC515.html │ │ │ │ ├── EC516.html │ │ │ │ ├── EC531.html │ │ │ │ ├── EC507.html │ │ │ │ ├── EC534.html │ │ │ │ ├── EC502.html │ │ │ │ ├── EC520.html │ │ │ │ ├── EC517.html │ │ │ │ ├── EC510.html │ │ │ │ ├── EC528.html │ │ │ │ ├── EC512.html │ │ │ │ ├── EC519.html │ │ │ │ ├── EC526.html │ │ │ │ ├── EC525.html │ │ │ │ ├── EC508.html │ │ │ │ ├── EC511.html │ │ │ │ ├── EC521.html │ │ │ │ ├── EC524.html │ │ │ │ ├── EC504.html │ │ │ │ ├── EC503.html │ │ │ │ ├── EC523.html │ │ │ │ └── EC527.html │ │ │ │ └── xml │ │ │ │ ├── EC542.json │ │ │ │ ├── EC545.json │ │ │ │ ├── EC540.json │ │ │ │ ├── EC546.json │ │ │ │ ├── EC548.json │ │ │ │ ├── EC541.json │ │ │ │ ├── EC543.json │ │ │ │ ├── EC544.json │ │ │ │ ├── EC547.json │ │ │ │ ├── EC549.json │ │ │ │ ├── EC547.html │ │ │ │ ├── EC543.html │ │ │ │ ├── README.md │ │ │ │ ├── EC544.html │ │ │ │ ├── EC542.html │ │ │ │ ├── EC546.html │ │ │ │ ├── EC540.html │ │ │ │ ├── EC541.html │ │ │ │ └── EC548.html │ │ └── java │ │ │ └── org │ │ │ └── sonar │ │ │ └── plugins │ │ │ └── groovy │ │ │ ├── package-info.java │ │ │ ├── jacoco │ │ │ └── package-info.java │ │ │ ├── utils │ │ │ └── package-info.java │ │ │ ├── codenarc │ │ │ └── package-info.java │ │ │ ├── gmetrics │ │ │ └── package-info.java │ │ │ ├── surefire │ │ │ ├── package-info.java │ │ │ ├── api │ │ │ │ └── package-info.java │ │ │ └── data │ │ │ │ └── package-info.java │ │ │ ├── cobertura │ │ │ └── package-info.java │ │ │ └── foundation │ │ │ └── package-info.java │ └── test │ │ ├── resources │ │ ├── org │ │ │ └── sonar │ │ │ │ └── plugins │ │ │ │ └── groovy │ │ │ │ ├── foundation │ │ │ │ ├── Error.groovy │ │ │ │ └── Greet.groovy │ │ │ │ ├── jacoco │ │ │ │ ├── Hello.class.toCopy │ │ │ │ ├── Hello$InnerClass.class.toCopy │ │ │ │ ├── JaCoCoSensor_0_7_4 │ │ │ │ │ ├── jacoco-ut.exec │ │ │ │ │ └── readme.txt │ │ │ │ ├── JaCoCoSensor_0_7_5 │ │ │ │ │ ├── jacoco-ut.exec │ │ │ │ │ └── readme.txt │ │ │ │ └── JaCoCo_incompatible_merge │ │ │ │ │ ├── jacoco-0.7.4.exec │ │ │ │ │ ├── jacoco-0.7.5.exec │ │ │ │ │ ├── jacoco-it-0.7.4.exec │ │ │ │ │ └── jacoco-it-0.7.5.exec │ │ │ │ ├── surefire │ │ │ │ ├── SurefireSensorTest │ │ │ │ │ ├── roundingTests │ │ │ │ │ │ └── TEST-Rounding.xml │ │ │ │ │ └── shouldHandleTestSuiteDetails │ │ │ │ │ │ ├── ExtensionsFinderTest2-expected-result.xml │ │ │ │ │ │ └── ExtensionsFinderTest3-expected-result.xml │ │ │ │ └── api │ │ │ │ │ └── SurefireUtilsTest │ │ │ │ │ └── shouldGetReportsFromProperty │ │ │ │ │ └── pom.xml │ │ │ │ ├── codenarc │ │ │ │ ├── parsing │ │ │ │ │ ├── Sample.groovy │ │ │ │ │ └── line-number-not-specified.xml │ │ │ │ └── exportProfile │ │ │ │ │ ├── exportNullParameters.xml │ │ │ │ │ ├── exportFixedRules.xml │ │ │ │ │ ├── exportProfile.xml │ │ │ │ │ ├── exportParameters.xml │ │ │ │ │ └── exportEscapedParameters.xml │ │ │ │ └── gmetrics │ │ │ │ └── Greeting.groovy │ │ └── checks │ │ │ ├── KeepCpuOnXmlRule │ │ │ ├── KeepCpuOnXmlCheckNoReport.xml │ │ │ └── KeepCpuOnXmlCheckReport.xml │ │ │ ├── IgnoreBatteryOptimizationsXmlRule │ │ │ ├── IgnoreBatteryOptimizationsXmlCheckNoReport.xml │ │ │ └── IgnoreBatteryOptimizationsXmlCheckReport.xml │ │ │ ├── ServiceBootTimeXmlRule │ │ │ └── ServiceBootTimeXmlCheck.xml │ │ │ ├── CompagnionInBackgroundXmlRule │ │ │ └── CompagnionInBackgroundXmlCheck.xml │ │ │ ├── KeepScreenOnXmlRule │ │ │ ├── KeepScreenOnXmlCheckFalse.xml │ │ │ └── KeepScreenOnXmlCheckTrue.xml │ │ │ ├── DarkUIBrightColorsXmlRule │ │ │ └── DarkUIBrightColorsXmlCheckResources.xml │ │ │ └── SaveModeAwarenessXmlRule │ │ │ └── SaveModeAwarenessXmlCheck.xml │ │ ├── files │ │ ├── social │ │ │ └── gdpr │ │ │ │ └── GoogleAndroidAdsConsentCheck.java │ │ └── environment │ │ │ ├── optimized_api │ │ │ ├── BluetoothLowEnergyCheckOnlyBle.java │ │ │ ├── BluetoothLowEnergyCheckBothBleBc.java │ │ │ └── FusedLocationCheckNoIssue.java │ │ │ └── leakage │ │ │ ├── CameraLeakCheckNoIssue.java │ │ │ ├── MediaLeakMediaPlayerCheckNoIssue.java │ │ │ └── MediaLeakMediaRecorderCheckNoIssue.java │ │ └── java │ │ └── io │ │ └── ecocode │ │ ├── xml │ │ └── checks │ │ │ └── sobriety │ │ │ └── HardwareAccelerationXmlRuleTest.java │ │ ├── java │ │ └── checks │ │ │ └── social │ │ │ └── gdpr │ │ │ └── GoogleAndroidAdsConsentRuleTest.java │ │ └── EcoCodeRulesPluginTest.java ├── docs │ ├── logo.png │ ├── logoNA.png │ ├── logoCCNR.png │ ├── ekko-sonar.png │ ├── logoSnapp.png │ ├── logoSolocal.png │ ├── logoUnivPau.png │ └── screenshot.png ├── NOTICE.txt └── docker-compose.yml ├── tool_build.sh ├── docs └── resources │ ├── img.png │ ├── 5ekko.png │ ├── img_1.png │ ├── apidays-2022.pdf │ └── devfest-2022.pdf ├── CODE_STYLE.md ├── CONTRIBUTING.md ├── tool_start_withtoken.sh ├── .gitattributes ├── .gitignore ├── Dockerfile ├── tool_release_1_prepare.sh ├── tool_prepare-codenarc.bat ├── tool_prepare-codenarc.sh ├── tool_release_2_branch.sh ├── CITATION.cff ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── sonar-project.properties /codenarc-converter/CodeNarc/docs/CNAME: -------------------------------------------------------------------------------- 1 | codenarc.org -------------------------------------------------------------------------------- /tool_stop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | docker-compose stop -------------------------------------------------------------------------------- /tool_start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | docker-compose start -------------------------------------------------------------------------------- /tool_compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | mvn clean compile 4 | -------------------------------------------------------------------------------- /tool_docker-logs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | docker-compose logs -f -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/SampleInvalidFile.txt: -------------------------------------------------------------------------------- 1 | %^&^% -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/source/SomeOtherFile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/codenarc-version.txt: -------------------------------------------------------------------------------- 1 | 2.2.5 2 | -------------------------------------------------------------------------------- /tool_docker-clean.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | docker-compose down --volumes -------------------------------------------------------------------------------- /tool_docker-init.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | docker-compose up --build -d -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docs/_config.yml: -------------------------------------------------------------------------------- 1 | name: CodeNarc 2 | markdown: kramdown 3 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/resource/SampleResource.txt: -------------------------------------------------------------------------------- 1 | abcdef12345 -------------------------------------------------------------------------------- /android-plugin/src/main/resources/org/sonar/plugins/groovy/profile-default.txt: -------------------------------------------------------------------------------- 1 | EC5001 2 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/SampleFile.groovy: -------------------------------------------------------------------------------- 1 | class SampleFile { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir2/subdir2b/NotAGroovyFile.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tool_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | rm -rf ./lib/*.jar 4 | mvn clean package -DskipTests 5 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/gradle.properties: -------------------------------------------------------------------------------- 1 | ossrhUsername = undefined 2 | ossrhPassword = undefined 3 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/settings.gradle: -------------------------------------------------------------------------------- 1 | include 'integration-test' 2 | 3 | rootProject.name = 'CodeNarc' 4 | -------------------------------------------------------------------------------- /docs/resources/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/docs/resources/img.png -------------------------------------------------------------------------------- /docs/resources/5ekko.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/docs/resources/5ekko.png -------------------------------------------------------------------------------- /docs/resources/img_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/docs/resources/img_1.png -------------------------------------------------------------------------------- /android-plugin/docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/logo.png -------------------------------------------------------------------------------- /android-plugin/docs/logoNA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/logoNA.png -------------------------------------------------------------------------------- /android-plugin/docs/logoCCNR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/logoCCNR.png -------------------------------------------------------------------------------- /android-plugin/src/main/resources/org/sonar/plugins/groovy/cost.csv: -------------------------------------------------------------------------------- 1 | ruleKey;remediationFunction;remediationFactor 2 | EC5001;linear;1h 3 | -------------------------------------------------------------------------------- /docs/resources/apidays-2022.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/docs/resources/apidays-2022.pdf -------------------------------------------------------------------------------- /docs/resources/devfest-2022.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/docs/resources/devfest-2022.pdf -------------------------------------------------------------------------------- /android-plugin/docs/ekko-sonar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/ekko-sonar.png -------------------------------------------------------------------------------- /android-plugin/docs/logoSnapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/logoSnapp.png -------------------------------------------------------------------------------- /android-plugin/docs/logoSolocal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/logoSolocal.png -------------------------------------------------------------------------------- /android-plugin/docs/logoUnivPau.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/logoUnivPau.png -------------------------------------------------------------------------------- /android-plugin/docs/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/docs/screenshot.png -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/foundation/Error.groovy: -------------------------------------------------------------------------------- 1 | class Error { 2 | def name# 3 | def missing 4 | } 5 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rule/NotARule.txt: -------------------------------------------------------------------------------- 1 | class NotARule { 2 | String name = 'DoNothing' 3 | int priority = 2 4 | } -------------------------------------------------------------------------------- /android-plugin/src/test/files/social/gdpr/GoogleAndroidAdsConsentCheck.java: -------------------------------------------------------------------------------- 1 | import com.google.android.ads.consent.Test; 2 | 3 | public class Test { 4 | } -------------------------------------------------------------------------------- /android-plugin/NOTICE.txt: -------------------------------------------------------------------------------- 1 | ecoCode SonarQube plugin 2 | Copyright (C) 2020-2021 Snapp' - Université de Pau et des Pays de l'Adour 3 | mailto: contact@ecocode.io 4 | -------------------------------------------------------------------------------- /CODE_STYLE.md: -------------------------------------------------------------------------------- 1 | Please read common [CODE_STYLE.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CODE_STYLE.md) in `ecoCode-common` repository. 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please read common [CONTRIBUTING.md](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/CONTRIBUTING.md) in `ecoCode-common` repository. -------------------------------------------------------------------------------- /tool_start_withtoken.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # private TOKEN to change once generated in your local SonarQube 4 | TOKEN=MY_TOKEN_TO_REPLACE docker-compose up --build -d -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docs/images/codenarc-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/codenarc-converter/CodeNarc/docs/images/codenarc-logo.png -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/codenarc-converter/CodeNarc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docs/images/forkme_right_red_aa0000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/codenarc-converter/CodeNarc/docs/images/forkme_right_red_aa0000.png -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/JsonRuleSet1.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExplicitCallToEqualsMethod": { "priority": 2}, 3 | "Println": { }, 4 | "SpaceAroundMapEntryColon": { "enabled" : false } 5 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/disable-rules-in-comments/disabling-rules.ruleset: -------------------------------------------------------------------------------- 1 | ruleset { 2 | description 'CodeNarc ruleset for testing disabling rules within comments' 3 | 4 | Println 5 | NoDef 6 | 7 | } -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/Hello.class.toCopy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/Hello.class.toCopy -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/Hello$InnerClass.class.toCopy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/Hello$InnerClass.class.toCopy -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCoSensor_0_7_4/jacoco-ut.exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCoSensor_0_7_4/jacoco-ut.exec -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCoSensor_0_7_5/jacoco-ut.exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCoSensor_0_7_5/jacoco-ut.exec -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/surefire/SurefireSensorTest/roundingTests/TEST-Rounding.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-0.7.4.exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-0.7.4.exec -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-0.7.5.exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-0.7.5.exec -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Ensure all SH files are checked out with LF line endings (regardless of the 2 | # OS they were checked out on). 3 | *.sh text eol=lf 4 | 5 | # Ensure BAT files will always be checked out with CRLFs (regardless of the 6 | # OS they were checked out on). 7 | *.bat text eol=crlf 8 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-it-0.7.4.exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-it-0.7.4.exec -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-it-0.7.5.exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/green-code-initiative/ecoCode-android/HEAD/android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCo_incompatible_merge/jacoco-it-0.7.5.exec -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/android/xml/ecocode_xml_profile.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecoCode Android", 3 | "ruleKeys": [ 4 | "EC540", 5 | "EC541", 6 | "EC542", 7 | "EC543", 8 | "EC544", 9 | "EC545", 10 | "EC546", 11 | "EC548", 12 | "EC549" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore all files and folders starting with ".", except a few exceptions 2 | .* 3 | !.gitignore 4 | !.gitattributes 5 | !.github/ 6 | 7 | # Ignore generated files 8 | target 9 | lib 10 | bin 11 | dependency-reduced-pom.xml 12 | 13 | # Ignore IDE files 14 | *.iml 15 | 16 | # Other ignores 17 | tool_start_withtoken.sh 18 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/foundation/Greet.groovy: -------------------------------------------------------------------------------- 1 | class Greet { 2 | def name 3 | Greet(who) { name = who } 4 | def salute() { println "Hello $name and $name!" } 5 | } 6 | 7 | /** 8 | * Javadoc style 9 | */ 10 | @groovy.beans.Bindable 11 | class Cool { 12 | double x = 1.4 // Comment 13 | } 14 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/codenarc-rule-extrainfo.properties: -------------------------------------------------------------------------------- 1 | # Optional extra information display next to rule names in the rule index and sample rule sets 2 | AbcMetric = Requires the GMetrics jar 3 | CrapMetric = Requires the GMetrics jar and a Cobertura coverage file 4 | CyclomaticComplexity = Requires the GMetrics jar 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3.8-openjdk-11 AS builder 2 | 3 | COPY . /usr/src/ecocode 4 | 5 | WORKDIR /usr/src/ecocode 6 | RUN ./tool_prepare-codenarc.sh 7 | RUN ./tool_build.sh 8 | 9 | FROM sonarqube:10.3.0-community 10 | USER root 11 | COPY --from=builder /usr/src/ecocode/lib/* /opt/sonarqube/extensions/plugins/ 12 | 13 | USER sonarqube 14 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/WeirdCharsRuleSet-,#.txt: -------------------------------------------------------------------------------- 1 | // Example Groovy RuleSet for testing 2 | 3 | import org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule 4 | 5 | ruleset { 6 | description 'A Groovy RuleSet whose filename contains weird, problematic characters' 7 | 8 | EmptyClass 9 | 10 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/codenarc-messages.properties: -------------------------------------------------------------------------------- 1 | # Custom Messages ResourceBundle file for testing. See HtmlReportWriterTest 2 | # WARNING: Do not changes the values within this file 3 | 4 | MyRuleXX.description=My Rule XX 5 | MyRuleXX.description.html=HTML Rule XX 6 | 7 | MyRuleYY.description = My Rule YY 8 | 9 | abc=123 10 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/surefire/SurefireSensorTest/shouldHandleTestSuiteDetails/ExtensionsFinderTest2-expected-result.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/KeepCpuOnXmlRule/KeepCpuOnXmlCheckNoReport.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCoSensor_0_7_4/readme.txt: -------------------------------------------------------------------------------- 1 | Coverage generated using 2 | 3 | mvn clean install 4 | 5 | on project : 6 | 7 | https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/groovy/groovy-sonar-runner-jacoco 8 | 9 | based on commit 10 | 11 | 052dda3ea6c7bfb61e0f7e6cb7b396b7d1d4a92a -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/GroovyRuleSet_Bad.txt: -------------------------------------------------------------------------------- 1 | // Example Groovy RuleSet for testing 2 | 3 | import org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule 4 | 5 | ruleset { 6 | description 'A sample Groovy RuleSet' 7 | 8 | rule(ThrowExceptionFromFinallyBlockRule) { 9 | priority = 3 10 | noSuchProperty = 'abc' 11 | } 12 | } -------------------------------------------------------------------------------- /tool_release_1_prepare.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ### 4 | # PURPOSE : use maven plugin release to prepare locally next release and next SNAPSHOT 5 | ### 6 | 7 | # creation of 2 commits with release and next SNAPSHOT 8 | mvn release:prepare -B -ff -DpushChanges=false -DtagNameFormat=@{project.version} 9 | 10 | sleep 2 11 | 12 | # clean temporary files 13 | mvn release:clean 14 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/IgnoreBatteryOptimizationsXmlRule/IgnoreBatteryOptimizationsXmlCheckNoReport.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/parsing/Sample.groovy: -------------------------------------------------------------------------------- 1 | 2 | class Sample { 3 | String format(Integer i) { 4 | i.toString() 5 | } 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | // file is pretty long 39 | 40 | } 41 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/jacoco/JaCoCoSensor_0_7_5/readme.txt: -------------------------------------------------------------------------------- 1 | Coverage generated using 2 | 3 | mvn clean install -Djacoco.version=0.7.5.201505241946 4 | 5 | on project : 6 | 7 | https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/groovy/groovy-sonar-runner-jacoco 8 | 9 | based on commit 10 | 11 | 052dda3ea6c7bfb61e0f7e6cb7b396b7d1d4a92a -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC533.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "GDPR: Google Consent", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "0min" 8 | }, 9 | "tags": [ 10 | "gdpr", 11 | "social", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Info" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/surefire/SurefireSensorTest/shouldHandleTestSuiteDetails/ExtensionsFinderTest3-expected-result.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rule/DoNothingRule.txt: -------------------------------------------------------------------------------- 1 | import org.codenarc.rule.AbstractRule 2 | import org.codenarc.rule.Violation 3 | import org.codenarc.source.SourceCode 4 | 5 | class DoNothingRule extends AbstractRule { 6 | String name = 'DoNothing' 7 | int priority = 2 8 | 9 | void applyTo(SourceCode sourceCode, List violations) { 10 | // Do nothing 11 | } 12 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC501.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Batch: Job Coalesce", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "3h" 8 | }, 9 | "tags": [ 10 | "batch", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC532.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Privacy: Google Tracker", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "privacy", 11 | "social", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC534.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Privacy: Tracking Id", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "privacy", 11 | "social", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC542.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Keep CPU On", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1h" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC545.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Power: Charge Awareness", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "0min" 8 | }, 9 | "tags": [ 10 | "power", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Info" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC500.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Batch: Sensor Coalesce", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "batch", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC507.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Keep Cpu On", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1h" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC509.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Rigid Alarm", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1d" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC512.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Leakage: Camera Leak", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "leakage", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Critical" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC513.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Leakage: Location Leak", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "leakage", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC519.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Power: Charge Awareness", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "0min" 8 | }, 9 | "tags": [ 10 | "power", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Info" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC520.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Power: Save Mode Awareness", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "0min" 8 | }, 9 | "tags": [ 10 | "power", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Info" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC540.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Batch: Service Boot Time", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "batch", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC546.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Power: Save Mode Awareness", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "0min" 8 | }, 9 | "tags": [ 10 | "power", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Info" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC548.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Dark UI (Theme)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1h" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC508.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Durable Wake Lock", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC511.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Keep Voice Awake", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC514.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Leakage: SensorManager Leak", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "leakage", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC528.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Vibration Free", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "5min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC530.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Torch Free", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "5min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } 18 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC531.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: High Frame Rate", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "5min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC541.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Keep Screen On", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC543.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Power: Compagnion In Background", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "power", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/RuleSet1.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tool_prepare-codenarc.bat: -------------------------------------------------------------------------------- 1 | REM == Define CodeNarc version 2 | set codenarc_version=2.2.5 3 | 4 | REM == Build CodeNarc 5 | cd codenarc-converter/CodeNarc 6 | call ./gradlew build -x test 7 | 8 | REM == Deploy to local repository 9 | cd .. 10 | mvn -B install:install-file -Dfile=CodeNarc/build/libs/CodeNarc-%codenarc_version%.jar -DgroupId=org.codenarc -DartifactId=CodeNarc -Dversion=%codenarc_version% -Dpackaging=jar 11 | -------------------------------------------------------------------------------- /tool_prepare-codenarc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Define CodeNarc version 4 | codenarcVersion="2.2.5" 5 | 6 | # Build CodeNarc 7 | cd codenarc-converter/CodeNarc 8 | ./gradlew build -x test 9 | 10 | # Deploy to local repository 11 | cd .. 12 | mvn -B install:install-file -Dfile=CodeNarc/build/libs/CodeNarc-${codenarcVersion}.jar -DgroupId=org.codenarc -DartifactId=CodeNarc -Dversion=${codenarcVersion} -Dpackaging=jar 13 | 14 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC510.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Continuous Rendering", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC516.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Leakage: Media Leak (MediaPlayer)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "leakage", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC521.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Motion Sensor", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "5min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC522.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Brightness Override", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC544.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Power: Ignore Battery Optimizations", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1h" 8 | }, 9 | "tags": [ 10 | "power", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC547.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Dark UI (Bright Colors)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1h" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC549.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Hardware acceleration", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "1min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC502.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Bottleneck: Internet In The Loop", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "3h" 8 | }, 9 | "tags": [ 10 | "optimized-api", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Critical" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC503.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Bottleneck: Wifi Multicast Lock", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "bottleneck", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC505.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Keep Screen On (addFlags)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC506.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Idleness: Keep Screen On (setFlags)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "idleness", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC515.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Leakage: Media Leak (MediaRecorder)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "leakage", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC517.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Optimized API: Fused Location", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "optimized-api", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC529.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Notification", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "5min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } 18 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC518.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Optimized API: Bluetooth Low-Energy", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "optimized-api", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC523.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Geolocation (minTime)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC524.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Geolocation Criteria", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "20min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } 18 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC527.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Geolocation (minDistance)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rule/DoesNotCompileRule.txt: -------------------------------------------------------------------------------- 1 | import org.codenarc.rule.AbstractRule 2 | import org.codenarc.rule.Violation 3 | import org.codenarc.source.SourceCode 4 | 5 | class DoesNotCompileRule extends AbstractRule { 6 | String name = 'DoNothing' 7 | int priority = 2 8 | 9 | void applyTo(SourceCode sourceCode, List violations) { 10 | &^%$%^ This definitely won't compile 11 | } 12 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC504.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Bottleneck: Uncompressed Data Transmission", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "bottleneck", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Minor" 17 | } 18 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/NOTICE.txt: -------------------------------------------------------------------------------- 1 | ====================================================================== 2 | == NOTICE file corresponding to section 4 d of the Apache License, == 3 | == Version 2.0, in this case for the CodeNarc distribution. == 4 | ====================================================================== 5 | 6 | This product includes software developed by 7 | the Apache Software Foundation (http://www.apache.org). 8 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC525.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Bluetooth Low Energy (setAdvertiseMode)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # / 3 | /.classpath 4 | /.settings 5 | /.project 6 | /hamlet_docs 7 | /*.patch 8 | /*.iws 9 | *.iml 10 | /*.ipr 11 | /AntBuilderTestXmlReport.xml 12 | /*.html 13 | /target 14 | /AntBuilderTestTextReport.txt 15 | /CodeNarcReport.txt 16 | /CodeNarcXmlReport.xml 17 | /*CodeNarcReport.xml 18 | /.idea 19 | build/ 20 | src/main/java/META-INF/ 21 | /.gradle 22 | /classes 23 | /out 24 | /integration-test/out/test/classes 25 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC526.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Sobriety: Thrifty Bluetooth Low Energy (requestConnectionPriority)", 3 | "type": "CODE_SMELL", 4 | "status": "ready", 5 | "remediation": { 6 | "func": "Constant\/Issue", 7 | "constantCost": "10min" 8 | }, 9 | "tags": [ 10 | "sobriety", 11 | "environment", 12 | "ecocode", 13 | "android", 14 | "eco-design" 15 | ], 16 | "defaultSeverity": "Major" 17 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/override-codenarc.properties: -------------------------------------------------------------------------------- 1 | # Test-only properties - Used by PropertiesFileRuleSetConfigurerTest 2 | 3 | # PropertiesFileRuleSetConfigurerTest 4 | rule1.priority=2 5 | rule2.violationMessage = override 6 | other.priority = 1 7 | rule2.other.form = ignore this 8 | 9 | # Not allowed to override rule name 10 | rule2.name = NewName_IgnoreThis 11 | 12 | # CodeNarcTaskTest 13 | TestPath.priority=3 14 | #TestPath.description=problem -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/GroovyRuleSet2.txt: -------------------------------------------------------------------------------- 1 | // Example Groovy RuleSet for testing 2 | 3 | import org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule 4 | 5 | ruleset { 6 | 7 | ruleset('rulesets/GroovyRuleSet1.txt') { 8 | 'CatchThrowable' { 9 | priority = 3 10 | } 11 | } 12 | 13 | rule(org.codenarc.rule.generic.StatelessClassRule) { 14 | addToIgnoreFieldNames = '*Test*' 15 | } 16 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/integration-test/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'groovy' 3 | id 'idea' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | testImplementation project(':'), { 12 | exclude group: 'org.codehaus.groovy' 13 | } 14 | testImplementation gradleTestKit() 15 | testImplementation 'junit:junit:4.12' 16 | } 17 | 18 | test { 19 | systemProperty 'codenarc.test.projectPath', rootProject.projectDir.absolutePath 20 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/RuleSet3.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android-plugin/src/test/java/io/ecocode/xml/checks/sobriety/HardwareAccelerationXmlRuleTest.java: -------------------------------------------------------------------------------- 1 | package io.ecocode.xml.checks.sobriety; 2 | 3 | import org.junit.Test; 4 | import org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheckVerifier; 5 | 6 | public class HardwareAccelerationXmlRuleTest { 7 | 8 | @Test 9 | public void detectExplicitOrImplicitHardwareAcceleration() { 10 | SonarXmlCheckVerifier.verifyIssues("HardwareAccelerationCheck.xml", new HardwareAccelerationXmlRule()); 11 | } 12 | } -------------------------------------------------------------------------------- /tool_release_2_branch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ### 4 | # PURPOSE : create an push an new branch with commits previously prepared with `tool_release_1_prepare.sh` 5 | ### 6 | 7 | # checkout released tag and creation of branch to push (becasue of main protection) 8 | LAST_TAG=$(git tag --sort=-version:refname | head -n 1) 9 | BRANCH_NAME=$(echo "release_${LAST_TAG}") 10 | git checkout -b ${BRANCH_NAME} 11 | 12 | # push branch associated to new tag release 13 | git push --set-upstream origin ${BRANCH_NAME} 14 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/KeepCpuOnXmlRule/KeepCpuOnXmlCheckReport.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC533.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Good Practice ! 4 | User consent checked. 5 |

6 |

7 | To support publishers in meeting their duties under the EU User Consent Policy, Google offers a Consent SDK. 8 | Hence, importing classes from com.google.android.ads.consent.* or com.google.android.ump.* 9 | since Android API 21 is considered as a good practice. 10 |

11 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/exportProfile/exportNullParameters.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | EcoCode rule set. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/templates/StarterRuleSet-AllRules.groovy.template: -------------------------------------------------------------------------------- 1 | ruleset { 2 | 3 | description ''' 4 | A Sample Groovy RuleSet containing all CodeNarc Rules 5 | You can use this as a template for your own custom RuleSet. 6 | Just delete the rules that you don't want to include. 7 | ''' 8 | 9 | <% rules.each { rule -> def extraInfo = ruleExtraInformation[rule.name] ? " // ${ruleExtraInformation[rule.name]}" : '' %>${rule.name} ${extraInfo} 10 | <% } %> 11 | } -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/surefire/api/SurefireUtilsTest/shouldGetReportsFromProperty/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | fake.group 5 | fake.artifactId 6 | jar 7 | 1.0-SNAPSHOT 8 | 9 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/exportProfile/exportFixedRules.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/templates/codenarc-rule-index-by-name.md.template: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: CodeNarc - Rule Index by Name 4 | --- 5 | 6 | # Rule Index by Name 7 | 8 | **CodeNarc** includes ${numberOfRules} rules. 9 | 10 | ## Rules 11 | <% ruleToRuleSetMap.each { rule, ruleSetName -> def extraInfo = ruleExtraInformation[rule.name] ? " (${ruleExtraInformation[rule.name]})" : '' %>\ 12 | * [${rule.name}](./codenarc-rules-${ruleSetName}.html#${rule.name.toLowerCase()}-rule) ${extraInfo} 13 | <% } %> 14 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/GroovyRuleSet1.txt: -------------------------------------------------------------------------------- 1 | // Example Groovy RuleSet for testing 2 | 3 | import org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule 4 | 5 | ruleset { 6 | description 'A sample Groovy RuleSet' 7 | 8 | ruleset('rulesets/RuleSet4.xml') { 9 | 'CatchThrowable' { 10 | priority = 1 11 | enabled = false 12 | } 13 | include 'CatchThrowable' 14 | } 15 | 16 | rule(ThrowExceptionFromFinallyBlockRule) { 17 | priority = 3 18 | } 19 | } -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/IgnoreBatteryOptimizationsXmlRule/IgnoreBatteryOptimizationsXmlCheckReport.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/GroovyRuleSet1.groovy: -------------------------------------------------------------------------------- 1 | // Example Groovy RuleSet for testing 2 | 3 | 4 | import org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule 5 | 6 | ruleset { 7 | description 'A sample Groovy RuleSet' 8 | 9 | ruleset('rulesets/RuleSet4.xml') { 10 | 'CatchThrowable' { 11 | priority = 1 12 | enabled = false 13 | } 14 | include 'CatchThrowable' 15 | } 16 | 17 | rule(ThrowExceptionFromFinallyBlockRule) { 18 | priority = 3 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/exportProfile/exportProfile.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docker/README.md: -------------------------------------------------------------------------------- 1 | # README for CodeNarc Dockerfile 2 | 3 | To build the image: 4 | 5 | docker build -t codenarc . 6 | # or 7 | docker build -t codenarc --build-arg CODENARC_VERSION=1.6.1 --build-arg GROOVY_VERSION=3.0.6 . 8 | 9 | To run: 10 | 11 | docker run --rm -v `pwd`:/ws --user `id -u`:`id -g` codenarc 12 | 13 | # or (assumes there is a "codenarc.ruleset" file in the current directory) 14 | docker run --rm -v `pwd`:/ws --user `id -u`:`id -g` codenarc -report=json -rulesetfiles=file:codenarc.ruleset 15 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/exportProfile/exportParameters.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/gmetrics/Greeting.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Header Comment 3 | * plop 4 | */ 5 | package example; 6 | 7 | class Greeting { 8 | 9 | def void sayHello() { 10 | if (true) { 11 | print "Hello world!" 12 | } else { 13 | } 14 | } 15 | 16 | } 17 | 18 | class OneMoreClass { //comment line 19 | 20 | def void sayHello() { 21 | /* 22 | * Multi-line comment 23 | * 24 | * with empty lines. 25 | */ 26 | if (true) { 27 | // 28 | print "Hello world!" 29 | } else { 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/ServiceBootTimeXmlRule/ServiceBootTimeXmlCheck.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/RuleSet4.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/exportProfile/exportEscapedParameters.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/CompagnionInBackgroundXmlRule/CompagnionInBackgroundXmlCheck.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docs/_data/navigation.yml: -------------------------------------------------------------------------------- 1 | sidebar-nav: 2 | - title: "General" 3 | children: 4 | - title: "Home" 5 | url: http://codenarc.org 6 | - title: "Downloads" 7 | url: https://github.com/CodeNarc/CodeNarc/releases 8 | - title: "GitHub Project" 9 | url: https://github.com/CodeNarc 10 | - title: "Running" 11 | children: 12 | - title: "Ant Task Usage" 13 | url: / 14 | - title: "Command-line" 15 | url: / 16 | - title: "Run as a Test" 17 | url: / 18 | - title: "Other Tools/Frameworks" 19 | url: / 20 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/codenarc.properties: -------------------------------------------------------------------------------- 1 | # Test-only properties - Used by PropertiesFileRuleSetConfigurerTest, CodeNarcTaskTest and CodeNarcTaskAllRuleSetsTest 2 | 3 | # PropertiesFileRuleSetConfigurerTest 4 | rule1.priority=3 5 | rule2.violationMessage = violation 6 | other.priority = 1 7 | rule2.other.form = ignore this 8 | 9 | # CodeNarcTaskTest 10 | TestPath.priority=3 11 | #TestPath.description=problem 12 | 13 | # CodeNarcTaskAllRuleSetsTest 14 | StatelessClass.enabled = false 15 | DuplicateNumberLiteral.enabled = false 16 | DuplicateStringLiteral.enabled = false 17 | UnnecessaryGetter.enabled = false -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/templates/StarterRuleSet-AllRulesByCategory.groovy.template: -------------------------------------------------------------------------------- 1 | ruleset { 2 | 3 | description ''' 4 | A Sample Groovy RuleSet containing all CodeNarc Rules, grouped by category. 5 | You can use this as a template for your own custom RuleSet. 6 | Just delete the rules that you don't want to include. 7 | ''' 8 | 9 | <% ruleSets.each { name, rules -> %>// ${name} 10 | <% rules.each { rule -> def extraInfo = ruleExtraInformation[rule.name] ? " // ${ruleExtraInformation[rule.name]}" : '' %>${rule.name} ${extraInfo} 11 | <% } %> 12 | <% } %> 13 | } -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/CustomRuleSet.groovy: -------------------------------------------------------------------------------- 1 | ruleset { 2 | description 'A custom Groovy RuleSet (see CodeNarcTask_CustomRuleSetTest)' 3 | 4 | CyclomaticComplexity { 5 | maxMethodComplexity = 1 6 | } 7 | 8 | ClassName 9 | 10 | MethodName 11 | 12 | ConfusingTernary(priority:3) 13 | 14 | StatelessClass { 15 | name = 'StatelessDao' 16 | applyToClassNames = '*Dao' 17 | } 18 | 19 | // Old style 20 | rule(org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule) { 21 | priority = 3 22 | } 23 | ruleset('rulesets/dry.xml') 24 | 25 | } 26 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC547.html: -------------------------------------------------------------------------------- 1 | 2 |

Displaying dark colors is particularly beneficial for mobile devices with (AM)OLED screens.
3 | Consequently, custom resources like bright colors values and bitmap images with too high luminance should be avoided.

4 |

Noncompliant Code Example

5 |
 6 |     <TextView
 7 |         android:layout_width="match_parent"
 8 |         android:layout_height="match_parent"
 9 |         android:foreground="#FFFFFF"
10 |         android:foregroundTint="#FFFFFF">
11 |     </TextView>
12 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC543.html: -------------------------------------------------------------------------------- 1 | 2 |

A negative effect on the device s battery is when an app is paired with a companion device (over Bluetooth, BLE, or Wi-Fi) 3 | and that it has been excluded from battery optimizations (run in the background) using the declaration 4 | Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND.

5 |

Noncompliant Code Example

6 |
 7 |     <manifest>
 8 |        <uses-permission android:name="android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND">
 9 |     </manifest>
10 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC505.html: -------------------------------------------------------------------------------- 1 | 2 |

To avoid draining the battery, an Android device that is left idle quickly falls asleep.
3 | Hence, keeping the screen on should be avoided, unless it is absolutely necessary. If so, developers typically 4 | use the FLAG_KEEP_SCREEN_ON in their activity. Another way to implement this is in their application's 5 | layout XML file, by using the android:keepScreenOn attribute.

6 |

Noncompliant Code Example

7 |
 8 |     getWindow().addFlags(FLAG_KEEP_SCREEN_ON);
 9 | 
10 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/templates/codenarc-rule-index.md.template: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: CodeNarc - Rule Index 4 | --- 5 | 6 | # Rule Index 7 | 8 | **CodeNarc** includes ${numberOfRules} rules. 9 | <% ruleSets.each { name, rules ->\ 10 | def ruleSetLink = "./codenarc-rules-${name}.html" 11 | def capitalizedName = name.capitalize() %> 12 | ## [$capitalizedName]($ruleSetLink) 13 | <% rules.each { rule -> def extraInfo = ruleExtraInformation[rule.name] ? " (${ruleExtraInformation[rule.name]})" : '' %>\ 14 | * [${rule.name}](./codenarc-rules-${name}.html#${rule.name.toLowerCase()}-rule) ${extraInfo} 15 | <% } } %> 16 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/README.md: -------------------------------------------------------------------------------- 1 | # These files are GENERATED 2 | 3 | The files from this folder are **generated** directly from our rules descriptions project. 4 | 5 | Consequently, do not attempt to manually modify files here, nor submit Pull Request (PR) modifying description 6 | or rule metatada. Any PR will be systematically rejected. 7 | 8 | If you want to: 9 | 10 | * update descriptions; 11 | * extends their content; 12 | * fix misleading content; 13 | * adjust rule metadata; 14 | * etc. 15 | 16 | Then, please reach us though our mail , prior to submitting any code change. 17 | 18 | Thanks, 19 | *The ecoCode Team* 20 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/README.md: -------------------------------------------------------------------------------- 1 | # These files are GENERATED 2 | 3 | The files from this folder are **generated** directly from our rules descriptions project. 4 | 5 | Consequently, do not attempt to manually modify files here, nor submit Pull Request (PR) modifying description 6 | or rule metatada. Any PR will be systematically rejected. 7 | 8 | If you want to: 9 | 10 | * update descriptions; 11 | * extends their content; 12 | * fix misleading content; 13 | * adjust rule metadata; 14 | * etc. 15 | 16 | Then, please reach us though our mail , prior to submitting any code change. 17 | 18 | Thanks, 19 | *The ecoCode Team* 20 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | preferred-citation: 4 | type: conference-paper 5 | conference: 6 | name: "Automated Software Engineering" 7 | collection-title: "Proceedings of the 37th IEEE/ACM International Conference on Automated Software Engineering" 8 | publisher: ACM 9 | authors: 10 | - family-names: "Le Goaër" 11 | given-names: "Olivier" 12 | orcid: "https://orcid.org/0000-0001-5405-1688" 13 | - family-names: "Hertout" 14 | given-names: "Julien" 15 | title: "ecoCode: A SonarQube Plugin to Remove Energy Smells from Android Projects" 16 | doi: 10.1145/3551349.3559518 17 | year: 2022 18 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC506.html: -------------------------------------------------------------------------------- 1 | 2 |

To avoid draining the battery, an Android device that is left idle quickly falls asleep.
3 | Hence, keeping the screen on should be avoided, unless it is absolutely necessary. If so, developers typically 4 | use the FLAG_KEEP_SCREEN_ON in their activity. Another way to implement this is in their application's 5 | layout XML file, by using the android:keepScreenOn attribute.

6 |

Noncompliant Code Example

7 |
 8 |     getWindow().setFlags(FLAG_KEEP_SCREEN_ON, FLAG_KEEP_SCREEN_ON);
 9 | 
10 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/parsing/line-number-not-specified.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/NestedRuleSet1.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | # must be unique in a given SonarQube instance 2 | sonar.projectKey=sonar-custom-plugin-example 3 | 4 | # --- optional properties --- 5 | 6 | # defaults to project key 7 | #sonar.projectName=My project 8 | # defaults to 'not provided' 9 | #sonar.projectVersion=1.0 10 | 11 | # Path is relative to the sonar-project.properties file. Defaults to . 12 | #sonar.sources=. 13 | 14 | # Encoding of the source code. Default is default system encoding 15 | #sonar.sourceEncoding=UTF-8 16 | 17 | sonar.eslint.reportPaths=/opt/project/eslint-report.json 18 | sonar.css.stylelint.reportPaths=/opt/project/stylelint-report.json 19 | sonar.java.binaries=/opt/project/java-plugin/target/classes 20 | sonar.scm.disabled=true -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/rulesets/RuleSet2.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC532.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Importing the com.google.android.gms.analytics.Tracker or com.google.firebase.analytics.FirebaseAnalytics classes means that the app sends hits to Google Analytics. It is not necessarily sensitive information, but it is a first step towards Google Ads and hence this practice should be discouraged at early stage. 4 |

5 |

Noncompliant Code Example

6 | Import of Google Analytics : 7 |
 8 |     import com.google.android.gms.analytics.Tracker
 9 | 
10 | Import of Firebase Analytics : 11 |
12 |     import com.google.firebase.analytics
13 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC544.html: -------------------------------------------------------------------------------- 1 | 2 |

An app holding the permission REQUEST_IGNORE_BATTERY_OPTIMIZATIONS asks the user to allow it to ignore 3 | battery optimizations (that is, put them on the whitelist of apps).

4 |

Most applications should not use this; there are many facilities provided by the platform for applications to 5 | operate correctly in the various power saving modes.

6 | 7 |

Noncompliant Code Example

8 |
 9 |     <manifest>
10 |         <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
11 |     </manifest>
12 | 
13 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/disable-rules-in-comments/Sample.groovy: -------------------------------------------------------------------------------- 1 | class MyClass { // codenarc-disable 2 | 3 | def maxValue = 10 4 | /* codenarc-enable */ 5 | 6 | def myMethod(def name) { // codenarc-disable NoDef 7 | def other = 123 8 | // codenarc-enable NoDef 9 | 10 | /* codenarc-disable NoDef, Println */ 11 | println other 12 | /* codenarc-enable NoDef, Println */ 13 | 14 | println "name=$name" /*codenarc-disable-line*/ 15 | } 16 | 17 | private void doStuff() { // codenarc-disable-line NoDef 18 | 19 | // codenarc-disable R1, R2, R3, R4, NoDef 20 | def count = 99 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC522.html: -------------------------------------------------------------------------------- 1 | 2 |

Introduced in Android 9, the adaptive brightness feature raises or lower the brightness of the screen depending on 3 | the light in the current environment.
4 | For some reasons, developers may disable this feature programmatically, setting the field 5 | WindowManager.LayoutParams#screenBrightness with the constant BRIGHTNESS_OVERRIDE_FULL.
6 | This feature was introduced to improve battery life, be careful when deactivating it.

7 |

Noncompliant Code Example

8 |
 9 |     getWindow().getAttributes().screenBrightness = BRIGHTNESS_OVERRIDE_FULL;
10 | 
11 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC530.html: -------------------------------------------------------------------------------- 1 | 2 |

Turning on the torch mode programmatically with CameraManager#setTorchMode(..., true) must absolutely be 3 | avoided because the flashlight is one of the most energy-intensive component.

4 |

Noncompliant Code Example

5 |
 6 |  CameraManager camManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
 7 |         String cameraId = null;
 8 |         try {
 9 |             cameraId = camManager.getCameraIdList()[0];
10 |             camManager.setTorchMode(cameraId, true);
11 |         } catch (CameraAccessException e) {
12 |             e.printStackTrace();
13 |         }
14 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/android/java/ecocode_java_profile.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecoCode Android", 3 | "ruleKeys": [ 4 | "EC500", 5 | "EC501", 6 | "EC502", 7 | "EC503", 8 | "EC504", 9 | "EC505", 10 | "EC506", 11 | "EC507", 12 | "EC508", 13 | "EC509", 14 | "EC510", 15 | "EC511", 16 | "EC512", 17 | "EC513", 18 | "EC514", 19 | "EC515", 20 | "EC516", 21 | "EC517", 22 | "EC518", 23 | "EC519", 24 | "EC520", 25 | "EC521", 26 | "EC522", 27 | "EC523", 28 | "EC524", 29 | "EC525", 30 | "EC526", 31 | "EC527", 32 | "EC528", 33 | "EC529", 34 | "EC530", 35 | "EC531", 36 | "EC532", 37 | "EC533", 38 | "EC534" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/KeepScreenOnXmlRule/KeepScreenOnXmlCheckFalse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/KeepScreenOnXmlRule/KeepScreenOnXmlCheckTrue.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC518.html: -------------------------------------------------------------------------------- 1 | 2 |

In contrast to classic Bluetooth, Bluetooth Low Energy (BLE) 3 | is designed to provide significantly lower power consumption. 4 | Its purpose is to save energy on both paired devices but very few 5 | developers are aware of this alternative API. 6 | From the Android client side, it means append android.bluetooth.le.* 7 | imports to android.bluetooth.* imports in order to benefits from 8 | low-energy features.

9 |

Noncompliant Code Example

10 |
11 |     import android.bluetooth.*
12 | 
13 |

Compliant Solution

14 |
15 |     import android.bluetooth.le.*
16 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC515.html: -------------------------------------------------------------------------------- 1 | 2 |

Creation of a Media Recorder object with new MediaRecorder() is used to record 3 | audio and video. Class own a release() method.

4 |

In addition to unnecessary resources (such as memory and instances of codecs) being held, 5 | failure to call this method immediately if a media object is no longer needed may also lead to 6 | continuous battery consumption for mobile devices.

7 |

Noncompliant Code Example

8 |
 9 |     MediaRecorder mr = new MediaRecorder();
10 | 
11 |

Compliant Solution

12 |
13 |     MediaRecorder mr = new MediaRecorder();
14 |     mr.release();
15 | 
16 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC542.html: -------------------------------------------------------------------------------- 1 | 2 |

To avoid draining the battery, an Android device that is left idle quickly falls asleep. 3 | Hence, keeping the screen on should be avoided, unless it is absolutely necessary.
4 | If so, developers typically use a Power Manager system service feature called wake locks 5 | by invoking PowerManager.WakeLock#newWakeLock(int levelAndFlags, String tag), 6 | along with the specific permission WAKE_LOCK in their manifest.

7 |

Noncompliant Code Example

8 |
 9 |     <manifest>
10 |         <uses-permission android:name="android.permission.WAKE_LOCK" />
11 |     </manifest>
12 | 
13 | -------------------------------------------------------------------------------- /android-plugin/src/test/resources/checks/DarkUIBrightColorsXmlRule/DarkUIBrightColorsXmlCheckResources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | #000000 5 | #FFBB86FC 6 | #FF6200EE 7 | #FF3700B3 8 | #FF03DAC5 9 | #FF018786 10 | #FF000000 11 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/xml/EC546.html: -------------------------------------------------------------------------------- 1 | 2 |

Taking into account when the device is entering or exiting the power save mode is higly desirable for the battery 3 | life. 4 | It implies the existence of a broadcast receiver registered on the action 5 | ACTION_POWER_SAVE_MODE_CHANGED, 6 | or programmaticaly with a call to PowerManager#isPowerSaveMode().

7 |

Compliant Code Example

8 |
 9 |     <receiver android:name="io.ecocode.testapp.core.service.MyReceiver">
10 |         <intent-filter>
11 |             <action android:name="android.intent.action.BATTERY_CHANGED"/>
12 |         </intent-filter>
13 |     </receiver>
14 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC516.html: -------------------------------------------------------------------------------- 1 | 2 |

Creation of a Media Player object with new MediaPlayer() can 3 | be used to control playback of audio/video files and streams. Class own arelease() method.

4 |

In addition to unnecessary resources (such as memory and instances of codecs) being held, 5 | failure to call this method immediately if a media object is no longer needed may also lead to 6 | continuous battery consumption for mobile devices.

7 |

Noncompliant Code Example

8 |
 9 |     MediaPlayer mp = new MediaPlayer();
10 | 
11 |

Compliant Solution

12 |
13 |     MediaPlayer mp = new MediaPlayer();
14 |     mp.release();
15 | 
16 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC531.html: -------------------------------------------------------------------------------- 1 | 2 |

In Android 11 (API level 30) or higher, a call to 3 | Surface#setFrameRate(float frameRate, int compatibility) results in a change to the display refresh 4 | rate. However, a regular app displays 60 frames per second (60Hz). In order to optimize content refreshes and hence 5 | saving energy, this frequency should not be raised to 90Hz or 120Hz, despite this is now supported by many devices. 6 |

7 |

Noncompliant Code Example

8 |
 9 |     surface.setFrameRate(120f, FRAME_RATE_COMPATIBILITY_DEFAULT);
10 | 
11 |

Compliant Code Example

12 |
13 |     surface.setFrameRate(60f, FRAME_RATE_COMPATIBILITY_DEFAULT);
14 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/jdbc.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | JDBC rule set. 8 | These rules check for JDBC-specific violations. 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC507.html: -------------------------------------------------------------------------------- 1 | 2 |

To avoid draining the battery, an Android device that is left idle quickly falls asleep. 3 | Hence, keeping the CPU on should be avoided, unless it is absolutely necessary.
4 | If so, developers typically use a Power Manager system service feature called wake locks 5 | by invoking PowerManager.WakeLock#newWakeLock(int levelAndFlags, String tag), 6 | along with the specific permission WAKE_LOCK in their manifest.

7 |

Noncompliant Code Example

8 |
 9 |     PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
10 |     WakeLock manager = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TAG");
11 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/templates/codenarc-rule-index.apt.template: -------------------------------------------------------------------------------- 1 | -------------------------------------------------- 2 | CodeNarc - Rule Index 3 | -------------------------------------------------- 4 | 5 | Rule Index 6 | ~~~~~~~~~~ 7 | <> includes ${numberOfRules} rules. 8 | 9 | <% ruleSets.each { name, rules -> %> 10 | <% def ruleSetLink = "./codenarc-rules-${name}.html" %> 11 | <% def capitalizedName = name.capitalize() %> 12 | * {{{$ruleSetLink}$capitalizedName}} 13 | <% rules.each { rule -> %> 14 | <% def extraInfo = ruleExtraInformation[rule.name] ? " (${ruleExtraInformation[rule.name]})" : '' %> 15 | * {{{./codenarc-rules-${name}.html#${rule.name}}${rule.name}}} ${extraInfo} 16 | <% } %> 17 | <% } %> 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /android-plugin/src/test/java/io/ecocode/java/checks/social/gdpr/GoogleAndroidAdsConsentRuleTest.java: -------------------------------------------------------------------------------- 1 | package io.ecocode.java.checks.social.gdpr; 2 | 3 | import org.junit.Test; 4 | import org.sonar.java.checks.verifier.CheckVerifier; 5 | 6 | public class GoogleAndroidAdsConsentRuleTest { 7 | @Test 8 | public void verify() { 9 | 10 | CheckVerifier.newVerifier().onFile("src/test/files/social/privacy/GoogleTrackerGoogleCheck.java") 11 | .withCheck(new GoogleAndroidAdsConsentRule()) 12 | .verifyNoIssues(); 13 | CheckVerifier.newVerifier().onFile("src/test/files/social/gdpr/GoogleAndroidAdsConsentCheck.java") 14 | .withCheck(new GoogleAndroidAdsConsentRule()) 15 | .verifyIssueOnProject("Good Smell : User Consent"); 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/braces.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Braces rule set. 8 | These rules implement standards and best practices related to using braces. 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/dry.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Dry rule set. 8 | These rules check for duplicate code, enforcing the DRY (Don't Repeat Yourself) principle. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC534.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | For some use cases, it might be necessary to get a unique device identifier by a call to TelephonyManager#getDeviceId() 4 | (returns IMEI on GSM, MEID for CDMA). 5 | However, this raises privacy concerns and it is not recommended. 6 | Alternatively, you may use android.provider.Settings.Secure.ANDROID_ID. 7 |

8 |

Noncompliant Code Example

9 | Use of: TelephonyManager#.getDeviceId() 10 |
11 |     TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
12 |     String deviceId = telephonyManager.getDeviceId()
13 | 
14 | Use : 15 |
16 |     android.provider.Settings.Secure.ANDROID_ID
17 | 
18 | 19 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC502.html: -------------------------------------------------------------------------------- 1 | 2 |

Opening and closing internet connection continuously is extremely battery-inefficient since HTTP exchange is the most 3 | consuming operation of the network. This bug typically occurs when one obtain a new HttpURLConnection 4 | by calling URL#openConnection() within a loop control structure (while, for, do-while, for-each).
5 | Also, this bad practice must be early prevented because it is the root of another evil that consists in polling 6 | data at regular intervals, instead of using push notifications to save a lot of battery power.

7 |

Noncompliant Code Example

8 |
 9 |     for (int val : myArray) {
10 |         URL.openConnection();
11 |     }
12 | 
13 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC520.html: -------------------------------------------------------------------------------- 1 | 2 |

Taking into account when the device is entering or exiting the power save mode is higly desirable for the battery 3 | life. 4 | It implies the existence of a broadcast receiver registered on the action 5 | ACTION_POWER_SAVE_MODE_CHANGED, 6 | or programmaticaly with a call to PowerManager#isPowerSaveMode().

7 |

Compliant Code Example

8 |
 9 |     new IntentFilter(Intent.ACTION_POWER_SAVE_MODE_CHANGED)
10 | 
11 | OR 12 |
13 |     intentFilter.addAction(ACTION_POWER_SAVE_MODE_CHANGED)
14 | 
15 | OR 16 |
17 |     IntentFilter.create(ACTION_POWER_SAVE_MODE_CHANGED,"")
18 | 
19 | OR 20 |
21 |     powerManager.isPowerSaveMode()
22 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/source/SourceFile1.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package source 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class SourceFile1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/serialization.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Serialization rule set. 8 | These rules check for Java serialization-specific violations. 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/SourceFile1.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewithdirs 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class SourceFile1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir1/Subdir1File1.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewithdirs.subdir1 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class Subdir1File1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir1/Subdir1File2.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewithdirs.subdir1 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class Subdir1File2 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir2/Subdir2File1.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewithdirs.subdir2 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class Subdir2File1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewitherrors/SourceFile1.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewitherrors 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class SourceFile1 { 24 | 25 | String name 26 | 27 | } 28 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir2/subdir2a/Subdir2aFile1.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewithdirs.subdir2.subdir2a 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class Subdir2aFile1 { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC517.html: -------------------------------------------------------------------------------- 1 | 2 |

The fused location provider is one of the location APIs in Google Play 3 | services which combines signals from GPS, Wi-Fi, and cell networks, as well 4 | as accelerometer, gyroscope, magnetometer and other sensors. It is officially 5 | recommended to maximize battery life.
6 | Thus, developer has to set up Google Play Service in her gradle file with a dependency to 7 | com.google.android.gms:play-services-location:x.y.z, and then to 8 | import from com.google.android.gms.location instead of the 9 | android.location package of the SDK.

10 |

Noncompliant Code Example

11 |
12 |     import android.location.*;
13 | 
14 |

Compliant Solution

15 |
16 |     import com.google.android.gms.location.*;
17 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/test/resources/sourcewitherrors/SourceFileWithCompileError.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package sourcewitherrors 17 | 18 | /** 19 | * Source file for testing 20 | * 21 | * @author Chris Mair 22 | */ 23 | class SourceFileWithCompileError { 24 | 25 | !$%^ 26 | 27 | } 28 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC510.html: -------------------------------------------------------------------------------- 1 | 2 |

For developers wishing to display OpenGL rendering, when choosing the rendering mode 3 | with GLSurfaceView#setRenderMode(int renderMode), 4 | using RENDERMODE_WHEN_DIRTY instead of RENDERMODE_CONTINUOUSLY 5 | (by default) can improve battery life and overall system performance by allowing the GPU and CPU 6 | to idle when the view does not need to be updated.

7 |

Noncompliant Code Example

8 |
 9 |      GLSurfaceView surfaceView = new GLSurfaceView(this);
10 |      surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY)
11 | 
12 |
13 |

Compliant Code Example

14 |
15 |      GLSurfaceView surfaceView = new GLSurfaceView(this);
16 |      surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY)
17 | 
18 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-slim AS gradle 2 | 3 | ARG CODENARC_VERSION=2.0.0 4 | ARG GROOVY_VERSION=2.5.12 5 | ARG GRADLE_VERSION=6.9.2 6 | 7 | RUN apt-get update && apt-get install -y unzip curl 8 | WORKDIR /gradle 9 | RUN curl -L https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip -o gradle-$GRADLE_VERSION-bin.zip 10 | RUN unzip gradle-$GRADLE_VERSION-bin.zip 11 | ENV GRADLE_HOME=/gradle/gradle-$GRADLE_VERSION 12 | ENV PATH=$PATH:$GRADLE_HOME/bin 13 | 14 | COPY . /gradle 15 | RUN sed -e "s/\${codenarc.version}/$CODENARC_VERSION/" -e "s/\${groovy.version}/$GROOVY_VERSION/" build.gradle.template > build.gradle 16 | 17 | RUN gradle --quiet --no-daemon shadowJar 18 | 19 | FROM openjdk:8-jre-slim 20 | 21 | WORKDIR /lib 22 | COPY --from=gradle /gradle/build/libs/codenarc-all.jar /lib/codenarc-all.jar 23 | RUN chmod 755 /lib/codenarc-all.jar 24 | 25 | WORKDIR /ws 26 | 27 | ENTRYPOINT ["java", "-jar", "/lib/codenarc-all.jar"] 28 | 29 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC528.html: -------------------------------------------------------------------------------- 1 | 2 |

Shaking of an Android device is possible in all circumstances with a call to getSystemService(Context.VIBRATOR_SERVICE) (API 26) or 3 | getSystemService(Context.VIBRATOR.MANAGER.SERVICE) (API 31). 4 | Behind this effect stands a specific miniature hardware component, motor or actuator, that consumes power. 5 | As a consequence, its usage must be discouraged, especially since its added value is not clear.

6 |

Noncompliant Code Example

7 | API 26: 8 |
 9 |     Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
10 |     v.vibrate(400);
11 | 
12 | API 31: 13 |
14 |     VibratorManager vm = (VibratorManager) getSystemService(Context.VIBRATOR_MANAGER_SERVICE);
15 |     vm.getDefaultVibrator().vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
16 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/docker/build.gradle.template: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'com.github.johnrengelman.shadow' version '6.1.0' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | compile 'org.codehaus.groovy:groovy:${groovy.version}' 12 | compile 'org.codehaus.groovy:groovy-xml:${groovy.version}' 13 | compile 'org.codehaus.groovy:groovy-json:${groovy.version}' 14 | compile 'org.codehaus.groovy:groovy-ant:${groovy.version}' 15 | compile 'org.codehaus.groovy:groovy-templates:${groovy.version}' 16 | 17 | compile('org.codenarc:CodeNarc:${codenarc.version}') { 18 | exclude group: 'org.codehaus.groovy' 19 | } 20 | 21 | compile 'ch.qos.logback:logback-classic:1.2.3' 22 | } 23 | 24 | shadowJar { 25 | archiveBaseName.set('codenarc-all') 26 | archiveClassifier.set('') 27 | archiveVersion.set('') 28 | manifest { 29 | attributes 'Main-Class': 'org.codenarc.CodeNarc' 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ruleset/RuleSetConfigurer.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codenarc.ruleset 17 | 18 | /** 19 | * Represents a configurer for a ruleset 20 | * 21 | * @author Chris Mair 22 | */ 23 | interface RuleSetConfigurer { 24 | 25 | void configure(RuleSet ruleSet, String name) 26 | 27 | } 28 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC512.html: -------------------------------------------------------------------------------- 1 | 2 |

Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. 3 | In addition to these are the image sensor (a.k.a. Camera) and the geo-positioning sensor (a.k.a. GPS).

4 |

The common point of all these sensors is that they are expensive while in use. Their common bug is to let the sensor 5 | unnecessarily process data when the app enters an idle state, typically when paused or stopped.
6 | Consequently, calls must be carefully pairwised: Camera.open()/Camera.release(). 7 | Failing to do so can drain the battery in just a few hours.

8 |

Noncompliant Code Example

9 |
10 |     Camera camera = Camera.open();
11 | 
12 |

Compliant Code Example

13 |
14 |     Camera camera = Camera.open();
15 |     camera.release();
16 | 
17 | 18 | -------------------------------------------------------------------------------- /android-plugin/src/test/java/io/ecocode/EcoCodeRulesPluginTest.java: -------------------------------------------------------------------------------- 1 | package io.ecocode; 2 | 3 | import org.junit.Test; 4 | import org.sonar.api.Plugin; 5 | import org.sonar.api.SonarEdition; 6 | import org.sonar.api.SonarQubeSide; 7 | import org.sonar.api.SonarRuntime; 8 | import org.sonar.api.internal.SonarRuntimeImpl; 9 | import org.sonar.api.utils.Version; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class EcoCodeRulesPluginTest { 14 | 15 | public static final Version VERSION_10_3 = Version.create(10, 3); 16 | 17 | @Test 18 | public void testExtensions() { 19 | EcoCodeRulesPlugin plugin = new EcoCodeRulesPlugin(); 20 | SonarRuntime runtime = 21 | SonarRuntimeImpl.forSonarQube(VERSION_10_3, SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); 22 | Plugin.Context context = new Plugin.Context(runtime); 23 | plugin.define(context); 24 | assertThat(context.getExtensions()).hasSize(14); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ruleregistry/RuleRegistryHolder.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codenarc.ruleregistry 17 | 18 | /** 19 | * Holds a reference to the RuleRegistry static singleton 20 | * 21 | * @author Chris Mair 22 | */ 23 | class RuleRegistryHolder { 24 | 25 | static RuleRegistry ruleRegistry 26 | } 27 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ruleregistry/RuleRegistry.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codenarc.ruleregistry 17 | 18 | /** 19 | * Represents a registry of rule classes, accessible by rule name 20 | * 21 | * @author Chris Mair 22 | */ 23 | interface RuleRegistry { 24 | 25 | Class getRuleClass(String ruleName) 26 | } 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC519.html: -------------------------------------------------------------------------------- 1 | 2 |

It's always good that an app has different behavior when device is connected/disconnected 3 | to a power station, or has different battery levels. 4 | One can monitor the changes in charging state with a broadcast receiver registered 5 | on the actions ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED, 6 | or monitor significant changes in battery level with a broadcast receiver registered 7 | on the actions BATTERY_LOW and BATTERY_OKAY.

8 |

Compliant Code Example

9 |
10 |     new IntentFilter(Intent.ACTION_POWER_CONNECTED)
11 | 
12 | OR 13 |
14 |     new IntentFilter(Intent.ACTION_POWER_DISCONNECTED)
15 | 
16 | OR 17 |
18 |     new IntentFilter(Intent.ACTION_POWER_BATTERY_OKAY)
19 | 
20 | OR 21 |
22 |     new IntentFilter(Intent.ACTION_POWER_BATTERY_LOW)
23 | 
-------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC526.html: -------------------------------------------------------------------------------- 1 | 2 |

With Bluetooth Low Energy technology (see BLE API smell), a Bluetooth Smart Ready 3 | device (the master) will establish a link with a Bluetooth Smart device (the slave). 4 | Most often, the slave is a GATT server and the master is a GATT client. GATT capable 5 | devices can be discovered using BLE scan process.

6 |

Invoking BluetoothGatt#requestConnectionPriority(int connectionPriority) 7 | with the value CONNECTION_PRIORITY_LOW_POWER, is recommended to reduce 8 | power consumption.

9 |

Noncompliant Code Example

10 |
11 |     BluetoothGatt gatt = new BluetoothGatt();
12 |     gatt.requestConnectionPriority(CONNECTION_PRIORITY_HIGH);
13 | 
14 |

Compliant Code Example

15 |
16 |     BluetoothGatt gatt = new BluetoothGatt();
17 |     gatt.requestConnectionPriority(CONNECTION_PRIORITY_LOW_POWER);
18 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/report/BaselineViolation.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codenarc.report 17 | 18 | import groovy.transform.Immutable 19 | 20 | /** 21 | * Represents a single violation within a baseline report 22 | */ 23 | @Immutable 24 | class BaselineViolation { 25 | 26 | String ruleName 27 | String message 28 | 29 | } 30 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/unused.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Unused rule set. 8 | These rules check for unused definitions within the source code. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/size.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Size and complexity rule set. 8 | These rules check against thresholds for code size and complexity. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /android-plugin/src/main/resources/io/ecocode/rules/java/EC525.html: -------------------------------------------------------------------------------- 1 | 2 |

With Bluetooth Low Energy technology, a Bluetooth Smart Ready device (the master) 3 | will establish a link with a Bluetooth Smart device (the slave). Most often, 4 | the slave is a GATT server and the master is a GATT client. GATT capable 5 | devices can be discovered using BLE scan process.

6 |

The default and preferred advertising mode is ADVERTISE_MODE_LOW_POWER 7 | when calling AdvertiseSettings.Builder#setAdvertiseMode(int advertiseMode). 8 |

9 |

Noncompliant Code Example

10 |
11 |     AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
12 |     builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);
13 | 
14 |

Compliant Code Example

15 |
16 |     AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
17 |     builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_POWER);
18 | 
-------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/resources/rulesets/imports.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Imports rule set. 8 | These rules implement standards and best practices related to import statements. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ant/ReportOption.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codenarc.ant 17 | 18 | /** 19 | * JavaBean class holding the properties for a