From 398b1057810785bf85991f687bdc2e830debbb5c Mon Sep 17 00:00:00 2001 From: reger24 Date: Tue, 18 Jan 2022 13:02:12 +0100 Subject: [PATCH] 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 --- source/net/yacy/yacy.java | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java index 4ed9b59ce..4ac5990eb 100644 --- a/source/net/yacy/yacy.java +++ b/source/net/yacy/yacy.java @@ -721,22 +721,23 @@ public final class yacy { // try to find the application root path within a Mac application // call com.apple.eio.FileManager.getPathToApplicationBundle(); - try { - // these methods will cause a warning: remove them with --illegal-access=permit - final Class comAppleEioFileManagerClass = Class.forName("com.apple.eio.FileManager"); - final Method getPathToApplicationBundleMethod = ClassProvider.getStaticMethod(comAppleEioFileManagerClass, "getPathToApplicationBundle", null); - final String apppath = (String) getPathToApplicationBundleMethod.invoke(null); - System.out.println("PathToApplicationBundle = " + apppath); // PathToApplicationBundle = /Users/admin/git/rc1/build/YaCy.app - if (apppath != null && apppath.endsWith(".app")) { - // modify the applicationRoot path to within the app file - applicationRoot = new File(apppath + "/Contents"); - System.setProperty("user.dir", applicationRoot.getAbsolutePath()); // required since nasty code elswhere is using it - System.setProperty("user.home", applicationRoot.getAbsolutePath()); // well + if (!OS.isWindows) { // prevent that YaCy always starts with an exception message on none Apple systems + try { + // these methods will cause a warning: remove them with --illegal-access=permit + final Class comAppleEioFileManagerClass = Class.forName("com.apple.eio.FileManager"); + final Method getPathToApplicationBundleMethod = ClassProvider.getStaticMethod(comAppleEioFileManagerClass, "getPathToApplicationBundle", null); + final String apppath = (String) getPathToApplicationBundleMethod.invoke(null); + System.out.println("PathToApplicationBundle = " + apppath); // PathToApplicationBundle = /Users/admin/git/rc1/build/YaCy.app + if (apppath != null && apppath.endsWith(".app")) { + // modify the applicationRoot path to within the app file + applicationRoot = new File(apppath + "/Contents"); + 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; //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("]");