Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: SonarQube
on:
push:
branches:
- main
# pull_request:
# types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build jacocoTestReport sonar -x ":springwolf-examples:e2e:test"
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias libs.plugins.owasp.dependencycheck
alias libs.plugins.spotless
alias libs.plugins.docker.spring.boot apply false
alias libs.plugins.sonarqube
}

applyDotEnvFileAsGradleProperties()
Expand Down Expand Up @@ -38,6 +39,7 @@ var plugins = [

allprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.diffplug.spotless'
Expand Down Expand Up @@ -170,6 +172,16 @@ allprojects {
}
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
}
}
tasks.withType(org.sonarqube.gradle.SonarTask).configureEach {
dependsOn jacocoTestReport
}

var publishingEnabled = (
project.name == 'springwolf-asyncapi' ||
project.name == 'springwolf-core' ||
Expand Down Expand Up @@ -266,6 +278,14 @@ dependencyCheck {
analyzers.nodeAudit.yarnEnabled = false
}

sonar {
properties {
property "sonar.projectKey", "timonback_springwolf"
property "sonar.organization", "timonback"
property "sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/test/jacocoTestReport.xml"
}
}

def static readEnvFile(path = ".env") {
def env = [:]

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ owasp-dependencycheck = { id = "org.owasp.dependencycheck", version.ref = "owasp
protobuf = { id = "com.google.protobuf", version.ref = "protobuf-plugin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot-plugin" }
sonarqube = { id = "org.sonarqube", version = "7.2.2.6593" }
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ void buildOperation() {
Class<?> clazz = ClassWithTestListenerAnnotation.class;
AsyncOperation asyncOperation =
clazz.getAnnotation(TestMethodListener.class).operation();
Set<Method> methods = Arrays.stream(clazz.getDeclaredMethods()).collect(Collectors.toSet());
Set<Method> methods = Arrays.stream(clazz.getDeclaredMethods())
.filter(method -> !method.isSynthetic())
.collect(Collectors.toSet());

when(asyncAnnotationProvider.getAsyncOperation(any())).thenReturn(asyncOperation);
when(asyncAnnotationMessageService.buildMessage(any(), any()))
Expand Down Expand Up @@ -97,7 +99,9 @@ void buildOperationWithMultipleMethods() {
Class<?> clazz = ClassWithMultipleTestListenerAnnotation.class;
AsyncOperation asyncOperation =
clazz.getAnnotation(TestMethodListener.class).operation();
Set<Method> methods = Arrays.stream(clazz.getDeclaredMethods()).collect(Collectors.toSet());
Set<Method> methods = Arrays.stream(clazz.getDeclaredMethods())
.filter(method -> !method.isSynthetic())
.collect(Collectors.toSet());

when(asyncAnnotationProvider.getAsyncOperation(any())).thenReturn(asyncOperation);
when(asyncAnnotationMessageService.buildMessage(any(), any()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.util.StringValueResolver;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -612,6 +613,10 @@ private void methodWithAnnotation(String payload) {}
}

private static RabbitListener getAnnotation(Class<?> clazz) {
return clazz.getDeclaredMethods()[0].getAnnotation(RabbitListener.class);
return Arrays.stream(clazz.getDeclaredMethods())
.filter(it -> !it.isSynthetic())
.findFirst()
.get()
.getAnnotation(RabbitListener.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.jms.annotation.JmsListener;
import org.springframework.util.StringValueResolver;

import java.util.Arrays;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -89,6 +90,10 @@ private void methodWithAnnotation(String payload) {}
}

private static JmsListener getAnnotation(Class<?> clazz) {
return clazz.getDeclaredMethods()[0].getAnnotation(JmsListener.class);
return Arrays.stream(clazz.getDeclaredMethods())
.filter(method -> !method.isSynthetic())
.findFirst()
.get()
.getAnnotation(JmsListener.class);
}
}
Loading