DEADSOFTWARE

Добавлена возможножность вызова команд
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sat, 16 Sep 2017 13:51:55 +0000 (16:51 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Sat, 16 Sep 2017 13:51:55 +0000 (16:51 +0300)
rtl/Oberon.obn
rtl/java/Launcher.java

index 3316b850ea9e30bfd4b0c82eac8f77994fb0a1b3..37067d702e8879834e09136b304f7f894bd20920 100644 (file)
@@ -29,7 +29,6 @@ BEGIN
   i := 1;
   WHILE i < Args.count DO
     Args.GetArg(i, str); Texts.WriteString(W, str); Texts.Write(W, " ");
-    Out.String("Param "); Out.Int(i, 0); Out.Char(" "); Out.String(str); Out.Ln;
     INC(i)
   END;
   Texts.Append(Par.text, W.buf);
index a49e32840ddb95efb76a6b743cd5b44de52d8328..3135732199c7bc03e68d3aae44dd41407cb6b277 100644 (file)
@@ -3,16 +3,85 @@ import java.lang.reflect.*;
 class Launcher
 {
        public static void main(String[] args)
-               throws
-                       ClassNotFoundException,
-                       InstantiationException,
-                       IllegalAccessException,
-                       NoSuchMethodException,
-                       InvocationTargetException
        {
+               /* Этап 1: Сохраняем список параметров */
                Args.args = args;
-               Class<?> module = Class.forName(args[0]);
-               Method begin = module.getMethod("BEGIN");
-               begin.invoke(null);
+
+               /* Этап 2: Получаем имена связки Модуль.Команда */
+               if(args == null || args.length < 1)
+               {
+                       System.err.println("uses: Launcher Module[.Command] {Argumets}");
+                       System.exit(1);
+               }
+
+               String moduleName = args[0];
+               String commandName = "";
+               int i = args[0].indexOf('.');
+               if(i >= 0)
+               {
+                       moduleName = args[0].substring(0, i);
+                       commandName = args[0].substring(i + 1);
+                       if(commandName == "BEGIN")
+                       {
+                               commandName = "";
+                       }
+               }
+
+               /* Этап 3: Выполнение тела модуля и команды */
+               Class<?> module = null;
+               Method begin = null;
+               Method command = null;
+
+               try {
+                       module = Class.forName(moduleName);
+               } catch(ClassNotFoundException e) {
+                       System.err.println("Module " + moduleName + " not found");
+                       System.exit(1);                 
+               }
+
+               try {
+                       begin = module.getMethod("BEGIN");
+               } catch(Exception e) {
+                       System.err.println("Invalid module " + moduleName);
+                       System.exit(1);
+               }
+
+               try {
+                       begin.invoke(null);
+               } catch(IllegalAccessException e) {
+                       System.err.println("Invalid module " + moduleName);
+                       System.exit(1);
+               } catch(IllegalArgumentException e) {
+                       System.err.println("Invalid module " + moduleName);
+                       System.exit(1);                 
+               } catch(InvocationTargetException e) {
+                       System.err.println("Invalid module " + moduleName);
+                       System.exit(1);
+               }
+
+               if(commandName == "")
+               {
+                       return;
+               }
+
+               try {
+                       command = module.getMethod(commandName);
+               } catch(Exception e) {
+                       System.err.println("Invalid command " + moduleName + "." + commandName);
+                       System.exit(1);
+               }
+
+               try {
+                       command.invoke(null);
+               } catch(IllegalAccessException e) {
+                       System.err.println("Invalid command " + moduleName + "." + commandName);
+                       System.exit(1);
+               } catch(IllegalArgumentException e) {
+                       System.err.println("Invalid command " + moduleName + "." + commandName);
+                       System.exit(1);
+               } catch(InvocationTargetException e) {
+                       System.err.println("Invalid command " + moduleName + "." + commandName);
+                       System.exit(1);
+               }
        }
 }