43 |
43 |
|
44 |
44 |
import org.slf4j.Logger;
|
45 |
45 |
import org.slf4j.LoggerFactory;
|
46 |
|
|
|
46 |
import org.apache.commons.io.FileUtils;
|
47 |
47 |
import org.gvsig.installer.lib.api.PackageInfo;
|
48 |
48 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
|
49 |
49 |
import org.gvsig.installer.lib.impl.DefaultPackageInfo;
|
... | ... | |
129 |
129 |
try {
|
130 |
130 |
option = OPTION_DECOMPRESS;
|
131 |
131 |
this.outputDirectory = outputDirectory;
|
|
132 |
FileUtils.forceMkdir(outputDirectory);
|
|
133 |
logger.info("decompress plugin to '"+outputDirectory.getAbsolutePath()+"'.");
|
132 |
134 |
decompressPlugin(is);
|
133 |
135 |
} catch (Exception e) {
|
134 |
136 |
logger.warn("Can't decompress plugin in '"+outputDirectory+"'.", e);
|
... | ... | |
229 |
231 |
defaultSelectedPackets = defaultPackagesList;
|
230 |
232 |
out.flush();
|
231 |
233 |
} else {
|
232 |
|
logger.debug("Extracting all Plugins, plugin: " + entry);
|
|
234 |
// logger.debug("Extracting all Plugins, plugin: " + name);
|
233 |
235 |
if (option == OPTION_INSTALL) {
|
234 |
236 |
|
235 |
237 |
} else {
|
236 |
238 |
if (option == OPTION_DECOMPRESS) {
|
|
239 |
logger.info("decompress plugin " + name);
|
237 |
240 |
decompressPlugin(zipInputStream);
|
238 |
241 |
} else if (option == OPTION_READ_INSTALLINFO) {
|
239 |
242 |
readPlugin(zipInputStream, entry.getName());
|
... | ... | |
319 |
322 |
.createDefaultSimpleTaskStatus("Uncompressing...");
|
320 |
323 |
|
321 |
324 |
manager.add(taskStatus);
|
322 |
|
|
|
325 |
int countRootFolders = 0;
|
|
326 |
String entryName = "(header)";
|
323 |
327 |
try {
|
324 |
|
long readed = 0;
|
325 |
|
|
326 |
|
// // First read all the contents size
|
327 |
|
// zis = new ZipInputStream(inputStream);
|
328 |
|
// while ((entry = zis.getNextEntry()) != null) {
|
329 |
|
// count += entry.getSize();
|
330 |
|
// }
|
331 |
|
// // zis.close();
|
332 |
|
// taskStatus.setRangeOfValues(0, count);
|
333 |
|
|
334 |
|
// Return the stream to the initial position
|
335 |
|
zis = new ZipInputStream(inputStream);
|
336 |
|
while ((entry = zis.getNextEntry()) != null) {
|
337 |
|
String entryName = entry.getName();
|
338 |
|
taskStatus.message(entryName);
|
339 |
|
|
340 |
|
if (File.separatorChar != '/') {
|
341 |
|
entryName = entryName.replace('/', File.separatorChar);
|
342 |
|
}
|
343 |
|
File file = new File(outputDirectory.getAbsolutePath()
|
344 |
|
+ File.separator + entryName);
|
345 |
|
if (file.exists()) {
|
346 |
|
logger.info("delete " + file.getAbsolutePath());
|
347 |
|
delete(file);
|
348 |
|
}
|
349 |
|
if (entry.isDirectory()) {
|
350 |
|
logger.debug("makedirs " + file.getAbsolutePath());
|
351 |
|
file.mkdirs();
|
352 |
|
} else {
|
353 |
|
createParentFolder(file);
|
354 |
|
logger.debug("extracting " + file.getAbsolutePath());
|
355 |
|
FileOutputStream fos = new FileOutputStream(file);
|
356 |
|
while ((count = zis.read(data, 0, BUFFER)) != -1) {
|
357 |
|
fos.write(data, 0, count);
|
358 |
|
readed += count;
|
359 |
|
taskStatus.setCurValue(readed);
|
|
328 |
long readed = 0;
|
|
329 |
|
|
330 |
// // First read all the contents size
|
|
331 |
// zis = new ZipInputStream(inputStream);
|
|
332 |
// while ((entry = zis.getNextEntry()) != null) {
|
|
333 |
// count += entry.getSize();
|
|
334 |
// }
|
|
335 |
// // zis.close();
|
|
336 |
// taskStatus.setRangeOfValues(0, count);
|
|
337 |
|
|
338 |
// Return the stream to the initial position
|
|
339 |
zis = new ZipInputStream(inputStream);
|
|
340 |
while ((entry = zis.getNextEntry()) != null) {
|
|
341 |
entryName = entry.getName();
|
|
342 |
taskStatus.message(entryName);
|
|
343 |
|
|
344 |
if (File.separatorChar != '/') {
|
|
345 |
entryName = entryName.replace('/', File.separatorChar);
|
360 |
346 |
}
|
361 |
|
fos.flush();
|
362 |
|
fos.close();
|
|
347 |
File file = new File(outputDirectory, entryName);
|
|
348 |
if (file.exists()) {
|
|
349 |
logger.info("delete " + file.getAbsolutePath());
|
|
350 |
delete(file);
|
|
351 |
}
|
|
352 |
if (entry.isDirectory()) {
|
|
353 |
if( !entryName.contains("/") ) {
|
|
354 |
if( ++countRootFolders > 1 ) {
|
|
355 |
logger.warn("More than one root folder in the package; it may be an error.");
|
|
356 |
}
|
|
357 |
}
|
|
358 |
logger.debug("makedirs " + file.getAbsolutePath());
|
|
359 |
file.mkdirs();
|
|
360 |
} else {
|
|
361 |
createParentFolder(file);
|
|
362 |
logger.debug("extracting " + file.getAbsolutePath());
|
|
363 |
FileOutputStream fos = new FileOutputStream(file);
|
|
364 |
while ((count = zis.read(data, 0, BUFFER)) != -1) {
|
|
365 |
fos.write(data, 0, count);
|
|
366 |
readed += count;
|
|
367 |
taskStatus.setCurValue(readed);
|
|
368 |
}
|
|
369 |
fos.flush();
|
|
370 |
fos.close();
|
|
371 |
}
|
363 |
372 |
}
|
364 |
|
}
|
365 |
|
zis.close();
|
366 |
|
|
|
373 |
zis.close();
|
|
374 |
} catch(IOException ex) {
|
|
375 |
logger.warn("Problems uncompresing plugin (last entry '"+entryName+"'.",ex);
|
|
376 |
throw ex;
|
|
377 |
|
|
378 |
} catch(RuntimeException ex) {
|
|
379 |
logger.warn("Problems uncompresing plugin (last entry '"+entryName+"'.",ex);
|
|
380 |
throw ex;
|
|
381 |
|
367 |
382 |
} finally {
|
368 |
383 |
|
369 |
384 |
taskStatus.remove();
|