-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make templates adjust with scala version #25293
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,23 @@ | |
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 java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletionStage; | ||
import org.apache.commons.io.FilenameUtils; | ||
|
||
final class QuteCodestartFileReader implements CodestartFileReader { | ||
|
@@ -49,6 +53,7 @@ public static String readQuteFile(CodestartResource projectResource, Source sour | |
final String content = source.read(); | ||
final String templateId = source.absolutePath(); | ||
final Engine engine = Engine.builder().addDefaults() | ||
.addValueResolver(new StringValueResolver()) | ||
.addResultMapper(new MissingValueMapper()) | ||
.removeStandaloneLines(true) | ||
// For now we need to disable strict rendering for codestarts | ||
|
@@ -142,4 +147,38 @@ public String map(Object result, Expression expression) { | |
* } | ||
* } | ||
**/ | ||
|
||
private static class StringValueResolver implements ValueResolver { | ||
@Override | ||
public boolean appliesTo(EvalContext context) { | ||
return ValueResolver.matchClass(context, String.class); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Object> resolve(EvalContext context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we call methods on string anyway ? |
||
String value = (String) context.getBase(); | ||
switch (context.getName()) { | ||
case "startsWith": | ||
if (context.getParams().size() == 1) { | ||
return context.evaluate(context.getParams().get(0)).thenCompose(e -> { | ||
return CompletedStage.of(value.startsWith((String) e)); | ||
}); | ||
} | ||
case "contains": | ||
if (context.getParams().size() == 1) { | ||
return context.evaluate(context.getParams().get(0)).thenCompose(e -> { | ||
return CompletedStage.of(value.contains((CharSequence) e)); | ||
}); | ||
} | ||
case "endsWith": | ||
if (context.getParams().size() == 1) { | ||
return context.evaluate(context.getParams().get(0)).thenCompose(e -> { | ||
return CompletedStage.of(value.endsWith((String) e)); | ||
}); | ||
} | ||
default: | ||
return Results.notFound(context); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that really the exact version to use ? What if we upgrade to 2.13 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We upgraded to 2.13, that's the issue. Old versions need a different path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I get that but can't we make the template more open ended so it works with 2.13 and higher so we avoid having to keep updating ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxandersen we could make it configurable I guess and check if the variable exists, maybe that's the best backward/forward compatible fix.