org.pentaho.packageManagement
Class DefaultPackageManager

java.lang.Object
  extended by org.pentaho.packageManagement.PackageManager
      extended by org.pentaho.packageManagement.DefaultPackageManager

public class DefaultPackageManager
extends PackageManager

A concrete implementation of PackageManager that uses Java properties files/class to manage package meta data. Assumes that meta data for individual packages is stored on the central repository (accessible via http) in properties files that live in a subdirectory with the same name as the package. Furthermore, each property file is assumed to be named as the version number of the package in question with a ".props" extension. A "Latest.props" file should exist for each package and should always hold meta data on the latest version of a package.

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

Field Summary
 
Fields inherited from class org.pentaho.packageManagement.PackageManager
m_authenticatorSet, m_baseSystemName, m_baseSystemVersion, m_httpProxy, m_packageHome, m_packageRepository, m_proxyPassword, m_proxyUsername
 
Constructor Summary
DefaultPackageManager()
           
 
Method Summary
protected static boolean checkDependencies(PackageConstraint toCheck, Map<String,Dependency> lookup, Map<String,List<Dependency>> conflicts)
          Checks a given package's list of dependencies for any conflicts with the packages in the supplied Map.
static void deleteDir(File dir, PrintStream... progress)
           
protected  File downloadArchive(URL packageURL, String fileExtension, PrintStream... progress)
           
protected  boolean establishPackageHome()
          Checks to see if the package home exists and creates it if necessary.
 List<Dependency> getAllDependenciesForPackage(Package target, Map<String,List<Dependency>> conflicts)
          Gets a full list of packages (encapsulated in Dependency objects) that are required by directly and indirectly by the named target package.
 List<Package> getAllPackages(PrintStream... progress)
          Get all packages that the system knows about (i.e.
 List<Package> getAvailablePackages()
          Get a list of packages that are not currently installed.
 Package getInstalledPackageInfo(String packageName)
          Get package information on the named installed package.
 List<Package> getInstalledPackages()
          Get a list of installed packages.
 Package getPackageArchiveInfo(String packageArchivePath)
          Get package information from the supplied package archive file.
 Package getRepositoryPackageInfo(String packageName)
          Get package information on the named package from the repository.
 Package getRepositoryPackageInfo(String packageName, Object version)
          Get package information on the named package from the repository.
 byte[] getRepositoryPackageMetaDataOnlyAsZip(PrintStream... progress)
          Gets an array of bytes containing a zip of all the repository meta data and supporting files.
 byte[] getRepositoryPackageMetaDataOnlyAsZipLegacy(PrintStream... progress)
          Gets an array of bytes containing a zip of all the repository meta data and supporting files using the legacy approach.
 List<Object> getRepositoryPackageVersions(String packageName)
          Get a list of available versions of the named package.
 Package getURLPackageInfo(URL packageURL)
          Get package information on the package at the given URL.
protected  void installAdditionalLibs(String packageName, String[] additionalLibURLs, PrintStream... progress)
          Installs additional library jar files (as specified in the AdditionalLibs entry in the Description.props file).
protected  void installPackage(String packageArchivePath, String packageName, PrintStream... progress)
          Installs a package from a zip/jar archive.
 String installPackageFromArchive(String packageArchivePath, PrintStream... progress)
          Install a package from an archive on the local file system.
 void installPackageFromRepository(String packageName, Object version, PrintStream... progress)
          Install a package sourced from the repository.
 String installPackageFromURL(URL packageURL, PrintStream... progress)
          Install a package sourced from a given URL.
 void installPackages(List<Package> toInstall, PrintStream... progress)
          Installs all the packages in the supplied list.
static void main(String[] args)
           
protected static String padLeft(String inString, int length)
          Pads a string to a specified length, inserting spaces on the left as required.
protected static String padRight(String inString, int length)
          Pads a string to a specified length, inserting spaces on the right as required.
 void uninstallPackage(String packageName, PrintStream... progress)
          Uninstall a package.
 
Methods inherited from class org.pentaho.packageManagement.PackageManager
create, establishProxy, getBaseSystemName, getBaseSystemVersion, getPackageHome, getPackageRepositoryURL, getProxy, setBaseSystemName, setBaseSystemVersion, setPackageHome, setPackageRepositoryURL, setProxy, setProxyAuthentication, setProxyPassword, setProxyUsername
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPackageManager

public DefaultPackageManager()
Method Detail

downloadArchive

protected File downloadArchive(URL packageURL,
                               String fileExtension,
                               PrintStream... progress)
                        throws Exception
Throws:
Exception

getURLPackageInfo

public Package getURLPackageInfo(URL packageURL)
                          throws Exception
Get package information on the package at the given URL.

Specified by:
getURLPackageInfo in class PackageManager
Parameters:
packageURL - the URL to the package.
Returns:
a Package object encapsulating the package meta data
Throws:
Exception - if the package meta data can't be retrieved.

getRepositoryPackageInfo

public Package getRepositoryPackageInfo(String packageName)
                                 throws Exception
Get package information on the named package from the repository. If multiple versions of the package are available, it assumes that the most recent is required.

Specified by:
getRepositoryPackageInfo in class PackageManager
Parameters:
packageName - the name of the package to get information about.
Returns:
a Package object encapsulating the package meta data.
Throws:
Exception - if the package meta data can't be retrieved.

getRepositoryPackageVersions

public List<Object> getRepositoryPackageVersions(String packageName)
                                          throws Exception
Get a list of available versions of the named package.

Specified by:
getRepositoryPackageVersions in class PackageManager
Parameters:
packageName - the name of the package to get versions.
Returns:
a list of available versions (or null if not applicable)
Throws:
Exception - if something goes wrong while trying to retrieve the list of versions.

getRepositoryPackageInfo

public Package getRepositoryPackageInfo(String packageName,
                                        Object version)
                                 throws Exception
Get package information on the named package from the repository.

Specified by:
getRepositoryPackageInfo in class PackageManager
Parameters:
packageName - the name of the package to get information about.
version - the version of the package to retrieve (may be null if not applicable).
Returns:
a Package object encapsulating the package meta data.
Throws:
Exception - if the package meta data can't be retrieved.

getPackageArchiveInfo

public Package getPackageArchiveInfo(String packageArchivePath)
                              throws Exception
Get package information from the supplied package archive file.

Specified by:
getPackageArchiveInfo in class PackageManager
Parameters:
packageArchivePath - the path to the package archive file
Returns:
a Package object encapsulating the package meta data.
Throws:
Exception - if the package meta data can't be retrieved.

getInstalledPackageInfo

public Package getInstalledPackageInfo(String packageName)
                                throws Exception
Get package information on the named installed package.

Specified by:
getInstalledPackageInfo in class PackageManager
Parameters:
packageName - the name of the package to get information about.
Returns:
a Package object encapsulating the package meta data or null if the package is not installed.
Throws:
Exception - if the package meta data can't be retrieved.

establishPackageHome

protected boolean establishPackageHome()
Checks to see if the package home exists and creates it if necessary.

Returns:
true if the package home exists/was created successfully.

deleteDir

public static void deleteDir(File dir,
                             PrintStream... progress)
                      throws Exception
Throws:
Exception

uninstallPackage

public void uninstallPackage(String packageName,
                             PrintStream... progress)
                      throws Exception
Uninstall a package.

Specified by:
uninstallPackage in class PackageManager
Parameters:
packageName - the package to uninstall.
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Throws:
Exception - if the named package could not be removed for some reason.

installPackageFromArchive

public String installPackageFromArchive(String packageArchivePath,
                                        PrintStream... progress)
                                 throws Exception
Install a package from an archive on the local file system.

Specified by:
installPackageFromArchive in class PackageManager
Parameters:
packageArchivePath - the path to the package archive file.
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Returns:
the name of the package installed
Throws:
Exception - if the package can't be installed for some reason.

installAdditionalLibs

protected void installAdditionalLibs(String packageName,
                                     String[] additionalLibURLs,
                                     PrintStream... progress)
                              throws Exception
Installs additional library jar files (as specified in the AdditionalLibs entry in the Description.props file).

Parameters:
packageName - the name of the package that will receive the downloaded libraries into its lib directory
additionalLibURLs - an array of urls to the libraries to download
progress - for progress reporting
Throws:
Exception - if a problem occurs

installPackages

public void installPackages(List<Package> toInstall,
                            PrintStream... progress)
                     throws Exception
Installs all the packages in the supplied list.

Specified by:
installPackages in class PackageManager
Parameters:
toInstall - a list of Packages to install.
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Throws:
Exception - if something goes wrong during the installation process.

checkDependencies

protected static boolean checkDependencies(PackageConstraint toCheck,
                                           Map<String,Dependency> lookup,
                                           Map<String,List<Dependency>> conflicts)
                                    throws Exception
Checks a given package's list of dependencies for any conflicts with the packages in the supplied Map. Any packages from this packages dependency list that are not in the Map are simply added and checkDependencies is called recursively for each.

Parameters:
toCheck - the package to check.
lookup - a Map of package name, Dependency pairs to check against.
conflicts - a list of Dependency objects for any conflicts that are detected.
Returns:
true if no conflicts are found.
Throws:
Exception - if a problem occurs when checking for conflicts.

getAllDependenciesForPackage

public List<Dependency> getAllDependenciesForPackage(Package target,
                                                     Map<String,List<Dependency>> conflicts)
                                              throws Exception
Gets a full list of packages (encapsulated in Dependency objects) that are required by directly and indirectly by the named target package. Also builds a Map of any packages that are required by more than one package and where there is a conflict of some sort (e.g. multiple conflicting versions). The keys of this map are package names (strings), and each associated value is a list of Dependency objects.

Specified by:
getAllDependenciesForPackage in class PackageManager
Parameters:
target - the package for which a list of dependencies is required.
conflicts - will hold any conflicts that are discovered while building the full dependency list.
Returns:
a list of packages that are directly and indirectly required by the named target package.
Throws:
Exception - if a problem occurs while building the dependency list.

installPackageFromRepository

public void installPackageFromRepository(String packageName,
                                         Object version,
                                         PrintStream... progress)
                                  throws Exception
Install a package sourced from the repository.

Specified by:
installPackageFromRepository in class PackageManager
Parameters:
packageName - the name of the package to install
version - the version of the package to install (may be null if not applicable).
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Throws:
Exception - if the package can't be installed for some reason.

installPackageFromURL

public String installPackageFromURL(URL packageURL,
                                    PrintStream... progress)
                             throws Exception
Install a package sourced from a given URL.

Specified by:
installPackageFromURL in class PackageManager
Parameters:
packageURL - the URL to the package.
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Returns:
the name of the package installed
Throws:
Exception - if the package can't be installed for some reason.

installPackage

protected void installPackage(String packageArchivePath,
                              String packageName,
                              PrintStream... progress)
                       throws Exception
Installs a package from a zip/jar archive.

Parameters:
packageArchivePath - the full path to the archived package to install.
packageName - the name of the package to install.
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Throws:
Exception - if the package can't be installed for some reason.

getRepositoryPackageMetaDataOnlyAsZip

public byte[] getRepositoryPackageMetaDataOnlyAsZip(PrintStream... progress)
                                             throws Exception
Gets an array of bytes containing a zip of all the repository meta data and supporting files. Does *not* contain any package archives etc., only a snapshot of the meta data. Could be used by clients to establish a cache of meta data.

Specified by:
getRepositoryPackageMetaDataOnlyAsZip in class PackageManager
Parameters:
progress - optional varargs parameter, that, if supplied, is expected to contain one or more PrintStream objects to write progress to.
Returns:
a zip compressed array of bytes.
Throws:
Exception - if the repository meta data can't be returned as a zip

getRepositoryPackageMetaDataOnlyAsZipLegacy

public byte[] getRepositoryPackageMetaDataOnlyAsZipLegacy(PrintStream... progress)
                                                   throws Exception
Gets an array of bytes containing a zip of all the repository meta data and supporting files using the legacy approach. Does *not* contain any package archives etc., only a snapshot of the meta data. Could be used by clients to establish a cache of meta data.

Returns:
a zip compressed array of bytes.
Throws:
Exception

getAllPackages

public List<Package> getAllPackages(PrintStream... progress)
                             throws Exception
Get all packages that the system knows about (i.e. all packages contained in the repository).

Specified by:
getAllPackages in class PackageManager
Parameters:
progress - optional varargs parameter, that, if supplied is expected to contain one or more PrintStream objects to write progress to.
Returns:
a list of all packages.
Throws:
Exception - if a list of packages can't be determined.

getAvailablePackages

public List<Package> getAvailablePackages()
                                   throws Exception
Get a list of packages that are not currently installed.

Specified by:
getAvailablePackages in class PackageManager
Returns:
a list of packages that are not currently installed.
Throws:
Exception - if a list of packages can't be determined.

getInstalledPackages

public List<Package> getInstalledPackages()
                                   throws Exception
Get a list of installed packages.

Specified by:
getInstalledPackages in class PackageManager
Returns:
a list of installed packages.
Throws:
Exception - if a list of packages can't be determined.

padLeft

protected static String padLeft(String inString,
                                int length)
Pads a string to a specified length, inserting spaces on the left as required. If the string is too long, characters are removed (from the right).

Parameters:
inString - the input string
length - the desired length of the output string
Returns:
the output string

padRight

protected static String padRight(String inString,
                                 int length)
Pads a string to a specified length, inserting spaces on the right as required. If the string is too long, characters are removed (from the right).

Parameters:
inString - the input string
length - the desired length of the output string
Returns:
the output string

main

public static void main(String[] args)


Copyright © 2013. All Rights Reserved.