diff --git a/generator/build.gradle b/generator/build.gradle index 916787f..25f6dbe 100644 --- a/generator/build.gradle +++ b/generator/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'application' } version '0.1' @@ -9,3 +10,14 @@ sourceCompatibility = 1.8 repositories { mavenCentral() } + +task('gen_tl', dependsOn: jar, type: JavaExec) { + main = "io.github.lonamiwebs.overgram.Overgram" + classpath = sourceSets.main.runtimeClasspath + // TODO Learn gradle and do this properly + setArgs([ + '../lib/src/main/java/io/github/lonamiwebs/overgram/tl/', + 'src/main/resources/mtproto_api.tl', + 'src/main/resources/telegram_api.tl' + ]) +} diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/Overgram.java b/generator/src/main/java/io/github/lonamiwebs/overgram/Overgram.java index d340186..593664b 100644 --- a/generator/src/main/java/io/github/lonamiwebs/overgram/Overgram.java +++ b/generator/src/main/java/io/github/lonamiwebs/overgram/Overgram.java @@ -6,21 +6,24 @@ import io.github.lonamiwebs.overgram.parser.TLReader; import java.io.File; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; public class Overgram { - public static void main(final String... args) { - final Map> objects = TLReader.readTlObjects(new File("telegram_api.tl")); - try { - Generator.generateJava( - objects.get("types"), - objects.get("functions"), - new File("Abstract.java"), - new File("Types.java"), - new File("Functions.java") - ); - } catch (IOException ignored) { + public static void main(final String... args) throws IOException { + final Map> objects = new HashMap<>(); + for (int i = 1; i < args.length; ++i) { + TLReader.readTlObjects(objects, new File(args[i])); } + + final File parent = new File(args[0]); + Generator.generateJava( + objects.get("types"), + objects.get("functions"), + new File(parent, "Abstract.java"), + new File(parent, "Types.java"), + new File(parent, "Functions.java") + ); } } diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/parser/TLReader.java b/generator/src/main/java/io/github/lonamiwebs/overgram/parser/TLReader.java index 88dc59d..734f169 100644 --- a/generator/src/main/java/io/github/lonamiwebs/overgram/parser/TLReader.java +++ b/generator/src/main/java/io/github/lonamiwebs/overgram/parser/TLReader.java @@ -12,8 +12,7 @@ import java.util.Map; public class TLReader { - public static final Map> readTlObjects(final File file) { - final Map> result = new HashMap<>(); + public static void readTlObjects(final Map> result, final File file) { for (final Map.Entry> entry : readTl(file).entrySet()) { final List objects = new ArrayList<>(); for (final String string : entry.getValue()) { @@ -21,7 +20,6 @@ public class TLReader { } result.put(entry.getKey(), objects); } - return result; } private static Map> readTl(final File file) { diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/tl/TLObject.java b/lib/src/main/java/io/github/lonamiwebs/overgram/tl/TLObject.java similarity index 100% rename from generator/src/main/java/io/github/lonamiwebs/overgram/tl/TLObject.java rename to lib/src/main/java/io/github/lonamiwebs/overgram/tl/TLObject.java diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/tl/TLRequest.java b/lib/src/main/java/io/github/lonamiwebs/overgram/tl/TLRequest.java similarity index 100% rename from generator/src/main/java/io/github/lonamiwebs/overgram/tl/TLRequest.java rename to lib/src/main/java/io/github/lonamiwebs/overgram/tl/TLRequest.java diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryReader.java b/lib/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryReader.java similarity index 100% rename from generator/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryReader.java rename to lib/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryReader.java diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryWriter.java b/lib/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryWriter.java similarity index 100% rename from generator/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryWriter.java rename to lib/src/main/java/io/github/lonamiwebs/overgram/utils/BinaryWriter.java diff --git a/generator/src/main/java/io/github/lonamiwebs/overgram/utils/CharacterIterator.java b/lib/src/main/java/io/github/lonamiwebs/overgram/utils/CharacterIterator.java similarity index 100% rename from generator/src/main/java/io/github/lonamiwebs/overgram/utils/CharacterIterator.java rename to lib/src/main/java/io/github/lonamiwebs/overgram/utils/CharacterIterator.java