From 53ea20ea694ed0684da137b20b9972bde7a2033e Mon Sep 17 00:00:00 2001 From: Yanis HAMOUDI Date: Thu, 6 Feb 2025 20:49:12 +0100 Subject: [PATCH] =?UTF-8?q?R=C3=A9solution=20de=20bug=20-=20TEST=20JAVA=20?= =?UTF-8?q?->=2001?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/monlouyan/bakefile/BakeEngine.java | 14 ++++++++++++++ src/fr/monlouyan/bakefile/BakefileParser.java | 2 +- src/fr/monlouyan/bakefile/Rule.java | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/fr/monlouyan/bakefile/BakeEngine.java b/src/fr/monlouyan/bakefile/BakeEngine.java index e0bc724..be1f436 100644 --- a/src/fr/monlouyan/bakefile/BakeEngine.java +++ b/src/fr/monlouyan/bakefile/BakeEngine.java @@ -1,19 +1,33 @@ package fr.monlouyan.bakefile; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class BakeEngine { private BakefileParser parser; private DependencyResolver resolver; private CommandExecutor executor; + private static Map ruleMap; public BakeEngine() { this.parser = new BakefileParser("Bakefile"); this.resolver = new DependencyResolver(BakeCLI.isDebug()); + ruleMap = new HashMap<>(); + } + + public static boolean hasRule(String target) { + // Vérifie si une règle existe pour créer cette cible + return ruleMap.containsKey(target); } public void run() { List rules = parser.parse(); + + for (Rule rule : rules) { + ruleMap.put(rule.getName(), rule); + } + List rulesToBuild = resolver.resolve(rules, BakeCLI.getTargets()); this.executor = new CommandExecutor(BakeCLI.isDebug(), resolver.isCircular()); diff --git a/src/fr/monlouyan/bakefile/BakefileParser.java b/src/fr/monlouyan/bakefile/BakefileParser.java index 61bf21d..1757752 100644 --- a/src/fr/monlouyan/bakefile/BakefileParser.java +++ b/src/fr/monlouyan/bakefile/BakefileParser.java @@ -54,7 +54,7 @@ public class BakefileParser { if (!Files.exists(Paths.get(filename))) { System.out.println("*** No targets specified and no makefile found. Stop."); System.exit(1); - } + } try { List lines = Files.readAllLines(Paths.get(filename)); diff --git a/src/fr/monlouyan/bakefile/Rule.java b/src/fr/monlouyan/bakefile/Rule.java index a3218c2..84ebae2 100644 --- a/src/fr/monlouyan/bakefile/Rule.java +++ b/src/fr/monlouyan/bakefile/Rule.java @@ -113,8 +113,10 @@ public class Rule { if (BakeCLI.isDebug()) { System.out.println("Debug : Dependency '" + dependency + "' last modified at " + TimestampManager.formatTimestamp(depTimestamp)); } - - if (!depFile.exists() && !dependency.isEmpty()) { + + 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); }