Prevent that YaCy always starts with a exception message on none Apple systems

Perform try to access com.apple.eio.FileManager  only on none Win systems
pull/442/head
reger24 2 years ago
parent 102277e946
commit 398b105781

@ -721,22 +721,23 @@ public final class yacy {
// try to find the application root path within a Mac application // try to find the application root path within a Mac application
// call com.apple.eio.FileManager.getPathToApplicationBundle(); // call com.apple.eio.FileManager.getPathToApplicationBundle();
try { if (!OS.isWindows) { // prevent that YaCy always starts with an exception message on none Apple systems
// these methods will cause a warning: remove them with --illegal-access=permit try {
final Class<?> comAppleEioFileManagerClass = Class.forName("com.apple.eio.FileManager"); // these methods will cause a warning: remove them with --illegal-access=permit
final Method getPathToApplicationBundleMethod = ClassProvider.getStaticMethod(comAppleEioFileManagerClass, "getPathToApplicationBundle", null); final Class<?> comAppleEioFileManagerClass = Class.forName("com.apple.eio.FileManager");
final String apppath = (String) getPathToApplicationBundleMethod.invoke(null); final Method getPathToApplicationBundleMethod = ClassProvider.getStaticMethod(comAppleEioFileManagerClass, "getPathToApplicationBundle", null);
System.out.println("PathToApplicationBundle = " + apppath); // PathToApplicationBundle = /Users/admin/git/rc1/build/YaCy.app final String apppath = (String) getPathToApplicationBundleMethod.invoke(null);
if (apppath != null && apppath.endsWith(".app")) { System.out.println("PathToApplicationBundle = " + apppath); // PathToApplicationBundle = /Users/admin/git/rc1/build/YaCy.app
// modify the applicationRoot path to within the app file if (apppath != null && apppath.endsWith(".app")) {
applicationRoot = new File(apppath + "/Contents"); // modify the applicationRoot path to within the app file
System.setProperty("user.dir", applicationRoot.getAbsolutePath()); // required since nasty code elswhere is using it applicationRoot = new File(apppath + "/Contents");
System.setProperty("user.home", applicationRoot.getAbsolutePath()); // well System.setProperty("user.dir", applicationRoot.getAbsolutePath()); // required since nasty code elswhere is using it
System.setProperty("user.home", applicationRoot.getAbsolutePath()); // well
}
} catch (ClassNotFoundException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
e.printStackTrace();
} }
} catch (ClassNotFoundException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
e.printStackTrace();
} }
File dataRoot = applicationRoot; File dataRoot = applicationRoot;
//System.out.println("args.length=" + args.length); //System.out.println("args.length=" + args.length);
//System.out.print("args=["); for (int i = 0; i < args.length; i++) System.out.print(args[i] + ", "); System.out.println("]"); //System.out.print("args=["); for (int i = 0; i < args.length; i++) System.out.print(args[i] + ", "); System.out.println("]");

Loading…
Cancel
Save