/** * Downloads the library and default configuration from NCBI. Save them where it can be found by * LibManager.loadLibrary() */ private LibDownloadResult download(String libname) { if (!AUTO_DOWNLOAD) { throw new RuntimeException("AUTO_DOWNLOAD is disabled. This method should not be called"); } LibDownloadResult result = new LibDownloadResult(); Version latestVersion = getLatestVersion(libname); if (latestVersion == null) { result.status = DownloadManager.DownloadResult.FAILED; return result; } result.status = downloadManager.downloadLib(this, libname, latestVersion); if (result.status == DownloadManager.DownloadResult.SUCCESS) { result.savedPath = createdFileName; createdFileName = null; properties.saved(libname, latestVersion.toSimpleVersion(), result.savedPath); } return result; // return downloadKfg(knownLibPath[i + 1]); }
private LibSearchResult searchLibrary(String libname, Version requiredVersion) { LibSearchResult searchResult = new LibSearchResult(); for (Location l : locations) { Logger.info("Checking " + libname + " from " + l + "..."); List<String> pathsToCheck = new ArrayList<String>(); boolean useLoadLibrary = false; boolean searchEvenAfterFound = !JUST_DO_SIMPLE_LOAD_LIBRARY; switch (l) { case LIBPATH: { pathsToCheck.add(libname); String libnameWithDataModel = libnameWithDataModel(libname); if (libnameWithDataModel != null) { pathsToCheck.add(libnameWithDataModel); } useLoadLibrary = true; break; } case CACHE: { String filename = properties.get(libname); if (filename == null) { continue; } // when search is enabled, we might skip it if cache has information about previously // loaded library and last search was less than SEARCH_LIB_FREQUENCY_INTERVAL ago Date lastSearchDate = properties.getLastSeach(libname); searchEvenAfterFound = lastSearchDate == null || (new Date().getTime() - lastSearchDate.getTime() > SEARCH_LIB_FREQUENCY_INTERVAL); pathsToCheck.add(filename); // this is kind of hack, but it does not require different checks between win/unix // we say that library was loaded from LIBPATH location when its path starts from // library simple name useLoadLibrary = filename.startsWith(libname); break; } case DOWNLOAD: { Logger.info("Downloading " + libname + " from NCBI..."); LibDownloadResult downloadResult; if (!mocksEnabled) { downloadResult = download(libname); } else if (mockDownloadStatus == null) { throw new RuntimeException("mockDownloadStatus must be set when mocks enabled"); } else { downloadResult = new LibDownloadResult(); downloadResult.status = mockDownloadStatus; downloadResult.savedPath = "/some/path/" + libname; } if (downloadResult.status != DownloadManager.DownloadResult.SUCCESS) { Logger.warning("Failed to download " + libname + " from NCBI"); if (downloadResult.status == DownloadManager.DownloadResult.UNSUPPORTED_OS) { searchResult.failCause = new UnsupportedArchCause(); } else { searchResult.failCause = new ConnectionProblemCause(); } continue; } Logger.info("Downloaded " + libname + " from NCBI"); Logger.fine("Checking " + libname + " library..."); pathsToCheck.add(downloadResult.savedPath); break; } default: { String name[] = mapLibraryName(libname); Logger.finest("System.mapLibraryName(" + libname + ") = " + name[0]); LibPathIterator it = new LibPathIterator(l, name); while (true) { String filename = it.nextName(); if (filename == null) { break; } pathsToCheck.add(filename); } break; } } boolean foundInLocation = false; for (String path : pathsToCheck) { Version v; if (!mocksEnabled) { v = checkLibraryVersion(libname, path, useLoadLibrary); } else if (mockLocationVersions == null) { throw new RuntimeException("mockLocationVersions must be set when mocks enabled"); } else { v = mockLocationVersions.get(l); } if (v == null) { continue; } foundInLocation = true; boolean versionFits = v.isCompatible(requiredVersion) && v.compareTo(requiredVersion) >= 0; // replace a found version if either: // a) none was previously found // b) found version which fits requirements and it is higher than previously found // c) found version version which fits requirements while previously found one does not if (searchResult.path == null || (versionFits && (v.compareTo(searchResult.version) > 0) || !searchResult.versionFits)) { searchResult.versionFits = versionFits; searchResult.location = l; searchResult.version = v; searchResult.path = path; } if (searchResult.versionFits && !searchEvenAfterFound) { break; } } if (l == Location.DOWNLOAD) { // when we downloaded something that either can't be loaded or does not fit our requirements // or we just overwrote our best found library and cannot load it if (!searchResult.versionFits || (!foundInLocation && searchResult.path.equals(pathsToCheck.get(0)))) { searchResult.versionFits = false; searchResult.location = l; searchResult.version = null; searchResult.path = pathsToCheck.get(0); } } if (searchResult.version != null && searchResult.version.isCompatible(requiredVersion)) { Version latestVersion = getLatestVersion(libname); // if we don't know the latest version, then we might stop the search if // found version is okay and searchEvenAfterFound == false if (latestVersion == null && searchResult.version.compareTo(requiredVersion) >= 0 && !searchEvenAfterFound) { break; } // if we know the latest version, then we should search until find it if (latestVersion != null && searchResult.version.compareTo(requiredVersion) >= 0) { break; } } } boolean downloadEnabled = Arrays.asList(locations).contains(Location.DOWNLOAD); if (searchResult.failCause == null && !downloadEnabled) { searchResult.failCause = new DownloadDisabledCause(); } return searchResult; }