├── sonar-scanner ├── src │ ├── python │ │ ├── __init__.py │ │ ├── tests │ │ │ ├── __init__.py │ │ │ └── test_shapes.py │ │ ├── README.md │ │ ├── shapes.py │ │ ├── strfile.py │ │ └── fortune.py │ ├── erlang │ │ └── hello.erl │ ├── apex │ │ └── more-apex-example-resources.txt │ ├── flex │ │ ├── Circle.as │ │ └── UncoveredCircle.as │ ├── sql │ │ ├── ddl.sql │ │ └── ut_report.pkb │ ├── swift │ │ └── example.swift │ ├── kotlin │ │ └── sample.kt │ ├── azureresourcemanager │ │ └── azuredeploy.parameters.json │ ├── javascript │ │ └── Person.js │ ├── terraform │ │ ├── gcp │ │ │ └── networks.tf │ │ └── azure │ │ │ └── sql.tf │ ├── docker │ │ └── Dockerfile │ ├── kubernetes │ │ └── newrelic-daemonset.yaml │ ├── vb6 │ │ ├── Info.frm │ │ └── Registry.bas │ ├── html │ │ └── sample.xhtml │ ├── rpg │ │ └── MYPROGRAM.rpg │ ├── pli │ │ └── maxlen.pli │ └── abap │ │ └── ZBCMKZ17.abap ├── copybooks │ ├── Errparm.cpy │ ├── Custmas.cpy │ └── Attr.cpy ├── README.md ├── sonar-project.properties └── coverage-report │ ├── coverage-cobertua-flex.xml │ ├── execution-python.xml │ └── coverage-python.xml ├── .github └── CODEOWNERS ├── sonar-scanner-gradle ├── gradle-kotlin-project │ ├── gradle.properties │ ├── settings.gradle.kts │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── src │ │ ├── main │ │ │ └── kotlin │ │ │ │ └── Main.kt │ │ └── test │ │ │ └── kotlin │ │ │ └── MainTest.kt │ ├── .gitignore │ ├── build.gradle.kts │ ├── README.md │ └── gradlew.bat ├── gradle-multimodule │ ├── settings.gradle │ ├── module-two │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── Two.java │ ├── module-one │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── One.java │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── README.md │ ├── build.gradle │ └── gradlew.bat ├── gradle-basic │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── acme │ │ │ │ └── App.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── acme │ │ │ └── AppTest.java │ ├── settings.gradle │ ├── README.md │ ├── build.gradle │ └── gradlew.bat ├── gradle-multimodule-coverage │ ├── settings.gradle │ ├── utilities │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── gradle │ │ │ └── sample │ │ │ └── utilities │ │ │ ├── StringUtils.java │ │ │ ├── JoinUtils.java │ │ │ └── SplitUtils.java │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── application │ │ ├── src │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── org │ │ │ │ │ └── gradle │ │ │ │ │ └── sample │ │ │ │ │ └── app │ │ │ │ │ ├── MessageUtils.java │ │ │ │ │ └── Main.java │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── gradle │ │ │ │ └── sample │ │ │ │ └── app │ │ │ │ └── MessageUtilsTest.java │ │ └── build.gradle │ ├── list │ │ ├── build.gradle │ │ └── src │ │ │ ├── test │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── gradle │ │ │ │ └── sample │ │ │ │ └── list │ │ │ │ └── LinkedListTest.java │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── gradle │ │ │ └── sample │ │ │ └── list │ │ │ └── LinkedList.java │ ├── sonar.gradle │ ├── build.gradle │ ├── gradlew.bat │ └── README.md └── gradle-kotlin-dsl │ ├── settings.gradle.kts │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── baeldung │ │ │ └── kotlindsl │ │ │ ├── RepositoryUnitTest.java │ │ │ ├── SorterUnitTest.java │ │ │ └── ReporterUnitTest.java │ ├── integrationTest │ │ └── java │ │ │ └── com │ │ │ └── baeldung │ │ │ └── kotlindsl │ │ │ └── ReporterIntegrationTest.java │ └── main │ │ └── java │ │ └── com │ │ └── baeldung │ │ └── kotlindsl │ │ ├── Repository.java │ │ ├── Sorter.java │ │ └── Reporter.java │ ├── README.md │ ├── gradlew.bat │ └── build.gradle.kts ├── swift-coverage ├── swift-coverage-example │ ├── .gitignore │ ├── sonar-project.properties │ ├── swift-coverage-example.xcodeproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── elenavilchik.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── swift-coverage-example.xcscheme │ ├── swift-coverage-example │ │ ├── AppDelegate2.swift │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ └── Info.plist │ ├── info.plist │ ├── swift-coverage-exampleTests │ │ ├── Info.plist │ │ └── swift_coverage_exampleTests.swift │ └── xccov-to-sonarqube-generic.sh └── README.md ├── sonar-scanner-maven ├── maven-basic │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── acme │ │ │ │ └── basic │ │ │ │ ├── ResourceResponse.java │ │ │ │ └── HelloWorld.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── acme │ │ │ └── basic │ │ │ └── HelloWorldTest.java │ ├── README.md │ └── pom.xml ├── maven-multilingual │ ├── src │ │ ├── test │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── acme │ │ │ │ │ └── multilingual │ │ │ │ │ └── HelloWorldTest.java │ │ │ └── kotlin │ │ │ │ └── com │ │ │ │ └── acme │ │ │ │ └── multilingual │ │ │ │ └── KotlinHelloWorldTest.kt │ │ └── main │ │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── acme │ │ │ │ └── multilingual │ │ │ │ └── KotlinHelloWorld.kt │ │ │ └── java │ │ │ └── com │ │ │ └── acme │ │ │ └── multilingual │ │ │ └── HelloWorld.java │ ├── README.md │ └── pom.xml └── maven-multimodule │ ├── module2 │ ├── src │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── acme │ │ │ │ └── module2 │ │ │ │ └── Module2Test.java │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── acme │ │ │ └── module2 │ │ │ └── Module2.java │ └── pom.xml │ ├── module1 │ ├── src │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── acme │ │ │ │ └── module1 │ │ │ │ └── Module1Test.java │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── acme │ │ │ └── module1 │ │ │ └── Module1.java │ └── pom.xml │ ├── tests │ ├── src │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── acme │ │ │ └── its │ │ │ └── ModulesTest.java │ └── pom.xml │ ├── pom.xml │ └── README.md ├── NOTICE.txt ├── sonar-scanner-ant ├── ant-basic │ ├── src │ │ └── One.java │ ├── sonar-project.properties │ ├── README.md │ └── build.xml └── ant-coverage │ ├── sonar-project.properties │ ├── src │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── jacoco │ │ │ └── examples │ │ │ └── parser │ │ │ ├── ExpressionParserIT.java │ │ │ └── ExpressionParserTest.java │ └── main │ │ └── java │ │ └── org │ │ └── jacoco │ │ └── examples │ │ ├── expressions │ │ ├── IExpression.java │ │ ├── Const.java │ │ ├── Add.java │ │ ├── Div.java │ │ ├── Mul.java │ │ └── Sub.java │ │ └── parser │ │ ├── Main.java │ │ └── ExpressionParser.java │ ├── README.md │ └── build.xml ├── sonar-scanner-dotnet └── CSharpProject │ ├── SomeConsoleApplication │ ├── App.config │ ├── SomeConsoleApplication.csproj │ └── Program.cs │ ├── SomeConsoleApplicationTest │ ├── SomeConsoleApplicationTest.csproj │ └── ProgramTests.cs │ ├── SomeConsoleApplication.sln │ └── README.md ├── .gitignore ├── SECURITY.md └── README.md /sonar-scanner/src/python/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sonar-scanner/src/python/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | .github/CODEOWNERS @sonarsource/support-team 2 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/settings.gradle: -------------------------------------------------------------------------------- 1 | include 'module-one' 2 | include 'module-two' 3 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=512M 2 | -------------------------------------------------------------------------------- /sonar-scanner/src/erlang/hello.erl: -------------------------------------------------------------------------------- 1 | -module(hello). 2 | -export([hello_world/0]). 3 | 4 | hello_world() -> io:fwrite("hello, world\n"). 5 | -------------------------------------------------------------------------------- /sonar-scanner/src/apex/more-apex-example-resources.txt: -------------------------------------------------------------------------------- 1 | More Apex Examples: 2 | * https://github.com/SonarSource-Demos/salesforce-apex-example 3 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/.gitignore: -------------------------------------------------------------------------------- 1 | ModuleCache.noindex 2 | Index/ 3 | Logs/ 4 | Build/ 5 | .scannerwork 6 | Coverage.xml 7 | Coverage.report 8 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/module-two/src/main/java/Two.java: -------------------------------------------------------------------------------- 1 | public class Two { 2 | public String foo() { 3 | return "foo"; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-basic/src/main/java/com/acme/basic/ResourceResponse.java: -------------------------------------------------------------------------------- 1 | package com.acme.basic; 2 | 3 | public class ResourceResponse { 4 | } 5 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'jvm-multi-project-with-code-coverage' 2 | include 'application', 'list', 'utilities' 3 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/utilities/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | dependencies { 6 | implementation project(':list') 7 | } 8 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | // Noncompliant - kotlin:6625 "rootProject.name" should always be present in Gradle settings 2 | //rootProject.name = "gradle-kotlin-dsl" 3 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" 3 | } 4 | rootProject.name = "gradle-kotlin-project" -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/HEAD/sonar-scanner-gradle/gradle-basic/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/module-one/src/main/java/One.java: -------------------------------------------------------------------------------- 1 | public class One { 2 | 3 | public String message = ""; 4 | 5 | public String foo() { 6 | return "foo"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | sonar-scanning-examples 2 | Copyright (C) 2016-2025 SonarSource SA 3 | mailto:info AT sonarsource DOT com 4 | 5 | This product includes software developed at 6 | SonarSource (http://www.sonarsource.com/). -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/HEAD/sonar-scanner-gradle/gradle-kotlin-dsl/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/HEAD/sonar-scanner-gradle/gradle-multimodule/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/HEAD/sonar-scanner-gradle/gradle-kotlin-project/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sonar-scanner/src/flex/Circle.as: -------------------------------------------------------------------------------- 1 | package { 2 | 3 | public class Circle { 4 | public var diameter:int = 0; 5 | 6 | function Circle (d:int) { 7 | this.diameter = d; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=swift-coverage-example 2 | sonar.projectName=swift-coverage-example 3 | sonar.projectVersion=1.0 4 | 5 | sonar.sources=swift-coverage-example 6 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/HEAD/sonar-scanner-gradle/gradle-multimodule-coverage/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sonar-scanner/src/flex/UncoveredCircle.as: -------------------------------------------------------------------------------- 1 | package { 2 | 3 | public class UncoveredCircle { 4 | public var diameter:int = 0; 5 | 6 | function UncoveredCircle (d:int) { 7 | this.diameter = d; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-basic/src/One.java: -------------------------------------------------------------------------------- 1 | public class One { 2 | String message = "foo"; 3 | 4 | public String foo() { 5 | return message; 6 | } 7 | 8 | public void uncoveredMethod() { 9 | System.out.println(foo()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/SomeConsoleApplication/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sonar-scanner/src/sql/ddl.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE OWNER.TABLE01 (ID NUMBER(12)); 2 | / 3 | ALTER TABLE OWNER.TABLE01 ADD (COL1 VARCHAR2(4000)); 4 | / 5 | 6 | CREATE TABLE OWNER.TABLE02 (ID NUMBER(12)); 7 | / 8 | ALTER TABLE OWNER.TABLE02 ADD (COL1 VARCHAR2(4000)); 9 | / 10 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-basic/sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=org.sonarqube:sonar-scanner-ant 2 | sonar.projectName=Example of SonarScanner CLI on Ant project 3 | sonar.projectVersion=1.0 4 | sonar.sources=src 5 | sonar.java.binaries=target 6 | sonar.sourceEncoding=UTF-8 7 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/application/src/main/java/org/gradle/sample/app/MessageUtils.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.app; 2 | 3 | class MessageUtils { 4 | public static String getMessage() { 5 | return "Hello, World!"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-basic/src/test/java/com/acme/basic/HelloWorldTest.java: -------------------------------------------------------------------------------- 1 | package com.acme.basic; 2 | 3 | import org.junit.Test; 4 | 5 | public class HelloWorldTest { 6 | 7 | @Test 8 | public void sayHello() { 9 | new HelloWorld().sayHello(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sonar-scanner/src/swift/example.swift: -------------------------------------------------------------------------------- 1 | 2 | let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"] 3 | 4 | func backwards(s1: String, s2: String) -> Bool { 5 | return s1 > s2 6 | } 7 | 8 | var reversed = sorted(names, backwards); 9 | 10 | if (true) { print(reversed) } 11 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /sonar-scanner/copybooks/Errparm.cpy: -------------------------------------------------------------------------------- 1 | 01 ERROR-PARAMETERS. 2 | * 3 | 05 ERR-RESP PIC S9(8) COMP. 4 | 05 ERR-RESP2 PIC S9(8) COMP. 5 | 05 ERR-TRNID PIC X(4) VALUE IS 99. 6 | 05 ERR-RSRCE PIC X(8). 7 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/list/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'jacoco' 4 | } 5 | 6 | dependencies { 7 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1' 8 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' 9 | } 10 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multilingual/src/test/java/com/acme/multilingual/HelloWorldTest.java: -------------------------------------------------------------------------------- 1 | package com.acme.multilingual; 2 | 3 | import org.junit.Test; 4 | 5 | public class HelloWorldTest { 6 | 7 | @Test 8 | public void sayHello() { 9 | new HelloWorld().sayHello(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multilingual/src/test/kotlin/com/acme/multilingual/KotlinHelloWorldTest.kt: -------------------------------------------------------------------------------- 1 | package com.acme.multilingual 2 | 3 | import org.junit.Test 4 | 5 | class KotlinHelloWorldTest { 6 | 7 | @Test 8 | fun sayHello() { 9 | KotlinHelloWorld().sayHello() 10 | } 11 | } -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/module2/src/test/java/com/acme/module2/Module2Test.java: -------------------------------------------------------------------------------- 1 | package com.acme.module2; 2 | 3 | import org.junit.Test; 4 | 5 | public class Module2Test { 6 | 7 | @Test 8 | public void coveredByUnitTest() { 9 | new Module2().coveredByUnitTest(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/src/main/java/com/acme/App.java: -------------------------------------------------------------------------------- 1 | package com.acme; 2 | 3 | public class App { 4 | public String getGreeting() { 5 | return "Hello world."; 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println(new App().getGreeting()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Aug 27 10:23:27 CEST 2025 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle files 2 | .gradle/ 3 | .classpath 4 | .project 5 | .settings/ 6 | bin/ 7 | 8 | # Build output 9 | build/ 10 | .sonar 11 | target/ 12 | bw-outputs/ 13 | .scannerwork 14 | 15 | # IntelliJ 16 | 17 | .idea 18 | *.iml 19 | 20 | # mac 21 | .DS_Store 22 | 23 | # MSBuild 24 | obj/ 25 | 26 | .coverage 27 | 28 | __pycache__ -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multilingual/src/main/kotlin/com/acme/multilingual/KotlinHelloWorld.kt: -------------------------------------------------------------------------------- 1 | package com.acme.multilingual 2 | 3 | class KotlinHelloWorld { 4 | fun sayHello() { 5 | println("Hello World!") 6 | } 7 | 8 | fun notCovered() { 9 | println("This method is not covered by unit tests") 10 | } 11 | } -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/module1/src/test/java/com/acme/module1/Module1Test.java: -------------------------------------------------------------------------------- 1 | package com.acme.module1; 2 | 3 | import org.junit.Test; 4 | 5 | public class Module1Test { 6 | 7 | @Test 8 | public void coveredByUnitTest() { 9 | Module1 module1 = new Module1(); 10 | module1.coveredByUnitTest(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-basic/src/main/java/com/acme/basic/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.acme.basic; 2 | 3 | public class HelloWorld { 4 | 5 | void sayHello() { 6 | System.out.println("Hello World!"); 7 | } 8 | 9 | void notCovered() { 10 | System.out.println("This method is not covered by unit tests"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | package org.example 2 | 3 | fun main() { 4 | val name = "Kotlin" 5 | println("Hello, " + name + "!") 6 | 7 | for (i in 1..5) { 8 | println("i = $i") 9 | } 10 | 11 | if (true) { 12 | println("Can confirm: true is still true") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/src/test/kotlin/MainTest.kt: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.Assertions.assertNotNull 2 | import org.junit.jupiter.api.Test 3 | import org.example.main 4 | 5 | class MainTest { 6 | @Test 7 | fun testMainReturnsNotNull() { 8 | val result = main() 9 | assertNotNull(result) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multilingual/src/main/java/com/acme/multilingual/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.acme.multilingual; 2 | 3 | public class HelloWorld { 4 | 5 | void sayHello() { 6 | System.out.println("Hello World!"); 7 | } 8 | 9 | void notCovered() { 10 | System.out.println("This method is not covered by unit tests"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=org.sonarqube:sonar-scanner-ant-coverage 2 | sonar.projectName=Example of SonarScanner CLI on Ant project with JaCoCo coverage 3 | sonar.projectVersion=1.0 4 | sonar.sources=src 5 | sonar.java.binaries=target 6 | sonar.sourceEncoding=UTF-8 7 | sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/report.xml -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example.xcodeproj/project.xcworkspace/xcuserdata/elenavilchik.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SonarSource/sonar-scanning-examples/HEAD/swift-coverage/swift-coverage-example/swift-coverage-example.xcodeproj/project.xcworkspace/xcuserdata/elenavilchik.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/sonar.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "org.sonarqube" 2 | 3 | sonar { 4 | properties { 5 | // Insert other SonarQube properties here 6 | property 'sonar.projectName', 'Example of SonarScanner for Gradle (multimodule with Jacoco code coverage)' 7 | property 'sonar.projectKey', 'org.sonarqube.gradle-multi-module-jacoco' 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/src/test/java/com/acme/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.acme; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertNotNull; 6 | public class AppTest { 7 | @Test 8 | public void testAppHasAGreeting() { 9 | App classUnderTest = new App(); 10 | assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/application/src/test/java/org/gradle/sample/app/MessageUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.app; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class MessageUtilsTest { 8 | @Test public void testGetMessage() { 9 | assertEquals("Hello, World!", MessageUtils.getMessage()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example/AppDelegate2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate2.swift 3 | // swift-coverage-example 4 | // 5 | // Created by Alexandre Gigleux on 30.04.18. 6 | // Copyright © 2018 SonarSource. All rights reserved. 7 | // 8 | 9 | 10 | class AB { 11 | func foo(){ 12 | if (1 > 2) { 13 | print("hello") 14 | } else { 15 | print("Bye") 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/application/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | id 'jacoco' 4 | } 5 | 6 | dependencies { 7 | implementation project(':list') 8 | implementation project(':utilities') 9 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1' 10 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' 11 | } 12 | 13 | application { 14 | mainClass = 'org.gradle.sample.Main' 15 | } 16 | -------------------------------------------------------------------------------- /sonar-scanner/copybooks/Custmas.cpy: -------------------------------------------------------------------------------- 1 | 01 CUSTOMER-MASTER-RECORD. 2 | * 3 | 05 CM-CUSTOMER-NUMBER PIC X(6). 4 | 05 CM-FIRST-NAME PIC X(20). 5 | 05 CM-LAST-NAME PIC X(30). 6 | 05 CM-ADDRESS PIC X(30). 7 | 05 CM-CITY PIC X(20). 8 | 05 CM-STATE PIC X(2). 9 | 05 CM-ZIP-CODE PIC X(10). 10 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/utilities/src/main/java/org/gradle/sample/utilities/StringUtils.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.utilities; 2 | 3 | import org.gradle.sample.list.LinkedList; 4 | 5 | public class StringUtils { 6 | public static String join(LinkedList source) { 7 | return JoinUtils.join(source); 8 | } 9 | 10 | public static LinkedList split(String source) { 11 | return SplitUtils.split(source); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/tests/src/test/java/com/acme/its/ModulesTest.java: -------------------------------------------------------------------------------- 1 | package com.acme.its; 2 | 3 | import com.acme.module1.Module1; 4 | import com.acme.module2.Module2; 5 | import org.junit.Test; 6 | 7 | public class ModulesTest { 8 | 9 | @Test 10 | public void integrationTest1() { 11 | new Module1().coveredByIntegrationTest(); 12 | } 13 | 14 | @Test 15 | public void integrationTest2() { 16 | new Module2().coveredByIntegrationTest(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/module2/src/main/java/com/acme/module2/Module2.java: -------------------------------------------------------------------------------- 1 | package com.acme.module2; 2 | 3 | public class Module2 { 4 | 5 | public void coveredByUnitTest() { 6 | System.out.println("This method is covered by unit test"); 7 | } 8 | 9 | public void coveredByIntegrationTest() { 10 | System.out.println("This method is covered by integration test"); 11 | } 12 | 13 | public void uncovered() { 14 | System.out.println("This method is not covered"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LastAccessedDate 6 | 2018-04-30T15:05:27Z 7 | WorkspacePath 8 | /Users/alexandregigleux/Repos/Training/sonar-scanning-examples/swift-coverage/swift-coverage-example/swift-coverage-example.xcodeproj 9 | 10 | 11 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/module1/src/main/java/com/acme/module1/Module1.java: -------------------------------------------------------------------------------- 1 | package com.acme.module1; 2 | 3 | public class Module1 { 4 | 5 | public void coveredByUnitTest() { 6 | System.out.println("This method is covered by unit test"); 7 | } 8 | 9 | public void coveredByIntegrationTest() { 10 | System.out.println("This method is covered by integration test"); 11 | } 12 | 13 | public void uncovered() { 14 | System.out.println("This method is not covered"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /sonar-scanner/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner 2 | 3 | Examples of [SonarScanner](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/) CLI usage. Browse folder, language samples, and properties file. 4 | 5 | For C-family (C/C++/Objective-C) project examples, please see https://github.com/sonarsource-cfamily-examples. 6 | * SonarSource sample C and C++ projects with SonarCloud or SonarQube analysis configured 7 | * C and C++ projects for different CI pipelines and build systems configured for Linux, Windows, and Mac 8 | -------------------------------------------------------------------------------- /sonar-scanner/src/kotlin/sample.kt: -------------------------------------------------------------------------------- 1 | fun vulnerableFunction() { 2 | val password = "password" // Vulnerability - hardcoded password 3 | if (!password.isNull()) println("null password!") 4 | } 5 | 6 | // Code Smell - Empty function 7 | fun emptyFunction() { 8 | } 9 | 10 | fun buggyFunction(str: String){ 11 | if (str == "hello"){ 12 | println("Hello!") 13 | } else if (str == "goodbye"){ 14 | println("Goodbye!") 15 | } else if (str == "hello"){ // Bug - Duplicate condition 16 | println("Hello again!") 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/SomeConsoleApplication/SomeConsoleApplication.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | SomeConsoleApplication 8 | 9 | 10 | 11 | 12 | false 13 | 14 | 15 | -------------------------------------------------------------------------------- /sonar-scanner/src/python/README.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | ## Generate test reports 4 | 5 | ```bash 6 | # install coverage report tool 7 | pip3 install coverage 8 | 9 | # install execution report tool 10 | pip3 install unittest-xml-reporting 11 | 12 | cd sonar-scanner 13 | 14 | # generate coverage report 15 | coverage run -m unittest discover -s src/python/ 16 | coverage xml -o coverage-report/coverage-python.xml 17 | 18 | # generate execution report 19 | python3 -m xmlrunner discover -s src/python/ -o coverage-report/execution-python.xml 20 | ``` -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/application/src/main/java/org/gradle/sample/app/Main.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.app; 2 | 3 | import org.gradle.sample.list.LinkedList; 4 | 5 | import static org.gradle.sample.utilities.StringUtils.join; 6 | import static org.gradle.sample.utilities.StringUtils.split; 7 | import static org.gradle.sample.app.MessageUtils.getMessage; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | LinkedList tokens; 12 | tokens = split(getMessage()); 13 | System.out.println(join(tokens)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/utilities/src/main/java/org/gradle/sample/utilities/JoinUtils.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.utilities; 2 | 3 | import org.gradle.sample.list.LinkedList; 4 | 5 | class JoinUtils { 6 | public static String join(LinkedList source) { 7 | StringBuilder result = new StringBuilder(); 8 | for (int i = 0; i < source.size(); ++i) { 9 | if (result.length() > 0) { 10 | result.append(" "); 11 | } 12 | result.append(source.get(i)); 13 | } 14 | 15 | return result.toString(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/module1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.sonarqube 8 | sonarscanner-maven-aggregate 9 | 1.0-SNAPSHOT 10 | 11 | 12 | module1 13 | 14 | Module 1 15 | 16 | 17 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/module2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.sonarqube 8 | sonarscanner-maven-aggregate 9 | 1.0-SNAPSHOT 10 | 11 | 12 | module2 13 | 14 | Module 2 15 | 16 | 17 | -------------------------------------------------------------------------------- /sonar-scanner/src/azureresourcemanager/azuredeploy.parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "aksClusterAdminUsername": { 6 | "value": "GEN-UNIQUE" 7 | }, 8 | "aksClusterSshPublicKey": { 9 | "value": "GEN-SSH-PUB-KEY" 10 | }, 11 | "logAnalyticsWorkspaceName": { 12 | "value": "GEN-UNIQUE" 13 | }, 14 | "vmAdminUsername": { 15 | "value": "GEN-UNIQUE" 16 | }, 17 | "vmAdminPasswordOrKey": { 18 | "value": "GEN-PASSWORD" 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This settings file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * In a single project build this file can be empty or even removed. 6 | * 7 | * Detailed information about configuring a multi-project build in Gradle can be found 8 | * in the user guide at https://docs.gradle.org/3.5/userguide/multi_project_builds.html 9 | */ 10 | 11 | /* 12 | // To declare projects as part of a multi-project build use the 'include' method 13 | include 'shared' 14 | include 'api' 15 | include 'services:webservice' 16 | */ 17 | 18 | rootProject.name = 'sonar-scanner-gradle-basic' 19 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/test/java/org/jacoco/examples/parser/ExpressionParserIT.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Mirko Friedenhagen - initial 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.parser; 14 | 15 | public class ExpressionParserIT extends ExpressionParserTest { 16 | } 17 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner for Multi-Module Java Gradle Project 2 | 3 | This example demonstrates how to analyze a multi-module Java project with Gradle. 4 | 5 | ## Prerequisites 6 | 7 | * [SonarQube](http://www.sonarqube.org/downloads/) 9.9 LTS or Latest 8 | * A gradle wrapper is included that bundles gradle. All other required plugins will be pulled by gradle as needed. 9 | 10 | ## Usage 11 | 12 | Run the following command (updating the sonar.host.url property as appropriate): 13 | 14 | * On Unix-like systems: 15 | 16 | ```shell 17 | ./gradlew build -Dsonar.host.url=http://myhost:9000 sonar 18 | ``` 19 | 20 | * On Windows: 21 | 22 | ```powershell 23 | .\gradle.bat build -Dsonar.host.url=http://myhost:9000 sonar 24 | ``` 25 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/expressions/IExpression.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.expressions; 14 | 15 | public interface IExpression { 16 | 17 | public double evaluate(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/**/build/ 5 | !**/src/test/**/build/ 6 | 7 | ### IntelliJ IDEA ### 8 | .idea/modules.xml 9 | .idea/jarRepositories.xml 10 | .idea/compiler.xml 11 | .idea/libraries/ 12 | *.iws 13 | *.iml 14 | *.ipr 15 | out/ 16 | !**/src/main/**/out/ 17 | !**/src/test/**/out/ 18 | 19 | ### Kotlin ### 20 | .kotlin 21 | 22 | ### Eclipse ### 23 | .apt_generated 24 | .classpath 25 | .factorypath 26 | .project 27 | .settings 28 | .springBeans 29 | .sts4-cache 30 | bin/ 31 | !**/src/main/**/bin/ 32 | !**/src/test/**/bin/ 33 | 34 | ### NetBeans ### 35 | /nbproject/private/ 36 | /nbbuild/ 37 | /dist/ 38 | /nbdist/ 39 | /.nb-gradle/ 40 | 41 | ### VS Code ### 42 | .vscode/ 43 | 44 | ### Mac OS ### 45 | .DS_Store -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/SomeConsoleApplication/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace SomeConsoleApplication 3 | { 4 | public class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | var iAmTrue = true; 9 | if (iAmTrue) 10 | { 11 | Console.WriteLine("true"); 12 | } 13 | else 14 | { 15 | Console.WriteLine("false"); 16 | } 17 | 18 | Console.ReadKey(); 19 | } 20 | 21 | public static bool AlwaysReturnsTrue() 22 | { 23 | return true; 24 | } 25 | 26 | public static object Passthrough(object obj) 27 | { 28 | return obj; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sonar-scanner/src/javascript/Person.js: -------------------------------------------------------------------------------- 1 | var Person = function(first, last, middle) { 2 | this.first = first; 3 | this.middle = middle; 4 | this.last = last; 5 | }; 6 | 7 | Person.prototype = { 8 | 9 | whoAreYou : function() { 10 | return this.first + (this.middle ? ' ' + this.middle: '') + ' ' + this.last; 11 | } 12 | 13 | }; 14 | 15 | var a = NaN; 16 | 17 | if (a === NaN) { // Noncompliant; always false 18 | console.log("a is not a number"); // this is dead code 19 | } 20 | if (a !== NaN) { // Noncompliant; always true 21 | console.log("a is not NaN"); // this statement is not necessarily true 22 | } 23 | 24 | for (var i = 0; i < strings.length; i--) { 25 | console.log("dead code") 26 | } 27 | 28 | if (str == null && str.length == 0) { 29 | console.log("String is empty"); 30 | } 31 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | jacoco 3 | id("org.sonarqube") version "latest.release" 4 | kotlin("jvm") version "2.2.0" 5 | } 6 | 7 | group = "org.example" 8 | version = "1.0-SNAPSHOT" 9 | 10 | sonar { 11 | properties { 12 | property("sonar.projectKey", "gradle-kotlin-example") 13 | property("sonar.projectName", "Example of Kotlin project built with Gradle") 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | testImplementation(kotlin("test")) 23 | } 24 | 25 | tasks.test { 26 | useJUnitPlatform() 27 | } 28 | kotlin { 29 | jvmToolchain(21) 30 | } 31 | 32 | tasks.jacocoTestReport { 33 | reports { 34 | xml.required.set(true) 35 | html.required.set(true) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-basic/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner CLI on a Java Ant project 2 | 3 | This example demonstrates how to analyze a simple Apache Ant project with SonarScanner CLI. SonarScanner for Ant is deprecated on SonarCloud and as of SonarQube 9.9, therefore this is the current way of scanning an Ant project. Please see [Moving from SonarScanner for Ant to SonarScanner](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner-for-ant/#moving-from-sonarscanner-for-ant-to-sonarscanner) documentation for how to migrate to the SonarScanner. 4 | 5 | ## Prerequisites 6 | * [SonarScanner CLI](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/) 7 | * [Ant](http://ant.apache.org/) 1.10.0 or higher 8 | 9 | ## Usage 10 | 1. Compile the project: 11 | ```shell 12 | ant all 13 | ``` 14 | 2. Run SonarScanner CLI. 15 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-exampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // swift-coverage-example 4 | // 5 | // Created by Elena Vilchik on 17/08/16. 6 | // Copyright © 2016-2018 SonarSource. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | @IBOutlet weak var window: NSWindow! 15 | 16 | 17 | func applicationDidFinishLaunching(_ aNotification: Notification) { 18 | // Insert code here to initialize your application 19 | } 20 | 21 | func applicationWillTerminate(_ aNotification: Notification) { 22 | // Insert code here to tear down your application 23 | } 24 | 25 | 26 | } 27 | 28 | class A { 29 | func foo(){ 30 | if (1 > 2) { 31 | print("hello") 32 | } else { 33 | print("Bye") 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "java-library" 3 | id "org.sonarqube" version "latest.release" 4 | } 5 | 6 | allprojects { 7 | ext.baseVersion = "0.1" 8 | ext.snapshotVersion = true 9 | 10 | group = "org.sonarqube" 11 | version = "$baseVersion" + (snapshotVersion ? "-SNAPSHOT" : "") 12 | } 13 | 14 | sonar { 15 | properties { 16 | property "sonar.projectName", "Example of SonarScanner for Gradle - Multimodule" 17 | property "sonar.projectKey", "org.sonarqube:gradle-multimodule" 18 | } 19 | } 20 | 21 | subprojects { 22 | apply plugin: 'java-library' 23 | apply plugin: 'org.sonarqube' 24 | sonar { 25 | properties { 26 | //property "sonar.java.libraries", 27 | } 28 | } 29 | } 30 | 31 | // In this section you declare where to find the dependencies of your project 32 | repositories { 33 | mavenCentral() 34 | } 35 | -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/SomeConsoleApplicationTest/SomeConsoleApplicationTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | 6 | false 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/expressions/Const.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.expressions; 14 | 15 | public class Const implements IExpression { 16 | 17 | private final double value; 18 | 19 | public Const(final double value) { 20 | this.value = value; 21 | } 22 | 23 | public double evaluate() { 24 | return value; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/SomeConsoleApplicationTest/ProgramTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using SomeConsoleApplication; 4 | 5 | namespace SomeConsoleApplicationTest 6 | { 7 | [TestClass] 8 | public class ProgramTests 9 | { 10 | [TestMethod] 11 | public void AlwaysReturnsTrue_ReturnsTrue() 12 | { 13 | // Arrange & Act 14 | var actual = Program.AlwaysReturnsTrue(); 15 | 16 | // Assert 17 | Assert.IsTrue(actual); 18 | } 19 | 20 | [TestMethod] 21 | public void Passthrough_ReturnsTheGivenValue() 22 | { 23 | // Arrange 24 | var value = 42; 25 | 26 | // Act 27 | var actual = Program.Passthrough(value); 28 | 29 | // Assert 30 | Assert.AreEqual(actual, value); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sonar-scanner/src/terraform/gcp/networks.tf: -------------------------------------------------------------------------------- 1 | resource "google_compute_network" "vpc" { 2 | name = "terragoat-${var.environment}-network" 3 | description = "Virtual vulnerable-by-design network" 4 | auto_create_subnetworks = false 5 | } 6 | 7 | resource "google_compute_subnetwork" "public-subnetwork" { 8 | name = "terragoat-${var.environment}-public-subnetwork" 9 | ip_cidr_range = "10.0.0.0/24" 10 | region = var.region 11 | network = google_compute_network.vpc.id 12 | 13 | secondary_ip_range { 14 | range_name = "tf-test-secondary-range-update1" 15 | ip_cidr_range = "192.168.10.0/24" 16 | } 17 | } 18 | 19 | resource "google_compute_firewall" "allow_all" { 20 | name = "terragoat-${var.environment}-firewall" 21 | network = google_compute_network.vpc.id 22 | source_ranges = ["0.0.0.0/0"] 23 | allow { 24 | protocol = "tcp" 25 | ports = ["0-65535"] 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sonar-scanner/sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=org.sonarqube:sonar-scanner 2 | sonar.projectName=Example of SonarScanner Usage 3 | sonar.projectVersion=1.0 4 | 5 | sonar.sources=src,copybooks 6 | sonar.exclusions=src/**/tests/**/* 7 | sonar.tests=src/python/tests 8 | sonar.sourceEncoding=UTF-8 9 | 10 | ## Cobol Specific Properties 11 | 12 | # comma-separated paths to directories with copybooks 13 | sonar.cobol.copy.directories=copybooks 14 | # comma-separated list of suffixes 15 | sonar.cobol.file.suffixes=cbl,cpy 16 | sonar.cobol.copy.suffixes=cpy 17 | 18 | ## Flex Specific Properties 19 | 20 | # retrieve code coverage data from the Cobertura report 21 | sonar.flex.cobertura.reportPath=coverage-report/coverage-cobertua-flex.xml 22 | 23 | # PL/I Specific Properties 24 | sonar.pli.marginLeft=2 25 | sonar.pli.marginRight=0 26 | 27 | ## Python specific properties 28 | sonar.python.coverage.reportPaths=coverage-report/coverage-python.xml 29 | sonar.python.xunit.reportPath=coverage-report/execution-python.xml -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/expressions/Add.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.expressions; 14 | 15 | public class Add implements IExpression { 16 | 17 | private final IExpression l; 18 | 19 | private final IExpression r; 20 | 21 | public Add(final IExpression l, final IExpression r) { 22 | this.l = l; 23 | this.r = r; 24 | } 25 | 26 | public double evaluate() { 27 | return l.evaluate() + r.evaluate(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/expressions/Div.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.expressions; 14 | 15 | public class Div implements IExpression { 16 | 17 | private final IExpression l; 18 | 19 | private final IExpression r; 20 | 21 | public Div(final IExpression l, final IExpression r) { 22 | this.l = l; 23 | this.r = r; 24 | } 25 | 26 | public double evaluate() { 27 | return l.evaluate() / r.evaluate(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/expressions/Mul.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.expressions; 14 | 15 | public class Mul implements IExpression { 16 | 17 | private final IExpression l; 18 | 19 | private final IExpression r; 20 | 21 | public Mul(final IExpression l, final IExpression r) { 22 | this.l = l; 23 | this.r = r; 24 | } 25 | 26 | public double evaluate() { 27 | return l.evaluate() * r.evaluate(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/expressions/Sub.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.expressions; 14 | 15 | public class Sub implements IExpression { 16 | 17 | private final IExpression l; 18 | 19 | private final IExpression r; 20 | 21 | public Sub(final IExpression l, final IExpression r) { 22 | this.l = l; 23 | this.r = r; 24 | } 25 | 26 | public double evaluate() { 27 | return l.evaluate() - r.evaluate(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/parser/Main.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.parser; 14 | 15 | import java.io.IOException; 16 | 17 | public class Main { 18 | 19 | public static void main(final String[] args) throws IOException { 20 | for (String expression : args) { 21 | ExpressionParser parser = new ExpressionParser(expression); 22 | double result = parser.parse().evaluate(); 23 | System.out.printf("%s = %s%n", expression, result); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/test/java/com/baeldung/kotlindsl/RepositoryUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.math.BigDecimal; 6 | import java.time.Instant; 7 | 8 | import static com.baeldung.kotlindsl.Reporter.StockPrice.stockPrice; 9 | import static com.baeldung.kotlindsl.Reporter.StockSymbol.stockSymbol; 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | class RepositoryTest { 13 | 14 | Repository repo = new Repository(); 15 | 16 | @Test 17 | void should_return_stored_list() { 18 | // given 19 | var stock = stockSymbol("TSL"); 20 | 21 | // when 22 | var result = repo.getStockPrice(stock); 23 | 24 | // then 25 | assertEquals(stockPrice(new BigDecimal("1.32"), Instant.parse("2021-01-01T15:00:00Z")), result.get(0)); 26 | assertEquals(stockPrice(new BigDecimal("1.57"), Instant.parse("2021-05-05T15:00:00Z")), result.get(1)); 27 | assertEquals(stockPrice(new BigDecimal("1.89"), Instant.parse("2021-02-03T15:00:00Z")), result.get(2)); 28 | } 29 | } -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/utilities/src/main/java/org/gradle/sample/utilities/SplitUtils.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.utilities; 2 | 3 | import org.gradle.sample.list.LinkedList; 4 | 5 | class SplitUtils { 6 | public static LinkedList split(String source) { 7 | int lastFind = 0; 8 | int currentFind = 0; 9 | LinkedList result = new LinkedList(); 10 | 11 | while ((currentFind = source.indexOf(" ", lastFind)) != -1) { 12 | String token = source.substring(lastFind); 13 | if (currentFind != -1) { 14 | token = token.substring(0, currentFind - lastFind); 15 | } 16 | 17 | addIfValid(token, result); 18 | lastFind = currentFind + 1; 19 | } 20 | 21 | String token = source.substring(lastFind); 22 | addIfValid(token, result); 23 | 24 | return result; 25 | } 26 | 27 | private static void addIfValid(String token, LinkedList list) { 28 | if (isTokenValid(token)) { 29 | list.add(token); 30 | } 31 | } 32 | 33 | private static boolean isTokenValid(String token) { 34 | return !token.isEmpty(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-exampleTests/swift_coverage_exampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // swift_coverage_exampleTests.swift 3 | // swift-coverage-exampleTests 4 | // 5 | // Created by Elena Vilchik on 17/08/16. 6 | // Copyright © 2016 SonarSource. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import swift_coverage_example 11 | 12 | class swift_coverage_exampleTests: XCTestCase { 13 | 14 | func testFoo() { 15 | A().foo() 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | super.tearDown() 21 | } 22 | 23 | func testExample() { 24 | // This is an example of a functional test case. 25 | // Use XCTAssert and related functions to verify your tests produce the correct results. 26 | } 27 | 28 | func testPerformanceExample() { 29 | // This is an example of a performance test case. 30 | self.measure { 31 | // Put the code you want to measure the time of here. 32 | } 33 | } 34 | 35 | func testFoo2() { 36 | AB().foo() 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting Security Issues 2 | 3 | A mature software vulnerability treatment process is a cornerstone of a robust information security management system. Contributions from the community play an important role in the evolution and security of our products, and in safeguarding the security and privacy of our users. 4 | 5 | If you believe you have discovered a security vulnerability in Sonar's products, we encourage you to report it immediately. 6 | 7 | To responsibly report a security issue, please email us at [security@sonarsource.com](mailto:security@sonarsource.com). Sonar’s security team will acknowledge your report, guide you through the next steps, or request additional information if necessary. Customers with a support contract can also report the vulnerability directly through the support channel. 8 | 9 | For security vulnerabilities found in third-party libraries, please also contact the library's owner or maintainer directly. 10 | 11 | ## Responsible Disclosure Policy 12 | 13 | For more information about disclosing a security vulnerability to Sonar, please refer to our community post: [Responsible Vulnerability Disclosure](https://community.sonarsource.com/t/responsible-vulnerability-disclosure/9317). -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-basic/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/integrationTest/java/com/baeldung/kotlindsl/ReporterIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.math.BigDecimal; 6 | import java.time.Instant; 7 | import java.util.List; 8 | 9 | import static com.baeldung.kotlindsl.Reporter.StockPrice.stockPrice; 10 | import static com.baeldung.kotlindsl.Reporter.StockSymbol.stockSymbol; 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | 13 | public class ReporterIntegrationTest { 14 | 15 | Reporter reporter = new Reporter(new Repository(), new Sorter()); 16 | 17 | @Test 18 | void should_return_sorted_list_of_stock_prices() { 19 | // given 20 | var stock = stockSymbol("FFB"); 21 | 22 | // when 23 | var result = reporter.getStockPrice(stock); 24 | 25 | // then 26 | assertEquals(List.of( 27 | stockPrice(new BigDecimal("4.57"), Instant.parse("2021-02-05T15:00:00Z")), 28 | stockPrice(new BigDecimal("5.32"), Instant.parse("2021-05-01T15:00:00Z")), 29 | stockPrice(new BigDecimal("9.89"), Instant.parse("2021-09-03T15:00:00Z"))), 30 | result 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2016 SonarSource. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/test/java/com/baeldung/kotlindsl/SorterUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.math.BigDecimal; 6 | import java.time.Instant; 7 | import java.util.List; 8 | 9 | import static com.baeldung.kotlindsl.Reporter.StockPrice.stockPrice; 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | class SorterTest { 13 | 14 | Sorter sorter = new Sorter(); 15 | 16 | @Test 17 | void should_sort_stock_prices_descending_order_of_timestamp() { 18 | // given 19 | var now = Instant.now(); 20 | var list = List.of( 21 | stockPrice(new BigDecimal("12.5"), now.minusSeconds(12)), 22 | stockPrice(new BigDecimal("12.9"), now.minusSeconds(45)), 23 | stockPrice(new BigDecimal("11.5"), now.minusSeconds(10)) 24 | ); 25 | 26 | // when 27 | var result = sorter.sort(list); 28 | 29 | // then 30 | assertEquals(stockPrice(new BigDecimal("12.9"), now.minusSeconds(45)), result.get(0)); 31 | assertEquals(stockPrice(new BigDecimal("12.5"), now.minusSeconds(12)), result.get(1)); 32 | assertEquals(stockPrice(new BigDecimal("11.5"), now.minusSeconds(10)), result.get(2)); 33 | } 34 | } -------------------------------------------------------------------------------- /sonar-scanner/coverage-report/coverage-cobertua-flex.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | src 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 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner for Gradle 2 | 3 | This example demonstrates how to analyze a simple project built with [Gradle](https://gradle.org/). See [SonarScanner for Gradle](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/) for more information. 4 | 5 | ## Prerequisites 6 | * A gradle wrapper is included that bundles gradle. All other required plugins will be pulled by gradle as needed. 7 | 8 | ## Usage 9 | 10 | Run the following command (updating the sonar.host.url property as appropriate): 11 | 12 | * On Unix-like systems: 13 | ```text 14 | ./gradlew build -Dsonar.host.url=http://myhost:9000 sonar 15 | ``` 16 | * On Windows: 17 | ```text 18 | .\gradlew.bat build -D'sonar.host.url=http://myhost:9000' sonar 19 | ``` 20 | 21 | ## Coverage 22 | 23 | To get the project [test coverage](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/java-test-coverage/) computed, add gradle task `jacocoTestReport` to your command line. 24 | 25 | * On Unix-like systems: 26 | ```text 27 | ./gradlew build jacocoTestReport -Dsonar.host.url=http://myhost:9000 sonar 28 | ``` 29 | * On Windows: 30 | ```text 31 | .\gradlew.bat build jacocoTestReport -D'sonar.host.url=http://myhost:9000' sonar 32 | ``` 33 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/list/src/test/java/org/gradle/sample/list/LinkedListTest.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.list; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | public class LinkedListTest { 8 | @Test public void testConstructor() { 9 | LinkedList list = new LinkedList(); 10 | assertEquals(0, list.size()); 11 | } 12 | 13 | @Test public void testAdd() { 14 | LinkedList list = new LinkedList(); 15 | 16 | list.add("one"); 17 | assertEquals(1, list.size()); 18 | assertEquals("one", list.get(0)); 19 | 20 | list.add("two"); 21 | assertEquals(2, list.size()); 22 | assertEquals("two", list.get(1)); 23 | } 24 | 25 | @Test public void testRemove() { 26 | LinkedList list = new LinkedList(); 27 | 28 | list.add("one"); 29 | list.add("two"); 30 | assertTrue(list.remove("one")); 31 | 32 | assertEquals(1, list.size()); 33 | assertEquals("two", list.get(0)); 34 | 35 | assertTrue(list.remove("two")); 36 | assertEquals(0, list.size()); 37 | } 38 | 39 | @Test public void testRemoveMissing() { 40 | LinkedList list = new LinkedList(); 41 | 42 | list.add("one"); 43 | list.add("two"); 44 | assertFalse(list.remove("three")); 45 | assertEquals(2, list.size()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.sonarqube 8 | sonarscanner-maven-aggregate 9 | 1.0-SNAPSHOT 10 | 11 | 12 | tests 13 | 14 | Tests 15 | 16 | 17 | 18 | org.sonarqube 19 | module1 20 | 1.0-SNAPSHOT 21 | 22 | 23 | org.sonarqube 24 | module2 25 | 1.0-SNAPSHOT 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.jacoco 33 | jacoco-maven-plugin 34 | 35 | 36 | report 37 | 38 | report-aggregate 39 | 40 | verify 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /sonar-scanner/src/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic-20180426 2 | 3 | ENV DEBIAN_FRONTEND="noninteractive" 4 | 5 | RUN apt-get update && apt-get upgrade -y 6 | 7 | # Sensitive 8 | RUN apt install -y build-essential 9 | 10 | RUN curl http://www.example.com/ 11 | 12 | # Noncompliant 13 | RUN curl --tlsv1.0 -O https://tlsv1-0.example.com/downloads/install.sh 14 | 15 | #Curl Vulnerability https://www.cvedetails.com/cve/CVE-2018-1000300/ 16 | RUN apt-get install -y curl && \ 17 | #GIT Vulnerability CVE https://www.cvedetails.com/cve/CVE-2018-17456/ 18 | apt-get install -y git && \ 19 | #OpenSSH Vulnerability https://www.cvedetails.com/cve/CVE-2018-15473/ 20 | apt-get install -y openssh-server && \ 21 | #Installation of ftp server 22 | apt-get install -y proftpd 23 | 24 | COPY ./userfiles/shadow /etc/shadow 25 | COPY ./userfiles/passwd /etc/passwd 26 | RUN chmod o-rwx /etc/shadow 27 | RUN chmod o-rwx /etc/passwd 28 | COPY ./user-data-ftp/ /home/ 29 | COPY ./sshd_config /etc/ssh/sshd_config 30 | RUN service ssh start 31 | CMD ["proftpd", "--nodaemon"] 32 | 33 | # TODO Not correctly configure for ARM architecture 34 | #LibreOffice Vulnerability CVE https://www.cvedetails.com/cve/CVE-2019-9851/ 35 | #RUN curl -LO https://downloadarchive.documentfoundation.org/libreoffice/old/6.2.3.1/deb/x86_64/LibreOffice_6.2.3.1_Linux_x86-64_deb.tar.gz 36 | #RUN tar zxf LibreOffice_6.2.3.1_Linux_x86-64_deb.tar.gz 37 | #RUN cd LibreOffice_6.2.3.1_Linux_x86-64_deb/DEBS/ && \ 38 | # dpkg -i *.deb 39 | #RUN rm LibreOffice_6.2.3.1_Linux_x86-64_deb.tar.gz 40 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner for Gradle (Kotlin DSL) 2 | 3 | Example taken from https://github.com/Baeldung/kotlin-tutorials/tree/master/gradle-kotlin-dsl 4 | 5 | This example repository exemplifies usage of integrating [SonarScanner for Gradle](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/) with Gradle's Kotlin DSL. 6 | 7 | ## Example Usage 8 | Obtain your user token from your own account. See [Generating and using tokens](https://docs.sonarsource.com/sonarqube/latest/user-guide/user-account/generating-and-using-tokens/) for more information. 9 | 10 | Run the following command (update `sonar.host.url`, `sonar.organization`, etc. properties as needed either at command line or in `build.gradle.kts`'s `sonar` block): 11 | * On Unix-like systems: 12 | ``` 13 | ./gradlew clean build jacocoTestReport -Dsonar.host.url=http://localhost:9000 -Dsonar.login= sonar 14 | ``` 15 | * On Windows: 16 | ``` 17 | .\gradlew.bat clean build jacocoTestReport -Dsonar.host.url=http://localhost:9000 -Dsonar.login= sonar 18 | ``` 19 | 20 | Remove `jacocoTestReport` task to remove coverage report task 21 | 22 | ### Relevant Articles: 23 | - [Kotlin DSL for Gradle](https://www.baeldung.com/kotlin/gradle-dsl) 24 | - [Gradle's Kotlin DSL Primer](https://docs.gradle.org/current/userguide/kotlin_dsl.html) 25 | - [Migrating build logic from Groovy to Kotlin](https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html#migrating_groovy_kotlin) 26 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/main/java/com/baeldung/kotlindsl/Repository.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import com.baeldung.kotlindsl.Reporter.StockPrice; 4 | import com.baeldung.kotlindsl.Reporter.StockSymbol; 5 | 6 | import java.math.BigDecimal; 7 | import java.time.Instant; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import static com.baeldung.kotlindsl.Reporter.StockPrice.stockPrice; 12 | import static com.baeldung.kotlindsl.Reporter.StockSymbol.stockSymbol; 13 | 14 | public class Repository { 15 | 16 | private static final Map> priceBySymbol = Map.of( 17 | stockSymbol("TSL"), List.of( 18 | stockPrice(new BigDecimal("1.32"), Instant.parse("2021-01-01T15:00:00Z")), 19 | stockPrice(new BigDecimal("1.57"), Instant.parse("2021-05-05T15:00:00Z")), 20 | stockPrice(new BigDecimal("1.89"), Instant.parse("2021-02-03T15:00:00Z")) 21 | ), 22 | stockSymbol("FFB"), List.of( 23 | stockPrice(new BigDecimal("5.32"), Instant.parse("2021-05-01T15:00:00Z")), 24 | stockPrice(new BigDecimal("4.57"), Instant.parse("2021-02-05T15:00:00Z")), 25 | stockPrice(new BigDecimal("9.89"), Instant.parse("2021-09-03T15:00:00Z")) 26 | ) 27 | ); 28 | 29 | public List getStockPrice(StockSymbol stockSymbol) { 30 | if (!priceBySymbol.containsKey(stockSymbol)) { 31 | throw new RuntimeException("Invalid stock symbol " + stockSymbol); 32 | } 33 | return priceBySymbol.get(stockSymbol); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner for Gradle on a Kotlin project 2 | 3 | This example demonstrates how to analyze a Kotlin project built with [Gradle](https://gradle.org/). See [SonarScanner for Gradle](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/) for more information. 4 | 5 | ## Prerequisites 6 | * A running instance of SonarQube Server or a connection to SonarCloud (in that case you would need to pass `-Dsonar.organization=`). 7 | * A gradle wrapper is included that bundles gradle. All other required plugins will be pulled by gradle as needed. 8 | 9 | ## Usage 10 | 11 | Run the following command (updating the sonar.host.url property as appropriate): 12 | 13 | * On Unix-like systems: 14 | ```text 15 | ./gradlew build -Dsonar.host.url= -Dsonar.login= sonar 16 | ``` 17 | * On Windows: 18 | ```text 19 | .\gradlew.bat build -D'sonar.host.url=' -Dsonar.login= sonar 20 | ``` 21 | 22 | ## Coverage 23 | 24 | To get the project [test coverage](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/java-test-coverage/) computed, add gradle task `jacocoTestReport` to your command line. 25 | 26 | * On Unix-like systems: 27 | ```text 28 | ./gradlew build jacocoTestReport -Dsonar.host.url= -Dsonar.login= sonar 29 | ``` 30 | * On Windows: 31 | ```text 32 | .\gradlew.bat build jacocoTestReport -D'sonar.host.url=' -Dsonar.login= sonar 33 | ``` 34 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | function convert_xccov_to_xml { 5 | sed -n \ 6 | -e '/:$/s/&/\&/g;s/^\(.*\):$/ /p' \ 7 | -e 's/^ *\([0-9][0-9]*\): 0.*$/ /p' \ 8 | -e 's/^ *\([0-9][0-9]*\): [1-9].*$/ /p' \ 9 | -e 's/^$/ <\/file>/p' 10 | } 11 | 12 | function xccov_to_generic { 13 | local xcresult="$1" 14 | 15 | echo '' 16 | xcrun xccov view --archive "$xcresult" | convert_xccov_to_xml 17 | echo '' 18 | } 19 | 20 | function check_xcode_version() { 21 | local major=${1:-0} minor=${2:-0} 22 | return $(( (major >= 14) || (major == 13 && minor >= 3) )) 23 | } 24 | 25 | if ! xcode_version="$(xcodebuild -version | sed -n '1s/^Xcode \([0-9.]*\)$/\1/p')"; then 26 | echo 'Failed to get Xcode version' 1>&2 27 | exit 1 28 | elif check_xcode_version ${xcode_version//./ }; then 29 | echo "Xcode version '$xcode_version' not supported, version 13.3 or above is required" 1>&2; 30 | exit 1 31 | fi 32 | 33 | xcresult="$1" 34 | if [[ $# -ne 1 ]]; then 35 | echo "Invalid number of arguments. Expecting 1 path matching '*.xcresult'" 36 | exit 1 37 | elif [[ ! -d $xcresult ]]; then 38 | echo "Path not found: $xcresult" 1>&2; 39 | exit 1 40 | elif [[ $xcresult != *".xcresult"* ]]; then 41 | echo "Expecting input to match '*.xcresult', got: $xcresult" 1>&2; 42 | exit 1 43 | fi 44 | 45 | xccov_to_generic "$xcresult" 46 | -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/SomeConsoleApplication.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SomeConsoleApplication", "SomeConsoleApplication\SomeConsoleApplication.csproj", "{96FED58B-6B13-4B22-9D88-8CA270701FF5}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SomeConsoleApplicationTest", "SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj", "{69A603A4-4241-4F3B-846C-E95307293CF0}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {96FED58B-6B13-4B22-9D88-8CA270701FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {96FED58B-6B13-4B22-9D88-8CA270701FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {96FED58B-6B13-4B22-9D88-8CA270701FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {96FED58B-6B13-4B22-9D88-8CA270701FF5}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {69A603A4-4241-4F3B-846C-E95307293CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {69A603A4-4241-4F3B-846C-E95307293CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {69A603A4-4241-4F3B-846C-E95307293CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {69A603A4-4241-4F3B-846C-E95307293CF0}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /sonar-scanner-dotnet/CSharpProject/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner for .NET example 2 | Formerly known as SonarScanner for MSBuild. 3 | 4 | This example demonstrates how to analyze a .NET Solution with the [SonarScanner for .NET](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-dotnet/). Please review [Specifying test project analysis](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/dotnet-environments/specify-test-project-analysis/) to ensure your C# project is scanned correctly. 5 | 6 | ## Prerequisites 7 | * [SonarScanner for .NET](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-dotnet/) 8 | * [Compatible .NET Build Environment](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-dotnet/#prerequisites) 9 | 10 | ## Usage 11 | 1. Run SonarScanner for .NET begin phase: 12 | ```powershell 13 | SonarScanner.MSBuild.exe begin /k:"org.sonarqube:sonar-scanner-msbuild" /n:"Example of SonarScanner for MSBuild Usage" /d:sonar.token="" /d:sonar.host.url="http://localhost:9000" /v:"1.0" 14 | ``` 15 | or 16 | ```bash 17 | dotnet sonarscanner begin /k:"org.sonarqube:sonar-scanner-msbuild" /n:"Example of SonarScanner for MSBuild Usage" /d:sonar.token="" /d:sonar.host.url="http://localhost:9000 /v:"1.0" 18 | ``` 19 | 2. Build the project with MSBuild/dotnet: 20 | ```powershell 21 | MSBuild.exe /t:Rebuild 22 | ``` 23 | or 24 | ```bash 25 | dotnet build --no-incremental 26 | ``` 27 | 3. Run SonarScanner for .NET phase: 28 | ```powershell 29 | SonarScanner.MSBuild.exe end /d:sonar.token="" 30 | ``` 31 | or 32 | ```bash 33 | dotnet sonarscanner end /d:sonar.token="" 34 | ``` 35 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "jacoco" 3 | id "java" 4 | id "application" 5 | id("org.sonarqube") version "latest.release" 6 | } 7 | 8 | description = 'Example of SonarScanner for Gradle Usage' 9 | version = '1.0' 10 | 11 | sonar { 12 | properties { 13 | property('sonar.projectName', 'Example of SonarScanner for Gradle Usage') 14 | property("sonar.projectKey", "sonar-scanner-gradle") 15 | property("sonar.sources", "src/main") 16 | property "sonar.tests", "src/test" 17 | } 18 | } 19 | 20 | // In this section you declare where to find the dependencies of your project 21 | repositories { 22 | // Use jcenter for resolving your dependencies. 23 | // You can declare any Maven/Ivy/file repository here. 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | // This dependency is found on compile classpath of this component and consumers. 29 | implementation 'com.google.guava:guava:31.1-jre' 30 | 31 | // Use JUnit test framework 32 | testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2' 33 | implementation 'org.junit.jupiter:junit-jupiter:5.9.2' 34 | testRuntimeOnly 'org.junit.platform:junit-platform-launcher' 35 | } 36 | 37 | // Apply a specific Java toolchain to ease working on different environments. 38 | java { 39 | toolchain { 40 | languageVersion = JavaLanguageVersion.of(17) 41 | } 42 | sourceSets.main.java.srcDirs = ['src'] 43 | } 44 | 45 | application { 46 | // Define the main class for the application. 47 | mainClass='com.acme.App' 48 | } 49 | 50 | test { 51 | // Use JUnit Platform for unit tests. 52 | useJUnitPlatform() 53 | } 54 | 55 | jacocoTestReport { 56 | reports { 57 | xml.required = true 58 | html.outputLocation = layout.buildDirectory.dir('jacocoHtml') 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/test/java/org/jacoco/examples/parser/ExpressionParserTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.parser; 14 | 15 | import java.io.IOException; 16 | import static org.junit.Assert.*; 17 | import org.junit.Test; 18 | 19 | public class ExpressionParserTest { 20 | 21 | @Test 22 | public void expression1() throws IOException { 23 | assertExpression("2 * 3 + 4", 10); 24 | } 25 | 26 | @Test 27 | public void expression2() throws IOException { 28 | assertExpression("2 + 3 * 4", 14); 29 | } 30 | 31 | @Test 32 | public void expression3() throws IOException { 33 | assertExpression("(2 + 3) * 4", 20); 34 | } 35 | 36 | @Test 37 | public void expression4() throws IOException { 38 | assertExpression("2 * 2 * 2 * 2", 16); 39 | } 40 | 41 | @Test 42 | public void expression5() throws IOException { 43 | assertExpression("1 + 2 + 3 + 4", 10); 44 | } 45 | 46 | @Test 47 | public void expression6() throws IOException { 48 | assertExpression("2 * 3 + 2 * 5", 16); 49 | } 50 | 51 | private static void assertExpression(final String expression, 52 | final double expected) throws IOException { 53 | final ExpressionParser parser = new ExpressionParser(expression); 54 | final double actual = parser.parse().evaluate(); 55 | assertEquals("expression", expected, actual, 0.0); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/main/java/com/baeldung/kotlindsl/Sorter.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import com.baeldung.kotlindsl.Reporter.StockPrice; 4 | 5 | 6 | import javax.crypto.Cipher; 7 | import javax.crypto.NoSuchPaddingException; 8 | import java.security.NoSuchAlgorithmException; 9 | import java.util.List; 10 | 11 | import static java.util.Comparator.comparing; 12 | import static java.util.stream.Collectors.toList; 13 | 14 | public class Sorter { 15 | 16 | public String sillyTime() { 17 | try { 18 | Cipher c1 = Cipher.getInstance("DES"); // Noncompliant: DES works with 56-bit keys allow attacks via exhaustive search 19 | Cipher c7 = Cipher.getInstance("DESede"); // Noncompliant: Triple DES is vulnerable to meet-in-the-middle attack 20 | Cipher c13 = Cipher.getInstance("RC2"); // Noncompliant: RC2 is vulnerable to a related-key attack 21 | Cipher c19 = Cipher.getInstance("RC4"); // Noncompliant: vulnerable to several attacks (see https://en.wikipedia.org/wiki/RC4#Security) 22 | Cipher c25 = Cipher.getInstance("Blowfish"); // Noncompliant: Blowfish use a 64-bit block size makes it vulnerable to birthday attacks 23 | } catch(NoSuchAlgorithmException|NoSuchPaddingException e) { 24 | // Do something 25 | } 26 | 27 | String speech = "Now is the time for all good people to come to the aid of their country."; 28 | 29 | String s1 = speech.substring(0); // Noncompliant. Yields the whole string 30 | String s2 = speech.substring(speech.length()); // Noncompliant. Yields ""; 31 | String s3 = speech.substring(5,speech.length()); // Noncompliant. Use the 1-arg version instead 32 | 33 | return (s1 == s2 ? s3 : "pink"); 34 | } 35 | 36 | public List sort(List list) { 37 | return list.stream() 38 | .sorted(comparing(it -> it.timestamp)) 39 | .collect(toList()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner CLI on a Java Ant project with JaCoCo Coverage 2 | 3 | This example demonstrates how to analyze a simple project with Apache Ant and JaCoCo coverage. Code example is derived from [JaCoCo's own repository of examples](https://github.com/jacoco/jacoco/tree/v0.8.7/org.jacoco.examples/build). SonarScanner for Ant is deprecated on SonarCloud and as of SonarQube 9.9, therefore this is the current way of scanning an Ant project. Please see [Moving from SonarScanner for Ant to SonarScanner](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner-for-ant/#moving-from-sonarscanner-for-ant-to-sonarscanner) documentation for how to migrate to the SonarScanner. 4 | 5 | The JaCoCo coverage report is imported via the following Sonar scanner analysis parameter `sonar.coverage.jacoco.xmlReportPaths` (see [Test Coverage & Execution Overview](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/test-coverage/overview/)): 6 | 7 | ```xml 8 | 9 | ``` 10 | 11 | For more details on JaCoCo integration with Ant, see [JaCoCo Ant Tasks](https://www.eclemma.org/jacoco/trunk/doc/ant.html). 12 | 13 | ## Prerequisites 14 | * [SonarScanner CLI](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/) 15 | * [Ant](http://ant.apache.org/) 1.10.0 or higher 16 | * [JaCoCo](https://www.eclemma.org/jacoco/) 0.8.7 or higher 17 | * You can find Jacoco artifacts by version [here](https://repo1.maven.org/maven2/org/jacoco/jacoco/). Once unzipped, look for lib/jacocoant.jar 18 | 19 | ## Usage 20 | 1. Set the path to the JaCoCo Ant Task (jar) in the build.xml file. 21 | 2. Set the path to the JaCoCo XML report, if necessary. The default is set to `${result.report.dir}/report.xml` in the build.xml file. 22 | 3. Compile the project: 23 | ```shell 24 | ant rebuild 25 | ``` 26 | 4. Run SonarScanner CLI. 27 | -------------------------------------------------------------------------------- /sonar-scanner/src/kubernetes/newrelic-daemonset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1 2 | kind: DaemonSet 3 | metadata: 4 | name: newrelic-agent 5 | labels: 6 | tier: monitoring 7 | app: newrelic-agent 8 | version: v1 9 | spec: 10 | selector: 11 | matchLabels: # TODO finish adding labels 12 | name: newrelic 13 | template: 14 | metadata: 15 | labels: 16 | name: newrelic 17 | spec: 18 | # Filter to specific nodes: 19 | # nodeSelector: 20 | # app: newrelic 21 | hostPID: true 22 | hostIPC: true 23 | hostNetwork: true 24 | containers: 25 | - resources: 26 | requests: 27 | cpu: 0.15 28 | securityContext: 29 | privileged: true 30 | env: 31 | - name: NRSYSMOND_logfile 32 | value: "/var/log/nrsysmond.log" 33 | image: newrelic/nrsysmond 34 | name: newrelic 35 | command: [ "bash", "-c", "source /etc/kube-newrelic/config && /usr/sbin/nrsysmond -E -F" ] 36 | volumeMounts: 37 | - name: newrelic-config 38 | mountPath: /etc/kube-newrelic 39 | readOnly: true 40 | - name: dev 41 | mountPath: /dev 42 | - name: run 43 | mountPath: /var/run/docker.sock 44 | - name: sys 45 | mountPath: /sys 46 | - name: log 47 | mountPath: /var/log 48 | volumes: 49 | - name: newrelic-config 50 | secret: 51 | secretName: newrelic-config 52 | - name: dev 53 | hostPath: 54 | path: /dev 55 | - name: run 56 | hostPath: 57 | path: /var/run/docker.sock 58 | type: Socket 59 | - name: sys 60 | hostPath: 61 | path: /sys 62 | - name: log 63 | hostPath: 64 | path: /var/log 65 | -------------------------------------------------------------------------------- /sonar-scanner/coverage-report/execution-python.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/list/src/main/java/org/gradle/sample/list/LinkedList.java: -------------------------------------------------------------------------------- 1 | package org.gradle.sample.list; 2 | 3 | public class LinkedList { 4 | private Node head; 5 | 6 | public void add(String element) { 7 | Node newNode = new Node(element); 8 | 9 | Node it = tail(head); 10 | if (it == null) { 11 | head = newNode; 12 | } else { 13 | it.next = newNode; 14 | } 15 | } 16 | 17 | private static Node tail(Node head) { 18 | Node it; 19 | 20 | for (it = head; it != null && it.next != null; it = it.next) {} 21 | 22 | return it; 23 | } 24 | 25 | public boolean remove(String element) { 26 | boolean result = false; 27 | Node previousIt = null; 28 | Node it = null; 29 | for (it = head; !result && it != null; previousIt = it, it = it.next) { 30 | if (0 == element.compareTo(it.data)) { 31 | result = true; 32 | unlink(previousIt, it); 33 | break; 34 | } 35 | } 36 | 37 | return result; 38 | } 39 | 40 | private void unlink(Node previousIt, Node currentIt) { 41 | if (currentIt == head) { 42 | head = currentIt.next; 43 | } else { 44 | previousIt.next = currentIt.next; 45 | } 46 | } 47 | 48 | public int size() { 49 | int size = 0; 50 | 51 | for (Node it = head; it != null; ++size, it = it.next) {} 52 | 53 | return size; 54 | } 55 | 56 | public String get(int index) { 57 | Node it = head; 58 | while (index > 0 && it != null) { 59 | it = it.next; 60 | index--; 61 | } 62 | 63 | if (it == null) { 64 | throw new IndexOutOfBoundsException("Index is out of range"); 65 | } 66 | 67 | return it.data; 68 | } 69 | 70 | private static class Node { 71 | final String data; 72 | Node next; 73 | 74 | Node(String data) { 75 | this.data = data; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/test/java/com/baeldung/kotlindsl/ReporterUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.math.BigDecimal; 6 | import java.time.Instant; 7 | import java.util.List; 8 | 9 | import static com.baeldung.kotlindsl.Reporter.StockPrice.stockPrice; 10 | import static com.baeldung.kotlindsl.Reporter.StockSymbol.stockSymbol; 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | import static org.mockito.ArgumentMatchers.any; 13 | import static org.mockito.BDDMockito.given; 14 | import static org.mockito.Mockito.mock; 15 | 16 | class ReporterTest { 17 | 18 | Repository repository = mock(Repository.class); 19 | Sorter sorter = mock(Sorter.class); 20 | 21 | Reporter reporter = new Reporter(repository, sorter); 22 | 23 | @Test 24 | void should_sort_values_returned_by_repository_and_return() { 25 | // given 26 | var stock = stockSymbol("AAP"); 27 | given(repository.getStockPrice(stock)) 28 | .willReturn(List.of( 29 | stockPrice(new BigDecimal("1.32"), Instant.parse("2021-01-01T15:00:00Z")), 30 | stockPrice(new BigDecimal("1.57"), Instant.parse("2021-05-05T15:00:00Z")), 31 | stockPrice(new BigDecimal("1.89"), Instant.parse("2021-02-03T15:00:00Z")))); 32 | given(sorter.sort(any())) 33 | .willReturn(List.of( 34 | stockPrice(new BigDecimal("1.57"), Instant.parse("2021-05-05T15:00:00Z")), 35 | stockPrice(new BigDecimal("1.89"), Instant.parse("2021-02-03T15:00:00Z")), 36 | stockPrice(new BigDecimal("1.32"), Instant.parse("2021-01-01T15:00:00Z")))); 37 | 38 | // when 39 | var result = reporter.getStockPrice(stock); 40 | 41 | // then 42 | assertEquals(List.of( 43 | stockPrice(new BigDecimal("1.57"), Instant.parse("2021-05-05T15:00:00Z")), 44 | stockPrice(new BigDecimal("1.89"), Instant.parse("2021-02-03T15:00:00Z")), 45 | stockPrice(new BigDecimal("1.32"), Instant.parse("2021-01-01T15:00:00Z"))), 46 | result 47 | ); 48 | } 49 | } -------------------------------------------------------------------------------- /sonar-scanner/src/python/tests/test_shapes.py: -------------------------------------------------------------------------------- 1 | 2 | # test_shapes.py -- tests for shapes.py 3 | # 4 | # Copyright (c) 2010, A. G. Smith 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in 14 | # all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | # THE SOFTWARE. 23 | 24 | 25 | import unittest 26 | import shapes 27 | 28 | class TestShapes(unittest.TestCase): 29 | 30 | def setUp(self): 31 | pass 32 | 33 | def test_shape_init(self): 34 | shapes.Shape() 35 | 36 | def test_polygon_init(self): 37 | shapes.Polygon() 38 | 39 | def test_triangle_init(self): 40 | shapes.Triangle() 41 | 42 | def test_triangle_init(self): 43 | # failing test example 44 | b = 4 45 | h = 10 46 | t = shapes.Triangle(base=b, height=h) 47 | self.assertEqual(t.area(), (b*h)/2) 48 | 49 | def test_quadrilateral_init(self): 50 | shapes.Quadrilateral() 51 | 52 | def test_parallelogram_init(self): 53 | shapes.Parallelogram() 54 | 55 | def test_parallelogram_area(self): 56 | b = 4 57 | h = 10 58 | p = shapes.Parallelogram(base=b, height=h) 59 | self.assertEqual(p.area(), b*h) 60 | 61 | def test_square_init(self): 62 | shapes.Square() 63 | 64 | def test_rectangle_init(self): 65 | shapes.Rectangle() -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/src/main/java/com/baeldung/kotlindsl/Reporter.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.kotlindsl; 2 | 3 | import java.math.BigDecimal; 4 | import java.time.Instant; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | public final class Reporter { 9 | 10 | private final Repository repository; 11 | private final Sorter sorter; 12 | 13 | public Reporter(Repository repository, Sorter sorter) { 14 | this.repository = repository; 15 | this.sorter = sorter; 16 | } 17 | 18 | public List getStockPrice(StockSymbol stockSymbol) { 19 | return sorter.sort(repository.getStockPrice(stockSymbol)); 20 | } 21 | 22 | static final class StockPrice { 23 | 24 | public final BigDecimal price; 25 | public final Instant timestamp; 26 | 27 | private StockPrice(BigDecimal price, Instant timestamp) { 28 | this.price = price; 29 | this.timestamp = timestamp; 30 | } 31 | 32 | public static StockPrice stockPrice(BigDecimal price, Instant timestamp) { 33 | return new StockPrice(price, timestamp); 34 | } 35 | 36 | @Override 37 | public boolean equals(Object o) { 38 | if (this == o) return true; 39 | if (o == null || getClass() != o.getClass()) return false; 40 | StockPrice that = (StockPrice) o; 41 | return Objects.equals(price, that.price) && Objects.equals(timestamp, that.timestamp); 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return Objects.hash(price, timestamp); 47 | } 48 | } 49 | 50 | static class StockSymbol { 51 | 52 | public final String symbol; 53 | 54 | private StockSymbol(String symbol) { 55 | this.symbol = symbol; 56 | } 57 | 58 | public static StockSymbol stockSymbol(String symbol) { 59 | return new StockSymbol(symbol); 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) return true; 65 | if (o == null || getClass() != o.getClass()) return false; 66 | StockSymbol that = (StockSymbol) o; 67 | return Objects.equals(symbol, that.symbol); 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | return Objects.hash(symbol); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /sonar-scanner/src/vb6/Info.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form frmInfo 3 | BorderStyle = 3 'Fixed Dialog 4 | Caption = "Info" 5 | ClientHeight = 3750 6 | ClientLeft = 45 7 | ClientTop = 330 8 | ClientWidth = 6270 9 | Icon = "Info.frx":0000 10 | LinkTopic = "Form1" 11 | MaxButton = 0 'False 12 | MinButton = 0 'False 13 | ScaleHeight = 3750 14 | ScaleWidth = 6270 15 | ShowInTaskbar = 0 'False 16 | StartUpPosition = 1 'CenterOwner 17 | Begin VB.CommandButton cmdOK 18 | Caption = "&OK" 19 | Default = -1 'True 20 | Height = 375 21 | Left = 5100 22 | TabIndex = 1 23 | Top = 3300 24 | Width = 1095 25 | End 26 | Begin VB.TextBox txtGPL 27 | BackColor = &H8000000F& 28 | BorderStyle = 0 'None 29 | Height = 3075 30 | Left = 120 31 | Locked = -1 'True 32 | MultiLine = -1 'True 33 | TabIndex = 0 34 | Text = "Info.frx":000C 35 | Top = 120 36 | Width = 6015 37 | End 38 | End 39 | Attribute VB_Name = "frmInfo" 40 | Attribute VB_GlobalNameSpace = False 41 | Attribute VB_Creatable = False 42 | Attribute VB_PredeclaredId = True 43 | Attribute VB_Exposed = False 44 | ' --- GPL --- 45 | ' 46 | ' Copyright (C) 1999 SAP AG 47 | ' 48 | ' This program is free software; you can redistribute it and/or 49 | ' modify it under the terms of the GNU General Public License 50 | ' as published by the Free Software Foundation; either version 2 51 | ' of the License, or (at your option) any later version. 52 | ' 53 | ' This program is distributed in the hope that it will be useful, 54 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of 55 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 56 | ' GNU General Public License for more details. 57 | ' 58 | ' You should have received a copy of the GNU General Public License 59 | ' along with this program; if not, write to the Free Software 60 | ' Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 61 | ' 62 | ' --- GPL --- 63 | Option Explicit 64 | 65 | Private Sub cmdOK_Click() 66 | Unload Me 67 | End Sub 68 | -------------------------------------------------------------------------------- /sonar-scanner/copybooks/Attr.cpy: -------------------------------------------------------------------------------- 1 | 01 ATTRIBUTE-DEFINITIONS. 2 | * 3 | 05 ATTR-UNPROT PIC X VALUE ' '. 4 | 05 ATTR-UNPROT-MDT PIC X VALUE X'C1'. 5 | 05 ATTR-UNPROT-BRT PIC X VALUE X'C8'. 6 | 05 ATTR-UNPROT-BRT-MDT PIC X VALUE X'C9'. 7 | 05 ATTR-UNPROT-DARK PIC X VALUE X'4C'. 8 | 05 ATTR-UNPROT-DARK-MDT PIC X VALUE X'4D'. 9 | 05 ATTR-UNPROT-NUM PIC X VALUE X'50'. 10 | 05 ATTR-UNPROT-NUM-MDT PIC X VALUE X'D1'. 11 | 05 ATTR-UNPROT-NUM-BRT PIC X VALUE X'D8'. 12 | 05 ATTR-UNPROT-NUM-BRT-MDT PIC X VALUE X'D9'. 13 | 05 ATTR-UNPROT-NUM-DARK PIC X VALUE X'5C'. 14 | 05 ATTR-UNPROT-NUM-DARK-MDT PIC X VALUE X'5D'. 15 | 05 ATTR-PROT PIC X VALUE X'60'. 16 | 05 ATTR-PROT-MDT PIC X VALUE X'61'. 17 | 05 ATTR-PROT-BRT PIC X VALUE X'E8'. 18 | 05 ATTR-PROT-BRT-MDT PIC X VALUE X'E9'. 19 | 05 ATTR-PROT-DARK PIC X VALUE '%'. 20 | 05 ATTR-PROT-DARK-MDT PIC X VALUE X'6D'. 21 | 05 ATTR-PROT-SKIP PIC X VALUE X'F0'. 22 | 05 ATTR-PROT-SKIP-MDT PIC X VALUE X'F1'. 23 | 05 ATTR-PROT-SKIP-BRT PIC X VALUE X'F8'. 24 | 05 ATTR-PROT-SKIP-BRT-MDT PIC X VALUE X'F9'. 25 | 05 ATTR-PROT-SKIP-DARK PIC X VALUE X'7C'. 26 | 05 ATTR-PROT-SKIP-DARK-MDT PIC X VALUE X'7D'. 27 | * 28 | 05 ATTR-NO-HIGHLIGHT PIC X VALUE X'00'. 29 | 05 ATTR-BLINK PIC X VALUE '1'. 30 | 05 ATTR-REVERSE PIC X VALUE '2'. 31 | 05 ATTR-UNDERSCORE PIC X VALUE '4'. 32 | * 33 | 05 ATTR-DEFAULT-COLOR PIC X VALUE X'00'. 34 | 05 ATTR-BLUE PIC X VALUE '1'. 35 | 05 ATTR-RED PIC X VALUE '2'. 36 | 05 ATTR-PINK PIC X VALUE '3'. 37 | 05 ATTR-GREEN PIC X VALUE '4'. 38 | 05 ATTR-TURQUOISE PIC X VALUE '5'. 39 | 05 ATTR-YELLOW PIC X VALUE '6'. 40 | 05 ATTR-NEUTRAL PIC X VALUE '7'. 41 | -------------------------------------------------------------------------------- /sonar-scanner/src/python/shapes.py: -------------------------------------------------------------------------------- 1 | 2 | # shapes.py -- object oriented shapes 3 | # 4 | # Copyright (c) 2010, A. G. Smith 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in 14 | # all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | # THE SOFTWARE. 23 | 24 | 25 | class Shape(object): 26 | 27 | def __init__(self, *args, **kwargs): 28 | return 29 | 30 | 31 | class Polygon(Shape): 32 | 33 | def __init__(self, base=None, height=None, *args, **kwargs): 34 | super(Polygon, self).__init__(*args, **kwargs) 35 | self.base = base 36 | self.height = height 37 | 38 | 39 | class Triangle(Polygon): 40 | 41 | def __init__(self, *args, **kwargs): 42 | super(Triangle, self).__init__(*args, **kwargs) 43 | 44 | 45 | def area(self): 46 | return self.base * self.height # failing test example 47 | 48 | 49 | class Quadrilateral(Polygon): 50 | 51 | def __init__(self, *args, **kwargs): 52 | super(Quadrilateral, self).__init__(*args, **kwargs) 53 | 54 | 55 | class Parallelogram(Quadrilateral): 56 | 57 | def __init__(self, *args, **kwargs): 58 | super(Parallelogram, self).__init__(*args, **kwargs) 59 | 60 | def area(self): 61 | return self.base * self.height 62 | 63 | 64 | class Square(Parallelogram): 65 | 66 | def __init__(self, *args, **kwargs): 67 | super(Square, self).__init__(*args, **kwargs) 68 | 69 | 70 | class Rectangle(Parallelogram): 71 | 72 | def __init__(self, *args, **kwargs): 73 | super(Rectangle, self).__init__(*args, **kwargs) -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-basic/README.md: -------------------------------------------------------------------------------- 1 | # Basic Maven Example 2 | 3 | This simple Maven project demonstrates how to generate and import both code coverage and unit test results into SonarQube using the JaCoCo and Maven Surefire plugins. 4 | 5 | For a multi-module project example, see [multi-module Maven project](../maven-multimodule/README.md) 6 | 7 | ## What It Does 8 | 9 | This project includes: 10 | 11 | -**JaCoCo** for code coverage reporting 12 | -**maven-surefire-report-plugin** (version 3.5.3) to generate unit test result reports in XML format 13 | -Configuration to import both coverage and test results into SonarQube 14 | 15 | By configuring `maven-surefire-report-plugin` in the `` section, unit test results are automatically generate in `target/surefire-reports` during the Maven `verify` phase. 16 | 17 | ## Generated Files 18 | 19 | After running the build, the following directory is created: `target/surefire-reports` 20 | 21 | This contains `.xml` files for each test class, such as: 22 | 23 | - `TEST-com.example.MyClassTest.xml` 24 | 25 | These files are used by SonarQube to analyze unit test execution (number of tests, success rate, duration, failures, etc.). 26 | 27 | ## How It Shows in SonarQube 28 | 29 | Once the project is analyzed, SonarQube will show: 30 | 31 | - Number of unit tests executed 32 | - Test pass/fail rate 33 | - Code coverage (if JaCoCo is enabled) 34 | - Test execution time 35 | - Detailed test trends and metrics under the **Tests** tab of the project 36 | 37 | ## Usage 38 | * Build the project, execute all the tests and analyze the project with SonarScanner for Maven (from the root of the project): 39 | ```shell 40 | mvn clean verify sonar:sonar 41 | ``` 42 | 43 | * You can confirm that the sonar.junit.reportPaths parameter was picked up by checking the debug output: 44 | ``` 45 | [DEBUG] sonar.junit.reportPaths: target/surefire-reports 46 | ``` 47 | 48 | 49 | ## Documentation 50 | [SonarScanner for Maven](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-maven/) 51 | [Test Coverage Parameters](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/test-coverage-parameters/) 52 | [Importing Unit Test Results](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/test-execution-parameters) 53 | 54 | ## Notes 55 | If you omit the -Dsonar.junit.reportPaths=... flag, test execution results will not be imported unless configured elsewhere. 56 | The path is relative to the module being analyzed. -------------------------------------------------------------------------------- /sonar-scanner/src/html/sample.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | User list 14 | 15 | 16 | 17 | 18 |
  • Apple
  • 19 |
  • Strawberry
  • 20 | 21 | 22 | 23 | 24 | 25 | 26 | User 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
    51 | -------------------------------------------------------------------------------- /sonar-scanner/src/rpg/MYPROGRAM.rpg: -------------------------------------------------------------------------------- 1 | 123456789012 C* Expressions in Extended Factor 2 syntax 2 | 123456789012 C IF A=X OR A=Y AND A=Z 3 | 123456789012 C AND B=Y 4 | 123456789012 C READ Y 5 | 123456789012 C ENDIF 6 | 123456789012 C IF A=X OR A=Y AND A=Z 7 | 123456789012 C AND B=Y OR B=Z 8 | 123456789012 C READ Y 9 | 123456789012 C ENDIF 10 | 123456789012 C* Expressions composed over several operations in IF 11 | 123456789012 C A IFEQ X 12 | 123456789012 C A OREQ Y 13 | 123456789012 C A ANDEQ Z 14 | 123456789012 C B ANDEQ Y 15 | 123456789012 C READ Y 16 | 123456789012 C ENDIF 17 | 123456789012 C A IFEQ X 18 | 123456789012 C A OREQ Y 19 | 123456789012 C A ANDEQ Z 20 | 123456789012 C B ANDEQ Y 21 | 123456789012 C B OREQ Z 22 | 123456789012 C READ Y 23 | 123456789012 C ENDIF 24 | 123456789012 C* Expressions composed over several operations in DO 25 | 123456789012 C A DOUEQ X 26 | 123456789012 C A OREQ Y 27 | 123456789012 C A ANDEQ Z 28 | 123456789012 C B ANDEQ Y 29 | 123456789012 C READ Y 30 | 123456789012 C END 31 | 123456789012 C A DOUEQ X 32 | 123456789012 C A OREQ Y 33 | 123456789012 C A ANDEQ Z 34 | 123456789012 C B ANDEQ Y 35 | 123456789012 C B OREQ Z 36 | 123456789012 C READ Y 37 | 123456789012 C END 38 | 123456789012 C* Expressions composed over several operations in WHEN 39 | 123456789012 C SELECT 40 | 123456789012 C A WHENEQ X 41 | 123456789012 C A OREQ Y 42 | 123456789012 C A ANDEQ Z 43 | 123456789012 C B ANDEQ Y 44 | 123456789012 C READ Y 45 | 123456789012 C END 46 | 123456789012 C SELECT 47 | 123456789012 C A WHENEQ X 48 | 123456789012 C A OREQ Y 49 | 123456789012 C A ANDEQ Z 50 | 123456789012 C B ANDEQ Y 51 | 123456789012 C B OREQ Z 52 | 123456789012 C READ Y 53 | 123456789012 C END -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'jacoco' 4 | id "org.sonarqube" version "latest.release" 5 | } 6 | 7 | allprojects { 8 | version = '1.0.2' 9 | group = 'org.sonarqube.sample' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | } 15 | 16 | subprojects { 17 | apply plugin: 'org.sonarqube' 18 | sonar { 19 | properties { 20 | property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml" 21 | } 22 | } 23 | 24 | tasks.withType(Test).configureEach { 25 | useJUnitPlatform() 26 | } 27 | } 28 | 29 | apply from: "$project.rootDir/sonar.gradle" 30 | 31 | // See here for more info: https://docs.gradle.org/6.4-rc-1/samples/sample_jvm_multi_project_with_code_coverage.html 32 | // 33 | // task to gather code coverage from multiple subprojects 34 | // NOTE: the `JacocoReport` tasks do *not* depend on the `test` task by default. Meaning you have to ensure 35 | // that `test` (or other tasks generating code coverage) run before generating the report. 36 | // You can achieve this by calling the `test` lifecycle task manually 37 | // $ ./gradlew test codeCoverageReport 38 | tasks.register("codeCoverageReport", JacocoReport) { 39 | // If a subproject applies the 'jacoco' plugin, add the result it to the report 40 | subprojects { subproject -> 41 | subproject.plugins.withType(JacocoPlugin).configureEach { 42 | subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask -> 43 | //the jacoco extension may be disabled for some projects 44 | if (testTask.extensions.getByType(JacocoTaskExtension).isEnabled()) { 45 | sourceSets subproject.sourceSets.main 46 | executionData(testTask) 47 | } else { 48 | logger.warn('Jacoco extension is disabled for test task \'{}\' in project \'{}\'. this test task will be excluded from jacoco report.',testTask.getName(),subproject.getName()) 49 | } 50 | } 51 | 52 | // To automatically run `test` every time `./gradlew codeCoverageReport` is called, 53 | // you may want to set up a task dependency between them as shown below. 54 | // Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which 55 | // may have a negative effect on the configuration time of your build. 56 | subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach { 57 | rootProject.tasks.codeCoverageReport.dependsOn(it) 58 | } 59 | } 60 | } 61 | 62 | // enable the different report types (html, xml, csv) 63 | reports { 64 | xml.required = true 65 | html.required = true 66 | html.outputLocation = layout.buildDirectory.dir('jacocoHtml') 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-basic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.sonarqube 7 | sonarscanner-maven-basic 8 | 1.0-SNAPSHOT 9 | 10 | Example of basic Maven project 11 | 12 | 13 | UTF-8 14 | UTF-8 15 | 11 16 | 17 | 18 | 19 | 20 | com.google.guava 21 | guava 22 | 32.1.1-jre 23 | 24 | 25 | junit 26 | junit 27 | 4.13.1 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-compiler-plugin 38 | 3.8.1 39 | 40 | 41 | org.sonarsource.scanner.maven 42 | sonar-maven-plugin 43 | 5.1.0.4751 44 | 45 | 46 | org.jacoco 47 | jacoco-maven-plugin 48 | 0.8.11 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-surefire-report-plugin 53 | 3.5.3 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | coverage 62 | 63 | true 64 | 65 | 66 | 67 | 68 | org.jacoco 69 | jacoco-maven-plugin 70 | 71 | 72 | prepare-agent 73 | 74 | prepare-agent 75 | 76 | 77 | 78 | report 79 | 80 | report 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-project/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multilingual/README.md: -------------------------------------------------------------------------------- 1 | # Multilingual Maven Example 2 | 3 | This simple Maven project is importing JaCoCo's coverage report for Java and Kotlin sources in one module. For multi-module project example 4 | see [multi-module Maven project](../maven-multimodule/README.md) 5 | 6 | ## Usage 7 | 8 | * Build the project, execute all the tests and analyze the project with SonarQube Scanner for Maven(from root of the project): 9 | 10 | mvn clean verify sonar:sonar 11 | 12 | ## Documentation 13 | 14 | [SonarScanner for Maven](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-maven/) 15 | # Basic Maven Example 16 | 17 | This simple Maven project demonstrates how to generate and import both code coverage and unit test results into SonarQube using the JaCoCo and Maven Surefire plugins. 18 | 19 | For a multi-module project example, see [multi-module Maven project](../maven-multimodule/README.md) 20 | 21 | ## What It Does 22 | 23 | This project includes: 24 | 25 | -**JaCoCo** for code coverage reporting 26 | -**maven-surefire-report-plugin** (version 3.5.3) to generate unit test result reports in XML format 27 | -Configuration to import both coverage and test results into SonarQube 28 | 29 | By configuring `maven-surefire-report-plugin` in the `` section, unit test results are automatically generate in `target/surefire-reports` during the Maven `verify` phase. 30 | 31 | ## Generated Files 32 | 33 | After running the build, the following directory is created: `target/surefire-reports` 34 | 35 | This contains `.xml` files for each test class, such as: 36 | 37 | - `TEST-com.example.MyClassTest.xml` 38 | 39 | These files are used by SonarQube to analyze unit test execution (number of tests, success rate, duration, failures, etc.). 40 | 41 | ## How It Shows in SonarQube 42 | 43 | Once the project is analyzed, SonarQube will show: 44 | 45 | - Number of unit tests executed 46 | - Test pass/fail rate 47 | - Code coverage (if JaCoCo is enabled) 48 | - Test execution time 49 | - Detailed test trends and metrics under the **Tests** tab of the project 50 | 51 | ## Usage 52 | * Build the project, execute all the tests and analyze the project with SonarScanner for Maven (from the root of the project): 53 | ```shell 54 | mvn clean verify sonar:sonar 55 | ``` 56 | 57 | * You can confirm that the sonar.junit.reportPaths parameter was picked up by checking the debug output: 58 | ``` 59 | [DEBUG] sonar.junit.reportPaths: target/surefire-reports 60 | ``` 61 | 62 | 63 | ## Documentation 64 | [SonarScanner for Maven](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-maven/) 65 | [Test Coverage Parameters](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/test-coverage-parameters/) 66 | [Importing Unit Test Results](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/test-execution-parameters) 67 | 68 | ## Notes 69 | If you omit the -Dsonar.junit.reportPaths=... flag, test execution results will not be imported unless configured elsewhere. 70 | The path is relative to the module being analyzed. -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/src/main/java/org/jacoco/examples/parser/ExpressionParser.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 | * This program and the accompanying materials are made available under 4 | * the terms of the Eclipse Public License 2.0 which is available at 5 | * http://www.eclipse.org/legal/epl-2.0 6 | * 7 | * SPDX-License-Identifier: EPL-2.0 8 | * 9 | * Contributors: 10 | * Marc R. Hoffmann - initial API and implementation 11 | * 12 | *******************************************************************************/ 13 | package org.jacoco.examples.parser; 14 | 15 | import static java.io.StreamTokenizer.TT_EOF; 16 | import static java.io.StreamTokenizer.TT_NUMBER; 17 | 18 | import java.io.IOException; 19 | import java.io.StreamTokenizer; 20 | import java.io.StringReader; 21 | 22 | import org.jacoco.examples.expressions.Add; 23 | import org.jacoco.examples.expressions.Const; 24 | import org.jacoco.examples.expressions.Div; 25 | import org.jacoco.examples.expressions.IExpression; 26 | import org.jacoco.examples.expressions.Mul; 27 | import org.jacoco.examples.expressions.Sub; 28 | 29 | public class ExpressionParser { 30 | 31 | private final StreamTokenizer tokenizer; 32 | 33 | public ExpressionParser(final String s) throws IOException { 34 | tokenizer = new StreamTokenizer(new StringReader(s)); 35 | tokenizer.ordinaryChar('('); 36 | tokenizer.ordinaryChar(')'); 37 | tokenizer.ordinaryChar('+'); 38 | tokenizer.ordinaryChar('-'); 39 | tokenizer.ordinaryChar('*'); 40 | tokenizer.ordinaryChar('/'); 41 | } 42 | 43 | public IExpression parse() throws IOException { 44 | tokenizer.nextToken(); 45 | final IExpression e = term(); 46 | expect(TT_EOF); 47 | return e; 48 | } 49 | 50 | private IExpression term() throws IOException { 51 | IExpression e = product(); 52 | while (true) { 53 | if (accept('+')) { 54 | e = new Add(e, product()); 55 | } else if (accept('-')) { 56 | e = new Sub(e, product()); 57 | } else { 58 | return e; 59 | } 60 | } 61 | } 62 | 63 | private IExpression product() throws IOException { 64 | IExpression e = factor(); 65 | while (true) { 66 | if (accept('*')) { 67 | e = new Mul(e, factor()); 68 | } else if (accept('/')) { 69 | e = new Div(e, factor()); 70 | } else { 71 | return e; 72 | } 73 | } 74 | } 75 | 76 | private IExpression factor() throws IOException { 77 | final IExpression e; 78 | if (accept('(')) { 79 | e = term(); 80 | expect(')'); 81 | } else { 82 | expect(TT_NUMBER); 83 | e = new Const(tokenizer.nval); 84 | } 85 | return e; 86 | } 87 | 88 | private boolean accept(final int type) throws IOException { 89 | if (tokenizer.ttype == type) { 90 | tokenizer.nextToken(); 91 | return true; 92 | } 93 | return false; 94 | } 95 | 96 | private void expect(final int type) throws IOException { 97 | if (tokenizer.ttype != type) { 98 | throw new IOException("Invalid Syntax."); 99 | } 100 | tokenizer.nextToken(); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.sonarqube 7 | sonarscanner-maven-aggregate 8 | 1.0-SNAPSHOT 9 | pom 10 | 11 | Example of multi-module Maven project 12 | 13 | 14 | module1 15 | module2 16 | tests 17 | 18 | 19 | 20 | UTF-8 21 | UTF-8 22 | 1.8 23 | 1.8 24 | ${maven.multiModuleProjectDirectory}/tests/target/site/jacoco-aggregate/jacoco.xml 25 | 26 | 27 | 28 | 29 | com.google.guava 30 | guava 31 | 32.1.1-jre 32 | 33 | 34 | junit 35 | junit 36 | 4.13.1 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 3.8.1 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-surefire-report-plugin 52 | 3.5.3 53 | 54 | 55 | org.sonarsource.scanner.maven 56 | sonar-maven-plugin 57 | 5.1.0.4751 58 | 59 | 60 | org.jacoco 61 | jacoco-maven-plugin 62 | 0.8.11 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | coverage 71 | 72 | true 73 | 74 | 75 | 76 | 77 | org.jacoco 78 | jacoco-maven-plugin 79 | 80 | 81 | prepare-agent 82 | 83 | prepare-agent 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-basic/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /sonar-scanner-ant/ant-coverage/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | 18 | Example Ant build file that demonstrates how a JaCoCo coverage report 19 | can be integrated into an existing build with SonarScanner CLI for an Ant project. 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /swift-coverage/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner - Swift Code Coverage Example 2 | 3 | This example demonstrates how to import Xcode Coverage data to SonarQube for a Swift project. See [[Coverage & Test Data] Generate Reports for Swift](https://community.sonarsource.com/t/coverage-test-data-generate-reports-for-swift/9700) for more information including alternative methods to import coverage data into SonarQube/SonarCloud. 4 | 5 | ## Prerequisites 6 | * [SonarScanner](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/) 5.x or higher 7 | * [Xcode](https://developer.apple.com/xcode/) 13.3+ 8 | 9 | ## Usage 10 | 11 | Run the following commands in folder `swift-coverage-example`. 12 | 13 | ### Build project 14 | 15 | Use `xcodebuild` to build and test the project example with the command: 16 | 17 | ```shell 18 | xcodebuild -project swift-coverage-example.xcodeproj/ -scheme swift-coverage-example -derivedDataPath Build/ -enableCodeCoverage YES clean build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO 19 | ``` 20 | 21 | ### Using xccov (recommended) 22 | 23 | The `xccov` command line tool is the recommended option to view Xcode coverage 24 | data and is more straightforward to use than the older `llvm-cov` tool. With 25 | the script `xccov-to-sonarqube-generic.sh`, you can convert Xcode test results 26 | stored in `*.xcresult` folders to the [SonarQube generic test coverage format](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/test-coverage/generic-test-data/). 27 | 28 | First, locate the Xcode test result folder (`*.xcresult`). Then use it as a parameter to the script converting the coverage data to the SonarQube format as in the following example: 29 | 30 | ```shell 31 | bash xccov-to-sonarqube-generic.sh Build/Logs/Test/Run-swift-coverage-example-2023.01.27_16-07-44-+0100.xcresult/ >Coverage.xml 32 | ``` 33 | 34 | Then, use the parameter `sonar.coverageReportPaths` to reference the generated report: 35 | 36 | ```shell 37 | sonar-scanner -Dsonar.coverageReportPaths=Coverage.xml 38 | ``` 39 | 40 | This parameter accepts a comma-separated list of files, which means you can also provide multiple coverage reports from multiple test results. 41 | 42 | ### Using llvm-cov 43 | 44 | You can also provide code coverage data using the `llvm-cov` format. The 45 | process of generating an llvm-cov report requires several steps to get the 46 | coverage for the application executable and the dynamic library binaries. 47 | 48 | In the case of the project example, first, locate the `Coverage.profdata` file 49 | under the `ProfileData` folder. Then, generate an `llvm-cov` report as in the 50 | following example (the located `Coverage.profdata` file should be the value of `-instr-profile` parameter): 51 | 52 | ```shell 53 | xcrun --run llvm-cov show -instr-profile=Build/Build/ProfileData/00006000-000428843C29801E/Coverage.profdata \ 54 | Build/Build/Products/Debug/swift-coverage-example.app/Contents/MacOS/swift-coverage-example \ 55 | >Coverage.report 56 | ``` 57 | 58 | Finally, use the parameter `sonar.swift.coverage.reportPaths` to reference the generated report. This parameter also accepts a comma-separated list of files. 59 | 60 | ```shell 61 | sonar-scanner -Dsonar.swift.coverage.reportPaths=Coverage.report 62 | ``` 63 | 64 | ### Verify in SonarQube 65 | 66 | Verify in SonarQube that for the project `swift-coverage-example` the coverage value is around 75%. 67 | -------------------------------------------------------------------------------- /sonar-scanner/coverage-report/coverage-python.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ~/sonar/sonar-scanning-examples/sonar-scanner 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 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sonar Scanning Examples 2 | 3 | This repository showcases basic examples of usage and code coverage for SonarScanners. 4 | * [SonarScanner for Gradle](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle) 5 | * [SonarScanner for .NET](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-dotnet) 6 | * [SonarScanner for Maven](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-maven) 7 | * SonarScanner CLI in a Java Ant project (Formerly [SonarScanner for Ant](https://docs.sonarsource.com/sonarqube/9.9/analyzing-source-code/scanners/sonarscanner-for-ant) - This scanner is now deprecated. See link for more details) 8 | * [SonarScanner CLI](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner) 9 | 10 | Sonar's [Clean Code solution](https://www.sonarsource.com/solutions/clean-code/) helps developers deliver high-quality, efficient code standards that benefit the entire team or organization. 11 | 12 | ## Examples 13 | ### Various Languages 14 | * [SonarScanner for various languages](sonar-scanner) 15 | 16 | ### Ant 17 | Scaning an Ant project is no different than scanning a plain Java (no build tool) project. Ant is used to build the project, but not to run the scan. Instead, the SonarScanner CLI is used. 18 | * [SonarScanner for Ant - Basic](sonar-scanner-ant/ant-basic) 19 | * [SonarScanner for Ant - Code Coverage](sonar-scanner-ant/ant-coverage) 20 | 21 | [SonarScanner for Ant](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-ant) is now deprecated. Please migrate to the SonarScanner CLI. 22 | 23 | 24 | ### Gradle 25 | If you have a Gradle project, we recommend usage of [SonarScanner for Gradle](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle) or the equivalent SonarScanner for Gradle on your CI pipeline. 26 | * [SonarScanner for Gradle - Basic](sonar-scanner-gradle/gradle-basic) 27 | * [SonarScanner for Gradle - Kotlin DSL](sonar-scanner-gradle/gradle-kotlin-dsl) 28 | * [SonarScanner for Gradle - Multi-Module](sonar-scanner-gradle/gradle-multimodule) 29 | * [SonarScanner for Gradle - Multi-Module Code Coverage](sonar-scanner-gradle/gradle-multimodule-coverage) 30 | 31 | ### Maven 32 | If you have a Maven project, we recommend the usage of [SonarScanner for Maven](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-maven) or the equivalent SonarScanner for Maven on your CI pipeline. 33 | * [SonarScanner for Maven - Basic](sonar-scanner-maven/maven-basic) 34 | * [SonarScanner for Maven - Multilingual (Java + Kotlin with coverage)](sonar-scanner-maven/maven-multilingual) 35 | * [SonarScanner for Maven - Multi-Module](sonar-scanner-maven/maven-multimodule) 36 | 37 | ### DotNet/C# 38 | If you have a .NET project, we recommend the usage of [SonarScanner for .NET](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-dotnet) or the equivalent SonarScanner for .NET on your CI pipeline. 39 | * [SonarScanner for .NET/MSBuild - C#](sonar-scanner-msbuild/CSharpProject) 40 | 41 | ### Swift 42 | [SonarScanner - Swift Code Coverage](swift-coverage) 43 | 44 | ### C/C++/Objective-C 45 | **_NOTE:_** All SonarScanner examples for C, C++ and Objective-C can be found [here](https://github.com/sonarsource-cfamily-examples). 46 | 47 | ## License 48 | Copyright 2016-2025 SonarSource. 49 | 50 | Licensed under the [GNU Lesser General Public License, Version 3.0](http://www.gnu.org/licenses/lgpl.txt) 51 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | @rem Execute Gradle 88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 89 | 90 | :end 91 | @rem End local scope for the variables with windows NT shell 92 | if "%ERRORLEVEL%"=="0" goto mainEnd 93 | 94 | :fail 95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 96 | rem the _cmd.exe /c_ return code! 97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 98 | exit /b 1 99 | 100 | :mainEnd 101 | if "%OS%"=="Windows_NT" endlocal 102 | 103 | :omega 104 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-multimodule-coverage/README.md: -------------------------------------------------------------------------------- 1 | # SonarScanner for Gradle Multi-Module Project with Code Coverage 2 | 3 | This example project demonstrates how to analyze a multi-module project with Jacoco code coverage built with Gradle. 4 | 5 | ## Prerequisites 6 | * A Gradle wrapper is included that bundles Gradle. All other required plugins will be pulled by Gradle as needed. 7 | 8 | ## Usage 9 | Run the following command (update `sonar.host.url` and `sonar.token` analysis parameters as needed either at command line or in your `gradle.properties` file): 10 | * On Unix-like systems: 11 | ```shell 12 | ./gradlew clean build codeCoverageReport -Dsonar.host.url=http://localhost:9000 -Dsonar.token= sonar 13 | ``` 14 | * On Windows: 15 | ```shell 16 | .\gradlew.bat clean build codeCoverageReport -Dsonar.host.url=http://localhost:9000 -Dsonar.token= sonar 17 | ``` 18 | 19 | ## Coverage 20 | This example project is based on the original example project from Gradle's [sample project](https://docs.gradle.org/6.4-rc-1/samples/sample_jvm_multi_project_with_code_coverage.html) for reporting code coverage for Jacoco (Gradle 6.4-rc-1 and Gradle 6.6.1) as well as Andranik Azizbekian's [article](https://developer.disqo.com/blog/setup-android-project/) integrating SonarQube with a Kotlin Android project. 21 | 22 | Here are the important changes compared to the original Gradle sample project linked above in order for SonarQube to pick up the code coverage metric: 23 | * ensure `settings.gradle` references your modules 24 | * add reference to the SonarScanner for Gradle to the root `build.gradle`: 25 | ```groovy 26 | plugins { 27 | id "org.sonarqube" version "latest.release" 28 | } 29 | ``` 30 | * add the following to `subprojects{}` block of root `build.gradle`: 31 | ```groovy 32 | apply plugin: "org.sonarqube" 33 | sonar { 34 | properties { 35 | property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml" 36 | } 37 | } 38 | ``` 39 | * add a new file to root of project called `sonar.gradle` with the following contents: 40 | ```groovy 41 | apply plugin: "org.sonarqube" 42 | sonar { 43 | properties { 44 | property 'sonar.projectName', 'gradle-multimodule' 45 | property "sonar.projectKey", "gradle-multimodule" 46 | // Add other analysis parameters here if you don't 47 | // want to add it to the Sonar scanner command line: 48 | // property "sonar.host.url", "yoursonarqubeurl" 49 | // property "sonar.login", "yourlogintoken" 50 | // etc. 51 | } 52 | } 53 | ``` 54 | * add `apply from: "$project.rootDir/sonar.gradle"` to root `build.gradle` 55 | 56 | 57 | For other forms of Gradle and Maven code coverage, see [test coverage](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/java-test-coverage/) in the SonarSource community forum. 58 | 59 | ## Things to Note 60 | * You may notice this warning about bytecode dependencies: 61 | ```text 62 | Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property. 63 | ``` 64 | This is primarily due to the lack of dependencies (e.g. empty `dependencies {}` block) in this example project. Your actual project may include dependencies that can may include vulnerabilities, which will require setting `sonar.java.binaries` and `sonar.java.libraries` parameters to scan for them. To avoid this warning and thus avoid needing to configure `sonar.java.binaries` and `sonar.java.libraries` manually, ensure that you are using SonarScanner for Gradle instead of SonarScanner. By using SonarScanner for Gradle, the setting of `sonar.java.binaries` and `sonar.java.libraries` is done automatically for you. See also [Java](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/java/) for more details. 65 | -------------------------------------------------------------------------------- /sonar-scanner-gradle/gradle-kotlin-dsl/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.io.ByteArrayOutputStream 2 | import java.io.FileOutputStream 3 | import java.io.OutputStream 4 | 5 | plugins { 6 | jacoco 7 | `java-library` 8 | id("org.flywaydb.flyway") version "9.20.0" 9 | id("org.sonarqube") version "latest.release" 10 | id("org.gradle.maven-publish") // Noncompliant - kotlin:S6634 Core plugins IDs should be replaced by their shortcuts 11 | } 12 | 13 | version = "1.0-SNAPSHOT" 14 | 15 | repositories { 16 | mavenCentral() 17 | maven { 18 | url = uri("https://maven.springframework.org/release") 19 | } 20 | } 21 | 22 | sourceSets { 23 | create("integrationTest") { 24 | compileClasspath += sourceSets.main.get().output 25 | runtimeClasspath += sourceSets.main.get().output 26 | } 27 | } 28 | 29 | sonar { 30 | properties { 31 | property("sonar.projectKey", "baeldung-gradle-kotlin-dsl") 32 | property("sonar.projectName", "Example of Gradle Project with Kotlin DSL") 33 | } 34 | } 35 | 36 | val integrationTestImplementation: Configuration by configurations.getting { 37 | extendsFrom(configurations.implementation.get()) 38 | extendsFrom(configurations.testImplementation.get()) 39 | } 40 | 41 | val integrationTestRuntimeOnly: Configuration by configurations.getting { 42 | extendsFrom(configurations.implementation.get()) 43 | extendsFrom(configurations.testRuntimeOnly.get()) 44 | } 45 | 46 | val integrationTest = task("integrationTest") { 47 | useJUnitPlatform() 48 | description = "Task to run integration tests" 49 | group = "verification" 50 | 51 | testClassesDirs = sourceSets["integrationTest"].output.classesDirs 52 | classpath = sourceSets["integrationTest"].runtimeClasspath 53 | shouldRunAfter("test") 54 | } 55 | 56 | tasks.check { dependsOn(integrationTest) } 57 | 58 | dependencies { 59 | api("com.google.inject:guice:7.0.0") 60 | testImplementation("org.mockito:mockito-core:5.4.0") 61 | implementation("com.google.guava:guava:32.1.0-jre") 62 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") 63 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 64 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") 65 | } 66 | 67 | tasks.getByName("test") { 68 | useJUnitPlatform() 69 | } 70 | 71 | // Noncompliant - kotlin:S6623 "tasks.register()" should be preferred over "tasks.create()" 72 | tasks.create("dummyTaskThatI'llDoLater") { 73 | group = JavaBasePlugin.DOCUMENTATION_GROUP 74 | description = "My task." 75 | // other configuration logic 76 | 77 | doLast { 78 | // ... 79 | } 80 | } 81 | 82 | tasks.register("helloUserCmd") { 83 | val user: String? = System.getenv("USER") 84 | project.exec { 85 | commandLine("echo", "Hello,", "$user!") 86 | } 87 | } 88 | 89 | tasks.register("helloUserInVarCmd") { 90 | val outputStream = ByteArrayOutputStream() 91 | val user: String? = System.getenv("USER") 92 | project.exec { 93 | standardOutput = outputStream 94 | commandLine("echo", "Hello,", "$user!") 95 | } 96 | val output = outputStream.toString().trim() 97 | println("Command output: $output") 98 | } 99 | 100 | tasks.register("tmpFilesCmd") { 101 | val outputFile = File("/tmp/output.txt") 102 | val outputStream: OutputStream = FileOutputStream(outputFile) 103 | project.exec { 104 | standardOutput = outputStream 105 | workingDir = project.file("/tmp") 106 | commandLine("ls", workingDir) 107 | } 108 | } 109 | 110 | tasks.register("alwaysFailCmd") { 111 | val result = project.exec { 112 | commandLine("ls", "invalid_path") 113 | isIgnoreExitValue = true 114 | } 115 | if (result.exitValue == 0) { 116 | println("Command executed successfully.") 117 | } else { 118 | println("Command execution failed.") 119 | println("Command status: $result") 120 | } 121 | } 122 | 123 | tasks.jacocoTestReport { 124 | reports { 125 | xml.required.set(true) 126 | html.required.set(true) 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /sonar-scanner/src/python/strfile.py: -------------------------------------------------------------------------------- 1 | 2 | # strfile.py -- write an index file for a fortune file, as the strfile(8) 3 | # program in the BSD-games package does 4 | # 5 | # Copyright (c) 2010, Andrew M. Kuchling 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in 15 | # all copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | # THE SOFTWARE. 24 | 25 | import struct, string, sys 26 | 27 | if len(sys.argv)==1: 28 | print "Usage: strfile.py " 29 | sys.exit() 30 | 31 | # C long variables are different sizes on 32-bit and 64-bit machines, 32 | # so we have to measure how big they are on the machine where this is running. 33 | LONG_SIZE = struct.calcsize('L') 34 | is_64_bit = (LONG_SIZE == 8) 35 | 36 | delimiter = '%' # The standard delimiter 37 | 38 | filename = sys.argv[1] 39 | input = open(filename, 'r') 40 | output = open(filename + '.dat', 'w') 41 | output.seek(LONG_SIZE * 6) # Skip over the header for now 42 | 43 | # Output a 32- or 64-bit integer 44 | 45 | def write_long(x): 46 | if is_64_bit: 47 | output.write( struct.pack("!LL", x & 0xffffFFFFL, x >> 32) ) 48 | else: 49 | output.write( struct.pack("!L", x) ) 50 | 51 | write_long(0) # Write the first pointer 52 | 53 | # We need to track various statistics: the longest and shortest 54 | # quotations, and their number 55 | 56 | shortest = sys.maxint ; longest = 0 57 | numstr = 0 58 | quotation = "" 59 | 60 | while (1): 61 | L=input.readline() # Get a line 62 | if L=="": break # Check for end-of-file 63 | if string.strip(L) != delimiter: 64 | # We haven't come to the end yet, so we just add the line to 65 | # the quotation we're building and continue 66 | quotation = quotation + L ; continue 67 | 68 | # If there's a leading % in the file, the first quotation will be 69 | # empty; we'll just ignore it 70 | if quotation == "": continue 71 | 72 | # Update the shortest and longest variables 73 | shortest = min(shortest, len(quotation) ) 74 | longest = max(longest, len(quotation) ) 75 | 76 | # Output the current file pointer 77 | write_long( input.tell() ) 78 | numstr = numstr + 1 79 | quotation = "" # Reset the quotation to null 80 | 81 | # To simplify the programming, we'll assume there's a trailing % line 82 | # in the file, with no quotation following. 83 | assert quotation == "" 84 | 85 | input.close() 86 | 87 | # We're done, so rewind to the beginning of the file and write the header 88 | output.seek(0) 89 | write_long( 1 ) # Version 90 | write_long(numstr) # Number of strings 91 | write_long(longest) # Longest string length 92 | write_long(shortest) # Shortest string length 93 | write_long(0) # Flags; we'll set them to zero 94 | output.write(delimiter + '\0'*(LONG_SIZE-1)) 95 | output.close() 96 | 97 | print '''"%s.dat" created 98 | There were %i strings 99 | Longest string: %i bytes 100 | Shortest string: %i bytes''' % (filename, numstr, longest, shortest) 101 | -------------------------------------------------------------------------------- /sonar-scanner/src/pli/maxlen.pli: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 1995 by R. A. Vowels, from "Introduction to PL/I, Algorithms, and */ 2 | /* Structured Programming". Permission is given to reproduce and to use these procedures */ 3 | /* as part of a program, and to include them as part of a larger work to be sold for profit. */ 4 | /* However, the user is not permitted to sell the procedures separately. Provided always */ 5 | /* that these procedures and this copyright notice are reproduced in full. */ 6 | 7 | DECLARE MAXLENGTH GENERIC 8 | (MAXLEN_graphic WHEN (GRAPHIC), 9 | MAXLEN_bit WHEN (BIT), 10 | MAXLEN_char WHEN (*) ); 11 | 12 | /* This procedure is provided for those who must have the */ 13 | /* built-in function MAXLENGTH. Do not call it often, as */ 14 | /* run-time is relatively high. */ 15 | /* This procedure returns the maximum length that a VARYING character string may take. */ 16 | MAXLEN_char: 17 | PROCEDURE (STRING) RETURNS (FIXED BINARY); 18 | DECLARE STRING CHARACTER (*) VARYING; 19 | 20 | DECLARE LENGTH BUILTIN; 21 | DECLARE TEMP CHARACTER (32767) VARYING; 22 | DECLARE STR CHARACTER (32767) STATIC INITIAL ( ' ' ); 23 | DECLARE K FIXED BINARY; 24 | 25 | TEMP = STRING; /* Preserve a copy of the string. */ 26 | (NOSTRINGSIZE): 27 | STRING = STR; /* Assign something very long to it. */ 28 | K = LENGTH (STRING); /* Find out how long the variable is. */ 29 | STRING = TEMP; /* Restore the string. */ 30 | RETURN (K); /* The declared length of the string. */ 31 | END MAXLEN_char; 32 | 33 | /* This procedure returns the maximum length that a VARYING graphic string may take. */ 34 | MAXLEN_graphic: 35 | PROCEDURE (STRING) RETURNS (FIXED BINARY); 36 | DECLARE STRING GRAPHIC (*) VARYING; 37 | 38 | DECLARE LENGTH BUILTIN; 39 | DECLARE TEMP GRAPHIC (16383) VARYING; 40 | DECLARE STR GRAPHIC (16383) STATIC INITIAL ( ' ' ); 41 | DECLARE K FIXED BINARY; 42 | 43 | TEMP = STRING; /* Preserve a copy of the string. */ 44 | (NOSTRINGSIZE): 45 | STRING = STR; /* Assign something very long to it. */ 46 | K = LENGTH (STRING); /* Find out how long the variable is. */ 47 | STRING = TEMP; /* Restore the string. */ 48 | RETURN (K); /* The declared length of the string. */ 49 | END MAXLEN_graphic; 50 | 51 | /* This procedure returns the maximum length that a VARYING bit string may take. */ 52 | MAXLEN_bit: 53 | PROCEDURE (STRING) RETURNS (FIXED BINARY); 54 | DECLARE STRING BIT (*) VARYING; 55 | 56 | DECLARE LENGTH BUILTIN; 57 | DECLARE TEMP BIT (32767) VARYING; 58 | DECLARE STR BIT (32767) STATIC INITIAL ( '0'B); 59 | DECLARE K FIXED BINARY; 60 | 61 | TEMP = STRING; /* Preserve a copy of the string. */ 62 | (NOSTRINGSIZE): 63 | STRING = STR; /* Assign something very long to it. */ 64 | K = LENGTH (STRING); /* Find out how long the variable is. */ 65 | STRING = TEMP; /* Restore the string. */ 66 | RETURN (K); /* The declared length of the string. */ 67 | END MAXLEN_bit; 68 | -------------------------------------------------------------------------------- /sonar-scanner/src/python/fortune.py: -------------------------------------------------------------------------------- 1 | 2 | # fortune.py -- chooses a random fortune, as the fortune(8) program in 3 | # the BSD-games package does 4 | # 5 | # Copyright (c) 2010, Andrew M. Kuchling 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in 15 | # all copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | # THE SOFTWARE. 24 | 25 | import struct, random, string 26 | 27 | # C long variables are different sizes on 32-bit and 64-bit machines, 28 | # so we have to measure how big they are on the machine where this is running. 29 | LONG_SIZE = struct.calcsize('L') 30 | is_64_bit = (LONG_SIZE == 8) 31 | 32 | def get(filename): 33 | "Select a random quotation, using a pregenerated .dat file" 34 | 35 | # First, we open the .dat file, and read the header information. 36 | # The C structure containing this info looks like: 37 | ## typedef struct { /* information table */ 38 | ## #define VERSION 1 39 | ## unsigned long str_version; /* version number */ 40 | ## unsigned long str_numstr; /* # of strings in the file */ 41 | ## unsigned long str_longlen; /* length of longest string */ 42 | ## unsigned long str_shortlen; /* length of shortest string */ 43 | ## #define STR_RANDOM 0x1 /* randomized pointers */ 44 | ## #define STR_ORDERED 0x2 /* ordered pointers */ 45 | ## #define STR_ROTATED 0x4 /* rot-13'd text */ 46 | ## unsigned long str_flags; /* bit field for flags */ 47 | ## unsigned char stuff[4]; /* long aligned space */ 48 | ## #define str_delim stuff[0] /* delimiting character */ 49 | ## } STRFILE; 50 | 51 | datfile = open(filename+'.dat', 'r') 52 | data = datfile.read(5 * LONG_SIZE) 53 | if is_64_bit: 54 | v1, v2, n1, n2, l1, l2, s1, s2, f1, f2 = struct.unpack('!10L', data) 55 | version = v1 + (v2 << 32) 56 | numstr = n1 + (n2 << 32) 57 | longlen = l1 + (l2 << 32) 58 | shortlen = s1 + (s2 << 32) 59 | flags = f1 + (f2 << 32) 60 | else: 61 | version, numstr, longlen, shortlen, flags = struct.unpack('5l', data) 62 | 63 | delimiter = datfile.read(1) 64 | datfile.read(3) # Throw away padding bytes 65 | if is_64_bit: datfile.read(4) # 64-bit machines align to 8 bytes 66 | 67 | # Pick a random number 68 | r = random.randint(0, numstr) 69 | datfile.seek(LONG_SIZE * r, 1) # Seek to the chosen pointer 70 | data = datfile.read(LONG_SIZE * 2) 71 | 72 | if is_64_bit: 73 | s1, s2, e1, e2 = struct.unpack('!4L', data) 74 | start, end = s1 + (s2 << 32), e1 + (e2 << 32) 75 | else: 76 | start, end = struct.unpack('!ll', data) 77 | datfile.close() 78 | 79 | file = open(filename, 'r') 80 | file.seek(start) 81 | quotation = file.read(end-start) 82 | L=string.split(quotation, '\n') 83 | while string.strip(L[-1]) == delimiter or string.strip(L[-1]) == "": 84 | L=L[:-1] 85 | return string.join(L, '\n') 86 | 87 | if __name__ == '__main__': 88 | import sys 89 | if len(sys.argv) == 1: 90 | print 'Usage: fortune.py ' 91 | sys.exit() 92 | print get(sys.argv[1]) 93 | -------------------------------------------------------------------------------- /swift-coverage/swift-coverage-example/swift-coverage-example.xcodeproj/xcshareddata/xcschemes/swift-coverage-example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 35 | 41 | 42 | 43 | 44 | 45 | 51 | 52 | 53 | 54 | 55 | 56 | 67 | 69 | 75 | 76 | 77 | 78 | 79 | 80 | 86 | 88 | 94 | 95 | 96 | 97 | 99 | 100 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multimodule/README.md: -------------------------------------------------------------------------------- 1 | # Multi-module Maven Example 2 | 3 | This project imports both: 4 | 5 | - JaCoCo's aggregate XML report to enable code coverage reporting across modules 6 | - Maven Surefire XML test reports to include unit test results for each module 7 | 8 | For a basic example, see [basic Maven project](../maven-basic/README.md). 9 | 10 | ## Usage 11 | 12 | Build the project, execute all the tests, and analyze it with SonarScanner for Maven: 13 | 14 | ```shell 15 | mvn clean verify sonar:sonar \ 16 | -Dsonar.coverage.jacoco.xmlReportPaths=$(pwd)/tests/target/site/jacoco-aggregate/jacoco.xml \ 17 | -Dsonar.junit.reportPaths=target/surefire-reports 18 | ``` 19 | 20 | ## Description 21 | 22 | This project consists of 3 modules: 23 | 24 | * [`module1`](module1/pom.xml) and [`module2`](module2/pom.xml) contain "business logic" and related unit tests. 25 | 26 | * [`tests`](tests/pom.xml) module contains integration tests which test functionality using both modules. 27 | `tests` module is also the one which creates the aggregate coverage report imported into SonarQube. 28 | 29 | ## Code Coverage with JaCoCo 30 | To collect code coverage across all modules: 31 | ### 1. JaCoCo Agent Setup 32 | In the top-level pom.xml, the JaCoCo plugin is configured under so it applies to all submodules. It is wrapped in the coverage profile to make it activatable (e.g. in CI): 33 | 34 | ``` 35 | 36 | 37 | 38 | 39 | org.jacoco 40 | jacoco-maven-plugin 41 | 42 | 43 | 44 | prepare-agent 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ``` 53 | 54 | ### 2. Generate Aggregate Coverage Report 55 | In the `tests` module, the `report-aggregate` goal is configured to run in the `verify` phase to generate a coverage report combining all modules: 56 | 57 | ``` 58 | 59 | 60 | 61 | org.jacoco 62 | jacoco-maven-plugin 63 | 64 | 65 | report 66 | 67 | report-aggregate 68 | 69 | verify 70 | 71 | 72 | 73 | 74 | 75 | ``` 76 | 77 | This creates the report at: 78 | ``` 79 | tests/target/site/jacoco-aggregate/jacoco.xml 80 | ``` 81 | 82 | To import it into SonarQube, set the path in the top-level `pom.xml`: 83 | 84 | ``` 85 | 86 | ${maven.multiModuleProjectDirectory}/tests/target/site/jacoco-aggregate/jacoco.xml 87 | 88 | ``` 89 | 90 | Or pass it directly via the command line: 91 | 92 | ``` 93 | -Dsonar..coverage.jacoco.xmlReportPaths=absolute/path/to/jacoco.xml 94 | ``` 95 | 96 | ## Unit Test Result Reporting 97 | To include unit test results (e.g. passed/failed/skipped test count, execution time) in SonarQube: 98 | 99 | ### Surefire Plugin Configuration 100 | 101 | The maven-surefire-report-plugin (version 3.5.3) is included in the root pom.xml under , ensuring all modules inherit it: 102 | 103 | ``` 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-surefire-report-plugin 109 | 3.5.3 110 | 111 | 112 | 113 | ``` 114 | 115 | During the `verify` phase, this generates XML reports in each module's `target/surefire-reports/` directory: 116 | 117 | ``` 118 | module1/target/surefire-reports/TEST-com.example.FooTest.xml 119 | module2/target/surefire-reports/TEST-com.example.BarTest.xml 120 | ``` 121 | 122 | To import these into SonarQube, set: 123 | 124 | ``` 125 | -Dsonar.junit.reportPaths=target/surefire-reports 126 | ``` 127 | 128 | ## SonarQube Results 129 | After analysis, SonarQube will display: 130 | 131 | - Code coverage metrics from jacoco.xml 132 | - Test execution stats from Surefire XML files: 133 | - Total tests 134 | - Passed/failed/skipped 135 | - Execution duration 136 | - Trends and drill-down under the "Tests" and "Coverage" tabs 137 | 138 | ## Documentation 139 | 140 | [SonarScanner for Maven](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-maven/) 141 | -------------------------------------------------------------------------------- /sonar-scanner/src/terraform/azure/sql.tf: -------------------------------------------------------------------------------- 1 | resource "azurerm_sql_firewall_rule" "example" { 2 | name = "terragoat-firewall-rule-${var.environment}" 3 | resource_group_name = azurerm_resource_group.example.name 4 | server_name = azurerm_sql_server.example.name 5 | start_ip_address = "10.0.17.62" 6 | end_ip_address = "10.0.17.62" 7 | } 8 | 9 | resource "azurerm_sql_server" "example" { 10 | name = "terragoat-sqlserver-${var.environment}${random_integer.rnd_int.result}" 11 | resource_group_name = azurerm_resource_group.example.name 12 | location = azurerm_resource_group.example.location 13 | version = "12.0" 14 | administrator_login = "ariel" 15 | administrator_login_password = "Aa12345678" 16 | tags = merge({ 17 | environment = var.environment 18 | terragoat = "true" 19 | }, { 20 | git_commit = "81738b80d571fa3034633690d13ffb460e1e7dea" 21 | git_file = "terraform/azure/sql.tf" 22 | git_last_modified_at = "2020-06-19 21:14:50" 23 | git_last_modified_by = "Adin.Ermie@outlook.com" 24 | git_modifiers = "Adin.Ermie/nimrodkor" 25 | git_org = "bridgecrewio" 26 | git_repo = "terragoat" 27 | yor_trace = "e5ec3432-e61f-4244-b59e-9ecc24ddd4cb" 28 | }) 29 | } 30 | 31 | resource "azurerm_mssql_server_security_alert_policy" "example" { 32 | resource_group_name = azurerm_resource_group.example.name 33 | server_name = azurerm_sql_server.example.name 34 | state = "Enabled" 35 | storage_endpoint = azurerm_storage_account.example.primary_blob_endpoint 36 | storage_account_access_key = azurerm_storage_account.example.primary_access_key 37 | disabled_alerts = [ 38 | "Sql_Injection", 39 | "Data_Exfiltration" 40 | ] 41 | retention_days = 20 42 | } 43 | 44 | resource "azurerm_mysql_server" "example" { 45 | name = "terragoat-mysql-${var.environment}${random_integer.rnd_int.result}" 46 | location = azurerm_resource_group.example.location 47 | resource_group_name = azurerm_resource_group.example.name 48 | 49 | administrator_login = "terragoat-${var.environment}" 50 | administrator_login_password = random_string.password.result 51 | 52 | sku_name = "B_Gen5_2" 53 | storage_mb = 5120 54 | version = "5.7" 55 | 56 | auto_grow_enabled = true 57 | backup_retention_days = 7 58 | infrastructure_encryption_enabled = true 59 | public_network_access_enabled = true 60 | ssl_enforcement_enabled = false 61 | tags = { 62 | git_commit = "81738b80d571fa3034633690d13ffb460e1e7dea" 63 | git_file = "terraform/azure/sql.tf" 64 | git_last_modified_at = "2020-06-19 21:14:50" 65 | git_last_modified_by = "Adin.Ermie@outlook.com" 66 | git_modifiers = "Adin.Ermie/nimrodkor" 67 | git_org = "bridgecrewio" 68 | git_repo = "terragoat" 69 | yor_trace = "1ac18c16-09a4-41c9-9a66-6f514050178e" 70 | } 71 | } 72 | 73 | resource "azurerm_postgresql_server" "example" { 74 | name = "terragoat-postgresql-${var.environment}${random_integer.rnd_int.result}" 75 | location = azurerm_resource_group.example.location 76 | resource_group_name = azurerm_resource_group.example.name 77 | sku_name = "B_Gen5_2" 78 | storage_mb = 5120 79 | backup_retention_days = 7 80 | geo_redundant_backup_enabled = false 81 | auto_grow_enabled = true 82 | administrator_login = "terragoat" 83 | administrator_login_password = "Aa12345678" 84 | version = "9.5" 85 | ssl_enforcement_enabled = false 86 | tags = { 87 | git_commit = "81738b80d571fa3034633690d13ffb460e1e7dea" 88 | git_file = "terraform/azure/sql.tf" 89 | git_last_modified_at = "2020-06-19 21:14:50" 90 | git_last_modified_by = "Adin.Ermie@outlook.com" 91 | git_modifiers = "Adin.Ermie/nimrodkor" 92 | git_org = "bridgecrewio" 93 | git_repo = "terragoat" 94 | yor_trace = "9eae126d-9404-4511-9c32-2243457df459" 95 | } 96 | } 97 | 98 | resource "azurerm_postgresql_configuration" "thrtottling_config" { 99 | name = "connection_throttling" 100 | resource_group_name = azurerm_resource_group.example.name 101 | server_name = azurerm_postgresql_server.example.name 102 | value = "off" 103 | } 104 | 105 | resource "azurerm_postgresql_configuration" "example" { 106 | name = "log_checkpoints" 107 | resource_group_name = azurerm_resource_group.example.name 108 | server_name = azurerm_postgresql_server.example.name 109 | value = "off" 110 | } 111 | -------------------------------------------------------------------------------- /sonar-scanner-maven/maven-multilingual/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.sonarqube 7 | sonarscanner-maven-multilingual 8 | 1.0-SNAPSHOT 9 | 10 | Example of multilingual Maven project 11 | 12 | 13 | UTF-8 14 | UTF-8 15 | 11 16 | 11 17 | 11 18 | 11 19 | 1.4.10 20 | src/main/java,src/main/kotlin 21 | src/test/java,src/test/kotlin 22 | 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.13.1 29 | test 30 | 31 | 32 | org.jetbrains.kotlin 33 | kotlin-stdlib-jdk8 34 | ${kotlin.version} 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.jacoco 43 | jacoco-maven-plugin 44 | 0.8.11 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-surefire-report-plugin 49 | 3.5.3 50 | 51 | 52 | org.sonarsource.scanner.maven 53 | sonar-maven-plugin 54 | 5.1.0.4751 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.codehaus.mojo 62 | build-helper-maven-plugin 63 | 3.0.0 64 | 65 | 66 | generate-sources 67 | 68 | add-source 69 | 70 | add-source 71 | 72 | 73 | src/main/kotlin 74 | 75 | 76 | 77 | 78 | add-test-source 79 | generate-test-sources 80 | 81 | add-test-source 82 | 83 | 84 | 85 | src/test/kotlin 86 | 87 | 88 | 89 | 90 | 91 | 92 | org.jetbrains.kotlin 93 | kotlin-maven-plugin 94 | ${kotlin.version} 95 | 96 | 97 | compile 98 | compile 99 | 100 | compile 101 | 102 | 103 | 104 | test-compile 105 | test-compile 106 | 107 | test-compile 108 | 109 | 110 | 111 | 112 | 1.8 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | coverage 121 | 122 | true 123 | 124 | 125 | 126 | 127 | org.jacoco 128 | jacoco-maven-plugin 129 | 130 | 131 | prepare-agent 132 | 133 | prepare-agent 134 | 135 | 136 | 137 | report 138 | 139 | report 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /sonar-scanner/src/abap/ZBCMKZ17.abap: -------------------------------------------------------------------------------- 1 | REPORT ZBCMKZ17. 2 | *----------------------------------------------------------------------* 3 | * Description: Report and Transaction Starter * 4 | * It shows an individual list of reports/Trans. to start* 5 | * * 6 | * Authorization: S_PROGRAM, Reports starten * 7 | * * 8 | * Class: Utility * 9 | * * 10 | * Customizing: Needs Customer Table: ZBCMKZ1 * 11 | * Field: Key Type Length Descr. * 12 | * ZBCMKZ1-BNAME X CHAR C 12 User name * 13 | * ZBCMKZ1-NAME X CHAR C 8 Report/Trans. code * 14 | * ZBCMKZ1-NUMMER INT1 X 1 Priority level * 15 | * * 16 | * R/3 Release: 3.0d * 17 | * * 18 | * Programmer: Bence Toth * 19 | * Date: 1997 April * 20 | * * 21 | *----------------------------------------------------------------------* 22 | INCLUDE: . 23 | TABLES: ZBCMKZ1, TRDIR, TSTCT, TSTC. 24 | DATA: BEGIN OF BTAB OCCURS 50, "Hilfstabelle fuer Textpool 25 | CODE(82), 26 | END OF BTAB. 27 | DATA: BEGIN OF T OCCURS 100, 28 | NUMMER LIKE ZBCMKZ1-NUMMER, 29 | NAME LIKE TRDIR-NAME, 30 | CODE(82), 31 | END OF T. 32 | DATA: FI(20). 33 | DATA BEGIN OF BDCDATA OCCURS 100. 34 | INCLUDE STRUCTURE BDCDATA. 35 | DATA END OF BDCDATA. 36 | 37 | DATA BEGIN OF MESSTAB OCCURS 10. 38 | INCLUDE STRUCTURE BDCMSGCOLL. 39 | DATA END OF MESSTAB. 40 | 41 | DATA REPORT. 42 | AUTHORITY-CHECK OBJECT 'S_PROGRAM' 43 | ID 'P_GROUP' FIELD '*' 44 | ID 'P_ACTION' FIELD '*'. 45 | IF SY-SUBRC NE 0. EXIT. ENDIF. 46 | WRITE: /2 'Er. Modus', 12 'Name', 22 'Text'. 47 | 48 | 49 | DETAIL. 50 | SKIP. 51 | SELECT * FROM ZBCMKZ1 WHERE BNAME EQ SY-UNAME. 52 | CHECK ZBCMKZ1-NAME+5(1) EQ ' '. 53 | SELECT SINGLE * FROM TSTC WHERE TCODE EQ ZBCMKZ1-NAME. 54 | CHECK SY-SUBRC EQ 0. 55 | CLEAR TSTCT. 56 | SELECT SINGLE * FROM TSTCT WHERE SPRSL EQ SY-LANGU AND 57 | TCODE EQ ZBCMKZ1-NAME. 58 | T-CODE = TSTCT-TTEXT. 59 | MOVE-CORRESPONDING ZBCMKZ1 TO T. 60 | APPEND T. 61 | CLEAR T. 62 | ENDSELECT. 63 | SORT T BY NUMMER CODE. 64 | REPORT = ' '. 65 | PERFORM LIST USING REPORT. 66 | SELECT * FROM ZBCMKZ1 WHERE BNAME EQ SY-UNAME. 67 | CHECK ZBCMKZ1-NAME+5(1) NE ' '. 68 | READ TEXTPOOL ZBCMKZ1-NAME INTO BTAB LANGUAGE SY-LANGU. 69 | CHECK SY-SUBRC EQ 0. 70 | LOOP AT BTAB. 71 | IF BTAB-CODE(1) EQ 'R'. 72 | EXIT. 73 | ENDIF. 74 | ENDLOOP. 75 | MOVE BTAB-CODE+9(70) TO T-CODE. 76 | MOVE-CORRESPONDING ZBCMKZ1 TO T. 77 | APPEND T. 78 | CLEAR T. 79 | ENDSELECT. 80 | SORT T BY NUMMER CODE. 81 | REPORT = 'X'. 82 | PERFORM LIST USING REPORT. 83 | 84 | AT LINE-SELECTION. 85 | CHECK NOT ( T-NAME IS INITIAL ). 86 | GET CURSOR FIELD FI. 87 | IF T-NAME+5(1) EQ ' '. 88 | REPORT = ' '. 89 | ELSE. 90 | REPORT = 'X'. 91 | ENDIF. 92 | IF FI = 'ICON_EXECUTE_OBJECT'. 93 | PERFORM PERO USING T-NAME REPORT. 94 | ELSEIF REPORT EQ ' '. 95 | * SELECT SINGLE * FROM TSTC WHERE TCODE EQ ZBCMKZ1-NAME. 96 | * IF T+5(1) EQ ' '. 97 | CALL TRANSACTION T-NAME. 98 | ELSE. 99 | SUBMIT (T-NAME) VIA SELECTION-SCREEN AND RETURN. 100 | ENDIF. 101 | CLEAR T-NAME. 102 | *---------------------------------------------------------------------* 103 | * FORM LIST * 104 | *---------------------------------------------------------------------* 105 | * ........ * 106 | *---------------------------------------------------------------------* 107 | FORM LIST USING REPORT. 108 | LOOP AT T. 109 | IF REPORT = ' '. 110 | WRITE: /5 ICON_EXECUTE_OBJECT AS ICON, T-NAME UNDER 'Name', 111 | T-CODE UNDER 'Text'. 112 | ELSE. 113 | WRITE: / T-NAME UNDER 'Name', T-CODE UNDER 'Text'. 114 | ENDIF. 115 | HIDE T. 116 | AT END OF NUMMER. 117 | SKIP. 118 | ENDAT. 119 | ENDLOOP. 120 | SKIP. 121 | CLEAR T. 122 | REFRESH T. 123 | ENDFORM. 124 | *---------------------------------------------------------------------* 125 | * FORM PERO * 126 | *---------------------------------------------------------------------* 127 | * ........ * 128 | *---------------------------------------------------------------------* 129 | * --> T-NAME * 130 | *---------------------------------------------------------------------* 131 | FORM PERO USING T-NAME REPORT. 132 | CHECK REPORT EQ ' '. 133 | MOVE T-NAME TO T-NAME+2(4). 134 | MOVE '/o' TO T-NAME+0(2). 135 | BDCDATA-PROGRAM = 'SAPMS01J'. 136 | BDCDATA-DYNPRO = '0310'. 137 | BDCDATA-DYNBEGIN = 'X'. 138 | APPEND BDCDATA. 139 | CLEAR BDCDATA. 140 | BDCDATA-FNAM = 'BDC_OKCODE'. 141 | BDCDATA-FVAL = T-NAME. 142 | APPEND BDCDATA. 143 | CALL TRANSACTION 'SU50' USING BDCDATA MODE 'N' 144 | MESSAGES INTO MESSTAB. 145 | CLEAR BDCDATA. 146 | REFRESH BDCDATA. 147 | ENDFORM. 148 | -------------------------------------------------------------------------------- /sonar-scanner/src/vb6/Registry.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "modRegistry" 2 | ' --- GPL --- 3 | ' 4 | ' Copyright (C) 1999 SAP AG 5 | ' 6 | ' This program is free software; you can redistribute it and/or 7 | ' modify it under the terms of the GNU General Public License 8 | ' as published by the Free Software Foundation; either version 2 9 | ' of the License, or (at your option) any later version. 10 | ' 11 | ' This program is distributed in the hope that it will be useful, 12 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ' GNU General Public License for more details. 15 | ' 16 | ' You should have received a copy of the GNU General Public License 17 | ' along with this program; if not, write to the Free Software 18 | ' Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | ' 20 | ' --- GPL --- 21 | Option Explicit 22 | 23 | 'Structures Needed For Registry Prototypes 24 | Public Type SECURITY_ATTRIBUTES 25 | nLength As Long 26 | lpSecurityDescriptor As Long 27 | bInheritHandle As Boolean 28 | End Type 29 | 30 | Public Type FILETIME 31 | dwLowDateTime As Long 32 | dwHighDateTime As Long 33 | End Type 34 | 35 | 'Registry Function Prototypes 36 | Public Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" ( _ 37 | ByVal hKey As Long, _ 38 | ByVal lpSubKey As String, _ 39 | ByVal ulOptions As Long, _ 40 | ByVal samDesired As Long, _ 41 | phkResult As Long) As Long 42 | 43 | Public Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" ( _ 44 | ByVal hKey As Long, _ 45 | ByVal lpSubKey As String, _ 46 | ByVal Reserved As Long, _ 47 | ByVal lpClass As String, _ 48 | ByVal dwOptions As Long, _ 49 | ByVal samDesired As Long, _ 50 | lpSecurityAttributes As SECURITY_ATTRIBUTES, _ 51 | phkResult As Long, _ 52 | lpdwDisposition As Long) As Long 53 | 54 | Public Declare Function RegQueryValueExNull Lib "advapi32.dll" Alias "RegQueryValueExA" ( _ 55 | ByVal hKey As Long, _ 56 | ByVal lpValueName As String, _ 57 | ByVal lpReserved As Long, _ 58 | lpType As Long, _ 59 | ByVal lpData As Long, _ 60 | lpcbData As Long) As Long 61 | 62 | Public Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" ( _ 63 | ByVal hKey As Long, _ 64 | ByVal lpValueName As String, _ 65 | ByVal lpReserved As Long, _ 66 | lpType As Long, _ 67 | ByVal lpData As String, _ 68 | lpcbData As Long) As Long 69 | 70 | Public Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" ( _ 71 | ByVal hKey As Long, _ 72 | ByVal lpValueName As String, _ 73 | ByVal lpReserved As Long, _ 74 | lpType As Long, _ 75 | lpData As Long, _ 76 | lpcbData As Long) As Long 77 | 78 | Public Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" ( _ 79 | ByVal hKey As Long, _ 80 | ByVal lpValueName As String, _ 81 | ByVal Reserved As Long, _ 82 | ByVal dwType As Long, _ 83 | ByVal lpValue As String, _ 84 | ByVal cbData As Long) As Long 85 | 86 | Public Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" ( _ 87 | ByVal hKey As Long, _ 88 | ByVal lpValueName As String, _ 89 | ByVal Reserved As Long, _ 90 | ByVal dwType As Long, _ 91 | lpValue As Long, _ 92 | ByVal cbData As Long) As Long 93 | 94 | Public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" ( _ 95 | ByVal hKey As Long, _ 96 | ByVal dwIndex As Long, _ 97 | ByVal lpName As String, _ 98 | lpcbName As Long, _ 99 | ByVal lpReserved As Long, _ 100 | ByVal lpClass As String, _ 101 | lpcbClass As Long, _ 102 | lpftLastWriteTime As FILETIME) As Long 103 | 104 | Public Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" ( _ 105 | ByVal hKey As Long, _ 106 | ByVal dwIndex As Long, _ 107 | ByVal lpValueName As String, _ 108 | lpcbValueName As Long, _ 109 | ByVal lpReserved As Long, _ 110 | lpType As Long, _ 111 | lpData As Any, _ 112 | lpcbData As Long) As Long 113 | 114 | Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" ( _ 115 | ByVal hKey As Long, _ 116 | ByVal lpSubKey As String) As Long 117 | 118 | Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" ( _ 119 | ByVal hKey As Long, _ 120 | ByVal lpValueName As String) As Long 121 | 122 | Public Declare Function RegCloseKey Lib "advapi32" ( _ 123 | ByVal hKey As Long) As Long 124 | 125 | ' 126 | ''masks for the predefined standard access types 127 | 'Private Const STANDARD_RIGHTS_ALL = &H1F0000 128 | 'Private Const SPECIFIC_RIGHTS_ALL = &HFFFF 129 | ' 130 | ''Define severity codes 131 | ' 132 | ''Public Const ERROR_ACCESS_DENIED = 5 133 | '' 134 | ''Global Const ERROR_NONE = 0 135 | ''Global Const ERROR_BADDB = 1 136 | ''Global Const ERROR_CANTOPEN = 3 137 | ''Global Const ERROR_CANTREAD = 4 138 | ''Global Const ERROR_CANTWRITE = 5 139 | ''Global Const ERROR_OUTOFMEMORY = 6 140 | ''Global Const ERROR_INVALID_PARAMETER = 7 141 | ''Global Const ERROR_ACCESS_DENIED = 8 142 | ''Global Const ERROR_INVALID_PARAMETERS = 87 143 | ''Global Const ERROR_NO_MORE_ITEMS = 259 144 | 145 | Public Type ByteValue 146 | b(1024) As Byte 147 | End Type 148 | 149 | Public Type LongValue 150 | l As Long 151 | End Type 152 | 153 | Public Function BytesToString(bValue As ByteValue) As String 154 | Dim s As String 155 | Dim i As Integer 156 | s = StrConv(bValue.b(), vbUnicode) 157 | i = InStr(s, Chr(0)) - 1 158 | BytesToString = Left(s, i) 159 | End Function 160 | 161 | Public Function BytesToLong(bValue As ByteValue) As Long 162 | Dim lValue As LongValue 163 | LSet lValue = bValue 164 | BytesToLong = lValue.l 165 | End Function 166 | 167 | -------------------------------------------------------------------------------- /sonar-scanner/src/sql/ut_report.pkb: -------------------------------------------------------------------------------- 1 | /* Formatted on 2002/03/31 23:53 (Formatter Plus v4.5.2) */ 2 | CREATE OR REPLACE PACKAGE BODY Utreport 3 | IS 4 | 5 | /************************************************************************ 6 | GNU General Public License for utPLSQL 7 | 8 | Copyright (C) 2000-2003 9 | Steven Feuerstein and the utPLSQL Project 10 | (steven@stevenfeuerstein.com) 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program (see license.txt); if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | ************************************************************************ 26 | $Log: ut_report.pkb,v $ 27 | Revision 1.3 2005/05/11 21:33:36 chrisrimmer 28 | Added testing of reporter infrastructure 29 | 30 | Revision 1.2 2004/11/16 09:46:49 chrisrimmer 31 | Changed to new version detection system. 32 | 33 | Revision 1.1 2004/07/14 17:01:57 chrisrimmer 34 | Added first version of pluggable reporter packages 35 | 36 | 37 | ************************************************************************/ 38 | 39 | DEFAULT_REPORTER VARCHAR2(100) := 'Output'; 40 | 41 | DYNAMIC_PLSQL_FAILURE NUMBER(10) := -6550; 42 | 43 | --This is the reporter we have been asked to use 44 | g_reporter VARCHAR2(100); 45 | 46 | --This is the reporter we are actually using 47 | --(this differs from the above in the event of error) 48 | g_actual VARCHAR2(100); 49 | 50 | FUNCTION parse_it(proc IN VARCHAR2, params IN NUMBER, force_reporter IN VARCHAR2) 51 | RETURN INTEGER 52 | IS 53 | dyn_handle INTEGER := NULL; 54 | query VARCHAR2(1000); 55 | BEGIN 56 | dyn_handle := DBMS_SQL.OPEN_CURSOR; 57 | QUERY := 'BEGIN ut' || NVL(force_reporter, g_actual) || 'Reporter.' || proc ; 58 | IF params = 1 THEN 59 | QUERY := QUERY || '(:p)'; 60 | END IF; 61 | QUERY := QUERY || '; END;'; 62 | DBMS_SQL.PARSE(dyn_handle, QUERY, DBMS_SQL.NATIVE); 63 | RETURN dyn_handle; 64 | EXCEPTION 65 | WHEN OTHERS THEN 66 | DBMS_SQL.CLOSE_CURSOR (dyn_handle); 67 | RAISE; 68 | END; 69 | 70 | PROCEDURE execute_it(dyn_handle IN OUT INTEGER) 71 | IS 72 | dyn_result INTEGER; 73 | BEGIN 74 | dyn_result := DBMS_SQL.EXECUTE (dyn_handle); 75 | DBMS_SQL.CLOSE_CURSOR (dyn_handle); 76 | END; 77 | 78 | --We use this to make dynamic calls to reporter packages 79 | PROCEDURE call(proc IN VARCHAR2, 80 | param IN VARCHAR2, 81 | params IN NUMBER := 1, 82 | force_reporter IN VARCHAR2 := NULL, 83 | failover IN BOOLEAN := TRUE) 84 | IS 85 | dyn_handle INTEGER := NULL; 86 | BEGIN 87 | dyn_handle := parse_it(proc, params, force_reporter); 88 | IF params = 1 THEN 89 | DBMS_SQL.BIND_VARIABLE (dyn_handle, 'p', param); 90 | END IF; 91 | execute_it(dyn_handle); 92 | EXCEPTION 93 | WHEN OTHERS THEN 94 | 95 | IF dyn_handle IS NOT NULL THEN 96 | DBMS_SQL.CLOSE_CURSOR (dyn_handle); 97 | END IF; 98 | 99 | IF g_actual <> DEFAULT_REPORTER THEN 100 | 101 | IF NOT failover OR SQLCODE <> DYNAMIC_PLSQL_FAILURE THEN 102 | g_actual := DEFAULT_REPORTER; 103 | pl(SQLERRM); 104 | pl('** REVERTING TO DEFAULT REPORTER **'); 105 | END IF; 106 | 107 | ELSE 108 | RAISE; 109 | END IF; 110 | 111 | call(proc, param, params, force_reporter => DEFAULT_REPORTER); 112 | END; 113 | 114 | PROCEDURE call(proc IN VARCHAR2, 115 | failover IN BOOLEAN := TRUE) 116 | IS 117 | BEGIN 118 | call(proc => proc, 119 | param => '', 120 | params => 0, 121 | failover => failover); 122 | END; 123 | 124 | PROCEDURE use(reporter IN VARCHAR2) 125 | IS 126 | BEGIN 127 | g_reporter := NVL(reporter, DEFAULT_REPORTER); 128 | g_actual := g_reporter; 129 | END; 130 | 131 | FUNCTION using RETURN VARCHAR2 132 | IS 133 | BEGIN 134 | RETURN g_reporter; 135 | END; 136 | 137 | PROCEDURE open 138 | IS 139 | BEGIN 140 | g_actual := g_reporter; 141 | call('open', failover => FALSE); 142 | END; 143 | 144 | PROCEDURE pl (str IN VARCHAR2) 145 | IS 146 | BEGIN 147 | call('pl', str); 148 | END; 149 | 150 | PROCEDURE pl (bool IN BOOLEAN) 151 | IS 152 | BEGIN 153 | pl (Utplsql.bool2vc (bool)); 154 | END; 155 | 156 | PROCEDURE before_results(run_id IN utr_outcome.run_id%TYPE) 157 | IS 158 | BEGIN 159 | call('before_results', run_id); 160 | END; 161 | 162 | PROCEDURE show_failure(rec_result IN utr_outcome%ROWTYPE) 163 | IS 164 | BEGIN 165 | outcome := rec_result; 166 | call('show_failure'); 167 | END; 168 | 169 | PROCEDURE show_result(rec_result IN utr_outcome%ROWTYPE) 170 | IS 171 | BEGIN 172 | outcome := rec_result; 173 | call('show_result'); 174 | END; 175 | 176 | PROCEDURE after_results(run_id IN utr_outcome.run_id%TYPE) 177 | IS 178 | BEGIN 179 | call('after_results', run_id); 180 | END; 181 | 182 | PROCEDURE before_errors(run_id IN utr_error.run_id%TYPE) 183 | IS 184 | BEGIN 185 | call('before_errors', run_id); 186 | END; 187 | 188 | PROCEDURE show_error(rec_error IN utr_error%ROWTYPE) 189 | IS 190 | BEGIN 191 | error := rec_error; 192 | call('show_error'); 193 | END; 194 | 195 | PROCEDURE after_errors(run_id IN utr_error.run_id%TYPE) 196 | IS 197 | BEGIN 198 | call('after_errors', run_id); 199 | END; 200 | 201 | PROCEDURE close 202 | IS 203 | BEGIN 204 | call('close'); 205 | END; 206 | 207 | BEGIN 208 | 209 | g_reporter := NVL(utconfig.getreporter, DEFAULT_REPORTER); 210 | g_actual := g_reporter; 211 | 212 | END; 213 | / 214 | --------------------------------------------------------------------------------