All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.install.products.PkgUnit

java.lang.Object
   |
   +----com.sun.install.products.InstallComponent
           |
           +----com.sun.install.products.InstallLeaf
                   |
                   +----com.sun.install.products.PkgUnit

public class PkgUnit
extends InstallLeaf
implements ResourceResolver
PkgUnit is the logical representation of a Solaris SVR4 "Package". It can be used to install a package onto a system. The underlying methods are based on the Solaris pkgadd command. See the pkgadd(1M) man page for more information on the usage. See the Solaris Tutorial for a complete example of using PkgUnit to install an example product using packages.

An object of this type is designed to fit into the product tree. The product tree is a tree-based representation of a product. The tree is traversed during the install and each leaf installs the piece of the product that is has been tasked to. When a PkgUnit is encountered in the tree, it will run pkgadd with the options that are provided in the constructor.

The PkgUnit class should be configured at build-time. There are several build-time constructors. All of them take some combination of parameters, all of which are described below:

SVR4 Packages can also be installed using an alternate root (see the pkgadd(1M) manpage for more information). This is useful when installing an application onto a client machine that gets its root filesystem from a remote machine. Users installing your product can specify this directory when running the wizard. For example, suppose John Q. User wants to install your app onto a client filesystem that existed at /export/root/pronto. They would execute the wizard as follows:
 # java installWizard -R /export/root/pronto
 
This would install the files onto the client filesystem located at /export/root/proto. pkgadd would also update the package database on the client filesystem and any other files it needed to.


Variable Index

 o BUILD_TIME
Indicates to PkgUnit that it should calculate its size requirements at build time (i.e.
 o DEFAULT_ADMIN
Specifies default rules
 o GZIP_PKGSTREAM_EMBED
Constant indicating package has already by streamed via pkgtrans, and further, it is has been compressed with the gzip compression algorithm.
 o NO_EMBED
Constant indicating package should not be embedded into wizard.
 o PKG_EMBED
Constant indicating package is in filesystem form, and should be embedded into the wizard as a standard package stream.
 o PKGSTREAM_BUFFER_SIZE
Buffer size used during pkgtrans execution and reading.
 o PKGSTREAM_EMBED
Constant indicating package is already in the standard pkgtrans stream format, and should be embedded into the wizard as such.
 o PKGTRANS
Constant indicating location of pkgtrans utility.
 o RUN_TIME
Indicates to PkgUnit that it should calculate its size requirements at run time (i.e.
 o SUID_MODE
Mode mask for an suid file

Constructor Index

 o PkgUnit()
Create a pkgadd Unit with no parameters.
 o PkgUnit(String, String)
Create a Solaris Package Unit with the given name and path.
 o PkgUnit(String, String, String, String)
Create a Solaris Package Unit with the given name, path, response file directory, and admin file directory.
 o PkgUnit(String, String, String, String, Hashtable)
Create a Solaris Package Unit with the given name, path, response file directory, admin file directory, and manual size information.
 o PkgUnit(String, String, String, String, Hashtable, Hashtable)
Create a Solaris Package Unit with the given name, path, response file directory, admin file directory, table of variable/setting pairs, and manual size information.
 o PkgUnit(String, String, String, String, Hashtable, int)
Create a Solaris Package Unit with the given name, path, response file directory, admin file directory, variable/setting values, and preprocessing directive.

Method Index

 o addRuntimeResources(Vector)
Add the runtime resources required by this class.
 o closeArchiveStream()
Closes stream that accesses the embedded package.
 o getArchiveStream()
Gets a stream pointing to the streamed package which is inside the wizard archive.
 o getCollection()
Generates a collection for this wizard.
 o getDestinationTable(Hashtable, String, String)
Creates the destination table out of a pre-processed pathname listing, an alternate root, and a directory.
 o getInstallLocation()
Form the install location based on the installDirKey and a possible relative path.
 o getStream()
Gets a stream that the package stream data can be read from (at buildtime).
 o getStreamSize()
Gets the size of the stream that the streamed package can be read from.
 o initialize(WizardState)
Initialize this PkgUnit.
 o install(WizardState)
Install (pkgadd) the package.
 o isInstallable(WizardState)
Determine if this package is installable.
 o isUninstallable(WizardState)
Determine if this package is unInstallable.
 o main(String[])
Shows size information for a package.
 o readPkgMap(String, Hashtable)
Reads the pkgmap of an SVR4 package, and returns the resulting table of relative directory names and the total size of all files in those directories that are contained in the pkgmap.
 o refresh(Vector, String)
Update this Package.
 o resolveResource(String, String, byte[])
Resolves resources for this wizard (namely the admin/response files, and the package data itself, in the case of an embedded package).
 o setEmbedName(String)
Sets the name of the compressed file to store.
 o setEmbedType(int)
Informs the wizard to archive the package within the wizard, instead of relying on the package to exist at runtime outside the wizard archive.
 o setRunPkgAsk(boolean)
Sets a flag that indicates whether or not pkgask should be executed.
 o toString()
Represent this object as a string.
 o uninstall(WizardState)
Uninstall (pkgrm) the package.

Variables

 o PKGTRANS
 public static final String PKGTRANS
Constant indicating location of pkgtrans utility.

 o NO_EMBED
 public static final int NO_EMBED
Constant indicating package should not be embedded into wizard. Used with setEmbedType().

 o PKG_EMBED
 public static final int PKG_EMBED
Constant indicating package is in filesystem form, and should be embedded into the wizard as a standard package stream. This assumes the existance of /usr/bin/pkgtrans. (pkgtrans is used to convert the package to a package stream). Used with setEmbedType().

 o PKGSTREAM_EMBED
 public static final int PKGSTREAM_EMBED
Constant indicating package is already in the standard pkgtrans stream format, and should be embedded into the wizard as such. Used with setEmbedType().

 o GZIP_PKGSTREAM_EMBED
 public static final int GZIP_PKGSTREAM_EMBED
Constant indicating package has already by streamed via pkgtrans, and further, it is has been compressed with the gzip compression algorithm. It will be stored in the wizard in gzip compressed form. Upon invocation of pkgadd, a GZIPInputStream will be used to decompress the package stream during pkgadd invocation.

Note: This is merely for convenience, if your packages are not compressed, you do not have to do anything, they will automatically be compressed if PKG_EMBED is issued to setEmbedType(). Used with setEmbedType().

 o PKGSTREAM_BUFFER_SIZE
 public static final int PKGSTREAM_BUFFER_SIZE
Buffer size used during pkgtrans execution and reading.

 o BUILD_TIME
 public static final int BUILD_TIME
Indicates to PkgUnit that it should calculate its size requirements at build time (i.e. when the wizard archive is created).

 o RUN_TIME
 public static final int RUN_TIME
Indicates to PkgUnit that it should calculate its size requirements at run time (i.e. when the wizard archive is executed). The time it takes for the wizard to run is increased.

 o DEFAULT_ADMIN
 public static final String DEFAULT_ADMIN
Specifies default rules

 o SUID_MODE
 public static final int SUID_MODE
Mode mask for an suid file

Constructors

 o PkgUnit
 public PkgUnit()
Create a pkgadd Unit with no parameters. Not very useful. Must exist for serialization of an object of this type.

 o PkgUnit
 public PkgUnit(String relativePath,
                String pkgName)
Create a Solaris Package Unit with the given name and path. No response file is used, the default admin files are used, and the sizes are calculated at runtime. See the top of this document for more information.

Parameters:
relativePath - The path to find the package at build/runtime
pkgName - The name of the package.
 o PkgUnit
 public PkgUnit(String relativePath,
                String pkgName,
                String adminDir,
                String responseDir)
Create a Solaris Package Unit with the given name, path, response file directory, and admin file directory. The package sizes are calculated at runtime. See the top of this document for more information.

Parameters:
relativePath - The path to find the package at build/runtime
pkgName - The name of the package.
adminDir - The relative directory where the admin file for this package lives.
responseDir - The relative directory where the response file for this package lives.
 o PkgUnit
 public PkgUnit(String relativePath,
                String pkgName,
                String adminDir,
                String responseDir,
                Hashtable variables,
                int sizeCheck)
Create a Solaris Package Unit with the given name, path, response file directory, admin file directory, variable/setting values, and preprocessing directive. See the top of this document for more information.

Parameters:
relativePath - The path to find the package at build/runtime
pkgName - The name of the package.
adminDir - The relative directory where the admin file for this package lives.
responseDir - The relative directory where the response file for this package lives.
variables - A table of variable name/key settings. Each key is looked up in the WizardState, and if a value is found, that value is set into the installation environment using the corresponding variable name. from the table.
sizeCheck - When to gather size information for this package.
 o PkgUnit
 public PkgUnit(String relativePath,
                String pkgName,
                String adminDir,
                String responseDir,
                Hashtable destinationTable)
Create a Solaris Package Unit with the given name, path, response file directory, admin file directory, and manual size information. See the top of this document for more information.

Parameters:
relativePath - The path to find the package at build/runtime
pkgName - The name of the package.
adminDir - The relative directory where the admin file for this package lives.
responseDir - The relative directory where the response file for this package lives.
destinationTable - a table of hard-coded destinations for this package.
 o PkgUnit
 public PkgUnit(String relativePath,
                String pkgName,
                String adminDir,
                String responseDir,
                Hashtable variables,
                Hashtable destinationTable)
Create a Solaris Package Unit with the given name, path, response file directory, admin file directory, table of variable/setting pairs, and manual size information. the top of this document for more information.

Parameters:
relativePath - The path to find the package at build/runtime
pkgName - The name of the package.
adminDir - The relative directory where the admin file for this package lives.
responseDir - The relative directory where the response file for this package lives.
variables - A table of variable name/key settings. Each key is looked up in the WizardState, and if a value is found, that value is set into the installation environment using the corresponding variable name. from the table.
destinationTable - a table of hard-coded destinations for this package.

Methods

 o setRunPkgAsk
 public void setRunPkgAsk(boolean runPkgAsk)
Sets a flag that indicates whether or not pkgask should be executed. If you set this to true, your package should contain a request script that will be executed to generate the response file when the package is installed. The request script must be non-interactive (e.g. should not stop and ask users questions).

Parameters:
runPkgAsk - If true, pkgask will be executed.
 o setEmbedType
 public void setEmbedType(int type)
Informs the wizard to archive the package within the wizard, instead of relying on the package to exist at runtime outside the wizard archive.

Parameters:
type - The type of embedding to use. Currently, the following types are supported:
  • NO_EMBED: This is the default, which is to not embed the wizard within the archive.

  • PKG_EMBED: This means that your package is currently in filesystem format (e.g. in a directory structure). Your package will be converted into a package stream via /usr/bin/pkgtrans, stored into the wizard archive, and decompressed at runtime.

  • PKGSTREAM_EMBED: Similiar to PKG_EMBED, except your package must already be in stream format (i.e. a single file).

  • GZIP_PKGSTREAM_EMBED: Similar to PKG_EMBED, except your package must already be in stream format (i.e. a single file). Furthermore, your package stream file must have been gzipped. The file will be stored in the wizard archive, and decompressed via the java.util.zip.GZIPInputStream utility class.

 o setEmbedName
 public void setEmbedName(String name)
Sets the name of the compressed file to store. Defaults to "[pkgname].pkgstream" or "[pkgname].pkgstream.gz" for gzipped package streams. This gets called automatically when setEmbedType() is called, to set the default name for each type.

Parameters:
name - The filename of the (possibly) compressed, streamed package, located at the relativePath passed in the constructor.
 o getCollection
 public ResourceCollection getCollection()
Generates a collection for this wizard. It must be currently set to a particular embedded type (via setEmbedType()) before this method is called.

Returns:
The resource collection consisting of the files required to embed this package into the wizard archive.
 o resolveResource
 public ResourceInputStream resolveResource(String section,
                                            String name,
                                            byte extData[])
Resolves resources for this wizard (namely the admin/response files, and the package data itself, in the case of an embedded package).

Parameters:
section - The section name of the resource to be resolved
name - The name of the resource to be resolved
extData - The extra data for this resource, if any.
Returns:
A stream that the resource can be read from
 o getStreamSize
 protected long getStreamSize() throws IOException
Gets the size of the stream that the streamed package can be read from.

Returns:
the size of the stream that the streamed package can be read from.
 o getStream
 protected InputStream getStream() throws IOException
Gets a stream that the package stream data can be read from (at buildtime).

Returns:
A stream that the package can be read from (at buildtime).
 o getArchiveStream
 protected ResourceInputStream getArchiveStream() throws IOException
Gets a stream pointing to the streamed package which is inside the wizard archive.

Returns:
A stream pointing to the streamed package which is inside the wizard archive.
 o closeArchiveStream
 protected void closeArchiveStream() throws IOException
Closes stream that accesses the embedded package. Should be called after each getArchiveStream() (after processing the stream).

 o getInstallLocation
 public String getInstallLocation()
Form the install location based on the installDirKey and a possible relative path. Althernate root is not considered in this method.

Returns:
The location this FileUnit will install to
Overrides:
getInstallLocation in class InstallComponent
 o install
 public boolean install(WizardState state)
Install (pkgadd) the package. This is the most important method this class overrides from InstallLeaf. This actually does the install, and reports the progress by using a ProgressTimer. It first lays down the admin and response files into the system temporary directory, and then executes pkgadd with the appropriate parameters.

Parameters:
state - The wizard state this component belongs to
Returns:
true, if the installation was sucessful, false otherwise
Overrides:
install in class InstallComponent
 o uninstall
 public boolean uninstall(WizardState state)
Uninstall (pkgrm) the package. The same admin file is used as was used during install. In addition, the -n flag is passed to pkgrm to avoid interaction. The package is first checked using pkginfo to verify its existance.

Parameters:
state - The wizard state this component belongs to
Returns:
true if the removal of this package was sucessful, false otherwise
Overrides:
uninstall in class InstallComponent
 o isInstallable
 public boolean isInstallable(WizardState state)
Determine if this package is installable. Several sanity checks are run here:

Parameters:
state - The wizard state this component belongs to
Returns:
true, if this is a valid, installable SVR4 package, false otherwise.
 o isUninstallable
 public boolean isUninstallable(WizardState state)
Determine if this package is unInstallable. Until uninstall is implemented, this method always returns false

Parameters:
state - The wizard state this component belongs to
Returns:
true, if this component is able to be removed, false otherwise
 o toString
 public String toString()
Represent this object as a string.

Returns:
A textual representation of this component, consisting of it's name and runtime install destination.
Overrides:
toString in class InstallComponent
 o initialize
 public boolean initialize(WizardState state)
Initialize this PkgUnit. This method reads in the meta-files for this package (admin, response files) and parses them. It also collects locale and architecture information about the package.

Parameters:
wizardState - The wizardstate this component belongs to
Returns:
true, if this PkgUnit was able to parse its meta files (pkginfo, response, admin), false otherwise.
Overrides:
initialize in class InstallComponent
 o refresh
 public boolean refresh(Vector targets,
                        String sharedPoolKey)
Update this Package. For the PkgUNit, the pkgmap is re-read and size re-calculated based on any new directory information.

Parameters:
targets - The target properties (set via setProperty()) to update.
sharedPoolKey - The key to use during the shared pool verification.
Returns:
true if the refresh was sucessful, falseotherwise.
Overrides:
refresh in class InstallComponent
 o getDestinationTable
 public static Hashtable getDestinationTable(Hashtable sizeTable,
                                             String alternateRoot,
                                             String newDirectory)
Creates the destination table out of a pre-processed pathname listing, an alternate root, and a directory.

Parameters:
sizeTable - the pre-processed table of directories and their sizes, in Longs. The table can contain both relative and absolute pathnames/
alternateRoot - The directory to prepend to all entries in the table, whether the entries are relative or absolute.
newDirectory - The direcectory to prepend to the relative paths that are present in the table.
Returns:
The new table of processed pathnames and sizes.
 o readPkgMap
 public static Hashtable readPkgMap(String path,
                                    Hashtable env)
Reads the pkgmap of an SVR4 package, and returns the resulting table of relative directory names and the total size of all files in those directories that are contained in the pkgmap.

Parameters:
path - The full path to the pkgmap file to read
env - The environment to resolve variables from. If a pkgmap entry has a parametric variable, this environment is searched to resolve the variable, recursively.
Returns:
The resulting table of relative and absolute paths, along with the size (in a Long) representing the total of all files to be placed in that directory.
 o addRuntimeResources
 public void addRuntimeResources(Vector resourceVector)
Add the runtime resources required by this class.

Parameters:
resourceVector - The vector containing all of the required resources for this class
Overrides:
addRuntimeResources in class InstallLeaf
 o main
 public static void main(String args[])
Shows size information for a package.

usage: java PkgUnit

Parameters:
args - The arguments to the class

All Packages  Class Hierarchy  This Package  Previous  Next  Index