diff --git a/.gitignore b/.gitignore index f02e4e8..f50dcce 100644 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,15 @@ .vscode/ .gradle/ .settings/ +.metals/ +.bloop/ +.bsp/ #build /build/ /bin/ /out/ -.metals/ -.bloop/ -.project +/target lcoal.properties # debug dir diff --git a/Dockerfile b/Dockerfile index 055ebfc..ba89e49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,19 @@ -FROM eclipse-temurin:20-jdk as build +FROM sbtscala/scala-sbt:eclipse-temurin-jammy-21.0.1_12_1.9.7_3.3.1 as build LABEL authors="A.C.Sukazyo Eyre" COPY . /app/source/ WORKDIR /app +ARG DOCKER_BUILD=yes RUN cd ./source \ -&& ./gradlew shadowJar -PdockerBuild \ +&& sbt assembly \ && cd .. \ -&& cp ./source/build/libs/morny-coeur-docker-build.jar ./morny-coeur.jar +&& cp ./source/target/morny-coeur-docker-build.jar ./morny-coeur.jar #&& rm -r ./source \ #&& rm -r /root/.gradle \ -FROM eclipse-temurin:20-jre +FROM eclipse-temurin:21-jre COPY --from=build /app/morny-coeur.jar /app/morny-coeur.jar WORKDIR /app diff --git a/build.gradle b/build.gradle deleted file mode 100644 index a436ee8..0000000 --- a/build.gradle +++ /dev/null @@ -1,249 +0,0 @@ -plugins { - id 'scala' - id 'java-library' - id 'application' - id 'maven-publish' - id "io.github.ysohda.scalatest" version "0.32.1" - id 'com.github.johnrengelman.shadow' version '8.1.1' - id 'com.github.gmazzo.buildconfig' version '4.1.2' - id 'org.ajoberstar.grgit' version '5.2.0' -} - -import org.ajoberstar.grgit.Status - -import java.nio.charset.Charset -import java.nio.charset.StandardCharsets - -final boolean proj_git = grgit != null -final String proj_store = MORNY_CODE_STORE -final String proj_commit = proj_git ? grgit.head().id : null -final String proj_commit_path = MORNY_COMMIT_PATH -final boolean proj_clean = isCleanBuild() -if (!proj_git) - println "[MornyBuild] git repository not available for current working space! git version tag will be disabled." -else if (isCleanBuild()) { - println "git: clean build at ${grgit.head().id}" -} -else { - final Status status = grgit.status() - println "git: non-clean-build" - if (!status.unstaged.allChanges.empty) { - println "git: unstaged changes" - listChanges(status.unstaged) - } - if (!status.staged.allChanges.empty) { - println "git: staged changes" - listChanges(status.staged) - } -} - -final String proj_group = 'cc.sukazyo' -final String proj_package = "${proj_group}.cono.morny" -final String proj_archive_name = MORNY_ARCHIVE_NAME -final String proj_application_main = "${proj_package}.ServerMain" - -final String proj_version_base = VERSION -final String proj_version_delta = VERSION_DELTA -final boolean proj_version_use_delta = Boolean.parseBoolean(USE_DELTA) -final String proj_version = proj_version_base + (proj_version_use_delta ? "-δ${proj_version_delta}" : "") -final String proj_version_full = proj_version + (proj_git ? - "+git.${proj_commit.substring(0, 8)}" + (proj_clean ? "" : ".δ") : "") -final String proj_version_codename = CODENAME -final long proj_code_time = proj_clean ? grgit.head().dateTime.toInstant().toEpochMilli() : System.currentTimeMillis() - -final JavaVersion proj_java = JavaVersion.VERSION_17 -final Charset proj_file_encoding = StandardCharsets.UTF_8 -final proj_scala_api = 3 -//final proj_scala_lib = proj_scala_api+'.4.0-RC1-bin-20230901-89e8dba-NIGHTLY' -final proj_scala_lib = proj_scala_api + '.3.1' -String publish_local_url = null -String publish_remote_url = null -String publish_remote_username = null -String publish_remote_password = null -if (project.hasProperty("publishLocalArchiveRepoUrl")) publish_local_url = publishLocalArchiveRepoUrl -if (project.hasProperty("publishMvnRepoUrl")) { - publish_remote_url = publishMvnRepoUrl - publish_remote_username = publishMvnRepoUsername - publish_remote_password = publishMvnRepoPassword -} - -group proj_group -version proj_version_full - -repositories { - mavenCentral() - maven { name '-ws'; url 'https://mvn.sukazyo.cc/releases' } -} - -dependencies { - - api group: 'org.scala-lang', name: 'scala3-library_3', version: proj_scala_lib - final scala = (String name) -> "${name}_$proj_scala_api" - compileOnlyApi group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: lib_spotbugs_v - - implementation group: 'cc.sukazyo', name: 'messiva', version: lib_messiva_v - implementation group: 'cc.sukazyo', name: 'resource-tools', version: lib_resourcetools_v - - implementation group: 'com.github.pengrad', name: 'java-telegram-bot-api', version: lib_javatelegramapi_v - implementation group: 'com.softwaremill.sttp.client3', name: scala('core'), version: lib_sttp_v - implementation group: 'com.softwaremill.sttp.client3', name: scala('okhttp-backend'), version: lib_sttp_v - runtimeOnly group: 'com.squareup.okhttp3', name: 'okhttp', version: lib_okhttp_v - implementation group: 'com.google.code.gson', name: 'gson', version: lib_gson_v - implementation group: 'io.circe', name: scala('circe-core'), version: lib_circe_v - implementation group: 'io.circe', name: scala('circe-generic'), version: lib_circe_v - implementation group: 'io.circe', name: scala('circe-parser'), version: lib_circe_v - implementation group: 'org.jsoup', name: 'jsoup', version: '1.16.2' - implementation group: 'com.cronutils', name: 'cron-utils', version: lib_cron_utils_v - - // used for disable slf4j - // due to the slf4j api have been used in the following libraries: - // - cron-utils - runtimeOnly group: 'org.slf4j', name: 'slf4j-nop', version: lib_slf4j_v - testRuntimeOnly group: 'org.slf4j', name: 'slf4j-nop', version: lib_slf4j_v - - testImplementation group: 'cc.sukazyo', name: 'resource-tools', version: lib_resourcetools_v - testImplementation group: 'org.scalatest', name: scala('scalatest'), version: lib_scalatest_v - testImplementation group: 'org.scalatest', name: scala('scalatest-freespec'), version: lib_scalatest_v - testRuntimeOnly group: 'org.scala-lang.modules', name: scala('scala-xml'), version: lib_scalamodule_xml_v - // for generating HTML report: required by gradle-scalatest plugin - testRuntimeOnly group: 'com.vladsch.flexmark', name: 'flexmark-all', version: '0.64.6' - -} - -java { - withSourcesJar() -} - -sourceSets { - - main { - java { destinationDirectory.set file("build/classes/main") } - scala { destinationDirectory.set file("build/classes/main") } - } - - test { - java { destinationDirectory.set file("build/classes/test") } - scala { destinationDirectory.set file("build/classes/test") } - } - -} - -tasks.withType(JavaCompile).configureEach { - - sourceCompatibility proj_java.getMajorVersion() - targetCompatibility proj_java.getMajorVersion() - - options.encoding = proj_file_encoding.name() - -} - -tasks.withType(ScalaCompile).configureEach { - - sourceCompatibility proj_java.getMajorVersion() - targetCompatibility proj_java.getMajorVersion() - - scalaCompileOptions.additionalParameters.add "-language:postfixOps" - scalaCompileOptions.additionalParameters.addAll ("-Xmax-inlines", "256") - - scalaCompileOptions.encoding = proj_file_encoding.name() - options.encoding = proj_file_encoding.name() - -} - -tasks.withType(Javadoc).configureEach { - options.encoding = proj_file_encoding.name() -} - -//tasks.withType(ScalaDoc).configureEach { -//} - -test { -} - -application { - mainClass = proj_application_main -} - -buildConfig { - - packageName(proj_package) - - buildConfigField('String', 'VERSION', "\"${proj_version}\"") - buildConfigField('String', 'VERSION_FULL', "\"${proj_version_full}\"") - buildConfigField('String', 'VERSION_BASE', "\"${proj_version_base}\"") - buildConfigField('String', 'VERSION_DELTA', proj_version_use_delta ? "\"${proj_version_delta}\"" : "null") - buildConfigField('String', 'CODENAME', "\"${proj_version_codename}\"") - buildConfigField('long', 'CODE_TIMESTAMP', "${proj_code_time}L") - buildConfigField('String', 'COMMIT', proj_git ? "\"${proj_commit}\"" : "null") - buildConfigField('boolean', 'CLEAN_BUILD', "${proj_clean}") - buildConfigField('String', 'CODE_STORE', proj_store == "" ? "null" : "\"${proj_store}\"") - buildConfigField('String', 'COMMIT_PATH', proj_commit_path == "" ? "null" : "\"${proj_commit_path}\"") - -} - -tasks.withType(Jar).configureEach { - archiveBaseName.set proj_archive_name -} - -shadowJar { - - archiveClassifier.set "fat" - - if (project.hasProperty("dockerBuild")) { - println "shadow-jar: using docker build name" - archiveVersion.set "" - archiveClassifier.set "docker-build" - } - -} - -@SuppressWarnings('GrMethodMayBeStatic') -boolean isCleanBuild () { - if (grgit == null) return false - Set changes = grgit.status().unstaged.allChanges + grgit.status().staged.allChanges - for (String file in changes) { - if (file.startsWith("src/")) return false - if (file == "build.gradle") return false - if (file == "gradle.properties") return false - } - return true -} - -void listChanges (Status.Changes listing) { - for (String file in listing.added) - println " add: ${file}" - for (String file in listing.modified) - println " mod: ${file}" - for (String file in listing.removed) - println " del: ${file}" -} - -publishing { - repositories { - if (publish_local_url != null) maven { - name 'archives' - url publish_local_url - } - if (publish_remote_url != null) maven { - name '-ws-' - url publish_remote_url - credentials { - username publish_remote_username - password publish_remote_password - } - } - } - publications { - //noinspection GroovyAssignabilityCheck - main(MavenPublication) { - //noinspection GroovyAssignabilityCheck - from components.java - //noinspection GroovyAssignabilityCheck - groupId = proj_group - //noinspection GroovyAssignabilityCheck - artifactId = proj_archive_name - //noinspection GroovyAssignabilityCheck - version = proj_version - } - } -} diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..654d5ba --- /dev/null +++ b/build.sbt @@ -0,0 +1,78 @@ +ThisBuild / organization := "cc.sukazyo" +ThisBuild / organizationName := "A.C. Sukazyo Eyre" + +ThisBuild / scalaVersion := "3.3.1" + +resolvers ++= Seq( + "-ws-releases" at "https://mvn.sukazyo.cc/releases" +) + +lazy val root = (project in file(".")) + .enablePlugins(BuildInfoPlugin) + .settings( + + name := "Coeur Morny Cono", + version := MornyProject.version, + + crossPaths := false, + moduleName := MornyProject.app_archive_name, + Compile / packageDoc / publishArtifact := false, + artifactName := {(sv: ScalaVersion, module: ModuleID, artifact: Artifact) => + val classifier = artifact.classifier match { + case Some(value) => s"-$value" + case None => "" + } + s"${module.name}-${MornyProject.version_full}$classifier.${artifact.extension}" + }, + + Compile / mainClass := Some(MornyProject.app_application_main), + + libraryDependencies ++= MornyProject.dependencies, + + buildInfoPackage := MornyProject.app_package, + buildInfoObject := "BuildConfig", + buildInfoKeys ++= Seq( + BuildInfoKey[String]("VERSION", MornyProject.version), + BuildInfoKey[String]("VERSION_FULL", MornyProject.version_full), + BuildInfoKey[String]("VERSION_BASE", MornyProject.version_base), + BuildInfoKey[Option[String]]("VERSION_DELTA", MornyProject.version_delta), + BuildInfoKey[String]("CODENAME", MornyProject.version_codename), + BuildInfoKey.action[Long]("CODE_TIMESTAMP") { MornyProject.code_time }, + BuildInfoKey.action[String]("COMMIT") { MornyProject.git_commit }, + BuildInfoKey.action[Boolean]("CLEAN_BUILD") { MornyProject.git_is_clean }, + BuildInfoKey[String]("CODE_STORE", MornyProject.git_store), + BuildInfoKey[String]("COMMIT_PATH", MornyProject.git_store_path), + ), + + scalacOptions ++= Seq( + "-language:postfixOps", + "-encoding", MornyProject.source_encoding + ), + javacOptions ++= Seq( + "-encoding", MornyProject.source_encoding, + "-source", "17", + "-target", "17" + ), + + assemblyMergeStrategy := { + case module if module endsWith "module-info.class" => MergeStrategy.concat + case module_kt if module_kt endsWith ".kotlin_module" => MergeStrategy.concat + case x => + val oldStrategy = (ThisBuild / assemblyMergeStrategy).value + oldStrategy(x) + }, + assembly / artifact := (assembly / artifact).value + .withClassifier(Some("fat")), + addArtifact(assembly / artifact, assembly), + if (System.getenv("DOCKER_BUILD") != null) { + assembly / assemblyJarName := { + sLog.value info "environment DOCKER_BUILD checked" + sLog.value info "assembly will output for docker build (morny-coeur-docker-build.jar)" + "morny-coeur-docker-build.jar" + } + } else Nil, + + publishTo := MornyProject.publishTo, + credentials ++= MornyProject.publishCredentials, + + ) diff --git a/docker-compose.yml b/docker-compose.yml.example similarity index 100% rename from docker-compose.yml rename to docker-compose.yml.example diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 3882b9d..0000000 --- a/gradle.properties +++ /dev/null @@ -1,32 +0,0 @@ -## Core - -MORNY_ARCHIVE_NAME = morny-coeur - -MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono -MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s - -VERSION = 1.3.0 - -USE_DELTA = false -VERSION_DELTA = - -CODENAME = guanggu - -# dependencies - -lib_spotbugs_v = 4.7.3 -lib_scalamodule_xml_v = 2.2.0 - -lib_messiva_v = 0.2.0 -lib_resourcetools_v = 0.2.2 -lib_slf4j_v = 2.0.9 - -lib_javatelegramapi_v = 6.2.0 - -lib_sttp_v = 3.9.0 -lib_okhttp_v = 4.11.0 -lib_gson_v = 2.10.1 -lib_circe_v = 0.14.6 -lib_cron_utils_v = 9.2.0 - -lib_scalatest_v = 3.2.17 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 7454180..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index fce403e..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 744e882..0000000 --- a/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100755 index 107acd3..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/project/.gitignore b/project/.gitignore new file mode 100644 index 0000000..a00c922 --- /dev/null +++ b/project/.gitignore @@ -0,0 +1,3 @@ +/target +/project +metals.sbt diff --git a/project/MornyConfiguration.scala b/project/MornyConfiguration.scala new file mode 100644 index 0000000..4653ae8 --- /dev/null +++ b/project/MornyConfiguration.scala @@ -0,0 +1,62 @@ +import sbt.* + +//noinspection TypeAnnotation +object MornyConfiguration { + + val MORNY_ARCHIVE_NAME = "morny-coeur" + + val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono" + val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s" + + val VERSION = "2.0.0-alpha1" + val VERSION_DELTA: Option[String] = None + val CODENAME = "guanggu" + + val SNAPSHOT = true + + val dependencies = Seq( + + "com.github.spotbugs" % "spotbugs-annotations" % "4.7.3" % Compile, + + "cc.sukazyo" % "messiva" % "0.2.0", + "cc.sukazyo" % "resource-tools" % "0.2.2", + + "com.github.pengrad" % "java-telegram-bot-api" % "6.2.0", + + "com.softwaremill.sttp.client3" %% "core" % "3.9.0", + "com.softwaremill.sttp.client3" %% "okhttp-backend" % "3.9.0", + "com.squareup.okhttp3" % "okhttp" % "4.11.0" % Runtime, + + "com.google.code.gson" % "gson" % "2.10.1", + "io.circe" %% "circe-core" % "0.14.6", + "io.circe" %% "circe-generic" % "0.14.6", + "io.circe" %% "circe-parser" % "0.14.6", + "org.jsoup" % "jsoup" % "1.16.2", + + "com.cronutils" % "cron-utils" % "9.2.0", + + // used for disable slf4j + // due to the slf4j api have been used in the following libraries: + // - cron-utils + "org.slf4j" % "slf4j-nop" % "2.0.9" % Runtime, + + "org.scalatest" %% "scalatest" % "3.2.17" % Test, + "org.scalatest" %% "scalatest-freespec" % "3.2.17" % Test, + + ) + + val publishTo: Some[Resolver] = { + //noinspection SimplifyBooleanMatch + SNAPSHOT match { + case true => Some("-ws-snapshots" at "https://mvn.sukazyo.cc/snapshots") + case false => Some("-ws-releases" at "https://mvn.sukazyo.cc/releases") + } +// Some(Resolver.file("build", file("./target/artifacts"))) +// None + } + val publishCredentials: Seq[Credentials] = { + Seq(Credentials(Path.userHome / ".sbt" / ("workshop-mvn"+".credentials"))) +// Nil + } + +} diff --git a/project/MornyProject.scala b/project/MornyProject.scala new file mode 100644 index 0000000..1242517 --- /dev/null +++ b/project/MornyProject.scala @@ -0,0 +1,53 @@ +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.revwalk.RevWalk +import org.eclipse.jgit.storage.file.FileRepositoryBuilder + +import java.io.File + +//noinspection TypeAnnotation +object MornyProject { + + val _git_repo = new FileRepositoryBuilder() + .setGitDir(new File(".git")) + .setWorkTree(new File("")) + .readEnvironment() + .build() + val _git = new Git(_git_repo) + def _git_head = _git_repo.resolve("HEAD") + def _git_head_commit = new RevWalk(_git_repo).parseCommit(_git_head) + val git_exists = true + val git_store = MornyConfiguration.MORNY_CODE_STORE + def git_commit = _git_head_commit.getName + def git_commit_time = _git_head_commit.getCommitTime*1000L + val git_store_path = MornyConfiguration.MORNY_COMMIT_PATH + // todo: is clean for project should only take care of app src and build src + def git_is_clean = _git.status.call.isClean + + // todo: git status log + + val app_group = "cc.sukazyo" + val app_package = s"$app_group.cono.morny" + val app_archive_name = MornyConfiguration.MORNY_ARCHIVE_NAME + val app_application_main = s"$app_package.ServerMain" + + val version_base = MornyConfiguration.VERSION + val version_delta = MornyConfiguration.VERSION_DELTA + val version_is_snapshot = MornyConfiguration.SNAPSHOT + val version = Seq( + version_base, + version_delta match { case Some(value) => "δ" + value case None => null}, + if (version_is_snapshot) "SNAPSHOT" else null + ).filterNot(f => f == null).mkString("-") + def version_full = version + (if (!git_exists) "" else + s"+git${git_commit take 8}${if (git_is_clean) "" else ".δ"}") + val version_codename = MornyConfiguration.CODENAME + def code_time = if (git_is_clean) git_commit_time else System.currentTimeMillis + + val dependencies = MornyConfiguration.dependencies + + def publishTo = MornyConfiguration.publishTo + val publishCredentials = MornyConfiguration.publishCredentials + + val source_encoding = "utf-8" + +} diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..3040987 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.4 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..642bf42 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,3 @@ +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") +addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.5") diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index b7b457e..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = "Coeur Morny Cono" - diff --git a/src/main/scala/cc/sukazyo/cono/morny/MornySystem.scala b/src/main/scala/cc/sukazyo/cono/morny/MornySystem.scala index 97866db..7400eb0 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/MornySystem.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/MornySystem.scala @@ -2,6 +2,7 @@ package cc.sukazyo.cono.morny import cc.sukazyo.cono.morny.internal.BuildConfigField import cc.sukazyo.cono.morny.Log.{exceptionLog, logger} +import cc.sukazyo.cono.morny.util.EpochDateTime.EpochMillis import cc.sukazyo.cono.morny.util.FileUtils import java.io.IOException @@ -13,24 +14,20 @@ object MornySystem { @BuildConfigField val VERSION: String = BuildConfig.VERSION @BuildConfigField val VERSION_FULL: String = BuildConfig.VERSION_FULL @BuildConfigField val VERSION_BASE: String = BuildConfig.VERSION_BASE - @BuildConfigField val VERSION_DELTA: String = BuildConfig.VERSION_DELTA + @BuildConfigField val VERSION_DELTA: Option[String] = BuildConfig.VERSION_DELTA + @BuildConfigField val GIT_COMMIT: Option[String] = Some(BuildConfig.COMMIT) + @BuildConfigField val CODE_TIMESTAMP: EpochMillis = BuildConfig.CODE_TIMESTAMP @BuildConfigField val CODENAME: String = BuildConfig.CODENAME @BuildConfigField val CODE_STORE: String = BuildConfig.CODE_STORE //noinspection ScalaWeakerAccess @BuildConfigField val COMMIT_PATH: String = BuildConfig.COMMIT_PATH - @BuildConfigField - def isUseDelta: Boolean = VERSION_DELTA ne null - - @BuildConfigField - def isGitBuild: Boolean = BuildConfig.COMMIT ne null - @BuildConfigField def isCleanBuild: Boolean = BuildConfig.CLEAN_BUILD def currentCodePath: String|Null = - if ((COMMIT_PATH eq null) || (!isGitBuild)) null - else COMMIT_PATH.formatted(BuildConfig.COMMIT) + if ((COMMIT_PATH eq null) || (GIT_COMMIT isEmpty)) null + else COMMIT_PATH.formatted(GIT_COMMIT get) def getJarMD5: String = { try { diff --git a/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala b/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala index e067cba..de6374a 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/ServerMain.scala @@ -94,7 +94,7 @@ object ServerMain { /// if (showHello) logger info MornyAbout.MORNY_PREVIEW_IMAGE_ASCII - if (mode_echoHello) return; + if (mode_echoHello) return if (unknownArgs.nonEmpty) logger warn s"""Can't understand arg to some meaning @@ -117,18 +117,18 @@ object ServerMain { s"""Morny Cono Version |- version : | Morny ${MornySystem.CODENAME toUpperCase} - | ${MornySystem.VERSION_BASE}${if (MornySystem.isUseDelta) "-δ"+MornySystem.VERSION_DELTA else ""} + | ${MornySystem.VERSION_BASE}${MornySystem.VERSION_DELTA match{case Some(d) => "-δ" + d case None => ""}} |- md5hash : | ${MornySystem.getJarMD5} |- gitstat : - |${ if (MornySystem.isGitBuild) { + |${ MornySystem.GIT_COMMIT match { case Some(commit) => s""" on commit ${if (MornySystem.isCleanBuild) "- clean-build" else "<δ/non-clean-build>"} - | ${BuildConfig.COMMIT}""" + | $commit""" .stripMargin - } else " "} + case None => " " }} |- buildtd : - | ${BuildConfig.CODE_TIMESTAMP} - | ${CommonFormat.formatDate(BuildConfig.CODE_TIMESTAMP, 0)} [UTC]""" + | ${MornySystem.CODE_TIMESTAMP} + | ${CommonFormat.formatDate(MornySystem.CODE_TIMESTAMP, 0)} [UTC]""" .stripMargin return @@ -138,7 +138,7 @@ object ServerMain { s"""ServerMain.java Loaded >>> |- version ${MornySystem.VERSION_FULL} |- Morny ${MornySystem.CODENAME toUpperCase} - |- <${MornySystem.getJarMD5}> [${BuildConfig.CODE_TIMESTAMP}]""".stripMargin + |- <${MornySystem.getJarMD5}> [${MornySystem.CODE_TIMESTAMP}]""".stripMargin // due to [[MornyFormatterConsole]] will use a localized time, it will output to the log logger info s"logging time will use time-zone ${tz.getID} ($tz_offset)" diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyInformation.scala b/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyInformation.scala index 00de370..c331c1c 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyInformation.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyInformation.scala @@ -1,6 +1,6 @@ package cc.sukazyo.cono.morny.bot.command -import cc.sukazyo.cono.morny.{BuildConfig, MornyCoeur, MornySystem} +import cc.sukazyo.cono.morny.{MornyCoeur, MornySystem} import cc.sukazyo.cono.morny.data.MornyInformation.* import cc.sukazyo.cono.morny.data.TelegramStickers import cc.sukazyo.cono.morny.util.CommonFormat.{formatDate, formatDuration} @@ -103,19 +103,19 @@ class MornyInformation (using coeur: MornyCoeur) extends ITelegramCommand { } private[command] def echoVersion (using event: Update): Unit = { - val versionDeltaHTML = if (MornySystem.isUseDelta) s"-δ${h(MornySystem.VERSION_DELTA)}" else "" - val versionGitHTML = if (MornySystem.isGitBuild) s"git $getVersionGitTagHTML" else "" + val versionDeltaHTML = MornySystem.VERSION_DELTA match {case Some(d) => s"-δ${h(d)}" case None => ""} + val versionGitHTML = if (MornySystem.GIT_COMMIT nonEmpty) s"git $getVersionGitTagHTML" else "" coeur.account exec new SendMessage( event.message.chat.id, // language=html s"""version: |- Morny ${h(MornySystem.CODENAME toUpperCase)} - |- ${h(MornySystem.VERSION_BASE)}$versionDeltaHTML${if (MornySystem.isGitBuild) "\n- " + versionGitHTML else ""} + |- ${h(MornySystem.VERSION_BASE)}$versionDeltaHTML${if (MornySystem.GIT_COMMIT nonEmpty) "\n- " + versionGitHTML else ""} |coeur md5_hash: |- ${h(MornySystem.getJarMD5)} |coding timestamp: - |- ${BuildConfig.CODE_TIMESTAMP} - |- ${h(formatDate(BuildConfig.CODE_TIMESTAMP, 0))} [UTC] + |- ${MornySystem.CODE_TIMESTAMP} + |- ${h(formatDate(MornySystem.CODE_TIMESTAMP, 0))} [UTC] |""".stripMargin ).replyToMessageId(event.message.messageId).parseMode(ParseMode HTML) } @@ -137,8 +137,8 @@ class MornyInformation (using coeur: MornyCoeur) extends ITelegramCommand { |coeur version: |- $getVersionAllFullTagHTML |- ${h(MornySystem.getJarMD5)} - |- ${h(formatDate(BuildConfig.CODE_TIMESTAMP, 0))} [UTC] - |- [${BuildConfig.CODE_TIMESTAMP}] + |- ${h(formatDate(MornySystem.CODE_TIMESTAMP, 0))} [UTC] + |- [${MornySystem.CODE_TIMESTAMP}] |continuous: |- ${h(formatDuration(System.currentTimeMillis - coeur.coeurStartTimestamp))} |- [${System.currentTimeMillis - coeur.coeurStartTimestamp}] diff --git a/src/main/scala/cc/sukazyo/cono/morny/data/MornyInformation.scala b/src/main/scala/cc/sukazyo/cono/morny/data/MornyInformation.scala index 19e4642..686b211 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/data/MornyInformation.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/data/MornyInformation.scala @@ -1,6 +1,6 @@ package cc.sukazyo.cono.morny.data -import cc.sukazyo.cono.morny.{BuildConfig, MornyAbout, MornySystem} +import cc.sukazyo.cono.morny.{MornyAbout, MornySystem} import java.net.InetAddress import java.rmi.UnknownHostException @@ -9,21 +9,23 @@ object MornyInformation { //noinspection ScalaWeakerAccess def getVersionGitTagHTML: String = { - if (!MornySystem.isGitBuild) return "" - val g = StringBuilder() - val cm = BuildConfig.COMMIT substring(0, 8) - val cp = MornySystem.currentCodePath - if (cp == null) g ++= s"$cm" - else g ++= s"$cm" - if (!MornySystem.isCleanBuild) g ++= ".δ" - g toString + MornySystem.GIT_COMMIT match + case None => "" + case Some(commit) => + val g = StringBuilder() + val cm = commit substring(0, 8) + val cp = MornySystem.currentCodePath + if (cp == null) g ++= s"$cm" + else g ++= s"$cm" + if (!MornySystem.isCleanBuild) g ++= ".δ" + g toString } def getVersionAllFullTagHTML: String = { val v = StringBuilder() v ++= s"${MornySystem VERSION_BASE}" - if (MornySystem isUseDelta) v ++= s"-δ${MornySystem VERSION_DELTA}" - if (MornySystem isGitBuild) v ++= "+git." ++= getVersionGitTagHTML + if (MornySystem.VERSION_DELTA nonEmpty) v ++= s"-δ${MornySystem.VERSION_DELTA.get}" + if (MornySystem.GIT_COMMIT nonEmpty) v ++= "+git." ++= getVersionGitTagHTML v ++= s"*${MornySystem.CODENAME toUpperCase}" v toString }