Skip to content

Commit 887ef60

Browse files
authored
fix(publish): fetch javadoc for 2 digit release numbers (#282)
* update * update * update
1 parent 2d92948 commit 887ef60

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

buildSrc/src/main/java/Publication.kt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import org.gradle.api.distribution.DistributionContainer
33
import org.gradle.api.file.CopySpec
44
import java.io.File
55

6-
private object Consts {
7-
val taskRegex = Regex("(.*)DistZip")
8-
}
9-
10-
val sep = File.separator
6+
val sep: String = File.separator
117

128
// configure distZip tasks for multiplatform
139
fun DistributionContainer.configureForMultiplatform(project: Project) {
@@ -26,13 +22,16 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
2622
}
2723
from("build${sep}kotlinToolingMetadata") {
2824
rename {
29-
it.replace("kotlin-tooling-metadata.json", "${project.name}-$version-kotlin-tooling-metadata.json")
25+
it.replace(
26+
"kotlin-tooling-metadata.json",
27+
"${project.name}-$version-kotlin-tooling-metadata.json"
28+
)
3029
}
3130
}
3231
from("build${sep}libs") {
33-
include("${project.name}-?.?.*")
3432
include("${project.name}-kotlin*")
3533
include("${project.name}-metadata*")
34+
withJavadoc(project.name)
3635
rename {
3736
it.replace("multiplatform-kotlin", "multiplatform").replace("-metadata", "")
3837
}
@@ -188,34 +187,42 @@ private fun CopySpec.fromKlib(projectName: String, target: String, version: Stri
188187
from("build${sep}classes${sep}kotlin${sep}${target}${sep}main${sep}cinterop") {
189188
include("*.klib")
190189
rename {
191-
it.replaceRange(pos, pos, "-${target.toLowerCase()}-$version")
190+
it.replaceRange(pos, pos, "-${target.lowercase()}-$version")
192191
}
193192
}
194193
from("build${sep}classes${sep}kotlin${sep}${target}${sep}main${sep}klib") {
195194
rename {
196-
"$projectName-${target.toLowerCase()}-$version.klib"
195+
"$projectName-${target.lowercase()}-$version.klib"
197196
}
198197
}
199198
}
200199

201200
private fun CopySpec.renameModule(projectName: String, renameTo: String = "", version: String) {
202201
var target = ""
203-
if (!renameTo.isEmpty()) {
202+
if (renameTo.isNotEmpty()) {
204203
target = "-$renameTo"
205204
}
206205
rename {
207206
it.replace("module.json", "$projectName$target-$version.module")
208207
}
209208
}
210209

211-
private fun CopySpec.withJavadoc(projectName: String, renameTo: String) {
210+
private fun CopySpec.withJavadoc(projectName: String, renameTo: String = "") {
212211
include("*javadoc*")
213-
rename {
214-
if (it.contains("javadoc")) {
215-
val pos = projectName.length
216-
it.replaceRange(pos, pos, "-$renameTo")
217-
} else {
218-
it
212+
rename { fileName ->
213+
when {
214+
"javadoc" in fileName -> {
215+
val newName = buildString {
216+
append(fileName.substring(0, projectName.length))
217+
if (renameTo.isNotEmpty()) {
218+
append('-')
219+
append(renameTo)
220+
}
221+
append(fileName.substring(projectName.length))
222+
}
223+
newName
224+
}
225+
else -> fileName
219226
}
220227
}
221228
}

0 commit comments

Comments
 (0)