Skip to content

Commit

Permalink
first merge (#1)
Browse files Browse the repository at this point in the history
* init gradle plugin

* Update README.md

* Add mirroring option
  • Loading branch information
ahai-code authored Mar 27, 2024
1 parent 594f8dc commit 896aa4d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./${{ env.REPO_NAME }}_${{ env.VERSION }}.zip
file: ./${{ env.REPO_NAME }}-${{ env.VERSION }}.zip
tag: v${{ env.VERSION }}
file_glob: true
- name: Publish manifest
Expand Down
20 changes: 7 additions & 13 deletions README.md
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
```
33 changes: 19 additions & 14 deletions hooks/available.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ local util = require("util")
--- @param ctx table Empty table used as context, for future extension
--- @return table Descriptions of available versions and accompanying tool descriptions
function PLUGIN:Available(ctx)
util:DoSomeThing()
local runtimeVersion = ctx.runtimeVersion
return {
{
version = "xxxx",
note = "LTS",
addition = {
{
name = "npm",
version = "8.8.8",
}
}
}
}
local resp, err = http.get({
url = util.AvailableVersionsUrl
})
if err ~= nil or resp.status_code ~= 200 then
error('get release info failed.')
end
local htmlBody = resp.body
local htmlContent= [[]] .. htmlBody .. [[]]

local result = {}

for version in htmlContent:gmatch('<a name="(.-)"></a>') do
table.insert(result, {version=version,note=""})
end
table.sort(result, function(a, b)
return util:compare_versions(a, b)
end)

return result
end
24 changes: 5 additions & 19 deletions hooks/env_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,16 @@
--- @field ctx.path string SDK installation directory
function PLUGIN:EnvKeys(ctx)
--- this variable is same as ctx.sdkInfo['plugin-name'].path
local mainPath = ctx.path
local runtimeVersion = ctx.runtimeVersion
local mainSdkInfo = ctx.main
local mpath = mainSdkInfo.path
local mversion = mainSdkInfo.version
local mname = mainSdkInfo.name
local sdkInfo = ctx.sdkInfo['sdk-name']
local path = sdkInfo.path
local version = sdkInfo.version
local name = sdkInfo.name
local path = ctx.path
return {
{
key = "JAVA_HOME",
value = mainPath
key = "GRADLE_HOME",
value = path
},
{
key = "PATH",
value = mainPath .. "/bin"
},
{
key = "PATH",
value = mainPath .. "/bin2"
},

value = path .. "/bin"
}
}

end
8 changes: 1 addition & 7 deletions hooks/post_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
--- such as file operations for the SDK installation directory or compile source code
--- Currently can be left unimplemented!
function PLUGIN:PostInstall(ctx)
--- ctx.rootPath SDK installation directory
local rootPath = ctx.rootPath
local runtimeVersion = ctx.runtimeVersion
local sdkInfo = ctx.sdkInfo['sdk-name']
local path = sdkInfo.path
local version = sdkInfo.version
local name = sdkInfo.name
--- DO-NOTHING
end
70 changes: 38 additions & 32 deletions hooks/pre_install.lua
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
24 changes: 1 addition & 23 deletions hooks/pre_use.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,5 @@
--- valid version information.
--- @param ctx table Context information
function PLUGIN:PreUse(ctx)
local runtimeVersion = ctx.runtimeVersion
--- user input version
local version = ctx.version
--- user current used version
local previousVersion = ctx.previousVersion

--- installed sdks
local sdkInfo = ctx.installedSdks['version']
local path = sdkInfo.path
local name = sdkInfo.name
local version = sdkInfo.version

--- working directory
local cwd = ctx.cwd

--- user input scope
--- could be one of global/project/session
local scope = ctx.scope

--- return the version information
return {
version = version,
}
--- DO-NOTHING
end
35 changes: 35 additions & 0 deletions lib/util.lua
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
12 changes: 6 additions & 6 deletions metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ PLUGIN = {}

--- !!! MUST BE SET !!!
--- Plugin name
PLUGIN.name = "your plugin name"
PLUGIN.name = "gradle"
--- Plugin author
PLUGIN.author = "your name"
PLUGIN.author = "ahai"
--- Plugin version
PLUGIN.version = "0.0.1"
PLUGIN.version = "0.1.0"
--- Plugin homepage
PLUGIN.homepage = "https://github.com/version-fox/vfox-plugin-template"
PLUGIN.homepage = "https://github.com/version-fox/vfox-gradle"
--- Plugin license, please choose a correct license according to your needs.
PLUGIN.license = "Apache 2.0"
--- Plugin description
PLUGIN.description = "your plugin description"
PLUGIN.description = "gradle"


--- !!! OPTIONAL !!!
Expand All @@ -35,7 +35,7 @@ NOTE:
you can set this address to the manifest file address, so that the plugin can be updated automatically.
--]]
PLUGIN.manifestUrl = "https://github.com/version-fox/vfox-plugin-template/releases/download/manifest/manifest.json"
PLUGIN.manifestUrl = "https://github.com/version-fox/vfox-gradle/releases/download/manifest/manifest.json"
-- Some things that need user to be attention!
PLUGIN.notes = {
"",
Expand Down

0 comments on commit 896aa4d

Please sign in to comment.