root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / event / AntActionUninstallerListener.java @ 15280
History | View | Annotate | Download (5.34 KB)
1 | 15280 | rgaitan | /*
|
---|---|---|---|
2 | * $Id: AntActionUninstallerListener.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
||
3 | * IzPack
|
||
4 | * Copyright (C) 2004 Klaus Bartz
|
||
5 | *
|
||
6 | * File : AntActionInstallerListener.java
|
||
7 | * Description : Uninstaller listener for ant custom actions.
|
||
8 | * Author's email : bartzkau@users.berlios.de
|
||
9 | * Website : http://www.izforge.com
|
||
10 | *
|
||
11 | *
|
||
12 | * This program is free software; you can redistribute it and/or
|
||
13 | * modify it under the terms of the GNU General Public License
|
||
14 | * as published by the Free Software Foundation; either version 2
|
||
15 | * of the License, or any later version.
|
||
16 | *
|
||
17 | * This program is distributed in the hope that it will be useful,
|
||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
20 | * GNU General Public License for more details.
|
||
21 | *
|
||
22 | * You should have received a copy of the GNU General Public License
|
||
23 | * along with this program; if not, write to the Free Software
|
||
24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
25 | */
|
||
26 | package com.izforge.izpack.event; |
||
27 | |||
28 | import java.io.File; |
||
29 | import java.io.InputStream; |
||
30 | import java.io.ObjectInputStream; |
||
31 | import java.util.ArrayList; |
||
32 | import java.util.Iterator; |
||
33 | import java.util.List; |
||
34 | |||
35 | import com.izforge.izpack.util.AbstractUIProgressHandler; |
||
36 | import com.izforge.izpack.util.IoHelper; |
||
37 | |||
38 | /**
|
||
39 | * Uninstaller listener for performing ANT actions at uninstall time.
|
||
40 | * The definition of what should be done here will be made in a
|
||
41 | * specification file that is referenced by the resource
|
||
42 | * id "AntActionsSpec.xml". There should be an entry in
|
||
43 | * the install.xml file in the sub ELEMENT "res" of
|
||
44 | * ELEMENT "resources" that references it. The specification
|
||
45 | * of the xml file is done in the DTD antaction.dtd.
|
||
46 | * The xml file may contain an ELEMENT "uninstall_target" that
|
||
47 | * should be performed for uninstalling purposes.
|
||
48 | *
|
||
49 | * @author Klaus Bartz
|
||
50 | */
|
||
51 | public class AntActionUninstallerListener extends SimpleUninstallerListener |
||
52 | { |
||
53 | /** Ant actions to be performed after deletion */
|
||
54 | private List antActions = null; |
||
55 | |||
56 | /**
|
||
57 | * Default constructor
|
||
58 | */
|
||
59 | public AntActionUninstallerListener()
|
||
60 | { |
||
61 | super();
|
||
62 | // TODO Auto-generated constructor stub
|
||
63 | } |
||
64 | |||
65 | /* (non-Javadoc)
|
||
66 | * @see com.izforge.izpack.uninstaller.UninstallerListener#beforeDeletion(java.util.List, com.izforge.izpack.util.AbstractUIProgressHandler)
|
||
67 | */
|
||
68 | public void beforeDeletion(List files, AbstractUIProgressHandler handler) |
||
69 | throws Exception |
||
70 | { |
||
71 | // Load the defined actions.
|
||
72 | InputStream in = getClass().getResourceAsStream("/antActions"); |
||
73 | if( in == null ) |
||
74 | { // No actions, nothing todo.
|
||
75 | return;
|
||
76 | } |
||
77 | ObjectInputStream objIn = new ObjectInputStream(in); |
||
78 | // The actions are stored at installation time as list of AntAction objects.
|
||
79 | // See AntActionInstallerListener.afterPacks.
|
||
80 | List allActions = (List)objIn.readObject(); |
||
81 | objIn.close(); |
||
82 | in.close(); |
||
83 | ArrayList befDel = new ArrayList(); |
||
84 | antActions = new ArrayList(); |
||
85 | Iterator iter = allActions.iterator();
|
||
86 | // There are two possible orders; before and after deletion.
|
||
87 | // Now we assign the actions to two different lists, the
|
||
88 | // local "before" list which we perform after the scan and
|
||
89 | // the class member "antActions" which should contain the
|
||
90 | // "afterdeletion" actions. Additionally we should save needed
|
||
91 | // files like the properties file for this order because if they're
|
||
92 | // part of the pack the'll be lost after the deletion has been performed.
|
||
93 | while( iter.hasNext())
|
||
94 | { |
||
95 | AntAction action = (AntAction) iter.next(); |
||
96 | //
|
||
97 | if( action.getUninstallOrder().equals(ActionBase.BEFOREDELETION))
|
||
98 | befDel.add(action); |
||
99 | else
|
||
100 | {// We need the build and the properties file(s) outside the install dir.
|
||
101 | File tmpFile = IoHelper.copyToTempFile(action.getBuildFile(), ".xml" ); |
||
102 | action.setBuildFile(tmpFile.getCanonicalPath()); |
||
103 | List props = action.getPropertyFiles();
|
||
104 | if( props != null ) |
||
105 | { |
||
106 | Iterator iter2 = props.iterator();
|
||
107 | ArrayList newProps = new ArrayList(); |
||
108 | while( iter2.hasNext())
|
||
109 | { |
||
110 | String propName = (String) iter2.next(); |
||
111 | File propFile = IoHelper.copyToTempFile(propName, ".properties" ); |
||
112 | newProps.add(propFile.getCanonicalPath()); |
||
113 | } |
||
114 | action.setPropertyFiles(newProps); |
||
115 | } |
||
116 | antActions.add(action); |
||
117 | } |
||
118 | } |
||
119 | // Perform the actions with the order "beforedeletion".
|
||
120 | if( befDel.size() > 0) |
||
121 | { |
||
122 | for (int i = 0; i < befDel.size(); i++) |
||
123 | { |
||
124 | AntAction act = (AntAction)befDel.get(i); |
||
125 | act.performUninstallAction(); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | } |
||
130 | |||
131 | /* (non-Javadoc)
|
||
132 | * @see com.izforge.izpack.uninstaller.UninstallerListener#afterDeletion(java.util.List, com.izforge.izpack.util.AbstractUIProgressHandler)
|
||
133 | */
|
||
134 | public void afterDeletion(List files, AbstractUIProgressHandler handler) |
||
135 | throws Exception |
||
136 | { |
||
137 | if( antActions != null && antActions.size() > 0 ) |
||
138 | { // There are actions of the order "afterdeletion".
|
||
139 | for (int i = 0; i < antActions.size(); i++) |
||
140 | { |
||
141 | AntAction act = (AntAction)antActions.get(i); |
||
142 | act.performUninstallAction(); |
||
143 | } |
||
144 | |||
145 | } |
||
146 | } |
||
147 | |||
148 | |||
149 | } |