diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 9d9f5579739..71f0259f450 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -99,14 +99,13 @@ jobs: strategy: matrix: app: - - full-default - - tomcat-mysql-ehcachexml - - undertow-simplecache - - tomcat-configserver - - undertow-consul - - tomcat-eureka - - tomcat-mongodb + - fullapp + - mysqlapp - flywayapp + - undertowapp + - eurekaapp + - consulapp + - mongodbapp - angularapp - reactapp - vueapp @@ -141,11 +140,21 @@ jobs: key: ${{ runner.os }}-maven-${{ matrix.app }}-${{ steps.cache_md5sum.outputs.md5sum_pom_xml }} restore-keys: | ${{ runner.os }}-maven- + - name: 'Test: starting Sonar' + working-directory: /tmp/jhlite/${{ matrix.app }}/ + run: | + docker-compose -f src/main/docker/sonar.yml up -d + sleep 30 + docker ps -a - name: 'Test: verify ${{ matrix.app }}' working-directory: /tmp/jhlite/${{ matrix.app }}/ run: | chmod +x mvnw - ./mvnw clean verify + ./mvnw clean verify sonar:sonar + - name: 'Test: check local Sonar Analysis' + run: | + sleep 15 + ./tests-ci/sonar.sh ${{ matrix.app }} #-------------------------------------------------- # Send analysis to Codecov #-------------------------------------------------- diff --git a/src/main/java/tech/jhipster/lite/common/domain/FileUtils.java b/src/main/java/tech/jhipster/lite/common/domain/FileUtils.java index 0a9ada62de8..90e6cc42d90 100644 --- a/src/main/java/tech/jhipster/lite/common/domain/FileUtils.java +++ b/src/main/java/tech/jhipster/lite/common/domain/FileUtils.java @@ -66,7 +66,7 @@ public static Path getPathOf(String... paths) { public static InputStream getInputStream(String... paths) { InputStream in = FileUtils.class.getResourceAsStream(FILE_SEPARATOR + getPath(paths)); if (in == null) { - throw new GeneratorException("File not found in classpath"); + throw new GeneratorException("File '" + getPath(paths) + "' not found in classpath"); } return in; } diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java index 958f8dc98c5..49ff3d8344e 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularDomainService.java @@ -82,11 +82,11 @@ public void addAngularFiles(Project project) { public void addImages(Project project) { projectRepository.add( project, - getPath(SOURCE_WEBAPP, "/content/images"), + getPath(SOURCE_WEBAPP, "content/images"), "JHipster-Lite-neon-red.png", "src/main/webapp/content/images" ); - projectRepository.add(project, getPath(SOURCE_WEBAPP, "/content/images"), "AngularLogo.svg", "src/main/webapp/content/images"); + projectRepository.add(project, getPath(SOURCE_WEBAPP, "content/images"), "AngularLogo.svg", "src/main/webapp/content/images"); } public void addJestSonar(Project project) { diff --git a/src/main/resources/generator/client/angular/src/main/webapp/app/common/primary/app/app.component.html.mustache b/src/main/resources/generator/client/angular/src/main/webapp/app/common/primary/app/app.component.html.mustache index 199897e44e3..3973685e4cb 100644 --- a/src/main/resources/generator/client/angular/src/main/webapp/app/common/primary/app/app.component.html.mustache +++ b/src/main/resources/generator/client/angular/src/main/webapp/app/common/primary/app/app.component.html.mustache @@ -5,13 +5,13 @@

{{=<% %>=}}{{ appName }}<%={{ }}=%>: Angular + TypeScript

Recommended IDE setup: - VSCode + VSCode

- Angular Documentation + Angular Documentation | - Angular CLI Documentation + Angular CLI Documentation

diff --git a/src/main/resources/generator/client/vite/vue/webapp/app/common/primary/app/StyledApp.html.mustache b/src/main/resources/generator/client/vite/vue/webapp/app/common/primary/app/StyledApp.html.mustache index 7d5caa287d0..19ab5e0dead 100644 --- a/src/main/resources/generator/client/vite/vue/webapp/app/common/primary/app/StyledApp.html.mustache +++ b/src/main/resources/generator/client/vite/vue/webapp/app/common/primary/app/StyledApp.html.mustache @@ -5,17 +5,17 @@

{{=<% %>=}}{{ appName }}<%={{ }}=%>: Vue 3 + TypeScript + Vite

Recommended IDE setup: - VSCode + VSCode + - Volar + Volar

- + Vite Documentation | - Vue 3 Documentation + Vue 3 Documentation

diff --git a/src/main/resources/generator/server/springboot/user/sqldatabase/UserEntity_without_sequence.java.mustache b/src/main/resources/generator/server/springboot/user/sqldatabase/UserEntity_without_sequence.java.mustache index 6d88bf7110b..023c7284109 100644 --- a/src/main/resources/generator/server/springboot/user/sqldatabase/UserEntity_without_sequence.java.mustache +++ b/src/main/resources/generator/server/springboot/user/sqldatabase/UserEntity_without_sequence.java.mustache @@ -12,8 +12,7 @@ import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import org.apache.commons.lang3.StringUtils; import org.hibernate.annotations.BatchSize; - -import tech.jhipster.beer.user.domain.UserConstants; +import {{packageName}}.user.domain.UserConstants; /** * A user. diff --git a/tests-ci/config/consulapp.json b/tests-ci/config/consulapp.json new file mode 100644 index 00000000000..6465fb38913 --- /dev/null +++ b/tests-ci/config/consulapp.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/consulapp", + "generator-jhipster": { + "projectName": "ConsulApp Project", + "baseName": "consulapp", + "packageName": "tech.jhipster.consulapp" + } +} diff --git a/tests-ci/config/eurekaapp.json b/tests-ci/config/eurekaapp.json new file mode 100644 index 00000000000..e1de26dd68a --- /dev/null +++ b/tests-ci/config/eurekaapp.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/eurekaapp", + "generator-jhipster": { + "projectName": "EurekaApp Project", + "baseName": "eurekaapp", + "packageName": "tech.jhipster.eurekaapp" + } +} diff --git a/tests-ci/config/full-default.json b/tests-ci/config/full-default.json deleted file mode 100644 index d6f0a1b415f..00000000000 --- a/tests-ci/config/full-default.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/full-default", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/fullapp.json b/tests-ci/config/fullapp.json new file mode 100644 index 00000000000..0d9370038f1 --- /dev/null +++ b/tests-ci/config/fullapp.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/fullapp", + "generator-jhipster": { + "projectName": "Fullapp Project", + "baseName": "fullapp", + "packageName": "tech.jhipster.fullapp" + } +} diff --git a/tests-ci/config/fullstack.json b/tests-ci/config/fullstack.json new file mode 100644 index 00000000000..c48144523bf --- /dev/null +++ b/tests-ci/config/fullstack.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/fullstack", + "generator-jhipster": { + "projectName": "Full Stack Project", + "baseName": "fullstack", + "packageName": "tech.jhipster.fullstack" + } +} diff --git a/tests-ci/config/mongodbapp.json b/tests-ci/config/mongodbapp.json new file mode 100644 index 00000000000..5edeb33bf61 --- /dev/null +++ b/tests-ci/config/mongodbapp.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/mongodbapp", + "generator-jhipster": { + "projectName": "MongoDB App Project", + "baseName": "mongodbapp", + "packageName": "tech.jhipster.mongodbapp" + } +} diff --git a/tests-ci/config/mysqlapp.json b/tests-ci/config/mysqlapp.json new file mode 100644 index 00000000000..f89f02a1ae5 --- /dev/null +++ b/tests-ci/config/mysqlapp.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/mysqlapp", + "generator-jhipster": { + "projectName": "MySQL Project", + "baseName": "mysqlapp", + "packageName": "tech.jhipster.mysqlapp" + } +} diff --git a/tests-ci/config/tomcat-configserver.json b/tests-ci/config/tomcat-configserver.json deleted file mode 100644 index 1886c137038..00000000000 --- a/tests-ci/config/tomcat-configserver.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/tomcat-configserver", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/tomcat-eureka.json b/tests-ci/config/tomcat-eureka.json deleted file mode 100644 index a3686c00e41..00000000000 --- a/tests-ci/config/tomcat-eureka.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/tomcat-eureka", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/tomcat-mongodb.json b/tests-ci/config/tomcat-mongodb.json deleted file mode 100644 index a648a9b0945..00000000000 --- a/tests-ci/config/tomcat-mongodb.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/tomcat-mongodb", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/tomcat-mysql-ehcachexml.json b/tests-ci/config/tomcat-mysql-ehcachexml.json deleted file mode 100644 index 2e63b57fbb2..00000000000 --- a/tests-ci/config/tomcat-mysql-ehcachexml.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/tomcat-mysql-ehcachexml", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/undertow-consul.json b/tests-ci/config/undertow-consul.json deleted file mode 100644 index c40ff7344df..00000000000 --- a/tests-ci/config/undertow-consul.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/undertow-consul", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/undertow-simplecache.json b/tests-ci/config/undertow-simplecache.json deleted file mode 100644 index 0ceff020e89..00000000000 --- a/tests-ci/config/undertow-simplecache.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folder": "/tmp/jhlite/undertow-simplecache", - "generator-jhipster": { - "projectName": "Beer Project", - "baseName": "beer", - "packageName": "tech.jhipster.beer" - } -} diff --git a/tests-ci/config/undertowapp.json b/tests-ci/config/undertowapp.json new file mode 100644 index 00000000000..bfedc78b3fd --- /dev/null +++ b/tests-ci/config/undertowapp.json @@ -0,0 +1,8 @@ +{ + "folder": "/tmp/jhlite/undertowapp", + "generator-jhipster": { + "projectName": "UndertowApp Project", + "baseName": "undertowapp", + "packageName": "tech.jhipster.undertowapp" + } +} diff --git a/tests-ci/generate.sh b/tests-ci/generate.sh index 7412c14d939..123976edefc 100755 --- a/tests-ci/generate.sh +++ b/tests-ci/generate.sh @@ -1,7 +1,7 @@ #!/bin/bash show_syntax() { - echo "Usage: $0 " >&2 + echo "Usage: $0 " >&2 exit 1 } @@ -9,14 +9,23 @@ if [ "$#" -ne 1 ]; then show_syntax fi -filename=$1 +application=$1 + +if test -f config/"$application".json; then + filename=config/"$application".json +elif test -f tests-ci/config/"$application".json; then + filename=tests-ci/config/"$application".json +else + echo "The application" "$application" "does not exist!" + exit 1 +fi callApi() { local api="$1" curl -X POST \ -H "accept: */*" \ - -H "Content-Type: application/json" -d @config/$filename.json \ - "http://localhost:7471"$api + -H "Content-Type: application/json" -d @"$filename" \ + "http://localhost:7471""$api" } springboot() { @@ -29,7 +38,7 @@ springboot() { callApi "/api/servers/spring-boot/mvc/web/actuator" } -springbootUndertow() { +springboot_undertow() { callApi "/api/projects/init" callApi "/api/build-tools/maven" callApi "/api/servers/java/base" @@ -39,16 +48,34 @@ springbootUndertow() { callApi "/api/servers/spring-boot/mvc/web/actuator" } -if [[ $filename == 'full-default' ]]; then +sonar_back() { + callApi "/api/servers/sonar/java-backend" +} + +sonar_back_front() { + callApi "/api/servers/sonar/java-backend-and-frontend" +} + +if [[ $application == 'springboot' ]]; then + springboot + sonar_back + +elif [[ $application == 'fullstack' ]]; then springboot + sonar_back_front + +elif [[ $application == 'fullapp' ]]; then + springboot + sonar_back_front callApi "/api/servers/spring-boot/async" callApi "/api/servers/spring-boot/devtools" 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-and-frontend" callApi "/api/servers/spring-boot/docker/jib" + callApi "/api/servers/java/arch" + callApi "/api/setup/codespaces" callApi "/api/servers/spring-boot/mvc/security/jwt" callApi "/api/servers/spring-boot/mvc/security/jwt/basic-auth" @@ -60,80 +87,82 @@ if [[ $filename == 'full-default' ]]; then callApi "/api/servers/spring-boot/databases/migration/liquibase/init" callApi "/api/servers/spring-boot/databases/migration/liquibase/user" - callApi "/api/servers/java/arch" - callApi "/api/servers/spring-boot/cache/ehcache/java-configuration" - callApi "/api/setup/codespaces" callApi "/api/frontend-maven-plugin" callApi "/api/vite/vue" -elif [[ $filename == 'springboot' ]]; then - springboot - -elif [[ $filename == 'tomcat-mysql-ehcachexml' ]]; then +elif [[ $application == 'mysqlapp' ]]; then springboot + sonar_back callApi "/api/servers/spring-boot/mvc/springdoc/init" + callApi "/api/servers/spring-boot/mvc/dummy" + callApi "/api/servers/spring-boot/databases/mysql" callApi "/api/servers/spring-boot/user/mysql" - callApi "/api/servers/spring-boot/databases/migration/flyway/init" - callApi "/api/servers/spring-boot/databases/migration/flyway/user" - - callApi "/api/servers/spring-boot/mvc/security/jwt" - callApi "/api/servers/spring-boot/mvc/security/jwt/basic-auth" - callApi "/api/servers/spring-boot/mvc/springdoc/init-with-security-jwt" + callApi "/api/servers/spring-boot/databases/migration/liquibase/init" + callApi "/api/servers/spring-boot/databases/migration/liquibase/user" callApi "/api/servers/spring-boot/cache/ehcache/xml-configuration" -elif [[ $filename == 'undertow-simplecache' ]]; then - springbootUndertow +elif [[ $application == 'flywayapp' ]]; then + springboot + sonar_back - callApi "/api/servers/spring-boot/banner/jhipster-v3" - callApi "/api/servers/spring-boot/mvc/dummy" + callApi "/api/servers/spring-boot/databases/postgresql" + callApi "/api/servers/spring-boot/user/postgresql" + callApi "/api/servers/spring-boot/databases/migration/flyway/init" + callApi "/api/servers/spring-boot/databases/migration/flyway/user" + +elif [[ $application == 'undertowapp' ]]; then + springboot_undertow + sonar_back callApi "/api/servers/spring-boot/databases/mysql" callApi "/api/servers/spring-boot/user/mysql" - callApi "/api/servers/spring-boot/databases/migration/liquibase/init" - callApi "/api/servers/spring-boot/databases/migration/liquibase/user" + callApi "/api/servers/spring-boot/databases/migration/flyway/init" + callApi "/api/servers/spring-boot/databases/migration/flyway/user" + callApi "/api/servers/spring-boot/cache/simple" -elif [[ $filename == 'tomcat-configserver' ]]; then +elif [[ $application == 'eurekaapp' ]]; then springboot - callApi "/api/servers/spring-boot/spring-cloud/config-client" - callApi "/api/servers/sonar/java-backend" + sonar_back -elif [[ $filename == 'tomcat-eureka' ]]; then - springboot callApi "/api/servers/spring-boot/spring-cloud/eureka-client" + callApi "/api/servers/spring-boot/spring-cloud/config-client" + +elif [[ $application == 'consulapp' ]]; then + springboot_undertow + sonar_back -elif [[ $filename == 'undertow-consul' ]]; then - springbootUndertow callApi "/api/servers/spring-boot/spring-cloud/consul" -elif [[ $filename == 'tomcat-mongodb' ]]; then +elif [[ $application == 'mongodbapp' ]]; then springboot - callApi "/api/servers/spring-boot/databases/mongodb" + sonar_back -elif [[ $filename == 'flywayapp' ]]; then - springboot - callApi "/api/servers/spring-boot/databases/postgresql" - callApi "/api/servers/spring-boot/user/postgresql" - callApi "/api/servers/spring-boot/databases/migration/flyway/init" - callApi "/api/servers/spring-boot/databases/migration/flyway/user" + callApi "/api/servers/spring-boot/databases/mongodbapp" -elif [[ $filename == 'angularapp' ]]; then +elif [[ $application == 'angularapp' ]]; then springboot + sonar_back_front + callApi "/api/frontend-maven-plugin" callApi "/api/angular" -elif [[ $filename == 'reactapp' ]]; then +elif [[ $application == 'reactapp' ]]; then springboot + sonar_back_front + callApi "/api/frontend-maven-plugin" callApi "/api/vite/react" -elif [[ $filename == 'vueapp' ]]; then +elif [[ $application == 'vueapp' ]]; then springboot + sonar_back_front + callApi "/api/frontend-maven-plugin" callApi "/api/vite/vue/styled" @@ -142,5 +171,7 @@ else exit 1 fi -echo "Waiting 5sec..." +echo "" +cat "$filename" +echo "" sleep 5 diff --git a/tests-ci/sonar.sh b/tests-ci/sonar.sh index 3a78f61ed46..38952b51d4f 100755 --- a/tests-ci/sonar.sh +++ b/tests-ci/sonar.sh @@ -1,19 +1,27 @@ #!/bin/bash -sonar=$(curl -sX GET 'http://localhost:9001/api/measures/component?component=jhlite&metricKeys=bugs%2Ccoverage%2Cvulnerabilities%2Cduplicated_lines_density%2Ccode_smells'); +application=$1 +if [[ $application == '' ]]; then + echo "using jhlite by default" + application='jhlite' +fi + +sonar=$(curl -sX GET 'http://localhost:9001/api/measures/component?component='"$application"'&metricKeys=bugs%2Ccoverage%2Cvulnerabilities%2Cduplicated_lines_density%2Ccode_smells%2Csecurity_hotspots'); vul=$(echo "$sonar"|jq -r .component|jq -r .measures|jq '[.[]|select(.metric=="vulnerabilities")][0]'|jq -r .value); cov=$(echo "$sonar"|jq -r .component|jq -r .measures|jq '[.[]|select(.metric=="coverage")][0]'|jq -r .value); bug=$(echo "$sonar"|jq -r .component|jq -r .measures|jq '[.[]|select(.metric=="bugs")][0]'|jq -r .value); dup=$(echo "$sonar"|jq -r .component|jq -r .measures|jq '[.[]|select(.metric=="duplicated_lines_density")][0]'|jq -r .value); csm=$(echo "$sonar"|jq -r .component|jq -r .measures|jq '[.[]|select(.metric=="code_smells")][0]'|jq -r .value); +sec=$(echo "$sonar"|jq -r .component|jq -r .measures|jq '[.[]|select(.metric=="security_hotspots")][0]'|jq -r .value); echo "----- Local Sonar Analysis -----" -echo " Coverage: $cov" -echo " Vulnerabilities: $vul" -echo " Bugs: $bug" -echo " Duplication: $dup" -echo " Code smells: $csm" +echo " Coverage: $cov" +echo " Vulnerabilities: $vul" +echo " Bugs: $bug" +echo " Duplication: $dup" +echo " Code smells: $csm" +echo " Security Hotspots: $sec" echo "--------------------------------" if [[ $vul != "0" ]]; then @@ -35,3 +43,8 @@ if [[ $csm != "0" ]]; then echo "Sonar Analysis failed -> Code smells" exit 1; fi + +if [[ $sec != "0" ]]; then + echo "Sonar Analysis failed -> Security Hotspots" + exit 1; +fi