From ca1d7892461bd4d0beb26f790a7a201e39e10298 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 15:26:49 +0800 Subject: [PATCH 01/10] Remove TestFile and related classes --- .../shadow/util/PluginSpecification.groovy | 2 +- .../shadow/util/file/ExecOutput.groovy | 13 - .../plugins/shadow/util/file/TestFile.java | 536 ------------------ .../shadow/util/file/TestFileHelper.groovy | 203 ------- .../util/file/TestWorkspaceBuilder.groovy | 38 -- .../shadow/util/repo/AbstractModule.groovy | 24 +- .../repo/maven/AbstractMavenModule.groovy | 17 +- .../util/repo/maven/MavenFileModule.groovy | 5 +- .../repo/maven/MavenFileRepository.groovy | 5 +- .../shadow/util/repo/maven/MavenModule.groovy | 7 +- 10 files changed, 28 insertions(+), 822 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/ExecOutput.groovy delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 96f2c459a..58fc422f0 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -1,6 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow.util -import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile + import org.codehaus.plexus.util.IOUtil import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/ExecOutput.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/ExecOutput.groovy deleted file mode 100644 index 3bd0f93f0..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/ExecOutput.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.file - -class ExecOutput { - ExecOutput(String rawOutput, String error) { - this.rawOutput = rawOutput - this.out = rawOutput.replaceAll("\r\n|\r", "\n") - this.error = error - } - - String rawOutput - String out - String error -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java deleted file mode 100644 index da2976a59..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Copyright 2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.github.jengelman.gradle.plugins.shadow.util.file; - -import groovy.lang.Closure; -import org.apache.commons.io.FileUtils; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.Tar; -import org.apache.tools.ant.taskdefs.Zip; -import org.apache.tools.ant.types.EnumeratedAttribute; -import org.codehaus.groovy.runtime.ResourceGroovyMethods; - -import java.io.*; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.util.*; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -import static org.junit.jupiter.api.Assertions.*; - -public class TestFile extends File { - private boolean useNativeTools; - - public TestFile(File file, Object... path) { - super(join(file, path).getAbsolutePath()); - } - - public TestFile(URI uri) { - this(new File(uri)); - } - - public TestFile(String path) { - this(new File(path)); - } - - public TestFile(URL url) { - this(toUri(url)); - } - - public TestFile usingNativeTools() { - useNativeTools = true; - return this; - } - - Object writeReplace() throws ObjectStreamException { - return new File(getAbsolutePath()); - } - - @Override - public File getCanonicalFile() throws IOException { - return new File(getAbsolutePath()).getCanonicalFile(); - } - - @Override - public String getCanonicalPath() throws IOException { - return new File(getAbsolutePath()).getCanonicalPath(); - } - - private static URI toUri(URL url) { - try { - return url.toURI(); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } - - private static File join(File file, Object[] path) { - File current = file.getAbsoluteFile(); - for (Object p : path) { - current = new File(current, p.toString()); - } - try { - return current.getCanonicalFile(); - } catch (IOException e) { - throw new RuntimeException(String.format("Could not canonicalise '%s'.", current), e); - } - } - - public TestFile file(Object... path) { - try { - return new TestFile(this, path); - } catch (RuntimeException e) { - throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(path), this), e); - } - } - - public List files(Object... paths) { - List files = new ArrayList<>(); - for (Object path : paths) { - files.add(file(path)); - } - return files; - } - - public TestFile withExtension(String extension) { - return getParentFile().file(getName().replaceAll("\\..*$", "." + extension)); - } - - public TestFile writelns(String... lines) { - return writelns(Arrays.asList(lines)); - } - - public TestFile write(Object content) { - try { - FileUtils.writeStringToFile(this, content.toString(), Charset.defaultCharset()); - } catch (IOException e) { - throw new RuntimeException(String.format("Could not write to test file '%s'", this), e); - } - return this; - } - - public TestFile leftShift(Object content) { - getParentFile().mkdirs(); - try { - ResourceGroovyMethods.leftShift(this, content); - return this; - } catch (IOException e) { - throw new RuntimeException(String.format("Could not append to test file '%s'", this), e); - } - } - - @Override - public TestFile[] listFiles() { - File[] children = super.listFiles(); - TestFile[] files = new TestFile[children.length]; - for (int i = 0; i < children.length; i++) { - File child = children[i]; - files[i] = new TestFile(child); - } - return files; - } - - public String getText() { - assertIsFile(); - try { - return FileUtils.readFileToString(this, Charset.defaultCharset()); - } catch (IOException e) { - throw new RuntimeException(String.format("Could not read from test file '%s'", this), e); - } - } - - public Map getProperties() { - assertIsFile(); - Properties properties = new Properties(); - try { - try (FileInputStream inStream = new FileInputStream(this)) { - properties.load(inStream); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - Map map = new HashMap<>(); - for (Object key : properties.keySet()) { - map.put(key.toString(), properties.getProperty(key.toString())); - } - return map; - } - - public Manifest getManifest() { - assertIsFile(); - try { - try (JarFile jarFile = new JarFile(this)) { - return jarFile.getManifest(); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void unzipTo(File target) { - assertIsFile(); - new TestFileHelper(this).unzipTo(target, useNativeTools); - } - - public void untarTo(File target) { - assertIsFile(); - - new TestFileHelper(this).untarTo(target, useNativeTools); - } - - public void copyTo(File target) { - if (isDirectory()) { - try { - FileUtils.copyDirectory(this, target); - } catch (IOException e) { - throw new RuntimeException(String.format("Could not copy test directory '%s' to '%s'", this, - target), e); - } - } else { - try { - FileUtils.copyFile(this, target); - } catch (IOException e) { - throw new RuntimeException(String.format("Could not copy test file '%s' to '%s'", this, target), e); - } - } - } - - public void copyFrom(File target) { - new TestFile(target).copyTo(this); - } - - public void copyFrom(URL resource) { - try { - FileUtils.copyURLToFile(resource, this); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void moveToDirectory(File target) { - if (target.exists() && !target.isDirectory()) { - throw new RuntimeException(String.format("Target '%s' is not a directory", target)); - } - try { - FileUtils.moveFileToDirectory(this, target, true); - } catch (IOException e) { - throw new RuntimeException(String.format("Could not move test file '%s' to directory '%s'", this, target), e); - } - } - - public TestFile touch() { - try { - FileUtils.touch(this); - } catch (IOException e) { - throw new RuntimeException(e); - } - assertIsFile(); - return this; - } - - /** - * Creates a directory structure specified by the given closure. - *
-     * dir.create {
-     *     subdir1 {
-     *        file 'somefile.txt'
-     *     }
-     *     subdir2 { nested { file 'someFile' } }
-     * }
-     * 
- */ - public TestFile create(Closure structure) { - assertTrue(isDirectory() || mkdirs()); - new TestWorkspaceBuilder(this).apply(structure); - return this; - } - - @Override - public TestFile getParentFile() { - return super.getParentFile() == null ? null : new TestFile(super.getParentFile()); - } - - public TestFile writelns(Iterable lines) { - Formatter formatter = new Formatter(); - for (String line : lines) { - formatter.format("%s%n", line); - } - return write(formatter); - } - - public TestFile assertExists() { - assertTrue(exists(), String.format("%s does not exist", this)); - return this; - } - - public TestFile assertIsFile() { - assertTrue(isFile(), String.format("%s is not a file", this)); - return this; - } - - public TestFile assertIsDir() { - assertTrue(isDirectory(), String.format("%s is not a directory", this)); - return this; - } - - public TestFile assertDoesNotExist() { - assertFalse(exists(), String.format("%s should not exist", this)); - return this; - } - - public TestFile assertIsCopyOf(TestFile other) { - assertIsFile(); - other.assertIsFile(); - assertEquals(other.length(), this.length(), String.format("%s is not the same length as %s", this, other)); - assertArrayEquals(getHash("MD5"), other.getHash("MD5"), String.format("%s does not have the same content as %s", this, other)); - return this; - } - - private byte[] getHash(String algorithm) { - try { - MessageDigest messageDigest = MessageDigest.getInstance(algorithm); - messageDigest.update(FileUtils.readFileToByteArray(this)); - return messageDigest.digest(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public String readLink() { - assertExists(); - return new TestFileHelper(this).readLink(); - } - - public String getPermissions() { - assertExists(); - return new TestFileHelper(this).getPermissions(); - } - - public TestFile setPermissions(String permissions) { - assertExists(); - new TestFileHelper(this).setPermissions(permissions); - return this; - } - - public TestFile setMode(int mode) { - assertExists(); - new TestFileHelper(this).setMode(mode); - return this; - } - - public int getMode() { - assertExists(); - return new TestFileHelper(this).getMode(); - } - - /** - * Asserts that this file contains exactly the given set of descendants. - */ - public TestFile assertHasDescendants(String... descendants) { - Set actual = new TreeSet<>(); - assertIsDir(); - visit(actual, "", this); - Set expected = new TreeSet<>(Arrays.asList(descendants)); - - Set extras = new TreeSet<>(actual); - extras.removeAll(expected); - Set missing = new TreeSet<>(expected); - missing.removeAll(actual); - - assertEquals(expected, actual, String.format("For dir: %s, extra files: %s, missing files: %s, expected: %s", this, extras, missing, expected)); - - return this; - } - - public TestFile assertIsEmptyDir() { - if (exists()) { - assertIsDir(); - assertHasDescendants(); - } - return this; - } - - private void visit(Set names, String prefix, File file) { - for (File child : file.listFiles()) { - if (child.isFile()) { - names.add(prefix + child.getName()); - } else if (child.isDirectory()) { - visit(names, prefix + child.getName() + "/", child); - } - } - } - - public boolean isSelfOrDescendent(File file) { - if (file.getAbsolutePath().equals(getAbsolutePath())) { - return true; - } - return file.getAbsolutePath().startsWith(getAbsolutePath() + File.separatorChar); - } - - public TestFile createDir() { - if (mkdirs()) { - return this; - } - if (isDirectory()) { - return this; - } - throw new AssertionError("Problems creating dir: " + this - + ". Diagnostics: exists=" + this.exists() + ", isFile=" + this.isFile() + ", isDirectory=" + this.isDirectory()); - } - - public TestFile createDir(Object path) { - return new TestFile(this, path).createDir(); - } - - public TestFile deleteDir() { - new TestFileHelper(this).delete(useNativeTools); - return this; - } - - /** - * Attempts to delete this directory, ignoring failures to do so. - * - * @return this - */ - public TestFile maybeDeleteDir() { - try { - deleteDir(); - } catch (RuntimeException e) { - // Ignore - } - return this; - } - - public TestFile createFile() { - new TestFile(getParentFile()).createDir(); - try { - assertTrue(isFile() || createNewFile()); - } catch (IOException e) { - throw new RuntimeException(e); - } - return this; - } - - public TestFile createFile(Object path) { - return file(path).createFile(); - } - - public TestFile createZip(Object path) { - Zip zip = new Zip(); - zip.setWhenempty((Zip.WhenEmpty) Zip.WhenEmpty.getInstance(Zip.WhenEmpty.class, "create")); - TestFile zipFile = file(path); - zip.setDestFile(zipFile); - zip.setBasedir(this); - zip.setExcludes("**"); - execute(zip); - return zipFile; - } - - public TestFile zipTo(TestFile zipFile) { - new TestFileHelper(this).zipTo(zipFile, useNativeTools); - return this; - } - - public TestFile tarTo(TestFile tarFile) { - new TestFileHelper(this).tarTo(tarFile, useNativeTools); - return this; - } - - public TestFile tgzTo(TestFile tarFile) { - Tar tar = new Tar(); - tar.setBasedir(this); - tar.setDestFile(tarFile); - tar.setCompression((Tar.TarCompressionMethod) EnumeratedAttribute.getInstance(Tar.TarCompressionMethod.class, "gzip")); - execute(tar); - return this; - } - - public TestFile tbzTo(TestFile tarFile) { - Tar tar = new Tar(); - tar.setBasedir(this); - tar.setDestFile(tarFile); - tar.setCompression((Tar.TarCompressionMethod) EnumeratedAttribute.getInstance(Tar.TarCompressionMethod.class, "bzip2")); - execute(tar); - return this; - } - - private void execute(Task task) { - task.setProject(new Project()); - task.execute(); - } - - public Snapshot snapshot() { - assertIsFile(); - return new Snapshot(lastModified(), getHash("MD5")); - } - - public void assertHasChangedSince(Snapshot snapshot) { - Snapshot now = snapshot(); - assertTrue(now.modTime != snapshot.modTime || !Arrays.equals(now.hash, snapshot.hash)); - } - - public void assertContentsHaveChangedSince(Snapshot snapshot) { - Snapshot now = snapshot(); - assertFalse(Arrays.equals(now.hash, snapshot.hash), String.format("contents of %s have not changed", this)); - } - - public void assertContentsHaveNotChangedSince(Snapshot snapshot) { - Snapshot now = snapshot(); - assertArrayEquals(snapshot.hash, now.hash, String.format("contents of %s has changed", this)); - } - - public void assertHasNotChangedSince(Snapshot snapshot) { - Snapshot now = snapshot(); - assertEquals(snapshot.modTime, now.modTime, String.format("last modified time of %s has changed", this)); - assertArrayEquals(snapshot.hash, now.hash, String.format("contents of %s has changed", this)); - } - - public void writeProperties(Map properties) { - Properties props = new Properties(); - props.putAll(properties); - try { - try (FileOutputStream stream = new FileOutputStream(this)) { - props.store(stream, "comment"); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public ExecOutput exec(Object... args) { - return new TestFileHelper(this).execute(Arrays.asList(args), null); - } - - public ExecOutput execute(List args, List env) { - return new TestFileHelper(this).execute(args, env); - } - - public static class Snapshot { - private final long modTime; - private final byte[] hash; - - public Snapshot(long modTime, byte[] hash) { - this.modTime = modTime; - this.hash = hash; - } - } -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy deleted file mode 100644 index 414f09132..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy +++ /dev/null @@ -1,203 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.file - -import org.apache.commons.io.FileUtils -import org.apache.commons.lang3.StringUtils -import org.apache.tools.ant.Project -import org.apache.tools.ant.taskdefs.Expand -import org.apache.tools.ant.taskdefs.Tar -import org.apache.tools.ant.taskdefs.Untar -import org.apache.tools.ant.taskdefs.Zip - -import java.util.zip.ZipInputStream - -import static org.junit.jupiter.api.Assertions.assertTrue - -class TestFileHelper { - TestFile file - - TestFileHelper(TestFile file) { - this.file = file - } - - void unzipTo(File target, boolean nativeTools) { - // Check that each directory in hierarchy is present - file.withInputStream { InputStream instr -> - def dirs = [] as Set - def zipStr = new ZipInputStream(instr) - def entry - while (entry = zipStr.getNextEntry()) { - if (entry.directory) { - assertTrue(dirs.add(entry.name), "Duplicate directory '$entry.name'") - } - if (!entry.name.contains('/')) { - continue - } - def parent = StringUtils.substringBeforeLast(entry.name, '/') + '/' - assertTrue(dirs.contains(parent), "Missing dir '$parent'") - } - } - - if (nativeTools && isUnix()) { - def process = ['unzip', '-o', file.absolutePath, '-d', target.absolutePath].execute() - process.consumeProcessOutput(System.out, System.err) - assert process.waitFor() == 0 - return - } - - def unzip = new Expand() - unzip.src = file - unzip.dest = target - - unzip.project = new Project() - unzip.execute() - } - - void untarTo(File target, boolean nativeTools) { - if (nativeTools && isUnix()) { - target.mkdirs() - def builder = new ProcessBuilder(['tar', '-xpf', file.absolutePath]) - builder.directory(target) - def process = builder.start() - process.consumeProcessOutput() - assert process.waitFor() == 0 - return - } - - def untar = new Untar() - untar.setSrc(file) - untar.setDest(target) - - if (file.name.endsWith(".tgz")) { - def method = new Untar.UntarCompressionMethod() - method.value = "gzip" - untar.compression = method - } else if (file.name.endsWith(".tbz2")) { - def method = new Untar.UntarCompressionMethod() - method.value = "bzip2" - untar.compression = method - } - - untar.project = new Project() - untar.execute() - } - - private static boolean isUnix() { - return !System.getProperty('os.name').toLowerCase().contains('windows') - } - - String getPermissions() { - if (!isUnix()) { - return "-rwxr-xr-x" - } - - def process = ["ls", "-ld", file.absolutePath].execute() - def result = process.inputStream.text - def error = process.errorStream.text - def retval = process.waitFor() - if (retval != 0) { - throw new RuntimeException("Could not list permissions for '$file': $error") - } - def perms = result.split()[0] - assert perms.matches("[d\\-][rwx\\-]{9}[@\\+]?") - return perms.substring(1, 10) - } - - void setPermissions(String permissions) { - if (!isUnix()) { - return - } - int m = toMode(permissions) - setMode(m) - } - - void setMode(int mode) { - def process = ["chmod", Integer.toOctalString(mode), file.absolutePath].execute() - def error = process.errorStream.text - def retval = process.waitFor() - if (retval != 0) { - throw new RuntimeException("Could not set permissions for '$file': $error") - } - } - - private static int toMode(String permissions) { - int m = [6, 3, 0].inject(0) { mode, pos -> - mode |= permissions[9 - pos - 3] == 'r' ? 4 << pos : 0 - mode |= permissions[9 - pos - 2] == 'w' ? 2 << pos : 0 - mode |= permissions[9 - pos - 1] == 'x' ? 1 << pos : 0 - return mode - } - return m - } - - int getMode() { - return toMode(getPermissions()) - } - - void delete(boolean nativeTools) { - if (isUnix() && nativeTools) { - def process = ["rm", "-rf", file.absolutePath].execute() - def error = process.errorStream.text - def retval = process.waitFor() - if (retval != 0) { - throw new RuntimeException("Could not delete '$file': $error") - } - } else { - FileUtils.deleteQuietly(file) - } - } - - String readLink() { - def process = ["readlink", file.absolutePath].execute() - def error = process.errorStream.text - def retval = process.waitFor() - if (retval != 0) { - throw new RuntimeException("Could not read link '$file': $error") - } - return process.inputStream.text.trim() - } - - ExecOutput exec(List args) { - return execute(args, null) - } - - ExecOutput execute(List args, List env) { - def process = ([file.absolutePath] + args).execute(env, null) - String output = process.inputStream.text - String error = process.errorStream.text - if (process.waitFor() != 0) { - throw new RuntimeException("Could not execute $file. Error: $error, Output: $output") - } - return new ExecOutput(output, error) - } - - void zipTo(TestFile zipFile, boolean nativeTools) { - if (nativeTools && isUnix()) { - def process = ['zip', zipFile.absolutePath, "-r", file.name].execute(null, zipFile.parentFile) - process.consumeProcessOutput(System.out, System.err) - assert process.waitFor() == 0 - } else { - Zip zip = new Zip() - zip.setBasedir(file) - zip.setDestFile(zipFile) - zip.setProject(new Project()) - def whenEmpty = new Zip.WhenEmpty() - whenEmpty.setValue("create") - zip.setWhenempty(whenEmpty) - zip.execute() - } - } - - void tarTo(TestFile tarFile, boolean nativeTools) { - if (nativeTools && isUnix()) { - def process = ['tar', "-cf", tarFile.absolutePath, file.name].execute(null, tarFile.parentFile) - process.consumeProcessOutput(System.out, System.err) - assert process.waitFor() == 0 - } else { - Tar tar = new Tar() - tar.setBasedir(file) - tar.setDestFile(tarFile) - tar.setProject(new Project()) - tar.execute() - } - } -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy deleted file mode 100644 index 2af22f3e9..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util.file - -/** - * Used in TestFile.create(). - * - * Should be inner class of TestFile, but can't because Groovy has issues with inner classes as delegates. - */ -class TestWorkspaceBuilder { - TestFile baseDir - - TestWorkspaceBuilder(TestFile baseDir) { - this.baseDir = baseDir - } - - def apply(Closure cl) { - cl.delegate = this - cl.resolveStrategy = Closure.DELEGATE_FIRST - cl() - } - - def file(String name) { - TestFile file = baseDir.file(name) - file.write('some content') - file - } - - def setMode(int mode) { - baseDir.mode = mode - } - - def methodMissing(String name, Object args) { - if (args.length == 1 && args[0] instanceof Closure) { - baseDir.file(name).create(args[0]) - } else { - throw new MissingMethodException(name, getClass(), args) - } - } -} 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 ea5504ec7..c03400ce4 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 @@ -1,13 +1,13 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo import com.github.jengelman.gradle.plugins.shadow.util.HashUtil -import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile + abstract class AbstractModule { /** * @param cl A closure that is passed a writer to use to generate the content. */ - protected void publish(TestFile file, Closure cl) { + protected void publish(File file, Closure cl) { def hashBefore = file.exists() ? getHash(file, "sha1") : null def tmpFile = file.parentFile.file("${file.name}.tmp") @@ -26,7 +26,7 @@ abstract class AbstractModule { onPublish(file) } - protected void publishWithStream(TestFile file, Closure cl) { + protected void publishWithStream(File file, Closure cl) { def hashBefore = file.exists() ? getHash(file, "sha1") : null def tmpFile = file.parentFile.file("${file.name}.tmp") @@ -45,36 +45,36 @@ abstract class AbstractModule { onPublish(file) } - protected abstract onPublish(TestFile file) + protected abstract onPublish(File file) - static TestFile getSha1File(TestFile file) { + static File getSha1File(File file) { getHashFile(file, "sha1") } - static TestFile sha1File(TestFile file) { + static File sha1File(File file) { hashFile(file, "sha1", 40) } - static TestFile getMd5File(TestFile file) { + static File getMd5File(File file) { getHashFile(file, "md5") } - static TestFile md5File(TestFile file) { + static File md5File(File file) { hashFile(file, "md5", 32) } - private static TestFile hashFile(TestFile file, String algorithm, int len) { + 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 TestFile getHashFile(TestFile file, String algorithm) { + private static File getHashFile(File file, String algorithm) { file.parentFile.file("${file.name}.${algorithm}") } - private static BigInteger getHash(TestFile file, String algorithm) { + private static BigInteger getHash(File file, String algorithm) { HashUtil.createHash(file, algorithm.toUpperCase()).asBigInteger() } -} \ No newline at end of file +} 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 16a2fffd6..f7ff4481f 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 @@ -1,6 +1,5 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven -import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile import com.github.jengelman.gradle.plugins.shadow.util.repo.AbstractModule import groovy.xml.MarkupBuilder import groovy.xml.XmlParser @@ -9,7 +8,7 @@ import java.text.SimpleDateFormat abstract class AbstractMavenModule extends AbstractModule implements MavenModule { protected static final String MAVEN_METADATA_FILE = "maven-metadata.xml" - final TestFile moduleDir + final File moduleDir final String groupId final String artifactId final String version @@ -22,7 +21,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule final updateFormat = new SimpleDateFormat("yyyyMMddHHmmss") final timestampFormat = new SimpleDateFormat("yyyyMMdd.HHmmss") - AbstractMavenModule(TestFile moduleDir, String groupId, String artifactId, String version) { + AbstractMavenModule(File moduleDir, String groupId, String artifactId, String version) { this.moduleDir = moduleDir this.groupId = groupId this.artifactId = artifactId @@ -42,7 +41,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule } @Override - TestFile getArtifactFile(Map options = [:]) { + File getArtifactFile(Map options = [:]) { if (version.endsWith("-SNAPSHOT") && !metaDataFile.exists() && uniqueSnapshots) { def artifact = toArtifact(options) return moduleDir.file("${artifactId}-${version}${artifact.classifier ? "-${artifact.classifier}" : ""}.${artifact.type}") @@ -188,20 +187,20 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule } @Override - TestFile getPomFile() { + File getPomFile() { return moduleDir.file("$artifactId-${publishArtifactVersion}.pom") } @Override - TestFile getMetaDataFile() { + File getMetaDataFile() { moduleDir.file(MAVEN_METADATA_FILE) } - TestFile getRootMetaDataFile() { + File getRootMetaDataFile() { moduleDir.parentFile.file(MAVEN_METADATA_FILE) } - TestFile artifactFile(Map options) { + File artifactFile(Map options) { def artifact = toArtifact(options) def fileName = "$artifactId-${publishArtifactVersion}.${artifact.type}" if (artifact.classifier) { @@ -282,7 +281,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule return this } - private void updateRootMavenMetaData(TestFile rootMavenMetaData) { + 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 -> 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 67a697f77..71233befb 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,11 +1,10 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven -import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile class MavenFileModule extends AbstractMavenModule { private boolean uniqueSnapshots = true - MavenFileModule(TestFile moduleDir, String groupId, String artifactId, String version) { + MavenFileModule(File moduleDir, String groupId, String artifactId, String version) { super(moduleDir, groupId, artifactId, version) } @@ -40,7 +39,7 @@ class MavenFileModule extends AbstractMavenModule { } @Override - protected onPublish(TestFile file) { + protected onPublish(File file) { sha1File(file) md5File(file) } 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 index f72d0cd09..ecb4773f1 100644 --- 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 @@ -1,14 +1,13 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven -import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile /** * A fixture for dealing with file Maven repositories. */ class MavenFileRepository implements MavenRepository { - final TestFile rootDir + final File rootDir - MavenFileRepository(TestFile rootDir) { + MavenFileRepository(File rootDir) { this.rootDir = rootDir } 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 index 2698e0a30..fcd466d10 100644 --- 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 @@ -1,6 +1,5 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven -import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile interface MavenModule { /** @@ -33,11 +32,11 @@ interface MavenModule { */ MavenModule hasType(String type) - TestFile getPomFile() + File getPomFile() - TestFile getArtifactFile() + File getArtifactFile() - TestFile getMetaDataFile() + File getMetaDataFile() MavenPom getParsedPom() From 0a27ea27a83f2c5772fe7a6221a0dbe5e7f3bac5 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 15:31:52 +0800 Subject: [PATCH 02/10] Add FileExtensions --- .../plugins/shadow/util/FileExtensions.groovy | 22 +++++++++++++++++++ .../shadow/util/PluginSpecification.groovy | 2 +- ...rg.codehaus.groovy.runtime.ExtensionModule | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy create mode 100644 src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy new file mode 100644 index 000000000..76681cf26 --- /dev/null +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy @@ -0,0 +1,22 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +final class FileExtensions { + static File file(File file, String relativePath) { + try { + return new File(file, relativePath) + } catch (RuntimeException e) { + throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(relativePath), file), e) + } + } + + static File createDir(File file) { + if (file.mkdirs()) { + return file + } + if (file.isDirectory()) { + return file + } + throw new AssertionError("Problems creating dir: " + this + + ". Diagnostics: exists=" + this.exists() + ", isFile=" + this.isFile() + ", isDirectory=" + this.isDirectory()) + } +} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 58fc422f0..c1ce5b6f8 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -121,7 +121,7 @@ abstract class PluginSpecification extends Specification { } AppendableMavenFileRepository repo(String path = 'maven-repo') { - new AppendableMavenFileRepository(new TestFile(dir.toFile(), path)) + new AppendableMavenFileRepository(dir.resolve(path).toFile()) } void assertJarFileContentsEqual(File f, String path, String contents) { diff --git a/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule b/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule new file mode 100644 index 000000000..bb7d5044f --- /dev/null +++ b/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule @@ -0,0 +1,3 @@ +moduleName = groovy-extensions +moduleVersion = ${moduleVersion} +extensionClasses =com.github.jengelman.gradle.plugins.shadow.util.FileExtensions From 3c25c3e406a99bd2b406c412873a0872fde2944b Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 15:32:26 +0800 Subject: [PATCH 03/10] Rename file to resolve --- .../plugins/shadow/PublishingSpec.groovy | 24 +++++++++---------- .../util/AppendableMavenFileRepository.groovy | 2 +- .../plugins/shadow/util/FileExtensions.groovy | 2 +- .../shadow/util/repo/AbstractModule.groovy | 6 ++--- .../repo/maven/AbstractMavenModule.groovy | 10 ++++---- .../repo/maven/MavenFileRepository.groovy | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 8787c532b..ce60a5e12 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -60,14 +60,14 @@ class PublishingSpec extends PluginSpecification { run('publish') then: - File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile + File publishedFile = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile assert publishedFile.exists() and: contains(publishedFile, ['a.properties', 'a2.properties']) and: - File pom = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile + File pom = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile assert pom.exists() def contents = new XmlSlurper().parse(pom) @@ -128,7 +128,7 @@ class PublishingSpec extends PluginSpecification { run('publish') then: - File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0-my-classifier.my-ext').canonicalFile + File publishedFile = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0-my-classifier.my-ext').canonicalFile assert publishedFile.exists() } @@ -209,14 +209,14 @@ class PublishingSpec extends PluginSpecification { run('publish') then: - File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile + File publishedFile = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile assert publishedFile.exists() and: contains(publishedFile, ['a.properties', 'a2.properties']) and: - File pom = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile + File pom = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile assert pom.exists() def contents = new XmlSlurper().parse(pom) @@ -273,8 +273,8 @@ class PublishingSpec extends PluginSpecification { run('publish') then: - File mainJar = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0.jar').canonicalFile - File shadowJar = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0-all.jar').canonicalFile + File mainJar = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.jar').canonicalFile + File shadowJar = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0-all.jar').canonicalFile assert mainJar.exists() assert shadowJar.exists() @@ -282,8 +282,8 @@ class PublishingSpec extends PluginSpecification { contains(shadowJar, ['a.properties', 'a2.properties']) and: "publishes both a POM file and a Gradle metadata file" - File pom = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0.pom').canonicalFile - File gmm = publishingRepo.rootDir.file('com/acme/maven/1.0/maven-1.0.module').canonicalFile + File pom = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.pom').canonicalFile + File gmm = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.module').canonicalFile pom.exists() gmm.exists() @@ -328,13 +328,13 @@ class PublishingSpec extends PluginSpecification { and: "verify shadow publication" assertions { - shadowJar = publishingRepo.rootDir.file('com/acme/maven-all/1.0/maven-all-1.0-all.jar').canonicalFile + shadowJar = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0-all.jar').canonicalFile assert shadowJar.exists() contains(shadowJar, ['a.properties', 'a2.properties']) } assertions { - pom = publishingRepo.rootDir.file('com/acme/maven-all/1.0/maven-all-1.0.pom').canonicalFile + pom = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0.pom').canonicalFile assert pom.exists() pomContents = new XmlSlurper().parse(pom) assert pomContents.dependencies[0].dependency.size() == 1 @@ -351,7 +351,7 @@ class PublishingSpec extends PluginSpecification { } assertions { - gmm = publishingRepo.rootDir.file('com/acme/maven-all/1.0/maven-all-1.0.module').canonicalFile + gmm = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0.module').canonicalFile assert gmm.exists() gmmContents = new JsonSlurper().parse(gmm) assert gmmContents.variants.size() == 1 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 index c92314796..cc79dc0b6 100644 --- 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 @@ -8,7 +8,7 @@ class AppendableMavenFileRepository extends MavenFileRepository { @Override AppendableMavenFileModule module(String groupId, String artifactId, Object version = '1.0') { - def artifactDir = rootDir.file("${groupId.replace('.', '/')}/$artifactId/$version") + def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") return new AppendableMavenFileModule(artifactDir, groupId, artifactId, version as String) } diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy index 76681cf26..377a05ec4 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy @@ -1,7 +1,7 @@ package com.github.jengelman.gradle.plugins.shadow.util final class FileExtensions { - static File file(File file, String relativePath) { + static File resolve(File file, String relativePath) { try { return new File(file, relativePath) } catch (RuntimeException e) { 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 c03400ce4..a2e67d34f 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 @@ -9,7 +9,7 @@ abstract class AbstractModule { */ protected void publish(File file, Closure cl) { def hashBefore = file.exists() ? getHash(file, "sha1") : null - def tmpFile = file.parentFile.file("${file.name}.tmp") + def tmpFile = file.parentFile.resolve("${file.name}.tmp") tmpFile.withWriter("utf-8") { cl.call(it) @@ -28,7 +28,7 @@ abstract class AbstractModule { protected void publishWithStream(File file, Closure cl) { def hashBefore = file.exists() ? getHash(file, "sha1") : null - def tmpFile = file.parentFile.file("${file.name}.tmp") + def tmpFile = file.parentFile.resolve("${file.name}.tmp") tmpFile.withOutputStream { cl.call(it) @@ -71,7 +71,7 @@ abstract class AbstractModule { } private static File getHashFile(File file, String algorithm) { - file.parentFile.file("${file.name}.${algorithm}") + file.parentFile.resolve("${file.name}.${algorithm}") } private static BigInteger getHash(File file, String algorithm) { 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 f7ff4481f..e08a29ad9 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 @@ -44,7 +44,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule File getArtifactFile(Map options = [:]) { if (version.endsWith("-SNAPSHOT") && !metaDataFile.exists() && uniqueSnapshots) { def artifact = toArtifact(options) - return moduleDir.file("${artifactId}-${version}${artifact.classifier ? "-${artifact.classifier}" : ""}.${artifact.type}") + return moduleDir.resolve("${artifactId}-${version}${artifact.classifier ? "-${artifact.classifier}" : ""}.${artifact.type}") } return artifactFile(options) } @@ -188,16 +188,16 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule @Override File getPomFile() { - return moduleDir.file("$artifactId-${publishArtifactVersion}.pom") + return moduleDir.resolve("$artifactId-${publishArtifactVersion}.pom") } @Override File getMetaDataFile() { - moduleDir.file(MAVEN_METADATA_FILE) + moduleDir.resolve(MAVEN_METADATA_FILE) } File getRootMetaDataFile() { - moduleDir.parentFile.file(MAVEN_METADATA_FILE) + moduleDir.parentFile.resolve(MAVEN_METADATA_FILE) } File artifactFile(Map options) { @@ -206,7 +206,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule if (artifact.classifier) { fileName = "$artifactId-$publishArtifactVersion-${artifact.classifier}.${artifact.type}" } - return moduleDir.file(fileName) + return moduleDir.resolve(fileName) } @Override 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 index ecb4773f1..455588315 100644 --- 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 @@ -18,7 +18,7 @@ class MavenFileRepository implements MavenRepository { @Override MavenFileModule module(String groupId, String artifactId, Object version = '1.0') { - def artifactDir = rootDir.file("${groupId.replace('.', '/')}/$artifactId/$version") + def artifactDir = rootDir.resolve("${groupId.replace('.', '/')}/$artifactId/$version") return new MavenFileModule(artifactDir, groupId, artifactId, version as String) } } From 713566cda7239304b71efe4d30d284b1868e203c Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 15:50:18 +0800 Subject: [PATCH 04/10] Rename MavenFileRepository to MavenPathRepository --- .../jengelman/gradle/plugins/shadow/PublishingSpec.groovy | 4 ++-- ...pository.groovy => AppendableMavenPathRepository.groovy} | 4 ++-- .../gradle/plugins/shadow/util/PluginSpecification.groovy | 6 +++--- ...avenFileRepository.groovy => MavenPathRepository.groovy} | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/{AppendableMavenFileRepository.groovy => AppendableMavenPathRepository.groovy} (85%) rename src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/{MavenFileRepository.groovy => MavenPathRepository.groovy} (85%) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index ce60a5e12..15a941b0a 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -1,6 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow -import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository +import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenPathRepository import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification import groovy.json.JsonSlurper import groovy.xml.XmlSlurper @@ -10,7 +10,7 @@ import spock.lang.Issue class PublishingSpec extends PluginSpecification { - AppendableMavenFileRepository publishingRepo + AppendableMavenPathRepository publishingRepo @Override def setup() { 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/AppendableMavenPathRepository.groovy similarity index 85% rename from src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy rename to src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenPathRepository.groovy index cc79dc0b6..4152c720e 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenPathRepository.groovy @@ -1,10 +1,10 @@ package com.github.jengelman.gradle.plugins.shadow.util -import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenFileRepository +import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenPathRepository import groovy.transform.InheritConstructors @InheritConstructors -class AppendableMavenFileRepository extends MavenFileRepository { +class AppendableMavenPathRepository extends MavenPathRepository { @Override AppendableMavenFileModule module(String groupId, String artifactId, Object version = '1.0') { diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index c1ce5b6f8..d6f2ae802 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -19,7 +19,7 @@ abstract class PluginSpecification extends Specification { public static final String SHADOW_VERSION = System.getProperty("shadowVersion") - AppendableMavenFileRepository repo + AppendableMavenPathRepository repo def setup() { repo = repo() @@ -120,8 +120,8 @@ abstract class PluginSpecification extends Specification { return dir.resolve(path).toFile() } - AppendableMavenFileRepository repo(String path = 'maven-repo') { - new AppendableMavenFileRepository(dir.resolve(path).toFile()) + AppendableMavenPathRepository repo(String path = 'maven-repo') { + new AppendableMavenPathRepository(dir.resolve(path).toFile()) } void assertJarFileContentsEqual(File f, String path, String contents) { 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/MavenPathRepository.groovy similarity index 85% rename from src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy rename to src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy index 455588315..7de383ac1 100644 --- 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/MavenPathRepository.groovy @@ -4,10 +4,10 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven /** * A fixture for dealing with file Maven repositories. */ -class MavenFileRepository implements MavenRepository { +class MavenPathRepository implements MavenRepository { final File rootDir - MavenFileRepository(File rootDir) { + MavenPathRepository(File rootDir) { this.rootDir = rootDir } From 020a4760a0f97e189347f9438ac22fe7822773c3 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 15:54:59 +0800 Subject: [PATCH 05/10] Replace File with Path in MavenPathRepository --- .../gradle/plugins/shadow/util/PluginSpecification.groovy | 2 +- .../shadow/util/repo/maven/MavenPathRepository.groovy | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index d6f2ae802..ac408ee9d 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -121,7 +121,7 @@ abstract class PluginSpecification extends Specification { } AppendableMavenPathRepository repo(String path = 'maven-repo') { - new AppendableMavenPathRepository(dir.resolve(path).toFile()) + new AppendableMavenPathRepository(dir.resolve(path)) } void assertJarFileContentsEqual(File f, String path, String contents) { diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy index 7de383ac1..e3a1a5980 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy @@ -1,19 +1,21 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven +import java.nio.file.Path + /** * A fixture for dealing with file Maven repositories. */ class MavenPathRepository implements MavenRepository { - final File rootDir + final Path rootDir - MavenPathRepository(File rootDir) { + MavenPathRepository(Path rootDir) { this.rootDir = rootDir } @Override URI getUri() { - return rootDir.toURI() + return rootDir.toFile().toURI() } @Override From e87fd0c35d5e5d7b26ac37dff189a8e8fef844ec Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 15:59:04 +0800 Subject: [PATCH 06/10] Move FileExtensions into PluginSpecification --- .../plugins/shadow/util/FileExtensions.groovy | 22 ---------------- .../shadow/util/PluginSpecification.groovy | 25 +++++++++++++++++++ ...rg.codehaus.groovy.runtime.ExtensionModule | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) delete mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy deleted file mode 100644 index 377a05ec4..000000000 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.jengelman.gradle.plugins.shadow.util - -final class FileExtensions { - static File resolve(File file, String relativePath) { - try { - return new File(file, relativePath) - } catch (RuntimeException e) { - throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(relativePath), file), e) - } - } - - static File createDir(File file) { - if (file.mkdirs()) { - return file - } - if (file.isDirectory()) { - return file - } - throw new AssertionError("Problems creating dir: " + this - + ". Diagnostics: exists=" + this.exists() + ", isFile=" + this.isFile() + ", isDirectory=" + this.isDirectory()) - } -} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index ac408ee9d..8c98488db 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -186,4 +186,29 @@ abstract class PluginSpecification extends Specification { } return new File(gradleUserHome, "testkit") } + + /** + * TODO: this is used as extensions for Groovy, could be replaced after migrated to Kotlin. + * Registered in resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule. + */ + static final class FileExtensions { + static final File resolve(File file, String relativePath) { + try { + return new File(file, relativePath) + } catch (RuntimeException e) { + throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(relativePath), file), e) + } + } + + static final File createDir(File file) { + if (file.mkdirs()) { + return file + } + if (file.isDirectory()) { + return file + } + throw new AssertionError("Problems creating dir: " + this + + ". Diagnostics: exists=" + file.exists() + ", isFile=" + file.isFile() + ", isDirectory=" + file.isDirectory()) + } + } } diff --git a/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule b/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule index bb7d5044f..cb99b3712 100644 --- a/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule +++ b/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule @@ -1,3 +1,3 @@ moduleName = groovy-extensions moduleVersion = ${moduleVersion} -extensionClasses =com.github.jengelman.gradle.plugins.shadow.util.FileExtensions +extensionClasses =com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification.FileExtensions From ebafa56e57775dc0248ad9a8ffba2e9119f5f1df Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 16:08:33 +0800 Subject: [PATCH 07/10] Revert "Replace File with Path in MavenPathRepository" This reverts commit 020a4760a0f97e189347f9438ac22fe7822773c3. --- .../gradle/plugins/shadow/util/PluginSpecification.groovy | 2 +- .../shadow/util/repo/maven/MavenPathRepository.groovy | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 8c98488db..c69835c70 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -121,7 +121,7 @@ abstract class PluginSpecification extends Specification { } AppendableMavenPathRepository repo(String path = 'maven-repo') { - new AppendableMavenPathRepository(dir.resolve(path)) + new AppendableMavenPathRepository(dir.resolve(path).toFile()) } void assertJarFileContentsEqual(File f, String path, String contents) { diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy index e3a1a5980..7de383ac1 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy @@ -1,21 +1,19 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven -import java.nio.file.Path - /** * A fixture for dealing with file Maven repositories. */ class MavenPathRepository implements MavenRepository { - final Path rootDir + final File rootDir - MavenPathRepository(Path rootDir) { + MavenPathRepository(File rootDir) { this.rootDir = rootDir } @Override URI getUri() { - return rootDir.toFile().toURI() + return rootDir.toURI() } @Override From ec934b21c6e0dbcbbfbf6f7bb3cbf2d6c75b3124 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 16:09:17 +0800 Subject: [PATCH 08/10] Revert "Rename MavenFileRepository to MavenPathRepository" This reverts commit 713566cda7239304b71efe4d30d284b1868e203c. --- .../jengelman/gradle/plugins/shadow/PublishingSpec.groovy | 4 ++-- ...pository.groovy => AppendableMavenFileRepository.groovy} | 4 ++-- .../gradle/plugins/shadow/util/PluginSpecification.groovy | 6 +++--- ...avenPathRepository.groovy => MavenFileRepository.groovy} | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/{AppendableMavenPathRepository.groovy => AppendableMavenFileRepository.groovy} (85%) rename src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/{MavenPathRepository.groovy => MavenFileRepository.groovy} (85%) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index 15a941b0a..ce60a5e12 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -1,6 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow -import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenPathRepository +import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification import groovy.json.JsonSlurper import groovy.xml.XmlSlurper @@ -10,7 +10,7 @@ import spock.lang.Issue class PublishingSpec extends PluginSpecification { - AppendableMavenPathRepository publishingRepo + AppendableMavenFileRepository publishingRepo @Override def setup() { diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenPathRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy similarity index 85% rename from src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenPathRepository.groovy rename to src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy index 4152c720e..cc79dc0b6 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenPathRepository.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileRepository.groovy @@ -1,10 +1,10 @@ package com.github.jengelman.gradle.plugins.shadow.util -import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenPathRepository +import com.github.jengelman.gradle.plugins.shadow.util.repo.maven.MavenFileRepository import groovy.transform.InheritConstructors @InheritConstructors -class AppendableMavenPathRepository extends MavenPathRepository { +class AppendableMavenFileRepository extends MavenFileRepository { @Override AppendableMavenFileModule module(String groupId, String artifactId, Object version = '1.0') { diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index c69835c70..194be67b5 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -19,7 +19,7 @@ abstract class PluginSpecification extends Specification { public static final String SHADOW_VERSION = System.getProperty("shadowVersion") - AppendableMavenPathRepository repo + AppendableMavenFileRepository repo def setup() { repo = repo() @@ -120,8 +120,8 @@ abstract class PluginSpecification extends Specification { return dir.resolve(path).toFile() } - AppendableMavenPathRepository repo(String path = 'maven-repo') { - new AppendableMavenPathRepository(dir.resolve(path).toFile()) + AppendableMavenFileRepository repo(String path = 'maven-repo') { + new AppendableMavenFileRepository(dir.resolve(path).toFile()) } void assertJarFileContentsEqual(File f, String path, String contents) { diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy similarity index 85% rename from src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy rename to src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy index 7de383ac1..455588315 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPathRepository.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileRepository.groovy @@ -4,10 +4,10 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven /** * A fixture for dealing with file Maven repositories. */ -class MavenPathRepository implements MavenRepository { +class MavenFileRepository implements MavenRepository { final File rootDir - MavenPathRepository(File rootDir) { + MavenFileRepository(File rootDir) { this.rootDir = rootDir } From b393ae32483a74aa0546e0db4729f2b97614b32d Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Tue, 3 Dec 2024 16:11:23 +0800 Subject: [PATCH 09/10] Apply suggestions from code review --- .../gradle/plugins/shadow/util/PluginSpecification.groovy | 1 - .../gradle/plugins/shadow/util/repo/AbstractModule.groovy | 1 - 2 files changed, 2 deletions(-) diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 194be67b5..67481c0ec 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -1,6 +1,5 @@ package com.github.jengelman.gradle.plugins.shadow.util - import org.codehaus.plexus.util.IOUtil import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner 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 a2e67d34f..7e5b983d0 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 @@ -2,7 +2,6 @@ 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. From 09afc7b96ed5b0971eb1322ce7f99b151474e6a0 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 3 Dec 2024 16:15:05 +0800 Subject: [PATCH 10/10] Revert "Move FileExtensions into PluginSpecification" This reverts commit e87fd0c35d5e5d7b26ac37dff189a8e8fef844ec. --- .../plugins/shadow/util/FileExtensions.groovy | 26 +++++++++++++++++++ .../shadow/util/PluginSpecification.groovy | 25 ------------------ ...rg.codehaus.groovy.runtime.ExtensionModule | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy new file mode 100644 index 000000000..936c0bbf9 --- /dev/null +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/FileExtensions.groovy @@ -0,0 +1,26 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +/** + * TODO: this is used as extensions for Groovy, could be replaced after migrated to Kotlin. + * Registered in resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule. + */ +final class FileExtensions { + static final File resolve(File file, String relativePath) { + try { + return new File(file, relativePath) + } catch (RuntimeException e) { + throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(relativePath), file), e) + } + } + + static final File createDir(File file) { + if (file.mkdirs()) { + return file + } + if (file.isDirectory()) { + return file + } + throw new AssertionError("Problems creating dir: " + file + + ". Diagnostics: exists=" + file.exists() + ", isFile=" + file.isFile() + ", isDirectory=" + file.isDirectory()) + } +} diff --git a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 67481c0ec..23b88c502 100644 --- a/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/funcTest/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -185,29 +185,4 @@ abstract class PluginSpecification extends Specification { } return new File(gradleUserHome, "testkit") } - - /** - * TODO: this is used as extensions for Groovy, could be replaced after migrated to Kotlin. - * Registered in resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule. - */ - static final class FileExtensions { - static final File resolve(File file, String relativePath) { - try { - return new File(file, relativePath) - } catch (RuntimeException e) { - throw new RuntimeException(String.format("Could not locate file '%s' relative to '%s'.", Arrays.toString(relativePath), file), e) - } - } - - static final File createDir(File file) { - if (file.mkdirs()) { - return file - } - if (file.isDirectory()) { - return file - } - throw new AssertionError("Problems creating dir: " + this - + ". Diagnostics: exists=" + file.exists() + ", isFile=" + file.isFile() + ", isDirectory=" + file.isDirectory()) - } - } } diff --git a/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule b/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule index cb99b3712..bb7d5044f 100644 --- a/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule +++ b/src/funcTest/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule @@ -1,3 +1,3 @@ moduleName = groovy-extensions moduleVersion = ${moduleVersion} -extensionClasses =com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification.FileExtensions +extensionClasses =com.github.jengelman.gradle.plugins.shadow.util.FileExtensions