diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/maven/base/pom.tpl.qute.xml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/maven/base/pom.tpl.qute.xml index 511b172afc41b..3d32afccb8efd 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/maven/base/pom.tpl.qute.xml +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/buildtool/maven/base/pom.tpl.qute.xml @@ -140,7 +140,7 @@ build generate-code generate-code-tests - {#if generate-native} + {#if generate-native and quarkus.platform.version.compareVersionTo("3.12") >= 0} native-image-agent {/if} diff --git a/independent-projects/tools/codestarts/pom.xml b/independent-projects/tools/codestarts/pom.xml index e93c8abfb7583..c6a726533f1b7 100644 --- a/independent-projects/tools/codestarts/pom.xml +++ b/independent-projects/tools/codestarts/pom.xml @@ -18,6 +18,10 @@ io.quarkus.qute qute-core + + org.apache.maven + maven-artifact + io.quarkus quarkus-bootstrap-app-model diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java index d26b1ec9774c9..b2d6f606cb610 100644 --- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java +++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReader.java @@ -6,8 +6,10 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletionStage; +import java.util.regex.Pattern; import org.apache.commons.io.FilenameUtils; +import org.apache.maven.artifact.versioning.ComparableVersion; import io.quarkus.devtools.codestarts.CodestartException; import io.quarkus.devtools.codestarts.CodestartResource; @@ -30,6 +32,7 @@ final class QuteCodestartFileReader implements CodestartFileReader { private static final String ENTRY_QUTE_FLAG = ".entry.qute"; public static final String INCLUDE_QUTE_FLAG = ".include.qute"; public static final String SKIP_TAG = ""; + private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)(\\.(\\d+))?(\\.(\\d+))?"); @Override public boolean matches(String fileName) { @@ -187,9 +190,24 @@ public CompletionStage resolve(EvalContext context) { return CompletedStage.of(value.endsWith((String) e)); }); } + + case "compareVersionTo": + if (context.getParams().size() == 1) { + return context.evaluate(context.getParams().get(0)).thenCompose(e -> { + return CompletedStage.of(compareVersionTo(value, (String) e)); + }); + } default: return Results.notFound(context); } } } + + static int compareVersionTo(String currentVersionString, String comparedVersionString) { + if (!VERSION_PATTERN.matcher(comparedVersionString).matches()) { + throw new IllegalArgumentException("Let's not put template condition on qualifier: " + comparedVersionString); + } + return new ComparableVersion(currentVersionString).compareTo(new ComparableVersion(comparedVersionString)); + } + } diff --git a/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReaderTest.java b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReaderTest.java new file mode 100644 index 0000000000000..732a943af22b3 --- /dev/null +++ b/independent-projects/tools/codestarts/src/test/java/io/quarkus/devtools/codestarts/core/reader/QuteCodestartFileReaderTest.java @@ -0,0 +1,23 @@ +package io.quarkus.devtools.codestarts.core.reader; + +import static io.quarkus.devtools.codestarts.core.reader.QuteCodestartFileReader.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + +class QuteCodestartFileReaderTest { + + @Test + void testCompareVersion() { + assertThat(compareVersionTo("3.12.0.Final", "1.0")).isGreaterThan(0); + assertThat(compareVersionTo("3.12.0.Final", "3.12")).isEqualTo(0); + assertThat(compareVersionTo("3.13.0", "3.12")).isGreaterThan(0); + assertThat(compareVersionTo("3.2.1", "3.12")).isLessThan(0); + assertThat(compareVersionTo("999-SNAPSHOT", "3.12")).isGreaterThan(0); + assertThat(compareVersionTo("1.0.0.Final-redhat-00001", "1.0")).isGreaterThan(0); + assertThat(compareVersionTo("1.0.1.Final-redhat-00001", "1.0")).isGreaterThan(0); + assertThatThrownBy(() -> compareVersionTo("999-SNAP", "1.0.1.Final-redhat-00001")) + .isInstanceOf(IllegalArgumentException.class); + } +}