From 60d4d1a81178b3ef4ac43dbe92d86c2e39813558 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 16 Apr 2023 22:23:31 +0300 Subject: [PATCH 1/2] Stop execution when link to tests directory can't be created It's not really clear what kind of exception a task should raise. There is `TaskExecutionException`, but that seems like it's an internal class, which Gradle raises itself. It's also not possible to pass it a custom string for the description. --- .../com/verificationgentleman/gradle/hdvl/svunit/TestTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java index ca8b74f..ea42c0a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java @@ -105,7 +105,7 @@ private void createLinkToTests() { File testsLink = new File(workingDir.get().getAsFile(), "tests"); Files.createSymbolicLink(testsLink.toPath(), getTestsRoot().toPath()); } catch (IOException e) { - System.out.println("Could not create 'tests' link"); + throw new RuntimeException("Could not create 'tests' link.\n\n" + e.toString()); } } From c98a9b52e82c3db4adba3bffb377efd0ae305cb0 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 16 Apr 2023 22:33:11 +0300 Subject: [PATCH 2/2] Delete tests link if it already exists We can't easily write a test for this, because the `TemporaryFolder` JUnit rule creates a directory in a virtual file system that doesn't throw exceptions when trying to create a link that already exists. --- .../com/verificationgentleman/gradle/hdvl/svunit/TestTask.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java index ea42c0a..46d08f5 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/TestTask.java @@ -103,6 +103,7 @@ protected void run() { private void createLinkToTests() { try { File testsLink = new File(workingDir.get().getAsFile(), "tests"); + Files.deleteIfExists(testsLink.toPath()); Files.createSymbolicLink(testsLink.toPath(), getTestsRoot().toPath()); } catch (IOException e) { throw new RuntimeException("Could not create 'tests' link.\n\n" + e.toString());