From 1bafee8e5c256178615159b02d8bf25014c09088 Mon Sep 17 00:00:00 2001
From: Louay DARDOURI <louay.dardouri@etu.u-pec.fr>
Date: Sun, 9 Feb 2025 17:48:18 +0100
Subject: [PATCH] =?UTF-8?q?=C3=80=20V=C3=89RIFIER=20:=20Correction=20des?=
 =?UTF-8?q?=20messages=20d'erreur=20pour=20utiliser=20des=20backticks=20au?=
 =?UTF-8?q?tour=20des=20d=C3=A9pendances=20et=20r=C3=A9organisation=20de?=
 =?UTF-8?q?=20la=20logique=20de=20v=C3=A9rification=20des=20mises=20=C3=A0?=
 =?UTF-8?q?=20jour=20dans=20la=20classe=20Rule=20+=20Ajout=20du=20test=201?=
 =?UTF-8?q?3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../monlouyan/bakefile/CommandExecutor.java   |   2 +-
 src/fr/monlouyan/bakefile/Rule.java           | 153 +++++++++---------
 2 files changed, 76 insertions(+), 79 deletions(-)

diff --git a/src/fr/monlouyan/bakefile/CommandExecutor.java b/src/fr/monlouyan/bakefile/CommandExecutor.java
index 065ea24..6a7e07d 100644
--- a/src/fr/monlouyan/bakefile/CommandExecutor.java
+++ b/src/fr/monlouyan/bakefile/CommandExecutor.java
@@ -68,7 +68,7 @@ public class CommandExecutor {
         // 2. Aucune règle n'avait besoin d'être mise à jour
         // 3. On n'a PAS de commandes à exécuter
         else if (rule.getName().equals(BakefileParser.getFirstTarget()) && !needsUpdate && rule.getCommands().isEmpty()) {
-            System.out.println("bake: Nothing to be done for '" + rule.getName() + "'.");
+            System.out.println("bake: Nothing to be done for `" + rule.getName() + "'.");
         }
     }
 }
\ No newline at end of file
diff --git a/src/fr/monlouyan/bakefile/Rule.java b/src/fr/monlouyan/bakefile/Rule.java
index 4831799..72c2e22 100644
--- a/src/fr/monlouyan/bakefile/Rule.java
+++ b/src/fr/monlouyan/bakefile/Rule.java
@@ -23,82 +23,79 @@ public class Rule {
     public boolean isEmpty() { return dependencies.isEmpty() && commands.isEmpty(); }
 
     public boolean needsUpdate() {
-        if (BakeCLI.isDebug()){
-            System.out.println("Debug : Checking if rule " + name + " needs update");
-        }
-
-        // Les règles phony sont toujours mises à jour
-        if (isPhony) {
-            if (BakeCLI.isDebug()) {
-                System.out.println("Debug : Rule " + name + " is phony, always needs update");
-            }
-            return true;
-        }
-
-        // Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour
-        if (commands.isEmpty()) {
-            for (String dependency : dependencies) {
-                File depFile = new File(dependency);
-                if (!depFile.exists() && !dependency.isEmpty() && !BakeEngine.hasRule(dependency)) {
-                    System.out.println("bake: *** No rule to make target `" + dependency + "', needed by '" + name + "'.  Stop.");
-                    System.exit(1);
-                }
-                Rule depRule = BakeEngine.getRule(dependency);
-                if (depRule != null && depRule.needsUpdate()) {
-                    if (BakeCLI.isDebug()) {
-                        System.out.println("Debug : Dependency rule " + dependency + " needs update");
-                    }
-                    return true;
-                }
-            }
-            return false;
-        }
-
-        // Pour les règles avec des commandes, on vérifie aussi les timestamps
-        File targetFile = new File(name);
-        if (BakeCLI.isDebug()){
-            System.out.println("Debug : Checking if target file " + name + " exist and is up to date");
-        }
-
-        long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0;
-        
-        if (BakeCLI.isDebug()) {
-            System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp));
-        }
-    
-        for (String dependency : dependencies) {
-            File depFile = new File(dependency);
-            long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0;
-
-            if (BakeCLI.isDebug()) {
-                System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
-            }
-
-            // Vérifier si une règle existe pour cette dépendance
-            boolean hasRule = BakeEngine.hasRule(dependency);
-
-            if (!depFile.exists() && !dependency.isEmpty() && !hasRule) {
-                System.out.println("bake: *** No rule to make target `" + dependency + "', needed by '" + name + "'.  Stop.");
-                System.exit(1);
-            }
-
-            // Si la dépendance est une règle et qu'elle a besoin d'être mise à jour
-            Rule depRule = BakeEngine.getRule(dependency);
-            if (depRule != null && depRule.needsUpdate()) {
-                if (BakeCLI.isDebug()) {
-                    System.out.println("Debug : Dependency rule " + dependency + " needs update");
-                }
-                return true;
-            }
-
-            // Vérifier les timestamps seulement si le fichier existe
-            if (depFile.exists() && TimestampManager.getTimestamp(depFile) > targetTimestamp) {
-                if (BakeCLI.isDebug()) {
-                    System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
-                }
-                return true;
-            }
-        }
-        return false;
-    }
+		if (BakeCLI.isDebug()){
+			System.out.println("Debug : Checking if rule " + name + " needs update");
+		}
+	
+		// Les règles phony sont toujours mises à jour
+		if (isPhony) {
+			if (BakeCLI.isDebug()) {
+				System.out.println("Debug : Rule " + name + " is phony, always needs update");
+			}
+			return true;
+		}
+	
+		// Vérifier d'abord toutes les dépendances avant d'exécuter quoi que ce soit
+		for (String dependency : dependencies) {
+			File depFile = new File(dependency);
+			boolean hasRule = BakeEngine.hasRule(dependency);
+			if (!depFile.exists() && !dependency.isEmpty() && !hasRule) {
+				System.out.println("bake: *** No rule to make target `" + dependency + "', needed by `" + name + "'.  Stop.");
+				System.exit(1);
+			}
+		}
+	
+		// Si la règle n'a pas de commandes, on vérifie seulement si une dépendance doit être mise à jour
+		if (commands.isEmpty()) {
+			for (String dependency : dependencies) {
+				Rule depRule = BakeEngine.getRule(dependency);
+				if (depRule != null && depRule.needsUpdate()) {
+					if (BakeCLI.isDebug()) {
+						System.out.println("Debug : Dependency rule " + dependency + " needs update");
+					}
+					return true;
+				}
+			}
+			return false;
+		}
+	
+		// Pour les règles avec des commandes, on vérifie aussi les timestamps
+		File targetFile = new File(name);
+		if (BakeCLI.isDebug()){
+			System.out.println("Debug : Checking if target file " + name + " exist and is up to date");
+		}
+	
+		long targetTimestamp = targetFile.exists() ? TimestampManager.getTimestamp(targetFile) : 0;
+		
+		if (BakeCLI.isDebug()) {
+			System.out.println("Debug : Target file '" + name + "' last modified at " + TimestampManager.formatTimestamp(targetTimestamp));
+		}
+	
+		for (String dependency : dependencies) {
+			File depFile = new File(dependency);
+			long depTimestamp = depFile.exists() ? TimestampManager.getTimestamp(depFile) : 0;
+	
+			if (BakeCLI.isDebug()) {
+				System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp));
+			}
+	
+			// Si la dépendance est une règle et qu'elle a besoin d'être mise à jour
+			Rule depRule = BakeEngine.getRule(dependency);
+			if (depRule != null && depRule.needsUpdate()) {
+				if (BakeCLI.isDebug()) {
+					System.out.println("Debug : Dependency rule " + dependency + " needs update");
+				}
+				return true;
+			}
+	
+			// Vérifier les timestamps seulement si le fichier existe
+			if (depFile.exists() && TimestampManager.getTimestamp(depFile) > targetTimestamp) {
+				if (BakeCLI.isDebug()) {
+					System.out.println("Debug : Dependency " + dependency + " is newer than target file " + name + ", needs update");
+				}
+				return true;
+			}
+		}
+		return false;
+	}
 }
\ No newline at end of file