|
| 1 | +/* |
| 2 | + * Copyright (c) 2023. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +plugins { |
| 18 | + alias(libs.plugins.kotlin.jvm) |
| 19 | + // We are not building an actual plugin here. |
| 20 | + // We use/abuse the gradle-intellij-plugin run tests with MPS. |
| 21 | + // (With enough time and effort, |
| 22 | + // one could inspect what the plugin does under the hood |
| 23 | + // and build something custom using the relevant parts. |
| 24 | + // For the time being, this solution works without much overhead and great benefit.) |
| 25 | + alias(libs.plugins.intellij) |
| 26 | +} |
| 27 | + |
| 28 | +val modelixCoreVersion: String = file("../version.txt").readText() |
| 29 | + |
| 30 | +version = modelixCoreVersion |
| 31 | + |
| 32 | +repositories { |
| 33 | + val modelixRegex = "org\\.modelix.*" |
| 34 | + mavenLocal { |
| 35 | + content { |
| 36 | + includeGroupByRegex(modelixRegex) |
| 37 | + } |
| 38 | + } |
| 39 | + gradlePluginPortal { |
| 40 | + content { |
| 41 | + excludeGroupByRegex(modelixRegex) |
| 42 | + } |
| 43 | + } |
| 44 | + maven { |
| 45 | + url = uri("https://artifacts.itemis.cloud/repository/maven-mps/") |
| 46 | + content { |
| 47 | + includeGroupByRegex(modelixRegex) |
| 48 | + includeGroup("com.jetbrains") |
| 49 | + } |
| 50 | + } |
| 51 | + mavenCentral { |
| 52 | + content { |
| 53 | + excludeGroupByRegex(modelixRegex) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +dependencies { |
| 59 | + testImplementation("org.modelix:bulk-model-sync-lib:$modelixCoreVersion") |
| 60 | + testImplementation("org.modelix.mps:model-adapters:$modelixCoreVersion") |
| 61 | + testImplementation(libs.kotlin.serialization.json) |
| 62 | +} |
| 63 | + |
| 64 | +val mpsVersion = project.findProperty("mps.version")?.toString()?.takeIf { it.isNotEmpty() } |
| 65 | + ?: "2021.1.4" |
| 66 | +println("Building for MPS version $mpsVersion") |
| 67 | + |
| 68 | +// Extract MPS during configuration phase, because using it in intellij.localPath requires it to already exist. |
| 69 | +val mpsHome = project.layout.buildDirectory.dir("mps-$mpsVersion") |
| 70 | +val mpsZip: Configuration by configurations.creating |
| 71 | +dependencies { mpsZip("com.jetbrains:mps:$mpsVersion") } |
| 72 | +mpsHome.get().asFile.let { baseDir -> |
| 73 | + if (baseDir.exists()) return@let // the content of MPS zip is not expected to change |
| 74 | + |
| 75 | + println("Extracting MPS ...") |
| 76 | + sync { |
| 77 | + from(zipTree({ mpsZip.singleFile })) |
| 78 | + into(mpsHome) |
| 79 | + } |
| 80 | + |
| 81 | + // The build number of a local IDE is expected to contain a product code, otherwise an exception is thrown. |
| 82 | + val buildTxt = mpsHome.get().asFile.resolve("build.txt") |
| 83 | + val buildNumber = buildTxt.readText() |
| 84 | + val prefix = "MPS-" |
| 85 | + if (!buildNumber.startsWith(prefix)) { |
| 86 | + buildTxt.writeText("$prefix$buildNumber") |
| 87 | + } |
| 88 | + |
| 89 | + println("Extracting MPS done.") |
| 90 | +} |
| 91 | + |
| 92 | +intellij { |
| 93 | + localPath = mpsHome.map { it.asFile.absolutePath } |
| 94 | +} |
0 commit comments