Lines 19-24
Link Here
|
19 |
// (NbBundle.getLocalizedValue is OK here.) |
19 |
// (NbBundle.getLocalizedValue is OK here.) |
20 |
|
20 |
|
21 |
import java.io.File; |
21 |
import java.io.File; |
|
|
22 |
import java.io.FileInputStream; |
22 |
import java.io.IOException; |
23 |
import java.io.IOException; |
23 |
import java.io.InputStream; |
24 |
import java.io.InputStream; |
24 |
import java.security.AllPermission; |
25 |
import java.security.AllPermission; |
Lines 28-33
Link Here
|
28 |
import java.util.ArrayList; |
29 |
import java.util.ArrayList; |
29 |
import java.util.Arrays; |
30 |
import java.util.Arrays; |
30 |
import java.util.Collections; |
31 |
import java.util.Collections; |
|
|
32 |
import java.util.Enumeration; |
31 |
import java.util.HashMap; |
33 |
import java.util.HashMap; |
32 |
import java.util.HashSet; |
34 |
import java.util.HashSet; |
33 |
import java.util.Iterator; |
35 |
import java.util.Iterator; |
Lines 43-48
Link Here
|
43 |
import java.util.jar.JarFile; |
45 |
import java.util.jar.JarFile; |
44 |
import java.util.jar.Manifest; |
46 |
import java.util.jar.Manifest; |
45 |
import java.util.zip.ZipEntry; |
47 |
import java.util.zip.ZipEntry; |
|
|
48 |
import org.openide.xml.XMLUtil; |
46 |
import org.netbeans.JarClassLoader; |
49 |
import org.netbeans.JarClassLoader; |
47 |
import org.netbeans.ProxyClassLoader; |
50 |
import org.netbeans.ProxyClassLoader; |
48 |
import org.openide.ErrorManager; |
51 |
import org.openide.ErrorManager; |
Lines 51-56
Link Here
|
51 |
import org.openide.modules.SpecificationVersion; |
54 |
import org.openide.modules.SpecificationVersion; |
52 |
import org.openide.util.NbBundle; |
55 |
import org.openide.util.NbBundle; |
53 |
import org.openide.util.WeakSet; |
56 |
import org.openide.util.WeakSet; |
|
|
57 |
import org.w3c.dom.Document; |
58 |
import org.w3c.dom.Element; |
59 |
import org.w3c.dom.NamedNodeMap; |
60 |
import org.w3c.dom.Node; |
61 |
import org.w3c.dom.NodeList; |
62 |
import org.xml.sax.InputSource; |
63 |
import org.xml.sax.SAXException; |
54 |
|
64 |
|
55 |
/** Object representing one module, possibly installed. |
65 |
/** Object representing one module, possibly installed. |
56 |
* Responsible for opening of module JAR file; reading |
66 |
* Responsible for opening of module JAR file; reading |
Lines 68-73
Link Here
|
68 |
public static final String PROP_VALID = "valid"; // NOI18N |
78 |
public static final String PROP_VALID = "valid"; // NOI18N |
69 |
public static final String PROP_PROBLEMS = "problems"; // NOI18N |
79 |
public static final String PROP_PROBLEMS = "problems"; // NOI18N |
70 |
|
80 |
|
|
|
81 |
private static final String ELEMENT_MODULES = "installed_modules"; // NOI18N |
82 |
private static final String ELEMENT_MODULE = "module"; // NOI18N |
83 |
private static final String ATTR_CODENAMEBASE = "codename"; // NOI18N |
84 |
private static final String ELEMENT_VERSION = "module_version"; // NOI18N |
85 |
private static final String ATTR_VERSION = "specification_version"; // NOI18N |
86 |
private static final String ATTR_ORIGIN = "origin"; // NOI18N |
87 |
private static final String ATTR_LAST = "last"; // NOI18N |
88 |
private static final String ATTR_INSTALL = "install_time"; // NOI18N |
89 |
private static final String ELEMENT_FILE = "file"; // NOI18N |
90 |
private static final String ATTR_FILE_NAME = "name"; // NOI18N |
91 |
private static final String ATTR_CRC = "crc"; // NOI18N |
92 |
private static final String UPDATE_TRACKING = "update_tracking"; // NOI18N |
93 |
|
71 |
/** manager which owns this module */ |
94 |
/** manager which owns this module */ |
72 |
private final ModuleManager mgr; |
95 |
private final ModuleManager mgr; |
73 |
/** event logging (should not be much here) */ |
96 |
/** event logging (should not be much here) */ |
Lines 1076-1083
Link Here
|
1076 |
OneModuleClassLoader l = (OneModuleClassLoader)it.next(); |
1099 |
OneModuleClassLoader l = (OneModuleClassLoader)it.next(); |
1077 |
l.releaseLocks(); |
1100 |
l.releaseLocks(); |
1078 |
} |
1101 |
} |
|
|
1102 |
Util.err.log ("Module " + getCodeNameBase () + " is being deleted. All module's file will be removed."); |
1103 |
removeModuleFiles (); |
1079 |
moduleJARs.remove(jar); |
1104 |
moduleJARs.remove(jar); |
1080 |
} |
1105 |
} |
|
|
1106 |
|
1107 |
// support for module uninstall |
1108 |
|
1109 |
private void removeModuleFiles () { |
1110 |
Iterator it = clusters ().iterator (); |
1111 |
while (it.hasNext ()) { |
1112 |
removeModuleFilesInCluster ((File)it.next ()); |
1113 |
} |
1114 |
return; |
1115 |
} |
1116 |
|
1117 |
private void removeModuleFilesInCluster (File cluster) { |
1118 |
File updateTracking = new File (cluster + File.separator + UPDATE_TRACKING); |
1119 |
if (!updateTracking.isDirectory ()) return; |
1120 |
File moduleUpdateTracking = new File (updateTracking, getCodeNameBase ().replace ('.', '-') + ".xml"); |
1121 |
Util.err.log (moduleUpdateTracking + " found."); |
1122 |
if (!moduleUpdateTracking.exists ()) return; |
1123 |
Set/*<String>*/ moduleFiles = getModuleFiles (moduleUpdateTracking); |
1124 |
Iterator it = moduleFiles.iterator (); |
1125 |
while (it.hasNext ()) { |
1126 |
String fileName = (String) it.next (); |
1127 |
File file = new File (cluster + File.separator + fileName); |
1128 |
assert file.exists () : "File " + file + " exists."; |
1129 |
Util.err.log ("File " + file + " is being deleted."); |
1130 |
file.delete (); |
1131 |
} |
1132 |
} |
1133 |
|
1134 |
// XXX replace with file locator |
1135 |
private static File getPlatformDir () { |
1136 |
return new File (System.getProperty ("netbeans.home")); // NOI18N |
1137 |
} |
1138 |
|
1139 |
private static List/*<File>*/ clusters () { |
1140 |
ArrayList/*<File>*/ files = new ArrayList (); |
1141 |
|
1142 |
File ud = new File (System.getProperty ("netbeans.user")); // NOI18N |
1143 |
files.add (ud); |
1144 |
|
1145 |
String dirs = System.getProperty ("netbeans.dirs"); // NOI18N |
1146 |
|
1147 |
if (dirs != null) { |
1148 |
Enumeration en = new StringTokenizer (dirs, File.pathSeparator); |
1149 |
while (en.hasMoreElements ()) { |
1150 |
File f = new File ((String)en.nextElement ()); |
1151 |
files.add (f); |
1152 |
} |
1153 |
} |
1154 |
|
1155 |
|
1156 |
File id = getPlatformDir (); |
1157 |
files.add (id); |
1158 |
|
1159 |
return java.util.Collections.unmodifiableList (files); |
1160 |
} |
1161 |
|
1162 |
private Set/*<String>*/ getModuleFiles (File moduleUpdateTracking) { |
1163 |
return readFromUpdateTracking (moduleUpdateTracking); |
1164 |
} |
1165 |
|
1166 |
private Set/*<String>*/ readFromUpdateTracking (File moduleUpdateTracking) { |
1167 |
Document document = null; |
1168 |
InputStream is; |
1169 |
try { |
1170 |
is = new FileInputStream (moduleUpdateTracking); |
1171 |
InputSource xmlInputSource = new InputSource (is); |
1172 |
document = XMLUtil.parse (xmlInputSource, false, false, null, org.openide.xml.EntityCatalog.getDefault ()); |
1173 |
if (is != null) { |
1174 |
is.close (); |
1175 |
} |
1176 |
} catch (SAXException saxe) { |
1177 |
ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, saxe); |
1178 |
return Collections.EMPTY_SET; |
1179 |
} catch (IOException ioe) { |
1180 |
ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ioe); |
1181 |
} |
1182 |
|
1183 |
assert document.getDocumentElement () != null : "File " + moduleUpdateTracking + " must contain <module> element."; |
1184 |
return readModuleElement (document.getDocumentElement ()); |
1185 |
} |
1186 |
|
1187 |
private Set/*<String>*/ readModuleElement (Element element) { |
1188 |
Set/*<String>*/ files = new HashSet (); |
1189 |
assert ELEMENT_MODULE.equals (element.getTagName ()) : "The root element is: " + ELEMENT_MODULE + " but was: " + element.getTagName (); |
1190 |
NodeList listModuleVersions = element.getElementsByTagName (ELEMENT_VERSION); |
1191 |
for (int i = 0; i < listModuleVersions.getLength (); i++) { |
1192 |
files.addAll (readModuleVersion (listModuleVersions.item (i))); |
1193 |
} |
1194 |
return files; |
1195 |
} |
1196 |
|
1197 |
private Set/*<String>*/ readModuleVersion (Node version) { |
1198 |
Node attrLast = version.getAttributes ().getNamedItem (ATTR_LAST); |
1199 |
assert attrLast != null : "ELEMENT_VERSION must contain ATTR_LAST attribute."; |
1200 |
if (Boolean.valueOf (attrLast.getNodeValue ()).booleanValue ()) { |
1201 |
return readModuleFiles (version); |
1202 |
} else { |
1203 |
return Collections.EMPTY_SET; |
1204 |
} |
1205 |
} |
1206 |
|
1207 |
private Set/*<String>*/ readModuleFiles (Node version) { |
1208 |
Set/*<String>*/ files = new HashSet (); |
1209 |
NodeList fileNodes = version.getChildNodes (); |
1210 |
for (int i = 0; i < fileNodes.getLength (); i++) { |
1211 |
if (fileNodes.item (i).hasAttributes ()) { |
1212 |
NamedNodeMap map = fileNodes.item (i).getAttributes (); |
1213 |
files.add (map.getNamedItem (ATTR_FILE_NAME).getNodeValue ()); |
1214 |
} |
1215 |
} |
1216 |
return files; |
1217 |
} |
1218 |
|
1219 |
// end of module uninstall |
1081 |
|
1220 |
|
1082 |
/** Get the JAR manifest. |
1221 |
/** Get the JAR manifest. |
1083 |
* Should never be null, even if disabled. |
1222 |
* Should never be null, even if disabled. |