Skip to content

Commit

Permalink
修复版本信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jun 17, 2021
1 parent e23d0e0 commit 15b0dd8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,33 @@ Options:
在 Linux 上安装(需要 JRE 8 或更高版本):

```shell
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/Glavo/gchecksum/releases/download/0.3.0/gchecksum-0.3.0) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/Glavo/gchecksum/releases/download/0.4.0/gchecksum-0.4.0) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
```

中国大陆用户如果访问 GitHub 缓慢,可以使用 [FastGit](http://fastgit.org/) 加速:

```shell
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://hub.fastgit.org/Glavo/gchecksum/releases/download/0.3.0/gchecksum-0.3.0) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://hub.fastgit.org/Glavo/gchecksum/releases/download/0.4.0/gchecksum-0.4.0) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
```

(备选)安装 Native Image 版本(无需 JRE 环境):

```shell
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/Glavo/gchecksum/releases/download/0.3.0/gchecksum-0.3.0-native-image) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/Glavo/gchecksum/releases/download/0.4.0/gchecksum-0.4.0-native-image) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
```

使用 [FastGit](http://fastgit.org/) 镜像:

```shell
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://hub.fastgit.org/Glavo/gchecksum/releases/download/0.3.0/gchecksum-0.3.0-native-image) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://hub.fastgit.org/Glavo/gchecksum/releases/download/0.4.0/gchecksum-0.4.0-native-image) > /usr/local/bin/gchecksum && chmod +x /usr/local/bin/gchecksum'
```

### Windows

下载为 Windows 生成的 Native Image 镜像:

* [gchecksum-0.3.0-native-image.exe](https://github.com/Glavo/gchecksum/releases/download/0.3.0/gchecksum-0.3.0-native-image.exe)
* [gchecksum-0.3.0-native-image.exe](https://hub.fastgit.org/Glavo/gchecksum/releases/download/0.3.0/gchecksum-0.3.0-native-image.exe)(FastGit 镜像链接)
* [gchecksum-0.4.0-native-image.exe](https://github.com/Glavo/gchecksum/releases/download/0.4.0/gchecksum-0.4.0-native-image.exe)
* [gchecksum-0.4.0-native-image.exe](https://hub.fastgit.org/Glavo/gchecksum/releases/download/0.4.0/gchecksum-0.4.0-native-image.exe)(FastGit 镜像链接)

## 介绍

Expand Down
15 changes: 13 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "org.glavo"
version = "0.4.0" + "-SNAPSHOT"
version = "0.4.0" //+ "-SNAPSHOT"

val mainName = "org.glavo.checksum.Main"

Expand All @@ -19,6 +19,12 @@ tasks.compileJava {
options.encoding = "UTF-8"
}

val generateVersionInfo by tasks.registering {
val baseDir = file("$buildDir/version")
baseDir.mkdirs()
file("$baseDir/Version.txt").writeText(version.toString())
}

val executableJar by tasks.registering {
group = "build"

Expand Down Expand Up @@ -47,11 +53,16 @@ val nativeImageJar by tasks.registering(org.gradle.jvm.tasks.Jar::class) {
}

tasks.withType(org.gradle.jvm.tasks.Jar::class) {
dependsOn(generateVersionInfo)
manifest.attributes(
mapOf(
"Main-Class" to mainName
"Main-Class" to mainName,
"Program-Version" to project.version.toString()
)
)
into("org/glavo/checksum") {
from(file("$buildDir/version/Version.txt"))
}
}

val buildNativeImage by tasks.registering {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/glavo/checksum/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public static void main(String[] args) throws Exception {
}
numThreads = n;
break;
default:
Logger.logErrorAndExit(resources.getInvalidOptionMessage(), currentArg);
break;
}
}
//endregion
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/org/glavo/checksum/Resources.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.glavo.checksum;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Locale;
import java.util.jar.Manifest;

public final class Resources {
private static final String VERSION = "0.1.0";

private static final String HELP_MESSAGE_EN =
"Usage: \n" +
" gchecksum c(reate) [options] : Create checksums file\n" +
Expand Down Expand Up @@ -55,7 +58,8 @@ public final class Resources {
"error: file '%s' cannot be read",
"error: invalid hash record '%s'",
"error: path '%s' is a directory",
"error: hash value of file '%s'(%s) does not match the value in the record(%s)"
"error: hash value of file '%s'(%s) does not match the value in the record(%s)",
"error: invalid option: %s"
};

private static final String[] ERROR_TABLE_ZH = {
Expand All @@ -71,7 +75,8 @@ public final class Resources {
"错误:文件 '%s' 无法读取",
"错误:无效哈希记录 '%s'",
"错误:路径 '%s' 是一个目录",
"错误:文件 '%s' 的哈希值(%s)不匹配记录(%s)"
"错误:文件 '%s' 的哈希值(%s)不匹配记录(%s)",
"错误:无效参数:%s"
};

private static final String[] MESSAGE_TABLE_EN = {
Expand All @@ -88,7 +93,9 @@ public final class Resources {
final Locale locale = Locale.getDefault();


if ("zh".equals(locale.getLanguage()) || "CN".equals(locale.getCountry())) {
if ("zh".equals(locale.getLanguage())
|| "CN".equals(locale.getCountry())
|| "zh".equals(System.getProperty("user.language"))) {
INSTANCE = new Resources(HELP_MESSAGE_ZH, ERROR_TABLE_ZH, MESSAGE_TABLE_ZH);
} else {
INSTANCE = new Resources(HELP_MESSAGE_EN, ERROR_TABLE_EN, MESSAGE_TABLE_EN);
Expand All @@ -114,7 +121,14 @@ public final String getHelpMessage() {
}

public final String getVersionInformation() {
return VERSION;
//noinspection ConstantConditions
try (BufferedReader reader = new BufferedReader(new InputStreamReader(Resources.class.getResourceAsStream("Version.txt")))) {
return reader.readLine();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
return null;
}
}

public final String getUnknownModeMessage() {
Expand Down Expand Up @@ -169,6 +183,10 @@ public final String getHashNotMatchMessage() {
return errorTable[12];
}

public final String getInvalidOptionMessage() {
return errorTable[13];
}

public final String getVerificationCompletedMessage() {
return messageTable[0];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"resources":{
"includes":[{"pattern":"\\Qorg/glavo/checksum/Version.txt\\E"}]},
"bundles":[]
}

0 comments on commit 15b0dd8

Please sign in to comment.