diff --git a/.github/workflows/build-for-ubuntu.yaml b/.github/workflows/build-for-ubuntu.yaml index 6cc0181..2dd2184 100644 --- a/.github/workflows/build-for-ubuntu.yaml +++ b/.github/workflows/build-for-ubuntu.yaml @@ -15,11 +15,11 @@ jobs: id: sdkman with: candidate: java - version: 22.1.0.1.r17-gln + version: 24.0.1-graal - uses: actions/setup-java@v1 id: setup-java with: - java-version: 17 + java-version: 24 jdkFile: ${{ steps.sdkman.outputs.file }} - name: Setup GRAALVM_HOME run: export GRAALVM_HOME="$JAVA_HOME" diff --git a/.github/workflows/build-for-windows.yaml b/.github/workflows/build-for-windows.yaml index c70263d..568a7a8 100644 --- a/.github/workflows/build-for-windows.yaml +++ b/.github/workflows/build-for-windows.yaml @@ -15,11 +15,11 @@ jobs: id: sdkman with: candidate: java - version: 22.1.0.1.r17-gln + version: 24.0.1-graal - uses: actions/setup-java@v1 id: setup-java with: - java-version: 17 + java-version: 24 jdkFile: ${{ steps.sdkman.outputs.file }} - name: Setup GRAALVM_HOME run: set GRAALVM_HOME=$JAVA_HOME diff --git a/.github/workflows/package-for-ubuntu.yaml b/.github/workflows/package-for-ubuntu.yaml index 8d7234c..967e9be 100644 --- a/.github/workflows/package-for-ubuntu.yaml +++ b/.github/workflows/package-for-ubuntu.yaml @@ -15,11 +15,11 @@ jobs: id: sdkman with: candidate: java - version: 22.1.0.1.r17-gln + version: 24.0.1-graal - uses: actions/setup-java@v1 id: setup-java with: - java-version: 17 + java-version: 24 jdkFile: ${{ steps.sdkman.outputs.file }} - name: Setup GRAALVM_HOME run: export GRAALVM_HOME="$JAVA_HOME" diff --git a/.github/workflows/package-for-windows.yaml b/.github/workflows/package-for-windows.yaml index aa9214e..1f57746 100644 --- a/.github/workflows/package-for-windows.yaml +++ b/.github/workflows/package-for-windows.yaml @@ -15,11 +15,11 @@ jobs: id: sdkman with: candidate: java - version: 22.1.0.1.r17-gln + version: 24.0.1-graal - uses: actions/setup-java@v1 id: setup-java with: - java-version: 17 + java-version: 24 jdkFile: ${{ steps.sdkman.outputs.file }} - name: Setup GRAALVM_HOME run: set GRAALVM_HOME=$JAVA_HOME diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..2733d28 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/4.0.0-rc-3/apache-maven-4.0.0-rc-3-bin.zip diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..19529dd --- /dev/null +++ b/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + 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" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..b150b91 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml index 970ddcd..09bc004 100644 --- a/pom.xml +++ b/pom.xml @@ -22,10 +22,14 @@ ${encoding} 17 gluon - ${java.version} - ${java.version} + 24 + 24 . ifml3.app.Ifml3App + 24.0.1 + 2.0.17 + 10.0.0.0 + 3.0.0 @@ -33,17 +37,27 @@ org.openjfx javafx-controls - 18.0.1 + ${version.library.javafx} + + + org.slf4j + slf4j-api + ${version.library.slf4j} + + + org.slf4j + slf4j-simple + ${version.library.slf4j} org.jruby jruby - 9.3.8.0 + ${version.library.jruby} org.asciidoctor asciidoctorj - 2.5.6 + ${version.library.asciidoctorj} @@ -55,27 +69,27 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.14.0 org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 + 3.5.3 org.apache.maven.plugins maven-failsafe-plugin - 3.0.0-M7 + 3.5.3 org.apache.maven.plugins maven-site-plugin - 3.12.1 + 3.21.0 org.asciidoctor asciidoctor-maven-plugin - 2.2.2 + 3.2.0 org.openjfx @@ -85,7 +99,7 @@ com.gluonhq gluonfx-maven-plugin - 1.0.15 + 1.0.26 @@ -117,9 +131,12 @@ javafx-controls - org.jboss.weld.se - weld-se-shaded - 5.0.1.Final + org.slf4j + slf4j-api + + + org.slf4j + slf4j-simple @@ -224,22 +241,22 @@ org.asciidoctor asciidoctor-maven-plugin - 2.2.2 + 3.2.0 org.jruby jruby - 9.3.8.0 + ${version.library.jruby} org.asciidoctor asciidoctorj - 2.5.6 + ${version.library.asciidoctorj} org.asciidoctor asciidoctorj-diagram - 2.2.3 + 2.3.2 @@ -278,6 +295,31 @@ + + native + + + + org.graalvm.buildtools + native-maven-plugin + 0.10.6 + true + + + build-native + + compile-no-fork + + package + + + + ifml3.app.Ifml3App + + + + + diff --git a/src/main/java/ifml3/api/connector/ComponentConnector.java b/src/main/java/ifml3/api/connector/ComponentConnector.java new file mode 100644 index 0000000..08bcc95 --- /dev/null +++ b/src/main/java/ifml3/api/connector/ComponentConnector.java @@ -0,0 +1,16 @@ +package ifml3.api.connector; + +import ifml3.api.connector.internal.BaseComponentConnector; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.Flow.Subscriber; + +public interface ComponentConnector { + + Subscriber subscriber(); + + Publisher publisher(); + + static ComponentConnector create(final Subscriber in, final Publisher out) { + return new BaseComponentConnector<>(in, out); + } +} diff --git a/src/main/java/ifml3/api/connector/engine/EngineMessage.java b/src/main/java/ifml3/api/connector/engine/EngineMessage.java new file mode 100644 index 0000000..cbae89c --- /dev/null +++ b/src/main/java/ifml3/api/connector/engine/EngineMessage.java @@ -0,0 +1,5 @@ +package ifml3.api.connector.engine; + +public interface EngineMessage { + +} diff --git a/src/main/java/ifml3/api/connector/internal/BaseComponentConnector.java b/src/main/java/ifml3/api/connector/internal/BaseComponentConnector.java new file mode 100644 index 0000000..0ecfc2b --- /dev/null +++ b/src/main/java/ifml3/api/connector/internal/BaseComponentConnector.java @@ -0,0 +1,11 @@ +package ifml3.api.connector.internal; + +import ifml3.api.connector.ComponentConnector; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.Flow.Subscriber; + +public record BaseComponentConnector( + Subscriber subscriber, + Publisher publisher +) implements ComponentConnector { +} diff --git a/src/main/java/ifml3/api/connector/internal/BaseSubscriber.java b/src/main/java/ifml3/api/connector/internal/BaseSubscriber.java new file mode 100644 index 0000000..5fc5dd9 --- /dev/null +++ b/src/main/java/ifml3/api/connector/internal/BaseSubscriber.java @@ -0,0 +1,37 @@ +package ifml3.api.connector.internal; + +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.Flow.Subscription; +import java.util.function.Consumer; + +public class BaseSubscriber implements Subscriber { + + private final Consumer consumer; + + private Subscription subscription; + + public BaseSubscriber(final Consumer consumer) { + this.consumer = consumer; + } + + @Override + public void onSubscribe(final Subscription subscription) { + this.subscription = subscription; + this.subscription.request(1L); + } + + @Override + public void onNext(final T item) { + consumer.accept(item); + subscription.request(1L); + } + + @Override + public void onError(final Throwable throwable) { + throw new IllegalStateException(throwable); + } + + @Override + public void onComplete() { + } +} diff --git a/src/main/java/ifml3/api/connector/ui/UIMessage.java b/src/main/java/ifml3/api/connector/ui/UIMessage.java new file mode 100644 index 0000000..65c56a5 --- /dev/null +++ b/src/main/java/ifml3/api/connector/ui/UIMessage.java @@ -0,0 +1,5 @@ +package ifml3.api.connector.ui; + +public interface UIMessage { + +} diff --git a/src/main/java/ifml3/api/engine/Engine.java b/src/main/java/ifml3/api/engine/Engine.java new file mode 100644 index 0000000..76b4516 --- /dev/null +++ b/src/main/java/ifml3/api/engine/Engine.java @@ -0,0 +1,8 @@ +package ifml3.api.engine; + +/** + * Story Engine. + */ +public interface Engine { + +} diff --git a/src/main/java/ifml3/api/engine/component/Component.java b/src/main/java/ifml3/api/engine/component/Component.java new file mode 100644 index 0000000..0dd91ec --- /dev/null +++ b/src/main/java/ifml3/api/engine/component/Component.java @@ -0,0 +1,8 @@ +package ifml3.api.engine; + +/** + * Entity component. + */ +public interface Component { + +} diff --git a/src/main/java/ifml3/api/engine/entity/Entity.java b/src/main/java/ifml3/api/engine/entity/Entity.java new file mode 100644 index 0000000..9b71996 --- /dev/null +++ b/src/main/java/ifml3/api/engine/entity/Entity.java @@ -0,0 +1,44 @@ +package ifml3.api.engine.entity; + +import ifml3.api.engine.Component; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Story entity. + */ +public class Entity { + + private final UUID id; + private final Map, Component> components; + + public Entity() { + this(UUID.randomUUID()); + } + + public Entity(final UUID id) { + this.id = id; + this.components = new ConcurrentHashMap(); + } + + public UUID id() { + return id; + } + + public boolean has(final Class type) { + return components.containsKey(type); + } + + public void put(final Class type, final C value) { + components.put(type, value); + } + + public C get(final Class type) { + return type.cast(components.get(type)); + } + + public void remove(final Class type) { + components.remove(type); + } +} diff --git a/src/main/java/ifml3/api/engine/entity/EntityPool.java b/src/main/java/ifml3/api/engine/entity/EntityPool.java new file mode 100644 index 0000000..124b705 --- /dev/null +++ b/src/main/java/ifml3/api/engine/entity/EntityPool.java @@ -0,0 +1,30 @@ +package ifml3.api.engine.entity; + +import java.util.Collection; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Entites. + */ +public class EntityPool { + + private final Map entities; + + public EntityPool() { + entities = new ConcurrentHashMap<>(); + } + + public void add(final Entity entity) { + entities.put(entity.id(), entity); + } + + public Entity findById(final UUID id) { + return entities.get(id); + } + + public Collection findAll() { + return entities.values(); + } +} diff --git a/src/main/java/ifml3/api/engine/internal/BaseEngine.java b/src/main/java/ifml3/api/engine/internal/BaseEngine.java new file mode 100644 index 0000000..c8d1041 --- /dev/null +++ b/src/main/java/ifml3/api/engine/internal/BaseEngine.java @@ -0,0 +1,34 @@ +package ifml3.api.engine.internal; + +import ifml3.api.connector.ComponentConnector; +import ifml3.api.connector.engine.EngineMessage; +import ifml3.api.connector.internal.BaseSubscriber; +import ifml3.api.connector.ui.UIMessage; +import ifml3.api.engine.Engine; +import java.util.concurrent.Flow; +import java.util.concurrent.SubmissionPublisher; + +public class BaseEngine implements Engine, ComponentConnector { + + private final SubmissionPublisher publisher; + private final Flow.Subscriber subscriber; + + public BaseEngine() { + this.publisher = new SubmissionPublisher<>(); + this.subscriber = new BaseSubscriber<>(this::process); + } + + @Override + public Flow.Subscriber subscriber() { + return subscriber; + } + + @Override + public Flow.Publisher publisher() { + return publisher; + } + + private void process(final UIMessage message) { + //FIXME + } +} diff --git a/src/main/java/ifml3/api/engine/system/System.java b/src/main/java/ifml3/api/engine/system/System.java new file mode 100644 index 0000000..bdc51b7 --- /dev/null +++ b/src/main/java/ifml3/api/engine/system/System.java @@ -0,0 +1,9 @@ +package ifml3.api.engine; + +/** + * System for engine. + */ +public interface System { + + void update(long dt); +} diff --git a/src/main/java/ifml3/api/i18n/I18N.java b/src/main/java/ifml3/api/i18n/I18N.java new file mode 100644 index 0000000..8066a2e --- /dev/null +++ b/src/main/java/ifml3/api/i18n/I18N.java @@ -0,0 +1,20 @@ +package ifml3.api.i18n; + +import ifml3.api.i18n.internal.AppI18N; +import java.util.ResourceBundle; + +@FunctionalInterface +public interface I18N { + + String message(Message message); + + @FunctionalInterface + interface Message { + + String key(); + } + + static I18N create(final ResourceBundle bundle) { + return new AppI18N(bundle); + } +} diff --git a/src/main/java/ifml3/app/i18n/AppTranslation.java b/src/main/java/ifml3/api/i18n/internal/AppI18N.java similarity index 67% rename from src/main/java/ifml3/app/i18n/AppTranslation.java rename to src/main/java/ifml3/api/i18n/internal/AppI18N.java index d3fb690..5a5312c 100644 --- a/src/main/java/ifml3/app/i18n/AppTranslation.java +++ b/src/main/java/ifml3/api/i18n/internal/AppI18N.java @@ -1,13 +1,14 @@ -package ifml3.app.i18n; +package ifml3.api.i18n.internal; +import ifml3.api.i18n.I18N; import java.util.Objects; import java.util.ResourceBundle; -public class AppTranslation implements Translation { +public class AppI18N implements I18N { private final ResourceBundle bundle; - public AppTranslation(final ResourceBundle bundle) { + public AppI18N(final ResourceBundle bundle) { this.bundle = bundle; } diff --git a/src/main/java/ifml3/api/i18n/package-info.java b/src/main/java/ifml3/api/i18n/package-info.java new file mode 100644 index 0000000..03a7df8 --- /dev/null +++ b/src/main/java/ifml3/api/i18n/package-info.java @@ -0,0 +1,4 @@ +/** + * Internalization classes. + */ +package ifml3.api.i18n; diff --git a/src/main/java/ifml3/app/Ifml3App.java b/src/main/java/ifml3/app/Ifml3App.java index cb73d92..0fa3fe5 100644 --- a/src/main/java/ifml3/app/Ifml3App.java +++ b/src/main/java/ifml3/app/Ifml3App.java @@ -1,27 +1,57 @@ package ifml3.app; import ifml3.app.i18n.AppMessage; -import ifml3.app.i18n.AppTranslation; -import ifml3.app.i18n.Translation; import ifml3.app.view.MainView; import ifml3.app.view.View; +import ifml3.app.view.ui.internal.PlayerComponent; +import ifml3.engine.Engine; +import ifml3.engine.internal.SimpleEngine; +import ifml3.lexer.Lexer; +import ifml3.lexer.internal.SimpleLexer; import java.util.ResourceBundle; import javafx.application.Application; import javafx.stage.Stage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ifml3.api.i18n.I18N; public class Ifml3App extends Application { - private Translation translation; + private static final Logger logger = LoggerFactory.getLogger(Ifml3App.class); + + private I18N translation; private View view; + private PlayerComponent player; + private Lexer lexer; + private Engine engine; @Override public void init() { - this.translation = new AppTranslation(ResourceBundle.getBundle("lang/ifml3")); - this.view = new MainView(translation); + logger.info("Initialization..."); + this.translation = I18N.create(ResourceBundle.getBundle("lang/ifml3")); + final var mainView = new MainView(translation); + this.view = mainView; + this.player = mainView.player(); + this.lexer = new SimpleLexer(); + this.engine = new SimpleEngine(); + connectComponents(); + } + + private void connectComponents() { + logger.info("Connect components"); + final var playerConnector = player.uiConnector(); + final var uiConnector = lexer.uiConnector(); + final var engineConnector = lexer.engineConnector(); + final var lexerConnector = engine.lexerConnector(); + playerConnector.publisher().subscribe(uiConnector.subscriber()); + uiConnector.publisher().subscribe(playerConnector.subscriber()); + lexerConnector.publisher().subscribe(engineConnector.subscriber()); + engineConnector.publisher().subscribe(lexerConnector.subscriber()); } @Override public void start(final Stage stage) throws Exception { + logger.info("Start application"); stage.setScene(view.scene()); stage.setTitle(translation.message(AppMessage.APP_TITLE)); stage.show(); diff --git a/src/main/java/ifml3/app/i18n/AppMessage.java b/src/main/java/ifml3/app/i18n/AppMessage.java index 950706a..c175a94 100644 --- a/src/main/java/ifml3/app/i18n/AppMessage.java +++ b/src/main/java/ifml3/app/i18n/AppMessage.java @@ -1,6 +1,6 @@ package ifml3.app.i18n; -import ifml3.app.i18n.Translation.Message; +import ifml3.api.i18n.I18N.Message; public enum AppMessage implements Message { APP_TITLE("app.title"), diff --git a/src/main/java/ifml3/app/i18n/Translation.java b/src/main/java/ifml3/app/i18n/Translation.java deleted file mode 100644 index eee49f6..0000000 --- a/src/main/java/ifml3/app/i18n/Translation.java +++ /dev/null @@ -1,13 +0,0 @@ -package ifml3.app.i18n; - -@FunctionalInterface -public interface Translation { - - String message(Message message); - - @FunctionalInterface - interface Message { - - String key(); - } -} diff --git a/src/main/java/ifml3/app/view/MainView.java b/src/main/java/ifml3/app/view/MainView.java index 4e831a7..67be5d7 100644 --- a/src/main/java/ifml3/app/view/MainView.java +++ b/src/main/java/ifml3/app/view/MainView.java @@ -1,7 +1,8 @@ package ifml3.app.view; +import ifml3.api.connector.ComponentConnector; import ifml3.app.i18n.AppMessage; -import ifml3.app.i18n.Translation; +import ifml3.app.view.ui.internal.PlayerComponent; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; @@ -9,15 +10,18 @@ import javafx.scene.control.MenuBar; import javafx.scene.control.TreeView; import javafx.scene.layout.BorderPane; +import ifml3.api.i18n.I18N; public class MainView implements View { - private final Translation translation; + private final I18N translation; private final Scene scene; + private final PlayerComponent player; - public MainView(final Translation translation) { + public MainView(final I18N translation) { this.translation = translation; - final var pane = new BorderPane(label("center"), menuBar(), label("right"), inputLine(), treeView()); + this.player = new PlayerComponent(); + final var pane = new BorderPane(player.get(), menuBar(), label("right"), inputLine(), treeView()); scene = new Scene(pane, 800.0, 600.0); } @@ -26,6 +30,10 @@ public Scene scene() { return scene; } + public PlayerComponent player() { + return player; + } + private Label label(final String text) { return new Label(text); } diff --git a/src/main/java/ifml3/app/view/ui/UIComponent.java b/src/main/java/ifml3/app/view/ui/UIComponent.java new file mode 100644 index 0000000..519729e --- /dev/null +++ b/src/main/java/ifml3/app/view/ui/UIComponent.java @@ -0,0 +1,8 @@ +package ifml3.app.view.ui; + +import javafx.scene.Parent; + +public interface UIComponent { + + Parent get(); +} diff --git a/src/main/java/ifml3/app/view/ui/internal/PlayerComponent.java b/src/main/java/ifml3/app/view/ui/internal/PlayerComponent.java new file mode 100644 index 0000000..835edbf --- /dev/null +++ b/src/main/java/ifml3/app/view/ui/internal/PlayerComponent.java @@ -0,0 +1,71 @@ +package ifml3.app.view.ui.internal; + +import ifml3.api.connector.ComponentConnector; +import ifml3.api.connector.internal.BaseSubscriber; +import ifml3.app.view.ui.UIComponent; +import ifml3.ui.TextSanitizer; +import ifml3.ui.UserCommand; +import ifml3.ui.UserInterface; +import ifml3.ui.UserMessage; +import ifml3.ui.internal.UserTextSanitizer; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.SubmissionPublisher; +import javafx.event.ActionEvent; +import javafx.scene.Parent; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PlayerComponent implements UIComponent, UserInterface { + + private static final Logger logger = LoggerFactory.getLogger(PlayerComponent.class); + + private final SubmissionPublisher publisher; + private final Subscriber subscriber; + private final TextSanitizer sanitizer; + private final ComponentConnector connector; + private final VBox vBox; + private final TextArea textArea; + private final TextField textField; + + public PlayerComponent() { + // @todo at least sanitizer should be as dependency + this.sanitizer = new UserTextSanitizer(); + this.publisher = new SubmissionPublisher<>(); + this.textArea = new TextArea(); + this.textArea.setEditable(false); + this.textArea.setPrefRowCount(1_000); + this.textField = new TextField(); + this.textField.setOnAction(this::processCommand); + this.vBox = new VBox(textArea, textField); + this.subscriber = new BaseSubscriber<>(this::processMessage); + this.connector = ComponentConnector.create(subscriber, publisher); + } + + @Override + public Parent get() { + return vBox; + } + + @Override + public ComponentConnector uiConnector() { + return connector; + } + + private void processCommand(final ActionEvent event) { + final var text = textField.getText(); + logger.info("Input from user: '{}'", text); + textField.setText(""); + textArea.appendText("> " + text + "\n"); + final var input = sanitizer.sanitize(text); + // @todo preprocessing needed + publisher.submit(() -> input); + } + + private void processMessage(final UserMessage message) { + logger.info("Get message for user: {}", message); + textArea.appendText("\n" + message.message() + "\n\n"); + } +} diff --git a/src/main/java/ifml3/engine/Engine.java b/src/main/java/ifml3/engine/Engine.java new file mode 100644 index 0000000..c97a340 --- /dev/null +++ b/src/main/java/ifml3/engine/Engine.java @@ -0,0 +1,8 @@ +package ifml3.engine; + +import ifml3.api.connector.ComponentConnector; + +public interface Engine { + + ComponentConnector lexerConnector(); +} diff --git a/src/main/java/ifml3/engine/EngineCommand.java b/src/main/java/ifml3/engine/EngineCommand.java new file mode 100644 index 0000000..7dd545f --- /dev/null +++ b/src/main/java/ifml3/engine/EngineCommand.java @@ -0,0 +1,10 @@ +package ifml3.engine; + +import ifml3.lexer.Phrase; +import java.util.Collection; + +@FunctionalInterface +public interface EngineCommand { + + Collection phrases(); +} diff --git a/src/main/java/ifml3/engine/EngineMessage.java b/src/main/java/ifml3/engine/EngineMessage.java new file mode 100644 index 0000000..4a1e2f2 --- /dev/null +++ b/src/main/java/ifml3/engine/EngineMessage.java @@ -0,0 +1,7 @@ +package ifml3.engine; + +@FunctionalInterface +public interface EngineMessage { + + String message(); +} diff --git a/src/main/java/ifml3/engine/internal/SimpleEngine.java b/src/main/java/ifml3/engine/internal/SimpleEngine.java new file mode 100644 index 0000000..cb107c0 --- /dev/null +++ b/src/main/java/ifml3/engine/internal/SimpleEngine.java @@ -0,0 +1,31 @@ +package ifml3.engine.internal; + +import ifml3.api.connector.ComponentConnector; +import ifml3.api.connector.internal.BaseSubscriber; +import ifml3.engine.Engine; +import ifml3.engine.EngineCommand; +import ifml3.engine.EngineMessage; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.SubmissionPublisher; + +public class SimpleEngine implements Engine { + + private final SubmissionPublisher publisher; + private final Subscriber subscriber; + private final ComponentConnector connector; + + public SimpleEngine() { + publisher = new SubmissionPublisher(); + subscriber = new BaseSubscriber<>(this::processCommand); + connector = ComponentConnector.create(subscriber, publisher); + } + + @Override + public ComponentConnector lexerConnector() { + return connector; + } + + private void processCommand(final EngineCommand command) { + publisher.submit("engine: непонятная команда."); + } +} diff --git a/src/main/java/ifml3/infra/package-info.java b/src/main/java/ifml3/infra/package-info.java new file mode 100644 index 0000000..8757052 --- /dev/null +++ b/src/main/java/ifml3/infra/package-info.java @@ -0,0 +1,4 @@ +/** + * Infrastructure classes. + */ +package ifml3.infra; diff --git a/src/main/java/ifml3/lexer/Dictionary.java b/src/main/java/ifml3/lexer/Dictionary.java new file mode 100644 index 0000000..8f3d658 --- /dev/null +++ b/src/main/java/ifml3/lexer/Dictionary.java @@ -0,0 +1,11 @@ +package ifml3.lexer; + +import ifml3.lexer.dictionary.Word; +import java.util.Set; + +public interface Dictionary { + + Set find(String text); + + Set findOrAdd(String text); +} diff --git a/src/main/java/ifml3/lexer/Lexer.java b/src/main/java/ifml3/lexer/Lexer.java new file mode 100644 index 0000000..52fe079 --- /dev/null +++ b/src/main/java/ifml3/lexer/Lexer.java @@ -0,0 +1,14 @@ +package ifml3.lexer; + +import ifml3.api.connector.ComponentConnector; +import ifml3.engine.EngineCommand; +import ifml3.engine.EngineMessage; +import ifml3.ui.UserCommand; +import ifml3.ui.UserMessage; + +public interface Lexer { + + ComponentConnector uiConnector(); + + ComponentConnector engineConnector(); +} diff --git a/src/main/java/ifml3/lexer/Phrase.java b/src/main/java/ifml3/lexer/Phrase.java new file mode 100644 index 0000000..bb1b40b --- /dev/null +++ b/src/main/java/ifml3/lexer/Phrase.java @@ -0,0 +1,5 @@ +package ifml3.lexer; + +public interface Phrase { + +} diff --git a/src/main/java/ifml3/lexer/dictionary/Word.java b/src/main/java/ifml3/lexer/dictionary/Word.java new file mode 100644 index 0000000..bd94e57 --- /dev/null +++ b/src/main/java/ifml3/lexer/dictionary/Word.java @@ -0,0 +1,12 @@ +package ifml3.lexer.dictionary; + +public interface Word { + + String text(); + + Word initForm(); + + default boolean isInitForm() { + return this == initForm(); + } +} diff --git a/src/main/java/ifml3/lexer/dictionary/internal/NounWord.java b/src/main/java/ifml3/lexer/dictionary/internal/NounWord.java new file mode 100644 index 0000000..dd1916c --- /dev/null +++ b/src/main/java/ifml3/lexer/dictionary/internal/NounWord.java @@ -0,0 +1,11 @@ +package ifml3.lexer.dictionary.internal; + +import ifml3.lexer.dictionary.Word; + +public record NounWord(String text) implements Word { + + @Override + public Word initForm() { + return this; + } +} diff --git a/src/main/java/ifml3/lexer/dictionary/internal/UnknownWord.java b/src/main/java/ifml3/lexer/dictionary/internal/UnknownWord.java new file mode 100644 index 0000000..619eba8 --- /dev/null +++ b/src/main/java/ifml3/lexer/dictionary/internal/UnknownWord.java @@ -0,0 +1,11 @@ +package ifml3.lexer.dictionary.internal; + +import ifml3.lexer.dictionary.Word; + +public record UnknownWord(String text) implements Word { + + @Override + public Word initForm() { + return this; + } +} diff --git a/src/main/java/ifml3/lexer/dictionary/internal/VerbWord.java b/src/main/java/ifml3/lexer/dictionary/internal/VerbWord.java new file mode 100644 index 0000000..009c2e9 --- /dev/null +++ b/src/main/java/ifml3/lexer/dictionary/internal/VerbWord.java @@ -0,0 +1,11 @@ +package ifml3.lexer.dictionary.internal; + +import ifml3.lexer.dictionary.Word; + +public record VerbWord(String text) implements Word { + + @Override + public Word initForm() { + return this; + } +} diff --git a/src/main/java/ifml3/lexer/internal/SimpleDictionary.java b/src/main/java/ifml3/lexer/internal/SimpleDictionary.java new file mode 100644 index 0000000..d54fec8 --- /dev/null +++ b/src/main/java/ifml3/lexer/internal/SimpleDictionary.java @@ -0,0 +1,51 @@ +package ifml3.lexer.internal; + +import ifml3.lexer.Dictionary; +import ifml3.lexer.dictionary.Word; +import ifml3.lexer.dictionary.internal.UnknownWord; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpleDictionary implements Dictionary { + + private static final Logger logger = LoggerFactory.getLogger(SimpleDictionary.class); + + private Map> words; + + public SimpleDictionary() { + this(new ConcurrentHashMap<>()); + } + + public SimpleDictionary(Map> words) { + this.words = words; + } + + @Override + public Set find(final String text) { + logger.info("Try to find word: {}", text); + if (words.containsKey(text)) { + return words.get(text); + } + logger.info("not found"); + return Collections.emptySet(); + } + + @Override + public Set findOrAdd(final String text) { + logger.info("Try to find word: {}", text); + if (words.containsKey(text)) { + return words.get(text); + } + logger.info("now found will be added as unkown word: {}", text); + final var set = new HashSet(); + final var word = new UnknownWord(text); + set.add(word); + words.put(text, set); + return set; + } +} diff --git a/src/main/java/ifml3/lexer/internal/SimpleLexer.java b/src/main/java/ifml3/lexer/internal/SimpleLexer.java new file mode 100644 index 0000000..47af1d2 --- /dev/null +++ b/src/main/java/ifml3/lexer/internal/SimpleLexer.java @@ -0,0 +1,80 @@ +package ifml3.lexer.internal; + +import ifml3.api.connector.ComponentConnector; +import ifml3.api.connector.internal.BaseComponentConnector; +import ifml3.api.connector.internal.BaseSubscriber; +import ifml3.engine.EngineCommand; +import ifml3.engine.EngineMessage; +import ifml3.lexer.Dictionary; +import ifml3.lexer.Lexer; +import ifml3.lexer.Phrase; +import ifml3.lexer.dictionary.Word; +import ifml3.ui.UserCommand; +import ifml3.ui.UserMessage; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.Flow.Subscriber; +import java.util.concurrent.SubmissionPublisher; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpleLexer implements Lexer { + + private static final Logger logger = LoggerFactory.getLogger(SimpleLexer.class); + + private final Dictionary dictionary; + private final SubmissionPublisher uiPublisher; + private final Subscriber uiSubscriber; + private final ComponentConnector uiConnector; + private final SubmissionPublisher enginePublisher; + private final Subscriber engineSubscriber; + private final ComponentConnector engineConnector; + + public SimpleLexer() { + this.dictionary = new SimpleDictionary(); + this.uiPublisher = new SubmissionPublisher<>(); + this.uiSubscriber = new BaseSubscriber<>(this::processUserCommand); + this.uiConnector = new BaseComponentConnector<>(uiSubscriber, uiPublisher); + this.enginePublisher = new SubmissionPublisher<>(); + this.engineSubscriber = new BaseSubscriber<>(this::processEngineMessage); + this.engineConnector = new BaseComponentConnector<>(engineSubscriber, enginePublisher); + } + + @Override + public ComponentConnector uiConnector() { + return uiConnector; + } + + @Override + public ComponentConnector engineConnector() { + return engineConnector; + } + + private void processUserCommand(final UserCommand command) { + logger.info("Got command from user: {}", command); + final var text = command.command(); + final var wordSets = Stream.of(text.split(" ")) + .map(dictionary::find) + .collect(Collectors.toList()); + final var phrases = toPhrases(wordSets); + if (null == phrases || phrases.isEmpty()) { + uiPublisher.submit(() -> "мне не понятно: " + text); + } else { + enginePublisher.submit(() -> phrases); + } + } + + private void processEngineMessage(final EngineMessage message) { + logger.info("Got message from engine: {}", message); + // @todo: process possible templates + uiPublisher.submit(() -> message.message()); + } + + private Collection toPhrases(final Collection> wordSets) { + // @todo: logic to build phrases + return Collections.emptyList(); + } +} diff --git a/src/main/java/ifml3/lexer/package-info.java b/src/main/java/ifml3/lexer/package-info.java new file mode 100644 index 0000000..89281e3 --- /dev/null +++ b/src/main/java/ifml3/lexer/package-info.java @@ -0,0 +1,4 @@ +/** + * The dictionary. + */ +package ifml3.lexer.dictionary; diff --git a/src/main/java/ifml3/story/Story.java b/src/main/java/ifml3/story/Story.java deleted file mode 100644 index 745611f..0000000 --- a/src/main/java/ifml3/story/Story.java +++ /dev/null @@ -1,32 +0,0 @@ -package ifml3.story; - -public class Story { - - private String name; - - private Story(Builder builder) { - this.name = builder.name; - } - - public String name() { - return name; - } - - public static Builder buidler() { - return new Builder(); - } - - public static class Builder { - - private String name; - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Story build() { - return new Story(this); - } - } -} diff --git a/src/main/java/ifml3/story/package-info.java b/src/main/java/ifml3/story/package-info.java deleted file mode 100644 index 01021c9..0000000 --- a/src/main/java/ifml3/story/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Story classes. - */ -package ifml3.story; diff --git a/src/main/java/ifml3/ui/TextSanitizer.java b/src/main/java/ifml3/ui/TextSanitizer.java new file mode 100644 index 0000000..f634cab --- /dev/null +++ b/src/main/java/ifml3/ui/TextSanitizer.java @@ -0,0 +1,6 @@ +package ifml3.ui; + +public interface TextSanitizer { + + String sanitize(String text); +} diff --git a/src/main/java/ifml3/ui/UserCommand.java b/src/main/java/ifml3/ui/UserCommand.java new file mode 100644 index 0000000..31b7a93 --- /dev/null +++ b/src/main/java/ifml3/ui/UserCommand.java @@ -0,0 +1,7 @@ +package ifml3.ui; + +@FunctionalInterface +public interface UserCommand { + + String command(); +} diff --git a/src/main/java/ifml3/ui/UserInterface.java b/src/main/java/ifml3/ui/UserInterface.java new file mode 100644 index 0000000..f7d9f87 --- /dev/null +++ b/src/main/java/ifml3/ui/UserInterface.java @@ -0,0 +1,8 @@ +package ifml3.ui; + +import ifml3.api.connector.ComponentConnector; + +public interface UserInterface { + + ComponentConnector uiConnector(); +} diff --git a/src/main/java/ifml3/ui/UserMessage.java b/src/main/java/ifml3/ui/UserMessage.java new file mode 100644 index 0000000..083c0f2 --- /dev/null +++ b/src/main/java/ifml3/ui/UserMessage.java @@ -0,0 +1,7 @@ +package ifml3.ui; + +@FunctionalInterface +public interface UserMessage { + + String message(); +} diff --git a/src/main/java/ifml3/ui/internal/UserTextSanitizer.java b/src/main/java/ifml3/ui/internal/UserTextSanitizer.java new file mode 100644 index 0000000..8cf2264 --- /dev/null +++ b/src/main/java/ifml3/ui/internal/UserTextSanitizer.java @@ -0,0 +1,11 @@ +package ifml3.ui.internal; + +import ifml3.ui.TextSanitizer; + +public class UserTextSanitizer implements TextSanitizer { + + @Override + public String sanitize(final String text) { + return text.replaceAll("\\.", ""); + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..85f1c58 --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,9 @@ +module ifml3.app { + requires javafx.base; + requires javafx.controls; + requires java.base; + requires org.slf4j; + requires org.slf4j.simple; + + exports ifml3.app; +} diff --git a/src/test/java/ifml3/app/i18n/ResourceBundleTest.java b/src/test/java/ifml3/app/i18n/ResourceBundleTest.java index 756cd60..797892d 100644 --- a/src/test/java/ifml3/app/i18n/ResourceBundleTest.java +++ b/src/test/java/ifml3/app/i18n/ResourceBundleTest.java @@ -2,8 +2,8 @@ import java.util.ResourceBundle; import java.util.stream.Stream; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/ifml3/ui/TextSanitizerTest.java b/src/test/java/ifml3/ui/TextSanitizerTest.java new file mode 100644 index 0000000..6e6e7b5 --- /dev/null +++ b/src/test/java/ifml3/ui/TextSanitizerTest.java @@ -0,0 +1,25 @@ +package ifml3.ui; + +import ifml3.ui.internal.UserTextSanitizer; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Text Sanitizer") +public class TextSanitizerTest { + + @Test + @DisplayName("can process simple text") + public void testSimpleText() { + final var sanitizer = new UserTextSanitizer(); + Assertions.assertEquals("просто текст", sanitizer.sanitize("просто текст")); + } + + @Test + @DisplayName("can remove dots") + public void testRemoveDots() { + final var sanitizer = new UserTextSanitizer(); + Assertions.assertEquals("ну, не очень так", sanitizer.sanitize("ну, не очень... так.")); + } +}