From ccda98de815fff77c8bebe4d538f4057fcd71b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 29 Mar 2023 08:52:28 +0200 Subject: [PATCH] Extract the code style and test from the Dockerfile --- .dockerignore | 10 ++-- .github/workflows/main.yaml | 59 +++++++------------ .gitignore | 2 + BREAKING-CHANGES.md | 4 ++ Dockerfile | 44 +++++++------- Makefile | 35 +++++++++-- build.gradle | 6 +- core/Dockerfile | 1 - .../print/jasperreports}/HumanAlphaSerie.java | 0 docker-compose.yaml | 9 +-- .../examples/paging/simpleReport.jrxml | 10 ++-- 11 files changed, 94 insertions(+), 86 deletions(-) rename {examples/src/test/java/org/mapfish/print => core/src/main/java/org/mapfish/print/jasperreports}/HumanAlphaSerie.java (100%) diff --git a/.dockerignore b/.dockerignore index 0840209223..f164a6b7c9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -20,9 +20,9 @@ ci build/ */build/ -examples/*.jasper -examples/src/test/resources/examples_to_port -examples/src/test/resources/examples -examples/geoserver-data +core/docker/ +core/src/test/ -core/docker +examples/*.jasper +examples/src/test/ +examples/geoserver-data/ diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e63951ff12..8e310d0741 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -82,59 +82,40 @@ jobs: run: c2cciutils-checks - run: make build - - run: make acceptance-tests-up - - run: make acceptance-tests-run - - # Extract artifacts - - run: docker run --rm --detach --name=builder mapfish_print_builder || true - if: always() - - run: docker cp builder:/src/core/build/ core/build/ || true - if: always() - - run: ls -l core/build/distributions - if: always() - - - run: docker cp mapfish-print_tests_1:/src/examples/build/ examples/build/ || true - if: always() - - run: c2cciutils-docker-logs || true - if: failure() - - - run: mkdir -p core/build/resources/actual examples/build/reports core/build/reports examples/build/resources/test/examples - if: always() - - uses: actions/upload-artifact@v3 - with: - name: Test results - path: core/build/resources/ - if-no-files-found: ignore - if: failure() + - run: make checks - uses: actions/upload-artifact@v3 with: - name: Reports examples - path: examples/build/reports + name: Checkstyle and Spotbugs reports + path: reports if-no-files-found: ignore - if: failure() + if: always() + + - run: make tests + - uses: actions/upload-artifact@v3 with: - name: Reports core - path: core/build/reports + name: Unit test results + path: core/build/resources/test/org/mapfish/print/ if-no-files-found: ignore if: failure() - uses: actions/upload-artifact@v3 with: - name: Examples - path: examples/build/resources/test/examples + name: Unit test report + path: core/build/reports/tests/test/ if-no-files-found: ignore - if: failure() + if: always() + + - run: make acceptance-tests-up + - run: make acceptance-tests-run + - run: c2cciutils-docker-logs || true + if: always() - - name: Collect test results - run: | - mkdir -p /tmp/test_results/junit - find . -name '*TEST-*.xml' -exec cp -v {} /tmp/test_results/junit/ \; - if: failure() - uses: actions/upload-artifact@v3 with: - name: Test results - path: /tmp/test_results + name: Acceptance tests (Examples) + path: examples/build/resources/test/examples/ + if-no-files-found: ignore if: failure() - name: Publish diff --git a/.gitignore b/.gitignore index a21035f5e3..cfc6ea912a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ /build/ /*/build/ +/docker-compose.override.yaml + /CI.asc diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index b5457385eb..5d8acc078e 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1,5 +1,9 @@ # Known breaking changes +## Version 3.31 + +- `HumanAlphaSerie` is moved from package `org.mapfish.print` to `org.mapfish.print.jasperreports`. + ## Version 3.30 - Add support of MapServer 8.0, remove support of MapServer <= 7.4 (MAP_ANGLE => ANGLE). diff --git a/Dockerfile b/Dockerfile index 3c141c3a3d..979f55e4e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,44 +3,42 @@ FROM gradle:8.1.1-jdk11 AS builder RUN --mount=type=cache,target=/var/cache,sharing=locked \ --mount=type=cache,target=/root/.cache \ apt-get update && \ - apt-get install --yes --no-install-recommends fonts-liberation gettext curl && \ - gradle --version + apt-get install --yes --no-install-recommends fonts-liberation gettext curl WORKDIR /src +ENV GRADLE_OPTS=-Dorg.gradle.daemon=false + +RUN --mount=type=cache,target=/home/gradle/.gradle \ + gradle --version + COPY gradle/ ./gradle/ COPY gradle.properties build.gradle settings.gradle CI.asc ./ COPY examples/build.gradle ./examples/ COPY docs/build.gradle ./docs/ COPY publish/build.gradle ./publish/ COPY core ./core - -RUN --mount=type=cache,target=/home/gradle/.gradle \ - gradle :core:processResources :core:classes -COPY checkstyle_* ./ -# '&& touch success || true' is a trick to be able to get out some artifacts -RUN --mount=type=cache,target=/home/gradle/.gradle \ - (gradle :core:checkstyleMain :core:spotbugsMain :core:violations --stacktrace) \ - && ( (gradle :core:build :core:explodedWar :core:libSourcesJar :core:libJavadocJar > /tmp/logs 2>&1 && touch success) || true) +COPY publish ./publish +COPY examples ./examples +COPY docs ./docs ARG GIT_HEAD ENV GIT_HEAD=${GIT_HEAD} -COPY publish ./publish - +# Exclude the tasks that will run out of the docker build (in a docker run) RUN --mount=type=cache,target=/home/gradle/.gradle \ - ([ -e success ] && ( (gradle :publish:build >> /tmp/logs 2>&1) && touch success-publish)) || true + gradle --parallel --exclude-task=:core:test \ + --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain --exclude-task=:core:violations \ + --exclude-task=:core:spotbugsTest --exclude-task=:core:checkstyleTest --exclude-task=:core:testCLI \ + :core:build :core:explodedWar :publish:build :examples:build :docs:buildDocs -COPY examples ./examples -COPY docs ./docs +RUN mkdir -p core/build/resources/test/org/mapfish/print/ \ + && chmod -R go=u /home/gradle /tmp/mapfish-print/ . \ + && chmod o+t -R core/build/resources +# Backup cache RUN --mount=type=cache,target=/home/gradle/.gradle \ - ([ -e success ] && ( (gradle :examples:build buildDocs >> /tmp/logs 2>&1) && touch success-examples-docs)) || true - -RUN chmod -R go=u /home/gradle . - -FROM builder AS test-builder + cp -r /home/gradle/.gradle /home/gradle/.gradle-backup +RUN mv /home/gradle/.gradle-backup /home/gradle/.gradle -RUN cat /tmp/logs && ls success success-publish success-examples-docs - -VOLUME [ "/src/core" ] +COPY checkstyle_* ./ diff --git a/Makefile b/Makefile index 647b7bdae1..5daf7b27b4 100644 --- a/Makefile +++ b/Makefile @@ -2,19 +2,42 @@ GIT_HEAD_ARG = --build-arg=GIT_HEAD=$(shell git rev-parse HEAD) export DOCKER_BUILDKIT = 1 .PHONY: build -build: +build: build-builder # Required and not necessarily exists touch CI.asc - docker build $(GIT_HEAD_ARG) --target=builder --tag=mapfish_print_builder . - docker build $(GIT_HEAD_ARG) . - docker build $(GIT_HEAD_ARG) --target=runner --tag=camptocamp/mapfish_print core docker build $(GIT_HEAD_ARG) --target=tester --tag=mapfish_print_tester core docker build $(GIT_HEAD_ARG) --target=watcher --tag=mapfish_print_watcher core +.PHONY: build-builder +build-builder: + docker build $(GIT_HEAD_ARG) --target=builder --tag=mapfish_print_builder . + +.PHONY: checks +checks: build-builder + mkdir --parent reports + docker run --rm --user=$(shell id -u):$(shell id -g) \ + --volume=$(PWD)/core/src/:/src/core/src/:ro \ + --volume=$(PWD)/reports/:/src/core/build/reports/ \ + mapfish_print_builder \ + gradle --parallel :core:spotbugsMain :core:checkstyleMain :core:violations + +.PHONY: tests +tests: build-builder + mkdir --parent core/build/reports/ + mkdir --parent core/build/resources/ + docker run --rm --user=$(shell id -u):$(shell id -g) \ + --volume=$(PWD)/core/src/:/src/core/src/:ro \ + --volume=$(PWD)/core/build/reports/:/src/core/build/reports/ \ + --volume=$(PWD)/core/build/resources/:/src/core/build/resources/ \ + mapfish_print_builder \ + gradle --parallel --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain --exclude-task=:core:violations \ + --exclude-task=:core:spotbugsTest --exclude-task=:core:checkstyleTest \ + :core:test + .PHONY: acceptance-tests-up -acceptance-tests-up: +acceptance-tests-up: build docker-compose down --remove-orphan mkdir /tmp/geoserver-data || true @@ -24,7 +47,7 @@ acceptance-tests-up: cp -r examples/geoserver-data/* /tmp/geoserver-data/ cp -r core/src/test/resources/map-data/* /tmp/geoserver-data/www/ - USER_ID=$(shell id -u):$(shell id -g) docker-compose up -d + USER_ID=$(shell id -u):$(shell id -g) docker-compose up --detach .PHONY: acceptance-tests-run acceptance-tests-run: diff --git a/build.gradle b/build.gradle index 73c4aad5df..25dffcff5d 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ configure(subprojects.findAll { ['core', 'examples'].contains(it.name) }) { tasks.register('violations', ViolationsTask) { minSeverity = 'INFO' detailLevel = 'VERBOSE' // PER_FILE_COMPACT, COMPACT or VERBOSE - maxViolations = 1070 + maxViolations = 1071 printViolations = true violations = [ ["FINDBUGS", ".", ".*/reports/spotbugsReports/.*\\.xml", "Spotbugs"], @@ -71,8 +71,8 @@ configure(subprojects.findAll { ['core', 'examples'].contains(it.name) }) { } check.finalizedBy violations - sourceCompatibility = 1.11 - targetCompatibility = 1.11 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 compileJava.options.compilerArgs = ['-Xlint:deprecation', '-Xlint:unchecked'] diff --git a/core/Dockerfile b/core/Dockerfile index 1a31f8f3a0..5b86f5e8ad 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -20,7 +20,6 @@ RUN --mount=type=cache,target=/var/cache,sharing=locked \ fonts-liberation fonts-dejavu fontconfig COPY --from=builder /src/core/build/webapp "${CATALINA_HOME}/webapps/ROOT/" -COPY --from=builder /src/examples/build/classes/java/test/org/mapfish/print/HumanAlphaSerie.class "${CATALINA_HOME}/webapps/ROOT/WEB-INF/classes/org/mapfish/print/" COPY docker / RUN mkdir -p "${CATALINA_HOME}/extlib/classes/org/mapfish/print" \ diff --git a/examples/src/test/java/org/mapfish/print/HumanAlphaSerie.java b/core/src/main/java/org/mapfish/print/jasperreports/HumanAlphaSerie.java similarity index 100% rename from examples/src/test/java/org/mapfish/print/HumanAlphaSerie.java rename to core/src/main/java/org/mapfish/print/jasperreports/HumanAlphaSerie.java diff --git a/docker-compose.yaml b/docker-compose.yaml index 563a32f037..ad14257dcf 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,11 +11,11 @@ services: image: mapfish_print_tester user: ${USER_ID} volumes: - - ./examples/src/test/resources/examples:/usr/local/tomcat/webapps/ROOT/print-apps + - ./examples/src/test/resources/examples:/usr/local/tomcat/webapps/ROOT/print-apps:ro ports: - 8080:8080 environment: - PRINT_YAML_MAX_ALIASES: 200 + PRINT_YAML_MAX_ALIASES: '200' LOG_LEVEL: DEBUG JASPER_LOG_LEVEL: DEBUG @@ -24,7 +24,8 @@ services: user: ${USER_ID} command: tail --follow /dev/null volumes: - - ./examples/src/test/resources/examples:/src/examples/src/test/resources/examples + - ./examples/src/test/resources/examples:/src/examples/src/test/resources/examples:ro + - ./examples/build/reports:/src/examples/build/reports environment: - PRINT_YAML_MAX_ALIASES: 200 + PRINT_YAML_MAX_ALIASES: '200' GRADLE_USER_HOME: /home/gradle/.gradle diff --git a/examples/src/test/resources/examples/paging/simpleReport.jrxml b/examples/src/test/resources/examples/paging/simpleReport.jrxml index 5c9658560f..33efa15904 100644 --- a/examples/src/test/resources/examples/paging/simpleReport.jrxml +++ b/examples/src/test/resources/examples/paging/simpleReport.jrxml @@ -23,19 +23,19 @@ - + - + - + - + - + <band height="390" splitType="Stretch">