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
|
* @param input Chaîne à traiter
|
||||||
* @return Chaîne avec les variables remplacées
|
* @return Chaîne avec les variables remplacées
|
||||||
*/
|
*/
|
||||||
private String replaceVariables(String input) {
|
private String replaceVariables(String input) {
|
||||||
if (input == null) return null;
|
if (input == null) return null;
|
||||||
|
|
||||||
String result = input;
|
String result = input;
|
||||||
Set<String> processedVars = new HashSet<>();
|
Set<String> processedVars = new HashSet<>();
|
||||||
boolean changed;
|
boolean changed;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
changed = false;
|
changed = false;
|
||||||
Matcher matcher = VARIABLE_REFERENCE.matcher(result);
|
Matcher matcher = VARIABLE_REFERENCE.matcher(result);
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String varName = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
|
String varName = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
|
||||||
if (!processedVars.contains(varName) && variables.containsKey(varName)) {
|
// Modification ici: remplacer par la valeur de la variable ou par une chaîne vide si elle n'existe pas
|
||||||
String replacement = variables.get(varName);
|
String replacement = "";
|
||||||
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
|
if (variables.containsKey(varName)) {
|
||||||
changed = true;
|
replacement = variables.get(varName);
|
||||||
processedVars.add(varName);
|
} else if (BakeCLI.isDebug()) {
|
||||||
}
|
System.out.println("Debug: Variable '" + varName + "' not defined, replacing with empty string");
|
||||||
}
|
}
|
||||||
matcher.appendTail(sb);
|
|
||||||
result = sb.toString();
|
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
|
||||||
|
changed = true;
|
||||||
// Si aucun changement n'a été fait dans ce passage, arrêter
|
processedVars.add(varName);
|
||||||
if (!changed) {
|
}
|
||||||
break;
|
matcher.appendTail(sb);
|
||||||
}
|
result = sb.toString();
|
||||||
|
|
||||||
// Réinitialiser processedVars pour le prochain passage si nécessaire
|
// Si aucun changement n'a été fait dans ce passage, arrêter
|
||||||
processedVars.clear();
|
if (!changed) {
|
||||||
|
break;
|
||||||
} while (changed);
|
}
|
||||||
|
|
||||||
return result.trim();
|
// 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.
|
* 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)
|
// Ajuster i pour sauter les lignes traitées (moins 1 car la boucle for incrémente i)
|
||||||
i += linesUsed - 1;
|
i += linesUsed - 1;
|
||||||
} else {
|
} else {
|
||||||
commands.add(command);
|
String executableCommand = command;
|
||||||
// Pour les commandes simples, créer une liste avec une seule ligne
|
commands.add(executableCommand);
|
||||||
List<String> singleLineDisplay = new ArrayList<>();
|
// Pour l'affichage, préserver le formatage mais remplacer les variables
|
||||||
singleLineDisplay.add(line);
|
String displayLine = line;
|
||||||
displayCommands.add(singleLineDisplay);
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user