Created
December 6, 2016 17:27
-
-
Save soywiz/0f90f798e3314dc56a17685ad31abb84 to your computer and use it in GitHub Desktop.
Copy gradle cache structure into local m2 folder structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import java.security.MessageDigest | |
val gradleBase = System.getenv("HOME") + "/.gradle/caches/modules-2/files-2.1" | |
val m2Base = System.getenv("HOME") + "/.m2/repository" | |
fun ByteArray.toHex() = this.map { "%02x".format(it) }.joinToString("") | |
operator fun File.get(name: String) = File(this, name) | |
for (groupFolder in File(gradleBase).listFiles().filter { it.isDirectory }) { | |
val group = groupFolder.name | |
for (artifactFolder in groupFolder.listFiles().filter { it.isDirectory }) { | |
val artifact = artifactFolder.name | |
for (versionFolder in artifactFolder.listFiles().filter { it.isDirectory }) { | |
val version = versionFolder.name | |
val m2Folder = "${group.replace('.', '/')}/$artifact/$version" | |
val realM2Folder = File(m2Base + "/" + m2Folder) | |
realM2Folder.mkdirs() | |
for (fileFolder in versionFolder.listFiles().filter { it.isDirectory }) { | |
for (fileFile in fileFolder.listFiles().filter { !it.isDirectory }) { | |
val fileName = fileFile.name | |
val outFile = realM2Folder[fileName] | |
print("$outFile...") | |
if (!outFile.exists()) { | |
val fileData = fileFile.readBytes() | |
val sha1 = MessageDigest.getInstance("SHA-1").digest(fileData).toHex() | |
outFile.writeBytes(fileData) | |
File(outFile.absolutePath + ".sha1").writeText(sha1) | |
println("Ok") | |
} else { | |
println("Exists") | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment