From 56789b989294c47ceb1b9c9c84bf9405b12b096b Mon Sep 17 00:00:00 2001 From: Louay DARDOURI <louay.dardouri@etu.u-pec.fr> Date: Wed, 12 Mar 2025 22:03:57 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20gestion=20des=20erreurs=20ign?= =?UTF-8?q?or=C3=A9es=20dans=20CommandExecutor=20et=20cr=C3=A9ation=20de?= =?UTF-8?q?=20nouveaux=20fichiers=20de=20test=20pour=20le=20Makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monlouyan/bakefile/CommandExecutor.java | 27 +++++++++++++++---- tests/tests-autres-groupes/amir/bake/Bakefile | 9 +++++++ tests/tests-autres-groupes/amir/bake/main | 0 tests/tests-autres-groupes/amir/make/Makefile | 9 +++++++ tests/tests-autres-groupes/amir/make/main | 0 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 tests/tests-autres-groupes/amir/bake/Bakefile create mode 100644 tests/tests-autres-groupes/amir/bake/main create mode 100644 tests/tests-autres-groupes/amir/make/Makefile create mode 100644 tests/tests-autres-groupes/amir/make/main diff --git a/src/fr/monlouyan/bakefile/CommandExecutor.java b/src/fr/monlouyan/bakefile/CommandExecutor.java index a4d6261..60664dc 100644 --- a/src/fr/monlouyan/bakefile/CommandExecutor.java +++ b/src/fr/monlouyan/bakefile/CommandExecutor.java @@ -76,6 +76,12 @@ public class CommandExecutor { // Enlever le @ si présent pour exécuter la commande correctement String actualCommand = silent ? command.substring(1) : command; + boolean ignoreErrors = actualCommand.startsWith("-"); + + if(ignoreErrors){ + actualCommand = actualCommand.substring(1).trim(); + } + if (isCircular){ if (!silent) { System.out.println(actualCommand); @@ -96,14 +102,25 @@ public class CommandExecutor { // Attendre la fin du processus int exitCode = process.waitFor(); - if (exitCode != 0) { - System.err.println("bake: *** [" + rule.getName() + "] Error " + exitCode); - System.exit(2); + if (exitCode != 0) { + if (ignoreErrors) { + System.err.println("bake: [" + rule.getName() + "] Error " + exitCode + " (ignored)"); + } else { + System.err.println("bake: *** [" + rule.getName() + "] Error " + exitCode); + System.exit(2); + } + } else if (exitCode != 0 && ignoreErrors && debug) { + System.out.println("Debug: Command failed with exit code " + exitCode + ", but errors are ignored"); } } catch (IOException | InterruptedException e) { - e.printStackTrace(); - System.exit(2); + if(!ignoreErrors){ + e.printStackTrace(); + System.exit(2); + } else if(debug){ + System.out.println("Debug: Command execution failed, but errors are ignored"); + e.printStackTrace(); + } } } } diff --git a/tests/tests-autres-groupes/amir/bake/Bakefile b/tests/tests-autres-groupes/amir/bake/Bakefile new file mode 100644 index 0000000..e1876d2 --- /dev/null +++ b/tests/tests-autres-groupes/amir/bake/Bakefile @@ -0,0 +1,9 @@ +all: main + +main: + echo "Compilation de main..." + touch main + +clean: + - rm main + @echo "Fichiers nettoyés." diff --git a/tests/tests-autres-groupes/amir/bake/main b/tests/tests-autres-groupes/amir/bake/main new file mode 100644 index 0000000..e69de29 diff --git a/tests/tests-autres-groupes/amir/make/Makefile b/tests/tests-autres-groupes/amir/make/Makefile new file mode 100644 index 0000000..e1876d2 --- /dev/null +++ b/tests/tests-autres-groupes/amir/make/Makefile @@ -0,0 +1,9 @@ +all: main + +main: + echo "Compilation de main..." + touch main + +clean: + - rm main + @echo "Fichiers nettoyés." diff --git a/tests/tests-autres-groupes/amir/make/main b/tests/tests-autres-groupes/amir/make/main new file mode 100644 index 0000000..e69de29