添加获取当前版本的命令,gradle更新,maven打包发布支持

This commit is contained in:
A.C.Sukazyo Eyre 2021-11-26 14:09:40 +08:00
parent 14d3f76ac1
commit c715287fb7
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
6 changed files with 121 additions and 15 deletions

View File

@ -1,18 +1,15 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0'
}
}
plugins {
id 'java'
id 'maven-publish'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.0'
}
group 'cc.sukazyo'
version '0.2.0'
version '0.3.0'
project.ext.archiveBaseName = 'Coeur_Morny_Cono'
project.ext.artifactId = 'morny-coeur'
mainClassName = 'cc.sukazyo.cono.morny.MornyCoeur'
repositories {
mavenCentral()
@ -31,6 +28,10 @@ test {
useJUnitPlatform()
}
java {
withSourcesJar()
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
@ -49,7 +50,38 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
shadowJar {
mainClassName = 'cc.sukazyo.cono.morny.MornyCoeur'
archiveBaseName.set("Morny_Coeur")
archiveVersion.set(version)
archiveBaseName.set("${project.ext.archiveBaseName}")
archiveVersion.set("${project.version}")
archiveClassifier.set("fat")
}
shadowJar {
archiveBaseName.set("${project.ext.archiveBaseName}")
archiveVersion.set("${project.version}")
archiveClassifier.set("fat")
}
publishing {
repositories{
maven {
name 'builds'
url = "file://" + new File("./build/publishing").getAbsolutePath()
}
maven {
name '-ws-'
url publishMvnRepoUrl
credentials {
username publishMvnRepoUsername
password publishMvnRepoPassword
}
}
}
publications {
main (MavenPublication) {
from components.java
groupId = project.group
artifactId = project.ext.artifactId
version = project.version
}
}
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -0,0 +1,20 @@
package cc.sukazyo.cono.morny;
import cc.sukazyo.cono.morny.util.FileUtils;
import java.net.URISyntaxException;
public class MornySystem {
public static final String VERSION = "0.3.0";
public static String getJarMd5() {
try {
return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
} catch (URISyntaxException e) {
e.printStackTrace(System.out);
return e.getMessage();
}
}
}

View File

@ -1,9 +1,12 @@
package cc.sukazyo.cono.morny.bot.event;
import cc.sukazyo.cono.morny.MornyCoeur;
import cc.sukazyo.cono.morny.MornySystem;
import cc.sukazyo.cono.morny.MornyTrusted;
import cc.sukazyo.cono.morny.bot.api.EventListener;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.model.request.ParseMode;
import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.request.SendSticker;
import static cc.sukazyo.cono.morny.Logger.logger;
@ -35,6 +38,10 @@ public class OnCommandExecute extends EventListener {
case "/exit@" + MornyCoeur.USERNAME:
onCommandExitExec(event);
break;
case "/version":
case "/version@" + MornyCoeur.USERNAME:
onCommandVersionExec(event);
break;
default:
return false;
}
@ -76,4 +83,18 @@ public class OnCommandExecute extends EventListener {
}
}
private void onCommandVersionExec (Update event) {
MornyCoeur.getAccount().execute(new SendMessage(
event.message().chat().id(),
String.format(
"version:\n" +
"\t<code>%s</code>\n" +
"core md5_hash:\n" +
"\t<code>%s</code>",
MornySystem.VERSION,
MornySystem.getJarMd5()
)
).parseMode(ParseMode.HTML));
}
}

View File

@ -0,0 +1,33 @@
package cc.sukazyo.cono.morny.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class FileUtils {
public static String getMD5Three (String path) {
BigInteger bi;
try {
byte[] buffer = new byte[8192];
int len;
MessageDigest md = MessageDigest.getInstance("MD5");
File f = new File(path);
FileInputStream fis = new FileInputStream(f);
while ((len = fis.read(buffer)) != -1) {
md.update(buffer, 0, len);
}
fis.close();
byte[] b = md.digest();
bi = new BigInteger(1, b);
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace(System.out);
return e.getMessage();
}
return bi.toString(16);
}
}