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;
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
"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" };
// }
// }
- String os = System.getProperty("os.name");
String userPath = Cache
.getDefault(isChimeraX ? Preferences.CHIMERAX_PATH
: Preferences.CHIMERA_PATH, null);
*/
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
{
// 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);
}
// Add default installation paths
- if (os.startsWith("Linux"))
+ if (Platform.isLinux())
{
// ChimeraX .deb and .rpm packages put symbolic link from
// /usr/bin/chimerax
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<File> 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<File> 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)
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<File> 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<File> 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;
}