Skip to content

Commit 82d0675

Browse files
authored
Merge pull request #19 from danger/gradle-5-support
Updated travis ci for gradle 5 support
2 parents 829eb13 + abbbcfa commit 82d0675

25 files changed

+295
-33
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.travis.yml

+26
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,29 @@ matrix:
2727
script:
2828
- make install
2929
- danger-kotlin ci
30+
- os: osx
31+
osx_image: xcode10
32+
install:
33+
- curl -s "https://get.sdkman.io" | bash
34+
- source ~/.bash_profile
35+
- sdk install kscript
36+
- sdk install gradle
37+
- sdk install kotlin
38+
- npm install -g danger
39+
script:
40+
- make install
41+
- danger-kotlin ci
42+
- os: linux
43+
sudo: required
44+
dist: trusty
45+
install:
46+
- curl -s "https://get.sdkman.io" | bash
47+
- source ~/.bash_profile
48+
- sdk install kscript
49+
- sdk install gradle
50+
- sdk install kotlin
51+
- npm install -g danger
52+
- sudo chmod -R a+rwx /usr/local/
53+
script:
54+
- make install
55+
- danger-kotlin ci

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VERSION = 0.1.0
33

44
PREFIX = /usr/local
55
INSTALL_PATH = $(PREFIX)/bin/$(TOOL_NAME)
6-
BUILD_PATH = danger-kotlin/build/konan/bin/*/$(TOOL_NAME).kexe
6+
BUILD_PATH = danger-kotlin/build/bin/runner/main/release/executable/$(TOOL_NAME).kexe
77
LIB_INSTALL_PATH = $(PREFIX)/lib/danger
88
TAR_FILENAME = $(TOOL_NAME)-$(VERSION).tar.gz
99

build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@ buildscript {
22
repositories {
33
mavenCentral()
44
}
5+
6+
dependencies {
7+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
8+
}
9+
}
10+
11+
allprojects {
12+
repositories {
13+
mavenCentral()
14+
}
515
}

buildSrc/build.gradle

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
5+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
6+
}
7+
8+
dependencies {
9+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10+
}
11+
}
12+
13+
apply plugin: 'kotlin'
14+
15+
repositories {
16+
mavenCentral()
17+
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
18+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
19+
maven { url 'https://plugins.gradle.org/m2/' }
20+
}
21+
22+
dependencies {
23+
compileOnly gradleApi()
24+
implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin'
25+
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.

buildSrc/settings.gradle

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Reuse Kotlin version from the root project.
2+
File rootProjectGradlePropertiesFile = file("${rootProject.projectDir}/../gradle.properties")
3+
if (!rootProjectGradlePropertiesFile.isFile()) {
4+
throw new Exception("File $rootProjectGradlePropertiesFile does not exist or is not a file")
5+
}
6+
7+
Properties rootProjectProperties = new Properties()
8+
rootProjectGradlePropertiesFile.withInputStream { inputStream ->
9+
rootProjectProperties.load(inputStream)
10+
if (!rootProjectProperties.containsKey('kotlin_version')) {
11+
throw new Exception("No 'kotlin_version' property in $rootProjectGradlePropertiesFile file")
12+
}
13+
}
14+
15+
gradle.beforeProject { project ->
16+
rootProjectProperties.forEach { String key, value ->
17+
if (!project.hasProperty(key))
18+
project.ext[key] = value
19+
}
20+
}

buildSrc/src/main/kotlin/Internals.kt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
3+
* that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
import org.gradle.api.NamedDomainObjectCollection
7+
import org.gradle.api.NamedDomainObjectContainer
8+
import org.gradle.api.Project
9+
import org.gradle.api.plugins.ExtraPropertiesExtension
10+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
11+
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
12+
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
13+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
14+
15+
/*
16+
* This file includes internal short-cuts visible only inside of the 'buildSrc' module.
17+
*/
18+
19+
internal val hostOs by lazy { System.getProperty("os.name") }
20+
internal val userHome by lazy { System.getProperty("user.home") }
21+
22+
internal val Project.ext: ExtraPropertiesExtension
23+
get() = extensions.getByName("ext") as ExtraPropertiesExtension
24+
25+
internal val Project.kotlin: KotlinMultiplatformExtension
26+
get() = extensions.getByName("kotlin") as KotlinMultiplatformExtension
27+
28+
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.macosX64: KotlinTargetPreset<*>
29+
get() = getByName(::macosX64.name) as KotlinTargetPreset<*>
30+
31+
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxX64: KotlinTargetPreset<*>
32+
get() = getByName(::linuxX64.name) as KotlinTargetPreset<*>
33+
34+
internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.mingwX64: KotlinTargetPreset<*>
35+
get() = getByName(::mingwX64.name) as KotlinTargetPreset<*>
36+
37+
internal val NamedDomainObjectContainer<out KotlinCompilation>.main: KotlinNativeCompilation
38+
get() = getByName(::main.name) as KotlinNativeCompilation

buildSrc/src/main/kotlin/MPPTools.kt

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
3+
* that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
@file:JvmName("MPPTools")
7+
8+
import groovy.lang.Closure
9+
import org.gradle.api.Project
10+
import org.gradle.api.Task
11+
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
12+
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
13+
import java.nio.file.Paths
14+
15+
/*
16+
* This file includes short-cuts that may potentially be implemented in Kotlin MPP Gradle plugin in the future.
17+
*/
18+
19+
// Short-cuts for detecting the host OS.
20+
@get:JvmName("isMacos")
21+
val isMacos by lazy { hostOs == "Mac OS X" }
22+
23+
@get:JvmName("isWindows")
24+
val isWindows by lazy { hostOs.startsWith("Windows") }
25+
26+
@get:JvmName("isLinux")
27+
val isLinux by lazy { hostOs == "Linux" }
28+
29+
// Short-cuts for mostly used paths.
30+
@get:JvmName("mingwPath")
31+
val mingwPath by lazy { System.getenv("MINGW64_DIR") ?: "c:/msys64/mingw64" }
32+
33+
@get:JvmName("kotlinNativeDataPath")
34+
val kotlinNativeDataPath by lazy {
35+
System.getenv("KONAN_DATA_DIR") ?: Paths.get(userHome, ".konan").toString()
36+
}
37+
38+
// A short-cut for evaluation of the default host Kotlin/Native preset.
39+
@JvmOverloads
40+
fun defaultHostPreset(
41+
subproject: Project,
42+
whitelist: List<KotlinTargetPreset<*>> = listOf(subproject.kotlin.presets.macosX64, subproject.kotlin.presets.linuxX64, subproject.kotlin.presets.mingwX64)
43+
): KotlinTargetPreset<*> {
44+
45+
if (whitelist.isEmpty())
46+
throw Exception("Preset whitelist must not be empty in Kotlin/Native ${subproject.displayName}.")
47+
48+
val presetCandidate = when {
49+
isMacos -> subproject.kotlin.presets.macosX64
50+
isLinux -> subproject.kotlin.presets.linuxX64
51+
isWindows -> subproject.kotlin.presets.mingwX64
52+
else -> null
53+
}
54+
55+
val preset = if (presetCandidate != null && presetCandidate in whitelist)
56+
presetCandidate
57+
else
58+
throw Exception("Host OS '$hostOs' is not supported in Kotlin/Native ${subproject.displayName}.")
59+
60+
subproject.ext.set("hostPreset", preset)
61+
62+
return preset
63+
}
64+
65+
// A short-cut to add a Kotlin/Native run task.
66+
@JvmOverloads
67+
fun createRunTask(
68+
subproject: Project,
69+
name: String,
70+
target: KotlinTarget,
71+
configureClosure: Closure<Any>? = null
72+
): Task {
73+
val task = subproject.tasks.create(name, RunKotlinNativeTask::class.java, target)
74+
task.configure(configureClosure ?: task.emptyConfigureClosure())
75+
return task
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
3+
* that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
import groovy.lang.Closure
7+
import org.gradle.api.DefaultTask
8+
import org.gradle.api.Task
9+
import org.gradle.api.tasks.TaskAction
10+
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
11+
import javax.inject.Inject
12+
13+
open class RunKotlinNativeTask @Inject constructor(
14+
private val myTarget: KotlinTarget
15+
): DefaultTask() {
16+
17+
var buildType = "RELEASE"
18+
var workingDir: Any = project.projectDir
19+
private var myArgs: List<String> = emptyList()
20+
private val myEnvironment: MutableMap<String, Any> = mutableMapOf()
21+
22+
fun args(vararg args: Any) {
23+
myArgs = args.map { it.toString() }
24+
}
25+
26+
fun environment(map: Map<String, Any>) {
27+
myEnvironment += map
28+
}
29+
30+
override fun configure(configureClosure: Closure<Any>): Task {
31+
val task = super.configure(configureClosure)
32+
this.dependsOn += myTarget.compilations.main.linkTaskName("EXECUTABLE", buildType)
33+
return task
34+
}
35+
36+
@TaskAction
37+
fun run() {
38+
project.exec {
39+
it.executable = myTarget.compilations.main.getBinary("EXECUTABLE", buildType).toString()
40+
it.args = myArgs
41+
it.environment = myEnvironment
42+
it.workingDir(workingDir)
43+
}
44+
}
45+
46+
internal fun emptyConfigureClosure() = object : Closure<Any>(this) {
47+
override fun call(): RunKotlinNativeTask {
48+
return this@RunKotlinNativeTask
49+
}
50+
}
51+
}

danger-kotlin-library/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
2+
id 'org.jetbrains.kotlin.jvm'
33
id 'maven-publish'
44
}
55

danger-kotlin-library/settings.gradle

-2
This file was deleted.

danger-kotlin/build.gradle

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.konan' version "1.3.11"
2+
id 'kotlin-multiplatform'
33
}
44

5-
konan.targets = ['linux', 'macbook', 'mingw']
6-
7-
konanArtifacts {
8-
program("danger-kotlin") {
9-
enableOptimizations(true)
5+
kotlin {
6+
targets {
7+
fromPreset(MPPTools.defaultHostPreset(project), 'runner') {
8+
compilations.main.outputKinds 'EXECUTABLE'
9+
compilations.main.entryPoint 'com.danger.runner.main'
10+
}
1011
}
1112
}
1213

13-
task('osName') {
14-
doLast {
15-
println "OS_TARGET=$org.jetbrains.kotlin.konan.target.HostManager.host"
16-
}
14+
15+
MPPTools.createRunTask(project, 'runProgram', kotlin.targets.runner) {
16+
1717
}

danger-kotlin/gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kotlin.code.style=official
2+
kotlin.import.noCommonSourceSets=true
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
5+
zipStorePath=wrapper/dists

danger-kotlin/settings.gradle

-11
This file was deleted.

danger-kotlin/src/main/kotlin/DangerJSRunner.kt danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerJSRunner.kt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package com.danger.runner
12
import platform.posix.*
23

34
fun runDangerJS(command: String, args: List<String>) {

danger-kotlin/src/main/kotlin/DangerKotlin.kt danger-kotlin/src/runnerMain/kotlin/com/danger/runner/DangerKotlin.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
package com.danger.runner
2+
13
import platform.posix.*
24

35
fun main(args: Array<String>) {
4-
if (args.size > 0) {
5-
val command = args.first()
6-
when (command) {
6+
if (args.isNotEmpty()) {
7+
when (val command = args.first()) {
78
"ci", "local", "pr" -> {
89
val dangerArgs = args.drop(1)
910
runDangerJS(command, dangerArgs)

danger-kotlin/src/main/kotlin/EditCommandRunner.kt danger-kotlin/src/runnerMain/kotlin/com/danger/runner/EditCommandRunner.kt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package com.danger.runner
12
import platform.posix.*
23

34
fun runEditCommand() {

danger-kotlin/src/main/kotlin/Runner.kt danger-kotlin/src/runnerMain/kotlin/com/danger/runner/Runner.kt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package com.danger.runner
12
import platform.posix.*
23

34
const val TMP_INPUT_JSON_FILE = "danger_in.json"
File renamed without changes.

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
kotlin.code.style=official
2-
kotlin.import.noCommonSourceSets=true
1+
kotlin_version=1.3.0
2+
kotlin.code.style=official

settings.gradle

+18-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
include ':danger-kotlin', 'danger-kotlin-library'
1+
pluginManagement {
2+
resolutionStrategy {
3+
eachPlugin {
4+
if (requested.id.id == "kotlin-multiplatform") {
5+
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
6+
}
7+
}
8+
}
9+
repositories {
10+
mavenCentral()
11+
}
12+
}
13+
14+
include ':danger-kotlin-library'
15+
16+
if (MPPTools.isMacos() || MPPTools.isLinux() || MPPTools.isWindows()) {
17+
include ':danger-kotlin'
18+
}

0 commit comments

Comments
 (0)