Added Iteration support.
Said support allows to use the #iterate & #argument #enditerate parameters. Which will duplicate the text block inside of it x amount of times with arguments being replaced. The idea being that if code can be replicated the iterate option would simplify the process. Multiple arguments can be defined (they will be not part of the output) and it will simply insert them. Note that all argument parameters have to be equal size. Otherwise the iterator processor will fail. Iterators can be stacked too to create layers upon layers. On top of that the iterator is part of the Template parser and not of the template processor meaning its a Pre processor step. And all mappers still apply themselves on to the output of the iterators!
This commit is contained in:
parent
d90a9ad71c
commit
d5a47ce568
|
@ -1,2 +1,13 @@
|
||||||
|
arguments=
|
||||||
|
auto.sync=false
|
||||||
|
build.scans.enabled=false
|
||||||
|
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||||
connection.project.dir=
|
connection.project.dir=
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
|
gradle.user.home=
|
||||||
|
java.home=
|
||||||
|
jvm.arguments=
|
||||||
|
offline.mode=false
|
||||||
|
override.workspace.settings=false
|
||||||
|
show.console.view=false
|
||||||
|
show.executions.view=false
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
108
build.gradle
108
build.gradle
|
@ -1,55 +1,55 @@
|
||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Simple Code Generator'
|
archivesBaseName = 'Simple Code Generator'
|
||||||
version = '1.2.2'
|
version = '1.3.0'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding = 'UTF-8'
|
options.encoding = 'UTF-8'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
task srcJar(type: Jar) {
|
task srcJar(type: Jar) {
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
archives srcJar
|
archives srcJar
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadArchives {
|
uploadArchives {
|
||||||
repositories.mavenDeployer {
|
repositories.mavenDeployer {
|
||||||
repository(url: 'https://maven.speiger.com/repository/main') {
|
repository(url: 'https://maven.speiger.com/repository/main') {
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
||||||
}
|
}
|
||||||
snapshotRepository(url: 'https://maven.speiger.com/repository/main') {
|
snapshotRepository(url: 'https://maven.speiger.com/repository/main') {
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
||||||
}
|
}
|
||||||
pom {
|
pom {
|
||||||
version = project.version
|
version = project.version
|
||||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||||
groupId = 'de.speiger'
|
groupId = 'de.speiger'
|
||||||
project {
|
project {
|
||||||
licenses {
|
licenses {
|
||||||
license {
|
license {
|
||||||
name = 'The Apache License, Version 2.0'
|
name = 'The Apache License, Version 2.0'
|
||||||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
developers {
|
developers {
|
||||||
developer {
|
developer {
|
||||||
id = 'speiger'
|
id = 'speiger'
|
||||||
name = 'Speiger'
|
name = 'Speiger'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
test=e949777578333aa849d74d6a2c651236
|
test=ddb9367ebd61888ab31a658dd6f6df86
|
||||||
|
|
|
@ -20,4 +20,34 @@ TESTING should not be overriden
|
||||||
#endignore
|
#endignore
|
||||||
|
|
||||||
TESTING should not be overriden
|
TESTING should not be overriden
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#iterate
|
||||||
|
#argument NUMBER 1 2 3 4 5 6 7 8 9
|
||||||
|
Lets test number NUMBER
|
||||||
|
#enditerate
|
||||||
|
|
||||||
|
#if TEST0
|
||||||
|
Lets test a true condition.
|
||||||
|
#iterate
|
||||||
|
#argument NUMBER 1 2 3 4 5 6 7 8 9
|
||||||
|
Lets test number NUMBER
|
||||||
|
#enditerate
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TEST1
|
||||||
|
Lets test a false condition.
|
||||||
|
#iterate
|
||||||
|
#argument NUMBER 1 2 3 4 5 6 7 8 9
|
||||||
|
Lets test number NUMBER
|
||||||
|
#enditerate
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Lets test stacked iterators
|
||||||
|
#iterate
|
||||||
|
#argument NUMBER1 1 2 3
|
||||||
|
#iterate
|
||||||
|
#argument NUMBER2 4 5 6
|
||||||
|
Lets test numbers NUMBER1 NUMBER2
|
||||||
|
#enditerate
|
||||||
|
#enditerate
|
|
@ -5,4 +5,37 @@ TESTING should not be overriden
|
||||||
Test2 should be overriden
|
Test2 should be overriden
|
||||||
TESTING should not be overriden too
|
TESTING should not be overriden too
|
||||||
|
|
||||||
Test2 should be overriden too
|
Test2 should be overriden too
|
||||||
|
|
||||||
|
Lets test number 1
|
||||||
|
Lets test number 2
|
||||||
|
Lets test number 3
|
||||||
|
Lets test number 4
|
||||||
|
Lets test number 5
|
||||||
|
Lets test number 6
|
||||||
|
Lets test number 7
|
||||||
|
Lets test number 8
|
||||||
|
Lets test number 9
|
||||||
|
|
||||||
|
Lets test a true condition.
|
||||||
|
Lets test number 1
|
||||||
|
Lets test number 2
|
||||||
|
Lets test number 3
|
||||||
|
Lets test number 4
|
||||||
|
Lets test number 5
|
||||||
|
Lets test number 6
|
||||||
|
Lets test number 7
|
||||||
|
Lets test number 8
|
||||||
|
Lets test number 9
|
||||||
|
|
||||||
|
|
||||||
|
Lets test stacked iterators
|
||||||
|
Lets test numbers 1 4
|
||||||
|
Lets test numbers 1 5
|
||||||
|
Lets test numbers 1 6
|
||||||
|
Lets test numbers 2 4
|
||||||
|
Lets test numbers 2 5
|
||||||
|
Lets test numbers 2 6
|
||||||
|
Lets test numbers 3 4
|
||||||
|
Lets test numbers 3 5
|
||||||
|
Lets test numbers 3 6
|
|
@ -97,6 +97,10 @@ public class ConditionedSegment
|
||||||
i += parse(fileName, null, lines, i, segmentText.length(), ignoreCounter, childSegments, postSegments);
|
i += parse(fileName, null, lines, i, segmentText.length(), ignoreCounter, childSegments, postSegments);
|
||||||
segmentText.add(lines.get(prev));
|
segmentText.add(lines.get(prev));
|
||||||
}
|
}
|
||||||
|
else if(trimmed.startsWith("#iterate")) {
|
||||||
|
SegmentIterator.iterateSegment(fileName, trimmed, lines, i, segmentText.length());
|
||||||
|
i--;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
segmentText.add(s);
|
segmentText.add(s);
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package speiger.src.builder.base;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SegmentIterator {
|
||||||
|
public static void iterateSegment(String fileName, String currentLine, List<String> lines, int currentIndex, int startIndex) {
|
||||||
|
List<String[]> arguments = new ArrayList<>();
|
||||||
|
StringJoiner toIterate = new StringJoiner("\n");
|
||||||
|
int skip = 0;
|
||||||
|
int end = 1;
|
||||||
|
for(int i = currentIndex+1;i<lines.size();i++, end++)
|
||||||
|
{
|
||||||
|
String s = lines.get(i);
|
||||||
|
String trimmed = s.trim();
|
||||||
|
if(trimmed.startsWith("#"))
|
||||||
|
{
|
||||||
|
if(trimmed.startsWith("#enditerate"))
|
||||||
|
{
|
||||||
|
skip--;
|
||||||
|
if(skip < 0)
|
||||||
|
{
|
||||||
|
end++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(trimmed.startsWith("#iterate")) skip++;
|
||||||
|
if(skip > 0)
|
||||||
|
{
|
||||||
|
toIterate.add(s);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(trimmed.startsWith("#argument"))
|
||||||
|
{
|
||||||
|
arguments.add(trimmed.substring(9).trim().split(" "));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toIterate.add(s);
|
||||||
|
}
|
||||||
|
int size = arguments.get(0).length;
|
||||||
|
for(int i = 1,m=arguments.size();i<m;i++) {
|
||||||
|
if(arguments.get(i).length != size) throw new RuntimeException("Iteration arguments in file ["+fileName+"] are not equal size. Arugments="+arguments.stream().flatMap(Arrays::stream).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
for(int i = 0;i<end;i++) {
|
||||||
|
lines.remove(currentIndex);
|
||||||
|
}
|
||||||
|
String toInsert = toIterate.toString();
|
||||||
|
for(int i = size-1;i>=1;i--) {
|
||||||
|
String temp = toInsert;
|
||||||
|
for(int j = 0;j<arguments.size();j++) {
|
||||||
|
String[] argument = arguments.get(j);
|
||||||
|
temp = temp.replace(argument[0], argument[i]);
|
||||||
|
}
|
||||||
|
lines.addAll(currentIndex, Arrays.asList(temp.split("\n", -1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -92,6 +92,11 @@ public class Template
|
||||||
joiner.add(lines.get(prev));
|
joiner.add(lines.get(prev));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
else if(trimmed.startsWith("#iterate")) {
|
||||||
|
SegmentIterator.iterateSegment(fileName, trimmed, lines, i, joiner.length());
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
else if(trimmed.startsWith("#symlink"))
|
else if(trimmed.startsWith("#symlink"))
|
||||||
{
|
{
|
||||||
return Template.parse(file.getParent().resolve(trimmed.substring(8).trim()));
|
return Template.parse(file.getParent().resolve(trimmed.substring(8).trim()));
|
||||||
|
|
|
@ -33,7 +33,7 @@ public interface ICondition
|
||||||
if(activeAnd != null) continue;
|
if(activeAnd != null) continue;
|
||||||
if(i != 0) {
|
if(i != 0) {
|
||||||
ICondition prev = conditions.get(conditions.size()-1);
|
ICondition prev = conditions.get(conditions.size()-1);
|
||||||
if(prev instanceof AndCondition) activeAnd = (AndCondition)prev;
|
if(prev instanceof AndCondition) activeAnd = (AndCondition)prev;
|
||||||
else {
|
else {
|
||||||
activeAnd = new AndCondition(prev);
|
activeAnd = new AndCondition(prev);
|
||||||
conditions.set(conditions.size()-1, activeAnd);
|
conditions.set(conditions.size()-1, activeAnd);
|
||||||
|
|
|
@ -96,6 +96,7 @@ public abstract class TemplateProcessor
|
||||||
protected Path getDataFolder() { return dataFolder; }
|
protected Path getDataFolder() { return dataFolder; }
|
||||||
protected boolean isSilencedSuccess() { return silencedSuccess; }
|
protected boolean isSilencedSuccess() { return silencedSuccess; }
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public final boolean process(boolean force) throws IOException, InterruptedException
|
public final boolean process(boolean force) throws IOException, InterruptedException
|
||||||
{
|
{
|
||||||
if(!init)
|
if(!init)
|
||||||
|
@ -112,7 +113,7 @@ public abstract class TemplateProcessor
|
||||||
}
|
}
|
||||||
AtomicLong[] counters = new AtomicLong[]{new AtomicLong(), new AtomicLong(), new AtomicLong()};
|
AtomicLong[] counters = new AtomicLong[]{new AtomicLong(), new AtomicLong(), new AtomicLong()};
|
||||||
final boolean relative = relativePackages();
|
final boolean relative = relativePackages();
|
||||||
Set<IMapper>[] mappers = debugUnusedMappers() ? new Set[]{Collections.synchronizedSet(new HashSet<IMapper>()), Collections.synchronizedSet(new HashSet<IMapper>())} : null;
|
Set<IMapper>[] mappers = debugUnusedMappers() ? new Set[]{Collections.synchronizedSet(new HashSet<>()), Collections.synchronizedSet(new HashSet<>())} : null;
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue