From 1838285850cf0001e07893efbb8049ed3b7f11e2 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 4 Dec 2024 20:02:13 +0800 Subject: [PATCH 01/13] Mark funcTest depend on the output of intiTest --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index 8cdb3d17e..42fbbde71 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -86,6 +86,7 @@ dependencies { exclude(group = "org.hamcrest") } funcTestImplementation(sourceSets.main.get().output) + funcTestImplementation(intiTest.output) lintChecks(libs.androidx.gradlePluginLints) lintChecks(libs.assertk.lint) From 8d780455c912df2cc44b60a875337f0cd70f876f Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 4 Dec 2024 20:04:40 +0800 Subject: [PATCH 02/13] Convert AppendableJar and JarBuilder --- .../plugins/shadow/util/AppendableJar.groovy | 25 --------- .../plugins/shadow/util/JarBuilder.groovy | 51 ------------------- .../plugins/shadow/util/AppendableJar.kt | 20 ++++++++ .../gradle/plugins/shadow/util/JarBuilder.kt | 42 +++++++++++++++ 4 files changed, 62 insertions(+), 76 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.groovy delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.kt create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.groovy deleted file mode 100644 index b6fad7012..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.groovy +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util - -class AppendableJar { - - Map contents = [:] - File file - - AppendableJar(File file) { - this.file = file - } - - AppendableJar insertFile(String path, String content) { - contents[path] = content - return this - } - - File write() { - JarBuilder builder = new JarBuilder(file.newOutputStream()) - contents.each { path, contents -> - builder.withFile(path, contents) - } - builder.build() - return file - } -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.groovy deleted file mode 100644 index b24eb994c..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.groovy +++ /dev/null @@ -1,51 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util - -import org.codehaus.plexus.util.IOUtil - -import java.util.jar.JarEntry -import java.util.jar.JarOutputStream - -class JarBuilder { - - List entries = [] - JarOutputStream jos - - JarBuilder(OutputStream os) { - jos = new JarOutputStream(os) - } - - private void addDirectory(String name) { - if (!entries.contains(name)) { - if (name.lastIndexOf('/') > 0) { - String parent = name.substring(0, name.lastIndexOf('/')) - if (!entries.contains(parent)) { - addDirectory(parent) - } - } - - // directory entries must end in "/" - JarEntry entry = new JarEntry(name + "/") - jos.putNextEntry(entry) - - entries.add(name) - } - } - - JarBuilder withFile(String path, String data) { - def idx = path.lastIndexOf('/') - if (idx != -1) { - addDirectory(path.substring(0, idx)) - } - if (!entries.contains(path)) { - JarEntry entry = new JarEntry(path) - jos.putNextEntry(entry) - entries << path - IOUtil.copy(data.bytes, jos) - } - return this - } - - void build() { - jos.close() - } -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.kt new file mode 100644 index 000000000..798a06bf7 --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableJar.kt @@ -0,0 +1,20 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +import java.io.File + +class AppendableJar(private val file: File) { + private val contents = mutableMapOf() + + fun insertFile(path: String, content: String): AppendableJar = apply { + contents[path] = content + } + + fun write(): File { + val builder = JarBuilder(file.outputStream()) + contents.forEach { (path, content) -> + builder.withFile(path, content) + } + builder.build() + return file + } +} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt new file mode 100644 index 000000000..d4c81cabb --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt @@ -0,0 +1,42 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +import java.io.OutputStream +import java.util.jar.JarEntry +import java.util.jar.JarOutputStream + +class JarBuilder(os: OutputStream) { + private val entries = mutableListOf() + private val jos = JarOutputStream(os) + + private fun addDirectory(name: String) { + if (!entries.contains(name)) { + val parent = name.substringBeforeLast('/', "") + if (parent.isNotEmpty() && !entries.contains(parent)) { + addDirectory(parent) + } + + // directory entries must end in "/" + val entry = JarEntry("$name/") + jos.putNextEntry(entry) + entries.add(name) + } + } + + fun withFile(path: String, data: String): JarBuilder { + val idx = path.lastIndexOf('/') + if (idx != -1) { + addDirectory(path.substring(0, idx)) + } + if (!entries.contains(path)) { + val entry = JarEntry(path) + jos.putNextEntry(entry) + entries.add(path) + data.byteInputStream().use { it.copyTo(jos) } + } + return this + } + + fun build() { + jos.close() + } +} From 22a736102352bab4e16d727f7930ff063ee7c40e Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 4 Dec 2024 20:07:48 +0800 Subject: [PATCH 03/13] Convert HashUtil and HashValue --- .../gradle/plugins/shadow/util/HashUtil.java | 93 ------------------- .../gradle/plugins/shadow/util/HashValue.java | 75 --------------- .../shadow/util/repo/AbstractModule.groovy | 2 +- .../gradle/plugins/shadow/util/HashUtil.kt | 55 +++++++++++ .../gradle/plugins/shadow/util/HashValue.kt | 7 ++ 5 files changed, 63 insertions(+), 169 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashValue.java create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashValue.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java deleted file mode 100644 index b4cb8404d..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util; - -import org.gradle.api.UncheckedIOException; -import org.gradle.internal.UncheckedException; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class HashUtil { - public static HashValue createHash(File file, String algorithm) { - try { - return createHash(new FileInputStream(file), algorithm); - } catch (UncheckedIOException e) { - // Catch any unchecked io exceptions and add the file path for troubleshooting - throw new UncheckedIOException(String.format("Failed to create %s hash for file %s.", algorithm, file.getAbsolutePath()), e.getCause()); - } catch (FileNotFoundException e) { - throw new UncheckedIOException(e); - } - } - - private static HashValue createHash(InputStream instr, String algorithm) { - MessageDigest messageDigest; - try { - messageDigest = createMessageDigest(algorithm); - byte[] buffer = new byte[4096]; - try { - while (true) { - int nread = instr.read(buffer); - if (nread < 0) { - break; - } - messageDigest.update(buffer, 0, nread); - } - } finally { - instr.close(); - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return new HashValue(messageDigest.digest()); - } - - private static MessageDigest createMessageDigest(String algorithm) { - try { - return MessageDigest.getInstance(algorithm); - } catch (NoSuchAlgorithmException e) { - throw UncheckedException.throwAsUncheckedException(e); - } - } - - public static HashValue sha1(byte[] bytes) { - return createHash(new ByteArrayInputStream(bytes), "SHA1"); - } - - public static HashValue sha1(InputStream inputStream) { - return createHash(inputStream, "SHA1"); - } - - public static HashValue md5(File file) { - return createHash(file, "MD5"); - } - - public static HashValue sha1(File file) { - return createHash(file, "SHA1"); - } - - public static HashValue sha256(byte[] bytes) { - return createHash(new ByteArrayInputStream(bytes), "SHA-256"); - } - - public static HashValue sha256(InputStream inputStream) { - return createHash(inputStream, "SHA-256"); - } - - public static HashValue sha256(File file) { - return createHash(file, "SHA-256"); - } - - public static HashValue sha512(InputStream inputStream) { - return createHash(inputStream, "SHA-512"); - } - - public static HashValue sha512(File file) { - return createHash(file, "SHA-512"); - } -} - diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashValue.java b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashValue.java deleted file mode 100644 index 967afe7ea..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashValue.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util; - -import java.math.BigInteger; - -public class HashValue { - private final BigInteger digest; - - public HashValue(byte[] digest) { - this.digest = new BigInteger(1, digest); - } - - public HashValue(String hexString) { - this.digest = new BigInteger(hexString, 16); - } - - public static HashValue parse(String inputString) { - if (inputString == null || inputString.isEmpty()) { - return null; - } - return new HashValue(parseInput(inputString)); - } - - private static String parseInput(String inputString) { - if (inputString == null) { - return null; - } - String cleaned = inputString.trim().toLowerCase(); - int spaceIndex = cleaned.indexOf(' '); - if (spaceIndex != -1) { - String firstPart = cleaned.substring(0, spaceIndex); - if (firstPart.startsWith("md") || firstPart.startsWith("sha")) { - cleaned = cleaned.substring(cleaned.lastIndexOf(' ') + 1); - } else if (firstPart.endsWith(":")) { - cleaned = cleaned.substring(spaceIndex + 1).replace(" ", ""); - } else { - cleaned = cleaned.substring(0, spaceIndex); - } - } - return cleaned; - } - - public String asCompactString() { - return digest.toString(36); - } - - public String asHexString() { - return digest.toString(16); - } - - public byte[] asByteArray() { - return digest.toByteArray(); - } - - public BigInteger asBigInteger() { - return digest; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (!(other instanceof HashValue)) { - return false; - } - - HashValue otherHashValue = (HashValue) other; - return digest.equals(otherHashValue.digest); - } - - @Override - public int hashCode() { - return digest.hashCode(); - } -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy index 8b99bf018..65301139d 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy @@ -66,6 +66,6 @@ abstract class AbstractModule { } private static BigInteger getHash(File file, String algorithm) { - HashUtil.createHash(file, algorithm.toUpperCase()).asBigInteger() + HashUtil.createHash(file, algorithm.toUpperCase()).getDigest() } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt new file mode 100644 index 000000000..315a0143c --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt @@ -0,0 +1,55 @@ +package com.github.jengelman.gradle.plugins.shadow.util +import java.io.File +import java.io.FileInputStream +import java.io.FileNotFoundException +import java.io.IOException +import java.io.InputStream +import java.io.UncheckedIOException +import java.security.MessageDigest +import java.security.NoSuchAlgorithmException +import org.gradle.internal.UncheckedException + +object HashUtil { + @JvmStatic + fun createHash(file: File, algorithm: String): HashValue { + try { + return createHash(FileInputStream(file), algorithm) + } catch (e: UncheckedIOException) { + // Catch any unchecked io exceptions and add the file path for troubleshooting + throw UncheckedIOException( + "Failed to create $algorithm hash for file ${file.absolutePath}.", + e.cause, + ) + } catch (e: FileNotFoundException) { + throw UncheckedIOException(e) + } + } + + private fun createHash(inputStream: InputStream, algorithm: String): HashValue { + val messageDigest: MessageDigest + try { + messageDigest = createMessageDigest(algorithm) + val buffer = ByteArray(4096) + inputStream.use { + while (true) { + val nread = it.read(buffer) + if (nread < 0) { + break + } + messageDigest.update(buffer, 0, nread) + } + } + } catch (e: IOException) { + throw UncheckedIOException(e) + } + return HashValue(messageDigest.digest()) + } + + private fun createMessageDigest(algorithm: String): MessageDigest { + try { + return MessageDigest.getInstance(algorithm) + } catch (e: NoSuchAlgorithmException) { + throw UncheckedException.throwAsUncheckedException(e) + } + } +} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashValue.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashValue.kt new file mode 100644 index 000000000..821a0953b --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashValue.kt @@ -0,0 +1,7 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +import java.math.BigInteger + +data class HashValue(val digest: BigInteger) { + constructor(digest: ByteArray) : this(BigInteger(1, digest)) +} From 979f79f64a57e9c1c9ac2562a886fac868e6b288 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 9 Dec 2024 20:22:17 +0800 Subject: [PATCH 04/13] Convert AbstractModule --- .../shadow/util/repo/AbstractModule.groovy | 71 ------------------- .../repo/maven/AbstractMavenModule.groovy | 8 +-- .../util/repo/maven/MavenFileModule.groovy | 4 +- .../gradle/plugins/shadow/util/HashUtil.kt | 1 - .../shadow/util/repo/AbstractModule.kt | 63 ++++++++++++++++ 5 files changed, 70 insertions(+), 77 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy deleted file mode 100644 index 65301139d..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy +++ /dev/null @@ -1,71 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo - -import com.github.jengelman.gradle.plugins.shadow.util.HashUtil - -abstract class AbstractModule { - /** - * @param cl A closure that is passed a writer to use to generate the content. - */ - protected void publish(File file, Closure cl) { - def hashBefore = file.exists() ? getHash(file, "sha1") : null - def tmpFile = file.parentFile.resolve("${file.name}.tmp") - - tmpFile.withWriter("utf-8") { - cl.call(it) - } - - def hashAfter = getHash(tmpFile, "sha1") - if (hashAfter == hashBefore) { - // Already published - return - } - - assert !file.exists() || file.delete() - assert tmpFile.renameTo(file) - onPublish(file) - } - - protected void publishWithStream(File file, Closure cl) { - def hashBefore = file.exists() ? getHash(file, "sha1") : null - def tmpFile = file.parentFile.resolve("${file.name}.tmp") - - tmpFile.withOutputStream { - cl.call(it) - } - - def hashAfter = getHash(tmpFile, "sha1") - if (hashAfter == hashBefore) { - // Already published - return - } - - assert !file.exists() || file.delete() - assert tmpFile.renameTo(file) - onPublish(file) - } - - protected abstract onPublish(File file) - - static File sha1File(File file) { - hashFile(file, "sha1", 40) - } - - static File md5File(File file) { - hashFile(file, "md5", 32) - } - - private static File hashFile(File file, String algorithm, int len) { - def hashFile = getHashFile(file, algorithm) - def hash = getHash(file, algorithm) - hashFile.text = String.format("%0${len}x", hash) - return hashFile - } - - private static File getHashFile(File file, String algorithm) { - file.parentFile.resolve("${file.name}.${algorithm}") - } - - private static BigInteger getHash(File file, String algorithm) { - HashUtil.createHash(file, algorithm.toUpperCase()).getDigest() - } -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy index aa3ec713b..bd86f29ec 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy @@ -111,12 +111,12 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule updateRootMavenMetaData(rootMavenMetaData) if (publishesMetaDataFile()) { - publish(metaDataFile) { Writer writer -> + publishWithWriter(metaDataFile) { Writer writer -> writer << getMetaDataFileContent() } } - publish(pomFile) { Writer writer -> + publishWithWriter(pomFile) { Writer writer -> def pomPackaging = packaging ?: type writer << """ @@ -160,7 +160,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule private void updateRootMavenMetaData(File rootMavenMetaData) { def allVersions = rootMavenMetaData.exists() ? new XmlParser().parseText(rootMavenMetaData.text).versioning.versions.version*.value().flatten() : [] allVersions << version - publish(rootMavenMetaData) { Writer writer -> + publishWithWriter(rootMavenMetaData) { Writer writer -> def builder = new MarkupBuilder(writer) builder.metadata { groupId(groupId) @@ -203,7 +203,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule if (type == 'pom') { return artifactFile } - publish(artifactFile) { Writer writer -> + publishWithWriter(artifactFile) { Writer writer -> writer << "${artifactFile.name} : $artifactContent" } return artifactFile diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy index fad253beb..80d482224 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy @@ -1,5 +1,7 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven +import org.jetbrains.annotations.NotNull + class MavenFileModule extends AbstractMavenModule { private boolean uniqueSnapshots = true @@ -32,7 +34,7 @@ class MavenFileModule extends AbstractMavenModule { } @Override - protected onPublish(File file) { + protected void onPublish(@NotNull File file) { sha1File(file) md5File(file) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt index 315a0143c..492a8a526 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.kt @@ -10,7 +10,6 @@ import java.security.NoSuchAlgorithmException import org.gradle.internal.UncheckedException object HashUtil { - @JvmStatic fun createHash(file: File, algorithm: String): HashValue { try { return createHash(FileInputStream(file), algorithm) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.kt new file mode 100644 index 000000000..51d740e5d --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.kt @@ -0,0 +1,63 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo + +import com.github.jengelman.gradle.plugins.shadow.util.HashUtil +import java.io.File +import java.io.OutputStream +import java.io.Writer +import java.math.BigInteger + +abstract class AbstractModule { + + protected abstract fun onPublish(file: File) + + protected fun publishWithWriter(file: File, action: (Writer) -> Unit) { + publishCommon(file) { it.writer().use(action) } + } + + protected fun publishWithStream(file: File, action: (OutputStream) -> Unit) { + publishCommon(file) { it.outputStream().use(action) } + } + + private fun publishCommon(file: File, action: (File) -> Unit) { + val hashBefore = if (file.exists()) getHash(file, "sha1") else null + val tempFile = file.resolveSibling("${file.name}.tmp") + action(tempFile) + + val hashAfter = getHash(tempFile, "sha1") + if (hashAfter == hashBefore) { + // Already published + return + } + + check(!file.exists() || file.delete()) + check(tempFile.renameTo(file)) + onPublish(file) + } + + companion object { + @JvmStatic + fun sha1File(file: File): File { + return hashFile(file, "sha1", 40) + } + + @JvmStatic + fun md5File(file: File): File { + return hashFile(file, "md5", 32) + } + + private fun hashFile(file: File, algorithm: String, len: Int): File { + val hashFile = getHashFile(file, algorithm) + val hash = getHash(file, algorithm) + hashFile.writeText("$hash${len}x") + return hashFile + } + + private fun getHashFile(file: File, algorithm: String): File { + return File(file.parentFile, "${file.name}.$algorithm") + } + + private fun getHash(file: File, algorithm: String): BigInteger { + return HashUtil.createHash(file, algorithm.uppercase()).digest + } + } +} From e21cbdcfd44f5f036a986df10acc114f6142877e Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 9 Dec 2024 20:29:32 +0800 Subject: [PATCH 05/13] Convert MavenModule --- .../shadow/util/repo/maven/MavenModule.groovy | 20 ----------------- .../shadow/util/repo/maven/MavenModule.kt | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.groovy deleted file mode 100644 index dd74383e3..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.groovy +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo.maven - -interface MavenModule { - /** - * Publishes the pom.xml plus main artifact, plus any additional artifacts for this module. Publishes only those artifacts whose content has - * changed since the last call to {@code #publish()}. - */ - MavenModule publish() - - /** - * Publishes the pom.xml only - */ - MavenModule publishPom() - - MavenModule dependsOn(String group, String artifactId, String version) - - File getPomFile() - - File getMetaDataFile() -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt new file mode 100644 index 000000000..484789e1c --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt @@ -0,0 +1,22 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo.maven + +import java.io.File + +interface MavenModule { + /** + * Publishes the `pom.xml` plus main artifact, plus any additional artifacts for this module. + * Publishes only those artifacts whose content has changed since the last call to `publish()`. + */ + fun publish(): MavenModule + + /** + * Publishes the `pom.xml` only + */ + fun publishPom(): MavenModule + + fun dependsOn(group: String, artifactId: String, version: String): MavenModule + + val pomFile: File + + val metaDataFile: File +} From 10f6fa333aac31e45172d39fc645698c46100251 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 9 Dec 2024 20:45:37 +0800 Subject: [PATCH 06/13] Convert MavenRepository --- .../shadow/util/repo/maven/MavenRepository.groovy | 12 ------------ .../shadow/util/repo/maven/MavenRepository.kt | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.groovy deleted file mode 100644 index 614b083bb..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.groovy +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo.maven - -/** - * A fixture for dealing with Maven repositories. - */ -interface MavenRepository { - URI getUri() - - MavenModule module(String groupId, String artifactId) - - MavenModule module(String groupId, String artifactId, String version) -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.kt new file mode 100644 index 000000000..a128e07f5 --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenRepository.kt @@ -0,0 +1,14 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo.maven + +import java.net.URI + +/** + * A fixture for dealing with Maven repositories. + */ +interface MavenRepository { + val uri: URI + + fun module(groupId: String, artifactId: String): MavenModule + + fun module(groupId: String, artifactId: String, version: String): MavenModule +} From c15be972fc79ffad19c0631c96656de54dfe5ba1 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 9 Dec 2024 20:52:23 +0800 Subject: [PATCH 07/13] Convert MavenFileRepository --- .../repo/maven/MavenFileRepository.groovy | 23 ------------------- .../util/repo/maven/MavenFileRepository.kt | 21 +++++++++++++++++ 2 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy deleted file mode 100644 index fdff3a8ed..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo.maven - -/** - * A fixture for dealing with file Maven repositories. - */ -class MavenFileRepository implements MavenRepository { - final File rootDir - - MavenFileRepository(File rootDir) { - this.rootDir = rootDir - } - - @Override - URI getUri() { - return rootDir.toURI() - } - - @Override - MavenFileModule module(String groupId, String artifactId, String version = '1.0') { - def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") - return new MavenFileModule(artifactDir, groupId, artifactId, version as String) - } -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt new file mode 100644 index 000000000..42af89739 --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt @@ -0,0 +1,21 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo.maven + +import java.io.File +import java.net.URI + +/** + * A fixture for dealing with file Maven repositories. + */ +abstract class MavenFileRepository(private val rootDir: File) : MavenRepository { + + override val uri: URI = rootDir.toURI() + + override fun module(groupId: String, artifactId: String): MavenModule { + return module(groupId, artifactId, "1.0") + } + + override fun module(groupId: String, artifactId: String, version: String): MavenModule { + val artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") + return MavenFileModule(artifactDir, groupId, artifactId, version) + } +} From dfe52c80d8e9ea7d754ccddcbd2d1513a4052b38 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 9 Dec 2024 21:09:14 +0800 Subject: [PATCH 08/13] Convert MavenFileModule --- .../util/repo/maven/MavenFileModule.groovy | 46 ------------------- .../shadow/util/repo/maven/MavenFileModule.kt | 43 +++++++++++++++++ 2 files changed, 43 insertions(+), 46 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy deleted file mode 100644 index 80d482224..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo.maven - -import org.jetbrains.annotations.NotNull - -class MavenFileModule extends AbstractMavenModule { - private boolean uniqueSnapshots = true - - MavenFileModule(File moduleDir, String groupId, String artifactId, String version) { - super(moduleDir, groupId, artifactId, version) - } - - @Override - boolean getUniqueSnapshots() { - return uniqueSnapshots - } - - @Override - String getMetaDataFileContent() { - """ - - - $groupId - $artifactId - $version - - - ${timestampFormat.format(publishTimestamp)} - $publishCount - - ${updateFormat.format(publishTimestamp)} - - - """.stripIndent() - } - - @Override - protected void onPublish(@NotNull File file) { - sha1File(file) - md5File(file) - } - - @Override - protected boolean publishesMetaDataFile() { - uniqueSnapshots && version.endsWith("-SNAPSHOT") - } -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt new file mode 100644 index 000000000..81b23ec0e --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt @@ -0,0 +1,43 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo.maven + +import java.io.File +import org.intellij.lang.annotations.Language +import org.jetbrains.annotations.NotNull + +class MavenFileModule( + moduleDir: File, + groupId: String, + artifactId: String, + version: String, +) : AbstractMavenModule(moduleDir, groupId, artifactId, version) { + + override fun getUniqueSnapshots(): Boolean = uniqueSnapshots + + @Language("XML") + override fun getMetaDataFileContent(): String { + return """ + + + $groupId + $artifactId + $version + + + ${timestampFormat.format(publishTimestamp)} + $publishCount + + ${updateFormat.format(publishTimestamp)} + + + """.trimIndent() + } + + override fun onPublish(@NotNull file: File) { + sha1File(file) + md5File(file) + } + + override fun publishesMetaDataFile(): Boolean { + return uniqueSnapshots && version.endsWith("-SNAPSHOT") + } +} From a84bfa305383f47b8d63a6c7f2943bb584cb1ecc Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 9 Dec 2024 21:12:22 +0800 Subject: [PATCH 09/13] Convert AppendableMavenFileRepository --- .../util/AppendableMavenFileRepository.groovy | 14 -------------- .../shadow/util/AppendableMavenFileRepository.kt | 12 ++++++++++++ .../shadow/util/repo/maven/MavenFileRepository.kt | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy deleted file mode 100644 index 18e4331da..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util - -import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenFileRepository -import groovy.transform.InheritConstructors - -@InheritConstructors -class AppendableMavenFileRepository extends MavenFileRepository { - - @Override - AppendableMavenFileModule module(String groupId, String artifactId, String version = '1.0') { - def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") - return new AppendableMavenFileModule(artifactDir, groupId, artifactId, version as String) - } -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt new file mode 100644 index 000000000..b0441362b --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt @@ -0,0 +1,12 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenFileRepository +import java.io.File + +class AppendableMavenFileRepository(rootDir: File) : MavenFileRepository(rootDir) { + + override fun module(groupId: String, artifactId: String, version: String): AppendableMavenFileModule { + val artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") + return AppendableMavenFileModule(artifactDir, groupId, artifactId, version) + } +} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt index 42af89739..026ebd8de 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt @@ -6,7 +6,7 @@ import java.net.URI /** * A fixture for dealing with file Maven repositories. */ -abstract class MavenFileRepository(private val rootDir: File) : MavenRepository { +abstract class MavenFileRepository(val rootDir: File) : MavenRepository { override val uri: URI = rootDir.toURI() From 21440f832f8b13d8d845f61801f6311bf2c1195c Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 11 Dec 2024 12:25:42 +0800 Subject: [PATCH 10/13] Revert "Convert AppendableMavenFileRepository" This reverts commit a84bfa305383f47b8d63a6c7f2943bb584cb1ecc. --- .../util/AppendableMavenFileRepository.groovy | 14 ++++++++++++++ .../shadow/util/AppendableMavenFileRepository.kt | 12 ------------ .../shadow/util/repo/maven/MavenFileRepository.kt | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy delete mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy new file mode 100644 index 000000000..18e4331da --- /dev/null +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy @@ -0,0 +1,14 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenFileRepository +import groovy.transform.InheritConstructors + +@InheritConstructors +class AppendableMavenFileRepository extends MavenFileRepository { + + @Override + AppendableMavenFileModule module(String groupId, String artifactId, String version = '1.0') { + def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") + return new AppendableMavenFileModule(artifactDir, groupId, artifactId, version as String) + } +} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt deleted file mode 100644 index b0441362b..000000000 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util - -import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenFileRepository -import java.io.File - -class AppendableMavenFileRepository(rootDir: File) : MavenFileRepository(rootDir) { - - override fun module(groupId: String, artifactId: String, version: String): AppendableMavenFileModule { - val artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") - return AppendableMavenFileModule(artifactDir, groupId, artifactId, version) - } -} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt index 026ebd8de..42af89739 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt @@ -6,7 +6,7 @@ import java.net.URI /** * A fixture for dealing with file Maven repositories. */ -abstract class MavenFileRepository(val rootDir: File) : MavenRepository { +abstract class MavenFileRepository(private val rootDir: File) : MavenRepository { override val uri: URI = rootDir.toURI() From c3fb8f13c9d0e58e4da507eae2df5cabc063d12d Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 11 Dec 2024 12:25:42 +0800 Subject: [PATCH 11/13] Revert "Convert MavenFileModule" This reverts commit dfe52c80d8e9ea7d754ccddcbd2d1513a4052b38. --- .../util/repo/maven/MavenFileModule.groovy | 46 +++++++++++++++++++ .../shadow/util/repo/maven/MavenFileModule.kt | 43 ----------------- 2 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy delete mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy new file mode 100644 index 000000000..80d482224 --- /dev/null +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy @@ -0,0 +1,46 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo.maven + +import org.jetbrains.annotations.NotNull + +class MavenFileModule extends AbstractMavenModule { + private boolean uniqueSnapshots = true + + MavenFileModule(File moduleDir, String groupId, String artifactId, String version) { + super(moduleDir, groupId, artifactId, version) + } + + @Override + boolean getUniqueSnapshots() { + return uniqueSnapshots + } + + @Override + String getMetaDataFileContent() { + """ + + + $groupId + $artifactId + $version + + + ${timestampFormat.format(publishTimestamp)} + $publishCount + + ${updateFormat.format(publishTimestamp)} + + + """.stripIndent() + } + + @Override + protected void onPublish(@NotNull File file) { + sha1File(file) + md5File(file) + } + + @Override + protected boolean publishesMetaDataFile() { + uniqueSnapshots && version.endsWith("-SNAPSHOT") + } +} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt deleted file mode 100644 index 81b23ec0e..000000000 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo.maven - -import java.io.File -import org.intellij.lang.annotations.Language -import org.jetbrains.annotations.NotNull - -class MavenFileModule( - moduleDir: File, - groupId: String, - artifactId: String, - version: String, -) : AbstractMavenModule(moduleDir, groupId, artifactId, version) { - - override fun getUniqueSnapshots(): Boolean = uniqueSnapshots - - @Language("XML") - override fun getMetaDataFileContent(): String { - return """ - - - $groupId - $artifactId - $version - - - ${timestampFormat.format(publishTimestamp)} - $publishCount - - ${updateFormat.format(publishTimestamp)} - - - """.trimIndent() - } - - override fun onPublish(@NotNull file: File) { - sha1File(file) - md5File(file) - } - - override fun publishesMetaDataFile(): Boolean { - return uniqueSnapshots && version.endsWith("-SNAPSHOT") - } -} From 28874769cf6c89fa9f311f08d82c8f855df152a7 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 11 Dec 2024 12:25:43 +0800 Subject: [PATCH 12/13] Revert "Convert MavenFileRepository" This reverts commit c15be972fc79ffad19c0631c96656de54dfe5ba1. --- .../repo/maven/MavenFileRepository.groovy | 23 +++++++++++++++++++ .../util/repo/maven/MavenFileRepository.kt | 21 ----------------- 2 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy delete mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy new file mode 100644 index 000000000..fdff3a8ed --- /dev/null +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy @@ -0,0 +1,23 @@ +package com.github.jengelman.gradle.plugins.shadow.util.repo.maven + +/** + * A fixture for dealing with file Maven repositories. + */ +class MavenFileRepository implements MavenRepository { + final File rootDir + + MavenFileRepository(File rootDir) { + this.rootDir = rootDir + } + + @Override + URI getUri() { + return rootDir.toURI() + } + + @Override + MavenFileModule module(String groupId, String artifactId, String version = '1.0') { + def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") + return new MavenFileModule(artifactDir, groupId, artifactId, version as String) + } +} diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt deleted file mode 100644 index 42af89739..000000000 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.repo.maven - -import java.io.File -import java.net.URI - -/** - * A fixture for dealing with file Maven repositories. - */ -abstract class MavenFileRepository(private val rootDir: File) : MavenRepository { - - override val uri: URI = rootDir.toURI() - - override fun module(groupId: String, artifactId: String): MavenModule { - return module(groupId, artifactId, "1.0") - } - - override fun module(groupId: String, artifactId: String, version: String): MavenModule { - val artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") - return MavenFileModule(artifactDir, groupId, artifactId, version) - } -} From c64b350cfd70fb05a6a4bb6b55b5ac4485242eb0 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 11 Dec 2024 12:29:05 +0800 Subject: [PATCH 13/13] Rename --- .../plugins/shadow/util/repo/maven/AbstractMavenModule.groovy | 4 ++-- .../gradle/plugins/shadow/util/repo/maven/MavenModule.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy index bd86f29ec..90dddd2f6 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy @@ -56,8 +56,8 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule } @Override - MavenModule dependsOn(String group, String artifactId, String version) { - this.dependencies << [groupId: group, artifactId: artifactId, version: version, type: type] + MavenModule dependsOn(String groupId, String artifactId, String version) { + this.dependencies << [groupId: groupId, artifactId: artifactId, version: version, type: type] return this } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt index 484789e1c..b77d25886 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenModule.kt @@ -14,7 +14,7 @@ interface MavenModule { */ fun publishPom(): MavenModule - fun dependsOn(group: String, artifactId: String, version: String): MavenModule + fun dependsOn(groupId: String, artifactId: String, version: String): MavenModule val pomFile: File