|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Plugin to help image annotation with SAM-based Deep Learning models |
| 4 | + * %% |
| 5 | + * Copyright (C) 2024 SAMJ developers. |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package ai.nets.samj.ij.utils; |
| 21 | + |
| 22 | +import java.io.File; |
| 23 | + |
| 24 | +import io.bioimage.modelrunner.system.PlatformDetection; |
| 25 | + |
| 26 | +public class Constants { |
| 27 | + |
| 28 | + /** |
| 29 | + * The folder of Fiji |
| 30 | + */ |
| 31 | + public static final String FIJI_FOLDER = getFijiFolder(); |
| 32 | + |
| 33 | + private static String getFijiFolder() { |
| 34 | + File jvmFolder = new File(System.getProperty("java.home")); |
| 35 | + String imageJExecutable; |
| 36 | + if (PlatformDetection.isWindows()) |
| 37 | + imageJExecutable = "fiji-windows-x64.exe"; |
| 38 | + else if (PlatformDetection.isLinux()) |
| 39 | + imageJExecutable = "fiji-linux-x64"; |
| 40 | + else if (PlatformDetection.isMacOS() && PlatformDetection.getArch().equals(PlatformDetection.ARCH_ARM64)) |
| 41 | + imageJExecutable = "Fiji.App/Contents/MacOS/fiji-macos-arm64"; |
| 42 | + else if (PlatformDetection.isMacOS()) |
| 43 | + imageJExecutable = "Fiji.App/Contents/MacOS/fiji-macos-x64"; |
| 44 | + else |
| 45 | + throw new IllegalArgumentException("Unsupported Operating System"); |
| 46 | + while (true && jvmFolder != null) { |
| 47 | + jvmFolder = jvmFolder.getParentFile(); |
| 48 | + if (new File(jvmFolder + File.separator + imageJExecutable).isFile()) |
| 49 | + return jvmFolder.getAbsolutePath(); |
| 50 | + } |
| 51 | + return getImageJFolder(); |
| 52 | + } |
| 53 | + |
| 54 | + private static String getImageJFolder() { |
| 55 | + File jvmFolder = new File(System.getProperty("java.home")); |
| 56 | + String imageJExecutable; |
| 57 | + if (PlatformDetection.isWindows()) |
| 58 | + imageJExecutable = "ImageJ-win64.exe"; |
| 59 | + else if (PlatformDetection.isLinux()) |
| 60 | + imageJExecutable = "ImageJ-linux64"; |
| 61 | + else if (PlatformDetection.isMacOS()) |
| 62 | + imageJExecutable = "Contents/MacOS/ImageJ-macosx"; |
| 63 | + else |
| 64 | + throw new IllegalArgumentException("Unsupported Operating System"); |
| 65 | + while (true && jvmFolder != null) { |
| 66 | + jvmFolder = jvmFolder.getParentFile(); |
| 67 | + if (new File(jvmFolder + File.separator + imageJExecutable).isFile()) |
| 68 | + return jvmFolder.getAbsolutePath(); |
| 69 | + } |
| 70 | + return new File("").getAbsolutePath(); |
| 71 | + // TODO remove throw new RuntimeException("Unable to find the path to the ImageJ/Fiji being used."); |
| 72 | + } |
| 73 | +} |
0 commit comments