Skip to content

Commit 94edaeb

Browse files
author
TheSnoozer
committed
use commons-io to copy files and delete dirs
1 parent b4cf1e3 commit 94edaeb

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@
225225
<version>${mockito.version}</version>
226226
<scope>test</scope>
227227
</dependency>
228+
<dependency>
229+
<groupId>commons-io</groupId>
230+
<artifactId>commons-io</artifactId>
231+
<version>2.11.0</version>
232+
<type>jar</type>
233+
<scope>test</scope>
234+
</dependency>
228235
<dependency>
229236
<groupId>pl.pragmatists</groupId>
230237
<artifactId>JUnitParams</artifactId>

src/test/java/pl/project13/core/GitCommitIdPluginIntegrationTest.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import junitparams.JUnitParamsRunner;
2121
import junitparams.Parameters;
22+
import org.apache.commons.io.FileUtils;
2223
import org.eclipse.jgit.api.Git;
2324
import org.eclipse.jgit.api.ResetCommand;
2425
import org.junit.*;
@@ -33,10 +34,8 @@
3334
import java.nio.charset.StandardCharsets;
3435
import java.nio.file.Files;
3536
import java.nio.file.Path;
36-
import java.nio.file.StandardCopyOption;
3737
import java.text.SimpleDateFormat;
3838
import java.util.*;
39-
import java.util.stream.Stream;
4039

4140
import static java.util.Arrays.asList;
4241
import static org.assertj.core.api.Assertions.assertThat;
@@ -1511,31 +1510,14 @@ private File createTmpDotGitDirectory(@Nonnull AvailableGitTestRepo availableGit
15111510
Path dotGitDirectory = sandbox.resolve(".git");
15121511
deleteDir(dotGitDirectory);
15131512

1514-
Path src = availableGitTestRepo.getDir().toPath();
1515-
Path dest = dotGitDirectory;
1516-
1517-
Stream<Path> files = Files.walk(src);
1518-
// copy all files and folders from `src` to `dest`
1519-
files.forEach(file -> {
1520-
try {
1521-
Files.copy(file, dest.resolve(src.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
1522-
} catch (IOException e) {
1523-
e.printStackTrace();
1524-
}
1525-
});
1526-
1527-
// close the stream
1528-
files.close();
1513+
FileUtils.copyDirectory(availableGitTestRepo.getDir(), dotGitDirectory.toFile());
15291514

15301515
return dotGitDirectory.toFile();
15311516
}
15321517

15331518
private void deleteDir(@Nonnull Path toBeDeleted) throws IOException {
15341519
if (toBeDeleted.toFile().exists()) {
1535-
Files.walk(toBeDeleted)
1536-
.sorted(Comparator.reverseOrder())
1537-
.map(Path::toFile)
1538-
.forEach(File::delete);
1520+
FileUtils.deleteDirectory(toBeDeleted.toFile());
15391521
}
15401522
}
15411523

0 commit comments

Comments
 (0)