Correction bug #2
This commit is contained in:
@@ -28,7 +28,7 @@ public class BakefileParser {
|
||||
* Format : "nom1 nom2 nom3 : dépendance1 dépendance2"
|
||||
* La nouvelle regex gère plusieurs cibles séparées par des espaces
|
||||
*/
|
||||
private static final Pattern TARGET_PATTERN = Pattern.compile("^([A-Za-z0-9_.\\/\\-\\$\\(\\)\\{\\}~]+(?:\\s+[A-Za-z0-9_.\\/\\-\\$\\(\\)\\{\\}~]+)*)\\s*:\\s*([^#]*?)\\s*(?:#.*)?$");
|
||||
private static final Pattern TARGET_PATTERN = Pattern.compile("^((?:\"[^\"]*\"|[A-Za-z0-9_.\\/\\-\\$\\(\\)\\{\\}~]+)(?:\\s+(?:\"[^\"]*\"|[A-Za-z0-9_.\\/\\-\\$\\(\\)\\{\\}~]+))*)\\s*:\\s*([^#]*?)\\s*(?:#.*)?$");
|
||||
|
||||
/**
|
||||
* Regex pour détecter les lignes de commande associées à une target.
|
||||
@@ -187,36 +187,105 @@ public class BakefileParser {
|
||||
* @param depStr Chaîne de dépendances
|
||||
* @return Liste de dépendances
|
||||
*/
|
||||
private List<String> splitDependencies(String depStr) {
|
||||
if (depStr == null || depStr.trim().isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private List<String> splitDependencies(String depStr) {
|
||||
if (depStr == null || depStr.trim().isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String cleanedStr = depStr.replaceAll("\\\\\\s*", " ");
|
||||
|
||||
String resolvedStr = replaceVariables(cleanedStr.trim());
|
||||
return Arrays.stream(resolvedStr.split("\\s+"))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<String> deps = new ArrayList<>();
|
||||
StringBuilder currentDep = new StringBuilder();
|
||||
boolean inQuotes = false;
|
||||
|
||||
for (int i = 0; i < cleanedStr.length(); i++) {
|
||||
char c = cleanedStr.charAt(i);
|
||||
|
||||
if (c == '"') {
|
||||
inQuotes = !inQuotes;
|
||||
currentDep.append(c);
|
||||
} else if (c == ' ' && !inQuotes) {
|
||||
// Espace en dehors des guillemets, c'est un séparateur
|
||||
if (currentDep.length() > 0) {
|
||||
String dep = currentDep.toString().trim();
|
||||
if (!dep.isEmpty()) {
|
||||
deps.add(dep);
|
||||
}
|
||||
currentDep = new StringBuilder();
|
||||
}
|
||||
} else {
|
||||
currentDep.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter la dernière dépendance s'il existe
|
||||
if (currentDep.length() > 0) {
|
||||
String dep = currentDep.toString().trim();
|
||||
if (!dep.isEmpty()) {
|
||||
deps.add(dep);
|
||||
}
|
||||
}
|
||||
|
||||
if (BakeCLI.isDebug()) {
|
||||
System.out.println("Debug: Split dependencies: " + deps);
|
||||
}
|
||||
|
||||
// Appliquer replaceVariables à chaque dépendance
|
||||
return deps.stream()
|
||||
.map(this::replaceVariables)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Découper les cibles en une liste de chaînes.
|
||||
* @param targetStr Chaîne de cibles
|
||||
* @return Liste de cibles
|
||||
*/
|
||||
private List<String> splitTargets(String targetStr) {
|
||||
if (targetStr == null || targetStr.trim().isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String resolvedStr = replaceVariables(targetStr.trim());
|
||||
return Arrays.stream(resolvedStr.split("\\s+"))
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
private List<String> splitTargets(String targetStr) {
|
||||
if (targetStr == null || targetStr.trim().isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> targets = new ArrayList<>();
|
||||
StringBuilder currentTarget = new StringBuilder();
|
||||
boolean inQuotes = false;
|
||||
|
||||
for (int i = 0; i < targetStr.length(); i++) {
|
||||
char c = targetStr.charAt(i);
|
||||
|
||||
if (c == '"') {
|
||||
inQuotes = !inQuotes;
|
||||
currentTarget.append(c);
|
||||
} else if (c == ' ' && !inQuotes) {
|
||||
// Espace en dehors des guillemets, c'est un séparateur
|
||||
if (currentTarget.length() > 0) {
|
||||
String target = currentTarget.toString().trim();
|
||||
if (!target.isEmpty()) {
|
||||
targets.add(target);
|
||||
}
|
||||
currentTarget = new StringBuilder();
|
||||
}
|
||||
} else {
|
||||
currentTarget.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter le dernier target s'il existe
|
||||
if (currentTarget.length() > 0) {
|
||||
String target = currentTarget.toString().trim();
|
||||
if (!target.isEmpty()) {
|
||||
targets.add(target);
|
||||
}
|
||||
}
|
||||
|
||||
if (BakeCLI.isDebug()) {
|
||||
System.out.println("Debug: Split targets: " + targets);
|
||||
}
|
||||
|
||||
// Appliquer replaceVariables à chaque cible
|
||||
return targets.stream()
|
||||
.map(this::replaceVariables)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyser le fichier Bakefile pour extraire les règles de build.
|
||||
|
||||
Reference in New Issue
Block a user