| 525 | } |
| 526 | |
| 527 | fun zeroCompressMavenRepo(source: Path, destination: Path, validateArchives: Boolean, logger: Logger) { |
| 528 | val normalizedSource = source.normalizedAbsolute() |
| 529 | val normalizedDestination = destination.normalizedAbsolute() |
| 530 | |
| 531 | require(Files.isDirectory(normalizedSource)) { |
| 532 | "Maven repository directory does not exist or is not a directory: $normalizedSource" |
| 533 | } |
| 534 | require(!normalizedDestination.startsWith(normalizedSource)) { |
| 535 | "Zero-compressed output directory must not be inside the input repository: $normalizedDestination" |
| 536 | } |
| 537 | |
| 538 | Files.createDirectories(normalizedDestination) |
| 539 | |
| 540 | normalizedSource.toFile().walkTopDown() |
| 541 | .filter { it.isFile } |
| 542 | .forEach { file -> |
| 543 | val sourceFile = file.toPath() |
| 544 | val targetFile = normalizedDestination.resolve(normalizedSource.relativize(sourceFile)) |
| 545 | |
| 546 | Files.createDirectories(targetFile.parent) |
| 547 | |
| 548 | when (file.extension.lowercase()) { |
| 549 | "aar", "jar" -> { |
| 550 | zeroCompressArchive(sourceFile, targetFile) |
| 551 | if (validateArchives) { |
| 552 | validateZeroCompressedArchive(sourceFile, targetFile) |
| 553 | } |
| 554 | logger.lifecycle("Zero-compressed ${sourceFile.relativeTo(normalizedSource)}") |
| 555 | } |
| 556 | else -> Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING) |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | fun zeroCompressArchive(source: Path, destination: Path) { |
| 562 | ZipInputStream(Files.newInputStream(source).buffered()).use { input -> |
no test coverage detected