mirror of
https://github.com/CarmJos/GithubReleases4J.git
synced 2026-06-04 21:18:16 +08:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e020c07749 | |||
| 6d688fb5c4 | |||
| 5096003228 | |||
| b60283a9c2 | |||
| 4cc891edc0 | |||
| 8bf0d98c00 | |||
| df72460044 | |||
| 81f621b0a6 | |||
| 6f8452bed8 | |||
| 3b787b8c0f | |||
| a6ab32a762 | |||
| 2cad1116b9 | |||
| 8445ac812d | |||
| c53ca18e96 | |||
| a3cb4bcb1a | |||
| 7eae212bc3 | |||
| dac264a09d | |||
| 63ae2f0025 | |||
| 91d3dab986 | |||
| 303dd703d6 | |||
| 6e3da70b48 | |||
| 50cddafd7a | |||
| b973167344 |
@@ -0,0 +1,9 @@
|
||||
# GithubReleases4J Javadoc
|
||||
|
||||
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://CarmJos.github.io/GithubReleases4J) 。
|
||||
|
||||
## 如何实现?
|
||||
|
||||
若您也想通过 [Github Actions](https://docs.github.com/en/actions/learn-github-actions)
|
||||
自动部署项目的Javadoc到 [Github Pages](https://pages.github.com/) ,
|
||||
可以参考我的文章 [《自动部署Javadoc到Github Pages》](https://pages.carm.cc/doc/javadoc-in-github.html) 。
|
||||
@@ -0,0 +1,41 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
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
|
||||
OK7d0W/LdJ3iFeselROADHgPQn14sg==
|
||||
=rRA5
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
@@ -1,7 +1,7 @@
|
||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Deploy & Upload
|
||||
name: "Deploy & Upload"
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
@@ -11,8 +11,8 @@ on:
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
gh-deploy:
|
||||
name: "Publish Project (GitHub)"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -26,14 +26,17 @@ jobs:
|
||||
server-id: github
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B deploy --file pom.xml -DskipTests
|
||||
- name: "Maven Deploy With Javadoc"
|
||||
run: mvn -B -Pgithub deploy --file pom.xml -DskipTests
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
- name: "Javadoc Deploy Staging"
|
||||
- name: "Copy Javadoc to Location"
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
@@ -44,10 +47,10 @@ jobs:
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||
base-url-path: https://carmjos.github.io/GithubReleases4J
|
||||
path-to-root: docs
|
||||
|
||||
- name: "Output Javadoc stats"
|
||||
- name: "Output stats"
|
||||
run: |
|
||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||
@@ -65,11 +68,11 @@ jobs:
|
||||
git config --global user.name 'CarmJos'
|
||||
git config --global user.email 'carm@carm.cc'
|
||||
|
||||
- name: "Commit Javadocs"
|
||||
- name: "Commit documentations"
|
||||
run: |
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:${{ github.repository }}.git
|
||||
git remote add origin git@github.com:CarmJos/GithubReleases4J.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
@@ -77,4 +80,29 @@ jobs:
|
||||
- name: "Push javadocs"
|
||||
run: |
|
||||
cd docs
|
||||
git push origin HEAD:gh-pages --force
|
||||
git push origin HEAD:gh-pages --force
|
||||
|
||||
central-deploy:
|
||||
name: "Deploy Project (Central)"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
server-id: ossrh
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_PASSWORD
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
|
||||
- name: "Central Deploy"
|
||||
run: mvn -B -Possrh deploy --file pom.xml -DskipTests
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
|
||||
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASS }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
@@ -1,7 +1,7 @@
|
||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Project Build & Tests
|
||||
name: Build & Tests
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
- name: "Package"
|
||||
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||
run: mvn --no-transfer-progress -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
|
||||
@@ -8,60 +8,73 @@
|
||||
|
||||
```
|
||||
|
||||
README LANGUAGES [ [ENGLISH](README_enUS.md) | [中文](README.md) ]
|
||||
README LANGUAGES [ [**ENGLISH**](README.md) | [中文](README_zh_CN.md) ]
|
||||
|
||||
# GithubReleases4J
|
||||
|
||||
[](https://github.com/CarmJos/GithubPM/releases)
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/GithubPM/actions/workflows/maven.yml)
|
||||

|
||||

|
||||
[](https://github.com/CarmJos/GithubReleases4J/releases)
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/GithubReleases4J/actions/workflows/maven.yml)
|
||||

|
||||

|
||||
|
||||
GitHub Releases for Java , 基于 [GitHub REST API](https://docs.github.com/cn/rest/reference/releases) 实现。
|
||||
GitHub Releases for Java , based on [GitHub REST API](https://docs.github.com/cn/rest/reference/releases) .
|
||||
|
||||
本项目对 GitHub Releases 相关的信息进行了封装,方便开发直接进行使用。
|
||||
To provide an easy way to fetch updates and download assets.
|
||||
|
||||
## 包含功能
|
||||
## Functions
|
||||
|
||||
- Release 的基本信息
|
||||
- Tag版本号、标题、内容介绍等
|
||||
- Release 的作者信息
|
||||
- ID 、头像、身份等
|
||||
- Release 的附件信息
|
||||
- 附件的名称、类型、大小、下载链接等
|
||||
- 支持直接对附件进行下载
|
||||
- Release Info
|
||||
- Tag Name
|
||||
- Release Name
|
||||
- Release Descriptions
|
||||
- ...
|
||||
- Release's Author Info
|
||||
- Login ID
|
||||
- AvatarURL
|
||||
- ...
|
||||
- Release's Assets Info
|
||||
- Name
|
||||
- Size
|
||||
- ...
|
||||
- Release's Assets Download
|
||||
- Update check methods. (See demo)
|
||||
|
||||
## 依赖方式
|
||||
## Dependency Usage
|
||||
|
||||
<details>
|
||||
<summary>展开查看 Maven 依赖方式</summary>
|
||||
<summary>Maven dependency</summary>
|
||||
|
||||
```xml
|
||||
|
||||
<project>
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||
<!--Using central repository-->
|
||||
<id>maven</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo1.maven.org/maven2</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!--Using github packages-->
|
||||
<id>GithubReleases4J</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/GithubReleases4J</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -70,15 +83,15 @@ GitHub Releases for Java , 基于 [GitHub REST API](https://docs.github.com/cn/r
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>展开查看 Gradle 依赖方式</summary>
|
||||
<summary>Gradle dependency</summary>
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||
|
||||
mavenCentral() // Using central repository.
|
||||
|
||||
// Using github packages.
|
||||
maven { url 'https://maven.pkg.github.com/CarmJos/GithubReleases4J' }
|
||||
|
||||
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -88,69 +101,10 @@ dependencies {
|
||||
|
||||
</details>
|
||||
|
||||
## 开发示例
|
||||
## DEMO Code
|
||||
|
||||
```java
|
||||
import cc.carm.lib.githubreleases4j.*;
|
||||
Please [click here](src/test/java/GithubDemo.java) to read the demo codes.
|
||||
|
||||
import java.io.IOException;
|
||||
## Open Source License.
|
||||
|
||||
public class demo {
|
||||
|
||||
public void onTest() {
|
||||
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases("作者名", "项目名");
|
||||
//获取Releases列表
|
||||
|
||||
GithubRelease latestRelease = GithubReleases4J.getLatestRelease(
|
||||
"作者名", "项目名",
|
||||
"Token" // 如果是私有项目,可以填写一个OAuth Token来获取信息和下载构件
|
||||
); // 获得最后一次的Release
|
||||
|
||||
if (lastRelease != null) {
|
||||
|
||||
List<GithubAsset> assets = latestRelease.getAssets();
|
||||
// 获取该 Release 的附件列表
|
||||
|
||||
for (GithubAsset asset : assets) {
|
||||
try {
|
||||
asset.download(null); // 以默认名称下载到当前目录
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
GithubUser author = latestRelease.getAuthor(); //获取该Release的作者
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
## 支持与捐赠
|
||||
|
||||
若您觉得本项目做的不错,您可以 [点击这里](https://donate.carm.cc) 捐赠支持我!
|
||||
|
||||
## 开源协议
|
||||
|
||||
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||
|
||||
<details>
|
||||
<summary>关于 GPL 协议</summary>
|
||||
|
||||
> GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利:
|
||||
>
|
||||
> #### 可自由复制
|
||||
> 你可以将软件复制到你的电脑,你客户的电脑,或者任何地方。复制份数没有任何限制。
|
||||
> #### 可自由分发
|
||||
> 在你的网站提供下载,拷贝到U盘送人,或者将源代码打印出来从窗户扔出去(环保起见,请别这样做)。
|
||||
> #### 可以用来盈利
|
||||
> 你可以在分发软件的时候收费,但你必须在收费前向你的客户提供该软件的 GNU GPL 许可协议,以便让他们知道,他们可以从别的渠道免费得到这份软件,以及你收费的理由。
|
||||
> #### 可自由修改
|
||||
> 如果你想添加或删除某个功能,没问题,如果你想在别的项目中使用部分代码,也没问题,唯一的要求是,使用了这段代码的项目也必须使用 GPL 协议。
|
||||
>
|
||||
> 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
||||
>
|
||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||
</details>
|
||||
The project using [The MIT License](https://opensource.org/licenses/MIT) .
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
```text
|
||||
_____ _ _ _ _ _____ _ _ _ _
|
||||
/ ____(_) | | | | | | __ \ | | | || | | |
|
||||
| | __ _| |_| |__ _ _| |__ | |__) |___| | ___ __ _ ___ ___ ___| || |_ | |
|
||||
| | |_ | | __| '_ \| | | | '_ \| _ // _ \ |/ _ \/ _` / __|/ _ \/ __|__ _| | |
|
||||
| |__| | | |_| | | | |_| | |_) | | \ \ __/ | __/ (_| \__ \ __/\__ \ | || |__| |
|
||||
\_____|_|\__|_| |_|\__,_|_.__/|_| \_\___|_|\___|\__,_|___/\___||___/ |_| \____/
|
||||
|
||||
```
|
||||
|
||||
README LANGUAGES [ [ENGLISH](README_enUS.md) | [中文](README) ]
|
||||
|
||||
# GithubReleases4J
|
||||
|
||||
[](https://github.com/CarmJos/GithubReleases4J/releases)
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/GithubReleases4J/actions/workflows/maven.yml)
|
||||

|
||||

|
||||

|
||||
|
||||
GitHub Releases for Java , based on [GitHub REST API](https://docs.github.com/cn/rest/reference/releases) .
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
```text
|
||||
_____ _ _ _ _ _____ _ _ _ _
|
||||
/ ____(_) | | | | | | __ \ | | | || | | |
|
||||
| | __ _| |_| |__ _ _| |__ | |__) |___| | ___ __ _ ___ ___ ___| || |_ | |
|
||||
| | |_ | | __| '_ \| | | | '_ \| _ // _ \ |/ _ \/ _` / __|/ _ \/ __|__ _| | |
|
||||
| |__| | | |_| | | | |_| | |_) | | \ \ __/ | __/ (_| \__ \ __/\__ \ | || |__| |
|
||||
\_____|_|\__|_| |_|\__,_|_.__/|_| \_\___|_|\___|\__,_|___/\___||___/ |_| \____/
|
||||
|
||||
```
|
||||
|
||||
README LANGUAGES [ [ENGLISH](README.md) | [**中文**](README_zh_CN.md) ]
|
||||
|
||||
# GithubReleases4J
|
||||
|
||||
[](https://github.com/CarmJos/GithubReleases4J/releases)
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/GithubReleases4J/actions/workflows/maven.yml)
|
||||

|
||||

|
||||
|
||||
GitHub Releases for Java , 基于 [GitHub REST API](https://docs.github.com/cn/rest/reference/releases) 实现。
|
||||
|
||||
本项目对 GitHub Releases 相关的信息进行了封装,方便开发直接进行使用。
|
||||
|
||||
## 包含功能
|
||||
|
||||
- Release 的基本信息
|
||||
- Tag版本号、标题、内容介绍等
|
||||
- Release 的作者信息
|
||||
- ID 、头像、身份等
|
||||
- Release 的附件信息
|
||||
- 附件的名称、类型、大小、下载链接等
|
||||
- 支持直接对附件进行下载
|
||||
|
||||
## 依赖方式
|
||||
|
||||
<details>
|
||||
<summary>展开查看 Maven 依赖方式</summary>
|
||||
|
||||
```xml
|
||||
|
||||
<project>
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<!--采用Maven中心库,安全稳定,但版本更新需要等待同步-->
|
||||
<id>maven</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo1.maven.org/maven2</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||
<id>GithubReleases4J</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/GithubReleases4J</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>展开查看 Gradle 依赖方式</summary>
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
|
||||
// 采用Maven中心库,安全稳定,但版本更新需要等待同步
|
||||
mavenCentral()
|
||||
|
||||
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||
maven { url 'https://maven.pkg.github.com/CarmJos/GithubReleases4J' }
|
||||
|
||||
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api "cc.carm.lib:githubreleases4j:[LATEST RELEASE]"
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## 开发示例
|
||||
|
||||
请 [**点击这里**](src/test/java/GithubDemoChinese.java) 查看示例代码,也可以 [点击这里](https://github.com/CarmJos/UltraDepository/blob/master/src/main/java/cc/carm/plugin/ultradepository/hooker/UpdateChecker.java) 查看实例项目。
|
||||
|
||||
## 支持与捐赠
|
||||
|
||||
若您觉得本项目做的不错,您可以 [点击这里](https://donate.carm.cc) 捐赠支持我!
|
||||
|
||||
## 开源协议
|
||||
|
||||
本项目源码采用 [The MIT License](https://opensource.org/licenses/MIT) 开源协议。
|
||||
|
||||
<details>
|
||||
<summary>关于 MIT 协议</summary>
|
||||
|
||||
> MIT 协议可能是几大开源协议中最宽松的一个,核心条款是:
|
||||
>
|
||||
> 该软件及其相关文档对所有人免费,可以任意处置,包括使用,复制,修改,合并,发表,分发,再授权,或者销售。唯一的限制是,软件中必须包含上述版 权和许可提示。
|
||||
>
|
||||
> 这意味着:
|
||||
> - 你可以自由使用,复制,修改,可以用于自己的项目。
|
||||
> - 可以免费分发或用来盈利。
|
||||
> - 唯一的限制是必须包含许可声明。
|
||||
>
|
||||
> MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。
|
||||
>
|
||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||
</details>
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.3.2</version>
|
||||
|
||||
<name>GithubReleases4J</name>
|
||||
<description>Github Releases for Java</description>
|
||||
@@ -53,11 +53,6 @@
|
||||
<name>Github Pages</name>
|
||||
<url>https://CarmJos.github.io/GithubReleases4J</url>
|
||||
</site>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/GithubReleases4J</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<scm>
|
||||
@@ -101,7 +96,7 @@
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20211205</version>
|
||||
<version>20230227</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -130,6 +125,26 @@
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
@@ -219,5 +234,35 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
|
||||
</project>
|
||||
<profile>
|
||||
<id>ossrh</id>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>github</id>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/GithubReleases4J</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@@ -18,59 +18,47 @@ import java.util.stream.Collectors;
|
||||
public class GitHubHttpUtils {
|
||||
|
||||
private GitHubHttpUtils() {
|
||||
// Should not be the instance or use by other codes.
|
||||
}
|
||||
|
||||
protected static JSONObject getObject(@NotNull String urlString, @Nullable String token) throws IOException {
|
||||
URL url = new URL(urlString);
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setRequestProperty("User-Agent", "GithubReleases4J");
|
||||
if (token != null) {
|
||||
conn.setRequestProperty("Authorization", "token " + token);
|
||||
}
|
||||
conn.setRequestProperty("Accept", "application/vnd.github.v3+json");
|
||||
conn.connect();
|
||||
|
||||
InputStream in = conn.getInputStream();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
String responseBody = reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
reader.close();
|
||||
return new JSONObject(responseBody);
|
||||
}
|
||||
|
||||
protected static JSONArray getArray(@NotNull String urlString, String token) throws IOException {
|
||||
URL url = new URL(urlString);
|
||||
private static URLConnection createConnection(@NotNull String httpURL, @Nullable String token) throws IOException {
|
||||
URL url = new URL(httpURL);
|
||||
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setRequestProperty("User-Agent", "GithubReleases4J");
|
||||
if (token != null) {
|
||||
conn.setRequestProperty("Authorization", "token " + token);
|
||||
}
|
||||
conn.setRequestProperty("Accept", "application/vnd.github.v3+json");
|
||||
conn.connect();
|
||||
|
||||
InputStream in = conn.getInputStream();
|
||||
if (token != null) conn.setRequestProperty("Authorization", "token " + token);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
String responseBody = reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
reader.close();
|
||||
|
||||
return new JSONArray(responseBody);
|
||||
return conn;
|
||||
}
|
||||
|
||||
protected static File download(@NotNull String urlString, @Nullable String token,
|
||||
private static String getResponse(@NotNull String httpURL, @Nullable String token) throws IOException {
|
||||
URLConnection connection = createConnection(httpURL, token);
|
||||
InputStream in = connection.getInputStream();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
String response = reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
reader.close();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
protected static JSONObject getObject(@NotNull String httpURL, @Nullable String token) throws IOException {
|
||||
return new JSONObject(getResponse(httpURL, token));
|
||||
}
|
||||
|
||||
protected static JSONArray getArray(@NotNull String httpURL, String token) throws IOException {
|
||||
return new JSONArray(getResponse(httpURL, token));
|
||||
}
|
||||
|
||||
protected static File download(@NotNull String httpURL, @Nullable String token,
|
||||
@NotNull String path, CopyOption... copyOptions) throws IOException {
|
||||
URL url = new URL(urlString);
|
||||
Path target = Paths.get(path);
|
||||
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setRequestProperty("User-Agent", "GithubReleases4J");
|
||||
if (token != null) {
|
||||
conn.setRequestProperty("Authorization", "token " + token);
|
||||
}
|
||||
conn.setRequestProperty("Accept", "application/vnd.github.v3+json");
|
||||
|
||||
InputStream in = conn.getInputStream();
|
||||
URLConnection connection = createConnection(httpURL, token);
|
||||
InputStream in = connection.getInputStream();
|
||||
|
||||
Files.copy(in, target, copyOptions);
|
||||
in.close();
|
||||
|
||||
@@ -81,15 +81,34 @@ public class GithubAsset {
|
||||
return GithubReleases4J.parseDate(getContents().getString("updated_at"));
|
||||
}
|
||||
|
||||
public File download() throws IOException {
|
||||
return download(null);
|
||||
/**
|
||||
* Download this asset to current path with original name.
|
||||
*
|
||||
* @param options Copy options e.g. {@link java.nio.file.StandardCopyOption}
|
||||
* @return Downloaded file.
|
||||
* @throws IOException Throws when has any io exception
|
||||
*/
|
||||
public File download(@NotNull CopyOption... options) throws IOException {
|
||||
return GitHubHttpUtils.download(getBrowserDownloadURL(), getSource().getAuthToken(), getName(), options);
|
||||
}
|
||||
|
||||
public File download(@Nullable String path, CopyOption... options) throws IOException {
|
||||
path = path == null ? getName() : path;
|
||||
/**
|
||||
* Download this asset with provided path and name.
|
||||
*
|
||||
* @param path target path with file suffix , e.g. "cache/build.zip"
|
||||
* @param options Copy options e.g. {@link java.nio.file.StandardCopyOption}
|
||||
* @return Downloaded file.
|
||||
* @throws IOException Throws when has any io exception
|
||||
*/
|
||||
public File download(@NotNull String path, @NotNull CopyOption... options) throws IOException {
|
||||
return GitHubHttpUtils.download(getBrowserDownloadURL(), getSource().getAuthToken(), path, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the uploader of this asset.
|
||||
*
|
||||
* @return The author user {@link GithubUser}
|
||||
*/
|
||||
public GithubUser getUploader() {
|
||||
return Optional.ofNullable(getContents().getJSONObject("uploader"))
|
||||
.map(GithubUser::of)
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -130,13 +129,21 @@ public class GithubRelease {
|
||||
return getContents().getString("discussion_url");
|
||||
}
|
||||
|
||||
public GithubUser getAuthor() {
|
||||
return Optional.ofNullable(getContents().getJSONObject("author"))
|
||||
.map(GithubUser::of)
|
||||
.orElse(null);
|
||||
/**
|
||||
* Get the author of this release.
|
||||
*
|
||||
* @return The author user {@link GithubUser}
|
||||
*/
|
||||
public @NotNull GithubUser getAuthor() {
|
||||
return GithubUser.of(getContents().getJSONObject("author"));
|
||||
}
|
||||
|
||||
public List<GithubAsset> getAssets() {
|
||||
/**
|
||||
* Get the assets of this release.
|
||||
*
|
||||
* @return {@link GithubAsset}
|
||||
*/
|
||||
public @NotNull List<GithubAsset> getAssets() {
|
||||
JSONArray assetsArray = getContents().getJSONArray("assets");
|
||||
if (assetsArray == null) return new ArrayList<>();
|
||||
return IntStream.range(0, assetsArray.length())
|
||||
|
||||
@@ -14,14 +14,32 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* GitHub Releases for Java
|
||||
* <br>To provide an easy way to fetch updates and download assets.
|
||||
* <br>Based on <a href="https://docs.github.com/cn/rest/reference/releases">GitHub REST API (Releases)</a> .
|
||||
*
|
||||
* @author CarmJos
|
||||
*/
|
||||
public class GithubReleases4J {
|
||||
|
||||
private GithubReleases4J() {
|
||||
// Should not be the instance.
|
||||
}
|
||||
|
||||
public static String GITHUB_URL = "https://github.com";
|
||||
public static String GITHUB_API_URL = "https://api.github.com";
|
||||
public static SimpleDateFormat GH_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
|
||||
/**
|
||||
* List repository's current existing releases.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param token OAuth Access Token
|
||||
* <br> Necessary when this repository is private.
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @NotNull List<GithubRelease> listReleases(@NotNull String owner, @NotNull String repository,
|
||||
@Nullable String token) {
|
||||
try {
|
||||
@@ -38,10 +56,28 @@ public class GithubReleases4J {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List a public repository's current existing releases.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @NotNull List<GithubRelease> listReleases(@NotNull String owner, @NotNull String repository) {
|
||||
return listReleases(owner, repository, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a repository's release by the id .
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param releaseID Release ID
|
||||
* @param token OAuth Access Token
|
||||
* <br> Necessary when this repository is private.
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @Nullable GithubRelease getRelease(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String releaseID, @Nullable String token) {
|
||||
|
||||
@@ -57,31 +93,130 @@ public class GithubReleases4J {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a public repository's release by the id .
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param releaseID Release ID
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @Nullable GithubRelease getRelease(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String releaseID) {
|
||||
return getRelease(owner, repository, releaseID, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a repository's release by the tag name .
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param tagName Release Tag Name
|
||||
* @param token OAuth Access Token
|
||||
* <br> Necessary when this repository is private.
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @Nullable GithubRelease getReleaseByTag(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String tagName, @Nullable String token) {
|
||||
return getRelease(owner, repository, "tags/" + tagName, token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a public repository's release by the tag name .
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param tagName Release Tag Name
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @Nullable GithubRelease getReleaseByTag(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String tagName) {
|
||||
return getReleaseByTag(owner, repository, tagName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a repository's latest release.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param token OAuth Access Token
|
||||
* <br> Necessary when this repository is private.
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @Nullable GithubRelease getLatestRelease(@NotNull String owner, @NotNull String repository,
|
||||
@Nullable String token) {
|
||||
return getRelease(owner, repository, "latest", token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a public repository's latest release.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @return {@link GithubRelease}
|
||||
*/
|
||||
public static @Nullable GithubRelease getLatestRelease(@NotNull String owner, @NotNull String repository) {
|
||||
return getLatestRelease(owner, repository, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many versions behind the current version's tag name.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param token OAuth Access Token
|
||||
* <br> Necessary when this repository is private.
|
||||
* @param currentTagName Current Version's tag name.
|
||||
* @return NULL if not fetch releases, -1 if no match tag name.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static @Nullable Integer getVersionBehind(@NotNull String owner, @NotNull String repository,
|
||||
@Nullable String token, @NotNull String currentTagName) {
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases(owner, repository, token);
|
||||
if (releases.isEmpty()) return null; // Could not fetch releases.
|
||||
|
||||
int i = 0;
|
||||
for (GithubRelease release : releases) {
|
||||
if (release.getTagName().equalsIgnoreCase(currentTagName)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == releases.size()) return -1; // No match tag name;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many versions behind the current version's tag name.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param currentTagName Current Version's tag name.
|
||||
* @return NULL if not fetch releases, -1 if no match tag name.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static @Nullable Integer getVersionBehind(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String currentTagName) {
|
||||
return getVersionBehind(owner, repository, null, currentTagName);
|
||||
}
|
||||
|
||||
public static @NotNull String getReleasesURL(@NotNull String owner, @NotNull String repository) {
|
||||
return buildURL("%s/%s/%s/releases", GITHUB_URL, owner, repository);
|
||||
}
|
||||
|
||||
public static @NotNull String getLatestReleaseURL(@NotNull String owner, @NotNull String repository) {
|
||||
return getReleasesURL(owner, repository) + "/latest";
|
||||
}
|
||||
|
||||
public static @NotNull String getReleaseURLByTag(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String releaseTagName) {
|
||||
return getReleasesURL(owner, repository) + "/tag/" + releaseTagName;
|
||||
}
|
||||
|
||||
private static String buildURL(@NotNull String url, Object... params) {
|
||||
return String.format(url, params);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import cc.carm.lib.githubreleases4j.GithubAsset;
|
||||
import cc.carm.lib.githubreleases4j.GithubRelease;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.lib.githubreleases4j.GithubUser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class GithubDemo {
|
||||
|
||||
public void demo() {
|
||||
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases("Owner", "RepoName");
|
||||
// List a public repository's current existing releases.
|
||||
|
||||
GithubRelease latestRelease = GithubReleases4J.getLatestRelease(
|
||||
"Owner", "RepoName",
|
||||
"Token" // OAuth token if it is a private repository.
|
||||
); // Get the latest release of the repository
|
||||
|
||||
if (latestRelease != null) {
|
||||
|
||||
List<GithubAsset> assets = latestRelease.getAssets();
|
||||
// Get the Release' assets list
|
||||
|
||||
for (GithubAsset asset : assets) {
|
||||
try {
|
||||
asset.download(); // Download by the original file name.
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
GithubUser uploader = asset.getUploader(); // Get the uploader of this asset.
|
||||
|
||||
}
|
||||
|
||||
GithubUser author = latestRelease.getAuthor(); // Get the author of this release.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
|
||||
String owner = "Owner";
|
||||
String repository = "RepoName";
|
||||
|
||||
Integer behindVersions = GithubReleases4J.getVersionBehind(
|
||||
owner, repository,
|
||||
"Token",// OAuth token if it is a private repository.
|
||||
"Current Version Tag"
|
||||
);
|
||||
|
||||
if (behindVersions == null) {
|
||||
System.out.println("Check failed! Please check updates manually.");
|
||||
System.out.println("Download at " + GithubReleases4J.getReleasesURL(owner, repository));
|
||||
} else if (behindVersions == 0) {
|
||||
System.out.println("Check successfully, Now is up-to-date.");
|
||||
} else if (behindVersions > 0) {
|
||||
System.out.println("Outdated! Now behind " + behindVersions + " versions.");
|
||||
System.out.println("Download latest version at " + GithubReleases4J.getLatestReleaseURL(owner, repository));
|
||||
} else {
|
||||
System.out.println("Check failed! Current version doesn't exists.");
|
||||
System.out.println("Please use original version to avoid security issues.");
|
||||
System.out.println("Download latest version at " + GithubReleases4J.getLatestReleaseURL(owner, repository));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import cc.carm.lib.githubreleases4j.GithubAsset;
|
||||
import cc.carm.lib.githubreleases4j.GithubRelease;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.lib.githubreleases4j.GithubUser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class GithubDemoChinese {
|
||||
|
||||
public void demo() {
|
||||
|
||||
String owner = "库主(用户名或组织名)";
|
||||
String repository = "库名";
|
||||
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases("Owner", "RepoName");
|
||||
// 列出项目中所有发行版
|
||||
|
||||
GithubRelease latestRelease = GithubReleases4J.getLatestRelease(
|
||||
owner, repository, "Token" // 如果是私有项目 则需要输入OAuth token
|
||||
); // 得到该库的最新发行
|
||||
|
||||
if (latestRelease != null) {
|
||||
|
||||
List<GithubAsset> assets = latestRelease.getAssets();
|
||||
// 得到该发行下的所有附件
|
||||
|
||||
for (GithubAsset asset : assets) {
|
||||
try {
|
||||
asset.download(); // 使用原附件名直接下载
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
GithubUser uploader = asset.getUploader(); // 得到附件的上传者
|
||||
|
||||
}
|
||||
|
||||
GithubUser author = latestRelease.getAuthor(); // 得到该发行的发布者
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
|
||||
String owner = "库主(用户名或组织名)";
|
||||
String repository = "库名";
|
||||
String version = "当前版本的 TagName";
|
||||
|
||||
Integer behindVersions = GithubReleases4J.getVersionBehind(
|
||||
owner, repository, "Token",// 如果是私有项目 则需要输入OAuth token
|
||||
version
|
||||
);
|
||||
|
||||
if (behindVersions == null) {
|
||||
System.out.println("检查更新失败! 请您手动检查版本更新。");
|
||||
System.out.println("下载地址 " + GithubReleases4J.getReleasesURL(owner, repository));
|
||||
} else if (behindVersions == 0) {
|
||||
System.out.println("检查完成,当前已是最新版本。");
|
||||
} else if (behindVersions > 0) {
|
||||
System.out.println("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
|
||||
System.out.println("最新版下载地址 " + GithubReleases4J.getLatestReleaseURL(owner, repository));
|
||||
} else {
|
||||
System.out.println("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
|
||||
System.out.println("最新版下载地址 " + GithubReleases4J.getLatestReleaseURL(owner, repository));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,7 +18,7 @@ public class GithubReleasesTest {
|
||||
@Test
|
||||
public void onTest() {
|
||||
|
||||
GithubReleases4J.listReleases("CarmJos", "EasyPlugin")
|
||||
GithubReleases4J.listReleases("CarmJos", "GithubReleases4J")
|
||||
.stream().limit(2).forEach(GithubReleasesTest::printInfo);
|
||||
|
||||
GithubRelease release = GithubReleases4J.getLatestRelease("CarmJos", "UltraDepository");
|
||||
@@ -31,16 +32,18 @@ public class GithubReleasesTest {
|
||||
private static void printInfo(@Nullable GithubRelease release) {
|
||||
if (release == null) System.out.println("# NULL");
|
||||
else {
|
||||
System.out.println("# " + release.getName() + " [" + FORMAT.format(release.getCreateTime()) + "]");
|
||||
print("# %s %s [%s] ",
|
||||
release.getRepository(), release.getName(),
|
||||
FORMAT.format(release.getCreateTime())
|
||||
);
|
||||
List<GithubAsset> assets = release.getAssets();
|
||||
assets.forEach(GithubReleasesTest::printAssets);
|
||||
}
|
||||
}
|
||||
|
||||
private static void printAssets(@Nullable GithubAsset assets) {
|
||||
if (assets == null) System.out.println("- NULL");
|
||||
else {
|
||||
System.out.println("- " + assets.getName() + " [" + assets.getSize() + "]");
|
||||
if (assets != null) {
|
||||
print("- %s (%s B)", assets.getName(), assets.getSize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +51,16 @@ public class GithubReleasesTest {
|
||||
if (!DOWNLOAD) return;
|
||||
if (assets == null) return;
|
||||
try {
|
||||
File file = assets.download(null);
|
||||
System.out.println("- at " + file.getAbsolutePath());
|
||||
File file = assets.download(StandardCopyOption.REPLACE_EXISTING);
|
||||
System.out.println("| -> " + file.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void print(String format, Object... params) {
|
||||
System.out.printf((format) + "%n", params);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class GithubUserTestTest {
|
||||
public class GithubUserInfoTest {
|
||||
|
||||
public static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GithubVersionCheckerTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "UltraDepository", "1.3.4"));
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "UltraDepository", "v1.2.0"));
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "UltraDepository", "TEST"));
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "NULL", "TEST"));
|
||||
|
||||
System.out.println("Download at " + GithubReleases4J.getReleaseURLByTag("CarmJos", "UltraDepository", "1.3.4"));
|
||||
System.out.println("Download at " + GithubReleases4J.getLatestReleaseURL("CarmJos", "UltraDepository"));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user