Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated travis ci for gradle 5 support #19

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
mavenCentral()
}
}
26 changes: 26 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
5 changes: 5 additions & 0 deletions buildSrc/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}
38 changes: 38 additions & 0 deletions buildSrc/src/main/kotlin/Internals.kt
Original file line number Diff line number Diff line change
@@ -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<KotlinTargetPreset<*>>.macosX64: KotlinTargetPreset<*>
get() = getByName(::macosX64.name) as KotlinTargetPreset<*>

internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.linuxX64: KotlinTargetPreset<*>
get() = getByName(::linuxX64.name) as KotlinTargetPreset<*>

internal val NamedDomainObjectCollection<KotlinTargetPreset<*>>.mingwX64: KotlinTargetPreset<*>
get() = getByName(::mingwX64.name) as KotlinTargetPreset<*>

internal val NamedDomainObjectContainer<out KotlinCompilation>.main: KotlinNativeCompilation
get() = getByName(::main.name) as KotlinNativeCompilation
76 changes: 76 additions & 0 deletions buildSrc/src/main/kotlin/MPPTools.kt
Original file line number Diff line number Diff line change
@@ -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<KotlinTargetPreset<*>> = 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<Any>? = null
): Task {
val task = subproject.tasks.create(name, RunKotlinNativeTask::class.java, target)
task.configure(configureClosure ?: task.emptyConfigureClosure())
return task
}
51 changes: 51 additions & 0 deletions buildSrc/src/main/kotlin/RunKotlinNativeTask.kt
Original file line number Diff line number Diff line change
@@ -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<String> = emptyList()
private val myEnvironment: MutableMap<String, Any> = mutableMapOf()

fun args(vararg args: Any) {
myArgs = args.map { it.toString() }
}

fun environment(map: Map<String, Any>) {
myEnvironment += map
}

override fun configure(configureClosure: Closure<Any>): 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<Any>(this) {
override fun call(): RunKotlinNativeTask {
return this@RunKotlinNativeTask
}
}
}
2 changes: 1 addition & 1 deletion danger-kotlin-library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
id 'org.jetbrains.kotlin.jvm'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fixed version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed.. is defined in gradle properties

id 'maven-publish'
}

Expand Down
2 changes: 0 additions & 2 deletions danger-kotlin-library/settings.gradle

This file was deleted.

20 changes: 10 additions & 10 deletions danger-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
plugins {
id 'org.jetbrains.kotlin.konan' version "1.3.11"
id 'kotlin-multiplatform'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

}

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) {

}
2 changes: 2 additions & 0 deletions danger-kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kotlin.code.style=official
kotlin.import.noCommonSourceSets=true
4 changes: 2 additions & 2 deletions danger-kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions danger-kotlin/settings.gradle

This file was deleted.

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

fun runDangerJS(command: String, args: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.danger.runner

import platform.posix.*

fun main(args: Array<String>) {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.danger.runner
import platform.posix.*

fun runEditCommand() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.danger.runner
import platform.posix.*

const val TMP_INPUT_JSON_FILE = "danger_in.json"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
kotlin.import.noCommonSourceSets=true
kotlin_version=1.3.0
kotlin.code.style=official
19 changes: 18 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
include ':danger-kotlin', 'danger-kotlin-library'
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'
}