generated from version-fox/vfox-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: support asdf formated version strings #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| local distribution_version_parser = require("distribution_version") | ||
|
|
||
| function PLUGIN:PreUse(ctx) | ||
| local distribution_version = distribution_version_parser.parse_version(ctx.version) | ||
| if distribution_version and distribution_version.distribution.short_name ~= "open" then | ||
| return { | ||
| version = distribution_version.version .. "-" .. distribution_version.distribution.short_name | ||
| } | ||
| else | ||
| return { | ||
| version = ctx.version, | ||
| } | ||
| end | ||
| end | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| local strings = require("vfox.strings") | ||
|
|
||
| local short_name = { | ||
| ["open"] = "openjdk", | ||
| ["bsg"] = "bisheng", | ||
| ["amzn"] = "corretto", | ||
| ["albba"] = "dragonwell", | ||
| ["graal"] = "graalvm", | ||
| ["graalce"] = "graalvm_community", | ||
| ["oracle"] = "oracle", | ||
| ["kona"] = "kona", | ||
| ["librca"] = "liberica", | ||
| ["nik"] = "liberica_native", | ||
| ["mandrel"] = "mandrel", | ||
| ["ms"] = "microsoft", | ||
| ["sapmchn"] = "sap_machine", | ||
| ["sem"] = "semeru", | ||
| ["tem"] = "temurin", | ||
| ["trava"] = "trava", | ||
| ["zulu"] = "zulu", | ||
| ["jb"] = "jetbrains", | ||
| } | ||
|
|
||
| local long_name={} | ||
| local distribution_version={ | ||
| distributions={} | ||
aooohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| for k,v in pairs(short_name) do | ||
| long_name[v]=k | ||
| table.insert(distribution_version.distributions,{ | ||
| name = v, | ||
| short_name = k | ||
| }) | ||
| end | ||
|
|
||
| function distribution_version.parse_distribution (name) | ||
| local distribution_name=long_name[name] | ||
| if distribution_name then | ||
| -- already a valid long name, just return it | ||
| return { | ||
| name = name, | ||
| short_name = distribution_name | ||
| } | ||
| end | ||
| distribution_name=short_name[name] | ||
| if distribution_name then | ||
| -- already a valid short name, just return it | ||
| return { | ||
| name = distribution_name, | ||
| short_name = name | ||
| } | ||
| end | ||
| return nil | ||
| end | ||
|
|
||
|
|
||
| function distribution_version.parse_version (arg) | ||
| local version_parts = strings.split(arg, "-") | ||
| local version | ||
| local distribution | ||
|
|
||
| if not version_parts[2] then | ||
| -- no parts, check if we got a distribution name without version | ||
| distribution = distribution_version.parse_distribution(version_parts[1]) | ||
| if not distribution then | ||
| -- no valid distribution found, handle as version with distribution "openjdk" | ||
| version=version_parts[1] | ||
| distribution = distribution_version.parse_distribution("openjdk") | ||
| end | ||
| else | ||
| -- check if the distribution is in the second part of the string (vfox/sdkman default) | ||
| distribution = distribution_version.parse_distribution(version_parts[2]) | ||
| if distribution then | ||
| -- valid distribution found, treat first part as version | ||
| version=version_parts[1] | ||
| else | ||
| -- check if the distribution is in the first part of the string (asdf default) | ||
| distribution = distribution_version.parse_distribution(version_parts[1]) | ||
| if distribution then | ||
| -- valid distribution found, treat second part as version | ||
| version=version_parts[2] | ||
| else | ||
| -- invalid distribution name | ||
| return nil | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return { | ||
| version = version, | ||
| distribution = distribution, | ||
| } | ||
| end | ||
|
|
||
| return distribution_version | ||
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.