Skip to content

Commit 96c0421

Browse files
author
Suszyński Krzysztof
committed
Compatibility with Java 6
1 parent 737d504 commit 96c0421

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@
138138
<version>19.0</version>
139139
<scope>test</scope>
140140
</dependency>
141-
141+
<dependency>
142+
<groupId>commons-io</groupId>
143+
<artifactId>commons-io</artifactId>
144+
<version>2.4</version>
145+
<scope>test</scope>
146+
</dependency>
142147
</dependencies>
143148

144149
<build>

src/test/java/pl/wavesoftware/testing/JmhCleaner.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package pl.wavesoftware.testing;
22

3+
import com.google.common.io.Files;
4+
import java.io.File;
35
import org.junit.Test;
46
import org.junit.rules.TestRule;
57
import org.junit.runner.Description;
@@ -9,12 +11,7 @@
911
import java.lang.reflect.Method;
1012
import java.lang.reflect.Modifier;
1113
import java.net.URISyntaxException;
12-
import java.nio.file.FileVisitResult;
13-
import java.nio.file.Files;
14-
import java.nio.file.Path;
15-
import java.nio.file.Paths;
16-
import java.nio.file.SimpleFileVisitor;
17-
import java.nio.file.attribute.BasicFileAttributes;
14+
import org.apache.commons.io.FileUtils;
1815

1916
/**
2017
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a>
@@ -47,7 +44,6 @@ private Class<?> validateTestClass(Class<?> testClass) {
4744

4845
@Override
4946
public Statement apply(final Statement base, Description description) {
50-
5147
return new Statement() {
5248
@Override
5349
public void evaluate() throws Throwable {
@@ -62,22 +58,19 @@ public void evaluate() throws Throwable {
6258

6359
private void cleanup() throws IOException, URISyntaxException {
6460
String location = testClass.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
65-
Path testAnnotationsPath = Paths.get(location).getParent().resolve(GENERATED_TEST_SOURCES).resolve(TEST_ANNOTATIONS);
66-
if (!testAnnotationsPath.toFile().isDirectory()) {
61+
File file = new File(location).getCanonicalFile().getParentFile();
62+
File testAnnotationsPath = resolve(file, GENERATED_TEST_SOURCES, TEST_ANNOTATIONS);
63+
if (!testAnnotationsPath.isDirectory()) {
6764
return;
6865
}
69-
Files.walkFileTree(testAnnotationsPath, new SimpleFileVisitor<Path>() {
70-
@Override
71-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
72-
Files.delete(file);
73-
return FileVisitResult.CONTINUE;
74-
}
75-
76-
@Override
77-
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
78-
Files.delete(dir);
79-
return FileVisitResult.CONTINUE;
80-
}
81-
});
66+
FileUtils.deleteDirectory(testAnnotationsPath);
67+
}
68+
69+
private File resolve(File parent, String... paths) {
70+
StringBuilder sb = new StringBuilder(parent.getPath());
71+
for (String path : paths) {
72+
sb.append(File.separator).append(path);
73+
}
74+
return new File(sb.toString());
8275
}
8376
}

0 commit comments

Comments
 (0)