From adef5c7dd4af925b9062d064472a71970d4bfa75 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 12 Feb 2022 17:02:53 +0100 Subject: [PATCH 1/6] Sonar: update generated properties --- .../generator/server/sonar/sonar-project.properties.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/generator/server/sonar/sonar-project.properties.mustache b/src/main/resources/generator/server/sonar/sonar-project.properties.mustache index de845110eff..1f29580f204 100644 --- a/src/main/resources/generator/server/sonar/sonar-project.properties.mustache +++ b/src/main/resources/generator/server/sonar/sonar-project.properties.mustache @@ -2,6 +2,7 @@ sonar.projectKey={{baseName}} sonar.projectName={{projectName}} sonar.sources=src/main/ +sonar.tests=src/test/ sonar.host.url=http://localhost:9001 sonar.test.inclusions=src/test/**/*.*, src/main/webapp/app/**/*.spec.ts @@ -10,7 +11,7 @@ sonar.java.codeCoveragePlugin=jacoco sonar.junit.reportPaths=target/surefire-reports,target/failsafe-reports sonar.sourceEncoding=UTF-8 -sonar.exclusions=src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/classes/static/**/*.* +sonar.exclusions=src/main/webapp/app/main.ts, src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/classes/static/**/*.* sonar.issue.ignore.multicriteria=S3437,S4502,S4684,S4032,UndocumentedApi From fe0caaad6870d5096c6ac2666fece473136db154 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 12 Feb 2022 17:06:47 +0100 Subject: [PATCH 2/6] Sonar: change some methods to private and it's not used publicly --- .../application/SonarApplicationService.java | 16 ------ .../sonar/domain/SonarDomainService.java | 12 ++--- .../server/sonar/domain/SonarService.java | 8 --- .../SonarApplicationServiceIT.java | 51 ------------------- 4 files changed, 4 insertions(+), 83 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java index 0cc2ed28b6a..0b050164d97 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java @@ -16,20 +16,4 @@ public SonarApplicationService(SonarService sonarService) { public void init(Project project) { this.sonarService.init(project); } - - void addPropertiesPlugin(Project project) { - this.sonarService.addPropertiesPlugin(project); - } - - void addSonarScannerPluginManagement(Project project) { - this.sonarService.addSonarScannerPluginManagement(project); - } - - void addPropertiesFile(Project project) { - this.sonarService.addPropertiesFile(project); - } - - void addDockerCompose(Project project) { - this.sonarService.addDockerCompose(project); - } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java index d8c83761810..51b0873a8c0 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java @@ -29,8 +29,7 @@ public void init(Project project) { addDockerCompose(project); } - @Override - public void addPropertiesPlugin(Project project) { + private void addPropertiesPlugin(Project project) { Plugin plugin = Plugin .builder() .groupId("org.codehaus.mojo") @@ -57,8 +56,7 @@ public void addPropertiesPlugin(Project project) { buildToolService.addPlugin(project, plugin); } - @Override - public void addSonarScannerPluginManagement(Project project) { + private void addSonarScannerPluginManagement(Project project) { Plugin plugin = Plugin .builder() .groupId("org.sonarsource.scanner.maven") @@ -69,15 +67,13 @@ public void addSonarScannerPluginManagement(Project project) { buildToolService.addPluginManagement(project, plugin); } - @Override - public void addPropertiesFile(Project project) { + private void addPropertiesFile(Project project) { project.addDefaultConfig(BASE_NAME); project.addDefaultConfig(PROJECT_NAME); projectRepository.template(project, SOURCE, "sonar-project.properties"); } - @Override - public void addDockerCompose(Project project) { + private void addDockerCompose(Project project) { project.addDefaultConfig(BASE_NAME); project.addConfig("sonarqubeDockerImage", Sonar.getSonarqubeDockerImage()); projectRepository.template(project, SOURCE, "sonar.yml", "src/main/docker", "sonar.yml"); diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java index edc51853f02..a49371b54cb 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java @@ -4,12 +4,4 @@ public interface SonarService { void init(Project project); - - void addPropertiesPlugin(Project project); - - void addSonarScannerPluginManagement(Project project); - - void addPropertiesFile(Project project); - - void addDockerCompose(Project project); } diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java index a189cf11a56..e2babe73156 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java @@ -46,57 +46,6 @@ void shouldInit() { assertFileContent(project, POM_XML, propertiesPlugin()); } - @Test - void shouldAddDockerCompose() { - Project project = tmpProject(); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - - sonarApplicationService.addDockerCompose(project); - - assertFileExist(project, "src/main/docker/sonar.yml"); - assertFileContent(project, "src/main/docker/sonar.yml", "image: " + Sonar.SONARQUBE_DOCKER_IMAGE); - } - - @Test - void shouldAddSonarProperties() { - Project project = tmpProject(); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - - sonarApplicationService.addPropertiesFile(project); - - assertFileExist(project, "sonar-project.properties"); - assertFileContent(project, "sonar-project.properties", List.of("sonar.sources=src/main/")); - } - - @Test - void shouldAddPropertiesPlugin() { - Project project = tmpProject(); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - - sonarApplicationService.addPropertiesPlugin(project); - - assertFileContent(project, POM_XML, ""); - assertFileContent(project, POM_XML, ""); - - assertFileContent(project, POM_XML, propertiesPlugin()); - } - - @Test - void shouldAddSonarScannerPluginManagement() { - Project project = tmpProject(); - initApplicationService.init(project); - mavenApplicationService.addPomXml(project); - - sonarApplicationService.addSonarScannerPluginManagement(project); - - assertFileContent(project, POM_XML, ""); - assertFileContent(project, POM_XML, ""); - assertFileContent(project, POM_XML, sonarSourcePlugin()); - } - private List propertiesPlugin() { return List.of( "", From f5c457d2eb483f1bea864e2f7648a8b42307cb7a Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 12 Feb 2022 17:08:44 +0100 Subject: [PATCH 3/6] Sonar: rename method init to addSonarJavaBackend --- .../server/sonar/application/SonarApplicationService.java | 4 ++-- .../generator/server/sonar/domain/SonarDomainService.java | 2 +- .../lite/generator/server/sonar/domain/SonarService.java | 2 +- .../server/sonar/infrastructure/primary/SonarResource.java | 4 ++-- .../server/sonar/application/SonarApplicationServiceIT.java | 5 ++--- .../sonar/infrastructure/primary/rest/SonarResourceIT.java | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java index 0b050164d97..71a12915721 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java @@ -13,7 +13,7 @@ public SonarApplicationService(SonarService sonarService) { this.sonarService = sonarService; } - public void init(Project project) { - this.sonarService.init(project); + public void addSonarJavaBackend(Project project) { + this.sonarService.addSonarJavaBackend(project); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java index 51b0873a8c0..e5996c2c882 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java @@ -22,7 +22,7 @@ public SonarDomainService(ProjectRepository projectRepository, BuildToolService } @Override - public void init(Project project) { + public void addSonarJavaBackend(Project project) { addPropertiesPlugin(project); addSonarScannerPluginManagement(project); addPropertiesFile(project); diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java index a49371b54cb..7fbea48e8c7 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java @@ -3,5 +3,5 @@ import tech.jhipster.lite.generator.project.domain.Project; public interface SonarService { - void init(Project project); + void addSonarJavaBackend(Project project); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java index 5aaa9befbea..6817e8cae79 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java @@ -27,8 +27,8 @@ public SonarResource(SonarApplicationService sonarApplicationService) { @ApiResponse(responseCode = "500", description = "An error occurred while adding Sonar configuration") @PostMapping @GeneratorStep(id = "sonar") - public void addSonar(@RequestBody ProjectDTO projectDTO) { + public void addSonarJavaBackend(@RequestBody ProjectDTO projectDTO) { Project project = ProjectDTO.toProject(projectDTO); - sonarApplicationService.init(project); + sonarApplicationService.addSonarJavaBackend(project); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java index e2babe73156..966534e5c0f 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java @@ -10,7 +10,6 @@ import tech.jhipster.lite.generator.buildtool.maven.application.MavenApplicationService; import tech.jhipster.lite.generator.init.application.InitApplicationService; import tech.jhipster.lite.generator.project.domain.Project; -import tech.jhipster.lite.generator.server.sonar.domain.Sonar; @IntegrationTest class SonarApplicationServiceIT { @@ -25,12 +24,12 @@ class SonarApplicationServiceIT { MavenApplicationService mavenApplicationService; @Test - void shouldInit() { + void shouldAddSonarJavaBackend() { Project project = tmpProject(); initApplicationService.init(project); mavenApplicationService.addPomXml(project); - sonarApplicationService.init(project); + sonarApplicationService.addSonarJavaBackend(project); assertFileExist(project, "src/main/docker/sonar.yml"); assertFileExist(project, "sonar-project.properties"); diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java index 747bd32b8fd..57575d8c6a9 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java @@ -35,12 +35,12 @@ class SonarResourceIT { MockMvc mockMvc; @Test - void shouldAddSonar() throws Exception { + void shouldAddSonarJavaBackend() throws Exception { ProjectDTO projectDTO = TestUtils.readFileToObject("json/chips.json", ProjectDTO.class).folder(FileUtils.tmpDirForTest()); Project project = ProjectDTO.toProject(projectDTO); initApplicationService.init(project); mavenApplicationService.init(project); - sonarApplicationService.init(project); + sonarApplicationService.addSonarJavaBackend(project); mockMvc .perform(post("/api/servers/sonar").contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(projectDTO))) From 9f6ce9a12a19489383a1179118c21b0e6f63f78c Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 12 Feb 2022 17:11:27 +0100 Subject: [PATCH 4/6] Sonar: refactoring SonarResource to rest package and update API --- .../infrastructure/primary/{ => rest}/SonarResource.java | 6 +++--- .../sonar/infrastructure/primary/rest/SonarResourceIT.java | 6 +++++- tests-ci/generate.sh | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) rename src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/{ => rest}/SonarResource.java (94%) diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java similarity index 94% rename from src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java rename to src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java index 6817e8cae79..9f46e967df9 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/SonarResource.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java @@ -1,4 +1,4 @@ -package tech.jhipster.lite.generator.server.sonar.infrastructure.primary; +package tech.jhipster.lite.generator.server.sonar.infrastructure.primary.rest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -25,8 +25,8 @@ public SonarResource(SonarApplicationService sonarApplicationService) { @Operation(summary = "Add Sonar configuration to inspect code quality") @ApiResponse(responseCode = "500", description = "An error occurred while adding Sonar configuration") - @PostMapping - @GeneratorStep(id = "sonar") + @PostMapping("/java-backend") + @GeneratorStep(id = "sonar-java-backend") public void addSonarJavaBackend(@RequestBody ProjectDTO projectDTO) { Project project = ProjectDTO.toProject(projectDTO); sonarApplicationService.addSonarJavaBackend(project); diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java index 57575d8c6a9..951fd145a16 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java @@ -43,7 +43,11 @@ void shouldAddSonarJavaBackend() throws Exception { sonarApplicationService.addSonarJavaBackend(project); mockMvc - .perform(post("/api/servers/sonar").contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(projectDTO))) + .perform( + post("/api/servers/sonar/java-backend") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.convertObjectToJsonBytes(projectDTO)) + ) .andExpect(status().isOk()); String projectPath = projectDTO.getFolder(); diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh index 6d34c44b929..79fbdadde80 100755 --- a/tests-ci/generate.sh +++ b/tests-ci/generate.sh @@ -31,7 +31,7 @@ if [[ $filename == 'full-default' ]]; then callApi "/api/servers/spring-boot/logging/aop" callApi "/api/servers/spring-boot/logging/logstash" callApi "/api/servers/spring-boot/banner/jhipster-v7" - callApi "/api/servers/sonar" + callApi "/api/servers/sonar/java-backend" callApi "/api/servers/spring-boot/docker/jib" callApi "/api/servers/spring-boot/mvc/web/tomcat" From d7915f0ee7a43de23b597ab3e0f08280bcbd3352 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 12 Feb 2022 17:25:07 +0100 Subject: [PATCH 5/6] Sonar: add java backend and frontend sonar configuration --- .../application/SonarApplicationService.java | 4 ++ .../sonar/domain/SonarDomainService.java | 14 ++++ .../server/sonar/domain/SonarService.java | 1 + .../primary/rest/SonarResource.java | 13 +++- ...onar-fullstack-project.properties.mustache | 39 +++++++++++ .../SonarApplicationServiceIT.java | 54 ++++----------- .../server/sonar/application/SonarAssert.java | 66 +++++++++++++++++++ .../primary/rest/SonarResourceIT.java | 29 ++++++-- 8 files changed, 169 insertions(+), 51 deletions(-) create mode 100644 src/main/resources/generator/server/sonar/sonar-fullstack-project.properties.mustache create mode 100644 src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarAssert.java diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java index 71a12915721..622874f83d8 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationService.java @@ -16,4 +16,8 @@ public SonarApplicationService(SonarService sonarService) { public void addSonarJavaBackend(Project project) { this.sonarService.addSonarJavaBackend(project); } + + public void addSonarJavaBackendAndFrontend(Project project) { + this.sonarService.addSonarJavaBackendAndFrontend(project); + } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java index e5996c2c882..f7458521523 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarDomainService.java @@ -29,6 +29,14 @@ public void addSonarJavaBackend(Project project) { addDockerCompose(project); } + @Override + public void addSonarJavaBackendAndFrontend(Project project) { + addPropertiesPlugin(project); + addSonarScannerPluginManagement(project); + addFullstackPropertiesFile(project); + addDockerCompose(project); + } + private void addPropertiesPlugin(Project project) { Plugin plugin = Plugin .builder() @@ -73,6 +81,12 @@ private void addPropertiesFile(Project project) { projectRepository.template(project, SOURCE, "sonar-project.properties"); } + private void addFullstackPropertiesFile(Project project) { + project.addDefaultConfig(BASE_NAME); + project.addDefaultConfig(PROJECT_NAME); + projectRepository.template(project, SOURCE, "sonar-fullstack-project.properties", "", "sonar-project.properties"); + } + private void addDockerCompose(Project project) { project.addDefaultConfig(BASE_NAME); project.addConfig("sonarqubeDockerImage", Sonar.getSonarqubeDockerImage()); diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java index 7fbea48e8c7..c2268105b02 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/domain/SonarService.java @@ -4,4 +4,5 @@ public interface SonarService { void addSonarJavaBackend(Project project); + void addSonarJavaBackendAndFrontend(Project project); } diff --git a/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java b/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java index 9f46e967df9..e83972ef390 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java +++ b/src/main/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResource.java @@ -23,12 +23,21 @@ public SonarResource(SonarApplicationService sonarApplicationService) { this.sonarApplicationService = sonarApplicationService; } - @Operation(summary = "Add Sonar configuration to inspect code quality") - @ApiResponse(responseCode = "500", description = "An error occurred while adding Sonar configuration") + @Operation(summary = "Add Sonar configuration for Java Backend to inspect code quality") + @ApiResponse(responseCode = "500", description = "An error occurred while adding Sonar configuration for Java Backend") @PostMapping("/java-backend") @GeneratorStep(id = "sonar-java-backend") public void addSonarJavaBackend(@RequestBody ProjectDTO projectDTO) { Project project = ProjectDTO.toProject(projectDTO); sonarApplicationService.addSonarJavaBackend(project); } + + @Operation(summary = "Add Sonar configuration for Java Backend and Frontend to inspect code quality") + @ApiResponse(responseCode = "500", description = "An error occurred while adding Sonar configuration for Java Backend and Frontend") + @PostMapping("/java-backend-and-frontend") + @GeneratorStep(id = "sonar-java-backend-and-frontend") + public void addSonarJavaBackendAndFrontend(@RequestBody ProjectDTO projectDTO) { + Project project = ProjectDTO.toProject(projectDTO); + sonarApplicationService.addSonarJavaBackendAndFrontend(project); + } } diff --git a/src/main/resources/generator/server/sonar/sonar-fullstack-project.properties.mustache b/src/main/resources/generator/server/sonar/sonar-fullstack-project.properties.mustache new file mode 100644 index 00000000000..ad4182d2034 --- /dev/null +++ b/src/main/resources/generator/server/sonar/sonar-fullstack-project.properties.mustache @@ -0,0 +1,39 @@ +sonar.projectKey={{baseName}} +sonar.projectName={{projectName}} + +sonar.sources=src/main/ +sonar.tests=src/test/ +sonar.host.url=http://localhost:9001 + +sonar.test.inclusions=src/test/**/*.*, src/main/webapp/app/**/*.spec.ts +sonar.coverage.jacoco.xmlReportPaths=target/jacoco/jacoco.xml +sonar.java.codeCoveragePlugin=jacoco +sonar.junit.reportPaths=target/surefire-reports,target/failsafe-reports + +sonar.testExecutionReportPaths=target/test-results/jest/TESTS-results-sonar.xml +sonar.javascript.lcov.reportPaths=target/test-results/lcov.info + +sonar.sourceEncoding=UTF-8 +sonar.exclusions=src/main/webapp/app/main.ts, src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/classes/static/**/*.* + +sonar.issue.ignore.multicriteria=S3437,S4502,S4684,S4032,UndocumentedApi + +# Rule https://rules.sonarsource.com/java/RSPEC-3437 is ignored, as a JPA-managed field cannot be transient +sonar.issue.ignore.multicriteria.S3437.resourceKey=src/main/java/**/* +sonar.issue.ignore.multicriteria.S3437.ruleKey=squid:S3437 + +# Rule https://rules.sonarsource.com/java/RSPEC-1176 is ignored, as we want to follow "clean code" guidelines and classes, methods and arguments names should be self-explanatory +sonar.issue.ignore.multicriteria.UndocumentedApi.resourceKey=src/main/java/**/* +sonar.issue.ignore.multicriteria.UndocumentedApi.ruleKey=squid:UndocumentedApi + +# Rule https://rules.sonarsource.com/java/RSPEC-4502 is ignored, as for JWT tokens we are not subject to CSRF attack +sonar.issue.ignore.multicriteria.S4502.resourceKey=src/main/java/**/* +sonar.issue.ignore.multicriteria.S4502.ruleKey=java:S4502 + +# Rule https://rules.sonarsource.com/java/RSPEC-4684 +sonar.issue.ignore.multicriteria.S4684.resourceKey=src/main/java/**/* +sonar.issue.ignore.multicriteria.S4684.ruleKey=java:S4684 + +# Rule: Packages containing only "package-info.java" should be removed +sonar.issue.ignore.multicriteria.S4032.resourceKey=src/main/java/**/* +sonar.issue.ignore.multicriteria.S4032.ruleKey=java:S4032 diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java index 966534e5c0f..eddadac991e 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarApplicationServiceIT.java @@ -31,50 +31,20 @@ void shouldAddSonarJavaBackend() { sonarApplicationService.addSonarJavaBackend(project); - assertFileExist(project, "src/main/docker/sonar.yml"); - assertFileExist(project, "sonar-project.properties"); - - assertFileContent(project, POM_XML, ""); - assertFileContent(project, POM_XML, ""); - - assertFileContent(project, POM_XML, ""); - assertFileContent(project, POM_XML, ""); - - assertFileContent(project, POM_XML, sonarSourcePlugin()); - - assertFileContent(project, POM_XML, propertiesPlugin()); + SonarAssert.assertFiles(project); + SonarAssert.assertPomXml(project); } - private List propertiesPlugin() { - return List.of( - "", - "org.codehaus.mojo", - "properties-maven-plugin", - "${properties-maven-plugin.version}", - "", - "", - "initialize", - "", - "read-project-properties", - "", - "", - "", - "sonar-project.properties", - "", - "", - "", - "", - "" - ); - } + @Test + void shouldAddSonarJavaBackendAndFrontend() { + Project project = tmpProject(); + initApplicationService.init(project); + mavenApplicationService.addPomXml(project); + + sonarApplicationService.addSonarJavaBackendAndFrontend(project); - private List sonarSourcePlugin() { - return List.of( - "", - "org.sonarsource.scanner.maven", - "sonar-maven-plugin", - "${sonar-maven-plugin.version}", - "" - ); + SonarAssert.assertFiles(project); + SonarAssert.assertFrontProperties(project); + SonarAssert.assertPomXml(project); } } diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarAssert.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarAssert.java new file mode 100644 index 00000000000..e0e7b310c39 --- /dev/null +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/application/SonarAssert.java @@ -0,0 +1,66 @@ +package tech.jhipster.lite.generator.server.sonar.application; + +import static tech.jhipster.lite.TestUtils.assertFileContent; +import static tech.jhipster.lite.TestUtils.assertFileExist; +import static tech.jhipster.lite.generator.project.domain.Constants.POM_XML; + +import java.util.List; +import tech.jhipster.lite.generator.project.domain.Project; + +public class SonarAssert { + + private SonarAssert() {} + + public static void assertFiles(Project project) { + assertFileExist(project, "src/main/docker/sonar.yml"); + assertFileExist(project, "sonar-project.properties"); + } + + public static void assertFrontProperties(Project project) { + assertFileContent(project, "sonar-project.properties", "sonar.testExecutionReportPaths"); + assertFileContent(project, "sonar-project.properties", "sonar.javascript.lcov.reportPaths"); + } + + public static void assertPomXml(Project project) { + assertFileContent(project, POM_XML, ""); + assertFileContent(project, POM_XML, ""); + assertFileContent(project, POM_XML, ""); + assertFileContent(project, POM_XML, ""); + + assertFileContent(project, POM_XML, sonarSourcePlugin()); + assertFileContent(project, POM_XML, propertiesPlugin()); + } + + private static List sonarSourcePlugin() { + return List.of( + "", + "org.sonarsource.scanner.maven", + "sonar-maven-plugin", + "${sonar-maven-plugin.version}", + "" + ); + } + + private static List propertiesPlugin() { + return List.of( + "", + "org.codehaus.mojo", + "properties-maven-plugin", + "${properties-maven-plugin.version}", + "", + "", + "initialize", + "", + "read-project-properties", + "", + "", + "", + "sonar-project.properties", + "", + "", + "", + "", + "" + ); + } +} diff --git a/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java b/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java index 951fd145a16..75fd9413a7b 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java +++ b/src/test/java/tech/jhipster/lite/generator/server/sonar/infrastructure/primary/rest/SonarResourceIT.java @@ -17,6 +17,7 @@ import tech.jhipster.lite.generator.project.domain.Project; import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; import tech.jhipster.lite.generator.server.sonar.application.SonarApplicationService; +import tech.jhipster.lite.generator.server.sonar.application.SonarAssert; @IntegrationTest @AutoConfigureMockMvc @@ -28,9 +29,6 @@ class SonarResourceIT { @Autowired MavenApplicationService mavenApplicationService; - @Autowired - SonarApplicationService sonarApplicationService; - @Autowired MockMvc mockMvc; @@ -40,7 +38,6 @@ void shouldAddSonarJavaBackend() throws Exception { Project project = ProjectDTO.toProject(projectDTO); initApplicationService.init(project); mavenApplicationService.init(project); - sonarApplicationService.addSonarJavaBackend(project); mockMvc .perform( @@ -50,9 +47,27 @@ void shouldAddSonarJavaBackend() throws Exception { ) .andExpect(status().isOk()); - String projectPath = projectDTO.getFolder(); + SonarAssert.assertFiles(project); + SonarAssert.assertPomXml(project); + } + + @Test + void shouldAddSonarJavaBackendAndFrontend() throws Exception { + ProjectDTO projectDTO = TestUtils.readFileToObject("json/chips.json", ProjectDTO.class).folder(FileUtils.tmpDirForTest()); + Project project = ProjectDTO.toProject(projectDTO); + initApplicationService.init(project); + mavenApplicationService.init(project); + + mockMvc + .perform( + post("/api/servers/sonar/java-backend-and-frontend") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.convertObjectToJsonBytes(projectDTO)) + ) + .andExpect(status().isOk()); - assertFileExist(projectPath, "sonar-project.properties"); - assertFileExist(projectPath, "src/main/docker/sonar.yml"); + SonarAssert.assertFiles(project); + SonarAssert.assertFrontProperties(project); + SonarAssert.assertPomXml(project); } } From 48c23969d77eac9042fddc7238dc1636baa05a68 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 12 Feb 2022 17:26:53 +0100 Subject: [PATCH 6/6] CI: add sonar java backend and frontend --- tests-ci/generate.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh index 79fbdadde80..55a86902d22 100755 --- a/tests-ci/generate.sh +++ b/tests-ci/generate.sh @@ -31,7 +31,7 @@ if [[ $filename == 'full-default' ]]; then callApi "/api/servers/spring-boot/logging/aop" callApi "/api/servers/spring-boot/logging/logstash" callApi "/api/servers/spring-boot/banner/jhipster-v7" - callApi "/api/servers/sonar/java-backend" + callApi "/api/servers/sonar/java-backend-and-frontend" callApi "/api/servers/spring-boot/docker/jib" callApi "/api/servers/spring-boot/mvc/web/tomcat" @@ -58,6 +58,8 @@ elif [[ $filename == 'tomcat-mysql-ehcachexml' ]]; then callApi "/api/servers/java/jacoco-minimum-coverage" callApi "/api/servers/spring-boot" + callApi "/api/servers/sonar/java-backend" + callApi "/api/servers/spring-boot/mvc/web/tomcat" callApi "/api/servers/spring-boot/mvc/springdoc/init"