Améliorations du code + Du mode debug
This commit is contained in:
@@ -26,8 +26,10 @@ public class BakefileParser {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public List<Target> parse() {
|
||||
List<Target> targets = new ArrayList<>();
|
||||
public List<Rule> parse() {
|
||||
List<Rule> rules = new ArrayList<>();
|
||||
Set<String> phonyTargets = new HashSet<>();
|
||||
|
||||
if (!Files.exists(Paths.get(filename))) {
|
||||
System.out.println("*** No targets specified and no makefile found. Stop.");
|
||||
System.exit(1);
|
||||
@@ -44,30 +46,29 @@ public class BakefileParser {
|
||||
Matcher commandMatcher = COMMAND_PATTERN.matcher(line);
|
||||
|
||||
if (targetMatcher.matches()) {
|
||||
// Sauvegarde de la précédente target si elle existe
|
||||
// Sauvegarde de la règle précédente si elle existe
|
||||
if (currentTarget != null) {
|
||||
targets.add(new Target(currentTarget, dependencies, String.join(" && ", commands)));
|
||||
rules.add(new Rule(currentTarget, dependencies, commands, phonyTargets.contains(currentTarget)));
|
||||
}
|
||||
|
||||
// Nouvelle target détectée
|
||||
// Nouvelle cible détectée
|
||||
currentTarget = targetMatcher.group(1);
|
||||
dependencies = new ArrayList<>(Arrays.asList(targetMatcher.group(2).trim().split("\\s+")));
|
||||
commands = new ArrayList<>();
|
||||
|
||||
} else if (commandMatcher.matches()) {
|
||||
// Ligne de commande associée à la dernière target trouvée
|
||||
// Ligne de commande associée à la dernière cible trouvée
|
||||
commands.add(commandMatcher.group(1));
|
||||
}
|
||||
}
|
||||
|
||||
// Ajout de la dernière target après la boucle
|
||||
// Ajout de la dernière règle après la boucle
|
||||
if (currentTarget != null) {
|
||||
targets.add(new Target(currentTarget, dependencies, String.join(" && ", commands)));
|
||||
rules.add(new Rule(currentTarget, dependencies, commands, phonyTargets.contains(currentTarget)));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return targets;
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user