Skip to content

Commit db7b76b

Browse files
authored
Merge pull request #595 from adecker89/copyFileDirectory
Allow copy-file to copy directories
2 parents e9a5682 + e9e417b commit db7b76b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: src/main/java/org/gradle/profiler/mutations/CopyFileMutator.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.base.Strings;
44
import com.google.common.io.Files;
55
import com.typesafe.config.Config;
6+
7+
import org.apache.commons.io.FileUtils;
68
import org.gradle.profiler.BuildMutator;
79
import org.gradle.profiler.CompositeBuildMutator;
810
import org.gradle.profiler.ConfigUtil;
@@ -30,7 +32,11 @@ protected void executeOnSchedule() {
3032
if (!target.exists()) {
3133
Files.createParentDirs(target);
3234
}
33-
Files.copy(source, target);
35+
if(source.isDirectory()) {
36+
FileUtils.copyDirectory(source, target);
37+
} else {
38+
Files.copy(source, target);
39+
}
3440
} catch (IOException e) {
3541
throw new UncheckedIOException("Failed to copy '" + source.getAbsolutePath() + "' to '" + target.getAbsolutePath() + "'", e);
3642
}

Diff for: src/test/groovy/org/gradle/profiler/mutations/CopyFileMutatorTest.groovy

+27
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ class CopyFileMutatorTest extends AbstractMutatorTest {
2727
target.text == expectedContents
2828
}
2929

30+
def "copies directory and contents from source to target"() {
31+
def testDir = tmpDir.newFolder()
32+
33+
def expectedContents = "Copy file from source to target"
34+
def source = new File(testDir, "source/file.txt")
35+
source.parentFile.mkdirs()
36+
source.text = expectedContents
37+
38+
def target = new File(testDir, "nested/target/file.txt")
39+
40+
def spec = mockConfigSpec("""{
41+
copy-file = {
42+
source = "source"
43+
target = "nested/target"
44+
}
45+
}""")
46+
_ * spec.projectDir >> testDir
47+
48+
when:
49+
def mutator = new CopyFileMutator.Configurator().configure("copy-file", spec)
50+
mutator.beforeScenario(scenarioContext)
51+
52+
then:
53+
target.exists()
54+
target.text == expectedContents
55+
}
56+
3057
def "copies multiple sets of source and target"() {
3158
def testDir = tmpDir.newFolder()
3259

0 commit comments

Comments
 (0)