Initial commit
This commit is contained in:
commit
7130618038
49 changed files with 1128 additions and 0 deletions
45
.gitignore
vendored
Normal file
45
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Kotlin ###
|
||||
.kotlin
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Environment-dependent path to Maven home directory
|
||||
/mavenHomeManager.xml
|
||||
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
|
|
@ -0,0 +1 @@
|
|||
bsk2
|
||||
10
.idea/codeStyles/Project.xml
generated
Normal file
10
.idea/codeStyles/Project.xml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
17
.idea/gradle.xml
generated
Normal file
17
.idea/gradle.xml
generated
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/kotlinc.xml
generated
Normal file
6
.idea/kotlinc.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="2.2.20" />
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="graalvm-ce-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
13
README.md
Normal file
13
README.md
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
### Building
|
||||
|
||||
Build a native binary for the current architecture using GraalVM:
|
||||
```shell
|
||||
./gradlew nativeCompile
|
||||
ls -l build/native/nativeCompile/bsk2
|
||||
```
|
||||
|
||||
Build an uber JAR:
|
||||
```shell
|
||||
./gradlew build
|
||||
ls -l build/libs/bsk2-*-all.jar
|
||||
```
|
||||
46
build.gradle.kts
Normal file
46
build.gradle.kts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
plugins {
|
||||
application
|
||||
alias(libs.plugins.kotlin.jvm)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
alias(libs.plugins.graalvm.buildtools.native)
|
||||
alias(libs.plugins.shadow)
|
||||
}
|
||||
|
||||
group = "eu.m724"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//implementation("org.eclipse.jgit:org.eclipse.jgit:7.3.0.202506031305-r")
|
||||
/// implementation("io.pebbletemplates:pebble:3.2.4")
|
||||
implementation(libs.clikt) // command line argument parsing
|
||||
implementation(libs.kaml) // YAML configuration parsing
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
testImplementation(libs.mockk)
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
minimize()
|
||||
}
|
||||
|
||||
graalvmNative {
|
||||
toolchainDetection = true
|
||||
|
||||
// -Os? --emit build-report? pgo?
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = "eu.m724.bsk2.MainKt"
|
||||
}
|
||||
1
gradle.properties
Normal file
1
gradle.properties
Normal file
|
|
@ -0,0 +1 @@
|
|||
kotlin.code.style=official
|
||||
18
gradle/libs.versions.toml
Normal file
18
gradle/libs.versions.toml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[versions]
|
||||
kotlin = "2.2.20"
|
||||
graalvm-buildtools-native = "0.11.1"
|
||||
shadow = "9.2.2"
|
||||
clikt = "5.0.3"
|
||||
kaml = "0.97.0"
|
||||
mockk = "1.14.5"
|
||||
|
||||
[libraries]
|
||||
clikt = { group = "com.github.ajalt.clikt", name = "clikt", version.ref = "clikt" }
|
||||
kaml = { group = "com.charleskorn.kaml", name = "kaml", version.ref = "kaml" }
|
||||
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
|
||||
|
||||
[plugins]
|
||||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||
graalvm-buildtools-native = { id = "org.graalvm.buildtools.native", version.ref = "graalvm-buildtools-native" }
|
||||
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#Wed Sep 24 14:33:20 CEST 2025
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
234
gradlew
vendored
Executable file
234
gradlew
vendored
Executable file
|
|
@ -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" "$@"
|
||||
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
|
|
@ -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
|
||||
4
settings.gradle.kts
Normal file
4
settings.gradle.kts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
}
|
||||
rootProject.name = "bsk2"
|
||||
50
src/main/kotlin/eu/m724/bsk2/Main.kt
Normal file
50
src/main/kotlin/eu/m724/bsk2/Main.kt
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package eu.m724.bsk2
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.core.Context
|
||||
import com.github.ajalt.clikt.core.main
|
||||
import com.github.ajalt.clikt.parameters.options.defaultLazy
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.options.required
|
||||
import com.github.ajalt.clikt.parameters.types.path
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.div
|
||||
import kotlin.time.TimeSource
|
||||
|
||||
class Main : CliktCommand() {
|
||||
private val sourceDirectory: Path by option("-i", help = "Your workspace directory")
|
||||
.path(mustExist = true, canBeFile = false)
|
||||
.required()
|
||||
|
||||
private val outputDirectory: Path by option("-o", help = "The output directory")
|
||||
.path(canBeDir = false, canBeFile = false, canBeSymlink = false) // I don't know if there's a cleaner way to require non existing?
|
||||
.defaultLazy(
|
||||
defaultForHelp = "source-directory/output",
|
||||
value = { sourceDirectory / "output" }
|
||||
)
|
||||
|
||||
override fun help(context: Context): String = "Render a blog"
|
||||
|
||||
override fun run() {
|
||||
println()
|
||||
printArguments()
|
||||
println()
|
||||
|
||||
println("Rendering now...")
|
||||
val startMark = TimeSource.Monotonic.markNow()
|
||||
|
||||
// TODO
|
||||
|
||||
val renderingTime = startMark.elapsedNow()
|
||||
println("Render successful, took ${renderingTime.inWholeMilliseconds} ms")
|
||||
}
|
||||
|
||||
private fun printArguments() {
|
||||
println("Read arguments:")
|
||||
println(" Source directory: $sourceDirectory")
|
||||
println(" Output directory: $outputDirectory")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) =
|
||||
Main().main(args)
|
||||
7
src/main/kotlin/eu/m724/bsk2/builder/FileSystem.kt
Normal file
7
src/main/kotlin/eu/m724/bsk2/builder/FileSystem.kt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package eu.m724.bsk2.builder
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
interface FileSystem {
|
||||
fun readText(path: Path): String
|
||||
}
|
||||
10
src/main/kotlin/eu/m724/bsk2/builder/PathUtils.kt
Normal file
10
src/main/kotlin/eu/m724/bsk2/builder/PathUtils.kt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package eu.m724.bsk2.builder
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
// TODO needs a test or two
|
||||
fun Path.isParentOf(child: Path): Boolean =
|
||||
child.toFile().canonicalPath.startsWith(this.toFile().canonicalPath)
|
||||
|
||||
fun Path.contains(other: Path): Boolean =
|
||||
isParentOf(other)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package eu.m724.bsk2.builder.config.data
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class RenderConfiguration(
|
||||
val templatePosts: Boolean = false,
|
||||
val compress: List<CompressionMethod> = listOf(CompressionMethod.GZIP, CompressionMethod.ZSTD)
|
||||
) {
|
||||
@Serializable
|
||||
enum class CompressionMethod {
|
||||
@SerialName("gzip")
|
||||
GZIP,
|
||||
|
||||
@SerialName("zstd")
|
||||
ZSTD
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package eu.m724.bsk2.builder.config.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SiteConfiguration(
|
||||
val name: String,
|
||||
val baseUrl: String = "/"
|
||||
)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package eu.m724.bsk2.builder.config.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class WorkspaceConfiguration(
|
||||
val site: SiteConfiguration,
|
||||
val render: RenderConfiguration = RenderConfiguration()
|
||||
)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package eu.m724.bsk2.builder.config.parser
|
||||
|
||||
import eu.m724.bsk2.builder.config.data.WorkspaceConfiguration
|
||||
|
||||
interface ConfigurationParser {
|
||||
fun parse(text: String): WorkspaceConfiguration
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package eu.m724.bsk2.builder.config.parser
|
||||
|
||||
import com.charleskorn.kaml.Yaml
|
||||
import com.charleskorn.kaml.YamlConfiguration
|
||||
import eu.m724.bsk2.builder.config.data.WorkspaceConfiguration
|
||||
import kotlinx.serialization.decodeFromString
|
||||
|
||||
class YamlConfigurationParser (
|
||||
private val yaml: Yaml = Yaml(
|
||||
configuration = YamlConfiguration(strictMode = false)
|
||||
)
|
||||
) : ConfigurationParser {
|
||||
override fun parse(text: String): WorkspaceConfiguration {
|
||||
return yaml.decodeFromString<WorkspaceConfiguration>(text)
|
||||
}
|
||||
}
|
||||
16
src/main/kotlin/eu/m724/bsk2/builder/post/data/Post.kt
Normal file
16
src/main/kotlin/eu/m724/bsk2/builder/post/data/Post.kt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package eu.m724.bsk2.builder.post.data
|
||||
|
||||
/**
|
||||
* This class represents a post with various attributes including metadata and content.
|
||||
*
|
||||
* @param id The unique identifier of this post, also the slug.
|
||||
* @param metadata The metadata of this post.
|
||||
* @param history The changes of this post, `null` if not a Git object.
|
||||
* @param content The content of this post, `null` if not loaded.
|
||||
*/
|
||||
data class Post(
|
||||
val id: String,
|
||||
val metadata: PostMeta,
|
||||
val history: PostHistory?,
|
||||
val content: String?
|
||||
)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package eu.m724.bsk2.builder.post.data
|
||||
|
||||
/**
|
||||
* Contains information about important change events of this post.
|
||||
*
|
||||
* @param revisions The amount of revisions this post had.
|
||||
* @param creationEvent The first (creation) event of this post.
|
||||
* @param lastModification The most recent event of this post.
|
||||
*/
|
||||
data class PostHistory(
|
||||
val revisions: Int,
|
||||
val creationEvent: PostModificationEvent,
|
||||
val lastModification: PostModificationEvent
|
||||
)
|
||||
20
src/main/kotlin/eu/m724/bsk2/builder/post/data/PostMeta.kt
Normal file
20
src/main/kotlin/eu/m724/bsk2/builder/post/data/PostMeta.kt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package eu.m724.bsk2.builder.post.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* This class represents user-specified post metadata.
|
||||
* It does not contain things that generally do not belong to the metadata file.
|
||||
*
|
||||
* @param title The post title.
|
||||
* @param summary The post summary.
|
||||
* @param draft Whether the post is a draft. Usually combined with [hidden].
|
||||
* @param hidden Whether the post is hidden from the all posts list.
|
||||
*/
|
||||
@Serializable
|
||||
data class PostMeta(
|
||||
val title: String,
|
||||
val summary: String,
|
||||
val draft: Boolean = false,
|
||||
val hidden: Boolean = false,
|
||||
)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package eu.m724.bsk2.builder.post.data
|
||||
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
/**
|
||||
* Represents a single post modification event, usually means a modification.
|
||||
*
|
||||
* @param author The author of this modification.
|
||||
* @param datetime The datetime this modification was made.
|
||||
* @param description The description of this modification.
|
||||
*/
|
||||
data class PostModificationEvent(
|
||||
val author: String,
|
||||
val datetime: ZonedDateTime,
|
||||
val description: String
|
||||
)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package eu.m724.bsk2.builder.post.loader
|
||||
|
||||
import com.charleskorn.kaml.Yaml
|
||||
import com.charleskorn.kaml.YamlConfiguration
|
||||
import eu.m724.bsk2.builder.FileSystem
|
||||
import eu.m724.bsk2.builder.isParentOf
|
||||
import eu.m724.bsk2.builder.post.data.PostMeta
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.div
|
||||
import kotlin.io.path.readText
|
||||
|
||||
/**
|
||||
* A post loader that loads from a file system
|
||||
*
|
||||
* @param postRoot The posts directory (usually `workspace/posts`)
|
||||
* @param fileSystem The file system reader, defaults to reading from disk
|
||||
*/
|
||||
class FileSystemPostLoader (
|
||||
private val postRoot: Path,
|
||||
private val fileSystem: FileSystem = object : FileSystem {
|
||||
override fun readText(path: Path): String = path.readText()
|
||||
},
|
||||
private val yaml: Yaml = Yaml(
|
||||
configuration = YamlConfiguration(strictMode = false)
|
||||
)
|
||||
) : PostLoader {
|
||||
private val cache = mutableMapOf<String, PostMeta>()
|
||||
|
||||
override fun getMeta(name: String): PostMeta {
|
||||
val path = postRoot / name / "meta.yml"
|
||||
|
||||
if (!postRoot.isParentOf(path)) {
|
||||
throw IllegalArgumentException("Path traversal ($path not a child of $postRoot)")
|
||||
}
|
||||
|
||||
return cache.getOrPut(name) {
|
||||
val text = fileSystem.readText(path)
|
||||
yaml.decodeFromString<PostMeta>(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package eu.m724.bsk2.builder.post.loader
|
||||
|
||||
import eu.m724.bsk2.builder.post.data.PostMeta
|
||||
|
||||
interface PostLoader {
|
||||
fun getMeta(name: String): PostMeta
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package eu.m724.bsk2.builder.template.loader
|
||||
|
||||
import eu.m724.bsk2.builder.FileSystem
|
||||
import eu.m724.bsk2.builder.isParentOf
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.div
|
||||
import kotlin.io.path.readText
|
||||
|
||||
/**
|
||||
* A template loader that loads from a file system
|
||||
*
|
||||
* @param templateRoot The root path of the template (usually `workspace/template`)
|
||||
* @param fileSystem The file system reader, defaults to reading from disk
|
||||
*/
|
||||
class FileSystemTemplateLoader (
|
||||
templateRoot: Path,
|
||||
private val fileSystem: FileSystem = object : FileSystem {
|
||||
override fun readText(path: Path): String = path.readText()
|
||||
}
|
||||
) : TemplateLoader {
|
||||
private val cache = mutableMapOf<String, String>()
|
||||
private val htmlRoot = templateRoot / "html"
|
||||
|
||||
override fun getHtml(name: String): String {
|
||||
val path = htmlRoot / "$name.html"
|
||||
|
||||
if (!htmlRoot.isParentOf(path)) {
|
||||
throw IllegalArgumentException("Path traversal ($path not a child of $htmlRoot)")
|
||||
}
|
||||
|
||||
return cache.getOrPut(name) {
|
||||
fileSystem.readText(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package eu.m724.bsk2.builder.template.loader
|
||||
|
||||
interface TemplateLoader {
|
||||
fun getHtml(name: String): String
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package eu.m724.bsk2.builder.config.parser
|
||||
|
||||
import eu.m724.bsk2.builder.config.data.RenderConfiguration
|
||||
import eu.m724.bsk2.builder.config.data.SiteConfiguration
|
||||
import eu.m724.bsk2.builder.config.data.WorkspaceConfiguration
|
||||
import eu.m724.bsk2.builder.config.parser.YamlConfigurationParser
|
||||
import kotlinx.serialization.SerializationException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class YamlConfigurationParserTest {
|
||||
private lateinit var parser: YamlConfigurationParser
|
||||
|
||||
@BeforeEach
|
||||
fun setupTest() {
|
||||
parser = YamlConfigurationParser()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test configuration loading`() {
|
||||
val expectedConfiguration = WorkspaceConfiguration(
|
||||
site = SiteConfiguration(
|
||||
name = "My Blog",
|
||||
baseUrl = "https://blog.example.com"
|
||||
),
|
||||
render = RenderConfiguration(
|
||||
templatePosts = true,
|
||||
compress = listOf(RenderConfiguration.CompressionMethod.GZIP, RenderConfiguration.CompressionMethod.ZSTD)
|
||||
)
|
||||
)
|
||||
|
||||
val sourceText = """
|
||||
# Site options
|
||||
site:
|
||||
name: My Blog
|
||||
# This is used only for RSS feed
|
||||
baseUrl: https://blog.example.com
|
||||
surplus: value which should be ignored
|
||||
|
||||
# Render options
|
||||
render:
|
||||
templatePosts: true
|
||||
|
||||
compress:
|
||||
- gzip
|
||||
- zstd
|
||||
|
||||
surplus: value which should be ignored
|
||||
""".trimIndent()
|
||||
|
||||
assertEquals(expectedConfiguration, parser.parse(sourceText))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test defaults`() {
|
||||
val expectedConfiguration = WorkspaceConfiguration(
|
||||
site = SiteConfiguration(
|
||||
name = "My Blog"
|
||||
),
|
||||
render = RenderConfiguration()
|
||||
)
|
||||
|
||||
val sourceText = """
|
||||
site:
|
||||
name: My Blog
|
||||
""".trimIndent()
|
||||
|
||||
assertEquals(expectedConfiguration, parser.parse(sourceText))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test invalid yaml`() {
|
||||
val sourceText = """
|
||||
i am totally invalid
|
||||
""".trimIndent()
|
||||
|
||||
assertThrows(SerializationException::class.java) {
|
||||
parser.parse(sourceText)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test invalid value type`() {
|
||||
val sourceText = """
|
||||
site:
|
||||
name: []
|
||||
""".trimIndent()
|
||||
|
||||
assertThrows(SerializationException::class.java) {
|
||||
parser.parse(sourceText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package eu.m724.bsk2.builder.post.loader
|
||||
|
||||
import com.charleskorn.kaml.YamlException
|
||||
import eu.m724.bsk2.builder.FileSystem
|
||||
import eu.m724.bsk2.builder.post.data.PostMeta
|
||||
import io.mockk.*
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.div
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class PostLoaderTest {
|
||||
private companion object {
|
||||
val ROOT_PATH: Path = Paths.get("workspace", "posts")
|
||||
|
||||
fun String.toMetaYmlPath() = ROOT_PATH / this / "meta.yml"
|
||||
}
|
||||
|
||||
private lateinit var fileSystem: FileSystem
|
||||
private lateinit var loader: PostLoader
|
||||
|
||||
@BeforeEach
|
||||
fun setupTest() {
|
||||
fileSystem = mockk<FileSystem>()
|
||||
|
||||
loader = FileSystemPostLoader(
|
||||
postRoot = ROOT_PATH,
|
||||
fileSystem = fileSystem
|
||||
)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun cleanupTest() {
|
||||
checkUnnecessaryStub(fileSystem)
|
||||
unmockkAll()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getPost should cache the result on success`() {
|
||||
everyMetaYmlRead("first") returns """
|
||||
title: Hello, world!
|
||||
summary: My first post
|
||||
draft: true
|
||||
hidden: true
|
||||
"""
|
||||
|
||||
// default values
|
||||
everyMetaYmlRead("second") returns """
|
||||
title: Hello, universe!
|
||||
summary: My second post
|
||||
"""
|
||||
|
||||
val expectedFirst = PostMeta(
|
||||
title = "Hello, world!",
|
||||
summary = "My first post",
|
||||
draft = true,
|
||||
hidden = true
|
||||
)
|
||||
|
||||
val expectedSecond = PostMeta(
|
||||
title = "Hello, universe!",
|
||||
summary = "My second post"
|
||||
)
|
||||
|
||||
repeat(3) { assertEquals(expectedFirst, loader.getMeta("first")) }
|
||||
repeat(3) { assertEquals(expectedSecond, loader.getMeta("second")) }
|
||||
|
||||
// ensure that cached
|
||||
verify(exactly = 1) { fileSystem.readText("first".toMetaYmlPath()) }
|
||||
verify(exactly = 1) { fileSystem.readText("second".toMetaYmlPath()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getPost should throw YamlException on invalid meta YML file and not cache the failure`() {
|
||||
everyMetaYmlRead("invalid") returns "Totally invalid"
|
||||
|
||||
repeat(3) { Assertions.assertThrows(YamlException::class.java) { loader.getMeta("invalid") } }
|
||||
|
||||
// ensure not cached
|
||||
verify(exactly = 3) { fileSystem.readText("invalid".toMetaYmlPath()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getPost should throw NoSuchFileException and not cache the failure`() {
|
||||
everyMetaYmlRead("non existent") throws NoSuchFileException("non existent".toMetaYmlPath().toFile())
|
||||
|
||||
repeat(3) { Assertions.assertThrows(NoSuchFileException::class.java) { loader.getMeta("non existent") } }
|
||||
|
||||
// ensure not cached
|
||||
verify(exactly = 3) { fileSystem.readText("non existent".toMetaYmlPath()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getPost should throw IllegalArgumentException for path traversal attempts`() {
|
||||
Assertions.assertThrows(IllegalArgumentException::class.java) { loader.getMeta("../traversed") }
|
||||
|
||||
// while not necessary, here for explicitness
|
||||
verify(exactly = 0) { fileSystem.readText(any()) }
|
||||
}
|
||||
|
||||
private fun everyMetaYmlRead(name: String) =
|
||||
every { fileSystem.readText(name.toMetaYmlPath()) }
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package eu.m724.bsk2.builder.template.loader
|
||||
|
||||
import eu.m724.bsk2.builder.FileSystem
|
||||
import io.mockk.*
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.div
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class emplateLoaderTest {
|
||||
private companion object {
|
||||
val ROOT_PATH: Path = Paths.get("workspace", "template")
|
||||
const val POST_TEMPLATE_TEXT = "This is the post template"
|
||||
const val INDEX_TEMPLATE_TEXT = "This is the index template"
|
||||
|
||||
fun String.toHtmlTemplatePath() = (ROOT_PATH / "html" / "$this.html")
|
||||
}
|
||||
|
||||
private lateinit var fileSystem: FileSystem
|
||||
private lateinit var loader: TemplateLoader
|
||||
|
||||
@BeforeEach
|
||||
fun setupTest() {
|
||||
fileSystem = mockk<FileSystem>()
|
||||
|
||||
loader = FileSystemTemplateLoader(
|
||||
templateRoot = ROOT_PATH,
|
||||
fileSystem = fileSystem
|
||||
)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun cleanupTest() {
|
||||
checkUnnecessaryStub(fileSystem)
|
||||
unmockkAll()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getHtml should return file content on success`() {
|
||||
everyHtmlTemplateRead("post") returns POST_TEMPLATE_TEXT
|
||||
everyHtmlTemplateRead("index") returns INDEX_TEMPLATE_TEXT
|
||||
|
||||
assertEquals(POST_TEMPLATE_TEXT, loader.getHtml("post"))
|
||||
assertEquals(INDEX_TEMPLATE_TEXT, loader.getHtml("index"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getHtml should cache the result on success`() {
|
||||
everyHtmlTemplateRead("post") returns POST_TEMPLATE_TEXT
|
||||
everyHtmlTemplateRead("index") returns INDEX_TEMPLATE_TEXT
|
||||
|
||||
repeat(3) { assertEquals(POST_TEMPLATE_TEXT, loader.getHtml("post")) }
|
||||
repeat(3) { assertEquals(INDEX_TEMPLATE_TEXT, loader.getHtml("index")) }
|
||||
|
||||
// ensure the reads are cached
|
||||
verify(exactly = 1) { fileSystem.readText("post".toHtmlTemplatePath()) }
|
||||
verify(exactly = 1) { fileSystem.readText("index".toHtmlTemplatePath()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getHtml should throw NoSuchFileException and not cache the failure`() {
|
||||
everyHtmlTemplateRead("non existent") throws NoSuchFileException("non existent".toHtmlTemplatePath().toFile())
|
||||
|
||||
Assertions.assertThrows(NoSuchFileException::class.java) { loader.getHtml("non existent") }
|
||||
|
||||
// ensure that the result is not cached
|
||||
Assertions.assertThrows(NoSuchFileException::class.java) { loader.getHtml("non existent") }
|
||||
|
||||
verify(exactly = 2) { fileSystem.readText("non existent".toHtmlTemplatePath()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getHtml should throw IllegalArgumentException for path traversal attempts`() {
|
||||
Assertions.assertThrows(IllegalArgumentException::class.java) {
|
||||
loader.getHtml("../traversed")
|
||||
}
|
||||
|
||||
// while not necessary, here for explicitness
|
||||
verify(exactly = 0) { fileSystem.readText(any()) }
|
||||
}
|
||||
|
||||
private fun everyHtmlTemplateRead(name: String) =
|
||||
every { fileSystem.readText(name.toHtmlTemplatePath()) }
|
||||
}
|
||||
1
src/test/resources/test-blog/assets/another_asset
Normal file
1
src/test/resources/test-blog/assets/another_asset
Normal file
|
|
@ -0,0 +1 @@
|
|||
this is an asset as well
|
||||
1
src/test/resources/test-blog/assets/asset.txt
Normal file
1
src/test/resources/test-blog/assets/asset.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
hello this is asset
|
||||
|
|
@ -0,0 +1 @@
|
|||
hello this is nested asset
|
||||
20
src/test/resources/test-blog/blog.yml
Normal file
20
src/test/resources/test-blog/blog.yml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Site options
|
||||
site:
|
||||
name: My Blog
|
||||
# This is used only for RSS feed
|
||||
baseUrl: https://blog.example.com
|
||||
|
||||
# Custom setting!
|
||||
hello: "World"
|
||||
|
||||
# Render options
|
||||
render:
|
||||
templatePosts: true
|
||||
|
||||
compress:
|
||||
- gzip
|
||||
- zstd
|
||||
|
||||
# Template options, if any
|
||||
template:
|
||||
some_template_setting: "indeed"
|
||||
2
src/test/resources/test-blog/posts/simple/content.html
Normal file
2
src/test/resources/test-blog/posts/simple/content.html
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<h1>Lorem ipsum</h1>
|
||||
<p>Lorem ipsum dolor sit amet</p>
|
||||
0
src/test/resources/test-blog/posts/simple/cover.webp
Normal file
0
src/test/resources/test-blog/posts/simple/cover.webp
Normal file
2
src/test/resources/test-blog/posts/simple/meta.yml
Normal file
2
src/test/resources/test-blog/posts/simple/meta.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
title: This is a post title
|
||||
summary: Summary of this post
|
||||
2
src/test/resources/test-blog/template/html/index.html
Normal file
2
src/test/resources/test-blog/template/html/index.html
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{{ site.name }}
|
||||
{{ static('style.css')
|
||||
8
src/test/resources/test-blog/template/html/post.html
Normal file
8
src/test/resources/test-blog/template/html/post.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<ul>
|
||||
<li>site name: {{ site.name }}</li>
|
||||
<li>style.css: {{ static('style.css') }}</li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
1
src/test/resources/test-blog/template/static/style.css
Normal file
1
src/test/resources/test-blog/template/static/style.css
Normal file
|
|
@ -0,0 +1 @@
|
|||
Contents of style.css
|
||||
5
src/test/resources/test-blog/template/template.yml
Normal file
5
src/test/resources/test-blog/template/template.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Incremental template specification version used by the compiler for backwards compatibility and forwards incompatibility
|
||||
specification_version: 1
|
||||
|
||||
# Configuration is not here as template directories aren't meant to be customized.
|
||||
# TODO figure out how to neatly configure templates
|
||||
Loading…
Add table
Add a link
Reference in a new issue