Skip to content

Commit

Permalink
Replace TemporaryFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Oct 11, 2024
1 parent 833254c commit a9b167c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -41,7 +42,7 @@ abstract class AbstractCachingSpec extends PluginSpecification {
List<String> 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) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -55,7 +57,7 @@ abstract class PluginSpecification extends Specification {

GradleRunner getRunner() {
GradleRunner.create()
.withProjectDir(dir.root)
.withProjectDir(dir.toFile())
.forwardOutput()
.withPluginClasspath()
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a9b167c

Please sign in to comment.