From 617cb11c800a35a67b7e8d7f1f57d0fe357ad107 Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Mon, 17 Feb 2025 18:31:28 +0100 Subject: [PATCH] fix: check for Vaadin native processor (#1297) Vaadin Quarkus extension introduced build steps for native image. This change prevents the execution of the same steps from Quarkus Hilla extension, if the Vaadin native processor is available. (cherry picked from commit 9a273938d25049c16a29b9e7eafb452a609093e7) --- .github/workflows/validation-native.yaml | 4 +-- .../QuarkusHillaNativeProcessor.java | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/validation-native.yaml b/.github/workflows/validation-native.yaml index 6a9b690d..e2c3a899 100644 --- a/.github/workflows/validation-native.yaml +++ b/.github/workflows/validation-native.yaml @@ -61,7 +61,7 @@ jobs: id: set-matrix run: | test_modules=$(find integration-tests -maxdepth 1 -mindepth 1 -type d -name "*-tests") - test_modules=$(while IFS= read -r mod; do grep -q "%test-security." $mod/src/main/resources/application.properties; echo "{\"name\": \"${mod/integration-tests\//}\", \"path\": \"$mod\", \"security\": $? }"; done <<< "${test_modules}" | jq -s -c '.') + test_modules=$(while IFS= read -r mod; do test -f $mod/src/main/resources/application.properties && grep -q "%test-security." $mod/src/main/resources/application.properties; echo "{\"name\": \"${mod/integration-tests\//}\", \"path\": \"$mod\", \"security\": $? }"; done <<< "${test_modules}" | jq -s -c '.') echo "modules=${test_modules}" >> "$GITHUB_OUTPUT" build-and-test-native: name: Native tests @@ -98,7 +98,7 @@ jobs: set -x -e -o pipefail mvn -V -e -B -ntp verify -am -DtrimStackTrace=false -Dselenide.browserBinary=${{ steps.setup-chrome.outputs.chrome-path }} -Pit-tests,production -Dnative -pl ${{ matrix.module.path }} - name: Native Security Test - if: ${{ matrix.module.security == 1 }} + if: ${{ matrix.module.security == 0 }} run: | set -x -e -o pipefail mvn -V -e -B -ntp verify -am -DtrimStackTrace=false -Dselenide.browserBinary=${{ steps.setup-chrome.outputs.chrome-path }} -Pit-tests,production -Dnative -Dquarkus.profile=test-security -pl ${{ matrix.module.path }} diff --git a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/QuarkusHillaNativeProcessor.java b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/QuarkusHillaNativeProcessor.java index de53224f..250951db 100644 --- a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/QuarkusHillaNativeProcessor.java +++ b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/QuarkusHillaNativeProcessor.java @@ -110,13 +110,13 @@ public class QuarkusHillaNativeProcessor { - @BuildStep(onlyIf = IsNativeBuild.class) + @BuildStep(onlyIf = IsNativeBuild.class, onlyIfNot = IsVaadinNativeProcessorAvailable.class) void patchAtmosphere(CombinedIndexBuildItem index, BuildProducer producer) { AtmospherePatches patcher = new AtmospherePatches(index.getComputingIndex()); patcher.apply(producer); } - @BuildStep(onlyIf = IsNativeBuild.class) + @BuildStep(onlyIf = IsNativeBuild.class, onlyIfNot = IsVaadinNativeProcessorAvailable.class) @Record(ExecutionTime.RUNTIME_INIT) @Produce(DefaultRouteBuildItem.class) void deferAtmosphereInit( @@ -156,7 +156,7 @@ void removeHillaSpringBasedClasses(Capabilities capabilities, BuildProducer producer) { String dauIntegration = "com.vaadin.pro.licensechecker.dau.DauIntegration"; @@ -223,6 +223,7 @@ void hillaNativeSupport( nativeImageResource.produce(NativeImageResourcePatternsBuildItem.builder() .includePatterns("hilla-openapi\\.json", "hilla-engine-configuration\\.json", "file-routes\\.json") .includePatterns("META-INF/microprofile-config\\.properties") + .includePatterns("META-INF/maven/com.github.mcollovati/quarkus-hilla-commons/pom\\.properties") .build()); IndexView index = combinedIndex.getComputingIndex(); @@ -286,7 +287,7 @@ private Set getJsonClasses(IndexView index) { return classes; } - @BuildStep + @BuildStep(onlyIfNot = IsVaadinNativeProcessorAvailable.class) void vaadinNativeSupport( CombinedIndexBuildItem combinedIndex, BuildProducer runtimeInitializedPackage, @@ -298,7 +299,7 @@ void vaadinNativeSupport( nativeImageResource.produce(NativeImageResourcePatternsBuildItem.builder() .includeGlobs("META-INF/VAADIN/**", "com/vaadin/**", "vaadin-i18n/**") .includePatterns("org/atmosphere/util/version\\.properties") - .includePatterns("META-INF/maven/com.github.mcollovati/quarkus-hilla-commons/pom\\.properties") + .includePatterns("META-INF/maven/com.vaadin/vaadin-core/pom\\.properties") .build()); runtimeInitializedPackage.produce(new RuntimeInitializedPackageBuildItem("org.atmosphere.util.analytics")); @@ -440,4 +441,20 @@ public boolean getAsBoolean() { return nativeConfig.enabled(); } } + + public static class IsVaadinNativeProcessorAvailable implements BooleanSupplier { + + @Override + public boolean getAsBoolean() { + try { + Class.forName( + "com.vaadin.quarkus.deployment.VaadinQuarkusNativeProcessor", + false, + Thread.currentThread().getContextClassLoader()); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + } }