Skip to content

Commit

Permalink
refactor: kotlin multi-platform [DHIS2-16221] (#116)
Browse files Browse the repository at this point in the history
* chore: RuleContent and RuleEffects as records

* chore: RuleEvaluationResult as record

* chore: RuleValidationResult as record

* chore: removed unused TimeInterval

* chore: DataItem as record

* chore: RuleEngineExecution as record

* chore: RuleEngineMultipleExecution as record

* chore: RuleVariableValue as record

* chore: RuleEnrollment, RuleEvent as record

* chore: removed unused class SupplementaryData

* chore: RuleEngine as record

* chore: RuleVariableValueMap as record

* chore: cleanup RuleVariableValueMapBuilder

* chore: RuleAction hierarchy as records

* chore: RuleDataValue as record

* chore: general cleanup

* chore: RuleVariable hierarchy as records and interfaces

* chore: RuleAttributeValue as record

* chore: RuleActionAttribute hierarchy to records

* chore: general cleanuo

* chore: test cleanup

* chore: removed unused dependency

* chore: remove common lang dependency

* chore: replace joda time with java.time

* chore: removed equalsverifier dependency

* chore: replaced assertj with vanilla junit

* chore: replace @nullable with @checkfornull

* chore: removed mockito dependency

* chore: replace slf4j with java.util.logging

* chore: removed apache commons dependency

* chore: replace Arrays.asList with List.of

* chore: replace Arrays.asList with List.of

* chore: general cleanup

* chore: use KMP expression parser snapshot

* refactor: RuleEngine, RuleValidationResult, AttributeType to kotlin

* refactor: RuleEngineTest to kotlin

* refactor: RuleActionHideField to kotlin

* refactor RuleActionHideProgramStage to kotlin

* refactor enums to kotlin

* refactor rule effects to kotlin

* put list of envs back

* Update github actions

* refactor utils to kotlin

* refactor option and dataItem to kotlin

* refactor ruleVariableValueMap to kotlin

* refactor ruleVariableValueMap to kotlin

* refactor Rule to kotlin and all related tests

* refactor RuleEvent to kotlin

* refactor RuleEngineContext to kotlin

* refactor RuleEnrollment to kotlin

* refactor RuleVariable to kotlin

* Make data for RuleEffect optional

* refactor RuleVariableValue to kotlin

* refactor hide actions to kotlin

* refactor more actions to kotlin

* refactor send actions to kotlin

* refactor mandatory action to kotlin

* refactor message action to kotlin

* refactor rule values to kotlin

* refactor assign action to kotlin

* last conversions to kotlin

* Allow null data for actions

* Add type for text actions

* Bump shanpshot version

* Create KMP structure

* Remove java.util.Callable usages

* Remove java.util.Map usages

* Remove Logger and Dates usages

* Move implementation to common

* Move tests to common

* Move tests to common

* refactor: Clean up description call to rule engine (#117)

* refactor: Clean up description call to rule engine

* refactor: Clean up evaluation call to rule engine

* refactor: Clean up evaluation call to rule engine

* refactor: EventDate changed from LocalDate to Instant

* Refactor package structure

* Refactor package structure

* Fix RuleAction interface

* Fix RuleAction interface

* Fix RuleEngine API interface

* Make engine package internal

* Make rule engine getInstance static for Java

* Update build.gradle.kts

---------

Co-authored-by: Enrico <[email protected]>
Co-authored-by: Victor Garcia <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent 86c2617 commit c5c7085
Show file tree
Hide file tree
Showing 191 changed files with 8,671 additions and 10,988 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@ jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Test
run: mvn clean install -DskipTests=false --update-snapshots -q
run: ./gradlew clean allTests

artifact:
name: Publish - Nexus
runs-on: ubuntu-latest
needs: unit-test

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Release Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
nexus_username: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
nexus_password: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
maven_profiles: "branch"
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
42 changes: 20 additions & 22 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,38 @@ jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
cache: maven
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Test
run: mvn clean install -DskipTests=false --update-snapshots -q
run: ./gradlew clean allTests

artifact:
name: Publish - Nexus
name: Publish
runs-on: ubuntu-latest
needs: unit-test

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Remove snapshot
run: mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
- name: Release Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
nexus_username: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
nexus_password: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
gpg_private_key: ${{ secrets.PGP_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.PGP_PASSPHRASE }}
maven_profiles: "master"
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Publish to Maven
#run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshot
run: ./gradlew assemble -PremoveSnapshot
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
SIGNING_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.PGP_PASSPHRASE }}
24 changes: 0 additions & 24 deletions build.gradle

This file was deleted.

68 changes: 68 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
plugins {
kotlin("multiplatform")
id("maven-publish-conventions")
id("npm-publish-conventions")
}

repositories {
mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}

group = "org.hisp.dhis.rules"
version = "3.0.0-SNAPSHOT"

val isReleaseVersion = project.hasProperty("removeSnapshot")
if (isReleaseVersion) {
version = (version as String).replace("-SNAPSHOT", "")
}

kotlin {
jvm {
jvmToolchain(17)
withJava()
testRuns.named("test") {
executionTask.configure {
useJUnit()
}
}
}
js {
nodejs()
useEsModules()
binaries.library()
generateTypeScriptDefinitions()
}
val hostOs = System.getProperty("os.name")
val isArm64 = System.getProperty("os.arch") == "aarch64"
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" && isArm64 -> macosArm64("native")
hostOs == "Mac OS X" && !isArm64 -> macosX64("native")
hostOs == "Linux" && isArm64 -> linuxArm64("native")
hostOs == "Linux" && !isArm64 -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}


sourceSets {
val commonMain by getting {
dependencies {
implementation("org.hisp.dhis.lib.expression:expression-parser:1.1.0-SNAPSHOT")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
20 changes: 20 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
`kotlin-dsl`
}

val kotlinVersion = "1.9.21"
val dokkaVersion = "1.9.10"
val nexusPluginVersion = "1.3.0"
val npmPluginVersion = "3.4.1"

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${dokkaVersion}")
implementation("io.github.gradle-nexus:publish-plugin:${nexusPluginVersion}")
implementation("dev.petuska:npm-publish-gradle-plugin:${npmPluginVersion}")
}
35 changes: 35 additions & 0 deletions buildSrc/src/main/kotlin/Props.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
object Props {
const val DESCRIPTION = "Rule Engine"

const val REPOSITORY_TYPE = "git"
const val REPOSITORY_SYSTEM = "GitHub"
const val REPOSITORY_URL = "https://github.com/dhis2/dhis2-rule-engine.git"

const val ORGANIZATION_NAME = "UiO"
const val ORGANIZATION_URL = "https://dhis2.org"

const val LICENSE_NAME = "BSD-3-Clause"
const val LICENSE_URL = "https://opensource.org/license/bsd-3-clause/"

val DEVELOPERS = listOf(
Developer(
name = "Enrico Colasante",
email = "[email protected]",
organization = "UiO",
organizationUrl = "https://www.uio.no/"
),
Developer(
name = "Zubair Asghar",
email = "[email protected]",
organization = "UiO",
organizationUrl = "https://www.uio.no/"
),
)
}

data class Developer(
val name: String,
val email: String,
val organization: String,
val organizationUrl: String,
)
76 changes: 76 additions & 0 deletions buildSrc/src/main/kotlin/maven-publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
plugins {
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin")
id("org.jetbrains.dokka")
}

val ossrhUsername: String? = System.getenv("OSSRH_USERNAME")
val ossrhPassword: String? = System.getenv("OSSRH_PASSWORD")
val signingPrivateKey: String? = System.getenv("SIGNING_PRIVATE_KEY")
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")

val isReleaseVersion = (version as String).contains("SNAPSHOT")

val dokkaHtml = tasks.findByName("dokkaHtml")!!

val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(dokkaHtml)
from(dokkaHtml.outputs)
archiveClassifier.set("docs")
}

publishing {
publications.withType<MavenPublication> {
artifact(dokkaHtmlJar)

pom {
name.set("rule-engine")
description.set(Props.DESCRIPTION)

organization {
name.set(Props.ORGANIZATION_NAME)
url.set(Props.ORGANIZATION_URL)
}
developers {
Props.DEVELOPERS.map {
developer {
name.set(it.name)
email.set(it.email)
organization.set(it.organization)
organizationUrl.set(it.organizationUrl)
}
}
}
licenses {
license {
name.set(Props.LICENSE_NAME)
url.set(Props.LICENSE_URL)
}
}
scm {
url.set("lp:dhis2")
}
issueManagement {
system.set(Props.REPOSITORY_SYSTEM)
url.set(Props.REPOSITORY_URL)
}
url.set(Props.REPOSITORY_URL)
}
}
}

nexusPublishing {
this.repositories {
sonatype {
username.set(ossrhUsername)
password.set(ossrhPassword)
}
}
}

signing {
isRequired = isReleaseVersion
useInMemoryPgpKeys(signingPrivateKey, signingPassword)
sign(publishing.publications)
}
52 changes: 52 additions & 0 deletions buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import dev.petuska.npm.publish.extension.domain.NpmAccess

plugins {
id("dev.petuska.npm.publish")
}

val npmjsToken: String? = System.getenv("NPMJS_TOKEN")

project.afterEvaluate {
npmPublish {
access.set(NpmAccess.PUBLIC)
packages {
named("js") {
scope.set("dhis2")
readme.set(File("./README.md"))
packageJson {
"module" by "${project.name}.mjs"
"main" by ""
"exports" by {
"import" by "./${project.name}.mjs"
}
"contributors" by Props.DEVELOPERS.map { developer ->
"${developer.name} <${developer.email}>"
}
"description" by Props.DESCRIPTION
"license" by Props.LICENSE_NAME
"repository" by {
"type" by Props.REPOSITORY_TYPE
"url" by Props.REPOSITORY_URL
}
"publishConfig" by {
"access" by "public"
}
}
}
}
registries {
npmjs {
authToken.set(npmjsToken)
}
}
}

tasks.named("assembleJsPackage") {
doLast {
val file = file("${layout.buildDirectory.get()}/packages/js/package.json")
val mainRegex = "\n \"main\": \"\","
val removedMain = file.readText().replace(mainRegex, "")
file.writeText(removedMain)
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit c5c7085

Please sign in to comment.