Package weka.core

# Class WekaPackageManager

java.lang.Object
weka.core.WekaPackageManager

public class WekaPackageManager extends Object
Class providing package management and manipulation routines. Also provides a command line interface for package management.

Version:
  $Revision: 15541 $
Author:
  Mark Hall (mhall{[at]}pentaho{[dot]}com)

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DISABLE_KEY`
  Package metadata key for package disablement
  `static final String`
  `DISABLED_KEY`
  Package metadata key for package disablement
  `static final String`
  `DO_NOT_LOAD_IF_CLASS_NOT_PRESENT_KEY`
  Package metadata key for preventing load if a class is not available
  `static final String`
  `DO_NOT_LOAD_IF_CLASS_NOT_PRESENT_MESSAGE_KEY`
  Package metadata key for preventing load if a class is not available
  `static final String`
  `DO_NOT_LOAD_IF_ENV_VAR_NOT_SET_KEY`
  Package metadata key for preventing load if an environment variable is not set
  `static final String`
  `DO_NOT_LOAD_IF_ENV_VAR_NOT_SET_MESSAGE_KEY`
  Package metadata key for preventing load if an environment variable is not set
  `static final String`
  `DO_NOT_LOAD_IF_FILE_NOT_PRESENT_KEY`
  Package metadata key for preventing load if a file is not present
  `static final String`
  `DO_NOT_LOAD_IF_FILE_NOT_PRESENT_MESSAGE_KEY`
  Package metadata key for preventing load if a file is not present
  `static final String`
  `INJECT_DEPENDENCY_KEY`
  Package metadata key for dependency injection
  `static Set<String>`
  `m_doNotLoadList`
  The set of packages that the user has requested not to load
  `static boolean`
  `m_initialPackageLoadingInProcess`
  Package loading in progress?
  `static boolean`
  `m_noPackageMetaDataAvailable`
  `static boolean`
  `m_offline`
  Operating offline?
  `static final String`
  `MESSAGE_TO_DISPLAY_ON_INSTALLATION_KEY`
  Package metadata key for a message to display on installation
  `static File`
  `NATIVE_LIBS_DIR`
  The default native libraries directory
  `static String`
  `NATIVE_LIBS_DIR_NAME`
  `static final String`
  `OS_ARCH_KEY`
  Package metadata key for OS architecture.
  `static final String`
  `OS_NAME_KEY`
  Package metadata key for OS name.
  `static File`
  `PACKAGES_DIR`
  The default packages directory
  `static final String`
  `PRECLUDES_KEY`
  Package metadata key for package preclusion
  `static File`
  `PROPERTIES_DIR`
  The default properties directory
  `static final String`
  `SET_SYSTEM_PROPERTIES_KEY`
  Package metadata key for setting system properties
  `static final String`
  `VERSION_KEY`
  Package metadata key for version info
  `static final String`
  `VM_VERSION_KEY`
  Package metadata key for JVM version.
  `static File`
  `WEKA_HOME`
  Default path to where Weka's configuration and packages are stored

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WekaPackageManager()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `checkForMissingFiles(Package toLoad, File packageRoot, PrintStream... progress)`
  Checks to see if there are any missing files/directories for a given package.
  `static Exception`
  `checkForNewPackages(PrintStream... progress)`
  Check for new packages on the server and refresh the local cache if needed
  `static Exception`
  `establishCacheIfNeeded(PrintStream... progress)`
  Establish the local copy of the package meta data if needed
  `static List<Dependency>`
  `getAllDependenciesForPackage(Package target, Map<String,List<Dependency>> conflicts)`
  Get a list of dependencies for a given package
  `static List<Package>`
  `getAllPackages()`
  Get a list of all packages
  `static List<Package>`
  `getAvailableCompatiblePackages()`
  Get a list of the most recent version of all available packages (i.e.
  `static List<Package>`
  `getAvailablePackages()`
  Get a list of all available packages (i.e.
  `static Package`
  `getInstalledPackageInfo(String packageName)`
  Get meta data for an installed package
  `static List<Package>`
  `getInstalledPackages()`
  Get a list of installed packages
  `static Package`
  `getLatestCompatibleVersion(String packageName)`
  Get the latest version of the named package that is compatible with the base version of Weka being used.
  `static Package`
  `getPackageArchiveInfo(String packageArchivePath)`
  Extract meta data from a package archive
  `static File`
  `getPackageHome()`
  `static Map<String,String>`
  `getPackageList(boolean local)`
  Just get a list of the package names.
  `static URL`
  `getPackageRepositoryURL()`
  Get the package repository URL
  `static Package`
  `getRepositoryPackageInfo(String packageName)`
  Get meta data for the latest version of a package from the repository
  `static Package`
  `getRepositoryPackageInfo(String packageName, String version)`
  Get meta data for a specific version of a package from the repository
  `static List<Object>`
  `getRepositoryPackageVersions(String packageName)`
  Get the versions of the supplied package available on the server
  `static PackageManager`
  `getUnderlyingPackageManager()`
  Get the underlying package manager implementation
  `static boolean`
  `hasBeenLoaded(Package toCheck)`
  Check to see if the named package has been loaded successfully
  `static boolean`
  `installedPackageResourceExists(String packageName, String resourceName)`
  Check if a named resource exists in an installed package
  `static String`
  `installPackageFromArchive(String packageArchivePath, PrintStream... progress)`
  Install a package from an archive (unofficial package install route)
  `static boolean`
  `installPackageFromRepository(String packageName, String version, PrintStream... progress)`
  Install a named package by retrieving the location of the archive from the meta data stored in the repository
  `static String`
  `installPackageFromURL(URL packageURL, PrintStream... progress)`
  Install a package from the supplied URL
  `static boolean`
  `installPackages(List<Package> toInstall, PrintStream... progress)`
  Install the supplied list of packages
  `static boolean`
  `loadCheck(Package toLoad, File packageRoot, PrintStream... progress)`
  Check whether a package should be loaded or not.
  `static void`
  `loadPackages(boolean verbose)`
  Load all packages
  `static void`
  `loadPackages(boolean verbose, boolean avoidTriggeringFullClassDiscovery, boolean refreshGOEProperties)`
  Load all packages
  `static void`
  `main(String[] args)`
  Main method for using the package manager from the command line
  `static Package`
  `mostRecentVersionWithRespectToConstraint(PackageConstraint toCheck)`
  Find the most recent version of the package encapsulated in the supplied PackageConstraint argument that satisfies the constraint
  `static int`
  `numRepositoryPackages()`
  Get the number of packages that are available at the repository.
  `static boolean`
  `osAndArchCheck(Package toLoad, PrintStream... progress)`
  Checks the supplied package against the current OS and architecture.
  `static Exception`
  `refreshCache(PrintStream... progress)`
  Refresh the local copy of the package meta data
  `static void`
  `refreshGOEProperties()`
  Refresh the generic object editor properties via re-running of the dynamic class discovery process.
  `static void`
  `removeExplorerProps(String installedPackageName)`
  Remove any ExplorerDefaults properties specified in the supplied package
  `static int`
  `repoZipArchiveSize()`
  Retrieves the size (in KB) of the repository zip archive stored on the server.
  `static Exception`
  `startupCheck(boolean force, PrintStream... progress)`
  `static List<String>`
  `toggleLoadStatus(List<String> packageNames)`
  Toggle the load status of the supplied list of package names
  `static void`
  `uninstallPackage(String packageName, boolean updateKnowledgeFlow, PrintStream... progress)`
  Uninstall a named package
  `static boolean`
  `vmVersionCheck(Package toLoad, PrintStream... progress)`
  Checks the supplied package against the JVM version running Weka.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### INJECT_DEPENDENCY_KEY

    public static final String INJECT_DEPENDENCY_KEY
    Package metadata key for dependency injection
    See Also:
      - Constant Field Values

  - ### VERSION_KEY

    public static final String VERSION_KEY
    Package metadata key for version info
    See Also:
      - Constant Field Values

  - ### DISABLE_KEY

    public static final String DISABLE_KEY
    Package metadata key for package disablement
    See Also:
      - Constant Field Values

  - ### DISABLED_KEY

    public static final String DISABLED_KEY
    Package metadata key for package disablement
    See Also:
      - Constant Field Values

  - ### PRECLUDES_KEY

    public static final String PRECLUDES_KEY
    Package metadata key for package preclusion
    See Also:
      - Constant Field Values

  - ### OS_NAME_KEY

    public static final String OS_NAME_KEY
    Package metadata key for OS name. Entries in this list are checked against the java property os.name using a String.contains() operation - any match in the list is taken as passing the test.
    See Also:
      - Constant Field Values

  - ### OS_ARCH_KEY

    public static final String OS_ARCH_KEY
    Package metadata key for OS architecture. Entries in this list are checked against the java property os.arch using a String.equalsIgnoreCase() operation, with the exception of entries that are either "64" or "32" in which case the os.arch is checked to see if it contains these numbers. Any match in the list is considered as passing the test.
    See Also:
      - Constant Field Values

  - ### VM_VERSION_KEY

    public static final String VM_VERSION_KEY
    Package metadata key for JVM version. Values can be prefixed by a less-than or greater-than sign. Otherwise, equality is assumed.
    See Also:
      - Constant Field Values

  - ### DO_NOT_LOAD_IF_ENV_VAR_NOT_SET_KEY

    public static final String DO_NOT_LOAD_IF_ENV_VAR_NOT_SET_KEY
    Package metadata key for preventing load if an environment variable is not set
    See Also:
      - Constant Field Values

  - ### DO_NOT_LOAD_IF_ENV_VAR_NOT_SET_MESSAGE_KEY

    public static final String DO_NOT_LOAD_IF_ENV_VAR_NOT_SET_MESSAGE_KEY
    Package metadata key for preventing load if an environment variable is not set
    See Also:
      - Constant Field Values

  - ### DO_NOT_LOAD_IF_CLASS_NOT_PRESENT_KEY

    public static final String DO_NOT_LOAD_IF_CLASS_NOT_PRESENT_KEY
    Package metadata key for preventing load if a class is not available
    See Also:
      - Constant Field Values

  - ### DO_NOT_LOAD_IF_CLASS_NOT_PRESENT_MESSAGE_KEY

    public static final String DO_NOT_LOAD_IF_CLASS_NOT_PRESENT_MESSAGE_KEY
    Package metadata key for preventing load if a class is not available
    See Also:
      - Constant Field Values

  - ### DO_NOT_LOAD_IF_FILE_NOT_PRESENT_KEY

    public static final String DO_NOT_LOAD_IF_FILE_NOT_PRESENT_KEY
    Package metadata key for preventing load if a file is not present
    See Also:
      - Constant Field Values

  - ### DO_NOT_LOAD_IF_FILE_NOT_PRESENT_MESSAGE_KEY

    public static final String DO_NOT_LOAD_IF_FILE_NOT_PRESENT_MESSAGE_KEY
    Package metadata key for preventing load if a file is not present
    See Also:
      - Constant Field Values

  - ### MESSAGE_TO_DISPLAY_ON_INSTALLATION_KEY

    public static final String MESSAGE_TO_DISPLAY_ON_INSTALLATION_KEY
    Package metadata key for a message to display on installation
    See Also:
      - Constant Field Values

  - ### SET_SYSTEM_PROPERTIES_KEY

    public static final String SET_SYSTEM_PROPERTIES_KEY
    Package metadata key for setting system properties
    See Also:
      - Constant Field Values

  - ### WEKA_HOME

    public static File WEKA_HOME
    Default path to where Weka's configuration and packages are stored

  - ### PACKAGES_DIR

    public static File PACKAGES_DIR
    The default packages directory

  - ### PROPERTIES_DIR

    public static File PROPERTIES_DIR
    The default properties directory

  - ### NATIVE_LIBS_DIR_NAME

    public static String NATIVE_LIBS_DIR_NAME

  - ### NATIVE_LIBS_DIR

    public static File NATIVE_LIBS_DIR
    The default native libraries directory

  - ### m_offline

    public static boolean m_offline
    Operating offline?

  - ### m_initialPackageLoadingInProcess

    public static boolean m_initialPackageLoadingInProcess
    Package loading in progress?

  - ### m_noPackageMetaDataAvailable

    public static boolean m_noPackageMetaDataAvailable

  - ### m_doNotLoadList

    public static Set<String> m_doNotLoadList
    The set of packages that the user has requested not to load

- ## Constructor Details

  - ### WekaPackageManager

    public WekaPackageManager()

- ## Method Details

  - ### removeExplorerProps

    public static void removeExplorerProps(String installedPackageName)
    Remove any ExplorerDefaults properties specified in the supplied package
    Parameters:
      `installedPackageName` - the package specifying properties that should be removed from ExplorerDefaults

  - ### hasBeenLoaded

    public static boolean hasBeenLoaded(Package toCheck)
    Check to see if the named package has been loaded successfully
    Parameters:
      `toCheck` - the name of the package to check for
    Returns:
      true if the named package has been loaded successfully

  - ### loadCheck

    public static boolean loadCheck(Package toLoad, File packageRoot, PrintStream... progress)
    Check whether a package should be loaded or not. Checks for missing classes, unset environment variables, missing dependencies etc.
    Parameters:
      `toLoad` - the package to check
      `packageRoot` - the root directory of the package
      `progress` - for reporting loading progress
    Returns:
      true if the package is good to load

  - ### vmVersionCheck

    public static boolean vmVersionCheck(Package toLoad, PrintStream... progress)
    Checks the supplied package against the JVM version running Weka. Packages that don't specify a JVM version are assumed to be OK. The entry in the JVMVersion key are expected to be a floating point number, optionally prefixed by either a greater-than or less-than symbol. Absence of either of these symbols imply equality as the test.
    Parameters:
      `toLoad` - the package to check
      `progress` - PrintStream for progress info
    Returns:
      true if the supplied package passes the JVM version test.

  - ### osAndArchCheck

    public static boolean osAndArchCheck(Package toLoad, PrintStream... progress)
    Checks the supplied package against the current OS and architecture. Packages that don't specify OS and (optionally) architecture constraints are assumed to be OK. OS names in the OSName entry of the package's Description.props are checked against System.getProperty("os.name") via a String.contains() comparison. Any single match results in a pass. If supplied, the package's OSArch entries are checked against System.getProperty("os.arch") using a String.equalsIgnoreCase() comparison, with the exception of the values "64" and "32" which are checked for with String.contains().
    Parameters:
      `toLoad` - the package to check
      `progress` - PrintStream for progress info
    Returns:
      true if the supplied package passes OS/arch constraints.

  - ### checkForMissingFiles

    public static boolean checkForMissingFiles(Package toLoad, File packageRoot, PrintStream... progress)
    Checks to see if there are any missing files/directories for a given package. If there are missing files, then the package can't be loaded. An example would be a connector package that, for whatever reason, can't include a necessary third-party jar file in its lib folder, and requires the user to download and install this jar file manually.
    Parameters:
      `toLoad` - the package to check
      `packageRoot` - the root directory of the package
    Returns:
      true if good to go

  - ### toggleLoadStatus

    public static List<String> toggleLoadStatus(List<String> packageNames) throws Exception
    Toggle the load status of the supplied list of package names
    Parameters:
      `packageNames` - the packages to toggle the load status for
    Returns:
      a list of unknown packages (i.e. any supplied package names that don't appear to be installed)
    Throws:
      `Exception` - if a problem occurs

  - ### loadPackages

    public static void loadPackages(boolean verbose)
    Load all packages
    Parameters:
      `verbose` - true if loading progress should be output

  - ### loadPackages

    public static void loadPackages(boolean verbose, boolean avoidTriggeringFullClassDiscovery, boolean refreshGOEProperties)
    Load all packages
    Parameters:
      `verbose` - true if loading progress should be output
      `avoidTriggeringFullClassDiscovery` - true if we should avoid processing any properties files that might cause a full class discovery run, and may involve instantiating GUI classes.
      `refreshGOEProperties` - true if the GOE properties should be refreshed after loading (i.e. a re-run of the class discovery mechanism, re-initialization of the Knowledge Flow etc.)

  - ### refreshGOEProperties

    public static void refreshGOEProperties()
    Refresh the generic object editor properties via re-running of the dynamic class discovery process.

  - ### getUnderlyingPackageManager

    public static PackageManager getUnderlyingPackageManager()
    Get the underlying package manager implementation
    Returns:
      the underlying concrete package management implementation.

  - ### repoZipArchiveSize

    public static int repoZipArchiveSize()
    Retrieves the size (in KB) of the repository zip archive stored on the server.
    Returns:
      the size of the repository zip archive in KB.

  - ### numRepositoryPackages

    public static int numRepositoryPackages()
    Get the number of packages that are available at the repository.
    Returns:
      the number of packages that are available (or -1 if this can't be determined for some reason.

  - ### getPackageList

    public static Map<String,String> getPackageList(boolean local)
    Just get a list of the package names. This is faster than calling getAllPackages(), especially if fetching from the online repository, since the full meta data for each package doesn't have to be read.
    Parameters:
      `local` - true if the local package list in the cache should be read rather than the online repository
    Returns:
      a Map<String, String> of all the package names available either locally or at the repository

  - ### establishCacheIfNeeded

    public static Exception establishCacheIfNeeded(PrintStream... progress)
    Establish the local copy of the package meta data if needed
    Parameters:
      `progress` - for reporting progress
    Returns:
      any Exception raised or null if all is good

  - ### checkForNewPackages

    public static Exception checkForNewPackages(PrintStream... progress)
    Check for new packages on the server and refresh the local cache if needed
    Parameters:
      `progress` - to report progress to
    Returns:
      any Exception raised or null if all is good

  - ### refreshCache

    public static Exception refreshCache(PrintStream... progress)
    Refresh the local copy of the package meta data
    Parameters:
      `progress` - to report progress to
    Returns:
      any Exception raised or null if all is successful

  - ### installedPackageResourceExists

    public static boolean installedPackageResourceExists(String packageName, String resourceName)
    Check if a named resource exists in an installed package
    Parameters:
      `packageName` - the name of the package in question
      `resourceName` - the name of the resource to check for
    Returns:
      true if the resource exists in the package

  - ### getPackageHome

    public static File getPackageHome()

  - ### mostRecentVersionWithRespectToConstraint

    public static Package mostRecentVersionWithRespectToConstraint(PackageConstraint toCheck) throws Exception
    Find the most recent version of the package encapsulated in the supplied PackageConstraint argument that satisfies the constraint
    Parameters:
      `toCheck` - the PackageConstraint containing the package in question
    Returns:
      the most recent version of the package satisfying the constraint
    Throws:
      `Exception` - if a version can't be found that satisfies the constraint or an error occurs while communicating with the respository

  - ### installPackages

    public static boolean installPackages(List<Package> toInstall, PrintStream... progress) throws Exception
    Install the supplied list of packages
    Parameters:
      `toInstall` - packages to install
      `progress` - to report progress to
    Returns:
      true if successful
    Throws:
      `Exception` - if a problem occurs

  - ### getRepositoryPackageVersions

    public static List<Object> getRepositoryPackageVersions(String packageName) throws Exception
    Get the versions of the supplied package available on the server
    Parameters:
      `packageName` - the package name to get available versions for
    Returns:
      a list of available versions
    Throws:
      `Exception` - if a problem occurs

  - ### getPackageRepositoryURL

    public static URL getPackageRepositoryURL()
    Get the package repository URL
    Returns:
      the package repository URL

  - ### getAllPackages

    public static List<Package> getAllPackages() throws Exception
    Get a list of all packages
    Returns:
      a list of all packages
    Throws:
      `Exception` - if a problem occurs

  - ### getAvailablePackages

    public static List<Package> getAvailablePackages() throws Exception
    Get a list of all available packages (i.e. those not yet installed(.
    Returns:
      a list of all available packages
    Throws:
      `Exception` - if a problem occurs

  - ### getAvailableCompatiblePackages

    public static List<Package> getAvailableCompatiblePackages() throws Exception
    Get a list of the most recent version of all available packages (i.e. those not yet installed or there is a higher version in the repository) that are compatible with the version of Weka that is installed.
    Returns:
      a list of packages that are compatible with the installed version of Weka
    Throws:
      `Exception` - if a problem occurs

  - ### getLatestCompatibleVersion

    public static Package getLatestCompatibleVersion(String packageName) throws Exception
    Get the latest version of the named package that is compatible with the base version of Weka being used.
    Parameters:
      `packageName` - the name of the package to get the latest compatible version of
    Returns:
      the latest compatible version or null if there is no compatible package
    Throws:
      `Exception` - if a problem occurs

  - ### getInstalledPackages

    public static List<Package> getInstalledPackages() throws Exception
    Get a list of installed packages
    Returns:
      a list of installed packages
    Throws:
      `Exception` - if a problem occurs

  - ### getAllDependenciesForPackage

    public static List<Dependency> getAllDependenciesForPackage(Package target, Map<String,List<Dependency>> conflicts) throws Exception
    Get a list of dependencies for a given package
    Parameters:
      `target` - the package to get the dependencies for
      `conflicts` - will hold any conflicts
    Returns:
      a list of dependencies for the target package
    Throws:
      `Exception` - if a problem occurs

  - ### getPackageArchiveInfo

    public static Package getPackageArchiveInfo(String packageArchivePath) throws Exception
    Extract meta data from a package archive
    Parameters:
      `packageArchivePath` - the path to the package archive
    Returns:
      the meta data for the package
    Throws:
      `Exception` - if a problem occurs

  - ### getInstalledPackageInfo

    public static Package getInstalledPackageInfo(String packageName) throws Exception
    Get meta data for an installed package
    Parameters:
      `packageName` - the name of the package
    Returns:
      the meta data for the package
    Throws:
      `Exception` - if a problem occurs

  - ### getRepositoryPackageInfo

    public static Package getRepositoryPackageInfo(String packageName) throws Exception
    Get meta data for the latest version of a package from the repository
    Parameters:
      `packageName` - the name of the package
    Returns:
      the meta data for the package
    Throws:
      `Exception` - if a problem occurs

  - ### getRepositoryPackageInfo

    public static Package getRepositoryPackageInfo(String packageName, String version) throws Exception
    Get meta data for a specific version of a package from the repository
    Parameters:
      `packageName` - the name of the package
      `version` - the version to get meta data for
    Returns:
      the meta data for the package
    Throws:
      `Exception` - if a problem occurs

  - ### installPackageFromRepository

    public static boolean installPackageFromRepository(String packageName, String version, PrintStream... progress) throws Exception
    Install a named package by retrieving the location of the archive from the meta data stored in the repository
    Parameters:
      `packageName` - the name of the package to install
      `version` - the version of the package to install
      `progress` - for reporting progress
    Returns:
      true if the package was installed successfully
    Throws:
      `Exception` - if a problem occurs

  - ### installPackageFromArchive

    public static String installPackageFromArchive(String packageArchivePath, PrintStream... progress) throws Exception
    Install a package from an archive (unofficial package install route)
    Parameters:
      `packageArchivePath` - the path to the package archive file to install
      `progress` - for reporting progress
    Returns:
      true if the package was installed successfully
    Throws:
      `Exception` - if a problem occurs

  - ### installPackageFromURL

    public static String installPackageFromURL(URL packageURL, PrintStream... progress) throws Exception
    Install a package from the supplied URL
    Parameters:
      `packageURL` - the URL to the package archive to install
      `progress` - for reporting progress
    Returns:
      true if the package was installed successfully
    Throws:
      `Exception` - if a problem occurs

  - ### uninstallPackage

    public static void uninstallPackage(String packageName, boolean updateKnowledgeFlow, PrintStream... progress) throws Exception
    Uninstall a named package
    Parameters:
      `packageName` - the name of the package to remove
      `updateKnowledgeFlow` - true if any Knowledge Flow beans provided by the package should be deregistered from the KnoweledgeFlow
      `progress` - for reporting progress
    Throws:
      `Exception` - if a problem occurs

  - ### startupCheck

    public static Exception startupCheck(boolean force, PrintStream... progress)

  - ### main

    public static void main(String[] args)
    Main method for using the package manager from the command line
    Parameters:
      `args` - command line arguments