Skip to content

Commit 252b5a0

Browse files
authored
Merge pull request #231 from danger/kotlin-upgrade-and-apple-silicon-m1-support
Kotlin upgrade to 1.7.0 and apple silicon m1 support
2 parents 6156c14 + cedadba commit 252b5a0

File tree

13 files changed

+57
-26
lines changed

13 files changed

+57
-26
lines changed

.github/workflows/ci.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
with:
1818
candidate: gradle
1919
version: 7.4.2
20-
20+
2121
- name: Install Kotlin
2222
run: |
23-
curl -o kotlin-compiler.zip -L https://github.com/JetBrains/kotlin/releases/download/v1.5.10/kotlin-compiler-1.5.10.zip
23+
curl -o kotlin-compiler.zip -L https://github.com/JetBrains/kotlin/releases/download/v1.7.0/kotlin-compiler-1.7.0.zip
2424
2525
if [[ "$OSTYPE" != "darwin"* ]]
2626
then
@@ -34,7 +34,16 @@ jobs:
3434
- uses: actions/setup-node@v3
3535
with:
3636
node-version: '14'
37-
37+
38+
- name: Install libncurses5
39+
run: |
40+
if [[ "$OSTYPE" == "darwin"* ]]
41+
then
42+
brew install ncurses
43+
else
44+
sudo apt-get install libncurses5
45+
fi
46+
3847
- name: Install Danger JS
3948
run: npm install -g danger
4049

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
-->
1313
## Master
14+
- Update `Kotlin` to `1.7.0` and added support for Apple Silicon Chipset [@gianluz] - [#231](https://github.com/danger/kotlin/pull/231)
1415

1516
# 1.1.0
1617

Dangerfile.df.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Repository("https://repo.maven.apache.org")
1+
@file:Repository("https://repo.maven.apache.org/maven2/")
22
@file:DependsOn("org.apache.commons:commons-text:1.6")
33

44
import systems.danger.kotlin.*

Dangerfile_ci.df.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Use external dependencies using the following annotations:
44
*/
5-
@file:Repository("https://repo.maven.apache.org")
5+
@file:Repository("https://repo.maven.apache.org/maven2/")
66
@file:DependsOn("org.apache.commons:commons-text:1.6")
77

88
//Testing plugin

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN apt-get update && \
1717
# Install danger-kotlin globally
1818
COPY . /usr/local/_danger-kotlin
1919
RUN cd /usr/lib && \
20-
wget -q https://github.com/JetBrains/kotlin/releases/download/v1.5.0/kotlin-compiler-1.5.0.zip && \
20+
wget -q https://github.com/JetBrains/kotlin/releases/download/v1.7.0/kotlin-compiler-1.7.0.zip && \
2121
unzip kotlin-compiler-*.zip && \
2222
rm kotlin-compiler-*.zip && \
2323
cd /usr/local/_danger-kotlin && \

danger-kotlin-kts/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ apply from: file('version.gradle')
2020
dependencies {
2121
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
2222
implementation "org.jetbrains.kotlin:kotlin-script-runtime:$versionKotlin"
23-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0"
23+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2"
24+
2425
includeJar "org.jetbrains.kotlin:kotlin-main-kts:$versionKotlin"
2526
}
2627

danger-kotlin-kts/src/main/kotlin/systems/danger/kts/DangerFileScriptDefinition.kt

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package systems.danger.kts
22

3-
import kotlinx.coroutines.runBlocking
43
import org.jetbrains.kotlin.mainKts.*
5-
import org.jetbrains.kotlin.mainKts.impl.IvyResolver
64
import java.io.File
75
import kotlin.script.dependencies.ScriptContents
86
import kotlin.script.dependencies.ScriptDependenciesResolver
97
import kotlin.script.experimental.annotations.KotlinScript
108
import kotlin.script.experimental.api.*
119
import kotlin.script.experimental.dependencies.*
10+
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
1211
import kotlin.script.experimental.host.FileBasedScriptSource
1312
import kotlin.script.experimental.host.FileScriptSource
13+
import kotlin.script.experimental.impl.internalScriptingRunSuspend
1414
import kotlin.script.experimental.jvm.compat.mapLegacyDiagnosticSeverity
1515
import kotlin.script.experimental.jvm.compat.mapLegacyScriptPosition
1616
import kotlin.script.experimental.jvm.dependenciesFromClassContext
@@ -32,7 +32,7 @@ abstract class DangerFileScript(val args: Array<String>)
3232

3333
object DangerFileScriptDefinition : ScriptCompilationConfiguration(
3434
{
35-
defaultImports(DependsOn::class, Repository::class, Import::class, CompilerOptions::class)
35+
defaultImports(DependsOn::class, Repository::class, Import::class, CompilerOptions::class, ScriptFileLocation::class)
3636
jvm {
3737
dependenciesFromClassContext(
3838
DangerFileScriptDefinition::class,
@@ -49,6 +49,8 @@ object DangerFileScriptDefinition : ScriptCompilationConfiguration(
4949
CompilerOptions::class,
5050
handler = DangerFileKtsConfigurator()
5151
)
52+
onAnnotations(ScriptFileLocation::class, handler = ScriptFileLocationCustomConfigurator())
53+
beforeCompiling(::configureScriptFileLocationPathVariablesForCompilation)
5254
beforeCompiling(::configureProvidedPropertiesFromJsr223Context)
5355
}
5456
ide {
@@ -64,7 +66,8 @@ class DangerFileKtsConfigurator : RefineScriptCompilationConfigurationHandler {
6466

6567
private val resolver = CompoundDependenciesResolver(
6668
FileSystemDependenciesResolver(DANGER_LIBS_FLAT_DIR),
67-
IvyResolver()
69+
FileSystemDependenciesResolver(),
70+
MavenDependenciesResolver()
6871
)
6972

7073
override operator fun invoke(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> =
@@ -89,28 +92,44 @@ class DangerFileKtsConfigurator : RefineScriptCompilationConfigurationHandler {
8992
?: return context.compilationConfiguration.asSuccess()
9093

9194
val scriptBaseDir = (context.script as? FileBasedScriptSource)?.file?.parentFile
92-
val importedSources = annotations.filterByAnnotationType<Import>().flatMap {
93-
it.annotation.paths.map { sourceName ->
94-
FileScriptSource(scriptBaseDir?.resolve(sourceName) ?: File(sourceName))
95+
val importedSources = linkedMapOf<String, Pair<File, String>>()
96+
var hasImportErrors = false
97+
annotations.filterByAnnotationType<Import>().forEach { scriptAnnotation ->
98+
scriptAnnotation.annotation.paths.forEach { sourceName ->
99+
val file = (scriptBaseDir?.resolve(sourceName) ?: File(sourceName)).normalize()
100+
val keyPath = file.absolutePath
101+
val prevImport = importedSources.put(keyPath, file to sourceName)
102+
if (prevImport != null) {
103+
diagnostics.add(
104+
ScriptDiagnostic(
105+
ScriptDiagnostic.unspecifiedError, "Duplicate imports: \"${prevImport.second}\" and \"$sourceName\"",
106+
sourcePath = context.script.locationId, location = scriptAnnotation.location?.locationInText
107+
)
108+
)
109+
hasImportErrors = true
110+
}
95111
}
96112
}
113+
if (hasImportErrors) return ResultWithDiagnostics.Failure(diagnostics)
114+
97115
val compileOptions = annotations.filterByAnnotationType<CompilerOptions>().flatMap {
98116
it.annotation.options.toList()
99117
}
100118

101119
val resolveResult = try {
102-
runBlocking {
120+
@Suppress("DEPRECATION_ERROR")
121+
internalScriptingRunSuspend {
103122
resolver.resolveFromScriptSourceAnnotations(annotations.filter { it.annotation is DependsOn || it.annotation is Repository })
104123
}
105-
106124
} catch (e: Throwable) {
107-
ResultWithDiagnostics.Failure(*diagnostics.toTypedArray(), e.asDiagnostics(path = context.script.locationId))
125+
diagnostics.add(e.asDiagnostics(path = context.script.locationId))
126+
ResultWithDiagnostics.Failure(diagnostics)
108127
}
109128

110129
return resolveResult.onSuccess { resolvedClassPath ->
111130
ScriptCompilationConfiguration(context.compilationConfiguration) {
112131
updateClasspath(resolvedClassPath)
113-
if (importedSources.isNotEmpty()) importScripts.append(importedSources)
132+
if (importedSources.isNotEmpty()) importScripts.append(importedSources.values.map { FileScriptSource(it.first) })
114133
if (compileOptions.isNotEmpty()) compilerOptions.append(compileOptions)
115134
}.asSuccess()
116135
}

danger-kotlin-library/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ test {
2222
}
2323

2424
compileKotlin {
25-
kotlinOptions.jvmTarget = "1.6"
25+
kotlinOptions.jvmTarget = "1.8"
2626
}
2727
compileTestKotlin {
28-
kotlinOptions.jvmTarget = "1.6"
28+
kotlinOptions.jvmTarget = "1.8"
2929
}
3030

3131
publishing {

danger-kotlin-sample-plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
plugins {
12-
id 'org.jetbrains.kotlin.jvm' version '1.5.0'
12+
id 'org.jetbrains.kotlin.jvm' version '1.7.0'
1313
}
1414

1515
apply plugin: 'danger-kotlin-plugin-installer'

danger-kotlin/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ kotlin {
99
val hostTarget = when (val hostOs = System.getProperty("os.name")) {
1010
"Mac OS X" -> macosX64("runner")
1111
"Linux" -> linuxX64("runner")
12+
"Mac OS X Apple silicon" -> macosArm64("runner")
1213
else -> throw GradleException("Host OS '$hostOs' is not supported.") as Throwable
1314
}
1415

danger-kotlin/src/runnerMain/kotlin/systems.danger/cmd/dangerfile/DangerFile.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private fun readLine(file: CPointer<FILE>): String? {
5757
var ch = getc(file)
5858
var lineBuffer: Array<Char> = arrayOf()
5959

60-
while ((ch != '\n'.toInt()) && (ch != EOF)) {
60+
while ((ch != '\n'.code) && (ch != EOF)) {
6161
lineBuffer += ch.toChar()
6262

6363
ch = getc(file)

dependencyVersions.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ project.ext.groupIdOkio = 'com.squareup.okio'
2020
project.ext.artifactIdOkio = 'okio'
2121

2222
// Kotlin
23-
project.ext.versionKotlin = '1.5.10'
23+
project.ext.versionKotlin = '1.7.0'
2424
project.ext.groupIdKotlin = 'org.jetbrains.kotlin'
2525
project.ext.groupIdKotlinx = 'org.jetbrains.kotlinx'
2626
project.ext.artifactIdKotlinMain = 'kotlin-main-kts'
2727
project.ext.artifactIdKotlinSerializationJson = 'kotlinx-serialization-json'
2828
project.ext.artifactIdKotlinDatetime = "kotlinx-datetime"
2929
project.ext.artifactIdKotlinCoroutines = "kotlinx-coroutines-core"
30-
project.ext.versionKotlinSerializationJson = '1.2.1'
30+
project.ext.versionKotlinSerializationJson = '1.3.2'
3131
project.ext.versionKotlinDatetime = '0.2.0'
32-
project.ext.versionKotlinCoroutines = '1.5.0'
32+
project.ext.versionKotlinCoroutines = '1.6.2'
3333

3434
ext.kotlin = [
3535
mainKts: "$groupIdKotlin:$artifactIdKotlinMain:$versionKotlin",

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
kotlinVersion=1.5.10
1+
kotlinVersion=1.7.0
22
kotlin.code.style=official
33
systemProp.org.gradle.internal.publish.checksums.insecure=true

0 commit comments

Comments
 (0)