Removed the double foldering and started some seriouse work.

This commit is contained in:
Speiger 2020-11-11 21:33:59 +01:00
parent 51f447b0d1
commit 7903343ac0
30 changed files with 132 additions and 77 deletions

View File

@ -1,5 +0,0 @@
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build

View File

@ -1 +0,0 @@
List=81eefe88c5fd5080b139b1b85e11f85d

View File

@ -1,11 +0,0 @@
package speiger.src.collections.example;
import java.util.List;
public interface LISTKEY_GENERIC_TYPE extends List<CLASS_TYPE>
{
#if !OBJECT
public void add(KEY_TYPE e);
#endif
public default boolean add(CLASS_TYPE e) {return true;}
}

View File

@ -1,12 +1,9 @@
package speiger.src.builder.base; package speiger.src.builder.base;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.StringJoiner; import java.util.StringJoiner;
@ -48,27 +45,6 @@ public class Template
return result; return result;
} }
public static void main(String...args)
{
try
{
Path path = new File("./src/main/resources/speiger/assets/collections/templates/List.template").toPath();
Template template = parse(path);
Set<String> parsePool = new HashSet<>();
parsePool.add("DEPEND");
parsePool.add("SUB_TEST");
parsePool.add("TEST_0");
parsePool.add("TEST_1");
parsePool.add("TEST_2");
System.out.println(path.getFileName().toString());
System.out.println(template.build(parsePool, Collections.emptyList()));
}
catch(IOException e)
{
e.printStackTrace();
}
}
public static Template parse(Path file) throws IOException public static Template parse(Path file) throws IOException
{ {
List<ConditionedSegment> segments = new ArrayList<ConditionedSegment>(); List<ConditionedSegment> segments = new ArrayList<ConditionedSegment>();

View File

@ -0,0 +1,44 @@
package speiger.src.builder.example;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
import speiger.src.builder.mappers.SimpleMapper;
import speiger.src.builder.processor.TemplateProcess;
public class GlobalVariables
{
String fileName;
String folderName;
List<UnaryOperator<String>> operators = new ArrayList<>();
Set<String> flags = new LinkedHashSet<>();
public GlobalVariables(String fileName, String folderName)
{
this.fileName = fileName;
this.folderName = folderName;
}
public GlobalVariables createInitials(String classType, String keyType)
{
operators.add(new SimpleMapper("CLASS_TYPE", classType));
operators.add(new SimpleMapper("KEY_TYPE", keyType));
return this;
}
public GlobalVariables createClassTypes(String fileType)
{
operators.add(new SimpleMapper("CONSUMER", fileType+"Consumer"));
return this;
}
public TemplateProcess create(String fileName)
{
// TemplateProcess process = new TemplateProcess(entry.getKey()+name+".java", Paths.get(""));
return null;
}
}

View File

@ -4,20 +4,23 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import speiger.src.builder.mappers.InjectMapper;
import speiger.src.builder.mappers.SimpleMapper; import speiger.src.builder.mappers.SimpleMapper;
import speiger.src.builder.processor.TemplateProcess; import speiger.src.builder.processor.TemplateProcess;
import speiger.src.builder.processor.TemplateProcessor; import speiger.src.builder.processor.TemplateProcessor;
public class TestBuilder extends TemplateProcessor public class TestBuilder extends TemplateProcessor
{ {
Map<String, List<UnaryOperator<String>>> data; public static final String[] KEY_TYPE = new String[]{"byte", "short", "int", "long", "float", "double", "T"};
public static final String[] CLASS_TYPE = new String[]{"Byte", "Short", "Integer", "Long", "Float", "Double", "Object"};
public static final String[] FILE_TYPE = new String[]{"Byte", "Short", "Int", "Long", "Float", "Double", "Object"};
List<GlobalVariables> varibles = new ArrayList<GlobalVariables>();
public TestBuilder() public TestBuilder()
{ {
@ -31,25 +34,33 @@ public class TestBuilder extends TemplateProcessor
} }
@Override @Override
protected void init() protected boolean relativePackages()
{ {
data = new LinkedHashMap<>(); return true;
data.put("Byte", createForType("byte", "Byte", "Byte"));
data.put("Short", createForType("short", "Short", "Short"));
data.put("Int", createForType("int", "Integer", "Int"));
data.put("Long", createForType("long", "Long", "Long"));
data.put("Float", createForType("float", "Float", "Float"));
data.put("Double", createForType("double", "Double", "Double"));
data.put("Object", createForType("Object", "T", "Object"));
} }
private List<UnaryOperator<String>> createForType(String lowercase, String upperCase, String classType) @Override
protected void init()
{ {
varibles.clear();
for(int i = 0,m=KEY_TYPE.length;i<m;i++)
{
GlobalVariables type = new GlobalVariables(FILE_TYPE[i]);
type.createInitials(CLASS_TYPE[i], KEY_TYPE[i]);
type.createClassTypes(FILE_TYPE[i]);
varibles.add(type);
}
}
private List<UnaryOperator<String>> createForType(String lowercase, String upperCase, String classType, String consumer)
{
Files
List<UnaryOperator<String>> list = new ArrayList<>(); List<UnaryOperator<String>> list = new ArrayList<>();
list.add(new SimpleMapper("LIST", classType+"List")); list.add(new SimpleMapper("JAVA_CONSUMER", "java.util.function."+consumer));
list.add(new SimpleMapper("CONSUMER", classType+"Consumer"));
list.add(new SimpleMapper("CLASS_TYPE", upperCase)); list.add(new SimpleMapper("CLASS_TYPE", upperCase));
list.add(new SimpleMapper("KEY_TYPE", lowercase)); list.add(new SimpleMapper("KEY_TYPE", lowercase));
list.add(new SimpleMapper("KEY_GENERIC_TYPE", "<T>")); list.add(new InjectMapper("OBJ_TO_KEY(\\([^)]+\\)|\\S)", "%s."+lowercase+"Value()").removeBraces());
return list; return list;
} }
@ -60,27 +71,31 @@ public class TestBuilder extends TemplateProcessor
{ {
TemplateProcess process = new TemplateProcess(entry.getKey()+name+".java", Paths.get("")); TemplateProcess process = new TemplateProcess(entry.getKey()+name+".java", Paths.get(""));
process.addMappers(entry.getValue()); process.addMappers(entry.getValue());
if(entry.getKey().equals("Object"))
{
process.addFlags("OBJECT");
}
acceptor.accept(process); acceptor.accept(process);
} }
} }
public static void main(String...args) public static void main(String...args)
{ {
try Path path = Paths.get("").toAbsolutePath();
System.out.println(path.toString());
for(int i = 0,m=path.getNameCount();i<m;i++)
{ {
new TestBuilder().process(true); System.out.println(path.getName(i).toString());
}
catch(InterruptedException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
} }
// try
// {
// new TestBuilder().process(true);
// }
// catch(InterruptedException e)
// {
// e.printStackTrace();
// }
// catch(IOException e)
// {
// e.printStackTrace();
// }
} }
} }

View File

@ -15,7 +15,6 @@ public class BuildTask implements Runnable
public BuildTask(Path basePath, Template template, TemplateProcess process) public BuildTask(Path basePath, Template template, TemplateProcess process)
{ {
super();
this.basePath = basePath; this.basePath = basePath;
this.template = template; this.template = template;
this.process = process; this.process = process;
@ -26,6 +25,13 @@ public class BuildTask implements Runnable
{ {
String s = template.build(process.parsePool, process.mappers); String s = template.build(process.parsePool, process.mappers);
Path path = basePath.resolve(process.path).resolve(process.fileName); Path path = basePath.resolve(process.path).resolve(process.fileName);
try
{
Files.createDirectories(path.getParent());
}
catch(Exception e)
{
}
try(BufferedWriter writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE, StandardOpenOption.SYNC)) try(BufferedWriter writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE, StandardOpenOption.SYNC))
{ {
writer.write(s); writer.write(s);

View File

@ -1,6 +1,5 @@
package speiger.src.builder.processor; package speiger.src.builder.processor;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -11,15 +10,14 @@ import java.util.function.UnaryOperator;
public class TemplateProcess public class TemplateProcess
{ {
Path path; UnaryOperator pathBuilder;
String fileName; String fileName;
Set<String> parsePool = new HashSet<>(); Set<String> parsePool = new HashSet<>();
List<UnaryOperator<String>> mappers = new ArrayList<>(); List<UnaryOperator<String>> mappers = new ArrayList<>();
public TemplateProcess(String fileName, Path path) public TemplateProcess(String fileName)
{ {
this.fileName = fileName; this.fileName = fileName;
this.path = path;
} }
public void addFlags(String...flags) public void addFlags(String...flags)

View File

@ -19,13 +19,14 @@ public abstract class TemplateProcessor
Path sourceFolder; Path sourceFolder;
Path outputFolder; Path outputFolder;
Path dataFolder; Path dataFolder;
boolean init = false;
public TemplateProcessor(Path sourceFolder, Path outputFolder, Path dataFolder) public TemplateProcessor(Path sourceFolder, Path outputFolder, Path dataFolder)
{ {
this.sourceFolder = sourceFolder; this.sourceFolder = sourceFolder;
this.outputFolder = outputFolder; this.outputFolder = outputFolder;
this.dataFolder = dataFolder; this.dataFolder = dataFolder;
init();
} }
protected abstract void init(); protected abstract void init();
@ -34,8 +35,15 @@ public abstract class TemplateProcessor
public abstract void createProcesses(String fileName, Consumer<TemplateProcess> process); public abstract void createProcesses(String fileName, Consumer<TemplateProcess> process);
protected abstract boolean relativePackages();
public boolean process(boolean force) throws IOException, InterruptedException public boolean process(boolean force) throws IOException, InterruptedException
{ {
if(!init)
{
init = true;
init();
}
Map<String, String> existing = FileUtils.loadMappings(dataFolder); Map<String, String> existing = FileUtils.loadMappings(dataFolder);
List<Path> pathsLeft = Files.walk(sourceFolder).filter(Files::isRegularFile).filter(T -> isFileValid(T.getFileName())).filter(T -> force || FileUtils.isValid(T, existing)).collect(Collectors.toList()); List<Path> pathsLeft = Files.walk(sourceFolder).filter(Files::isRegularFile).filter(T -> isFileValid(T.getFileName())).filter(T -> force || FileUtils.isValid(T, existing)).collect(Collectors.toList());
if(pathsLeft.isEmpty() && !force) if(pathsLeft.isEmpty() && !force)
@ -43,6 +51,7 @@ public abstract class TemplateProcessor
System.out.println("Nothing has changed"); System.out.println("Nothing has changed");
return false; return false;
} }
final boolean relative = relativePackages();
ThreadPoolExecutor service = (ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); ThreadPoolExecutor service = (ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
service.setKeepAliveTime(10, TimeUnit.MILLISECONDS); service.setKeepAliveTime(10, TimeUnit.MILLISECONDS);
service.allowCoreThreadTimeOut(true); service.allowCoreThreadTimeOut(true);
@ -53,7 +62,7 @@ public abstract class TemplateProcessor
try try
{ {
Template template = Template.parse(path); Template template = Template.parse(path);
createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(outputFolder, template, T))); createProcesses(FileUtils.getFileName(path), T -> service.execute(new BuildTask(relative ? outputFolder.resolve(sourceFolder.relativize(path).getParent()) : outputFolder, template, T)));
} }
catch(Exception e) catch(Exception e)
{ {

View File

@ -0,0 +1,2 @@
List=8346cdbb0624aa07f1c54d00f765cbd5
Consumer=e0112061d850a9ea6049cfe6571e2750

View File

@ -0,0 +1,22 @@
package speiger.src.collections.example.functions;
import java.util.Objects;
import java.util.function.Consumer;
public interface CONSUMER extends Consumer<CLASS_TYPE>, JAVA_CONSUMER
{
void accept(KEY_TYPE t);
default void accept(CLASS_TYPE t) { accept(OBJ_TO_KEY(t)); }
@Override
default CONSUMER andThen(Consumer<? super CLASS_TYPE> after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(T);};
}
default CONSUMER andThen(CONSUMER after) {
Objects.requireNonNull(after);
return T -> {accept(T); after.accept(T);};
}
}