[izpack-changes] r1545 - izpack-src/trunk/src/lib/com/izforge/izpack/panels

noreply at berlios.de noreply at berlios.de
Sun Aug 27 15:25:26 CEST 2006


Author: eppelman
Date: 2006-08-27 15:25:24 +0200 (Sun, 27 Aug 2006)
New Revision: 1545

Modified:
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanelAutomationHelper.java
Log:
Added uninstall information for automated installation.

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanelAutomationHelper.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanelAutomationHelper.java	2006-08-27 13:17:27 UTC (rev 1544)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanelAutomationHelper.java	2006-08-27 13:25:24 UTC (rev 1545)
@@ -13,60 +13,62 @@
 import com.izforge.izpack.ExecutableFile;
 import com.izforge.izpack.installer.AutomatedInstallData;
 import com.izforge.izpack.installer.PanelAutomation;
+import com.izforge.izpack.installer.UninstallData;
 import com.izforge.izpack.util.Debug;
 import com.izforge.izpack.util.FileExecutor;
 import com.izforge.izpack.util.OsConstraint;
 import com.izforge.izpack.util.TargetFactory;
 import com.izforge.izpack.util.os.Shortcut;
 
-
-
 /**
  * @author marc.eppelmann
- *
+ * 
  */
 public class ShortcutPanelAutomationHelper implements PanelAutomation
 {
 
     /** the one shortcut instance for reuse in many locations */
 
-    
-    /* (non-Javadoc)
-     * @see com.izforge.izpack.installer.PanelAutomation#makeXMLData(com.izforge.izpack.installer.AutomatedInstallData, net.n3.nanoxml.XMLElement)
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.izforge.izpack.installer.PanelAutomation#makeXMLData(com.izforge.izpack.installer.AutomatedInstallData,
+     * net.n3.nanoxml.XMLElement)
      */
-    public void makeXMLData( AutomatedInstallData idata, XMLElement panelRoot )
+    public void makeXMLData(AutomatedInstallData idata, XMLElement panelRoot)
     {
-        Debug.log( this.getClass().getName() + "::entering makeXMLData()" );        
-        //ShortcutPanel.getInstance().makeXMLData(  idata, panelRoot );
-        
+        Debug.log(this.getClass().getName() + "::entering makeXMLData()");
+        // ShortcutPanel.getInstance().makeXMLData( idata, panelRoot );
+
     }
-    
-    
 
-    /* (non-Javadoc)
-     * @see com.izforge.izpack.installer.PanelAutomation#runAutomated(com.izforge.izpack.installer.AutomatedInstallData, net.n3.nanoxml.XMLElement)
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.izforge.izpack.installer.PanelAutomation#runAutomated(com.izforge.izpack.installer.AutomatedInstallData,
+     * net.n3.nanoxml.XMLElement)
      */
-    public boolean runAutomated( AutomatedInstallData installData, XMLElement panelRoot )
-    {        
+    public boolean runAutomated(AutomatedInstallData installData, XMLElement panelRoot)
+    {
         Shortcut shortcut;
 
         /**
-         * A list of ShortcutData> objects. Each object is the complete specification for one shortcut
-         * that must be created.
+         * A list of ShortcutData> objects. Each object is the complete specification for one
+         * shortcut that must be created.
          */
         Vector shortcuts = new Vector();
-        
+
         Vector execFiles = new Vector();
-        
+
         /**
-         * Holds a list of all the shortcut files that have been created. Note: this variable contains
-         * valid data only after createShortcuts() has been called. This list is created so that the
-         * files can be added to the uninstaller.
+         * Holds a list of all the shortcut files that have been created. Note: this variable
+         * contains valid data only after createShortcuts() has been called. This list is created so
+         * that the files can be added to the uninstaller.
          */
         Vector files = new Vector();
-        
-        Debug.log( this.getClass().getName() + " Entered runAutomated()");
-        
+
+        Debug.log(this.getClass().getName() + " Entered runAutomated()");
+
         try
         {
             shortcut = (Shortcut) (TargetFactory.getInstance()
@@ -85,9 +87,17 @@
         // create shortcuts, even if there was any install
         // data. Just return.
         // ----------------------------------------------------
-        if (!shortcut.supported()) { Debug.log("shortcuts not supported here"); return true; }
+        if (!shortcut.supported())
+        {
+            Debug.log("shortcuts not supported here");
+            return true;
+        }
 
-        if (!OsConstraint.oneMatchesCurrentSystem(panelRoot)) { Debug.log("Shortcuts Not oneMatchesCurrentSystem"); return true; }
+        if (!OsConstraint.oneMatchesCurrentSystem(panelRoot))
+        {
+            Debug.log("Shortcuts Not oneMatchesCurrentSystem");
+            return true;
+        }
 
         shortcuts = new Vector();
 
@@ -111,191 +121,204 @@
         // ----------------------------------------------------
         shortcutElements = panelRoot.getChildrenNamed(ShortcutPanel.AUTO_KEY_SHORTCUT);
 
-        for (int i = 0; i < shortcutElements.size(); i++)            
+        for (int i = 0; i < shortcutElements.size(); i++)
         {
-            Debug.log( this.getClass().getName() + "runAutomated:shortcutElements " + i);
+            Debug.log(this.getClass().getName() + "runAutomated:shortcutElements " + i);
             data = new ShortcutData();
             dataElement = (XMLElement) shortcutElements.elementAt(i);
 
             data.name = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_NAME);
-            data.addToGroup = Boolean.valueOf(dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_GROUP))
-                    .booleanValue();
-            
-            
+            data.addToGroup = Boolean.valueOf(
+                    dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_GROUP)).booleanValue();
+
             try
             {
-                data.type = Integer.valueOf(dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TYPE)).intValue();
+                data.type = Integer.valueOf(
+                        dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TYPE)).intValue();
             }
             catch (NumberFormatException e)
             {
-               Debug.log( "WARN: On Linux data.type is NOT an int. Ignored." );
+                Debug.log("WARN: On Linux data.type is NOT an int. Ignored.");
             }
-            
-            
+
             data.commandLine = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_COMMAND);
             data.description = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_DESCRIPTION);
             data.iconFile = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON);
-            data.iconIndex = Integer.valueOf(dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON_INDEX))
+            data.iconIndex = Integer.valueOf(
+                    dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_ICON_INDEX)).intValue();
+            data.initialState = Integer.valueOf(
+                    dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_INITIAL_STATE))
                     .intValue();
-            data.initialState = Integer.valueOf(
-                    dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_INITIAL_STATE)).intValue();
             data.target = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_TARGET);
-            data.workingDirectory = dataElement.getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_WORKING_DIR);
-            
+            data.workingDirectory = dataElement
+                    .getAttribute(ShortcutPanel.AUTO_ATTRIBUTE_WORKING_DIR);
+
             // Linux
-            data.deskTopEntryLinux_Encoding = dataElement.getAttribute( ShortcutPanel.SPEC_ATTRIBUTE_ENCODING, "");
-            data.deskTopEntryLinux_MimeType = dataElement.getAttribute( ShortcutPanel.SPEC_ATTRIBUTE_MIMETYPE, "");
-            data.deskTopEntryLinux_Terminal = dataElement.getAttribute( ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL, "");
-            data.deskTopEntryLinux_TerminalOptions = dataElement.getAttribute( ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL_OPTIONS, "");
-            data.deskTopEntryLinux_Type = dataElement.getAttribute( ShortcutPanel.SPEC_ATTRIBUTE_TYPE, "");
+            data.deskTopEntryLinux_Encoding = dataElement.getAttribute(
+                    ShortcutPanel.SPEC_ATTRIBUTE_ENCODING, "");
+            data.deskTopEntryLinux_MimeType = dataElement.getAttribute(
+                    ShortcutPanel.SPEC_ATTRIBUTE_MIMETYPE, "");
+            data.deskTopEntryLinux_Terminal = dataElement.getAttribute(
+                    ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL, "");
+            data.deskTopEntryLinux_TerminalOptions = dataElement.getAttribute(
+                    ShortcutPanel.SPEC_ATTRIBUTE_TERMINAL_OPTIONS, "");
+            data.deskTopEntryLinux_Type = dataElement.getAttribute(
+                    ShortcutPanel.SPEC_ATTRIBUTE_TYPE, "");
 
-            data.deskTopEntryLinux_URL = dataElement.getAttribute( ShortcutPanel.SPEC_ATTRIBUTE_URL, "");
+            data.deskTopEntryLinux_URL = dataElement.getAttribute(ShortcutPanel.SPEC_ATTRIBUTE_URL,
+                    "");
 
             data.deskTopEntryLinux_X_KDE_SubstituteUID = dataElement.getAttribute(
-            ShortcutPanel.SPEC_ATTRIBUTE_KDE_SUBST_UID, "");
+                    ShortcutPanel.SPEC_ATTRIBUTE_KDE_SUBST_UID, "");
 
-            data.createForAll = new Boolean(dataElement.getAttribute(ShortcutPanel.CREATE_FOR_ALL, "false"));
-            data.userType = Integer.valueOf( dataElement.getAttribute( ShortcutPanel.USER_TYPE, Integer.toString( Shortcut.CURRENT_USER) ) ).intValue();
-            //END LINUX
+            data.createForAll = new Boolean(dataElement.getAttribute(ShortcutPanel.CREATE_FOR_ALL,
+                    "false"));
+            data.userType = Integer.valueOf(
+                    dataElement.getAttribute(ShortcutPanel.USER_TYPE, Integer
+                            .toString(Shortcut.CURRENT_USER))).intValue();
+            // END LINUX
 
-            shortcuts.add( data );
+            shortcuts.add(data);
         }
 
-        
         System.out.print("[ creating shortcuts ");
-           
 
-           // ShortcutData data;
+        // ShortcutData data;
 
-            for (int i = 0; i < shortcuts.size(); i++)
+        for (int i = 0; i < shortcuts.size(); i++)
+        {
+            data = (ShortcutData) shortcuts.elementAt(i);
+
+            try
             {
-                data = (ShortcutData) shortcuts.elementAt(i);
+                groupName = groupName + data.subgroup;
+                shortcut.setUserType(data.userType);
+                shortcut.setLinkName(data.name);
+                shortcut.setLinkType(data.type);
+                shortcut.setArguments(data.commandLine);
+                shortcut.setDescription(data.description);
+                shortcut.setIconLocation(data.iconFile, data.iconIndex);
 
-                try
-                {
-                    groupName = groupName + data.subgroup;
-                    shortcut.setUserType( data.userType );
-                    shortcut.setLinkName(data.name);
-                    shortcut.setLinkType(data.type);
-                    shortcut.setArguments(data.commandLine);
-                    shortcut.setDescription(data.description);
-                    shortcut.setIconLocation(data.iconFile, data.iconIndex);
+                shortcut.setShowCommand(data.initialState);
+                shortcut.setTargetPath(data.target);
+                shortcut.setWorkingDirectory(data.workingDirectory);
+                shortcut.setEncoding(data.deskTopEntryLinux_Encoding);
+                shortcut.setMimetype(data.deskTopEntryLinux_MimeType);
 
-                    shortcut.setShowCommand(data.initialState);
-                    shortcut.setTargetPath(data.target);
-                    shortcut.setWorkingDirectory(data.workingDirectory);
-                    shortcut.setEncoding(data.deskTopEntryLinux_Encoding);
-                    shortcut.setMimetype(data.deskTopEntryLinux_MimeType);
+                shortcut.setTerminal(data.deskTopEntryLinux_Terminal);
+                shortcut.setTerminalOptions(data.deskTopEntryLinux_TerminalOptions);
+                shortcut.setType(data.deskTopEntryLinux_Type);
+                shortcut.setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID);
+                shortcut.setURL(data.deskTopEntryLinux_URL);
+                shortcut.setCreateForAll(data.createForAll);
 
-                    shortcut.setTerminal(data.deskTopEntryLinux_Terminal);
-                    shortcut.setTerminalOptions(data.deskTopEntryLinux_TerminalOptions);
-                    shortcut.setType(data.deskTopEntryLinux_Type);
-                    shortcut.setKdeSubstUID(data.deskTopEntryLinux_X_KDE_SubstituteUID);
-                    shortcut.setURL(data.deskTopEntryLinux_URL);
-                    shortcut.setCreateForAll(data.createForAll);
+                if (data.addToGroup)
+                {
+                    shortcut.setProgramGroup(groupName);
+                }
+                else
+                {
+                    shortcut.setProgramGroup("");
+                }
 
-                    if (data.addToGroup)
+                try
+                {
+                    // ----------------------------------------------
+                    // save the shortcut only if it is either not on
+                    // the desktop or if it is on the desktop and
+                    // the user has signalled that it is ok to place
+                    // shortcuts on the desktop.
+                    // ----------------------------------------------
+                    if ((data.type != Shortcut.DESKTOP) || ((data.type == Shortcut.DESKTOP)))
                     {
-                        shortcut.setProgramGroup(groupName);
-                    }
-                    else
-                    {
-                        shortcut.setProgramGroup("");
-                    }
+                        // save the shortcut
 
-                    try
-                    {
-                        // ----------------------------------------------
-                        // save the shortcut only if it is either not on
-                        // the desktop or if it is on the desktop and
-                        // the user has signalled that it is ok to place
-                        // shortcuts on the desktop.
-                        // ----------------------------------------------
-                        if ((data.type != Shortcut.DESKTOP)
-                                || ((data.type == Shortcut.DESKTOP) ))
-                        {
-                            // save the shortcut
-                            
-                            System.out.print(".");
-                            System.out.flush();
-                            
-                            
-                            shortcut.save();
+                        System.out.print(".");
+                        System.out.flush();
 
-                            // add the file and directory name to the file list
-                            String fileName = shortcut.getFileName();
-                            files.add(0, fileName);
+                        shortcut.save();
 
-                            File file = new File(fileName);
-                            File base = new File(shortcut.getBasePath());
-                            Vector intermediates = new Vector();
+                        // add the file and directory name to the file list
+                        String fileName = shortcut.getFileName();
+                        files.add(0, fileName);
 
-                            // String directoryName = shortcut.getDirectoryCreated ();
-                            execFiles.add(new ExecutableFile(fileName, ExecutableFile.UNINSTALL,
-                                    ExecutableFile.IGNORE, new ArrayList(), false));
+                        File file = new File(fileName);
+                        File base = new File(shortcut.getBasePath());
+                        Vector intermediates = new Vector();
 
-                            files.add(fileName);
+                        // String directoryName = shortcut.getDirectoryCreated ();
+                        execFiles.add(new ExecutableFile(fileName, ExecutableFile.UNINSTALL,
+                                ExecutableFile.IGNORE, new ArrayList(), false));
 
-                            while ((file = file.getParentFile()) != null)
+                        files.add(fileName);
+
+                        while ((file = file.getParentFile()) != null)
+                        {
+                            if (file.equals(base))
                             {
-                                if (file.equals(base))
-                                {
-                                    break;
-                                }
-
-                                intermediates.add(file);
+                                break;
                             }
 
-                            if (file != null)
+                            intermediates.add(file);
+                        }
+
+                        if (file != null)
+                        {
+                            Enumeration filesEnum = intermediates.elements();
+
+                            while (filesEnum.hasMoreElements())
                             {
-                                Enumeration filesEnum = intermediates.elements();
-
-                                while (filesEnum.hasMoreElements())
-                                {
-                                    files.add(0, filesEnum.nextElement().toString());
-                                }
+                                files.add(0, filesEnum.nextElement().toString());
                             }
                         }
                     }
-                    catch (Exception exception)
-                    {}
                 }
-                catch (Throwable exception)
-                {
-                    continue;
-                }
+                catch (Exception exception)
+                {}
             }
+            catch (Throwable exception)
+            {
+                continue;
+            }
+        }
 
-            // }
-            //
-            try
+        // }
+        //
+        try
+        {
+            if (execFiles != null)
             {
-                if (execFiles != null)
-                {
-                    FileExecutor executor = new FileExecutor(execFiles);
+                FileExecutor executor = new FileExecutor(execFiles);
 
-                    // 
-                    // TODO: Hi Guys,
-                    // TODO The following commented-out line sometimes produces an uncatchable
-                    // nullpointer Exception!
-                    // TODO evaluate for what reason the files should exec.
-                    // TODO if there is a serious explanation, why to do that,
-                    // TODO the code must be more robust
-                    // evaluate executor.executeFiles( ExecutableFile.NEVER, null );
-                }
+                // 
+                // TODO: Hi Guys,
+                // TODO The following commented-out line sometimes produces an uncatchable
+                // nullpointer Exception!
+                // TODO evaluate for what reason the files should exec.
+                // TODO if there is a serious explanation, why to do that,
+                // TODO the code must be more robust
+                // evaluate executor.executeFiles( ExecutableFile.NEVER, null );
             }
-            catch (NullPointerException nep)
-            {
-                nep.printStackTrace();
-            }
-            catch (RuntimeException cannot)
-            {
-                cannot.printStackTrace();
-            }
+        }
+        catch (NullPointerException nep)
+        {
+            nep.printStackTrace();
+        }
+        catch (RuntimeException cannot)
+        {
+            cannot.printStackTrace();
+        }
 
-            // /////parent.unlockNextButton();
-        System.out.println( " done. ]");
+        UninstallData uninstallData = UninstallData.getInstance();
 
+        for (int i = 0; i < files.size(); i++)
+        {
+            uninstallData.addFile((String) files.elementAt(i));
+        }
+
+        // /////parent.unlockNextButton();
+        System.out.println(" done. ]");
+
         return true;
     }
 




More information about the izpack-changes mailing list