com.izforge.izpack.installer.unpacker
Class UnpackerBase

java.lang.Object
  extended by com.izforge.izpack.installer.unpacker.UnpackerBase
All Implemented Interfaces:
IUnpacker, Runnable
Direct Known Subclasses:
MultiVolumeUnpacker, Unpacker

public abstract class UnpackerBase
extends Object
implements IUnpacker

Abstract base class for all unpacker implementations.

Author:
Dennis Reil, , Tim Anderson

Field Summary
static String RESOURCES_PATH
          Path to resources in jar
 
Constructor Summary
UnpackerBase(InstallData installData, PackResources resources, RulesEngine rules, VariableSubstitutor variableSubstitutor, UninstallData uninstallData, FileQueueFactory factory, Housekeeper housekeeper, InstallerListeners listeners, Prompt prompt, PlatformModelMatcher matcher)
          Constructs an UnpackerBase.
 
Method Summary
protected  void checkInterrupt()
          Throws an ResourceInterruptedException if installation has been interrupted.
protected  void cleanup()
          Invoked after unpacking has completed, in order to clean up.
protected  void createDirectory(File dir, PackFile file, Pack pack)
          Creates a directory including any necessary but nonexistent parent directories, associated with a pack file.
protected  FileUnpacker createFileUnpacker(PackFile file, Pack pack, FileQueue queue, Cancellable cancellable)
          Creates an unpacker to unpack a pack file.
protected  void extract(PackFile packFile, File target, InputStream packInputStream, Pack pack, FileQueue queue)
          Extracts a pack file.
protected  InstallData getInstallData()
          Returns the installation data.
protected  Prompt getPrompt()
          Returns the prompt.
protected  PackResources getResources()
          Returns the pack resources.
 boolean getResult()
          Return the state of the operation.
protected  String getStepName(Pack pack)
          Returns the step name for a pack, for reporting purposes.
protected  UninstallData getUninstallData()
          Returns the uninstallation data.
protected  VariableSubstitutor getVariableSubstitutor()
          Returns the variable replacer.
protected  void handleOverrideRename(PackFile pf, File file)
          Renames a file, if it exists and the pack file defines how it should be handled.
 boolean interrupt(long timeout)
          Interrupts the unpacker, and waits for it to complete.
protected  boolean isConditionTrue(String id)
           
 boolean isInterruptDisabled()
          Determines if interrupts have been disabled or not.
protected  boolean isInterrupted()
          Determines if the unpacker has been interrupted.
protected  boolean isOverwriteFile(PackFile pf, File file)
          Determines if a file should be overwritten.
protected  void performUpdateChecks(List<UpdateCheck> checks)
          Performs update checks.
protected  void postUnpack(List<Pack> packs, FileQueue queue)
          Invoked after each pack has been unpacked.
protected  void preUnpack(List<Pack> packs)
          Invoked prior to unpacking.
protected  void readExecutableFiles(PackInfo packInfo, List<ExecutableFile> executables)
          Initializes executable files according to the current environment.
protected  void readParsableFiles(PackInfo packInfo, List<ParsableFile> parsables)
          Initializes parseable files according to the current environment.
protected  void readUpdateChecks(PackInfo packInfo, List<UpdateCheck> updateChecks)
          Initializes update checks according to the current environment.
 void run()
          Runs the unpacker.
 void setDisableInterrupt(boolean disable)
          Determines if interrupts should be disabled.
 void setProgressListener(ProgressListener listener)
          Sets the progress listener.
protected  void setResult(boolean result)
          Sets the result of the unpacking operation.
protected  boolean shouldUnpack(Pack pack)
          Determines if a pack should be unpacked.
protected  void skip(InputStream stream, long bytes)
          Skips bytes in a stream.
protected  void skip(PackFile packFile, Pack pack, InputStream packInputStream)
          Skips a pack file.
 void unpack()
          Unpacks the installation files.
protected  void unpack(List<PackInfo> packs, FileQueue queue)
          Unpacks the selected packs.
protected  void unpack(PackFile packFile, InputStream packInputStream, int fileNo, Pack pack, FileQueue queue)
          Unpacks a pack file.
protected  void unpack(PackInfo packInfo, int packNo, FileQueue queue, List<ParsableFile> parsables, List<ExecutableFile> executables, List<UpdateCheck> updateChecks)
          Unpacks a pack.
protected  void writeInstallationInformation()
          Writes information about the installed packs and the variables at installation time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCES_PATH

public static final String RESOURCES_PATH
Path to resources in jar

See Also:
Constant Field Values
Constructor Detail

UnpackerBase

public UnpackerBase(InstallData installData,
                    PackResources resources,
                    RulesEngine rules,
                    VariableSubstitutor variableSubstitutor,
                    UninstallData uninstallData,
                    FileQueueFactory factory,
                    Housekeeper housekeeper,
                    InstallerListeners listeners,
                    Prompt prompt,
                    PlatformModelMatcher matcher)
Constructs an UnpackerBase.

Parameters:
installData - the installation data
resources - the pack resources
rules - the rules engine
variableSubstitutor - the variable substituter
uninstallData - the uninstallation data
factory - the file queue factory
housekeeper - the housekeeper
listeners - the listeners
prompt - the prompt
matcher - the platform-model matcher
Method Detail

setProgressListener

public void setProgressListener(ProgressListener listener)
Sets the progress listener.

Specified by:
setProgressListener in interface IUnpacker
Parameters:
listener - the progress listener

run

public void run()
Runs the unpacker.

Specified by:
run in interface Runnable

unpack

public void unpack()
Unpacks the installation files.


getResult

public boolean getResult()
Return the state of the operation.

Specified by:
getResult in interface IUnpacker
Returns:
true if the operation was successful, false otherwise.

interrupt

public boolean interrupt(long timeout)
Interrupts the unpacker, and waits for it to complete.

If interrupts have been prevented (isInterruptDisabled() returns true), then this returns immediately.

Specified by:
interrupt in interface IUnpacker
Parameters:
timeout - the maximum time to wait, in milliseconds
Returns:
true if the interrupt will be performed, false if the interrupt will be discarded

setDisableInterrupt

public void setDisableInterrupt(boolean disable)
Determines if interrupts should be disabled.

Specified by:
setDisableInterrupt in interface IUnpacker
Parameters:
disable - if true disable interrupts, otherwise enable them

isInterruptDisabled

public boolean isInterruptDisabled()
Determines if interrupts have been disabled or not.

Specified by:
isInterruptDisabled in interface IUnpacker
Returns:
true if interrupts have been disabled, otherwise false

preUnpack

protected void preUnpack(List<Pack> packs)
                  throws InstallerException
Invoked prior to unpacking.

This notifies the ProgressListener, and any registered listeners.

Parameters:
packs - the packs to unpack
Throws:
InstallerException - for any error

unpack

protected void unpack(List<PackInfo> packs,
                      FileQueue queue)
               throws InstallerException
Unpacks the selected packs.

Parameters:
packs - the packs to unpack
queue - the file queue, or null if queuing is not supported
Throws:
ResourceInterruptedException - if unpacking is cancelled
InstallerException - for any error

unpack

protected void unpack(PackInfo packInfo,
                      int packNo,
                      FileQueue queue,
                      List<ParsableFile> parsables,
                      List<ExecutableFile> executables,
                      List<UpdateCheck> updateChecks)
Unpacks a pack.

Parameters:
packInfo - the pack info of the current pack
packNo - the pack number
queue - the file queue, or null if queuing is not supported
Throws:
IzPackException - for any error

unpack

protected void unpack(PackFile packFile,
                      InputStream packInputStream,
                      int fileNo,
                      Pack pack,
                      FileQueue queue)
               throws IOException
Unpacks a pack file.

Parameters:
packFile - the pack file
packInputStream - the pack file input stream
fileNo - the pack file number
pack - the pack that the pack file comes from
queue - the file queue, or null if queuing is not supported
Throws:
IOException - for any I/O error
IzPackException - for any other error

extract

protected void extract(PackFile packFile,
                       File target,
                       InputStream packInputStream,
                       Pack pack,
                       FileQueue queue)
                throws IOException
Extracts a pack file.

Parameters:
packFile - the pack file
target - the file to write to
packInputStream - the pack file input stream
pack - the pack that the pack file comes from
queue - the file queue, or null if queuing is not supported
Throws:
IOException - for any I/O error
ResourceInterruptedException - if installation is cancelled
IzPackException - for any IzPack error

skip

protected void skip(PackFile packFile,
                    Pack pack,
                    InputStream packInputStream)
             throws IOException
Skips a pack file.

Parameters:
packFile - the pack file
pack - the pack
packInputStream - the pack stream
Throws:
IOException - if the file cannot be skipped

createFileUnpacker

protected FileUnpacker createFileUnpacker(PackFile file,
                                          Pack pack,
                                          FileQueue queue,
                                          Cancellable cancellable)
                                   throws InstallerException
Creates an unpacker to unpack a pack file.

Parameters:
file - the pack file to unpack
pack - the parent pack
queue - the file queue. May be null
cancellable - determines if the unpacker should be cancelled
Returns:
the unpacker
Throws:
InstallerException - for any installer error

postUnpack

protected void postUnpack(List<Pack> packs,
                          FileQueue queue)
                   throws IOException,
                          InstallerException
Invoked after each pack has been unpacked.

Parameters:
packs - the packs
queue - the file queue, or null if queuing is not supported
Throws:
ResourceInterruptedException - if installation is cancelled
IOException - for any I/O error
InstallerException

cleanup

protected void cleanup()
Invoked after unpacking has completed, in order to clean up.


getInstallData

protected InstallData getInstallData()
Returns the installation data.

Returns:
the installation data

getUninstallData

protected UninstallData getUninstallData()
Returns the uninstallation data.

Returns:
the uninstallation data

getResources

protected PackResources getResources()
Returns the pack resources.

Returns:
the pack resources

getVariableSubstitutor

protected VariableSubstitutor getVariableSubstitutor()
Returns the variable replacer.

Returns:
the variable replacer

getPrompt

protected Prompt getPrompt()
Returns the prompt.

Returns:
the prompt

shouldUnpack

protected boolean shouldUnpack(Pack pack)
Determines if a pack should be unpacked.

Parameters:
pack - the pack
Returns:
true if the pack should be unpacked, false if it should be skipped

setResult

protected void setResult(boolean result)
Sets the result of the unpacking operation.

Parameters:
result - if true denotes success

isConditionTrue

protected boolean isConditionTrue(String id)

getStepName

protected String getStepName(Pack pack)
Returns the step name for a pack, for reporting purposes.

Parameters:
pack - the pack
Returns:
the pack's step name

createDirectory

protected void createDirectory(File dir,
                               PackFile file,
                               Pack pack)
Creates a directory including any necessary but nonexistent parent directories, associated with a pack file.

If InstallerListeners are registered, these will be notified for each directory created.

Parameters:
dir - the directory to create
file - the pack file
pack - the pack that file comes from
Throws:
IzPackException - if the directory cannot be created or a listener throws an exception

isInterrupted

protected boolean isInterrupted()
Determines if the unpacker has been interrupted.

Returns:
true if the unpacker has been interrupted, otherwise false

checkInterrupt

protected void checkInterrupt()
Throws an ResourceInterruptedException if installation has been interrupted.

Throws:
ResourceInterruptedException - if installation is interrupted

performUpdateChecks

protected void performUpdateChecks(List<UpdateCheck> checks)
Performs update checks.

Parameters:
checks - the update checks. May be null
Throws:
IzPackException - for any error

writeInstallationInformation

protected void writeInstallationInformation()
                                     throws IOException
Writes information about the installed packs and the variables at installation time.

Throws:
InstallerException - for any installer error
IOException - for any I/O error

skip

protected void skip(InputStream stream,
                    long bytes)
             throws IOException
Skips bytes in a stream.

Parameters:
stream - the stream
bytes - the no. of bytes to skip
Throws:
IOException - for any I/O error, or if the no. of bytes skipped doesn't match that expected

isOverwriteFile

protected boolean isOverwriteFile(PackFile pf,
                                  File file)
Determines if a file should be overwritten.

Parameters:
pf - the pack file
file - the file to check
Returns:
true if the file should be overwritten

handleOverrideRename

protected void handleOverrideRename(PackFile pf,
                                    File file)
Renames a file, if it exists and the pack file defines how it should be handled.

Parameters:
pf - the pack file
file - the file to rename
Throws:
InstallerException - if the file cannot be renamed

readParsableFiles

protected void readParsableFiles(PackInfo packInfo,
                                 List<ParsableFile> parsables)
Initializes parseable files according to the current environment.

Parameters:
packInfo - the pack info fpor the current pack
parsables - used to collect the read objects

readExecutableFiles

protected void readExecutableFiles(PackInfo packInfo,
                                   List<ExecutableFile> executables)
Initializes executable files according to the current environment.

Parameters:
packInfo - the pack info fpor the current pack
executables - used to collect the read objects

readUpdateChecks

protected void readUpdateChecks(PackInfo packInfo,
                                List<UpdateCheck> updateChecks)
Initializes update checks according to the current environment.

Parameters:
packInfo - the pack info fpor the current pack
updateChecks - used to collect the read objects


Copyright © 2018. All rights reserved.