Revision 2291
trunk/frameworks/_fwAndami/.classpath | ||
---|---|---|
5 | 5 |
<classpathentry kind="lib" path="lib/castor-0.9.5.3-xml.jar"/> |
6 | 6 |
<classpathentry kind="lib" path="lib/xercesImpl.jar"/> |
7 | 7 |
<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/> |
8 |
<classpathentry kind="lib" path="lib/javaws.jar"/> |
|
9 | 8 |
<classpathentry sourcepath="/Utiles/src" kind="lib" path="lib/iver-utiles.jar"/> |
10 |
<classpathentry kind="lib" path="andami.jar"/> |
|
11 | 9 |
<classpathentry kind="lib" path="lib/tempFileManager.jar"/> |
12 | 10 |
<classpathentry kind="lib" path="lib/xml-apis.jar"/> |
13 | 11 |
<classpathentry kind="output" path="bin"/> |
trunk/frameworks/_fwAndami/src/com/iver/andami/Launcher.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.andami; |
42 | 42 |
|
43 |
import java.awt.Dimension; |
|
44 | 43 |
import java.awt.EventQueue; |
45 | 44 |
import java.awt.Toolkit; |
46 |
import java.io.BufferedInputStream; |
|
47 |
import java.io.BufferedOutputStream; |
|
48 | 45 |
import java.io.File; |
49 | 46 |
import java.io.FileFilter; |
50 |
import java.io.FileInputStream; |
|
51 | 47 |
import java.io.FileNotFoundException; |
52 |
import java.io.FileOutputStream; |
|
53 | 48 |
import java.io.FileReader; |
54 | 49 |
import java.io.FileWriter; |
55 | 50 |
import java.io.FilenameFilter; |
56 | 51 |
import java.io.IOException; |
57 |
import java.io.InputStream; |
|
58 | 52 |
import java.lang.reflect.InvocationTargetException; |
59 | 53 |
import java.net.MalformedURLException; |
60 | 54 |
import java.net.URL; |
61 |
import java.net.URLConnection; |
|
62 | 55 |
import java.util.ArrayList; |
63 | 56 |
import java.util.Comparator; |
64 |
import java.util.Date; |
|
65 | 57 |
import java.util.HashMap; |
66 | 58 |
import java.util.HashSet; |
67 | 59 |
import java.util.Iterator; |
68 | 60 |
import java.util.Locale; |
69 |
import java.util.Properties; |
|
70 | 61 |
import java.util.TreeMap; |
71 | 62 |
|
72 |
import javax.jnlp.BasicService; |
|
73 |
import javax.jnlp.ServiceManager; |
|
74 |
import javax.jnlp.UnavailableServiceException; |
|
75 | 63 |
import javax.swing.ImageIcon; |
76 | 64 |
import javax.swing.JComponent; |
77 |
import javax.swing.JDialog; |
|
78 | 65 |
import javax.swing.SwingUtilities; |
79 | 66 |
import javax.swing.UIManager; |
80 | 67 |
|
... | ... | |
89 | 76 |
import com.iver.andami.config.generate.AndamiConfig; |
90 | 77 |
import com.iver.andami.config.generate.Plugin; |
91 | 78 |
import com.iver.andami.messages.Messages; |
92 |
import com.iver.andami.messages.NotificationManager; |
|
93 | 79 |
import com.iver.andami.plugins.PluginClassLoader; |
94 | 80 |
import com.iver.andami.plugins.config.generate.ActionTool; |
95 | 81 |
import com.iver.andami.plugins.config.generate.Depends; |
... | ... | |
214 | 200 |
splashWindow = new SplashWindow(null); |
215 | 201 |
|
216 | 202 |
// TODO Buscar actualizaciones de los plugins |
217 |
downloadExtensions(andamiConfig.getPluginsDirectory()); |
|
218 | 203 |
|
219 | 204 |
// Se leen los config.xml de los plugins -----++++ |
220 | 205 |
loadPlugins(andamiConfig.getPluginsDirectory()); |
... | ... | |
1155 | 1140 |
/** |
1156 | 1141 |
* DOCUMENT ME! |
1157 | 1142 |
* |
1158 |
* @param extDir DOCUMENT ME! |
|
1159 |
*/ |
|
1160 |
private static void downloadExtensions(String extDir) { |
|
1161 |
java.util.Date fechaActual = null; |
|
1162 |
|
|
1163 |
try { |
|
1164 |
if (System.getProperty("javawebstart.version") != null) { |
|
1165 |
//Obtenemos la URL del servidor |
|
1166 |
BasicService bs = (BasicService) ServiceManager.lookup( |
|
1167 |
"javax.jnlp.BasicService"); |
|
1168 |
URL baseURL = bs.getCodeBase(); |
|
1169 |
|
|
1170 |
//Se descargan las extensiones |
|
1171 |
SplashWindow.process(5, |
|
1172 |
"Descargando las extensiones desde " + baseURL + " a " + |
|
1173 |
extDir); |
|
1174 |
|
|
1175 |
URL url = new URL(baseURL + "extensiones.zip"); |
|
1176 |
URLConnection connection = url.openConnection(); |
|
1177 |
|
|
1178 |
System.out.println(url.toExternalForm() + ":"); |
|
1179 |
System.out.println(" Content Type: " + |
|
1180 |
connection.getContentType()); |
|
1181 |
System.out.println(" Content Length: " + |
|
1182 |
connection.getContentLength()); |
|
1183 |
System.out.println(" Last Modified: " + |
|
1184 |
new Date(connection.getLastModified())); |
|
1185 |
System.out.println(" Expiration: " + |
|
1186 |
connection.getExpiration()); |
|
1187 |
System.out.println(" Content Encoding: " + |
|
1188 |
connection.getContentEncoding()); |
|
1189 |
|
|
1190 |
// Guardamos la fecha del fichero de extensiones que nos hemos bajado, y |
|
1191 |
// comprobamos el ?ltimo que se ha bajado. Si no son |
|
1192 |
// iguales, nos bajamos el nuevo. Si son iguales, no |
|
1193 |
// nos bajamos nada. |
|
1194 |
Long miliSecondsInWeb = new Long(connection.getLastModified()); |
|
1195 |
|
|
1196 |
// PluginServices ps = PluginServices.getPluginServices("com.iver.core"); |
|
1197 |
// if (ps.getPersistentXML().getStringProperty("timestamp") != null) |
|
1198 |
File destDir = new File(extDir); |
|
1199 |
|
|
1200 |
if (!destDir.exists()) { |
|
1201 |
// Creamos gvSIG |
|
1202 |
destDir.getParentFile().mkdir(); |
|
1203 |
|
|
1204 |
if (!destDir.mkdir()) { |
|
1205 |
System.err.println("Imposible crear el directorio " + |
|
1206 |
destDir.getAbsolutePath()); |
|
1207 |
} |
|
1208 |
} |
|
1209 |
|
|
1210 |
File timeFile = new File(destDir.getParent() + File.separator + |
|
1211 |
"timeStamp.properties"); |
|
1212 |
|
|
1213 |
if (!timeFile.exists()) { |
|
1214 |
timeFile.createNewFile(); |
|
1215 |
} |
|
1216 |
|
|
1217 |
FileInputStream inAux = new FileInputStream(timeFile); |
|
1218 |
Properties prop = new Properties(); |
|
1219 |
prop.load(inAux); |
|
1220 |
inAux.close(); |
|
1221 |
|
|
1222 |
if (prop.getProperty("timestamp") != null) { |
|
1223 |
Long lastMiliSeconds = (Long) new Long(prop.getProperty( |
|
1224 |
"timestamp")); |
|
1225 |
|
|
1226 |
if (lastMiliSeconds.longValue() == miliSecondsInWeb.longValue()) { |
|
1227 |
System.out.println("No hay nueva actualizaci?n"); |
|
1228 |
|
|
1229 |
return; |
|
1230 |
} |
|
1231 |
|
|
1232 |
System.out.println("timeStampWeb= " + miliSecondsInWeb); |
|
1233 |
System.out.println("timeStampLocal= " + lastMiliSeconds); |
|
1234 |
} else { |
|
1235 |
System.out.println("El timeStamp no est? escrito en " + |
|
1236 |
timeFile.getAbsolutePath()); |
|
1237 |
} |
|
1238 |
|
|
1239 |
InputStream stream = connection.getInputStream(); |
|
1240 |
File temp = File.createTempFile("gvsig", ".zip"); |
|
1241 |
temp.deleteOnExit(); |
|
1242 |
|
|
1243 |
FileOutputStream file = new FileOutputStream(temp); |
|
1244 |
BufferedInputStream in = new BufferedInputStream(stream); |
|
1245 |
BufferedOutputStream out = new BufferedOutputStream(file); |
|
1246 |
|
|
1247 |
int i; |
|
1248 |
int pct; |
|
1249 |
int desde; |
|
1250 |
int hasta; |
|
1251 |
|
|
1252 |
hasta = connection.getContentLength() / 1024; |
|
1253 |
desde = 0; |
|
1254 |
|
|
1255 |
while ((i = in.read()) != -1) { |
|
1256 |
pct = ((desde / 1024) * 100) / hasta; |
|
1257 |
|
|
1258 |
if (((desde % 10240) == 0) && (pct > 10) && |
|
1259 |
((pct % 10) == 0)) { |
|
1260 |
SplashWindow.process(pct, |
|
1261 |
(desde / 1024) + "Kb de " + hasta + |
|
1262 |
"Kb descargados..."); |
|
1263 |
} |
|
1264 |
|
|
1265 |
out.write(i); |
|
1266 |
desde++; |
|
1267 |
} |
|
1268 |
|
|
1269 |
out.flush(); |
|
1270 |
out.close(); |
|
1271 |
in.close(); |
|
1272 |
|
|
1273 |
//Se extrae el zip |
|
1274 |
SplashWindow.process(5, "Extensiones descargadas."); |
|
1275 |
|
|
1276 |
System.out.println("Extrayendo a " + destDir.getAbsolutePath()); |
|
1277 |
|
|
1278 |
Date fechaDir = new Date(destDir.lastModified()); |
|
1279 |
System.out.println("Fecha del directorio " + extDir + " = " + |
|
1280 |
fechaDir.toString()); |
|
1281 |
Utilities.extractTo(temp, new File(extDir), splashWindow); |
|
1282 |
|
|
1283 |
// Si todo ha ido bien, guardamos el timestamp. |
|
1284 |
/// App.instance.getPc().addProperties("timestamp", miliSecondsInWeb); |
|
1285 |
// XMLEntity xml=ps.getPersistentXML(); |
|
1286 |
fechaActual = new java.util.Date(); |
|
1287 |
|
|
1288 |
FileOutputStream outAux = new FileOutputStream(timeFile); |
|
1289 |
prop.setProperty("timestamp", miliSecondsInWeb.toString()); |
|
1290 |
prop.store(outAux, "last download"); |
|
1291 |
outAux.close(); |
|
1292 |
System.out.println("Fecha actual guardada: " + |
|
1293 |
fechaActual.toGMTString()); |
|
1294 |
|
|
1295 |
/* xml.putProperty("timestamp",fechaActual.toGMTString()); |
|
1296 |
ps.setPresistentXML(xml); */ |
|
1297 |
} |
|
1298 |
} catch (IOException e) { |
|
1299 |
NotificationManager.addError("", e); |
|
1300 |
} catch (UnavailableServiceException e) { |
|
1301 |
NotificationManager.addError("", e); |
|
1302 |
} catch (SecurityException e) { |
|
1303 |
System.err.println("No se puede escribir el timeStamp " + |
|
1304 |
fechaActual.toGMTString()); |
|
1305 |
NotificationManager.addError("", e); |
|
1306 |
} |
|
1307 |
} |
|
1308 |
|
|
1309 |
/** |
|
1310 |
* DOCUMENT ME! |
|
1311 |
* |
|
1312 | 1143 |
* @return DOCUMENT ME! |
1313 | 1144 |
*/ |
1314 | 1145 |
private static Extensions[] getExtensions() { |
trunk/frameworks/_fwAndami/src/com/iver/andami/plugins/PluginClassLoader.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.andami.plugins; |
42 | 42 |
|
43 |
import com.iver.andami.messages.Messages; |
|
44 |
|
|
45 |
import org.apache.log4j.Logger; |
|
46 |
|
|
43 | 47 |
import java.io.DataInputStream; |
44 | 48 |
import java.io.File; |
49 |
import java.io.FileInputStream; |
|
50 |
import java.io.FileNotFoundException; |
|
45 | 51 |
import java.io.IOException; |
46 | 52 |
import java.io.InputStream; |
53 |
|
|
47 | 54 |
import java.net.MalformedURLException; |
48 | 55 |
import java.net.URL; |
49 | 56 |
import java.net.URLClassLoader; |
57 |
|
|
50 | 58 |
import java.security.AllPermission; |
51 | 59 |
import java.security.CodeSource; |
52 | 60 |
import java.security.PermissionCollection; |
61 |
|
|
53 | 62 |
import java.util.ArrayList; |
54 | 63 |
import java.util.Enumeration; |
55 | 64 |
import java.util.Hashtable; |
... | ... | |
60 | 69 |
import java.util.zip.ZipException; |
61 | 70 |
import java.util.zip.ZipFile; |
62 | 71 |
|
63 |
import org.apache.log4j.Logger; |
|
64 | 72 |
|
65 |
import com.iver.andami.messages.Messages; |
|
66 |
|
|
67 |
|
|
68 | 73 |
/** |
69 | 74 |
* Class loader que carga las clases pedidas por los plugins de manera que |
70 | 75 |
* primero busca en el classpath, luego busca en el directorio del propio |
... | ... | |
96 | 101 |
* @param cl ClassLoader padre del classLoader, al que se le pedir? |
97 | 102 |
* resolver las clases antes de utilizar el algoritmo propio |
98 | 103 |
* @param pluginLoaders DOCUMENT ME! |
104 |
* |
|
99 | 105 |
* @throws IOException |
100 |
* @throws IOException |
|
101 | 106 |
*/ |
102 | 107 |
public PluginClassLoader(URL[] jars, String baseDir, ClassLoader cl, |
103 | 108 |
PluginClassLoader[] pluginLoaders) throws IOException { |
... | ... | |
128 | 133 |
if (clasesJar.get(fileName) != null) { |
129 | 134 |
throw new JarException(Messages.getString( |
130 | 135 |
"PluginClassLoader.Dos_clases_con_el_mismo_nombre_en_el_plugin" + |
131 |
": " + fileName + " en " + jarFiles[i].getName() + " y en " + ((ZipFile)clasesJar.get(fileName)).getName())); |
|
136 |
": " + fileName + " en " + |
|
137 |
jarFiles[i].getName() + " y en " + |
|
138 |
((ZipFile) clasesJar.get(fileName)).getName())); |
|
132 | 139 |
} |
133 | 140 |
|
134 | 141 |
clasesJar.put(fileName, jarFiles[i]); |
135 | 142 |
} |
136 | 143 |
} catch (ZipException e) { |
137 |
throw new IOException(e.getMessage() + " Jar: " + jars[i].getPath()+": " + jarFiles[i]); |
|
144 |
throw new IOException(e.getMessage() + " Jar: " + |
|
145 |
jars[i].getPath() + ": " + jarFiles[i]); |
|
138 | 146 |
} catch (IOException e) { |
139 | 147 |
throw e; |
140 |
}
|
|
148 |
}
|
|
141 | 149 |
} |
142 | 150 |
} |
143 | 151 |
|
... | ... | |
145 | 153 |
* DOCUMENT ME! |
146 | 154 |
* |
147 | 155 |
* @param name DOCUMENT ME! |
148 |
* @param resolve DOCUMENT ME! |
|
149 | 156 |
* |
150 | 157 |
* @return DOCUMENT ME! |
151 | 158 |
* |
152 | 159 |
* @throws ClassNotFoundException DOCUMENT ME! |
153 | 160 |
*/ |
154 |
protected Class singleLoadClass(String name) |
|
155 |
throws ClassNotFoundException { |
|
161 |
protected Class singleLoadClass(String name) throws ClassNotFoundException { |
|
156 | 162 |
// Buscamos en las clases de las librer?as del plugin |
157 | 163 |
Class c = findLoadedClass(name); |
158 |
if (c != null){ |
|
159 |
return c; |
|
160 |
} |
|
161 | 164 |
|
165 |
if (c != null) { |
|
166 |
return c; |
|
167 |
} |
|
168 |
|
|
162 | 169 |
try { |
163 | 170 |
ZipFile jar = (ZipFile) clasesJar.get(name); |
164 | 171 |
|
172 |
//No est? en ning?n jar |
|
165 | 173 |
if (jar == null) { |
166 |
for (int i = 0; i < pluginLoaders.length; i++) { |
|
167 |
c = pluginLoaders[i].singleLoadClass(name); |
|
174 |
//Buscamos en el directorio de clases |
|
175 |
String classFileName = baseDir + "/classes/" + |
|
176 |
name.replace('.', '/') + ".class"; |
|
177 |
File f = new File(classFileName); |
|
178 |
if (f.exists()){ |
|
179 |
byte[] data = loadClassData(f); |
|
180 |
c = defineClass(name, data, 0, data.length); |
|
181 |
}else{ |
|
182 |
//Buscamos en los otros plugins |
|
183 |
for (int i = 0; i < pluginLoaders.length; i++) { |
|
184 |
c = pluginLoaders[i].singleLoadClass(name); |
|
168 | 185 |
|
169 |
if (c != null) { |
|
170 |
break; |
|
186 |
if (c != null) { |
|
187 |
break; |
|
188 |
} |
|
171 | 189 |
} |
172 | 190 |
} |
173 | 191 |
} else { |
... | ... | |
251 | 269 |
} |
252 | 270 |
|
253 | 271 |
/** |
272 |
* Gets the bytes of a File |
|
273 |
* |
|
274 |
* @param file File |
|
275 |
* |
|
276 |
* @return bytes of file |
|
277 |
* |
|
278 |
* @throws IOException If the operation fails |
|
279 |
*/ |
|
280 |
private byte[] loadClassData(File file) throws IOException { |
|
281 |
InputStream is = new FileInputStream(file); |
|
282 |
|
|
283 |
// Get the size of the file |
|
284 |
long length = file.length(); |
|
285 |
|
|
286 |
// You cannot create an array using a long type. |
|
287 |
// It needs to be an int type. |
|
288 |
// Before converting to an int type, check |
|
289 |
// to ensure that file is not larger than Integer.MAX_VALUE. |
|
290 |
if (length > Integer.MAX_VALUE) { |
|
291 |
// File is too large |
|
292 |
} |
|
293 |
|
|
294 |
// Create the byte array to hold the data |
|
295 |
byte[] bytes = new byte[(int) length]; |
|
296 |
|
|
297 |
// Read in the bytes |
|
298 |
int offset = 0; |
|
299 |
int numRead = 0; |
|
300 |
|
|
301 |
while ((offset < bytes.length) && |
|
302 |
((numRead = is.read(bytes, offset, bytes.length - offset)) >= 0)) { |
|
303 |
offset += numRead; |
|
304 |
} |
|
305 |
|
|
306 |
// Ensure all the bytes have been read in |
|
307 |
if (offset < bytes.length) { |
|
308 |
throw new IOException("Could not completely read file " + |
|
309 |
file.getName()); |
|
310 |
} |
|
311 |
|
|
312 |
// Close the input stream and return bytes |
|
313 |
is.close(); |
|
314 |
|
|
315 |
return bytes; |
|
316 |
} |
|
317 |
|
|
318 |
/** |
|
254 | 319 |
* Obtiene los recursos tomando como la raiz el directorio base del plugin. |
255 | 320 |
* Si no se encuentra el recurso ah? se invoca a getResource del |
256 | 321 |
* classloader padre, que buscar? en el jar de la aplicaci?n. Si ah? |
... | ... | |
324 | 389 |
* @return |
325 | 390 |
*/ |
326 | 391 |
public String getPluginName() { |
327 |
String ret = baseDir.getAbsolutePath().substring(baseDir.getAbsolutePath().lastIndexOf(File.separatorChar) + |
|
392 |
String ret = baseDir.getAbsolutePath().substring(baseDir.getAbsolutePath() |
|
393 |
.lastIndexOf(File.separatorChar) + |
|
328 | 394 |
1); |
329 | 395 |
|
330 | 396 |
return ret; |
Also available in: Unified diff