use of com.jopdesign.common.misc.Cmdline in project jop by jop-devel.
the class MainRunner method main.
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: MainRunner <mainclass> [<options>]");
System.exit(1);
}
final String clsName = args[0].substring(args[0].lastIndexOf(".") + 1);
try {
Class cls = Class.forName(args[0]);
Method main = cls.getMethod("main", new Class[] { String[].class });
Cmdline cmdline = new Cmdline(clsName);
System.out.print("Arguments: " + clsName);
for (int i = 1; i < args.length; i++) {
System.out.print(" " + args[i]);
}
System.out.println();
while (true) {
String[] cmdArgs = cmdline.readInput();
if (cmdline.isExit(cmdArgs)) {
return;
}
List<String> argList = new ArrayList<String>(args.length);
argList.addAll(Arrays.asList(Arrays.copyOfRange(args, 1, args.length)));
argList.addAll(Arrays.asList(cmdArgs));
String[] mainArgs = argList.toArray(new String[argList.size()]);
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
}
@Override
public void checkPermission(Permission perm, Object context) {
}
@Override
public void checkExit(int status) {
throw new SecurityException(clsName + " exited with " + status);
}
});
try {
main.invoke(null, new Object[] { mainArgs });
} catch (Exception e) {
System.err.flush();
if (e.getCause() instanceof SecurityException) {
System.out.println(e.getCause().getMessage());
} else {
e.printStackTrace();
}
} finally {
System.setSecurityManager(null);
}
// cleanup for next invoke
System.out.flush();
System.err.flush();
AppInfo.getSingleton().clear(true);
LogConfig.stopLogger();
}
} catch (ClassNotFoundException e) {
System.out.println("Main class '" + args[0] + "' not found: " + e.getMessage());
System.exit(1);
} catch (NoSuchMethodException e) {
System.out.println("Main method in class '" + args[0] + "' not found: " + e.getMessage());
System.exit(1);
}
}
use of com.jopdesign.common.misc.Cmdline in project jop by jop-devel.
the class JopLookup method main.
public static void main(String[] args) {
File jopFile = null;
if (args.length == 0) {
// try to find it ..
File binDir = new File("java/target/dist/bin");
String[] files = binDir.list();
for (String file : files) {
if (file.endsWith(".jop")) {
jopFile = new File(binDir, file);
}
}
if (jopFile == null) {
usage();
System.exit(1);
} else {
System.out.println("Using link file " + jopFile);
}
} else if (args.length > 1) {
usage();
System.exit(1);
} else if ("--help".equals(args[0]) || "-h".equals(args[0])) {
usage();
System.exit(0);
} else {
jopFile = new File(args[0]);
}
File txtFile = new File(jopFile.toString() + ".txt");
File linkFile = new File(jopFile.toString() + ".link.txt");
if (!jopFile.exists()) {
System.out.println("Jopfile " + jopFile + " does not exist");
System.exit(1);
}
if (!txtFile.exists()) {
System.out.println("Jop-txt-file " + txtFile + " does not exist");
System.exit(1);
}
if (!linkFile.exists()) {
System.out.println("Linkfile " + linkFile + " does not exist");
System.exit(1);
}
readLinkFile(linkFile);
readTxtFile(txtFile);
Cmdline cmdline = new Cmdline();
while (true) {
String[] qArgs = cmdline.readInput();
if (cmdline.isExit(qArgs)) {
return;
}
try {
processQuery(qArgs);
} catch (NumberFormatException e) {
System.out.println("Error: " + e);
e.printStackTrace();
}
}
}
Aggregations