[izpack-changes] r1828 - izpack-src/branches/3.10/src/lib/com/izforge/izpack/installer

noreply at berlios.de noreply at berlios.de
Thu May 10 22:15:48 CEST 2007


Author: eppelman
Date: 2007-05-10 22:15:47 +0200 (Thu, 10 May 2007)
New Revision: 1828

Modified:
   izpack-src/branches/3.10/src/lib/com/izforge/izpack/installer/AutomatedInstaller.java
Log:
Fixed AutomatedUninstaller.writeUninstallData() "out of sync" with InstallerFrame (Marius Nicolae via Marc Eppelmann)

Modified: izpack-src/branches/3.10/src/lib/com/izforge/izpack/installer/AutomatedInstaller.java
===================================================================
--- izpack-src/branches/3.10/src/lib/com/izforge/izpack/installer/AutomatedInstaller.java	2007-05-10 20:15:03 UTC (rev 1827)
+++ izpack-src/branches/3.10/src/lib/com/izforge/izpack/installer/AutomatedInstaller.java	2007-05-10 20:15:47 UTC (rev 1828)
@@ -27,11 +27,17 @@
 import java.io.InputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStreamWriter;
+import java.io.ByteArrayOutputStream;
+
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.TreeMap;
 import java.util.Vector;
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
 import java.util.zip.ZipOutputStream;
 
 import net.n3.nanoxml.NonValidator;
@@ -40,6 +46,7 @@
 import net.n3.nanoxml.StdXMLReader;
 import net.n3.nanoxml.XMLElement;
 
+import com.izforge.izpack.CustomData;
 import com.izforge.izpack.ExecutableFile;
 import com.izforge.izpack.LocaleDatabase;
 import com.izforge.izpack.Panel;
@@ -101,6 +108,7 @@
         this.panelInstanceCount = new TreeMap();
     }
 
+   
     /**
      * Writes the uninstalldata.
      * 
@@ -158,7 +166,137 @@
             }
             execStream.flush();
             outJar.closeEntry();
+	    
+            // ***  ADDED code bellow 
+	    // Write out additional uninstall data
+            // Do not "kill" the installation if there is a problem
+            // with custom uninstall data. Therefore log it to Debug,
+            // but do not throw.
+            Map additionalData = udata.getAdditionalData();
+            if (additionalData != null && !additionalData.isEmpty())
+            {
+                Iterator keys = additionalData.keySet().iterator();
+                HashSet exist = new HashSet();
+                while (keys != null && keys.hasNext())
+                {
+                    String key = (String) keys.next();
+                    Object contents = additionalData.get(key);
+                    if ("__uninstallLibs__".equals(key))
+                    {
+                        Iterator nativeLibIter = ((List) contents).iterator();
+                        while (nativeLibIter != null && nativeLibIter.hasNext())
+                        {
+                            String nativeLibName = (String) ((List) nativeLibIter.next()).get(0);
+                            byte[] buffer = new byte[5120];
+                            long bytesCopied = 0;
+                            int bytesInBuffer;
+                            outJar.putNextEntry(new ZipEntry("native/" + nativeLibName));
+                            InputStream in = getClass().getResourceAsStream(
+                                    "/native/" + nativeLibName);
+                            while ((bytesInBuffer = in.read(buffer)) != -1)
+                            {
+                                outJar.write(buffer, 0, bytesInBuffer);
+                                bytesCopied += bytesInBuffer;
+                            }
+                            outJar.closeEntry();
+                        }
+                    }
+                    else if ("uninstallerListeners".equals(key) || "uninstallerJars".equals(key))
+                    { // It is a ArrayList of ArrayLists which contains the
+                        // full
+                        // package paths of all needed class files.
+                        // First we create a new ArrayList which contains only
+                        // the full paths for the uninstall listener self; thats
+                        // the first entry of each sub ArrayList.
+                        ArrayList subContents = new ArrayList();
 
+                        // Secound put the class into uninstaller.jar
+                        Iterator listenerIter = ((List) contents).iterator();
+                        while (listenerIter.hasNext())
+                        {
+                            byte[] buffer = new byte[5120];
+                            long bytesCopied = 0;
+                            int bytesInBuffer;
+                            CustomData customData = (CustomData) listenerIter.next();
+                            // First element of the list contains the listener
+                            // class path;
+                            // remind it for later.
+                            if (customData.listenerName != null)
+                                subContents.add(customData.listenerName);
+                            Iterator liClaIter = customData.contents.iterator();
+                            while (liClaIter.hasNext())
+                            {
+                                String contentPath = (String) liClaIter.next();
+                                if (exist.contains(contentPath)) continue;
+                                exist.add(contentPath);
+                                try
+                                {
+                                    outJar.putNextEntry(new ZipEntry(contentPath));
+                                }
+                                catch (ZipException ze)
+                                { // Ignore, or ignore not ?? May be it is a
+                                    // exception because
+                                    // a doubled entry was tried, then we should
+                                    // ignore ...
+                                    Debug.trace("ZipException in writing custom data: "
+                                            + ze.getMessage());
+                                    continue;
+                                }
+                                InputStream in = getClass().getResourceAsStream("/" + contentPath);
+                                if (in != null)
+                                {
+                                    while ((bytesInBuffer = in.read(buffer)) != -1)
+                                    {
+                                        outJar.write(buffer, 0, bytesInBuffer);
+                                        bytesCopied += bytesInBuffer;
+                                    }
+                                }
+                                else
+                                    Debug.trace("custom data not found: " + contentPath);
+                                outJar.closeEntry();
+
+                            }
+                        }
+                        // Third we write the list into the
+                        // uninstaller.jar
+                        outJar.putNextEntry(new ZipEntry(key));
+                        ObjectOutputStream objOut = new ObjectOutputStream(outJar);
+                        objOut.writeObject(subContents);
+                        objOut.flush();
+                        outJar.closeEntry();
+
+                    }
+                    else
+                    {
+                        outJar.putNextEntry(new ZipEntry(key));
+                        if (contents instanceof ByteArrayOutputStream)
+                        {
+                            ((ByteArrayOutputStream) contents).writeTo(outJar);
+                        }
+                        else
+                        {
+                            ObjectOutputStream objOut = new ObjectOutputStream(outJar);
+                            objOut.writeObject(contents);
+                            objOut.flush();
+                        }
+                        outJar.closeEntry();
+                    }
+                }
+            }
+            // write the files which should be deleted by root for another user
+
+            outJar.putNextEntry(new ZipEntry(UninstallData.ROOTSCRIPT));
+            ObjectOutputStream rootStream = new ObjectOutputStream(outJar);
+
+            String rootScript = udata.getRootScript();
+
+            rootStream.writeUTF(rootScript);
+
+            rootStream.flush();
+            outJar.closeEntry();
+
+            // ***  ADDED to this point 
+
             // Cleanup
             outJar.flush();
             outJar.close();




More information about the izpack-changes mailing list