Correction de bug #3
This commit is contained in:
parent
06cd424919
commit
116a661e42
@ -137,42 +137,47 @@ public class BakefileParser {
|
||||
* @param input Chaîne à traiter
|
||||
* @return Chaîne avec les variables remplacées
|
||||
*/
|
||||
private String replaceVariables(String input) {
|
||||
if (input == null) return null;
|
||||
|
||||
String result = input;
|
||||
Set<String> processedVars = new HashSet<>();
|
||||
boolean changed;
|
||||
|
||||
do {
|
||||
changed = false;
|
||||
Matcher matcher = VARIABLE_REFERENCE.matcher(result);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while (matcher.find()) {
|
||||
String varName = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
|
||||
if (!processedVars.contains(varName) && variables.containsKey(varName)) {
|
||||
String replacement = variables.get(varName);
|
||||
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
|
||||
changed = true;
|
||||
processedVars.add(varName);
|
||||
}
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
result = sb.toString();
|
||||
|
||||
// Si aucun changement n'a été fait dans ce passage, arrêter
|
||||
if (!changed) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Réinitialiser processedVars pour le prochain passage si nécessaire
|
||||
processedVars.clear();
|
||||
|
||||
} while (changed);
|
||||
|
||||
return result.trim();
|
||||
}
|
||||
private String replaceVariables(String input) {
|
||||
if (input == null) return null;
|
||||
|
||||
String result = input;
|
||||
Set<String> processedVars = new HashSet<>();
|
||||
boolean changed;
|
||||
|
||||
do {
|
||||
changed = false;
|
||||
Matcher matcher = VARIABLE_REFERENCE.matcher(result);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while (matcher.find()) {
|
||||
String varName = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
|
||||
// Modification ici: remplacer par la valeur de la variable ou par une chaîne vide si elle n'existe pas
|
||||
String replacement = "";
|
||||
if (variables.containsKey(varName)) {
|
||||
replacement = variables.get(varName);
|
||||
} else if (BakeCLI.isDebug()) {
|
||||
System.out.println("Debug: Variable '" + varName + "' not defined, replacing with empty string");
|
||||
}
|
||||
|
||||
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
|
||||
changed = true;
|
||||
processedVars.add(varName);
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
result = sb.toString();
|
||||
|
||||
// Si aucun changement n'a été fait dans ce passage, arrêter
|
||||
if (!changed) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Réinitialiser processedVars pour le prochain passage si nécessaire
|
||||
processedVars.clear();
|
||||
|
||||
} while (changed);
|
||||
|
||||
return result.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remplacer les variables dans une liste de chaînes.
|
||||
@ -328,11 +333,25 @@ public class BakefileParser {
|
||||
// Ajuster i pour sauter les lignes traitées (moins 1 car la boucle for incrémente i)
|
||||
i += linesUsed - 1;
|
||||
} else {
|
||||
commands.add(command);
|
||||
// Pour les commandes simples, créer une liste avec une seule ligne
|
||||
List<String> singleLineDisplay = new ArrayList<>();
|
||||
singleLineDisplay.add(line);
|
||||
displayCommands.add(singleLineDisplay);
|
||||
String executableCommand = command;
|
||||
commands.add(executableCommand);
|
||||
// Pour l'affichage, préserver le formatage mais remplacer les variables
|
||||
String displayLine = line;
|
||||
// Ne pas modifier les lignes qui commencent par @ (silencieuses)
|
||||
if (command.startsWith("@")) {
|
||||
displayLine = line; // Garder le formatage complet pour les commandes silencieuses
|
||||
} else {
|
||||
// Remplacer les variables dans la partie de la commande uniquement (après la tabulation)
|
||||
Matcher cmdMatcher = COMMAND_PATTERN.matcher(line);
|
||||
if (cmdMatcher.matches()) {
|
||||
String cmdPart = cmdMatcher.group(1);
|
||||
String cmdWithVars = replaceVariables(cmdPart);
|
||||
displayLine = "\t" + cmdWithVars;
|
||||
}
|
||||
}
|
||||
List<String> singleLineDisplay = new ArrayList<>();
|
||||
singleLineDisplay.add(displayLine);
|
||||
displayCommands.add(singleLineDisplay);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user