Class ClassLoaderTestHelper

java.lang.Object
org.apache.hadoop.hbase.util.ClassLoaderTestHelper

public final class ClassLoaderTestHelper extends Object
Some utilities to help class loader testing
  • Field Details

  • Constructor Details

  • Method Details

    • createJarArchive

      private static boolean createJarArchive(File archiveFile, File[] tobeJared)
      Jar a list of files into a jar archive.
      Parameters:
      archiveFile - the target jar archive
      tobeJared - a list of files to be jared
      Returns:
      true if a jar archive is build, false otherwise
    • buildJar

      public static File buildJar(String testDir, String className, String code) throws Exception
      Create a test jar for testing purpose for a given class name with specified code string: save the class to a file, compile it, and jar it up. If the code string passed in is null, a bare empty class will be created and used.
      Parameters:
      testDir - the folder under which to store the test class and jar
      className - the test class name
      code - the optional test class code, which can be null. If null, a bare empty class will be used
      Returns:
      the test jar file generated
      Throws:
      Exception
    • buildJar

      public static File buildJar(String testDir, String className, String code, String folder) throws Exception
      Create a test jar for testing purpose for a given class name with specified code string.
      Parameters:
      testDir - the folder under which to store the test class
      className - the test class name
      code - the optional test class code, which can be null. If null, an empty class will be used
      folder - the folder under which to store the generated jar
      Returns:
      the test jar file generated
      Throws:
      Exception
    • addJarFilesToJar

      public static void addJarFilesToJar(File targetJar, String libPrefix, File... srcJars) throws Exception
      Add a list of jar files to another jar file under a specific folder. It is used to generated coprocessor jar files which can be loaded by the coprocessor class loader. It is for testing usage only so we don't be so careful about stream closing in case any exception.
      Parameters:
      targetJar - the target jar file
      libPrefix - the folder where to put inner jar files
      srcJars - the source inner jar files to be added
      Throws:
      Exception - if anything doesn't work as expected
    • localDirPath

      public static String localDirPath(org.apache.hadoop.conf.Configuration conf)
    • deleteClass

      public static void deleteClass(String className, String testDir, org.apache.hadoop.conf.Configuration conf) throws Exception
      Throws:
      Exception