-
-
Notifications
You must be signed in to change notification settings - Fork 180
fix: resource references with property resolving #2153
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ///usr/bin/env jbang "$0" "$@" ; exit $? | ||
|
|
||
| import static java.lang.System.*; | ||
|
|
||
| public class linux { | ||
|
|
||
| public static void main(String... args) { | ||
| out.println("Hello linux"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ///usr/bin/env jbang "$0" "$@" ; exit $? | ||
|
|
||
| import static java.lang.System.*; | ||
|
|
||
| public class osx { | ||
|
|
||
| public static void main(String... args) { | ||
| out.println("Hello osx"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ///usr/bin/env jbang "$0" "$@" ; exit $? | ||
|
|
||
| import static java.lang.System.*; | ||
|
|
||
| public class win { | ||
|
|
||
| public static void main(String... args) { | ||
| out.println("Hello Windows"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,12 +258,41 @@ private List<MavenRepo> allToMavenRepo(List<String> repos) { | |
| } | ||
|
|
||
| public Project build(String resource) { | ||
| ResourceRef resourceRef = resolveChecked(getResourceResolver(), resource); | ||
| ResourceRef resourceRef = resolveChecked(getResourceResolver(), resource, true); | ||
| return build(resourceRef); | ||
| } | ||
|
|
||
| private ResourceRef resolveChecked(ResourceResolver resolver, String resource) { | ||
| Util.verboseMsg("Resolving resource ref: " + resource); | ||
| return resolveChecked(resolver, resource, false); | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the given resource, with property resolution from project context | ||
| * and handles retry on caching. | ||
| * | ||
| * Note: only enable property replacement if you know the resource is not | ||
| * something that can be embedded/included directly in the project from users | ||
| * data. | ||
| * | ||
| * i.e. jbang run someref${os.detected.os}.jar is ok but //FILES with | ||
| * ${user.home} is definitely not. | ||
| * | ||
| * @param resolver | ||
| * @param resource | ||
| * @return | ||
| */ | ||
| private ResourceRef resolveChecked(ResourceResolver resolver, String orginal_resource, | ||
|
Contributor
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. This is already merged, but
Collaborator
Author
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. This is what was already there afaik. Unless you identify as AI it was human :)
Contributor
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. Don't gaslight me, this code is new, the diff shows you just added it :-) I would never ever write a (Java) variable name with an underscore, the very idea gives me shivers 😁
Collaborator
Author
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. The only answer must be that I'm an AI then :) |
||
| boolean propertyReplacement) { | ||
| final String resource = propertyReplacement | ||
| ? PropertiesValueResolver.replaceProperties(orginal_resource, getContextProperties()) | ||
| : orginal_resource; | ||
|
|
||
| if (!resource.equals(orginal_resource)) { | ||
| Util.verboseMsg("Resolving resource ref: " + orginal_resource + " -> " + resource); | ||
|
Contributor
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. Logging this is good, but I think the wording could be improved. In this case if there are no properties to be replaced you won't get a "resolving ..." message, which is wrong because we definitely are resolving. So I'd say that we'd either have to always log something or change the wording to something like "Applying properties" instead of "Resolving".
Collaborator
Author
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. but something gets logged everytime - its just only when applying properties we put the "-> " I did that to avoid it to say 99% of the time "Resolving resource ref: abc -> abc" but if you can think of a better one do open pr.
Contributor
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. Well, that's why I said to simply change the text. Because it's not resolving, it's "applying properties to resource ref" or something like that. Just to avoid any confusion that that line suggests that resolving has been done/performed.
Collaborator
Author
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. But resolve xyz is what we wrote before applying any properties. So are you saying the old one was wrong?
Contributor
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. Maybe I'm just misunderstanding things. Doesn't matter. Not important, |
||
| } else { | ||
| Util.verboseMsg("Resolving resource ref:" + resource); | ||
| } | ||
|
|
||
| boolean retryCandidate = catalogFile == null && !Util.isFresh() && Settings.getCacheEvict() > 0 | ||
| && (Catalog.isValidName(resource) || Catalog.isValidCatalogReference(resource) | ||
| || Util.isRemoteRef(resource)); | ||
|
|
@@ -618,6 +647,7 @@ private ResourceResolver getAliasResourceResolver(Alias alias) { | |
| if (alias != null) { | ||
| updateFromAlias(alias); | ||
| } | ||
|
|
||
| return new CombinedResourceResolver( | ||
| new RenamingScriptResourceResolver(forceType), | ||
| new LiteralScriptResourceResolver(forceType), | ||
|
|
||
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.
Either put proper docs or remove the
@params:-)