From: Ben Soares Date: Tue, 5 Nov 2024 16:35:42 +0000 (+0000) Subject: JAL-4485 Initially look for all installations of Chimera/X and add to the pathlist... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=11f6950ab4b5f8aa2a2e16f2f46d61fc9ea3aca2;p=jalview.git JAL-4485 Initially look for all installations of Chimera/X and add to the pathlist if version is not in the blacklist --- diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/StructureManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/StructureManager.java index 85d0def..b83333c 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/StructureManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/StructureManager.java @@ -38,6 +38,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -49,6 +50,8 @@ import org.slf4j.LoggerFactory; import jalview.bin.Cache; import jalview.gui.Preferences; +import jalview.util.FileUtils; +import jalview.util.Platform; /** * This object maintains the relationship between Chimera objects and Cytoscape @@ -75,11 +78,16 @@ public class StructureManager "1.13.1", "1.13", "1.12.2", "1.12.1", "1.12", "1.11.2", "1.11.2", "1.11.1", "1.11" }; + private static String[] CHIMERA_VERSIONS_BLACKLIST = new String[] {}; + // Missing 1.1 as this has known bug see JAL-2422 private static String[] CHIMERAX_VERSIONS = new String[] { "1.7", "1.6.1", "1.6", "1.5", "1.4", "1.3", "1.2.5", "1.0", "0.93", "0.92", "0.91", "0.9" }; + private static String[] CHIMERAX_VERSIONS_BLACKLIST = new String[] { + "1.1" }; + static final String[] defaultStructureKeys = { "Structure", "pdb", "pdbFileName", "PDB ID", "structure", "biopax.xref.PDB", "pdb_ids", "ModelName", "ModelNumber" }; @@ -939,7 +947,6 @@ public class StructureManager // } // } - String os = System.getProperty("os.name"); String userPath = Cache .getDefault(isChimeraX ? Preferences.CHIMERAX_PATH : Preferences.CHIMERA_PATH, null); @@ -953,6 +960,8 @@ public class StructureManager */ String chimera = isChimeraX ? "ChimeraX" : "Chimera"; String chimeraExe = isChimeraX ? "ChimeraX" : "chimera"; + String[] versionsBlacklist = isChimeraX ? CHIMERAX_VERSIONS_BLACKLIST + : CHIMERA_VERSIONS_BLACKLIST; /* * Jalview addition: check if path set in user preferences @@ -961,7 +970,7 @@ public class StructureManager { // in macos, deal with the user selecting the .app folder boolean adjusted = false; - if (os.startsWith("Mac") && userPath.endsWith((".app"))) + if (Platform.isMac() && userPath.endsWith((".app"))) { String possiblePath = String.format("%s/Contents/MacOS/%s", userPath, chimeraExe); @@ -978,7 +987,7 @@ public class StructureManager } // Add default installation paths - if (os.startsWith("Linux")) + if (Platform.isLinux()) { // ChimeraX .deb and .rpm packages put symbolic link from // /usr/bin/chimerax @@ -1015,13 +1024,51 @@ public class StructureManager pathList.add(String.format("%s/local/bin/%s", System.getProperty("user.home"), chimeraExe)); } - else if (os.startsWith("Windows")) + else if (Platform.isWin()) { - for (String root : new String[] { "\\Program Files", + Set installedChimera = new HashSet<>(); + String[] templates = new String[] { "%s\\%s %s\\bin\\%s" }; + String[] roots = new String[] { "\\Program Files", "C:\\Program Files", "\\Program Files (x86)", "C:\\Program Files (x86)", String.format("%s\\AppData\\Local", - System.getProperty("user.home")) }) + System.getProperty("user.home")) }; + for (String root : roots) { + for (String template : templates) + { + String globMatch = String.format(template, root, chimera, "*", + chimeraExe); + List foundInstalls = FileUtils.getFilesFromGlob(globMatch, + false); + for (File found : foundInstalls) + { + boolean add = true; + for (String notVersion : versionsBlacklist) + { + if (String.format(template, root, chimera, notVersion, + chimeraExe).equals(found.getPath())) + { + add = false; + break; + } + } + if (add) + { + installedChimera.add(found); + } + } + } + // try without a version number too + String nonVersioned = String.format("%s\\%s\\bin\\%s", root, + chimera, chimeraExe); + installedChimera + .addAll(FileUtils.getFilesFromGlob(nonVersioned, false)); + + for (File file : installedChimera) + { + pathList.add(file.getPath()); + } + String[] candidates = isChimeraX ? CHIMERAX_VERSIONS : CHIMERA_VERSIONS; for (String version : candidates) @@ -1039,25 +1086,65 @@ public class StructureManager pathList.add(path + ".exe"); } } - else if (os.startsWith("Mac")) + else if (Platform.isMac()) { - // check for installations with version numbers first - String[] candidates = isChimeraX ? CHIMERAX_VERSIONS - : CHIMERA_VERSIONS; - for (String version : candidates) + Set installedChimera = new HashSet<>(); + String[] templates = new String[] { + "%s/%s-%s.app/Contents/MacOS/%s" }; + String[] roots = new String[] { "/Application", String + .format("%s/Application", System.getProperty("user.home")) }; + for (String root : roots) { - pathList.add( - String.format("/Applications/%s-%s.app/Contents/MacOS/%s", - chimera, version, chimeraExe)); - pathList.add( - String.format("%s/Applications/%s-%s.app/Contents/MacOS/%s", - System.getProperty("user.home"), chimera, version, - chimeraExe)); + for (String template : templates) + { + String globMatch = String.format(template, root, chimera, "*", + chimeraExe); + List foundInstalls = FileUtils.getFilesFromGlob(globMatch, + false); + for (File found : foundInstalls) + { + boolean add = true; + for (String notVersion : versionsBlacklist) + { + if (String.format(template, root, chimera, notVersion, + chimeraExe).equals(found.getPath())) + { + add = false; + break; + } + } + if (add) + { + installedChimera.add(found); + } + } + } + // try without a version number too + String nonVersioned = String.format("%s/%s.app/Contents/MacOS/%s", + root, chimera, chimeraExe); + installedChimera + .addAll(FileUtils.getFilesFromGlob(nonVersioned, false)); + + for (File file : installedChimera) + { + pathList.add(file.getPath()); + } + + // check for installations with version numbers first + String[] candidates = isChimeraX ? CHIMERAX_VERSIONS + : CHIMERA_VERSIONS; + for (String version : candidates) + { + + for (String template : templates) + { + pathList.add(String.format(template, root, chimera, version, + chimeraExe)); + } + } + pathList.add(String.format("%s/%s.app/Contents/MacOS/%s", root, + chimera, chimeraExe)); } - pathList.add(String.format("/Applications/%s.app/Contents/MacOS/%s", - chimera, chimeraExe)); - pathList.add(String.format("%s/Applications/%s.app/Contents/MacOS/%s", - System.getProperty("user.home"), chimera, chimeraExe)); } return pathList; } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 883d270..84dff9c 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -1046,6 +1046,7 @@ public class Preferences extends GPreferences Cache.enableSessionProperties(); } + @Override public void saveProxySettings() { Cache.disableSessionProperties(); @@ -1467,11 +1468,17 @@ public class Preferences extends GPreferences Cache.enableSessionProperties(); structureViewerPath.setText(viewerPath); + jalview.bin.Console.debug("Found " + paths.size() + + " paths to look for " + selectedItem.toString()); paths.add(0, structureViewerPath.getText()); for (String path : paths) { + jalview.bin.Console.debug("Looking for " + selectedItem.toString() + + " in " + path.trim()); if (new File(path.trim()).canExecute()) { + jalview.bin.Console.debug( + "Found " + selectedItem.toString() + " in " + path.trim()); found = true; break; }