diff --git a/android_java/__init__.py b/android_java/__init__.py index 97ee4a6..fecbb66 100644 --- a/android_java/__init__.py +++ b/android_java/__init__.py @@ -1,12 +1,18 @@ import argparse +import os + +from android_java.compile import CompilerStage +from android_java.execute import ExecutionStatge def do_compile(args): - pass + stage = CompilerStage(os.getcwd()) + stage.compile(args.source_file) def do_run(args): - pass + stage = ExecutionStatge(os.getcwd()) + stage.execute_main_class(args.main_class) def main(): @@ -14,15 +20,18 @@ def main(): subparsers: argparse._SubParsersAction = parser.add_subparsers(dest="mode") compile_parser = subparsers.add_parser("compile", help="Compile source file") compile_parser.add_argument( - "SourceFile.java", help="The source file to compile/create dex for" + "SourceFile.java", + dest="source_file", + help="The source file to compile/create dex for", ) - java_parser = subparsers.add_parser( + run_parser = subparsers.add_parser( "run", help="Run main method of class. Ensure you are in the same directory as the source file", ) - java_parser.add_argument("MainClass", help="The class to run.") + run_parser.add_argument("MainClass", help="The class to run.", dest="main_class") args = parser.parse_args() + if args.mode == "compile": do_compile(args) elif args.mode == "run": diff --git a/android_java/compile.py b/android_java/compile.py index 408e438..a3d8d45 100644 --- a/android_java/compile.py +++ b/android_java/compile.py @@ -1,19 +1,13 @@ import os import subprocess -os.mkdir +from android_java.stage import Stage -def make_droid_dir(root): - droid_dir = os.path.join(root, ".droid") - os.makedirs(droid_dir, exist_ok=True) - return droid_dir - - -class CompilerStage: +class CompilerStage(Stage): def __init__(self, source_root): - self.source_root = source_root - self.droid_dir = make_droid_dir(source_root) + super().__init__(source_root) + self.make_droid_dir() def create_ecj_command(self): cmdline = ["ecj"] diff --git a/android_java/execute.py b/android_java/execute.py index 324ccf1..8cbf484 100644 --- a/android_java/execute.py +++ b/android_java/execute.py @@ -1,13 +1,11 @@ import os import subprocess -from android_java.exceptions import NoClassesFoundError +from android_java.exceptions import NoClassesFoundError +from android_java.stage import Stage -class ExecutionStatge: - def __init__(self, source_root): - self.source_root = source_root - self.droid_dir = os.path.join(source_root, ".droid") +class ExecutionStatge(Stage): def execute_main_class(self, classname): classes_dex_file = os.path.join(self.droid_dir, "classes.dex") if not os.path.exists(classes_dex_file): diff --git a/android_java/stage.py b/android_java/stage.py new file mode 100644 index 0000000..1d5680f --- /dev/null +++ b/android_java/stage.py @@ -0,0 +1,10 @@ +import os + + +class Stage: + def __init__(self, source_root): + self.source_root = source_root + self.droid_dir = os.path.join(self.source_root, ".droid") + + def make_droid_dir(self): + os.makedirs(self.droid_dir, exist_ok=True)