diff options
33 files changed, 1311 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b6985c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/archenemyexample/build.gradle.kts b/archenemyexample/build.gradle.kts new file mode 100644 index 0000000..eb0d9ff --- /dev/null +++ b/archenemyexample/build.gradle.kts @@ -0,0 +1,32 @@ +import moe.nea.archenemy.MCSide + +plugins { + kotlin("multiplatform") version "1.9.10" + id("moe.nea.archenemy.mojang") +} + +repositories { + mavenCentral() +} + +kotlin { + val allJvm by sourceSets.creating { + this.dependencies { + } + } + + jvm("forge") { + compilations.named("main").get().run { + defaultSourceSet.dependsOn(allJvm) + this.dependencies { + implementation(mojang.minecraft("1.8.9", MCSide.CLIENT)) + } + } + } +// jvm("fabric") { +// compilations.named("main").get().run { +// defaultSourceSet.dependsOn(allJvm) +// } +// } +} + diff --git a/archenemyexample/gradle/wrapper/gradle-wrapper.jar b/archenemyexample/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000..41d9927 --- /dev/null +++ b/archenemyexample/gradle/wrapper/gradle-wrapper.jar diff --git a/archenemyexample/gradle/wrapper/gradle-wrapper.properties b/archenemyexample/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a595206 --- /dev/null +++ b/archenemyexample/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/archenemyexample/gradlew b/archenemyexample/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/archenemyexample/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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 "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/archenemyexample/gradlew.bat b/archenemyexample/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/archenemyexample/gradlew.bat @@ -0,0 +1,89 @@ +@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/archenemyexample/settings.gradle.kts b/archenemyexample/settings.gradle.kts new file mode 100644 index 0000000..d69f7a0 --- /dev/null +++ b/archenemyexample/settings.gradle.kts @@ -0,0 +1,7 @@ +includeBuild("..") +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + maven("https://maven.neoforged.net/releases") + }}
\ No newline at end of file diff --git a/archenemyexample/src/allJvm/kotlin/test.kt b/archenemyexample/src/allJvm/kotlin/test.kt new file mode 100644 index 0000000..87010a6 --- /dev/null +++ b/archenemyexample/src/allJvm/kotlin/test.kt @@ -0,0 +1,9 @@ +expect fun doStuff(args: Int) + +fun callDoStuff() { + doStuff(1) +} + + + + diff --git a/archenemyexample/src/fabricMain/kotlin/doStuff.kt b/archenemyexample/src/fabricMain/kotlin/doStuff.kt new file mode 100644 index 0000000..659bc2b --- /dev/null +++ b/archenemyexample/src/fabricMain/kotlin/doStuff.kt @@ -0,0 +1,3 @@ +actual fun doStuff(args: Int) { + +}
\ No newline at end of file diff --git a/archenemyexample/src/fabricMain/kotlin/test.kt b/archenemyexample/src/fabricMain/kotlin/test.kt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/archenemyexample/src/fabricMain/kotlin/test.kt diff --git a/archenemyexample/src/forgeMain/kotlin/doStuff.kt b/archenemyexample/src/forgeMain/kotlin/doStuff.kt new file mode 100644 index 0000000..659bc2b --- /dev/null +++ b/archenemyexample/src/forgeMain/kotlin/doStuff.kt @@ -0,0 +1,3 @@ +actual fun doStuff(args: Int) { + +}
\ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000..249e583 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a595206 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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 "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f127cfd --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,91 @@ +@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% equ 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% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts new file mode 100644 index 0000000..d0a7eff --- /dev/null +++ b/plugin/build.gradle.kts @@ -0,0 +1,50 @@ +plugins { + `java-gradle-plugin` + kotlin("jvm") version "1.8.0" + kotlin("plugin.serialization") version "1.8.0" +} + +repositories { + mavenCentral() + maven("https://maven.neoforged.net/releases") +} + +dependencies { + implementation("net.neoforged:artifactural:3.0.17") + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2") + + testImplementation("org.jetbrains.kotlin:kotlin-test") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit") +} + +gradlePlugin { + val greeting by plugins.creating { + id = "moe.nea.archenemy.greeting" + implementationClass = "moe.nea.archenemy.ArchenemyGreetingPlugin" + } + val mojang by plugins.creating { + id = "moe.nea.archenemy.mojang" + implementationClass = "moe.nea.archenemy.mojang.ArchenemyMojangPlugin" + } +} + +// Add a source set for the functional test suite +val functionalTestSourceSet = sourceSets.create("functionalTest") { +} + +configurations["functionalTestImplementation"].extendsFrom(configurations["testImplementation"]) + +// Add a task to run the functional tests +val functionalTest by tasks.registering(Test::class) { + testClassesDirs = functionalTestSourceSet.output.classesDirs + classpath = functionalTestSourceSet.runtimeClasspath +} + +gradlePlugin.testSourceSets(functionalTestSourceSet) + +tasks.named<Task>("check") { + // Run the functional tests as part of `check` + dependsOn(functionalTest) +} diff --git a/plugin/src/functionalTest/kotlin/moe/nea/archenemy/ArchenemyPluginFunctionalTest.kt b/plugin/src/functionalTest/kotlin/moe/nea/archenemy/ArchenemyPluginFunctionalTest.kt new file mode 100644 index 0000000..c4ba495 --- /dev/null +++ b/plugin/src/functionalTest/kotlin/moe/nea/archenemy/ArchenemyPluginFunctionalTest.kt @@ -0,0 +1,44 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package moe.nea.archenemy + +import java.io.File +import java.nio.file.Files +import kotlin.test.assertTrue +import kotlin.test.Test +import org.gradle.testkit.runner.GradleRunner +import org.junit.Rule +import org.junit.rules.TemporaryFolder + +/** + * A simple functional test for the 'moe.nea.archenemy.greeting' plugin. + */ +class ArchenemyPluginFunctionalTest { + @get:Rule val tempFolder = TemporaryFolder() + + private fun getProjectDir() = tempFolder.root + private fun getBuildFile() = getProjectDir().resolve("build.gradle") + private fun getSettingsFile() = getProjectDir().resolve("settings.gradle") + + @Test fun `can run task`() { + // Setup the test build + getSettingsFile().writeText("") + getBuildFile().writeText(""" +plugins { + id('moe.nea.archenemy.greeting') +} +""") + + // Run the build + val runner = GradleRunner.create() + runner.forwardOutput() + runner.withPluginClasspath() + runner.withArguments("greeting") + runner.withProjectDir(getProjectDir()) + val result = runner.build(); + + // Verify the result + assertTrue(result.output.contains("Hello from plugin 'moe.nea.archenemy.greeting'")) + } +} diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/ArchenemyGreetingPlugin.kt b/plugin/src/main/kotlin/moe/nea/archenemy/ArchenemyGreetingPlugin.kt new file mode 100644 index 0000000..85144f1 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/ArchenemyGreetingPlugin.kt @@ -0,0 +1,21 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package moe.nea.archenemy + +import org.gradle.api.Project +import org.gradle.api.Plugin + +/** + * A simple 'hello world' plugin. + */ +class ArchenemyGreetingPlugin: Plugin<Project> { + override fun apply(project: Project) { + // Register a task + project.tasks.register("greeting") { task -> + task.doLast { + println("Hello from plugin 'moe.nea.archenemy.greeting'") + } + } + } +} diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/DownloadUtils.kt b/plugin/src/main/kotlin/moe/nea/archenemy/DownloadUtils.kt new file mode 100644 index 0000000..c849349 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/DownloadUtils.kt @@ -0,0 +1,52 @@ +package moe.nea.archenemy + +import java.io.File +import java.io.IOException +import java.net.URL +import java.security.MessageDigest + +object DownloadUtils { + fun bytesToHex(hash: ByteArray): String { + val hexString = StringBuilder(2 * hash.size) + for (i in hash.indices) { + val hex = Integer.toHexString(0xff and hash[i].toInt()) + if (hex.length == 1) { + hexString.append('0') + } + hexString.append(hex) + } + return hexString.toString() + } + + + fun sha1Hash(file: File): String { + if (!file.exists()) return "" + val messageDigest = MessageDigest.getInstance("SHA-1") + + file.inputStream().use { + val r = ByteArray(4096) + while (true) { + val d = it.read(r) + if (d < 0) break + messageDigest.update(r, 0, d) + } + } + return bytesToHex(messageDigest.digest()) + } + + fun areHashesEqual(a: String, b: String): Boolean { + return b.equals(a, ignoreCase = true) + } + + fun downloadFile(source: URL, sha1: String, targetFile: File) { + targetFile.parentFile.mkdirs() + if (areHashesEqual(sha1Hash(targetFile), sha1)) return + source.openStream().use { inp -> + targetFile.outputStream().use { out -> + inp.copyTo(out) + } + } + if (!areHashesEqual(sha1Hash(targetFile), sha1)) + throw IOException("$targetFile should hash to $sha1, but does not") + } +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/MCSide.kt b/plugin/src/main/kotlin/moe/nea/archenemy/MCSide.kt new file mode 100644 index 0000000..65604aa --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/MCSide.kt @@ -0,0 +1,6 @@ +package moe.nea.archenemy + + +enum class MCSide { + CLIENT, SERVER +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt new file mode 100644 index 0000000..b3b3cfd --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt @@ -0,0 +1,38 @@ +package moe.nea.archenemy.mojang + +import moe.nea.archenemy.MCSide +import net.minecraftforge.artifactural.gradle.GradleRepositoryAdapter +import org.gradle.api.Project +import org.gradle.api.artifacts.Dependency +import java.net.URI + +abstract class ArchenemyMojangExtension(val project: Project) { + val sharedExtension = project.rootProject.extensions.getByType(ArchenemySharedExtension::class.java) + + private val _registerMinecraftProvider by lazy { + GradleRepositoryAdapter.add( + project.repositories, + "Minecraft Provider", + sharedExtension.getLocalCacheDirectory().resolve("minecraft-provider"), + sharedExtension.minecraftProvider + ) + project.repositories.maven { + it.name = "Minecraft Libraries" + it.url = URI("https://libraries.minecraft.net/") + } + } + + + fun minecraft(version: String, side: MCSide): Dependency { + _registerMinecraftProvider + return project.dependencies.create( + sharedExtension.minecraftProvider.getDependencyCoordinate( + MinecraftProvider.MinecraftCoordinate( + version, + side, + ) + ) + ) + } + +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangPlugin.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangPlugin.kt new file mode 100644 index 0000000..4f01322 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangPlugin.kt @@ -0,0 +1,22 @@ +package moe.nea.archenemy.mojang + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class ArchenemyMojangPlugin : Plugin<Project> { + + override fun apply(project: Project) { + project.rootProject.tasks.maybeCreate( + "downloadMinecraftVersionManifest", + DownloadMinecraftVersionManifest::class.java + ) + + val rootExt = project.rootProject.extensions + if (rootExt.findByName("archenemyShared") == null) { + rootExt.create("archenemyShared", ArchenemySharedExtension::class.java, project.rootProject) + } + val mojang = project.extensions.create( + "mojang", ArchenemyMojangExtension::class.java, project, + ) + } +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt new file mode 100644 index 0000000..950446d --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt @@ -0,0 +1,20 @@ +package moe.nea.archenemy.mojang + +import org.gradle.api.Project +import java.io.File + +abstract class ArchenemySharedExtension(val rootProject: Project) { + init { + require(rootProject == rootProject.rootProject) + } + + fun getLocalCacheDirectory(): File { + return rootProject.rootDir.resolve(".gradle/archenemy") + } + + fun getDownloadMinecraftVersionManifestTask(): DownloadMinecraftVersionManifest { + return rootProject.tasks.getByName("downloadMinecraftVersionManifest") as DownloadMinecraftVersionManifest + } + + val minecraftProvider = MinecraftProvider(this) +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadMinecraftVersionManifest.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadMinecraftVersionManifest.kt new file mode 100644 index 0000000..2a21c2e --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadMinecraftVersionManifest.kt @@ -0,0 +1,55 @@ +package moe.nea.archenemy.mojang + +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import org.gradle.api.DefaultTask +import org.gradle.api.Project +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import java.net.URL + +abstract class DownloadMinecraftVersionManifest : DefaultTask() { + + @get:OutputFile + abstract val manifestFile: RegularFileProperty + + @get:Input + abstract val manifestUrl: Property<String> + + init { + manifestUrl.convention("https://launchermeta.mojang.com/mc/game/version_manifest.json") + manifestFile.convention(project.layout.buildDirectory.file("mojang-version-manifest.json")) + } + + @TaskAction + fun downloadManifest() { + val url = URL(manifestUrl.get()) + val file = manifestFile.asFile.get() + file.parentFile.mkdirs() + url.openStream().use { input -> + file.outputStream().use { output -> + input.copyTo(output) + } + } + } + + @Internal + fun getManifestNow(): MojangVersionManifest { + // Force resolution + project.objects.fileCollection().from(manifestFile).files + return getManifest().get() + } + + @Internal + fun getManifest(): Provider<MojangVersionManifest> { + return manifestFile.asFile.map { + val manifestText = it.readText() + Json.decodeFromString<MojangVersionManifest>(manifestText) + } + } +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/IdentityMinecraftTransformer.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/IdentityMinecraftTransformer.kt new file mode 100644 index 0000000..9d23c60 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/IdentityMinecraftTransformer.kt @@ -0,0 +1,15 @@ +package moe.nea.archenemy.mojang + +import java.io.File +import java.security.MessageDigest + +class IdentityMinecraftTransformer : MinecraftTransformer { + override fun updateHash(hash: MessageDigest) { + hash.update("Identity") + } + + override fun transformJar(oldJar: File, newJar: File) { + oldJar.copyTo(newJar) + } + +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MinecraftProvider.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MinecraftProvider.kt new file mode 100644 index 0000000..845d3e7 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MinecraftProvider.kt @@ -0,0 +1,138 @@ +package moe.nea.archenemy.mojang + +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import moe.nea.archenemy.DownloadUtils +import moe.nea.archenemy.MCSide +import net.minecraftforge.artifactural.api.artifact.Artifact +import net.minecraftforge.artifactural.api.artifact.ArtifactIdentifier +import net.minecraftforge.artifactural.api.artifact.ArtifactType +import net.minecraftforge.artifactural.api.artifact.Streamable +import net.minecraftforge.artifactural.api.repository.Repository +import net.minecraftforge.artifactural.base.artifact.StreamableArtifact +import java.io.File +import java.io.IOException +import java.net.URL +import java.security.MessageDigest +import java.util.concurrent.ConcurrentHashMap + +fun MessageDigest.updateField(text: String, value: String) { + this.update(text) + this.update(":") + this.update(value) + this.update(";") +} + +fun MessageDigest.update(text: String) { + this.update(text.encodeToByteArray()) +} + +class MinecraftProvider(val sharedExtension: ArchenemySharedExtension) : Repository { + + + data class MinecraftCoordinate( + val version: String, + val side: MCSide, + ) + + private val manifest by lazy { + URL("https://launchermeta.mojang.com/mc/game/version_manifest.json").openStream().use { + Json.decodeFromStream<MojangVersionManifest>(it) + } + } + private val providers = mutableSetOf<MinecraftCoordinate>() + private val versionManifest: MutableMap<String, MojangVersionMetadata> = ConcurrentHashMap() + private val json = Json { + ignoreUnknownKeys = true + } + + fun getDependencyCoordinate(minecraftCoordinate: MinecraftCoordinate): String { + providers.add(minecraftCoordinate) + return "archenemy.mojang:minecraft:${minecraftCoordinate.version}:${minecraftCoordinate.side}" + } + + fun getMappingsDependencyCoordinate(minecraftCoordinate: MinecraftCoordinate): String { + providers.add(minecraftCoordinate) + return "archenemy.mojang:minecraft:${minecraftCoordinate.version}:${minecraftCoordinate.side}-mappings@txt" + } + + + private fun getVersionManifest(version: String): MojangVersionMetadata { + return versionManifest.computeIfAbsent(version) { + val versionMetadata = manifest.versions.find { it.id == version } + if (versionMetadata == null) + throw IOException("Invalid minecraft version $version") + val metadata = URL(versionMetadata.url).openStream().use { + json.decodeFromStream<MojangVersionMetadata>(it) + } + metadata + } + } + + private fun downloadMinecraft(coordinate: MinecraftCoordinate, mappings: Boolean): File { + val metadata = getVersionManifest(coordinate.version) + val downloadType = when (coordinate.side) { + MCSide.CLIENT -> "client" + MCSide.SERVER -> "server" + } + if (mappings) "-mappings" else "" + val download = metadata.downloads[downloadType] + ?: throw IOException("Invalid minecraft side $downloadType for ${coordinate.version}") + val targetFile = + sharedExtension.getLocalCacheDirectory().resolve("minecraft-raw") + .resolve("minecraft-${coordinate.version}-${coordinate.side}.${if (mappings) "txt" else "jar"}") + DownloadUtils.downloadFile(URL(download.url), download.sha1, targetFile) + return targetFile + } + + private fun provideStreamableMinecraftJar(coordinate: MinecraftCoordinate): Streamable { + return Streamable { + downloadMinecraft(coordinate, false).inputStream() + } + } + + private fun provideStreamableMappings(coordinate: MinecraftCoordinate): Streamable { + return Streamable { + downloadMinecraft(coordinate, true).inputStream() + } + } + + fun getNullsafeIdentifier(identifier: ArtifactIdentifier): ArtifactIdentifier { + return object : ArtifactIdentifier by identifier { + override fun getClassifier(): String { + return if (identifier.classifier == null) + "" + else + identifier.classifier + } + } + } + + override fun getArtifact(identifier: ArtifactIdentifier?): Artifact { + if (identifier == null) return Artifact.none() + if (identifier.name != "minecraft") return Artifact.none() + if (!identifier.group.startsWith("archenemy.")) return Artifact.none() + if (identifier.extension == "pom") return Artifact.none() + val coordinate = + MinecraftCoordinate(identifier.version, MCSide.valueOf(identifier.classifier.removeSuffix("-mappings"))) + val isMappings = identifier.classifier.endsWith("-mappings") + if (!providers.contains(coordinate)) + error("Unregistered minecraft dependency") + if (identifier.extension == "jar" && !isMappings) { + return StreamableArtifact.ofStreamable( + getNullsafeIdentifier(identifier), + ArtifactType.BINARY, + provideStreamableMinecraftJar(coordinate) + ) + } + if (identifier.extension == "txt" && isMappings) { + return StreamableArtifact.ofStreamable( + getNullsafeIdentifier(identifier), + ArtifactType.OTHER, + provideStreamableMappings(coordinate) + ) + } + return Artifact.none() + } + + +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MinecraftTransformer.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MinecraftTransformer.kt new file mode 100644 index 0000000..4748e36 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MinecraftTransformer.kt @@ -0,0 +1,9 @@ +package moe.nea.archenemy.mojang + +import java.io.File +import java.security.MessageDigest + +interface MinecraftTransformer { + fun updateHash(hash: MessageDigest) + fun transformJar(oldJar: File, newJar: File) +} diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MojangVersionManifest.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MojangVersionManifest.kt new file mode 100644 index 0000000..b3daa48 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MojangVersionManifest.kt @@ -0,0 +1,29 @@ +@file:UseSerializers(InstantSerializer::class) + +package moe.nea.archenemy.mojang + +import kotlinx.serialization.Serializable +import kotlinx.serialization.UseSerializers +import moe.nea.archenemy.util.InstantSerializer +import java.time.Instant + +@Serializable +data class MojangVersionManifest( + val latest: Promotions, + val versions: List<VersionReference> +) { + @Serializable + data class VersionReference( + val id: String, + val type: String, + val url: String, + val time: Instant, + val releaseTime: Instant, + ) + + @Serializable + data class Promotions( + val release: String, + val snapshot: String, + ) +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MojangVersionMetadata.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MojangVersionMetadata.kt new file mode 100644 index 0000000..4ef3313 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MojangVersionMetadata.kt @@ -0,0 +1,31 @@ +package moe.nea.archenemy.mojang + +import kotlinx.serialization.Serializable + +@Serializable +data class MojangVersionMetadata( + val assetIndex: AssetIndex, + val downloads: Map<String, Download>, + val libraries: List<Library> +) { + @Serializable + data class Library( + val name: String, + ) + @Serializable + data class Download( + val sha1: String, + val size: Long, + val url: String, + ) + + @Serializable + data class AssetIndex( + val id: String, + val sha1: String, + val size: Long, + val totalSize: Long, + val url: String, + ) + +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/util/InstantSerializer.kt b/plugin/src/main/kotlin/moe/nea/archenemy/util/InstantSerializer.kt new file mode 100644 index 0000000..10baf04 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/util/InstantSerializer.kt @@ -0,0 +1,24 @@ +package moe.nea.archenemy.util + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import java.time.Instant +import java.time.format.DateTimeFormatter + +object InstantSerializer : KSerializer<Instant> { + override val descriptor: SerialDescriptor + get() = PrimitiveSerialDescriptor("Instant", PrimitiveKind.STRING) + val format: DateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME + + override fun deserialize(decoder: Decoder): Instant { + return format.parse(decoder.decodeString(), Instant::from) as Instant + } + + override fun serialize(encoder: Encoder, value: Instant) { + TODO("Not yet implemented") + } +}
\ No newline at end of file diff --git a/plugin/src/test/kotlin/moe/nea/archenemy/ArchenemyGreetingPluginTest.kt b/plugin/src/test/kotlin/moe/nea/archenemy/ArchenemyGreetingPluginTest.kt new file mode 100644 index 0000000..7d36988 --- /dev/null +++ b/plugin/src/test/kotlin/moe/nea/archenemy/ArchenemyGreetingPluginTest.kt @@ -0,0 +1,22 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package moe.nea.archenemy + +import org.gradle.testfixtures.ProjectBuilder +import kotlin.test.Test +import kotlin.test.assertNotNull + +/** + * A simple unit test for the 'moe.nea.archenemy.greeting' plugin. + */ +class ArchenemyGreetingPluginTest { + @Test fun `plugin registers task`() { + // Create a test project and apply the plugin + val project = ProjectBuilder.builder().build() + project.plugins.apply("moe.nea.archenemy.greeting") + + // Verify the result + assertNotNull(project.tasks.findByName("greeting")) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..6b81798 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,3 @@ + +rootProject.name = "archenemy" +include("plugin") |