MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / convertCacheToLocalMavenRepo

Function convertCacheToLocalMavenRepo

build.gradle.kts:487–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485 toAbsolutePath().normalize()
486
487fun convertCacheToLocalMavenRepo(source: Path, destination: Path, logger: Logger) {
488 val allowedExtensions = setOf("aar", "jar", "module", "pom")
489 val normalizedSource = source.normalizedAbsolute()
490 val normalizedDestination = destination.normalizedAbsolute()
491
492 require(Files.isDirectory(normalizedSource)) {
493 "Maven cache directory does not exist or is not a directory: $normalizedSource"
494 }
495 require(!normalizedDestination.startsWith(normalizedSource)) {
496 "Local Maven output directory must not be inside the input cache: $normalizedDestination"
497 }
498
499 Files.createDirectories(normalizedDestination)
500
501 normalizedSource.toFile().walkTopDown()
502 .filter { it.isFile }
503 .filter { it.extension.lowercase() in allowedExtensions }
504 .forEach { file ->
505 val filePath = file.toPath()
506 val relativeParent =
507 filePath.parent
508 ?.let { normalizedSource.relativize(it).map(Path::toString).toList() }
509 .orEmpty()
510
511 val targetParts =
512 if (relativeParent.firstOrNull()?.contains(".") == true) {
513 relativeParent.first().split(".") + relativeParent.drop(1).dropLast(1)
514 } else {
515 relativeParent.dropLast(1)
516 }
517
518 val targetParent = normalizedDestination.resolveParts(targetParts)
519 val targetFile = targetParent.resolve(file.name)
520
521 Files.createDirectories(targetParent)
522 Files.copy(filePath, targetFile, StandardCopyOption.REPLACE_EXISTING)
523 logger.lifecycle("Copied ${filePath.relativeTo(normalizedSource)} -> ${targetFile.relativeTo(normalizedDestination)}")
524 }
525}
526
527fun zeroCompressMavenRepo(source: Path, destination: Path, validateArchives: Boolean, logger: Logger) {
528 val normalizedSource = source.normalizedAbsolute()

Callers 1

build.gradle.ktsFile · 0.85

Calls 15

requireFunction · 0.85
lowercaseMethod · 0.80
startsWithMethod · 0.65
mapMethod · 0.65
containsMethod · 0.65
splitMethod · 0.65
resolveMethod · 0.65
copyMethod · 0.65
isDirectoryMethod · 0.45
forEachMethod · 0.45
filterMethod · 0.45
toFileMethod · 0.45

Tested by

no test coverage detected