org.geneweaver.query.ui.Main Maven / Gradle / Ivy
package org.geneweaver.query.ui;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.geneweaver.query.cli.CLI;
public class Main {
public static void main(String[] args) throws Throwable {
if (args==null || args.length<1) {
System.out.println("Use the '-UI' switch to open a GUI");
}
if (isUI(args)) {
doUI();
} else {
doCLI(args);
}
}
private static void doCLI(String[] args) throws Exception {
CLI.main(args);
}
private static boolean isUI(String[] args) {
for (String arg : args) {
arg = arg.toLowerCase();
if (arg.equals("-ui")) return true;
if (arg.equals("--userinterface")) return true;
}
return false;
}
private static void doUI() throws Throwable {
// On MacOC Aarch there is a bug that the swt library
// does not get copied in. So we try to do it now.
// This will likely get fixed in later eclipse versions.
// If you want to run this app as a developer run in nondev mode
// to copy the files in or use the files in src/main/resources/aarch64
// by copying them to ~/.swt/lib/macosx/aarch64/
String osname = System.getProperty("os.name"); // e.g. Mac OS X
String osarch = System.getProperty("os.arch"); // e.g. aarch64
if (osname.toLowerCase().contains("mac") && osarch.toLowerCase().contains("aarch")) {
// Manually copy library
// These names come with SWT 3.121.0
String[] paths = new String[] { "aarch64/libswt-awt-cocoa-4954r7.jnilib",
"aarch64/libswt-cocoa-4954r7.jnilib",
"aarch64/libswt-pi-cocoa-4954r7.jnilib"
};
String uhome = System.getProperty("user.home");
copy(paths, Paths.get(uhome+"/.swt/lib/macosx/aarch64/"));
}
org.geneweaver.query.ui.QueryEngineEntry.open();
}
private static void copy(String[] paths, Path dir) {
try {
dir.toFile().mkdirs();
for (String subpath : paths) {
String name = Paths.get(subpath).getFileName().toString();
Path to = dir.toAbsolutePath().resolve(name);
if (!Files.exists(to)) {
try (InputStream in = Main.class.getResourceAsStream("/"+subpath)) {
System.out.println("Copying "+name+" to "+to.toAbsolutePath());
Files.copy(in, to.toAbsolutePath());
}
}
}
} catch (Exception ne) {
// We just print it, it maybe will not be fatal if the swt library gets fixed.
ne.printStackTrace();
}
}
}