From caced85ad0ddbf8146d81ea87aa97b08f2064953 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Thu, 3 Feb 2022 12:14:47 -0500 Subject: [PATCH] User board-specific terms in error messages #3886 just refactoring for now --- .../java/com/rusefi/ConfigDefinition.java | 18 +++----- .../src/main/java/com/rusefi/PinoutLogic.java | 43 ++++++++++++++++--- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java index 016d748479..65c6c06db9 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java @@ -76,7 +76,7 @@ public class ConfigDefinition { String signaturePrependFile = null; List enumInputFiles = new ArrayList<>(); boolean withC_Defines = true; - File[] boardYamlFiles = null; + PinoutLogic pinoutLogic = null; String tsOutputsDestination = null; String definitionInputFile = null; @@ -162,15 +162,9 @@ public class ConfigDefinition { break; case KEY_BOARD_NAME: String boardName = args[i + 1]; - String dirPath = "./config/boards/" + boardName + "/connectors"; - File dirName = new File(dirPath); - FilenameFilter filter = (f, name) -> name.endsWith(".yaml"); - boardYamlFiles = dirName.listFiles(filter); - if (boardYamlFiles != null) { - for (File yamlFile : boardYamlFiles) { - inputFiles.add("config/boards/" + boardName + "/connectors/" + yamlFile.getName()); - } - } + pinoutLogic = PinoutLogic.create(boardName); + if (pinoutLogic != null) + inputFiles.addAll(pinoutLogic.getInputFiles()); break; } } @@ -198,8 +192,8 @@ public class ConfigDefinition { for (String prependFile : prependFiles) state.variableRegistry.readPrependValues(prependFile); - if (boardYamlFiles != null) { - PinoutLogic.processYamls(state.variableRegistry, boardYamlFiles, state); + if (pinoutLogic != null) { + pinoutLogic.processYamls(state.variableRegistry, state); } // Parse the input files diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/PinoutLogic.java b/java_tools/configuration_definition/src/main/java/com/rusefi/PinoutLogic.java index 7bb38b1f7e..13e68bd9c6 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/PinoutLogic.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/PinoutLogic.java @@ -6,16 +6,20 @@ import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.FileReader; +import java.io.FilenameFilter; import java.io.IOException; import java.util.*; public class PinoutLogic { - public static void processYamls(VariableRegistry registry, File[] yamlFiles, ReaderState state) throws IOException { - ArrayList> listPins = new ArrayList<>(); - for (File yamlFile : yamlFiles) { - processYamlFile(yamlFile, listPins); - } - registerPins(listPins, registry, state); + private static final String CONFIG_BOARDS = "config/boards/"; + private static final String CONNECTORS = "/connectors"; + + private final File[] boardYamlFiles; + private final String boardName; + + public PinoutLogic(String boardName, File[] boardYamlFiles) { + this.boardName = boardName; + this.boardYamlFiles = boardYamlFiles; } private static void registerPins(ArrayList> listPins, VariableRegistry registry, ReaderState state) { @@ -141,4 +145,31 @@ public class PinoutLogic { thisPin.put("class", pinClass); thisPinList.add(thisPin); } + + public static PinoutLogic create(String boardName) { + String dirPath = PinoutLogic.CONFIG_BOARDS + boardName + PinoutLogic.CONNECTORS; + File dirName = new File(dirPath); + FilenameFilter filter = (f, name) -> name.endsWith(".yaml"); + File[] boardYamlFiles = dirName.listFiles(filter); + if (boardYamlFiles == null) + return null; + return new PinoutLogic(boardName, boardYamlFiles); + } + + public void processYamls(VariableRegistry registry, ReaderState state) throws IOException { + ArrayList> listPins = new ArrayList<>(); + for (File yamlFile : boardYamlFiles) { + processYamlFile(yamlFile, listPins); + } + registerPins(listPins, registry, state); + } + + public List getInputFiles() { + List result = new ArrayList<>(); + for (File yamlFile : boardYamlFiles) { + result.add(PinoutLogic.CONFIG_BOARDS + boardName + PinoutLogic.CONNECTORS + + File.separator + yamlFile.getName()); + } + return result; + } }