From 0749f05bf6eca52daba332b460d73248e9defd14 Mon Sep 17 00:00:00 2001 From: Kari Cordes Date: Mon, 11 Mar 2024 14:51:52 -0400 Subject: [PATCH 1/5] Added commands for generation of jacoco .xml report --- .circleci/config.yml | 11 +++++++++++ Dockerfile | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index df27e029d..9680fa560 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,6 +24,9 @@ jobs: name: "Create and start all services from the docker-compose configuration" command: | cp example/src/main/resources/application.properties.example ./example/src/main/resources/application.properties + mkdir jacocoJars + curl -L -o ./jacocoJars/jacocoagent.jar "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar" + curl -L -o ./jacocoJars/jacococli.jar "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.7/org.jacoco.cli-0.8.7-nodeps.jar" docker-compose up --build -d docker run --network container:mms curlimages/curl --retry 8 --retry-delay 10 --retry-max-time 90 --retry-connrefused http://mms:8080/healthcheck @@ -41,6 +44,14 @@ jobs: docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run artifacts.postman_collection.json -e test-env.json --delay-request 500 docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run elastic.postman_collection.json -e test-env.json --delay-request 500 docker run --volumes-from mms_test_configs --network container:mms -t postman/newman run groups.postman_collection.json -e test-env.json --delay-request 500 + + docker stop mms + mkdir -p jacocoOutput + docker cp mms:/mms/jacocoOutput/jacoco-it.exec ./jacocoOutput/jacoco-it.exec + cp -r */build/classes/* TEMPORARYclassfiles/ + java -jar jacocoJars/jacococli.jar report jacocoOutput/jacoco-it.exec --classfiles TEMPORARYclassfiles/ --xml ./jacocoOutput/jacocoXMLReport + rm -r TEMPORARYclassfiles + - persist_to_workspace: root: /home/circleci/ diff --git a/Dockerfile b/Dockerfile index e027f83cd..7ad2000ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,5 +5,6 @@ RUN ./gradlew --no-daemon bootJar --warning-mode all RUN find . -type f -name example-*.jar -not -iname '*javadoc*' -not -iname '*sources*' -exec cp '{}' '/app.jar' ';' ENV JDK_JAVA_OPTIONS "-XX:MaxRAMPercentage=90.0" -ENTRYPOINT ["java", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "-jar", "/app.jar"] +COPY jacocoJars/jacocoagent.jar ./jacocoagent.jar +ENTRYPOINT ["java", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "-javaagent:jacocoJars/jacocoagent.jar=destfile=jacocoOutput/jacoco-it.exec,output=file", "-jar", "/app.jar"] EXPOSE 8080 From 81718ea5c70ee8d8b5b88f045e76520fc04f026e Mon Sep 17 00:00:00 2001 From: Kari Cordes Date: Mon, 11 Mar 2024 15:54:16 -0400 Subject: [PATCH 2/5] Changed file path to gather classes --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b707a0859..005f2c554 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,7 +50,7 @@ jobs: docker stop mms mkdir -p jacocoOutput docker cp mms:/mms/jacocoOutput/jacoco-it.exec ./jacocoOutput/jacoco-it.exec - cp -r */build/classes/* TEMPORARYclassfiles/ + cp -r ./*/build/classes/* TEMPORARYclassfiles/ java -jar jacocoJars/jacococli.jar report jacocoOutput/jacoco-it.exec --classfiles TEMPORARYclassfiles/ --xml ./jacocoOutput/jacocoXMLReport rm -r TEMPORARYclassfiles From 5bcce0fd61257862e38033901045b6c381d60220 Mon Sep 17 00:00:00 2001 From: Kari Cordes Date: Mon, 11 Mar 2024 19:38:40 -0500 Subject: [PATCH 3/5] Fixed scan to depend on build_and_test, moved xml report to scan --- .circleci/config.yml | 13 ++++++++----- sonar-project.properties | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 005f2c554..7827d9593 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,11 +50,7 @@ jobs: docker stop mms mkdir -p jacocoOutput docker cp mms:/mms/jacocoOutput/jacoco-it.exec ./jacocoOutput/jacoco-it.exec - cp -r ./*/build/classes/* TEMPORARYclassfiles/ - java -jar jacocoJars/jacococli.jar report jacocoOutput/jacoco-it.exec --classfiles TEMPORARYclassfiles/ --xml ./jacocoOutput/jacocoXMLReport - rm -r TEMPORARYclassfiles - - persist_to_workspace: root: /home/circleci/ paths: @@ -67,7 +63,12 @@ jobs: - checkout - run: name: Build classes to scan - command: ./gradlew build -x test + command: | + ./gradlew build -x test + cp -r */build/classes/java/main/* TEMPORARYclassfiles/ + java -jar jacocoJars/jacococli.jar report jacocoOutput/jacoco-it.exec --classfiles TEMPORARYclassfiles/ --xml ./jacocoOutput/jacocoXMLReport + rm -r TEMPORARYclassfiles + - sonarcloud/scan deploy_snapshot: @@ -98,6 +99,8 @@ workflows: tags: only: /[0-9.]+(-(a|b|rc)[0-9]+)?/ - scan: + requires: + - build_and_test filters: tags: only: /[0-9.]+(-(a|b|rc)[0-9]+)?/ diff --git a/sonar-project.properties b/sonar-project.properties index b3bfa8103..581029b1d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,3 +2,4 @@ sonar.projectKey=Open-MBEE_exec-mms sonar.organization=openmbee sonar.language=java sonar.java.binaries=**/build/classes/java/main +sonar.coverage.jacoco.xmlReportPaths=jacocoOutput/jacocoXMLReport \ No newline at end of file From b7c0efd67e9f4c84c3c36d2d00eb773d273cde69 Mon Sep 17 00:00:00 2001 From: Kari Cordes Date: Mon, 11 Mar 2024 19:49:15 -0500 Subject: [PATCH 4/5] Command to create directory to copy to --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7827d9593..4d681a902 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,7 +50,7 @@ jobs: docker stop mms mkdir -p jacocoOutput docker cp mms:/mms/jacocoOutput/jacoco-it.exec ./jacocoOutput/jacoco-it.exec - + - persist_to_workspace: root: /home/circleci/ paths: @@ -65,6 +65,7 @@ jobs: name: Build classes to scan command: | ./gradlew build -x test + mkdir -p TEMPORARYclassfiles cp -r */build/classes/java/main/* TEMPORARYclassfiles/ java -jar jacocoJars/jacococli.jar report jacocoOutput/jacoco-it.exec --classfiles TEMPORARYclassfiles/ --xml ./jacocoOutput/jacocoXMLReport rm -r TEMPORARYclassfiles From ca310540fe728d28f2acc9210d24df4942abcbc0 Mon Sep 17 00:00:00 2001 From: Kari Cordes Date: Tue, 12 Mar 2024 11:52:35 -0700 Subject: [PATCH 5/5] Changed Dockerfile; scan step to attach workspace --- .circleci/config.yml | 5 +++-- Dockerfile | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4d681a902..54171256a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,7 +24,7 @@ jobs: name: "Create and start all services from the docker-compose configuration" command: | cp example/src/main/resources/application.properties.example ./example/src/main/resources/application.properties - mkdir jacocoJars + mkdir -p jacocoJars curl -L -o ./jacocoJars/jacocoagent.jar "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar" curl -L -o ./jacocoJars/jacococli.jar "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.7/org.jacoco.cli-0.8.7-nodeps.jar" docker-compose up --build -d @@ -60,7 +60,8 @@ jobs: executor: openjdk_executor working_directory: /home/circleci/mms steps: - - checkout + - attach_workspace: + at: ~/ - run: name: Build classes to scan command: | diff --git a/Dockerfile b/Dockerfile index 7ad2000ae..d7fdacdfa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,5 @@ RUN ./gradlew --no-daemon bootJar --warning-mode all RUN find . -type f -name example-*.jar -not -iname '*javadoc*' -not -iname '*sources*' -exec cp '{}' '/app.jar' ';' ENV JDK_JAVA_OPTIONS "-XX:MaxRAMPercentage=90.0" -COPY jacocoJars/jacocoagent.jar ./jacocoagent.jar ENTRYPOINT ["java", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "-javaagent:jacocoJars/jacocoagent.jar=destfile=jacocoOutput/jacoco-it.exec,output=file", "-jar", "/app.jar"] EXPOSE 8080