Skip to content

Commit

Permalink
Introduce version check in base codestarts and use them
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Jun 17, 2024
1 parent 59bad99 commit 834b192
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
{#if generate-native}
{#if generate-native and quarkus.platform.version.compareVersionTo("3.12") >= 0}
<goal>native-image-agent</goal>
{/if}
</goals>
Expand Down
4 changes: 4 additions & 0 deletions independent-projects/tools/codestarts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<groupId>io.quarkus.qute</groupId>
<artifactId>qute-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-app-model</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@
import java.util.concurrent.CompletionStage;

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;
import io.quarkus.devtools.codestarts.CodestartResource.Source;
import io.quarkus.qute.CompletedStage;
import io.quarkus.qute.Engine;
import io.quarkus.qute.EvalContext;
import io.quarkus.qute.Expression;
import io.quarkus.qute.ResultMapper;
import io.quarkus.qute.Results;
import io.quarkus.qute.TemplateException;
import io.quarkus.qute.TemplateLocator;
import io.quarkus.qute.TemplateNode;
import io.quarkus.qute.ValueResolver;
import io.quarkus.qute.Variant;
import io.quarkus.qute.*;

final class QuteCodestartFileReader implements CodestartFileReader {

Expand Down Expand Up @@ -187,9 +178,21 @@ public CompletionStage<Object> 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) {
return new ComparableVersion(currentVersionString).compareTo(new ComparableVersion(comparedVersionString));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 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("3.12", "SOMETHING")).isGreaterThan(0);
assertThat(compareVersionTo("1.0.0.Final-redhat-00001", "1.0.0.Final-redhat-00002")).isLessThan(0);
assertThat(compareVersionTo("1.0.0.Final-redhat-00001", "1.0.0.SP1-redhat-00001")).isGreaterThan(0);
}
}

0 comments on commit 834b192

Please sign in to comment.