| 1193 | } |
| 1194 | |
| 1195 | fun assetsFileDownload( |
| 1196 | asset: Asset, |
| 1197 | target: File, |
| 1198 | ) { |
| 1199 | if (isCiCd) { |
| 1200 | val stagedFile = stagedFileFor(asset, rootProject.projectDir) |
| 1201 | if (!stagedFile.exists()) { |
| 1202 | throw GradleException("Staged file not found: ${stagedFile.absolutePath}") |
| 1203 | } |
| 1204 | target.parentFile.mkdirs() |
| 1205 | stagedFile.copyTo(target, overwrite = true) |
| 1206 | project.logger.lifecycle("Copied staged ${stagedFile.absolutePath} → ${target.absolutePath}") |
| 1207 | } else { |
| 1208 | val url = URL(asset.url) |
| 1209 | val conn = url.openConnection() as HttpURLConnection |
| 1210 | conn.requestMethod = "GET" |
| 1211 | conn.setRequestProperty( |
| 1212 | "User-Agent", |
| 1213 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", |
| 1214 | ) |
| 1215 | conn.setRequestProperty("Accept", "*/*") |
| 1216 | conn.setRequestProperty("Connection", "keep-alive") |
| 1217 | conn.instanceFollowRedirects = true |
| 1218 | conn.connectTimeout = 10_000 |
| 1219 | conn.readTimeout = 10_000 |
| 1220 | |
| 1221 | try { |
| 1222 | val status = conn.responseCode |
| 1223 | if (status == HttpURLConnection.HTTP_OK) { |
| 1224 | // Stream the response body into the target file |
| 1225 | conn.inputStream.use { input -> |
| 1226 | target.outputStream().use { output -> |
| 1227 | input.copyTo(output) |
| 1228 | } |
| 1229 | } |
| 1230 | project.logger.lifecycle("Downloaded ${asset.url} → ${target.absolutePath}") |
| 1231 | } else { |
| 1232 | throw GradleException("Failed to download ${asset.url} (HTTP $status: ${conn.responseMessage})") |
| 1233 | } |
| 1234 | } finally { |
| 1235 | conn.disconnect() |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | fun assetsFileChecksum(asset: Asset): String? { |
| 1241 | return if (isCiCd) { |
no test coverage detected