Try to workaround file locking on windows

This commit is contained in:
Guillaume Nodet
2021-01-13 13:07:54 +01:00
parent b10af9fe15
commit 29e823eb1b
2 changed files with 13 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ import org.mvndaemon.mvnd.assertj.TestClientOutput;
import org.mvndaemon.mvnd.client.Client;
import org.mvndaemon.mvnd.client.DaemonParameters;
import org.mvndaemon.mvnd.common.Message;
import org.mvndaemon.mvnd.common.Os;
import org.mvndaemon.mvnd.junit.MvndNativeTest;
import org.mvndaemon.mvnd.junit.TestUtils;
@@ -90,7 +91,7 @@ public class SingleModuleNativeIT {
final TestClientOutput o1 = new TestClientOutput();
client.execute(o1, "clean", "install", "-e", "-B").assertSuccess();
TestUtils.deleteDir(localMavenRepo);
TestUtils.deleteDir(localMavenRepo, Os.current() != Os.WINDOWS);
final TestClientOutput o2 = new TestClientOutput();
client.execute(o2, "clean", "install", "-e", "-B").assertSuccess();

View File

@@ -38,9 +38,13 @@ public class TestUtils {
}
public static Path deleteDir(Path dir) {
return deleteDir(dir, true);
}
public static Path deleteDir(Path dir, boolean failOnError) {
if (Files.exists(dir)) {
try (Stream<Path> files = Files.walk(dir)) {
files.sorted(Comparator.reverseOrder()).forEach(TestUtils::deleteFile);
files.sorted(Comparator.reverseOrder()).forEach(f -> deleteFile(f, failOnError));
} catch (Exception e) {
throw new RuntimeException("Could not walk " + dir, e);
}
@@ -48,11 +52,15 @@ public class TestUtils {
return dir;
}
private static void deleteFile(Path f) {
private static void deleteFile(Path f, boolean failOnError) {
try {
Files.delete(f);
} catch (Exception e) {
throw new RuntimeException("Could not delete " + f, e);
if (failOnError) {
throw new RuntimeException("Could not delete " + f, e);
} else {
System.err.println("Error deleting " + f + ": " + e);
}
}
}