Skip to content

Commit 655c9eb

Browse files
committed
clean up
1 parent 5ebfee3 commit 655c9eb

File tree

1 file changed

+49
-54
lines changed

1 file changed

+49
-54
lines changed

build.gradle.kts

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ subprojects {
4141
val distributionFilePath =
4242
"${this.project.buildDir}${sep}distributions${sep}${this.project.name}-${this.project.version}.zip"
4343
val file = File(distributionFilePath)
44-
if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist")
45-
if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty")
44+
if (!file.exists()) throw GradleException("Distribution file: $distributionFilePath does not exist")
45+
if (file.length() == 0L) throw GradleException("Distribution file: $distributionFilePath is empty")
4646
}
4747
}
4848

@@ -67,22 +67,21 @@ tasks.register("validateDistributions") {
6767
subprojects {
6868
val subproject = this@subprojects
6969
if (subproject.name == "sentry-kotlin-multiplatform") {
70-
validateKotlinMultiplatformCoreArtifacts(subproject)
70+
subproject.validateKotlinMultiplatformCoreArtifacts()
7171
}
7272
}
7373
}
7474

75-
private fun validateKotlinMultiplatformCoreArtifacts(project: Project) {
76-
val rootDistributionFilePath =
77-
"${project.layout.buildDirectory.asFile.get().path}${sep}distributions"
75+
private fun Project.validateKotlinMultiplatformCoreArtifacts() {
76+
val distributionDir = project.layout.buildDirectory.dir("distributions").get().asFile
7877
val expectedNumOfFiles = 15
79-
val filesList = File(rootDistributionFilePath).listFiles()
80-
val actualNumberOfFiles = filesList?.size ?: 0
78+
val filesList = distributionDir.listFiles()
79+
val actualNumOfFiles = filesList?.size ?: 0
8180

82-
if (actualNumberOfFiles == expectedNumOfFiles) {
83-
println("✅ Found $actualNumberOfFiles distribution files as expected.")
81+
if (actualNumOfFiles == expectedNumOfFiles) {
82+
println("✅ Found $actualNumOfFiles distribution files as expected.")
8483
} else {
85-
throw IllegalStateException("❌ Expected $expectedNumOfFiles distribution files, but found $actualNumberOfFiles")
84+
throw GradleException("❌ Expected $expectedNumOfFiles distribution files, but found $actualNumOfFiles")
8685
}
8786

8887
val baseFileName = "sentry-kotlin-multiplatform"
@@ -94,66 +93,62 @@ private fun validateKotlinMultiplatformCoreArtifacts(project: Project) {
9493
"iosx64", "iossimulatorarm64", "iosarm64",
9594
"android"
9695
)
97-
val listOfArtifactPaths = buildList {
98-
add("$rootDistributionFilePath$sep$baseFileName-$version.zip")
96+
97+
val artifactPaths = buildList {
98+
add(distributionDir.resolve("$baseFileName-$version.zip"))
9999
addAll(
100100
platforms.map { platform ->
101-
"$rootDistributionFilePath$sep$baseFileName-$platform-$version.zip"
101+
distributionDir.resolve("$baseFileName-$platform-$version.zip")
102102
}
103103
)
104104
}
105105

106-
listOfArtifactPaths.forEach { artifactPath ->
107-
val artifactFile = File(artifactPath)
106+
val commonRequiredEntries = listOf(
107+
"javadoc",
108+
"sources",
109+
"module",
110+
"pom-default.xml"
111+
)
112+
113+
artifactPaths.forEach { artifactFile ->
108114
if (!artifactFile.exists()) {
109-
throw IllegalStateException("❌ Artifact file: $artifactPath does not exist")
115+
throw GradleException("❌ Artifact file: ${artifactFile.path} does not exist")
110116
}
111117
if (artifactFile.length() == 0L) {
112-
throw IllegalStateException("❌ Artifact file: $artifactPath is empty")
118+
throw GradleException("❌ Artifact file: ${artifactFile.path} is empty")
113119
}
114120

115-
val file = File(artifactPath)
116-
ZipFile(file).use { zip ->
121+
ZipFile(artifactFile).use { zip ->
117122
val entries = zip.entries().asSequence().map { it.name }.toList()
118-
val javadocFile = entries.firstOrNull { it.contains("javadoc") }
119-
if (javadocFile == null) {
120-
throw IllegalStateException("❌ javadoc file not found in ${file.name}")
121-
}
122-
val sourcesFile = entries.firstOrNull { it.contains("sources") }
123-
if (sourcesFile == null) {
124-
throw IllegalStateException("❌ sources file not found in ${file.name}")
125-
}
126-
val moduleFile = entries.firstOrNull { it.contains("module") }
127-
if (moduleFile == null) {
128-
throw IllegalStateException("❌ module file not found in ${file.name}")
129-
}
130-
val pomFile = entries.firstOrNull { it.contains("pom-default.xml") }
131-
if (pomFile == null) {
132-
throw IllegalStateException("❌ pom file not found in ${file.name}")
133-
}
134123

135-
val isAppleArtifact =
136-
file.name.contains("ios") || file.name.contains("macos") || file.name.contains("watchos") || file.name.contains(
137-
"tvos"
138-
)
139-
if (isAppleArtifact) {
140-
// this is hardcoded but will probably not change unless we add another cinterop library or remove one
141-
val expectedNumOfKlibFiles = 3
142-
val actualKlibFiles = entries.filter { it.contains("klib") }
143-
if (actualKlibFiles.size != expectedNumOfKlibFiles) {
144-
throw IllegalStateException("$expectedNumOfKlibFiles klib files not found in ${file.name}")
124+
commonRequiredEntries.forEach { requiredEntry ->
125+
if (entries.none { it.contains(requiredEntry) }) {
126+
throw GradleException("$requiredEntry not found in ${artifactFile.name}")
145127
} else {
146-
println("✅ Found $expectedNumOfKlibFiles klib files in ${file.name}")
128+
println("✅ Found $requiredEntry in ${artifactFile.name}")
147129
}
148130
}
149131

150-
val isAndroidArtifact = file.name.contains("android")
151-
if (isAndroidArtifact) {
152-
val aarFile = entries.firstOrNull() { it.contains("aar") }
153-
if (aarFile == null) {
154-
throw IllegalStateException("❌ aar file not found in ${file.name}")
155-
} else {
156-
println("✅ Found aar file in ${file.name}")
132+
when {
133+
artifactFile.name.contains("ios", ignoreCase = true) ||
134+
artifactFile.name.contains("macos", ignoreCase = true) ||
135+
artifactFile.name.contains("watchos", ignoreCase = true) ||
136+
artifactFile.name.contains("tvos", ignoreCase = true) -> {
137+
val expectedNumOfKlibFiles = 3
138+
val actualKlibFiles = entries.count { it.contains("klib") }
139+
if (actualKlibFiles != expectedNumOfKlibFiles) {
140+
throw GradleException("❌ Expected $expectedNumOfKlibFiles klib files in ${artifactFile.name}, but found $actualKlibFiles")
141+
} else {
142+
println("✅ Found $expectedNumOfKlibFiles klib files in ${artifactFile.name}")
143+
}
144+
}
145+
146+
artifactFile.name.contains("android", ignoreCase = true) -> {
147+
if (entries.none { it.contains("aar") }) {
148+
throw GradleException("❌ aar file not found in ${artifactFile.name}")
149+
} else {
150+
println("✅ Found aar file in ${artifactFile.name}")
151+
}
157152
}
158153
}
159154
}

0 commit comments

Comments
 (0)