From 9646cc7c7b425f3eed94f0cc6721a61acca4e4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Kardy=C5=9B?= Date: Wed, 10 Nov 2021 12:50:23 +0100 Subject: [PATCH] Rewriting scripts from bash to gradle --- ci/build.gradle.kts | 129 +++++++++++++++++++++++++++++++++++++++++++ ci/gradle.properties | 6 ++ settings.gradle.kts | 2 +- 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 ci/build.gradle.kts create mode 100644 ci/gradle.properties diff --git a/ci/build.gradle.kts b/ci/build.gradle.kts new file mode 100644 index 000000000..d3ee7616d --- /dev/null +++ b/ci/build.gradle.kts @@ -0,0 +1,129 @@ +group = "com.intellij.plugins" +version = "1.18.0" + +repositories { + mavenCentral() +} +val cwd: String by lazy { System.getProperty("user.dir") } +val env: Map by lazy { + val intellijVersion: String by project + val intellijBuildNumber: String by project + val intellijSHA: String by project + val isUltimate = System.getenv().getOrDefault("IJ_ULTIMATE", false) == true + val intellijPrefix = if (isUltimate) "IU" else "IC" + val intellijBuild = "$intellijPrefix-$intellijVersion" + val fullIntellijBuild = "$intellijPrefix-$intellijBuildNumber" + val pythonId = if (isUltimate) "Pythonid" else "PythonCore" + val jdkJars = System.getenv()["JAVA_HOME"]?.takeIf { + file("$it/lib/tools.jar").exists() + }?.let { + mapOf("JDK_JARS" to arrayOf("sa-jdi.jar", "tools.jar")) + } ?: emptyMap() + mapOf( + "CWD" to cwd, + "IJ_VERSION" to intellijVersion, + "IJ_BUILD_NUMBER" to intellijBuildNumber, + "IJ_SHA" to intellijSHA, + "PANTS_TEST_JUNIT_STRICT_JVM_VERSION" to true, + "MODE" to "debug", + "IJ_BUILD" to intellijBuild, + "FULL_IJ_BUILD_NUMBER" to fullIntellijBuild, + "PYTHON_PLUGIN_ID" to pythonId, + "INTELLIJ_PLUGINS_HOME" to "$cwd/.cache/intellij/$fullIntellijBuild/plugins", + "INTELLIJ_HOME" to "$cwd/.cache/intellij/$fullIntellijBuild/idea-dist", + "OSS_PANTS_HOME" to "$cwd/.cache/pants", + "DUMMY_REPO_HOME" to "$cwd/.cache/dummy_repo", + "JDK_LIBS_HOME" to "$cwd/.cache/jdk-libs" + ) + jdkJars +} + +fun appendIntellijJvmOptions(scope: String): String { + + val plugins = mutableListOf( + "com.intellij.properties", + "JUnit", + "org.intellij.groovy", + "com.intellij.java", + "org.intellij.intelliLang", + "PythonCore", + "com.intellij.modules.python-core-capable", + "com.intellij.plugins.pants" + ) + + val scalaEnabled = System.getenv().getOrDefault("ENABLE_SCALA_PLUGIN", true) == true + if (scalaEnabled) plugins.add("org.intellij.scala") + + val intellijJvmOptions = listOf( + "-Didea.load.plugins.id=${plugins.joinToString(",")}", + "-Didea.plugins.path=${env["INTELLIJ_PLUGINS_HOME"]}", + "-Didea.home.path=${env["INTELLIJ_HOME"]}", + "-Didea.plugins.compatible.build=$${env["IJ_BUILD_NUMBER"]}" + ) + + val vmoptions = file("${env["CWD"]}/resources/idea64.vmoptions").takeIf { it.exists() }?.readLines().orEmpty() + + return (intellijJvmOptions + vmoptions).reduce { acc, s -> "$acc --jvm-$scope-options=$s" } +} +tasks { + +} +task("setup-pants") { + workingDir("$cwd/.cache") + commandLine("git", "clone", "https://github.com/pantsbuild/pants") + doLast { + commandLine("git", "checkout", "33735fe23228472367dc73f26bb96a755452192f") + } +} +task("setup-scalameta-pants") { + workingDir("$cwd/.cache") + commandLine("git", "clone", "https://github.com/scalameta/pants", "-b", "1.26.x-intellij-plugin", "pants-host") + doLast { + commandLine("git", "checkout", "70bcd0aacb3dd3aacf61231c9db54592597776a8") + } +} + +task("setup-ci-environment") { + environment(env) + val jdkLibDir = "${env["JAVA_HOME"]}/lib" + environment("JDK_LIB_DIR", jdkLibDir) + val cacheJdkLibDir = "$cwd/.cache/jdk-libs" + environment("CACHE_JDK_LIB_DIR", cacheJdkLibDir) + file(cacheJdkLibDir).mkdirs() + doFirst { + (env["JDK_JARS"] as? Array)?.forEach { + val old = file("$jdkLibDir/$it") + val new = file("$cacheJdkLibDir/$it") + if (old.exists() && !new.exists()) { + old.copyTo(new) + } + } + } + if (!file("$cwd/.cache/pants/.git").exists()) { + dependsOn("setup-pants") + } + if (!file("$cwd/.cache/pants-host/.git").exists()) { + dependsOn("setup-scalameta-pants") + } + workingDir("$cwd/.cache/pants") + commandLine("./pants", "help", "goals") + doLast { + workingDir("$cwd/.cache/pants-host") + commandLine("./pants", "help", "goals") + } +} + +task("run-tests-ci") { + environment(env) + workingDir(cwd) + val tasksScope: String? by project + val testSet: String? by project + val additionalArgs: String? by project + val arguments = "${tasksScope ?: "-test"} tests:${testSet ?: "-"} " + + "${appendIntellijJvmOptions("test-junit")} ${additionalArgs.orEmpty()}" + doFirst { + file("$cwd/.cache/dummy_repo").deleteRecursively() + file("$cwd/src/test/resources/testData/dummy_repo").copyRecursively(file("$cwd/.cache/dummy_repo")) + file("$cwd/..cache/intellij/*/idea-dist/system/caches/").delete() + } + commandLine(".cache/pants-host/pants", arguments) +} \ No newline at end of file diff --git a/ci/gradle.properties b/ci/gradle.properties new file mode 100644 index 000000000..a59382b54 --- /dev/null +++ b/ci/gradle.properties @@ -0,0 +1,6 @@ +# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +intellijVersion="2021.2.1" +intellijBuildNumber="212.5080.55" +intellijSHA="ff078524f38391d396747007de41f9db02698c107f8e9cd86178fb1c0a1bc4a9" \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index fc85b8dcb..33c4e42f3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,4 +8,4 @@ */ rootProject.name = "pants" -include("common", "testFramework", "externalTestApi") +include("common", "testFramework", "externalTestApi", "ci")