diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy index 16940a296..bd33ca03d 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy @@ -4,14 +4,15 @@ import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification import org.apache.commons.io.FileUtils import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.TaskOutcome -import org.junit.Rule -import org.junit.rules.TemporaryFolder +import spock.lang.TempDir + +import java.nio.file.Path import static org.gradle.testkit.runner.TaskOutcome.FROM_CACHE import static org.gradle.testkit.runner.TaskOutcome.SUCCESS abstract class AbstractCachingSpec extends PluginSpecification { - @Rule TemporaryFolder alternateDir + @TempDir Path alternateDir @Override def setup() { @@ -41,7 +42,7 @@ abstract class AbstractCachingSpec extends PluginSpecification { List cacheArguments = [ '--build-cache' ] cacheArguments.addAll(arguments) // TODO: Use PluginSpecification.run here to reuse flags, but cache tests failed for now, need to investigate. - return runner.withProjectDir(alternateDir.root).withArguments(cacheArguments).build() + return runner.withProjectDir(alternateDir.toFile()).withArguments(cacheArguments).build() } private String escapedPath(File file) { @@ -59,9 +60,9 @@ abstract class AbstractCachingSpec extends PluginSpecification { } void copyToAlternateDir() { - FileUtils.deleteDirectory(alternateDir.root) - FileUtils.forceMkdir(alternateDir.root) - FileUtils.copyDirectory(dir.root, alternateDir.root) + FileUtils.deleteDirectory(alternateDir.toFile()) + FileUtils.forceMkdir(alternateDir.toFile()) + FileUtils.copyDirectory(dir.toFile(), alternateDir.toFile()) } void assertShadowJarIsCachedAndRelocatable() { diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 9e5fc66f4..36b5d12c1 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -7,14 +7,16 @@ import org.gradle.testkit.runner.GradleRunner import org.junit.Rule import org.junit.rules.TemporaryFolder import spock.lang.Specification +import spock.lang.TempDir +import java.nio.file.Path import java.util.function.Function import java.util.jar.JarEntry import java.util.jar.JarFile abstract class PluginSpecification extends Specification { - @Rule TemporaryFolder dir + @TempDir Path dir public static final String SHADOW_VERSION = System.getProperty("shadowVersion") @@ -55,7 +57,7 @@ abstract class PluginSpecification extends Specification { GradleRunner getRunner() { GradleRunner.create() - .withProjectDir(dir.root) + .withProjectDir(dir.toFile()) .forwardOutput() .withPluginClasspath() } @@ -104,20 +106,22 @@ abstract class PluginSpecification extends Specification { } File file(String path) { - File f = new File(dir.root, path) + File f = dir.resolve(path).toFile() if (!f.exists()) { f.parentFile.mkdirs() - return dir.newFile(path) + if (!f.createNewFile()) { + throw new IOException("a file with the name \'" + f.name + "\' already exists in the test folder.") + } } return f } File getFile(String path) { - new File(dir.root, path) + new File(dir.root.toFile(), path) } AppendableMavenFileRepository repo(String path = 'maven-repo') { - new AppendableMavenFileRepository(new TestFile(dir.root, path)) + new AppendableMavenFileRepository(new TestFile(dir.toFile(), path)) } void assertJarFileContentsEqual(File f, String path, String contents) {