Package weka.core

Class WekaPackageManager


  • public class WekaPackageManager
    extends java.lang.Object
    Class providing package management and manipulation routines. Also provides a command line interface for package management.
    Version:
    $Revision: 15423 $
    Author:
    Mark Hall (mhall{[at]}pentaho{[dot]}com)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean checkForMissingFiles​(Package toLoad, java.io.File packageRoot, java.io.PrintStream... progress)
      Checks to see if there are any missing files/directories for a given package.
      static java.lang.Exception checkForNewPackages​(java.io.PrintStream... progress)
      Check for new packages on the server and refresh the local cache if needed
      static java.lang.Exception establishCacheIfNeeded​(java.io.PrintStream... progress)
      Establish the local copy of the package meta data if needed
      static java.util.List<Dependency> getAllDependenciesForPackage​(Package target, java.util.Map<java.lang.String,​java.util.List<Dependency>> conflicts)
      Get a list of dependencies for a given package
      static java.util.List<Package> getAllPackages()
      Get a list of all packages
      static java.util.List<Package> getAvailableCompatiblePackages()
      Get a list of the most recent version of all available packages (i.e.
      static java.util.List<Package> getAvailablePackages()
      Get a list of all available packages (i.e.
      static Package getInstalledPackageInfo​(java.lang.String packageName)
      Get meta data for an installed package
      static java.util.List<Package> getInstalledPackages()
      Get a list of installed packages
      static Package getLatestCompatibleVersion​(java.lang.String packageName)
      Get the latest version of the named package that is compatible with the base version of Weka being used.
      static Package getPackageArchiveInfo​(java.lang.String packageArchivePath)
      Extract meta data from a package archive
      static java.io.File getPackageHome()  
      static java.util.Map<java.lang.String,​java.lang.String> getPackageList​(boolean local)
      Just get a list of the package names.
      static java.net.URL getPackageRepositoryURL()
      Get the package repository URL
      static Package getRepositoryPackageInfo​(java.lang.String packageName)
      Get meta data for the latest version of a package from the repository
      static Package getRepositoryPackageInfo​(java.lang.String packageName, java.lang.String version)
      Get meta data for a specific version of a package from the repository
      static java.util.List<java.lang.Object> getRepositoryPackageVersions​(java.lang.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​(java.lang.String packageName, java.lang.String resourceName)
      Check if a named resource exists in an installed package
      static java.lang.String installPackageFromArchive​(java.lang.String packageArchivePath, java.io.PrintStream... progress)
      Install a package from an archive (unofficial package install route)
      static boolean installPackageFromRepository​(java.lang.String packageName, java.lang.String version, java.io.PrintStream... progress)
      Install a named package by retrieving the location of the archive from the meta data stored in the repository
      static java.lang.String installPackageFromURL​(java.net.URL packageURL, java.io.PrintStream... progress)
      Install a package from the supplied URL
      static boolean installPackages​(java.util.List<Package> toInstall, java.io.PrintStream... progress)
      Install the supplied list of packages
      static boolean loadCheck​(Package toLoad, java.io.File packageRoot, java.io.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​(java.lang.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, java.io.PrintStream... progress)
      Checks the supplied package against the current OS and architecture.
      static java.lang.Exception refreshCache​(java.io.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​(java.lang.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 java.lang.Exception startupCheck​(boolean force, java.io.PrintStream... progress)  
      static java.util.List<java.lang.String> toggleLoadStatus​(java.util.List<java.lang.String> packageNames)
      Toggle the load status of the supplied list of package names
      static void uninstallPackage​(java.lang.String packageName, boolean updateKnowledgeFlow, java.io.PrintStream... progress)
      Uninstall a named package
      static boolean vmVersionCheck​(Package toLoad, java.io.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 Detail

      • INJECT_DEPENDENCY_KEY

        public static final java.lang.String INJECT_DEPENDENCY_KEY
        Package metadata key for dependency injection
        See Also:
        Constant Field Values
      • VERSION_KEY

        public static final java.lang.String VERSION_KEY
        Package metadata key for version info
        See Also:
        Constant Field Values
      • DISABLE_KEY

        public static final java.lang.String DISABLE_KEY
        Package metadata key for package disablement
        See Also:
        Constant Field Values
      • DISABLED_KEY

        public static final java.lang.String DISABLED_KEY
        Package metadata key for package disablement
        See Also:
        Constant Field Values
      • PRECLUDES_KEY

        public static final java.lang.String PRECLUDES_KEY
        Package metadata key for package preclusion
        See Also:
        Constant Field Values
      • OS_NAME_KEY

        public static final java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String SET_SYSTEM_PROPERTIES_KEY
        Package metadata key for setting system properties
        See Also:
        Constant Field Values
      • WEKA_HOME

        public static java.io.File WEKA_HOME
        Default path to where Weka's configuration and packages are stored
      • PACKAGES_DIR

        public static java.io.File PACKAGES_DIR
        The default packages directory
      • PROPERTIES_DIR

        public static java.io.File PROPERTIES_DIR
        The default properties directory
      • NATIVE_LIBS_DIR_NAME

        public static java.lang.String NATIVE_LIBS_DIR_NAME
      • NATIVE_LIBS_DIR

        public static java.io.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 java.util.Set<java.lang.String> m_doNotLoadList
        The set of packages that the user has requested not to load
    • Constructor Detail

      • WekaPackageManager

        public WekaPackageManager()
    • Method Detail

      • removeExplorerProps

        public static void removeExplorerProps​(java.lang.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,
                                        java.io.File packageRoot,
                                        java.io.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,
                                             java.io.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,
                                             java.io.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,
                                                   java.io.File packageRoot,
                                                   java.io.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 java.util.List<java.lang.String> toggleLoadStatus​(java.util.List<java.lang.String> packageNames)
                                                                 throws java.lang.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:
        java.lang.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 java.util.Map<java.lang.String,​java.lang.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 of all the package names available either locally or at the repository
      • establishCacheIfNeeded

        public static java.lang.Exception establishCacheIfNeeded​(java.io.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 java.lang.Exception checkForNewPackages​(java.io.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 java.lang.Exception refreshCache​(java.io.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​(java.lang.String packageName,
                                                             java.lang.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 java.io.File getPackageHome()
      • mostRecentVersionWithRespectToConstraint

        public static Package mostRecentVersionWithRespectToConstraint​(PackageConstraint toCheck)
                                                                throws java.lang.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:
        java.lang.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​(java.util.List<Package> toInstall,
                                              java.io.PrintStream... progress)
                                       throws java.lang.Exception
        Install the supplied list of packages
        Parameters:
        toInstall - packages to install
        progress - to report progress to
        Returns:
        true if successful
        Throws:
        java.lang.Exception - if a problem occurs
      • getRepositoryPackageVersions

        public static java.util.List<java.lang.Object> getRepositoryPackageVersions​(java.lang.String packageName)
                                                                             throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • getPackageRepositoryURL

        public static java.net.URL getPackageRepositoryURL()
        Get the package repository URL
        Returns:
        the package repository URL
      • getAllPackages

        public static java.util.List<Package> getAllPackages()
                                                      throws java.lang.Exception
        Get a list of all packages
        Returns:
        a list of all packages
        Throws:
        java.lang.Exception - if a problem occurs
      • getAvailablePackages

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

        public static java.util.List<Package> getAvailableCompatiblePackages()
                                                                      throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • getLatestCompatibleVersion

        public static Package getLatestCompatibleVersion​(java.lang.String packageName)
                                                  throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • getInstalledPackages

        public static java.util.List<Package> getInstalledPackages()
                                                            throws java.lang.Exception
        Get a list of installed packages
        Returns:
        a list of installed packages
        Throws:
        java.lang.Exception - if a problem occurs
      • getAllDependenciesForPackage

        public static java.util.List<Dependency> getAllDependenciesForPackage​(Package target,
                                                                              java.util.Map<java.lang.String,​java.util.List<Dependency>> conflicts)
                                                                       throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • getPackageArchiveInfo

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

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

        public static Package getRepositoryPackageInfo​(java.lang.String packageName)
                                                throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • getRepositoryPackageInfo

        public static Package getRepositoryPackageInfo​(java.lang.String packageName,
                                                       java.lang.String version)
                                                throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • installPackageFromRepository

        public static boolean installPackageFromRepository​(java.lang.String packageName,
                                                           java.lang.String version,
                                                           java.io.PrintStream... progress)
                                                    throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • installPackageFromArchive

        public static java.lang.String installPackageFromArchive​(java.lang.String packageArchivePath,
                                                                 java.io.PrintStream... progress)
                                                          throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • installPackageFromURL

        public static java.lang.String installPackageFromURL​(java.net.URL packageURL,
                                                             java.io.PrintStream... progress)
                                                      throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • uninstallPackage

        public static void uninstallPackage​(java.lang.String packageName,
                                            boolean updateKnowledgeFlow,
                                            java.io.PrintStream... progress)
                                     throws java.lang.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:
        java.lang.Exception - if a problem occurs
      • startupCheck

        public static java.lang.Exception startupCheck​(boolean force,
                                                       java.io.PrintStream... progress)
      • main

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