Beispiel #1
0
  private Version checkLibraryVersion(String libname, String libpath, boolean useLoadLibrary) {
    if (!useLoadLibrary && !fileExists(libpath)) {
      Logger.finer("File " + libpath + " not found");
      return null;
    }

    Version version = LibVersionChecker.getVersion(libname, libpath, useLoadLibrary);
    if (version == null) {
      Logger.fine("Cannot load or get library version: " + libpath);
    }

    return version;
  }
Beispiel #2
0
  /**
   * Loads the system library by finding it by iterating the location array. Try to download it from
   * NCBI if not found.
   *
   * <p>Will throw LibraryLoadError when failed.
   */
  void loadLibrary(String libname) {
    Version requiredVersion = getRequiredVersion(libname);
    boolean updateCache = Arrays.asList(locations).contains(Location.CACHE);

    Logger.fine("Searching for " + libname + " library...");
    try {
      LibSearchResult searchResult = searchLibrary(libname, requiredVersion);

      if (searchResult.path == null) {
        throw new LibraryNotFoundError(
            libname, "No installed library was found", searchResult.failCause);
      }

      Logger.fine("Found " + libname + " library");

      String libpath = searchResult.path;
      Logger.info("Loading " + libname + "...");
      try {
        if (!mocksEnabled) {
          if (libpath.startsWith(libname)) {
            System.loadLibrary(libpath);
          } else {
            System.load(libpath);
          }
        } else if (mockLoadException != null) {
          throw mockLoadException;
        }
      } catch (Throwable e) {
        if (searchResult.location != Location.DOWNLOAD) {
          throw new LibraryLoadError(
              libname, "Failed to load found library " + libpath, new JvmErrorCause(e));
        }

        throw new LibraryLoadError(
            libname,
            "No installed library was found and downloaded library '"
                + libpath
                + "' cannot be loaded",
            new JvmErrorCause(e),
            "Please install ngs and ncbi-vdb manually:"
                + " https://github.com/ncbi/ngs/wiki/Downloads"
                + " or write to \"[email protected]\" if problems persist");
      }
      Logger.fine("Loaded " + libname + " library");

      Logger.fine("Checking library " + libname + " version...");
      String v;
      if (!mocksEnabled) {
        v = LibVersionChecker.getLoadedVersion(libname);
      } else {
        v = mockLoadedLibraryVersion;
      }
      if (v == null) {
        throw new LibraryLoadError(
            libname, "Failed to retrieve loaded library's version", new InvalidLibraryCause());
      }
      Version loadedVersion = new Version(v);
      if (loadedVersion.compareTo(requiredVersion) < 0
          || !loadedVersion.isCompatible(requiredVersion)) {
        Logger.fine(
            "Library version is not compatible. Required: "
                + requiredVersion.toSimpleVersion()
                + " loaded: "
                + loadedVersion.toSimpleVersion());
        LibraryLoadCause failCause = searchResult.failCause;
        if (searchResult.location == Location.DOWNLOAD || failCause == null) {
          failCause =
              (loadedVersion.compareTo(requiredVersion) < 0)
                  ? new PrereleaseReqLibCause()
                  : new OutdatedJarCause();
        }
        throw new LibraryIncompatibleVersionError(
            libname, "Library is incompatible", libpath, failCause);
      }
      Logger.fine(
          "Library "
              + libname
              + " was loaded successfully."
              + " Version = "
              + loadedVersion.toSimpleVersion());

      if (updateCache) {
        properties.loaded(libname, searchResult.version.toSimpleVersion(), libpath);

        if (searchResult.location != Location.CACHE) {
          properties.setLastSearch(libname);
        }
      }
    } catch (LibraryLoadError e) {
      if (updateCache) {
        properties.notLoaded(libname);
      }
      Logger.warning("Loading of " + libname + " library failed");
      throw e;
    } finally {
      if (updateCache) {
        properties.store();
      }
    }
  }