Améliorations du code + Du mode debug
This commit is contained in:
@@ -9,20 +9,31 @@ public class CommandExecutor {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public void execute(Target target) {
|
||||
if (!target.needsUpdate()){
|
||||
System.out.println("bake: '" + target.getName() + "' is up to date.");
|
||||
public void execute(Rule rule) {
|
||||
if (rule.getCommands().isEmpty()) {
|
||||
System.out.println("bake: Nothing to be done for '" + rule.getName() + "'.");
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
if (!rule.needsUpdate()){
|
||||
System.out.println("bake: '" + rule.getName() + "' is up to date.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(target.getCommand());
|
||||
ProcessBuilder pb = new ProcessBuilder("sh", "-c", target.getCommand());
|
||||
Process process = pb.start();
|
||||
int exitCode = process.waitFor();
|
||||
if (debug) System.out.println("Executed: " + target.getCommand() + " with exit code " + exitCode);
|
||||
if (exitCode != 0) System.err.println("Error executing " + target.getName());
|
||||
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;
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user