Skip to content

Commit 75655ee

Browse files
Adding KtLint
1 parent d146084 commit 75655ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+903
-815
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# .editorconfig
2+
root = true
3+
4+
[*.{kt,kts}]
5+
end_of_line = lf
6+
ij_kotlin_packages_to_use_import_on_demand = true
7+
ij_kotlin_allow_trailing_comma = true
8+
ij_kotlin_allow_trailing_comma_on_call_site = true
9+
ij_kotlin_imports_layout = *
10+
ij_kotlin_indent_before_arrow_on_new_line = false
11+
ij_kotlin_line_break_after_multiline_when_entry = true
12+
indent_size = 4
13+
indent_style = space
14+
insert_final_newline = true
15+
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = 8
16+
ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 4
17+
ktlint_code_style = android_studio
18+
ktlint_enum_entry_name_casing = upper_or_camel_cases
19+
ktlint_function_naming_ignore_when_annotated_with = Composable
20+
ktlint_function_signature_body_expression_wrapping = default
21+
ktlint_ignore_back_ticked_identifier = false
22+
max_line_length = 140
23+
parameter-list-wrapping = true

build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ plugins {
1414
alias(libs.plugins.kotlin) apply false
1515
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.0" apply false
1616
alias(libs.plugins.maven.publish) apply false
17+
id("org.jlleitschuh.gradle.ktlint") version "12.2.0" apply false
1718
}
1819

1920
subprojects {
21+
apply(plugin = "org.jlleitschuh.gradle.ktlint")
2022
repositories {
2123
gradlePluginPortal()
2224
mavenCentral()
@@ -25,6 +27,14 @@ subprojects {
2527
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension>()?.apply {
2628
jvmToolchain(17)
2729
}
30+
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
31+
version.set("1.4.0")
32+
enableExperimentalRules.set(true)
33+
verbose.set(true)
34+
filter {
35+
exclude { it.file.path.contains("build/") }
36+
}
37+
}
2838

2939
val GROUP: String by project
3040
val VERSION_NAME: String by project
@@ -36,5 +46,8 @@ subprojects {
3646
tasks.getByName<Test>("test") {
3747
useJUnitPlatform()
3848
}
49+
tasks.named("check") {
50+
dependsOn(tasks.getByName("ktlintCheck"))
51+
}
3952
}
4053
}

kmmbridge-github/build.gradle.kts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins {
2020
id("java-gradle-plugin")
2121
alias(libs.plugins.maven.publish)
2222
id("com.gradle.plugin-publish") version "1.0.0"
23+
id("org.jlleitschuh.gradle.ktlint")
2324
}
2425

2526
@Suppress("UnstableApiUsage")
@@ -33,18 +34,19 @@ gradlePlugin {
3334
id = "co.touchlab.kmmbridge.github"
3435
implementationClass = "co.touchlab.kmmbridge.github.KMMBridgeGitHubPlugin"
3536
displayName = "KMMBridge/GitHub"
36-
tags = listOf(
37-
"kmm",
38-
"kotlin",
39-
"multiplatform",
40-
"mobile",
41-
"ios",
42-
"xcode",
43-
"framework",
44-
"binary",
45-
"publish",
46-
"consume"
47-
)
37+
tags =
38+
listOf(
39+
"kmm",
40+
"kotlin",
41+
"multiplatform",
42+
"mobile",
43+
"ios",
44+
"xcode",
45+
"framework",
46+
"binary",
47+
"publish",
48+
"consume",
49+
)
4850
}
4951
}
5052
}
@@ -67,4 +69,4 @@ mavenPublishing {
6769
pomFromGradleProperties()
6870
@Suppress("UnstableApiUsage")
6971
configureBasedOnAppliedPlugins()
70-
}
72+
}

kmmbridge-github/src/main/kotlin/Extensions.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,21 @@ import co.touchlab.kmmbridge.github.internal.githubPublishUser
55
import co.touchlab.kmmbridge.github.internal.githubRepoOrNull
66
import co.touchlab.kmmbridge.github.kmmBridgeExtension
77
import co.touchlab.kmmbridge.publishingExtension
8-
import org.gradle.api.Project
98
import java.net.URI
9+
import org.gradle.api.Project
1010

1111
@Suppress("unused")
12-
fun Project.gitHubReleaseArtifacts(
13-
repository: String? = null,
14-
releasString: String? = null,
15-
useExistingRelease: Boolean = false
16-
) {
12+
fun Project.gitHubReleaseArtifacts(repository: String? = null, releasString: String? = null, useExistingRelease: Boolean = false) {
1713
kmmBridgeExtension.setupGitHubReleaseArtifacts(
1814
GithubReleaseArtifactManager(
1915
repository,
2016
releasString,
21-
useExistingRelease
22-
)
17+
useExistingRelease,
18+
),
2319
)
2420
}
2521

26-
private fun KmmBridgeExtension.setupGitHubReleaseArtifacts(
27-
githubReleaseArtifactManager: GithubReleaseArtifactManager
28-
) {
22+
private fun KmmBridgeExtension.setupGitHubReleaseArtifacts(githubReleaseArtifactManager: GithubReleaseArtifactManager) {
2923
artifactManager.setAndFinalize(githubReleaseArtifactManager)
3024
}
3125

@@ -53,4 +47,4 @@ fun Project.addGithubPackagesRepository() {
5347
}
5448
}
5549
}
56-
}
50+
}

kmmbridge-github/src/main/kotlin/co/touchlab/kmmbridge/github/GithubReleaseArtifactManager.kt

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ import co.touchlab.kmmbridge.github.internal.githubArtifactIdentifierName
77
import co.touchlab.kmmbridge.github.internal.githubArtifactReleaseId
88
import co.touchlab.kmmbridge.github.internal.githubPublishToken
99
import co.touchlab.kmmbridge.github.internal.githubRepo
10+
import java.io.File
11+
import kotlin.properties.Delegates
1012
import org.gradle.api.GradleException
1113
import org.gradle.api.Project
1214
import org.gradle.api.Task
1315
import org.gradle.api.tasks.Input
1416
import org.gradle.api.tasks.TaskProvider
1517
import org.gradle.kotlin.dsl.getByType
16-
import java.io.File
17-
import kotlin.properties.Delegates
1818

1919
open class GithubReleaseArtifactManager(
2020
private val repository: String?,
2121
private val releaseString: String?,
22-
@Deprecated("Releases should be created externally. This parameter controls the flow for releases created " +
23-
"by this class, which will eventually be unsupported.")
24-
private val useExistingRelease: Boolean
22+
@Deprecated(
23+
"Releases should be created externally. This parameter controls the flow for releases created " +
24+
"by this class, which will eventually be unsupported.",
25+
)
26+
private val useExistingRelease: Boolean,
2527
) : ArtifactManager {
26-
2728
@get:Input
2829
lateinit var releaseVersion: String
2930

@@ -43,9 +44,7 @@ open class GithubReleaseArtifactManager(
4344
// https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:secrets
4445
lateinit var githubPublishToken: String
4546

46-
override fun configure(
47-
project: Project, version: String, uploadTask: TaskProvider<Task>, kmmPublishTask: TaskProvider<Task>
48-
) {
47+
override fun configure(project: Project, version: String, uploadTask: TaskProvider<Task>, kmmPublishTask: TaskProvider<Task>) {
4948
this.releaseVersion = releaseString ?: project.version.toString()
5049
this.repoName = this.repository ?: project.githubRepo
5150
this.githubPublishToken = project.githubPublishToken
@@ -55,47 +54,55 @@ open class GithubReleaseArtifactManager(
5554
}
5655

5756
override fun deployArtifact(task: Task, zipFilePath: File, version: String): String {
58-
val uploadReleaseId = if (artifactReleaseId == 0) {
59-
val existingReleaseId = GithubCalls.findReleaseId(
60-
githubPublishToken, repoName, releaseVersion
61-
)
62-
63-
task.logger.info("existingReleaseId: $existingReleaseId")
64-
65-
if (existingReleaseId != null && !useExistingRelease) {
66-
throw GradleException("Release for '$releaseVersion' exists. Set 'useExistingRelease = true' to update existing releases.")
57+
val uploadReleaseId =
58+
if (artifactReleaseId == 0) {
59+
val existingReleaseId =
60+
GithubCalls.findReleaseId(
61+
githubPublishToken,
62+
repoName,
63+
releaseVersion,
64+
)
65+
66+
task.logger.info("existingReleaseId: $existingReleaseId")
67+
68+
if (existingReleaseId != null && !useExistingRelease) {
69+
throw GradleException(
70+
"Release for '$releaseVersion' exists. Set 'useExistingRelease = true' to update existing releases.",
71+
)
72+
}
73+
74+
val idReply: Int =
75+
existingReleaseId ?: GithubCalls.createRelease(
76+
githubPublishToken,
77+
repoName,
78+
releaseVersion,
79+
null,
80+
)
81+
82+
task.logger.info("GitHub Release created with id: $idReply")
83+
84+
idReply
85+
} else {
86+
artifactReleaseId
6787
}
6888

69-
val idReply: Int = existingReleaseId ?: GithubCalls.createRelease(
70-
githubPublishToken, repoName, releaseVersion, null
71-
)
72-
73-
task.logger.info("GitHub Release created with id: $idReply")
74-
75-
idReply
76-
} else {
77-
artifactReleaseId
78-
}
79-
8089
val fileName = artifactName(version, useExistingRelease)
8190

8291
val uploadUrl = GithubCalls.uploadZipFile(githubPublishToken, zipFilePath, repoName, uploadReleaseId, fileName)
83-
return "${uploadUrl}.zip"
92+
return "$uploadUrl.zip"
8493
}
8594

86-
private fun artifactName(versionString: String, useExistingRelease: Boolean): String {
87-
return if (useExistingRelease) {
88-
"$frameworkName-${versionString}-${(System.currentTimeMillis() / 1000)}.xcframework.zip"
89-
} else {
90-
uploadZipFileName(versionString)
91-
}
95+
private fun artifactName(versionString: String, useExistingRelease: Boolean): String = if (useExistingRelease) {
96+
"$frameworkName-$versionString-${(System.currentTimeMillis() / 1000)}.xcframework.zip"
97+
} else {
98+
uploadZipFileName(versionString)
9299
}
93100

94101
open fun uploadZipFileName(versionString: String) = if (artifactIdentifierName.isNotEmpty()) {
95-
"$frameworkName-${artifactIdentifierName}.xcframework.zip"
102+
"$frameworkName-$artifactIdentifierName.xcframework.zip"
96103
} else {
97104
"$frameworkName.xcframework.zip"
98105
}
99106
}
100107

101-
internal val Project.kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension>()
108+
internal val Project.kmmBridgeExtension get() = extensions.getByType<KmmBridgeExtension>()

0 commit comments

Comments
 (0)