Skip to content

Commit

Permalink
Merge pull request #168 from modelix/feature/model-sync-gradle
Browse files Browse the repository at this point in the history
MODELIX-448 bulk-model-sync-gradle: Gradle plugin for syncing models between model server and MPS
  • Loading branch information
mhuster23 authored Sep 15, 2023
2 parents c37921b + eba5b1d commit 739934d
Show file tree
Hide file tree
Showing 99 changed files with 3,772 additions and 522 deletions.
54 changes: 49 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ jobs:
arguments: |
--build-cache
build
publishToMavenLocal
-PciBuild=true
- name: Test Model API Generator Gradle Plugin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: model-api-gen-gradle-test/ci.sh
- name: Archive test report
uses: actions/upload-artifact@v3
if: always()
Expand All @@ -42,3 +37,52 @@ jobs:
path: |
*/build/test-results
*/build/reports
test-model-api-gen-gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Assemble
uses: gradle/gradle-build-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
arguments: |
--build-cache
assemble
publishToMavenLocal
-PciBuild=true
- name: Test Model API Generator Gradle Plugin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: model-api-gen-gradle-test/ci.sh

test-bulk-model-sync-gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Assemble
uses: gradle/gradle-build-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
arguments: |
--build-cache
assemble
publishToMavenLocal
-PciBuild=true
- name: Test Bulk Model Sync Gradle Plugin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bulk-model-sync-gradle-test/ci.sh
17 changes: 16 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import kotlinx.html.unsafe
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
import org.semver.Version

buildscript {
Expand Down Expand Up @@ -76,12 +78,25 @@ subprojects {
version.set("0.50.0")
}

val kotlinApiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_6
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
if (!name.lowercase().contains("test")) {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs += listOf("-Xjvm-default=all-compatibility")
apiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_6.version
apiVersion = kotlinApiVersion.version
}
}
}

plugins.withType<KotlinMultiplatformPluginWrapper> {
project.extensions.configure<KotlinMultiplatformExtension> {
sourceSets.all {
if (!name.lowercase().contains("test")) {
languageSettings {
apiVersion = kotlinApiVersion.version
}
}
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions bulk-model-sync-gradle-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.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/

### 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
/test-repo/**/**/classes_gen/
/test-repo/**/**/generator/
/test-repo/**/**/source_gen/
/test-repo/**/**/source_gen.caches/
120 changes: 120 additions & 0 deletions bulk-model-sync-gradle-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (c) 2023.
*
* 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
*
* 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.
*/

import org.modelix.model.server.Main

buildscript {
val modelixCoreVersion: String = file("../version.txt").readText()
dependencies {
classpath("org.modelix:model-server:$modelixCoreVersion")
classpath("org.modelix:graph-lang-api:$modelixCoreVersion")
}
}

plugins {
alias(libs.plugins.kotlin.jvm)
id("org.modelix.bulk-model-sync")
}

val modelixCoreVersion: String = file("../version.txt").readText()

version = modelixCoreVersion

repositories {
mavenLocal()
maven { url = uri("https://repo.maven.apache.org/maven2") }
maven { url = uri("https://plugins.gradle.org/m2/") }
mavenCentral()
maven { url = uri("https://artifacts.itemis.cloud/repository/maven-mps/") }
}

val mps by configurations.creating
val mpsDir = buildDir.resolve("mps").apply { mkdirs() }
val kotlinGenDir = buildDir.resolve("metamodel/kotlin").apply { mkdirs() }

dependencies {
mps("com.jetbrains:mps:2021.2.5")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2")
implementation("org.modelix:model-server:$modelixCoreVersion")
implementation("org.modelix:model-api-gen-runtime:$modelixCoreVersion")
testImplementation("org.modelix:model-client:$modelixCoreVersion")
testImplementation("org.modelix:bulk-model-sync-lib:$modelixCoreVersion")
testImplementation("org.modelix.mps:model-adapters:$modelixCoreVersion")
testImplementation("org.modelix:graph-lang-api:$modelixCoreVersion")
testImplementation(kotlin("test"))
testImplementation(libs.xmlunit.core)
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(11)
}

tasks.register("runModelServer", JavaExec::class) {
group = "modelix"

description = "Launches a model-server instance to be used as a target for the test. " +
"This task will block and is intended to be run in a separate process, apart from the actual test execution."

classpath = sourceSets["main"].runtimeClasspath
mainClass.set("org.modelix.model.server.Main")
args("-inmemory")
}

val resolveMps by tasks.registering(Copy::class) {
from(mps.resolve().map { zipTree(it) })
into(mpsDir)
}

val repoDir = buildDir.resolve("test-repo")

val copyTestRepo by tasks.registering(Sync::class) {
from(projectDir.resolve("test-repo"))
into(repoDir)
}

modelSync {
dependsOn(resolveMps)
dependsOn(copyTestRepo)
direction("testPush") {
org.modelix.model.sync.bulk.gradle.test.GraphLanguagesHelper.registerAll()
includeModule("GraphSolution")
fromLocal {
mpsHome = mpsDir
mpsHeapSize = "2g"
repositoryDir = repoDir
}
toModelServer {
url = "http://0.0.0.0:${Main.DEFAULT_PORT}/v2"
repositoryId = "ci-test"
branchName = "master"
}
}
direction("testPull") {
fromModelServer {
url = "http://0.0.0.0:${Main.DEFAULT_PORT}/v2"
repositoryId = "ci-test"
branchName = "master"
}
toLocal {
mpsHome = mpsDir
repositoryDir = repoDir
}
}
}
36 changes: 36 additions & 0 deletions bulk-model-sync-gradle-test/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -e

cd "$(dirname "$0")"

(
cd graph-lang-api
./gradlew publishToMavenLocal --console=plain
)

./gradlew assemble --console=plain

if [ "${CI}" != "true" ]; then
trap cleanup INT TERM EXIT
cleanup () {
kill "${MODEL_SERVER_PID}"
exit
}
fi

./gradlew runModelServer --console=plain &
MODEL_SERVER_PID=$!
sleep 5

#CI needs more time
if [ "${CI}" = "true" ]; then
sleep 10
fi

curl -X POST http://127.0.0.1:28101/v2/repositories/ci-test/init

./gradlew runSyncTestPush --console=plain --stacktrace
./gradlew test --tests 'PushTest'
./gradlew runSyncTestPull --console=plain --stacktrace
./gradlew test --tests 'PullTest'
1 change: 1 addition & 0 deletions bulk-model-sync-gradle-test/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions bulk-model-sync-gradle-test/gradlew
1 change: 1 addition & 0 deletions bulk-model-sync-gradle-test/gradlew.bat
73 changes: 73 additions & 0 deletions bulk-model-sync-gradle-test/graph-lang-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
plugins {
id("org.modelix.model-api-gen")
`maven-publish`
alias(libs.plugins.kotlin.jvm)
}

repositories {
mavenLocal()
gradlePluginPortal()
maven { url = uri("https://artifacts.itemis.cloud/repository/maven-mps/") }
mavenCentral()
}

val modelixCoreVersion = file("../../version.txt").readText()

version = modelixCoreVersion

val mps: Configuration by configurations.creating
val kotlinGenDir = buildDir.resolve("metamodel/kotlin").apply { mkdirs() }

dependencies {
mps("com.jetbrains:mps:2021.2.5")
api("org.modelix:model-api-gen-runtime:$modelixCoreVersion")
}

val mpsDir = buildDir.resolve("mps").apply { mkdirs() }

val resolveMps by tasks.registering(Copy::class) {
from(mps.resolve().map { zipTree(it) })
into(mpsDir)
}

val repoDir = projectDir.resolve("test-repo")

val copyMetamodelToMpsHome by tasks.registering(Copy::class) {
from(file(projectDir.resolve("../test-repo/languages")))
into(file(mpsDir.resolve("languages").apply { mkdirs() }))
}

kotlin {
sourceSets.named("main") {
kotlin.srcDir(kotlinGenDir)
}
}

metamodel {
dependsOn(resolveMps)
dependsOn(copyMetamodelToMpsHome)
mpsHome = mpsDir
kotlinDir = kotlinGenDir
includeLanguage("GraphLang")
registrationHelperName = "org.modelix.model.sync.bulk.gradle.test.GraphLanguagesHelper"
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = "org.modelix"
from(components["kotlin"])
}
}
repositories {
mavenLocal()
}
}

tasks.named("processResources") {
dependsOn("generateMetaModelSources")
}

tasks.named("compileKotlin") {
dependsOn("generateMetaModelSources")
}
Loading

0 comments on commit 739934d

Please sign in to comment.