From a0a3723173f590f1d07b0527aa41912b5456afac Mon Sep 17 00:00:00 2001 From: Murilo Kakazu Date: Tue, 30 Apr 2024 22:14:44 -0300 Subject: [PATCH 1/2] build: add static analysis --- .github/workflows/ci.yaml | 5 +++++ build.gradle | 12 +++++++++--- .../grupo30/fastfood/FastfoodApplicationTests.java | 8 +++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a794e24..997cd94 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,6 +35,11 @@ jobs: - name: Code linting run: ./gradlew spotlessCheck + - name: Static analysis + run: | + ./gradlew pmdMain + ./gradlew pmdTest + - name: Build run: ./gradlew clean build diff --git a/build.gradle b/build.gradle index 3bfe9ab..fd3dfff 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'org.springframework.boot' version '3.2.5' id 'io.spring.dependency-management' version '1.1.4' id 'com.diffplug.spotless' version '6.25.0' + id 'pmd' } group = 'br.com.fiap.grupo30' @@ -20,12 +21,10 @@ configurations { spotless { format 'misc', { - // define the files to apply `misc` to target '*.gradle', '.gitattributes', '.gitignore' - // define the steps to apply to those files trimTrailingWhitespace() - indentWithTabs() // or spaces. Takes an integer argument if you don't like 4 + indentWithTabs() endWithNewline() } java { @@ -35,6 +34,13 @@ spotless { } } +pmd { + toolVersion = '7.1.0' + ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"] + consoleOutput = true + sourceSets = [sourceSets.main, sourceSets.test] +} + repositories { mavenCentral() } diff --git a/src/test/java/br/com/fiap/grupo30/fastfood/FastfoodApplicationTests.java b/src/test/java/br/com/fiap/grupo30/fastfood/FastfoodApplicationTests.java index 460f0f3..b98f18c 100644 --- a/src/test/java/br/com/fiap/grupo30/fastfood/FastfoodApplicationTests.java +++ b/src/test/java/br/com/fiap/grupo30/fastfood/FastfoodApplicationTests.java @@ -1,5 +1,7 @@ package br.com.fiap.grupo30.fastfood; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -7,5 +9,9 @@ class FastfoodApplicationTests { @Test - void contextLoads() {} + void contextLoads() { + int x = 1; + int y = 1; + assertTrue(x == y, "assertion failed"); + } } From 1980be59b0fbdcbb27dd777e58d19bc87ad280d4 Mon Sep 17 00:00:00 2001 From: Murilo Kakazu Date: Tue, 30 Apr 2024 22:16:32 -0300 Subject: [PATCH 2/2] build: indent misc files with spaces --- build.gradle | 66 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index fd3dfff..c329f8b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,60 +1,60 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.2.5' - id 'io.spring.dependency-management' version '1.1.4' - id 'com.diffplug.spotless' version '6.25.0' - id 'pmd' + id 'java' + id 'org.springframework.boot' version '3.2.5' + id 'io.spring.dependency-management' version '1.1.4' + id 'com.diffplug.spotless' version '6.25.0' + id 'pmd' } group = 'br.com.fiap.grupo30' version = '0.0.1-SNAPSHOT' java { - sourceCompatibility = '21' + sourceCompatibility = '21' } configurations { - compileOnly { - extendsFrom annotationProcessor - } + compileOnly { + extendsFrom annotationProcessor + } } spotless { - format 'misc', { - target '*.gradle', '.gitattributes', '.gitignore' + format 'misc', { + target '*.gradle', '.gitattributes', '.gitignore' - trimTrailingWhitespace() - indentWithTabs() - endWithNewline() - } - java { - googleJavaFormat('1.22.0').aosp().reflowLongStrings().skipJavadocFormatting() - formatAnnotations() - target 'src/main/**/*.java', 'src/test/**/*.java' - } + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + } + java { + googleJavaFormat('1.22.0').aosp().reflowLongStrings().skipJavadocFormatting() + formatAnnotations() + target 'src/main/**/*.java', 'src/test/**/*.java' + } } pmd { - toolVersion = '7.1.0' - ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"] - consoleOutput = true - sourceSets = [sourceSets.main, sourceSets.test] + toolVersion = '7.1.0' + ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"] + consoleOutput = true + sourceSets = [sourceSets.main, sourceSets.test] } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-web' - compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.h2database:h2' - runtimeOnly 'org.postgresql:postgresql' - annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.h2database:h2' + runtimeOnly 'org.postgresql:postgresql' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() }