diff --git a/connector/.fleet/receipt.json b/connector/.fleet/receipt.json new file mode 100644 index 0000000..beb1373 --- /dev/null +++ b/connector/.fleet/receipt.json @@ -0,0 +1,19 @@ +// Project generated by Kotlin Multiplatform Wizard +{ + "spec": { + "template_id": "kmt", + "targets": { + "desktop": { + "ui": [ + "compose" + ] + }, + "server": { + "engine": [ + "ktor" + ] + } + } + }, + "timestamp": "2024-03-30T17:11:47.077783195Z" +} \ No newline at end of file diff --git a/connector/.gitignore b/connector/.gitignore new file mode 100644 index 0000000..33e4c75 --- /dev/null +++ b/connector/.gitignore @@ -0,0 +1,17 @@ +*.iml +.gradle +**/build/ +xcuserdata +!src/**/build/ +local.properties +.idea +.DS_Store +captures +.externalNativeBuild +.cxx +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +**/xcshareddata/WorkspaceSettings.xcsettings diff --git a/connector/README.md b/connector/README.md new file mode 100644 index 0000000..cd5abd6 --- /dev/null +++ b/connector/README.md @@ -0,0 +1,16 @@ +This is a Kotlin Multiplatform project targeting Desktop, Server. + +* `/composeApp` is for code that will be shared across your Compose Multiplatform applications. + It contains several subfolders: + - `commonMain` is for code that’s common for all targets. + - Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name. + For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app, + `iosMain` would be the right folder for such calls. + +* `/server` is for the Ktor server application. + +* `/shared` is for the code that will be shared between all targets in the project. + The most important subfolder is `commonMain`. If preferred, you can add code to the platform-specific folders here too. + + +Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)… \ No newline at end of file diff --git a/connector/build.gradle.kts b/connector/build.gradle.kts index 93ac316..1c52932 100644 --- a/connector/build.gradle.kts +++ b/connector/build.gradle.kts @@ -1,23 +1,7 @@ plugins { - kotlin("jvm") version "1.9.23" -} - -group = "io.anthonyberg" -version = "1.0-SNAPSHOT" - -repositories { - mavenCentral() -} - -dependencies { - implementation("dk.au.ece.vdmj:vdmj:4.5.0") - testImplementation("org.jetbrains.kotlin:kotlin-test") -} - -tasks.test { - useJUnitPlatform() -} - -kotlin { - jvmToolchain(21) -} + // this is necessary to avoid the plugins to be loaded multiple times + // in each subproject's classloader + alias(libs.plugins.jetbrainsCompose) apply false + alias(libs.plugins.kotlinJvm) apply false + alias(libs.plugins.kotlinMultiplatform) apply false +} \ No newline at end of file diff --git a/connector/composeApp/build.gradle.kts b/connector/composeApp/build.gradle.kts new file mode 100644 index 0000000..6c988e1 --- /dev/null +++ b/connector/composeApp/build.gradle.kts @@ -0,0 +1,41 @@ +import org.jetbrains.compose.desktop.application.dsl.TargetFormat + +plugins { + alias(libs.plugins.kotlinMultiplatform) + + alias(libs.plugins.jetbrainsCompose) +} + +kotlin { + jvm("desktop") + + sourceSets { + val desktopMain by getting + + commonMain.dependencies { + implementation(compose.runtime) + implementation(compose.foundation) + implementation(compose.material) + implementation(compose.ui) + implementation(compose.components.resources) + implementation(compose.components.uiToolingPreview) + implementation(projects.shared) + } + desktopMain.dependencies { + implementation(compose.desktop.currentOs) + } + } +} + + +compose.desktop { + application { + mainClass = "MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "io.anthonyberg.connector" + packageVersion = "1.0.0" + } + } +} diff --git a/connector/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml b/connector/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml new file mode 100644 index 0000000..d7bf795 --- /dev/null +++ b/connector/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml @@ -0,0 +1,36 @@ + + + + + + + + diff --git a/connector/composeApp/src/desktopMain/kotlin/App.kt b/connector/composeApp/src/desktopMain/kotlin/App.kt new file mode 100644 index 0000000..6fdf8fc --- /dev/null +++ b/connector/composeApp/src/desktopMain/kotlin/App.kt @@ -0,0 +1,37 @@ +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.Button +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import org.jetbrains.compose.resources.ExperimentalResourceApi +import org.jetbrains.compose.resources.painterResource +import org.jetbrains.compose.ui.tooling.preview.Preview + +import connector.composeapp.generated.resources.Res +import connector.composeapp.generated.resources.compose_multiplatform + +@OptIn(ExperimentalResourceApi::class) +@Composable +@Preview +fun App() { + MaterialTheme { + var showContent by remember { mutableStateOf(false) } + Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { + Button(onClick = { showContent = !showContent }) { + Text("Click me!") + } + AnimatedVisibility(showContent) { + val greeting = remember { Greeting().greet() } + Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { + Image(painterResource(Res.drawable.compose_multiplatform), null) + Text("Compose: $greeting") + } + } + } + } +} \ No newline at end of file diff --git a/connector/composeApp/src/desktopMain/kotlin/main.kt b/connector/composeApp/src/desktopMain/kotlin/main.kt new file mode 100644 index 0000000..8a046f8 --- /dev/null +++ b/connector/composeApp/src/desktopMain/kotlin/main.kt @@ -0,0 +1,9 @@ +import androidx.compose.runtime.Composable +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.application + +fun main() = application { + Window(onCloseRequest = ::exitApplication, title = "connector") { + App() + } +} \ No newline at end of file diff --git a/connector/gradle.properties b/connector/gradle.properties new file mode 100644 index 0000000..ded57be --- /dev/null +++ b/connector/gradle.properties @@ -0,0 +1,9 @@ +kotlin.code.style=official + +#Gradle +org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" + + + +#Development +development=true \ No newline at end of file diff --git a/connector/gradle/libs.versions.toml b/connector/gradle/libs.versions.toml new file mode 100644 index 0000000..8fa039d --- /dev/null +++ b/connector/gradle/libs.versions.toml @@ -0,0 +1,24 @@ +[versions] +compose = "1.6.2" +compose-plugin = "1.6.0" +junit = "4.13.2" +kotlin = "1.9.22" +ktor = "2.3.9" +logback = "1.5.3" + +[libraries] +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } +junit = { group = "junit", name = "junit", version.ref = "junit" } +compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } +compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } +logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } +ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" } +ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" } +ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" } + +[plugins] +jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } +kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +ktor = { id = "io.ktor.plugin", version.ref = "ktor" } +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } \ No newline at end of file diff --git a/connector/gradle/wrapper/gradle-wrapper.properties b/connector/gradle/wrapper/gradle-wrapper.properties index 9f57aa1..3fa8f86 100644 --- a/connector/gradle/wrapper/gradle-wrapper.properties +++ b/connector/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Fri Mar 29 17:41:10 CET 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/connector/gradlew b/connector/gradlew index 1b6c787..fcb6fca 100755 --- a/connector/gradlew +++ b/connector/gradlew @@ -55,7 +55,7 @@ # 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 +# https://github.com/gradle/gradle/blob/HEAD/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/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 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"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +130,29 @@ 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. + if ! command -v java >/dev/null 2>&1 + then + 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 fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# 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"' + # 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 @@ -205,6 +213,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/connector/gradlew.bat b/connector/gradlew.bat index 107acd3..93e3f59 100644 --- a/connector/gradlew.bat +++ b/connector/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/connector/server/build.gradle.kts b/connector/server/build.gradle.kts new file mode 100644 index 0000000..32ad529 --- /dev/null +++ b/connector/server/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + alias(libs.plugins.kotlinJvm) + alias(libs.plugins.ktor) + application +} + +group = "io.anthonyberg.connector" +version = "1.0.0" +application { + mainClass.set("io.anthonyberg.connector.ApplicationKt") + applicationDefaultJvmArgs = listOf("-Dio.ktor.development=${extra["development"] ?: "false"}") +} + +dependencies { + implementation(projects.shared) + implementation(libs.logback) + implementation(libs.ktor.server.core) + implementation(libs.ktor.server.netty) + testImplementation(libs.ktor.server.tests) + testImplementation(libs.kotlin.test.junit) + + implementation("dk.au.ece.vdmj:vdmj:4.5.0") +} diff --git a/connector/server/src/main/kotlin/io/anthonyberg/connector/Application.kt b/connector/server/src/main/kotlin/io/anthonyberg/connector/Application.kt new file mode 100644 index 0000000..8ea2d38 --- /dev/null +++ b/connector/server/src/main/kotlin/io/anthonyberg/connector/Application.kt @@ -0,0 +1,22 @@ +package io.anthonyberg.connector + +import Greeting +import SERVER_PORT +import io.ktor.server.application.* +import io.ktor.server.engine.* +import io.ktor.server.netty.* +import io.ktor.server.response.* +import io.ktor.server.routing.* + +fun main() { + embeddedServer(Netty, port = SERVER_PORT, host = "0.0.0.0", module = Application::module) + .start(wait = true) +} + +fun Application.module() { + routing { + get("/") { + call.respondText("Ktor: ${Greeting().greet()}") + } + } +} \ No newline at end of file diff --git a/connector/src/main/kotlin/VDMJ.kt b/connector/server/src/main/kotlin/io/anthonyberg/connector/VDMJ.kt similarity index 95% rename from connector/src/main/kotlin/VDMJ.kt rename to connector/server/src/main/kotlin/io/anthonyberg/connector/VDMJ.kt index 02d27e7..a8d6e28 100644 --- a/connector/src/main/kotlin/VDMJ.kt +++ b/connector/server/src/main/kotlin/io/anthonyberg/connector/VDMJ.kt @@ -1,4 +1,4 @@ -package io.anthonyberg +package io.anthonyberg.connector import com.fujitsu.vdmj.ExitStatus import com.fujitsu.vdmj.Settings diff --git a/connector/server/src/main/resources/logback.xml b/connector/server/src/main/resources/logback.xml new file mode 100644 index 0000000..bdbb64e --- /dev/null +++ b/connector/server/src/main/resources/logback.xml @@ -0,0 +1,12 @@ + + + + %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + diff --git a/connector/settings.gradle.kts b/connector/settings.gradle.kts index 17bb23c..a8a632c 100644 --- a/connector/settings.gradle.kts +++ b/connector/settings.gradle.kts @@ -1,5 +1,23 @@ -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" -} rootProject.name = "connector" +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +pluginManagement { + repositories { + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + google() + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + } +} + +include(":composeApp") +include(":server") +include(":shared") \ No newline at end of file diff --git a/connector/shared/build.gradle.kts b/connector/shared/build.gradle.kts new file mode 100644 index 0000000..b33a8fa --- /dev/null +++ b/connector/shared/build.gradle.kts @@ -0,0 +1,16 @@ + +plugins { + alias(libs.plugins.kotlinMultiplatform) + +} + +kotlin { + jvm() + + sourceSets { + commonMain.dependencies { + // put your Multiplatform dependencies here + } + } +} + diff --git a/connector/shared/src/commonMain/kotlin/Constants.kt b/connector/shared/src/commonMain/kotlin/Constants.kt new file mode 100644 index 0000000..6210230 --- /dev/null +++ b/connector/shared/src/commonMain/kotlin/Constants.kt @@ -0,0 +1 @@ +const val SERVER_PORT = 8080 \ No newline at end of file diff --git a/connector/shared/src/commonMain/kotlin/Greeting.kt b/connector/shared/src/commonMain/kotlin/Greeting.kt new file mode 100644 index 0000000..887d835 --- /dev/null +++ b/connector/shared/src/commonMain/kotlin/Greeting.kt @@ -0,0 +1,7 @@ +class Greeting { + private val platform = getPlatform() + + fun greet(): String { + return "Hello, ${platform.name}!" + } +} \ No newline at end of file diff --git a/connector/shared/src/commonMain/kotlin/Platform.kt b/connector/shared/src/commonMain/kotlin/Platform.kt new file mode 100644 index 0000000..87ca3ff --- /dev/null +++ b/connector/shared/src/commonMain/kotlin/Platform.kt @@ -0,0 +1,5 @@ +interface Platform { + val name: String +} + +expect fun getPlatform(): Platform \ No newline at end of file diff --git a/connector/shared/src/jvmMain/kotlin/Platform.jvm.kt b/connector/shared/src/jvmMain/kotlin/Platform.jvm.kt new file mode 100644 index 0000000..f5e7e49 --- /dev/null +++ b/connector/shared/src/jvmMain/kotlin/Platform.jvm.kt @@ -0,0 +1,5 @@ +class JVMPlatform: Platform { + override val name: String = "Java ${System.getProperty("java.version")}" +} + +actual fun getPlatform(): Platform = JVMPlatform() \ No newline at end of file diff --git a/connector/src/main/kotlin/Main.kt b/connector/src/main/kotlin/Main.kt deleted file mode 100644 index a2da457..0000000 --- a/connector/src/main/kotlin/Main.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.anthonyberg - -fun main() { - // Open VDMJ - val VDMJ = VDMJ() -} diff --git a/connector/src/main/resources/checklist.vdmsl b/connector/src/main/resources/checklist.vdmsl deleted file mode 120000 index 9360f66..0000000 --- a/connector/src/main/resources/checklist.vdmsl +++ /dev/null @@ -1 +0,0 @@ -/home/smyalygames/Documents/dissertation/formal/checklist.vdmsl \ No newline at end of file