Package weka.core
Class WekaPackageManager
- java.lang.Object
-
- weka.core.WekaPackageManager
-
public class WekaPackageManager extends java.lang.ObjectClass 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)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDISABLE_KEYPackage metadata key for package disablementstatic java.lang.StringDISABLED_KEYPackage metadata key for package disablementstatic java.lang.StringDO_NOT_LOAD_IF_CLASS_NOT_PRESENT_KEYPackage metadata key for preventing load if a class is not availablestatic java.lang.StringDO_NOT_LOAD_IF_CLASS_NOT_PRESENT_MESSAGE_KEYPackage metadata key for preventing load if a class is not availablestatic java.lang.StringDO_NOT_LOAD_IF_ENV_VAR_NOT_SET_KEYPackage metadata key for preventing load if an environment variable is not setstatic java.lang.StringDO_NOT_LOAD_IF_ENV_VAR_NOT_SET_MESSAGE_KEYPackage metadata key for preventing load if an environment variable is not setstatic java.lang.StringDO_NOT_LOAD_IF_FILE_NOT_PRESENT_KEYPackage metadata key for preventing load if a file is not presentstatic java.lang.StringDO_NOT_LOAD_IF_FILE_NOT_PRESENT_MESSAGE_KEYPackage metadata key for preventing load if a file is not presentstatic java.lang.StringINJECT_DEPENDENCY_KEYPackage metadata key for dependency injectionstatic java.util.Set<java.lang.String>m_doNotLoadListThe set of packages that the user has requested not to loadstatic booleanm_initialPackageLoadingInProcessPackage loading in progress?static booleanm_noPackageMetaDataAvailablestatic booleanm_offlineOperating offline?static java.lang.StringMESSAGE_TO_DISPLAY_ON_INSTALLATION_KEYPackage metadata key for a message to display on installationstatic java.io.FileNATIVE_LIBS_DIRThe default native libraries directorystatic java.lang.StringNATIVE_LIBS_DIR_NAMEstatic java.lang.StringOS_ARCH_KEYPackage metadata key for OS architecture.static java.lang.StringOS_NAME_KEYPackage metadata key for OS name.static java.io.FilePACKAGES_DIRThe default packages directorystatic java.lang.StringPRECLUDES_KEYPackage metadata key for package preclusionstatic java.io.FilePROPERTIES_DIRThe default properties directorystatic java.lang.StringSET_SYSTEM_PROPERTIES_KEYPackage metadata key for setting system propertiesstatic java.lang.StringVERSION_KEYPackage metadata key for version infostatic java.lang.StringVM_VERSION_KEYPackage metadata key for JVM version.static java.io.FileWEKA_HOMEDefault path to where Weka's configuration and packages are stored
-
Constructor Summary
Constructors Constructor Description WekaPackageManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckForMissingFiles(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.ExceptioncheckForNewPackages(java.io.PrintStream... progress)Check for new packages on the server and refresh the local cache if neededstatic java.lang.ExceptionestablishCacheIfNeeded(java.io.PrintStream... progress)Establish the local copy of the package meta data if neededstatic 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 packagestatic java.util.List<Package>getAllPackages()Get a list of all packagesstatic 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 PackagegetInstalledPackageInfo(java.lang.String packageName)Get meta data for an installed packagestatic java.util.List<Package>getInstalledPackages()Get a list of installed packagesstatic PackagegetLatestCompatibleVersion(java.lang.String packageName)Get the latest version of the named package that is compatible with the base version of Weka being used.static PackagegetPackageArchiveInfo(java.lang.String packageArchivePath)Extract meta data from a package archivestatic java.io.FilegetPackageHome()static java.util.Map<java.lang.String,java.lang.String>getPackageList(boolean local)Just get a list of the package names.static java.net.URLgetPackageRepositoryURL()Get the package repository URLstatic PackagegetRepositoryPackageInfo(java.lang.String packageName)Get meta data for the latest version of a package from the repositorystatic PackagegetRepositoryPackageInfo(java.lang.String packageName, java.lang.String version)Get meta data for a specific version of a package from the repositorystatic java.util.List<java.lang.Object>getRepositoryPackageVersions(java.lang.String packageName)Get the versions of the supplied package available on the serverstatic PackageManagergetUnderlyingPackageManager()Get the underlying package manager implementationstatic booleanhasBeenLoaded(Package toCheck)Check to see if the named package has been loaded successfullystatic booleaninstalledPackageResourceExists(java.lang.String packageName, java.lang.String resourceName)Check if a named resource exists in an installed packagestatic java.lang.StringinstallPackageFromArchive(java.lang.String packageArchivePath, java.io.PrintStream... progress)Install a package from an archive (unofficial package install route)static booleaninstallPackageFromRepository(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 repositorystatic java.lang.StringinstallPackageFromURL(java.net.URL packageURL, java.io.PrintStream... progress)Install a package from the supplied URLstatic booleaninstallPackages(java.util.List<Package> toInstall, java.io.PrintStream... progress)Install the supplied list of packagesstatic booleanloadCheck(Package toLoad, java.io.File packageRoot, java.io.PrintStream... progress)Check whether a package should be loaded or not.static voidloadPackages(boolean verbose)Load all packagesstatic voidloadPackages(boolean verbose, boolean avoidTriggeringFullClassDiscovery, boolean refreshGOEProperties)Load all packagesstatic voidmain(java.lang.String[] args)Main method for using the package manager from the command linestatic PackagemostRecentVersionWithRespectToConstraint(PackageConstraint toCheck)Find the most recent version of the package encapsulated in the supplied PackageConstraint argument that satisfies the constraintstatic intnumRepositoryPackages()Get the number of packages that are available at the repository.static booleanosAndArchCheck(Package toLoad, java.io.PrintStream... progress)Checks the supplied package against the current OS and architecture.static java.lang.ExceptionrefreshCache(java.io.PrintStream... progress)Refresh the local copy of the package meta datastatic voidrefreshGOEProperties()Refresh the generic object editor properties via re-running of the dynamic class discovery process.static voidremoveExplorerProps(java.lang.String installedPackageName)Remove any ExplorerDefaults properties specified in the supplied packagestatic intrepoZipArchiveSize()Retrieves the size (in KB) of the repository zip archive stored on the server.static java.lang.ExceptionstartupCheck(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 namesstatic voiduninstallPackage(java.lang.String packageName, boolean updateKnowledgeFlow, java.io.PrintStream... progress)Uninstall a named packagestatic booleanvmVersionCheck(Package toLoad, java.io.PrintStream... progress)Checks the supplied package against the JVM version running Weka.
-
-
-
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
-
-
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 checkpackageRoot- the root directory of the packageprogress- 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 checkprogress- 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 checkprogress- 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 checkpackageRoot- 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.ExceptionToggle 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 outputavoidTriggeringFullClassDiscovery- 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 questionresourceName- 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 installprogress- 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.ExceptionGet 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 forconflicts- 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 packageversion- 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.ExceptionInstall 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 installversion- the version of the package to installprogress- 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.ExceptionInstall a package from an archive (unofficial package install route)- Parameters:
packageArchivePath- the path to the package archive file to installprogress- 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.ExceptionInstall a package from the supplied URL- Parameters:
packageURL- the URL to the package archive to installprogress- 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.ExceptionUninstall a named package- Parameters:
packageName- the name of the package to removeupdateKnowledgeFlow- true if any Knowledge Flow beans provided by the package should be deregistered from the KnoweledgeFlowprogress- 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
-
-