only:dependency injection towards TDD
This commit is contained in:
parent
2acef57b1b
commit
3bcee51447
|
@ -79,7 +79,7 @@ public class SdCardFieldsGeneratorTest {
|
|||
}
|
||||
|
||||
private static void processAndAssert(String input, String expectedOutput, Actor actor) {
|
||||
ReaderStateImpl state = new ReaderStateImpl();
|
||||
ReaderStateImpl state = new ReaderStateImpl(null);
|
||||
actor.act(state);
|
||||
|
||||
SdCardFieldsConsumer consumer = new SdCardFieldsConsumer(LazyFile.TEST);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.util.IoUtils;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public interface ReaderProvider {
|
||||
ReaderProvider REAL = fileName -> new InputStreamReader(new FileInputStream(fileName), IoUtils.CHARSET.name());
|
||||
|
||||
Reader read(String fileName) throws FileNotFoundException, UnsupportedEncodingException;
|
||||
}
|
|
@ -37,6 +37,7 @@ public class ReaderStateImpl implements ReaderState {
|
|||
private final Map<String, Integer> tsCustomSize = new HashMap<>();
|
||||
private final Map<String, String> tsCustomLine = new HashMap<>();
|
||||
private final Map<String, ConfigStructureImpl> structures = new HashMap<>();
|
||||
private final ReaderProvider readerProvider;
|
||||
private String headerMessage;
|
||||
// well, technically those should be a builder for state, not this state class itself
|
||||
private String tsFileOutputName = "rusefi.ini";
|
||||
|
@ -49,6 +50,14 @@ public class ReaderStateImpl implements ReaderState {
|
|||
private final EnumsReader enumsReader = new EnumsReader();
|
||||
private final VariableRegistry variableRegistry = new VariableRegistry();
|
||||
|
||||
public ReaderStateImpl() {
|
||||
this(ReaderProvider.REAL);
|
||||
}
|
||||
|
||||
public ReaderStateImpl(ReaderProvider readerProvider) {
|
||||
this.readerProvider = readerProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWithC_Defines(boolean withC_Defines) {
|
||||
this.withC_Defines = withC_Defines;
|
||||
|
@ -91,6 +100,7 @@ public class ReaderStateImpl implements ReaderState {
|
|||
structure.addBitField(bitField);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doJob() throws IOException {
|
||||
|
||||
|
@ -102,7 +112,7 @@ public class ReaderStateImpl implements ReaderState {
|
|||
* the destinations/writers
|
||||
*/
|
||||
SystemOut.println("Reading definition from " + Objects.requireNonNull(definitionInputFile));
|
||||
BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(RootHolder.ROOT + definitionInputFile), IoUtils.CHARSET.name()));
|
||||
BufferedReader definitionReader = new BufferedReader(readerProvider.read(RootHolder.ROOT + definitionInputFile));
|
||||
readBufferedReader(definitionReader, destinations);
|
||||
|
||||
if (destCDefinesFileName != null) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
|||
|
||||
public class TriggerMetaGenerator {
|
||||
public static void main(String[] a) throws IOException {
|
||||
ReaderStateImpl reader = new ReaderStateImpl();
|
||||
ReaderStateImpl reader = new ReaderStateImpl(null);
|
||||
reader.setDefinitionInputFile("integration/rusefi_config_trigger.txt");
|
||||
reader.addCHeaderDestination("../unit_tests/TriggerMeta.h");
|
||||
reader.addJavaDestination("../java_tools/trigger-image/src/main/java/com/rusefi/config/generated/TriggerMeta.java");
|
||||
|
|
|
@ -3,13 +3,11 @@ package com.rusefi.ldmp;
|
|||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.output.*;
|
||||
import com.rusefi.util.IoUtils;
|
||||
import com.rusefi.util.LazyFile;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -24,6 +22,8 @@ public class LiveDataProcessor {
|
|||
|
||||
private final static String tsOutputsDestination = "console/binary/";
|
||||
|
||||
private final ReaderProvider readerProvider;
|
||||
|
||||
private final GaugeConsumer gaugeConsumer = new GaugeConsumer(tsOutputsDestination + File.separator + "generated/gauges.ini");
|
||||
|
||||
private final StringBuilder enumContent = new StringBuilder(header +
|
||||
|
@ -43,6 +43,10 @@ public class LiveDataProcessor {
|
|||
|
||||
private final String extraPrepend = System.getProperty("LiveDataProcessor.extra_prepend");
|
||||
|
||||
public LiveDataProcessor(ReaderProvider readerProvider) {
|
||||
this.readerProvider = readerProvider;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length != 1) {
|
||||
System.err.println("One parameter expected: name of live data yaml input file");
|
||||
|
@ -50,10 +54,10 @@ public class LiveDataProcessor {
|
|||
}
|
||||
TriggerMetaGenerator.main(null);
|
||||
String yamlFileName = args[0];
|
||||
Yaml yaml = new Yaml();
|
||||
Map<String, Object> data = yaml.load(new FileReader(yamlFileName));
|
||||
Map<String, Object> data = getStringObjectMap(new FileReader(yamlFileName));
|
||||
|
||||
LiveDataProcessor liveDataProcessor = new LiveDataProcessor();
|
||||
|
||||
LiveDataProcessor liveDataProcessor = new LiveDataProcessor(ReaderProvider.REAL);
|
||||
|
||||
int sensorTsPosition = liveDataProcessor.handleYaml(data);
|
||||
liveDataProcessor.writeFiles();
|
||||
|
@ -78,6 +82,11 @@ public class LiveDataProcessor {
|
|||
liveDataProcessor.end();
|
||||
}
|
||||
|
||||
public static Map<String, Object> getStringObjectMap(Reader reader) {
|
||||
Yaml yaml = new Yaml();
|
||||
return yaml.load(reader);
|
||||
}
|
||||
|
||||
private void end() throws IOException {
|
||||
gaugeConsumer.endFile();
|
||||
}
|
||||
|
@ -86,7 +95,7 @@ public class LiveDataProcessor {
|
|||
void onEntry(String name, String javaName, String folder, String prepend, boolean withCDefines, String[] outputNames, String constexpr, String conditional, String engineModule, Boolean isPtr) throws IOException;
|
||||
}
|
||||
|
||||
private int handleYaml(Map<String, Object> data) throws IOException {
|
||||
public int handleYaml(Map<String, Object> data) throws IOException {
|
||||
JavaSensorsConsumer javaSensorsConsumer = new JavaSensorsConsumer();
|
||||
|
||||
OutputsSectionConsumer outputsSections = new OutputsSectionConsumer(tsOutputsDestination + File.separator + "generated/output_channels.ini");
|
||||
|
@ -107,7 +116,7 @@ public class LiveDataProcessor {
|
|||
|
||||
baseAddressCHeader.append("#define " + name.toUpperCase() + "_BASE_ADDRESS " + startingPosition + "\n");
|
||||
|
||||
ReaderState state = new ReaderStateImpl();
|
||||
ReaderState state = new ReaderStateImpl(readerProvider);
|
||||
state.setDefinitionInputFile(folder + File.separator + name + ".txt");
|
||||
state.setWithC_Defines(withCDefines);
|
||||
|
||||
|
|
Loading…
Reference in New Issue