generated from version-fox/vfox-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init gradle plugin * Update README.md * Add mirroring option
- Loading branch information
Showing
9 changed files
with
113 additions
and
115 deletions.
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 |
---|---|---|
@@ -1,15 +1,9 @@ | ||
# vfox-plugin-template | ||
# vfox-gradle | ||
|
||
This is a [vfox plugin](https://vfox.lhan.me/plugins/create/howto.html) template with CI that package and publish the plugin. | ||
Gradle plugin for vfox [vfox](https://vfox.lhan.me/) . | ||
|
||
## Usage | ||
|
||
1. [Generate](https://github.com/version-fox/vfox-plugin-template/generate) a new repository based on this template. | ||
2. Configure [metadata](https://github.com/version-fox/vfox-plugin-template/blob/main/metadata.lua) information | ||
3. To develop your plugin further, please read [the plugins create section of the docs](https://vfox.lhan.me/plugins/create/howto.html). | ||
|
||
|
||
## How to publish? | ||
|
||
1. Push a new tag to the repository which name is `vX.Y.Z` (X.Y.Z is the version number). | ||
2. The CI will automatically package, then publish [release](https://github.com/version-fox/vfox-plugin-template/releases/tag/v0.0.1) and publish [manifest](https://github.com/version-fox/vfox-plugin-template/releases/tag/manifest). | ||
## Install | ||
After install vfox [vfox](https://vfox.lhan.me/),install the plugin by running: | ||
```bash | ||
vfox install gradle | ||
``` |
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
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 |
---|---|---|
@@ -1,40 +1,46 @@ | ||
local util = require("util") | ||
local os = require("os") | ||
--- Returns some pre-installed information, such as version number, download address, local files, etc. | ||
--- If checksum is provided, vfox will automatically check it for you. | ||
--- @param ctx table | ||
--- @field ctx.version string User-input version | ||
--- @return table Version information | ||
function PLUGIN:PreInstall(ctx) | ||
|
||
local result = {} | ||
local version = ctx.version | ||
local runtimeVersion = ctx.runtimeVersion | ||
return { | ||
--- Version number | ||
version = "xxx", | ||
--- remote URL or local file path [optional] | ||
url = "xxx", | ||
--- SHA256 checksum [optional] | ||
sha256 = "xxx", | ||
--- md5 checksum [optional] | ||
md5 = "xxx", | ||
--- sha1 checksum [optional] | ||
sha1 = "xxx", | ||
--- sha512 checksum [optional] | ||
sha512 = "xx", | ||
--- additional need files [optional] | ||
addition = { | ||
{ | ||
--- additional file name ! | ||
name = "xxx", | ||
--- remote URL or local file path [optional] | ||
url = "xxx", | ||
--- SHA256 checksum [optional] | ||
sha256 = "xxx", | ||
--- md5 checksum [optional] | ||
md5 = "xxx", | ||
--- sha1 checksum [optional] | ||
sha1 = "xxx", | ||
--- sha512 checksum [optional] | ||
sha512 = "xx", | ||
} | ||
} | ||
} | ||
result.version = version | ||
|
||
local downloadUrl = "" | ||
local imageUrl = os.getenv("GRADLE_DOWNLOAD_IMAGE") | ||
|
||
if imageUrl ~=nil then | ||
downloadUrl = imageUrl.."/gradle-"..version.."-bin.zip" | ||
else | ||
downloadUrl = util.DownloadInfoUrl:format(version) | ||
end | ||
|
||
result.url = downloadUrl | ||
|
||
local resp, err = http.get({ | ||
url = downloadUrl..".sha256" | ||
}) | ||
|
||
if err then | ||
error("HTTP request error: " .. err) | ||
end | ||
|
||
if resp.status_code == 200 then | ||
if resp.body then | ||
result.sha256 = resp.body | ||
else | ||
error("Empty body in HTTP response") | ||
end | ||
elseif resp.status_code == 404 then | ||
print("This version does not have checksums") | ||
else | ||
return nil | ||
end | ||
|
||
return result | ||
end |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local Util = {} | ||
|
||
Util.__index = Util | ||
|
||
local UtilSingleton = setmetatable({}, Util) | ||
UtilSingleton.AvailableVersionsUrl = "https://gradle.org/releases/" | ||
UtilSingleton.DownloadInfoUrl = "https://services.gradle.org/distributions/gradle-%s-bin.zip" | ||
|
||
function Util:compare_versions(v1o, v2o) | ||
local v1 = v1o.version | ||
local v2 = v2o.version | ||
local v1_parts = {} | ||
for part in string.gmatch(v1, "[^.]+") do | ||
table.insert(v1_parts, tonumber(part)) | ||
end | ||
|
||
local v2_parts = {} | ||
for part in string.gmatch(v2, "[^.]+") do | ||
table.insert(v2_parts, tonumber(part)) | ||
end | ||
|
||
for i = 1, math.max(#v1_parts, #v2_parts) do | ||
local v1_part = v1_parts[i] or 0 | ||
local v2_part = v2_parts[i] or 0 | ||
if v1_part > v2_part then | ||
return true | ||
elseif v1_part < v2_part then | ||
return false | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
return UtilSingleton |
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