Améliorations des dépendances circulaire

This commit is contained in:
2025-02-04 21:25:16 +01:00
parent c20a508069
commit 1f31e318dc
35 changed files with 156 additions and 58 deletions

View File

@@ -4,9 +4,12 @@ import java.io.IOException;
public class CommandExecutor {
private boolean debug;
public CommandExecutor(boolean debug) {
private boolean needsUpdate = false; // Pour tracker si quelque chose doit être mis à jour
private boolean isCircular = false; // Pour tracker si un cycle a été détecté
public CommandExecutor(boolean debug, boolean isCircular) {
this.debug = debug;
this.isCircular = isCircular;
}
public void execute(Rule rule) {
@@ -15,28 +18,43 @@ public class CommandExecutor {
return;
}
if (!rule.needsUpdate()) {
if (rule.getName().equals(BakefileParser.getFirstTarget())) {
System.out.println("bake: '" + rule.getName() + "' is up to date.");
}
return;
// On vérifie d'abord si cette règle a besoin d'être mise à jour
boolean ruleNeedsUpdate = rule.needsUpdate();
if (ruleNeedsUpdate) {
needsUpdate = true; // Au moins une règle doit être mise à jour
}
try {
for (String command : rule.getCommands()) {
System.out.println(command); // Affichage de la commande executée
ProcessBuilder pb = new ProcessBuilder("sh", "-c", command);
Process process = pb.start();
int exitCode = process.waitFor();
if (debug) System.out.println("Executed: " + command + " with exit code " + exitCode);
if (exitCode != 0) {
System.err.println("Error executing " + rule.getName() + "");
break;
for (String command : rule.getCommands()) {
if (isCircular){
System.out.println(command);
}
// Mais on n'exécute que si nécessaire
if (ruleNeedsUpdate) {
try {
if(!isCircular){
System.out.println(command);
}
if (debug) System.out.println("Debug: Executing " + command);
ProcessBuilder pb = new ProcessBuilder("sh", "-c", command);
Process process = pb.start();
int exitCode = process.waitFor();
if (exitCode != 0) {
System.err.println("Error executing " + rule.getName());
System.exit(1);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
System.exit(1);
}
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
// On affiche "up to date" seulement après avoir traité TOUTES les règles
// et seulement si AUCUNE règle n'avait besoin d'être mise à jour
if (rule.getName().equals(BakefileParser.getFirstTarget()) && !needsUpdate) {
System.out.println("bake: '" + rule.getName() + "' is up to date.");
}
}
}