adding flexibility
This commit is contained in:
parent
8a149245c5
commit
1b1ffd6a96
|
@ -2,6 +2,7 @@ package com.rusefi.output;
|
|||
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.util.LazyFile;
|
||||
import com.rusefi.util.Output;
|
||||
import com.rusefi.util.SystemOut;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -99,13 +100,17 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
return tsPosition;
|
||||
}
|
||||
|
||||
private void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException {
|
||||
protected void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException {
|
||||
TsFileContent tsContent = readTsFile(tsPath);
|
||||
SystemOut.println("Got " + tsContent.getPrefix().length() + "/" + tsContent.getPostfix().length() + " of " + TS_FILE_INPUT_NAME);
|
||||
|
||||
// File.getPath() would eliminate potential separator at the end of the path
|
||||
String fileName = new File(tsPath).getPath() + File.separator + TS_FILE_OUTPUT_NAME;
|
||||
LazyFile tsHeader = new LazyFile(fileName);
|
||||
Output tsHeader = new LazyFile(fileName);
|
||||
writeContent(fieldsSection, tsContent, tsHeader);
|
||||
}
|
||||
|
||||
protected void writeContent(String fieldsSection, TsFileContent tsContent, Output tsHeader) throws IOException {
|
||||
tsHeader.write(tsContent.getPrefix());
|
||||
|
||||
tsHeader.write("; " + CONFIG_DEFINITION_START + ConfigDefinition.EOL);
|
||||
|
@ -184,8 +189,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startFile() throws IOException {
|
||||
|
||||
public void startFile() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TsFileContent;
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
import com.rusefi.output.TSProjectConsumer;
|
||||
import com.rusefi.util.Output;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BitParsingTest {
|
||||
@Test
|
||||
public void testBitParser() throws IOException {
|
||||
ReaderState state = new ReaderState();
|
||||
|
||||
String inputString = "struct pid_s\nbit activateAuxPid1;\n" +
|
||||
"bit fieldName;\n" +
|
||||
"end_struct\n";
|
||||
BufferedReader reader = new BufferedReader(new StringReader(inputString));
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
TSProjectConsumer javaFieldsConsumer = new TSProjectConsumer(new CharArrayWriter(), "", state) {
|
||||
@Override
|
||||
protected void writeTunerStudioFile(String tsPath, String fieldsSection) throws IOException {
|
||||
writeContent(fieldsSection, new TsFileContent("", ""), createOutput(sw));
|
||||
}
|
||||
};
|
||||
state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer));
|
||||
|
||||
System.out.printf("start[" + sw.toString() + "]end");
|
||||
|
||||
}
|
||||
|
||||
private Output createOutput(StringWriter sw) {
|
||||
return new Output() {
|
||||
@Override
|
||||
public void write(String line) {
|
||||
sw.write(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
* This file would override file content only of content has changed, disregarding the magic tag line.
|
||||
*/
|
||||
public class LazyFile {
|
||||
public class LazyFile implements Output {
|
||||
public static final String LAZY_FILE_TAG = "was generated automatically by rusEfi tool ";
|
||||
private static final String PROPERTY_NAME = "rusefi.generator.lazyfile.enabled";
|
||||
private static boolean ENABLED = Boolean.getBoolean(PROPERTY_NAME);
|
||||
|
@ -26,12 +26,14 @@ public class LazyFile {
|
|||
this.filename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(String line) {
|
||||
content.append(line);
|
||||
if (!line.contains(LAZY_FILE_TAG))
|
||||
contentWithoutTag.append(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
String fileContent = unifySpaces(readCurrentContent(filename));
|
||||
String newContent = unifySpaces(contentWithoutTag.toString().trim());
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.rusefi.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Output {
|
||||
void write(String line);
|
||||
|
||||
void close() throws IOException;
|
||||
}
|
Loading…
Reference in New Issue