From 1f909b70141759230be05a41b401519cb3cba809 Mon Sep 17 00:00:00 2001
From: mamunozgil <miguel.munoz-gil@hft-stuttgart.de>
Date: Mon, 27 Jan 2025 10:47:32 +0100
Subject: [PATCH] Added debug in Testrunner

---
 docker-compose.yaml                           |  5 +-
 .../java/de/hftstuttgart/dta/Testrunner.java  | 58 +++++++++++++------
 2 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/docker-compose.yaml b/docker-compose.yaml
index 8a4e5a7..c661b48 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -33,12 +33,11 @@ services:
       - mariadb-dtt
   backend:
     container_name: backend
-    image: cota-backend:latest
+    image: cota-backend:volumes
     user: "${UID}:${GID}"
     volumes: 
       - /var/run/docker.sock:/var/run/docker.sock
-      - 'backend_dta_data: /dta-tests-assignments'
-      - '/tmp/dta-tests:/tmp/dta-tests'
+      - 'backend_dta_data:/dta-tests-assignments'
 volumes:
   mariadb_data_dtt:
     driver: local
diff --git a/src/main/java/de/hftstuttgart/dta/Testrunner.java b/src/main/java/de/hftstuttgart/dta/Testrunner.java
index aff1c57..082e916 100644
--- a/src/main/java/de/hftstuttgart/dta/Testrunner.java
+++ b/src/main/java/de/hftstuttgart/dta/Testrunner.java
@@ -63,25 +63,45 @@ public class Testrunner
     public static String[] classPathItems;      // items for the classpath
     public static String resultFolder;          // folder the result file gets serialized to
 
-    public static void main(String[] args) throws Exception
-    {
-        LOG.info("OpenJDK21 JUnit5/Jupiter Testrunner started");
-
-        LOG.info("initializing fields...");
-        sourceFolders = args[0].split(":");
-        libraryFolders = args[1].split(":");
-        resultFolder = args[2];
-        classFolder = Files.createTempDirectory("testrunner").toAbsolutePath().toString();
-
-        // finding all source files
-        Set<File> sourceFiles = new HashSet<>();
-        for (String folder : sourceFolders)
-        {
-            sourceFiles.addAll(getAllJavaFilesInFolder(Paths.get(folder).toFile()));
-        }
-
-        // call compilation and generate Results for failed compiles
-        Set<Result> compilationErrors = generateCompileResults(compile(sourceFiles, new File(classFolder)));
+    public static void main(String[] args) throws Exception {
+       LOG.info("OpenJDK21 JUnit5/Jupiter Testrunner started");
+
+       if (args.length < 3) {
+           LOG.severe("Insufficient arguments provided. Expected: <sourceFolders>:<libraryFolders>:<resultFolder>");
+           throw new IllegalArgumentException("Missing required arguments.");
+       }
+
+       LOG.info("Initializing fields...");
+       sourceFolders = args[0].split(":");
+       libraryFolders = args[1].split(":");
+       resultFolder = args[2];
+
+       LOG.info(String.format("Source folders: %s", Arrays.toString(sourceFolders)));
+       LOG.info(String.format("Library folders: %s", Arrays.toString(libraryFolders)));
+       LOG.info(String.format("Result folder: %s", resultFolder));
+
+       classFolder = Files.createTempDirectory("testrunner").toAbsolutePath().toString();
+       LOG.info(String.format("Temporary class folder: %s", classFolder));
+
+       // Discover source files
+       Set<File> sourceFiles = new HashSet<>();
+       for (String folder : sourceFolders) {
+           File dir = Paths.get(folder).toFile();
+           if (!dir.exists() || !dir.isDirectory()) {
+               LOG.warning(String.format("Source folder does not exist or is not a directory: %s", folder));
+               continue;
+           }
+           sourceFiles.addAll(getAllJavaFilesInFolder(dir));
+       }
+
+       LOG.info(String.format("Discovered %d source files.", sourceFiles.size()));
+       if (sourceFiles.isEmpty()) {
+           LOG.severe("No source files found. Compilation cannot proceed.");
+           throw new IllegalStateException("No source files found.");
+       }
+
+       // Compilation
+       Set<Result> compilationErrors = generateCompileResults(compile(sourceFiles, new File(classFolder)));
 
         // run unit tests found in the compiled class files
         ResultSummary resultSummary = runTests();
-- 
GitLab