<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -30,9 +30,12 @@ import com.izforge.izpack.util.*;
 import com.izforge.izpack.adaptator.IXMLElement;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -380,6 +383,13 @@ public class AntActionInstallerListener extends SimpleInstallerListener
             act.addUninstallTarget(spec.getRequiredAttribute(utargEl, ActionBase.NAME));
         }
 
+        // see if this was an build_resource and there were uninstall actions
+        if (null != buildResource &amp;&amp;  act.getUninstallTargets().size() &gt; 0)
+        {
+            // We need to add the build_resource file to the uninstaller
+            addBuildResourceToUninstallerData(buildResource);
+        }
+
         return act;
     }
 
@@ -435,4 +445,29 @@ public class AntActionInstallerListener extends SimpleInstallerListener
         }
         return buildResource;
     }
+
+    private void addBuildResourceToUninstallerData(String buildResource) throws InstallerException {
+        byte[] content = null;
+        File buildFile = new File(buildResource);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream((int) buildFile.length());
+        BufferedInputStream bis = null;
+        try {
+            bis = new BufferedInputStream(new FileInputStream(buildFile));
+            int c;
+            while (-1 != (c = bis.read())) {
+                bos.write(c);
+            }
+            content = bos.toByteArray();
+            UninstallData.getInstance().addAdditionalData(&quot;build_resource&quot;, content);
+        } catch (Exception x) {
+            throw new InstallerException(&quot;Failed to add buildfile_resource to uninstaller&quot;, x);
+        } finally {
+            try {
+                bis.close();
+                bos.close();
+            } catch (IOException iOException) {
+                // Ignore the error
+            }
+        }
+    }
 }</diff>
      <filename>src/lib/com/izforge/izpack/event/AntActionInstallerListener.java</filename>
    </modified>
    <modified>
      <diff>@@ -23,6 +23,7 @@ package com.izforge.izpack.event;
 import com.izforge.izpack.util.AbstractUIProgressHandler;
 import com.izforge.izpack.util.IoHelper;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
@@ -65,6 +66,26 @@ public class AntActionUninstallerListener extends SimpleUninstallerListener
      */
     public void beforeDeletion(List files, AbstractUIProgressHandler handler) throws Exception
     {
+        String buildResource = null;
+        // See if we have an embedded build_resource.  If so, it will be stored
+        //  under the /build_resource stream
+        InputStream is = getClass().getResourceAsStream(&quot;/build_resource&quot;);
+        if (null != is)
+        {
+            // There is an embedded build_resource.  The stream will contain a byte array
+            //  of the contents of the embedded build_resouce.
+            ObjectInputStream ois = new ObjectInputStream(is);
+            byte[] content = (byte[]) ois.readObject();
+            if (null != content)
+            {
+                // Save it to a temporary file
+                ByteArrayInputStream bin = new ByteArrayInputStream(content);
+                File buildFile = IoHelper.copyToTempFile(bin, &quot;xml&quot;, null);
+                buildResource = buildFile.getAbsolutePath();
+            }
+            ois.close();
+            is.close();
+        }
         // Load the defined actions.
         InputStream in = getClass().getResourceAsStream(&quot;/antActions&quot;);
         if (in == null)
@@ -92,6 +113,12 @@ public class AntActionUninstallerListener extends SimpleUninstallerListener
         while (iter.hasNext())
         {
             AntAction action = (AntAction) iter.next();
+            // See if we need to set the action with the build_resource that
+            //  we extracted
+            if (null != buildResource) {
+                // We do
+                action.setBuildFile(buildResource);
+            }
             // 
             if (action.getUninstallOrder().equals(ActionBase.BEFOREDELETION))
             {
@@ -100,8 +127,14 @@ public class AntActionUninstallerListener extends SimpleUninstallerListener
             else
             {// We need the build and the properties file(s) outside the
                 // install dir.
-                File tmpFile = IoHelper.copyToTempFile(action.getBuildFile(), &quot;.xml&quot;);
-                action.setBuildFile(tmpFile.getCanonicalPath());
+                if (null == buildResource)
+                {
+                    // We have not copied a build_resource to a temporary file
+                    //  so now copy the local build file to a temporary file
+                    //  and set it as the build file for the action
+                    File tmpFile = IoHelper.copyToTempFile(action.getBuildFile(), &quot;.xml&quot;);
+                    action.setBuildFile(tmpFile.getCanonicalPath());
+                }
                 List&lt;String&gt; props = action.getPropertyFiles();
                 if (props != null)
                 {</diff>
      <filename>src/lib/com/izforge/izpack/event/AntActionUninstallerListener.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b7a13d7028f817feca2e9c15140ba9341bcac4ae</id>
    </parent>
  </parents>
  <author>
    <name>jponge</name>
    <email>jponge@7d736ef5-cfd4-0310-9c9a-b52d5c14b761</email>
  </author>
  <url>http://github.com/jponge/izpack/commit/2f883664052b40b014230e32499976f00833f99b</url>
  <id>2f883664052b40b014230e32499976f00833f99b</id>
  <committed-date>2009-06-16T00:46:24-07:00</committed-date>
  <authored-date>2009-06-16T00:46:24-07:00</authored-date>
  <message>Issue: IZPACK-158
--
Modified to check to see if there are uninstaller actions and an internal build script is being used.  If so, the build script is
stored as a resource in the unisntaller.  The uninstaller first checks for this resource and if found, extracts the build script
to a temporary file and then updates all of the ant actions to reference this temporary file as their build script.

git-svn-id: https://svn.codehaus.org/izpack/izpack-src/branches/4.3@2799 7d736ef5-cfd4-0310-9c9a-b52d5c14b761</message>
  <tree>10131f121f9656cb76c5d7b253190e474a88a01c</tree>
  <committer>
    <name>jponge</name>
    <email>jponge@7d736ef5-cfd4-0310-9c9a-b52d5c14b761</email>
  </committer>
</commit>
