<commit_before>package us.ihmc.tools.nativelibraries;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import javax.xml.bind.DatatypeConverter;

import org.apache.commons.lang3.ArchUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.arch.Processor;

import us.ihmc.tools.nativelibraries.NativeLibraryDescription.Architecture;
import us.ihmc.tools.nativelibraries.NativeLibraryDescription.OperatingSystem;

/**
 * Helper class that unpacks and optionally loads native libraries
 * 
 * @author <NAME>
 */
public class NativeLibraryLoader
{
   public final static String LIBRARY_LOCATION = new File(System.getProperty("user.home"), ".ihmc" + File.separator + "lib").getAbsolutePath();
   private static final HashMap<String, List<String>> extractedLibraries = new HashMap<>();
   private static final HashSet<String> loadedLibraries = new HashSet<>();

   private NativeLibraryLoader()
   {
      // Disallow construction
   }

   /**
    * Convenience method to load a single library that's available on all platforms. Throws a
    * UnsatisfiedLinkError if the library cannot be found.
    * 
    * @param packageName
    * @param libraryName
    */
   public static void loadLibrary(String packageName, String libraryName)
   {
      if (!loadLibrary(new DefaultNativeLibraryDescription(packageName, libraryName)))
      {
         throw new UnsatisfiedLinkError("Cannot load " + createPackagePrefix(packageName) + libraryName);
      }
   }

   /**
    * Extract the library if necessary, returns full path to the library. Useful for JNA libraries.
    * 
    * @param packageName Name of the package
    * @param libraryName Name of the library
    * @return Full path to the library.
    */
   public static String extractLibrary(String packageName, String libraryName)
   {
      return extractLibraries(packageName, libraryName);
   }

   /**
    * Extract multiple JNA libraries. Returns the full path to the first library. The path 
    * is based on the first library name.
    * 
    * @param packageName Name of the package
    * @param mainLibrary Name of the main library. A SHA-1 hash is taken of this library.
    * @param libraries   Names of the libraries
    * @return Full path to the mainLibrary
    */
   public static String extractLibraries(String packageName, String mainLibrary, String... libraries)
   {

      NativeLibraryWithDependencies library = NativeLibraryWithDependencies.fromPlatform(getOS(), getArchitecture(), mainLibrary, libraries);

      List<String> extracted = extractLibraryWithDependenciesAbsolute(packageName, library);

      return extracted.get(0);

   }

   /**
    * Extract multiple JNA libraries.  <commit_msg>Add extractLibraryAbsolute back.<commit_after>package us.ihmc.tools.nativelibraries;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import javax.xml.bind.DatatypeConverter;

import org.apache.commons.lang3.ArchUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.arch.Processor;

import us.ihmc.tools.nativelibraries.NativeLibraryDescription.Architecture;
import us.ihmc.tools.nativelibraries.NativeLibraryDescription.OperatingSystem;

/**
 * Helper class that unpacks and optionally loads native libraries
 * 
 * @author <NAME>
 */
public class NativeLibraryLoader
{
   public final static String LIBRARY_LOCATION = new File(System.getProperty("user.home"), ".ihmc" + File.separator + "lib").getAbsolutePath();
   private static final HashMap<String, List<String>> extractedLibraries = new HashMap<>();
   private static final HashSet<String> loadedLibraries = new HashSet<>();

   private NativeLibraryLoader()
   {
      // Disallow construction
   }

   /**
    * Convenience method to load a single library that's available on all platforms. Throws a
    * UnsatisfiedLinkError if the library cannot be found.
    * 
    * @param packageName
    * @param libraryName
    */
   public static void loadLibrary(String packageName, String libraryName)
   {
      if (!loadLibrary(new DefaultNativeLibraryDescription(packageName, libraryName)))
      {
         throw new UnsatisfiedLinkError("Cannot load " + createPackagePrefix(packageName) + libraryName);
      }
   }

   /**
    * Extract the library if necessary, returns full path to the library. Useful for JNA libraries.
    * 
    * @param packageName Name of the package
    * @param libraryName Name of the library
    * @return Full path to the library.
    */
   public static String extractLibrary(String packageName, String libraryName)
   {
      return extractLibraries(packageName, libraryName);
   }

   /**
    * Extract multiple JNA libraries. Returns the full path to the first library. The path 
    * is based on the first library name.
    * 
    * @param packageName Name of the package
    * @param mainLibrary Name of the main library. A SHA-1 hash is taken of this library.
    * @param libraries   Names of the libraries
    * @return Full path to the mainLibrary
    */
   public static String extractLibraries(String packageName, String mainLibrary, String... libraries)
   {

      NativeLibraryWithDependencies library = NativeLibraryWithDependencies.fromPlatform(getOS(), getArchitecture(), mainLibrary, libraries);

      List<String> extracted = extractLibraryWithDependenciesAbsolute(packageName, library);

      return extracted.get(0);
   }

   @Deprecated
   public static String extractLibraryAbsolute(String packageName, String library)
   {
      NativeLibraryWithDependencies libraryWithDependencies = NativeLibraryWithDependencies.fromFilename(library);
      return extractLibraryWithDependenciesAbsolute(packageName, libraryWithDependencies).get(0);
   }

   /**
    * Extract multiple JNA libraries.  
{'fraction_non_alphanumeric': 0.08431248015242934, 'fraction_numerical': 0.0017465862178469354, 'mean_word_length': 4.019123505976095, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2405274', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1630, 'n_words': 504}