From e035022d3b3a27141020eb9ebd07e4030a0a985b Mon Sep 17 00:00:00 2001 From: Gianluca Zuddas Date: Mon, 18 Feb 2019 15:38:28 +0000 Subject: [PATCH 1/4] Updated travis ci for gradle 5 support --- .travis.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5fa5f8ec..af40b0af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,3 +27,29 @@ matrix: script: - make install - danger-kotlin ci + - os: osx + osx_image: xcode10 + install: + - curl -s "https://get.sdkman.io" | bash + - source ~/.bash_profile + - sdk install kscript + - sdk install gradle 5.2.1 + - sdk install kotlin + - npm install -g danger + script: + - make install + - danger-kotlin ci + - os: linux + sudo: required + dist: trusty + install: + - curl -s "https://get.sdkman.io" | bash + - source ~/.bash_profile + - sdk install kscript + - sdk install gradle 5.2.1 + - sdk install kotlin + - npm install -g danger + - sudo chmod -R a+rwx /usr/local/ + script: + - make install + - danger-kotlin ci \ No newline at end of file From 3963866113a747b9ecfd5932dab95bcc70f49a4b Mon Sep 17 00:00:00 2001 From: Gianluca Zuddas Date: Wed, 27 Feb 2019 15:41:31 +0000 Subject: [PATCH 2/4] Autocomplete and kotlin multiplatform --- .DS_Store | Bin 6148 -> 6148 bytes Makefile | 2 +- build.gradle | 14 ++++ buildSrc/build.gradle | 26 ++++++ .../gradle/wrapper/gradle-wrapper.properties | 5 ++ {danger-kotlin => buildSrc}/gradlew | 0 {danger-kotlin => buildSrc}/gradlew.bat | 0 buildSrc/settings.gradle | 20 +++++ buildSrc/src/main/kotlin/Internals.kt | 38 +++++++++ buildSrc/src/main/kotlin/MPPTools.kt | 76 ++++++++++++++++++ .../src/main/kotlin/RunKotlinNativeTask.kt | 51 ++++++++++++ danger-kotlin-library/build.gradle | 2 +- danger-kotlin-library/settings.gradle | 2 - danger-kotlin/build.gradle | 20 ++--- danger-kotlin/gradle.properties | 2 + .../gradle/wrapper/gradle-wrapper.properties | 4 +- danger-kotlin/settings.gradle | 11 --- .../com/danger/runner}/DangerJSRunner.kt | 1 + .../kotlin/com/danger/runner}/DangerKotlin.kt | 3 + .../com/danger/runner}/EditCommandRunner.kt | 1 + .../kotlin/com/danger/runner}/Runner.kt | 1 + .../danger_in.json => danger_in.json | 0 gradle.properties | 4 +- settings.gradle | 23 +++++- 24 files changed, 276 insertions(+), 30 deletions(-) create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/gradle/wrapper/gradle-wrapper.properties rename {danger-kotlin => buildSrc}/gradlew (100%) rename {danger-kotlin => buildSrc}/gradlew.bat (100%) create mode 100644 buildSrc/settings.gradle create mode 100644 buildSrc/src/main/kotlin/Internals.kt create mode 100644 buildSrc/src/main/kotlin/MPPTools.kt create mode 100644 buildSrc/src/main/kotlin/RunKotlinNativeTask.kt delete mode 100644 danger-kotlin-library/settings.gradle create mode 100644 danger-kotlin/gradle.properties delete mode 100644 danger-kotlin/settings.gradle rename danger-kotlin/src/{main/kotlin => runnerMain/kotlin/com/danger/runner}/DangerJSRunner.kt (91%) rename danger-kotlin/src/{main/kotlin => runnerMain/kotlin/com/danger/runner}/DangerKotlin.kt (94%) rename danger-kotlin/src/{main/kotlin => runnerMain/kotlin/com/danger/runner}/EditCommandRunner.kt (77%) rename danger-kotlin/src/{main/kotlin => runnerMain/kotlin/com/danger/runner}/Runner.kt (96%) rename danger-kotlin/danger_in.json => danger_in.json (100%) diff --git a/.DS_Store b/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..72f4cbba556318765aad8a33791107a949378d06 100644 GIT binary patch delta 130 zcmZoMXfc=|&e%3FQEZ}~q9`K+0|O8XFfgPt6fx*BWHaP5luS%ipKKt)qQc9N!jQ<2 z$B>RJ$&ka4$&i;)oSc)CpP$3HF)@T4q + rootProjectProperties.load(inputStream) + if (!rootProjectProperties.containsKey('kotlin_version')) { + throw new Exception("No 'kotlin_version' property in $rootProjectGradlePropertiesFile file") + } +} + +gradle.beforeProject { project -> + rootProjectProperties.forEach { String key, value -> + if (!project.hasProperty(key)) + project.ext[key] = value + } +} diff --git a/buildSrc/src/main/kotlin/Internals.kt b/buildSrc/src/main/kotlin/Internals.kt new file mode 100644 index 00000000..d46ce36b --- /dev/null +++ b/buildSrc/src/main/kotlin/Internals.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +import org.gradle.api.NamedDomainObjectCollection +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.Project +import org.gradle.api.plugins.ExtraPropertiesExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation + +/* + * This file includes internal short-cuts visible only inside of the 'buildSrc' module. + */ + +internal val hostOs by lazy { System.getProperty("os.name") } +internal val userHome by lazy { System.getProperty("user.home") } + +internal val Project.ext: ExtraPropertiesExtension + get() = extensions.getByName("ext") as ExtraPropertiesExtension + +internal val Project.kotlin: KotlinMultiplatformExtension + get() = extensions.getByName("kotlin") as KotlinMultiplatformExtension + +internal val NamedDomainObjectCollection>.macosX64: KotlinTargetPreset<*> + get() = getByName(::macosX64.name) as KotlinTargetPreset<*> + +internal val NamedDomainObjectCollection>.linuxX64: KotlinTargetPreset<*> + get() = getByName(::linuxX64.name) as KotlinTargetPreset<*> + +internal val NamedDomainObjectCollection>.mingwX64: KotlinTargetPreset<*> + get() = getByName(::mingwX64.name) as KotlinTargetPreset<*> + +internal val NamedDomainObjectContainer.main: KotlinNativeCompilation + get() = getByName(::main.name) as KotlinNativeCompilation diff --git a/buildSrc/src/main/kotlin/MPPTools.kt b/buildSrc/src/main/kotlin/MPPTools.kt new file mode 100644 index 00000000..d3175f25 --- /dev/null +++ b/buildSrc/src/main/kotlin/MPPTools.kt @@ -0,0 +1,76 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +@file:JvmName("MPPTools") + +import groovy.lang.Closure +import org.gradle.api.Project +import org.gradle.api.Task +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset +import java.nio.file.Paths + +/* + * This file includes short-cuts that may potentially be implemented in Kotlin MPP Gradle plugin in the future. + */ + +// Short-cuts for detecting the host OS. +@get:JvmName("isMacos") +val isMacos by lazy { hostOs == "Mac OS X" } + +@get:JvmName("isWindows") +val isWindows by lazy { hostOs.startsWith("Windows") } + +@get:JvmName("isLinux") +val isLinux by lazy { hostOs == "Linux" } + +// Short-cuts for mostly used paths. +@get:JvmName("mingwPath") +val mingwPath by lazy { System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64" } + +@get:JvmName("kotlinNativeDataPath") +val kotlinNativeDataPath by lazy { + System.getenv("KONAN_DATA_DIR") ?: Paths.get(userHome, ".konan").toString() +} + +// A short-cut for evaluation of the default host Kotlin/Native preset. +@JvmOverloads +fun defaultHostPreset( + subproject: Project, + whitelist: List> = listOf(subproject.kotlin.presets.macosX64, subproject.kotlin.presets.linuxX64, subproject.kotlin.presets.mingwX64) +): KotlinTargetPreset<*> { + + if (whitelist.isEmpty()) + throw Exception("Preset whitelist must not be empty in Kotlin/Native ${subproject.displayName}.") + + val presetCandidate = when { + isMacos -> subproject.kotlin.presets.macosX64 + isLinux -> subproject.kotlin.presets.linuxX64 + isWindows -> subproject.kotlin.presets.mingwX64 + else -> null + } + + val preset = if (presetCandidate != null && presetCandidate in whitelist) + presetCandidate + else + throw Exception("Host OS '$hostOs' is not supported in Kotlin/Native ${subproject.displayName}.") + + subproject.ext.set("hostPreset", preset) + + return preset +} + +// A short-cut to add a Kotlin/Native run task. +@JvmOverloads +fun createRunTask( + subproject: Project, + name: String, + target: KotlinTarget, + configureClosure: Closure? = null +): Task { + val task = subproject.tasks.create(name, RunKotlinNativeTask::class.java, target) + task.configure(configureClosure ?: task.emptyConfigureClosure()) + return task +} diff --git a/buildSrc/src/main/kotlin/RunKotlinNativeTask.kt b/buildSrc/src/main/kotlin/RunKotlinNativeTask.kt new file mode 100644 index 00000000..2ad0c638 --- /dev/null +++ b/buildSrc/src/main/kotlin/RunKotlinNativeTask.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +import groovy.lang.Closure +import org.gradle.api.DefaultTask +import org.gradle.api.Task +import org.gradle.api.tasks.TaskAction +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import javax.inject.Inject + +open class RunKotlinNativeTask @Inject constructor( + private val myTarget: KotlinTarget +): DefaultTask() { + + var buildType = "RELEASE" + var workingDir: Any = project.projectDir + private var myArgs: List = emptyList() + private val myEnvironment: MutableMap = mutableMapOf() + + fun args(vararg args: Any) { + myArgs = args.map { it.toString() } + } + + fun environment(map: Map) { + myEnvironment += map + } + + override fun configure(configureClosure: Closure): Task { + val task = super.configure(configureClosure) + this.dependsOn += myTarget.compilations.main.linkTaskName("EXECUTABLE", buildType) + return task + } + + @TaskAction + fun run() { + project.exec { + it.executable = myTarget.compilations.main.getBinary("EXECUTABLE", buildType).toString() + it.args = myArgs + it.environment = myEnvironment + it.workingDir(workingDir) + } + } + + internal fun emptyConfigureClosure() = object : Closure(this) { + override fun call(): RunKotlinNativeTask { + return this@RunKotlinNativeTask + } + } +} diff --git a/danger-kotlin-library/build.gradle b/danger-kotlin-library/build.gradle index b51c6475..abbcf6ed 100644 --- a/danger-kotlin-library/build.gradle +++ b/danger-kotlin-library/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.3.0' + id 'org.jetbrains.kotlin.jvm' id 'maven-publish' } diff --git a/danger-kotlin-library/settings.gradle b/danger-kotlin-library/settings.gradle deleted file mode 100644 index d0714de6..00000000 --- a/danger-kotlin-library/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'kotlin' - diff --git a/danger-kotlin/build.gradle b/danger-kotlin/build.gradle index 3cef7af2..6d583a57 100644 --- a/danger-kotlin/build.gradle +++ b/danger-kotlin/build.gradle @@ -1,17 +1,17 @@ plugins { - id 'org.jetbrains.kotlin.konan' version "1.3.11" + id 'kotlin-multiplatform' } -konan.targets = ['linux', 'macbook', 'mingw'] - -konanArtifacts { - program("danger-kotlin") { - enableOptimizations(true) +kotlin { + targets { + fromPreset(MPPTools.defaultHostPreset(project), 'runner') { + compilations.main.outputKinds 'EXECUTABLE' + compilations.main.entryPoint 'com.danger.runner.main' + } } } -task('osName') { - doLast { - println "OS_TARGET=$org.jetbrains.kotlin.konan.target.HostManager.host" - } + +MPPTools.createRunTask(project, 'runProgram', kotlin.targets.runner) { + } \ No newline at end of file diff --git a/danger-kotlin/gradle.properties b/danger-kotlin/gradle.properties new file mode 100644 index 00000000..de16ded2 --- /dev/null +++ b/danger-kotlin/gradle.properties @@ -0,0 +1,2 @@ +kotlin.code.style=official +kotlin.import.noCommonSourceSets=true \ No newline at end of file diff --git a/danger-kotlin/gradle/wrapper/gradle-wrapper.properties b/danger-kotlin/gradle/wrapper/gradle-wrapper.properties index 115e6ac0..c2b685fd 100644 --- a/danger-kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/danger-kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/danger-kotlin/settings.gradle b/danger-kotlin/settings.gradle deleted file mode 100644 index 47201fe9..00000000 --- a/danger-kotlin/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -pluginManagement { - resolutionStrategy { - eachPlugin { - if (requested.id.id == "kotlin-multiplatform") { - useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") - } - } - } -} -rootProject.name = 'danger-kotlin' - diff --git a/danger-kotlin/src/main/kotlin/DangerJSRunner.kt b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerJSRunner.kt similarity index 91% rename from danger-kotlin/src/main/kotlin/DangerJSRunner.kt rename to danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerJSRunner.kt index ad3b2995..f02def87 100644 --- a/danger-kotlin/src/main/kotlin/DangerJSRunner.kt +++ b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerJSRunner.kt @@ -1,3 +1,4 @@ +package com.danger.runner import platform.posix.* fun runDangerJS(command: String, args: List) { diff --git a/danger-kotlin/src/main/kotlin/DangerKotlin.kt b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt similarity index 94% rename from danger-kotlin/src/main/kotlin/DangerKotlin.kt rename to danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt index da5d5afc..b2554e50 100644 --- a/danger-kotlin/src/main/kotlin/DangerKotlin.kt +++ b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt @@ -1,5 +1,8 @@ +package com.danger.runner + import platform.posix.* + fun main(args: Array) { if (args.size > 0) { val command = args.first() diff --git a/danger-kotlin/src/main/kotlin/EditCommandRunner.kt b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/EditCommandRunner.kt similarity index 77% rename from danger-kotlin/src/main/kotlin/EditCommandRunner.kt rename to danger-kotlin/src/runnerMain/kotlin/com/danger/runner/EditCommandRunner.kt index c990026c..2650f329 100644 --- a/danger-kotlin/src/main/kotlin/EditCommandRunner.kt +++ b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/EditCommandRunner.kt @@ -1,3 +1,4 @@ +package com.danger.runner import platform.posix.* fun runEditCommand() { diff --git a/danger-kotlin/src/main/kotlin/Runner.kt b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/Runner.kt similarity index 96% rename from danger-kotlin/src/main/kotlin/Runner.kt rename to danger-kotlin/src/runnerMain/kotlin/com/danger/runner/Runner.kt index 05787cb1..f093f061 100644 --- a/danger-kotlin/src/main/kotlin/Runner.kt +++ b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/Runner.kt @@ -1,3 +1,4 @@ +package com.danger.runner import platform.posix.* const val TMP_INPUT_JSON_FILE = "danger_in.json" diff --git a/danger-kotlin/danger_in.json b/danger_in.json similarity index 100% rename from danger-kotlin/danger_in.json rename to danger_in.json diff --git a/gradle.properties b/gradle.properties index de16ded2..7c48c459 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -kotlin.code.style=official -kotlin.import.noCommonSourceSets=true \ No newline at end of file +kotlin_version=1.3.0 +kotlin.code.style=official \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 94e129c3..a205f98d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,22 @@ -include ':danger-kotlin', 'danger-kotlin-library' \ No newline at end of file +pluginManagement { + resolutionStrategy { + eachPlugin { + if (requested.id.id == "kotlin-multiplatform") { + useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") + } + } + } + repositories { + mavenCentral() + maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + } +} + +enableFeaturePreview('GRADLE_METADATA') + +include ':danger-kotlin-library' + +if (MPPTools.isMacos() || MPPTools.isLinux() || MPPTools.isWindows()) { + include ':danger-kotlin' +} \ No newline at end of file From d2efe90597081f2d4d49528bd0cb507b5f716a38 Mon Sep 17 00:00:00 2001 From: Gianluca Zuddas Date: Wed, 27 Feb 2019 16:00:59 +0000 Subject: [PATCH 3/4] Omitting gradle last version --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index af40b0af..0f14d6ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ matrix: - curl -s "https://get.sdkman.io" | bash - source ~/.bash_profile - sdk install kscript - - sdk install gradle 5.2.1 + - sdk install gradle - sdk install kotlin - npm install -g danger script: @@ -46,7 +46,7 @@ matrix: - curl -s "https://get.sdkman.io" | bash - source ~/.bash_profile - sdk install kscript - - sdk install gradle 5.2.1 + - sdk install gradle - sdk install kotlin - npm install -g danger - sudo chmod -R a+rwx /usr/local/ From abbbcfa1c63db1dcf69cb28b02626505bfc53c20 Mon Sep 17 00:00:00 2001 From: Gianluca Zuddas Date: Thu, 28 Feb 2019 09:48:03 +0000 Subject: [PATCH 4/4] Remove not needed maven repos --- build.gradle | 4 ---- .../src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt | 6 ++---- settings.gradle | 4 ---- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 1f6f9cbf..7af697fe 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,6 @@ buildscript { repositories { mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } } dependencies { @@ -13,7 +11,5 @@ buildscript { allprojects { repositories { mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } } } \ No newline at end of file diff --git a/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt index b2554e50..f8b5ddd0 100644 --- a/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt +++ b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt @@ -2,11 +2,9 @@ package com.danger.runner import platform.posix.* - fun main(args: Array) { - if (args.size > 0) { - val command = args.first() - when (command) { + if (args.isNotEmpty()) { + when (val command = args.first()) { "ci", "local", "pr" -> { val dangerArgs = args.drop(1) runDangerJS(command, dangerArgs) diff --git a/settings.gradle b/settings.gradle index a205f98d..07eab82d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,13 +8,9 @@ pluginManagement { } repositories { mavenCentral() - maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } - maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } } } -enableFeaturePreview('GRADLE_METADATA') - include ':danger-kotlin-library' if (MPPTools.isMacos() || MPPTools.isLinux() || MPPTools.isWindows()) {