java.lang.Object
de.uni_hildesheim.sse.easy.loader.framework.Utils

public class Utils extends Object
Some basic utility functions. Some may be present in existing libraries, but we aim at avoiding the use of libraries in this loader in order to avoid class loading conflicts.
Author:
Holger Eichelberger
  • Field Details

  • Constructor Details

    • Utils

      private Utils()
      Prevents external creation.
  • Method Details

    • closeQuietly

      public static void closeQuietly(Closeable closeable)
      Closes the given closeable without throwing an exception.
      Parameters:
      closeable - the closeable to be closed, may be null
    • toArray

      public static final URL[] toArray(List<URL> urls)
      Turns a list of URLs into an array of URLS.
      Parameters:
      urls - the URLs to be turned into an array
      Returns:
      the related URL array
    • copy

      public static void copy(InputStream is, OutputStream os) throws IOException
      Copies is to os.
      Parameters:
      is - the input stream
      os - the output stream
      Throws:
      IOException - in case of I/O problems
    • analyzeForCyclicDependencies

      public static List<String> analyzeForCyclicDependencies(List<BundleInfo> infos)
      Analyzes the given bundles for cyclic dependencies.
      Parameters:
      infos - the bundle information objects to be analyzed
      Returns:
      empty if there are no cyclic dependencies, the dependency paths leading to cyclic dependencies else
    • sortByContainment

      public static List<BundleInfo> sortByContainment(List<BundleInfo> infos)
      Sorts the given bundle informations according to the containment of their bundles to initialize. This method aims at simulating a startup process and tries putting those bundles with less/few bundles at the beginning.
      Parameters:
      infos - the information objects to be sorted
      Returns:
      the sorted information objects
    • getBundlesToInitialize

      private static List<BundleInfo> getBundlesToInitialize(Map<BundleInfo,List<BundleInfo>> cache, BundleInfo info, Map<String,BundleInfo> mapping)
      Returns the bundles to initialize.
      Parameters:
      cache - the initialization set cache (may be modified as a side effect)
      info - the information object to return the initialization for
      mapping - the name/version-bundle mapping
      Returns:
      the bundles to initialize
    • collectBundlesToInitialize

      private static void collectBundlesToInitialize(BundleInfo info, List<BundleInfo> result, boolean topLevel, Map<String,BundleInfo> mapping)
      Collects those bundles (including the given one and dependent bundles), which shall be initialized explicitly.
      Parameters:
      info - the bundle info to collect information for
      result - the bundle information objects to be initialized (modified as a side effect)
      topLevel - whether this is a top-level call
      mapping - the name/version-bundle mapping
    • activateDsInstance

      public static boolean activateDsInstance(ClassLoader loader, String className)
      Activates a DS class / instance.
      Parameters:
      loader - the class loader to find the DS class
      className - the class name of the class to activated in (simple) DS way
      Returns:
      true if successful, false else
    • deactivateDsInstance

      public static boolean deactivateDsInstance(ClassLoader loader, String className)
      Deactivates a DS class / instance.
      Parameters:
      loader - the class loader to find the DS class
      className - the class name of the class to de-activated in (simple) DS way
      Returns:
      true if successful, false else
    • callMethod

      private static boolean callMethod(ClassLoader loader, String className, String methodName, Object param, String callType)
      Calls a DS method.
      Parameters:
      loader - the class loader to find the DS class
      className - the class name of the class to de-activated in (simple) DS way
      methodName - the name of the method to be called (1-parameter ComponentContext)
      param - the only param to be passed in, must not be null
      callType - additional info to be printed out in case of problems
      Returns:
      true if successful, false else
    • findMethod

      private static Method findMethod(Class<?> cls, String methodName, Object param)
      Searches for the specified method in the given class or (if available) the super classes.
      Parameters:
      cls - the class to search in
      methodName - the method name to search for
      param - the param (and type) to search for
      Returns:
      the found method (may be null if not found)
    • startBundle

      public static boolean startBundle(ClassLoader loader, String className)
      Starts the bundle activator given by className.
      Parameters:
      loader - the class loader to find the DS class
      className - the class name of the class to de-activated in (simple) DS way
      Returns:
      true if successful, false else
    • stopBundle

      public static boolean stopBundle(ClassLoader loader, String className)
      Stops the bundle activator given by className.
      Parameters:
      loader - the class loader to find the DS class
      className - the class name of the class to de-activated in (simple) DS way
      Returns:
      true if successful, false else
    • loadBundles

      public static void loadBundles(List<File> files, IBundleFilter filter, Object tag)
      Loads the bundles from the given file folder.
      Parameters:
      files - the files to load from
      filter - an optional bundle filter determining the actual bundles to load (may be null)
      tag - an optional tag to identify bundles for later use
    • findRecentBundles

      public static List<File> findRecentBundles(File folder)
      Returns all recent bundles in folder.
      Parameters:
      folder - the folder to analyze
      Returns:
      all recent JAR files in folder (oder versions of the same bundle are skipped)
    • findJars

      public static List<File> findJars(File folder)
      Returns all JAR files in folder.
      Parameters:
      folder - the folder to analyze
      Returns:
      all JAR files in folder
    • filter

      public static List<BundleInfo> filter(List<BundleInfo> infos, IBundleFilter filter)
      Filters the given infos according to filter.
      Parameters:
      infos - the bundle information objects to be filtered
      filter - the IBundleFilter to be applied
      Returns:
      the filtered bundle information objects
    • toURLs

      public static URL[] toURLs(List<File> files) throws MalformedURLException
      Turns files into an URL array.
      Parameters:
      files - the files to be turned into URLs
      Returns:
      the resulting URLs
      Throws:
      MalformedURLException - in case that at least one of the files cannot be turned into an URL
    • setTempDir

      public static void setTempDir(File tempDir)
      Sets the temp directory for extracting and reading temporary files.
      Parameters:
      tempDir - A folder used by the unpacking process.
    • createTempFile

      public static File createTempFile(String name) throws IOException
      Creates a temp file.
      Parameters:
      name - the name/subpath of the temp file to be created
      Returns:
      the temp file
      Throws:
      IOException - in case of I/O problems
    • jarEntryToFile

      public static boolean jarEntryToFile(JarFile jarFile, JarEntry entry, File target)
      Copies the contents of a JAR entry to the given target file.
      Parameters:
      jarFile - the JAR file being processed
      entry - the JAR entry
      target - the target file
      Returns:
      true if successful, false else