diff --git a/.DS_Store b/.DS_Store index 5008ddfc..72f4cbba 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.travis.yml b/.travis.yml index 5fa5f8ec..0f14d6ac 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 + - 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 + - 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 diff --git a/Makefile b/Makefile index babfa335..8fd4e798 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ VERSION = 0.1.0 PREFIX = /usr/local INSTALL_PATH = $(PREFIX)/bin/$(TOOL_NAME) -BUILD_PATH = danger-kotlin/build/konan/bin/*/$(TOOL_NAME).kexe +BUILD_PATH = danger-kotlin/build/bin/runner/main/release/executable/$(TOOL_NAME).kexe LIB_INSTALL_PATH = $(PREFIX)/lib/danger TAR_FILENAME = $(TOOL_NAME)-$(VERSION).tar.gz diff --git a/build.gradle b/build.gradle index 52848790..7af697fe 100644 --- a/build.gradle +++ b/build.gradle @@ -2,4 +2,14 @@ buildscript { repositories { mavenCentral() } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + mavenCentral() + } } \ No newline at end of file diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000..f167e041 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,26 @@ +buildscript { + repositories { + mavenCentral() + maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' + +repositories { + mavenCentral() + maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' } + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } + maven { url 'https://plugins.gradle.org/m2/' } +} + +dependencies { + compileOnly gradleApi() + implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin' + implementation 'org.jetbrains.kotlin:kotlin-stdlib' +} diff --git a/buildSrc/gradle/wrapper/gradle-wrapper.properties b/buildSrc/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..d2c45a4b --- /dev/null +++ b/buildSrc/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/danger-kotlin/gradlew b/buildSrc/gradlew similarity index 100% rename from danger-kotlin/gradlew rename to buildSrc/gradlew diff --git a/danger-kotlin/gradlew.bat b/buildSrc/gradlew.bat similarity index 100% rename from danger-kotlin/gradlew.bat rename to buildSrc/gradlew.bat diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 00000000..43c08c10 --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1,20 @@ +// Reuse Kotlin version from the root project. +File rootProjectGradlePropertiesFile = file("${rootProject.projectDir}/../gradle.properties") +if (!rootProjectGradlePropertiesFile.isFile()) { + throw new Exception("File $rootProjectGradlePropertiesFile does not exist or is not a file") +} + +Properties rootProjectProperties = new Properties() +rootProjectGradlePropertiesFile.withInputStream { inputStream -> + 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 78% rename from danger-kotlin/src/main/kotlin/DangerKotlin.kt rename to danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt index da5d5afc..f8b5ddd0 100644 --- a/danger-kotlin/src/main/kotlin/DangerKotlin.kt +++ b/danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt @@ -1,9 +1,10 @@ +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/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..07eab82d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,18 @@ -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() + } +} + +include ':danger-kotlin-library' + +if (MPPTools.isMacos() || MPPTools.isLinux() || MPPTools.isWindows()) { + include ':danger-kotlin' +} \ No newline at end of file