com.izforge.izpack.util
Class LibraryRemover

java.lang.Object
  extended by com.izforge.izpack.util.LibraryRemover

public class LibraryRemover
extends java.lang.Object

This class tries to remove a given list of files which are locked by this process. For this the paths of the files are stored in a temporary file and a new process will be created. The class files which are needed by the new process will be unpacked from the jar file under users temp dir in a "sandbox". The new process receive the path of the temporary file and some other information. After a wait intervall it reads the path file and removes all files which there are listed. Next the created "sandbox" and the path file will be removed. This class uses the characteristik of the system loader that jar files will be keeped open, simple class files will be closed after loading a class. Therefore jar files are locked and cannot be deleted, class files are not locked and deletable.
The idea for this stuff is copied from Chadwick McHenry's SelfModifier in the uninstaller stuff of IzPack.

Author:
Klaus Bartz

Nested Class Summary
static class LibraryRemover.StreamProxy
           
 
Field Summary
private static java.lang.String BASE_KEY
          System property name of base for log and sandbox of secondary processes.
private  java.util.Date date
          Also for logging time.
private  java.text.SimpleDateFormat isoPoint
          For logging time.
private static java.lang.String JAVA_HOME
          VM home Needed for the java command.
(package private)  java.io.PrintStream log
          ******************************************************************************************** --------------------------------------------------------------------- Logging --------------------------------------------------------------------- Copied from com.izforge.izpack.uninstaller.SelfModifier.
private  java.io.File logFile
          Log for phase 2, because we can't capture the stdio from them.
private  int phase
          Phase of this process.
private static java.lang.String PHASE_KEY
          System property name of phase (1, 2, or 3) indicator.
private static java.lang.String PREFIX
          Prefix of sandbox, path and log file.
private  java.io.File sandbox
          Directory which we extract too, invoke from, and finally delete.
private static java.lang.String[] SANDBOX_CONTENT
          All class files which are needed for the second process.
private  java.io.File specFile
          The file which contains the paths of the files to delete.
 
Constructor Summary
private LibraryRemover(int phase)
          Constructor for both phases.
 
Method Summary
private static java.lang.String addExtension(java.lang.String command)
          Copied from com.izforge.izpack.uninstaller.SelfModifier.
private  java.io.PrintStream checkLog()
           
static boolean deleteTree(java.io.File file)
          Recursively delete a file structure.
private  java.util.ArrayList<java.io.File> getFilesList()
          Returns an ArrayList of the files to delete.
private  void initJavaExec()
          This call ensures that java can be exec'd in a separate process.
static void invoke(java.util.List<java.lang.String> temporaryFileNames)
          Entry point for phase 1.
private  void invoke1(java.util.List<java.lang.String> temporaryFileNames)
          Internal invoke method for phase 1.
private  void invoke2()
          Invoke methode for phase 2.
private static java.lang.String javaCommand()
          Copied from com.izforge.izpack.uninstaller.SelfModifier.
private  void log(java.lang.String msg)
           
private  void log(java.lang.Throwable t)
           
static void main(java.lang.String[] args)
           
private  java.lang.Process spawn(int nextPhase)
          Copied from com.izforge.izpack.uninstaller.SelfModifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SANDBOX_CONTENT

private static final java.lang.String[] SANDBOX_CONTENT
All class files which are needed for the second process. All have to be in this installers jar file. No slash in front should be used; no dot else slashes should be used; extension (.class) will be required.


BASE_KEY

private static final java.lang.String BASE_KEY
System property name of base for log and sandbox of secondary processes.

See Also:
Constant Field Values

PHASE_KEY

private static final java.lang.String PHASE_KEY
System property name of phase (1, 2, or 3) indicator.

See Also:
Constant Field Values

JAVA_HOME

private static final java.lang.String JAVA_HOME
VM home Needed for the java command.


PREFIX

private static final java.lang.String PREFIX
Prefix of sandbox, path and log file.

See Also:
Constant Field Values

phase

private int phase
Phase of this process.


logFile

private java.io.File logFile
Log for phase 2, because we can't capture the stdio from them.


sandbox

private java.io.File sandbox
Directory which we extract too, invoke from, and finally delete.


specFile

private java.io.File specFile
The file which contains the paths of the files to delete.


isoPoint

private java.text.SimpleDateFormat isoPoint
For logging time.


date

private java.util.Date date
Also for logging time.


log

java.io.PrintStream log
******************************************************************************************** --------------------------------------------------------------------- Logging --------------------------------------------------------------------- Copied from com.izforge.izpack.uninstaller.SelfModifier.

Constructor Detail

LibraryRemover

private LibraryRemover(int phase)
                throws java.io.IOException
Constructor for both phases. Depending on the phase different initializing will be performed.

Parameters:
phase - for which an object should be created.
Throws:
java.io.IOException
Method Detail

invoke

public static void invoke(java.util.List<java.lang.String> temporaryFileNames)
                   throws java.io.IOException
Entry point for phase 1. This class tries to remove all files given in the Vector.

Parameters:
temporaryFileNames -
Throws:
java.io.IOException

initJavaExec

private void initJavaExec()
                   throws java.io.IOException
This call ensures that java can be exec'd in a separate process.

Throws:
java.io.IOException - if an I/O error occurs, indicating java is unable to be exec'd
java.lang.SecurityException - if a security manager exists and doesn't allow creation of a subprocess

invoke1

private void invoke1(java.util.List<java.lang.String> temporaryFileNames)
              throws java.io.IOException
Internal invoke method for phase 1.

Parameters:
temporaryFileNames - list of paths of the files which should be removed
Throws:
java.io.IOException

getFilesList

private java.util.ArrayList<java.io.File> getFilesList()
                                                throws java.lang.Exception
Returns an ArrayList of the files to delete.

Returns:
The files list.
Throws:
java.lang.Exception - Description of the Exception

invoke2

private void invoke2()
Invoke methode for phase 2.


spawn

private java.lang.Process spawn(int nextPhase)
                         throws java.io.IOException
Copied from com.izforge.izpack.uninstaller.SelfModifier. Little addaption for this class.

Parameters:
nextPhase - phase of the spawn
Returns:
created process object
Throws:
java.io.IOException

deleteTree

public static boolean deleteTree(java.io.File file)
Recursively delete a file structure. Copied from com.izforge.izpack.uninstaller.SelfModifier. Little addaption to this class.

Returns:
command for spawning

addExtension

private static java.lang.String addExtension(java.lang.String command)
Copied from com.izforge.izpack.uninstaller.SelfModifier.

Returns:
command command extended with extension of executable

javaCommand

private static java.lang.String javaCommand()
Copied from com.izforge.izpack.uninstaller.SelfModifier. Little addaption for this class.

Returns:
command for spawning

main

public static void main(java.lang.String[] args)

checkLog

private java.io.PrintStream checkLog()

log

private void log(java.lang.Throwable t)

log

private void log(java.lang.String msg)