use of org.apache.commons.compress.archivers.ArchiveException in project kontraktor by RuedigerMoeller.
the class JNPM method downLoadAndInstall.
private IPromise downLoadAndInstall(String tarUrl, String moduleName, String resolvedVersion, File targetDir) {
Promise p = new Promise();
String moduleKey = createModuleKey(moduleName, targetDir);
List<Promise> promlist = packagesUnderway.get(moduleKey);
if (promlist != null) {
if (promlist.size() == 0) {
// timing: has already arrived and proms resolved
p.resolve(true);
} else {
packagesUnderway.get(moduleKey).add(p);
}
return p;
}
Log.Info(this, String.format("installing '%s' in %s.", moduleName + "@" + resolvedVersion, targetDir.getAbsolutePath()));
ArrayList list = new ArrayList();
packagesUnderway.put(moduleKey, list);
list.add(p);
checkThread();
http.getContentBytes(tarUrl).then((resp, err) -> {
execInThreadPool(() -> {
// multithread unpacking (java io blocks, so lets mass multithread)
byte[] b = resp;
try {
b = AsyncHttpActor.unGZip(b, b.length * 10);
File outputDir = new File(targetDir, moduleName);
unTar(new ByteArrayInputStream(b), outputDir);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (ArchiveException e) {
e.printStackTrace();
return false;
}
return true;
}).then(() -> {
checkThread();
// Log.Info(this,String.format("installed '%s' in %s.", moduleName+"@"+ resolvedVersion, nodeModulesDir.getAbsolutePath()));
packagesUnderway.get(moduleKey).forEach(prom -> prom.resolve(true));
packagesUnderway.get(moduleKey).clear();
});
});
return p;
}
use of org.apache.commons.compress.archivers.ArchiveException in project n4js by eclipse.
the class NpmExportWizard method performFinish.
@Override
public boolean performFinish() {
String destination = exportPage.getDestinationValue();
List<IProject> toExport = exportPage.getChosenProjects();
boolean shouldPackAsTarball = exportPage.getShouldPackAsTarball();
File folder = new File(destination);
// remap all IProjects
List<? extends IN4JSProject> toExportIN4JSProjects = mapToIN4JSProjects(toExport);
if (runTools() && toolRunnerPage.isToolrunRequested()) {
// bring to front.
((WizardDialog) getContainer()).showPage(toolRunnerPage);
}
try {
npmExporter.export(toExportIN4JSProjects, folder);
if (shouldPackAsTarball) {
npmExporter.tarAndZip(toExportIN4JSProjects, folder);
}
boolean runIt = runTools() && toolRunnerPage.queryRunTool();
if (runIt) {
final List<String> toolCommand = toolRunnerPage.getCommand();
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<String> cmds = newArrayList();
// cmds.add("echo"); // prepend with echo for debug TODO remove
// cmds.addAll(toolCommand);
cmds.add("bash");
cmds.add("-login");
cmds.add("-c");
// cmds.addAll(toolCommand);
cmds.add(Joiner.on(" ").join(toolCommand));
System.out.println("Comman will be: " + Joiner.on(" :: ").join(cmds));
for (IN4JSProject p : toExportIN4JSProjects) {
String info = "Processing " + p.toString() + "\n";
System.out.println(info);
toolRunnerPage.appendText(info);
File dir = npmExporter.exportDestination(p, folder);
ProcessBuilder pb = new ProcessBuilder();
pb.directory(dir);
pb.command(cmds);
pb.redirectErrorStream(true);
Process proc = pb.start();
// handle each of proc's streams in a separate thread
ExecutorService handlerThreadPool = Executors.newFixedThreadPool(3);
// handlerThreadPool.submit(new Runnable() {
// @Override
// public void run() {
// // we want to write to the stdin of the process
// BufferedWriter stdin = new BufferedWriter(
// new OutputStreamWriter(proc.getOutputStream()));
//
// // read from our own stdin so we can write it to proc's stdin
// BufferedReader myStdin =
// new BufferedReader(new InputStreamReader(System.in));
// String line = null;
// try {
// do {
// line = myStdin.readLine();
// stdin.write(String.format("%s%n", line));
// stdin.flush();
// } while(! "exit".equalsIgnoreCase(line));
// } catch(IOException e) {
// e.printStackTrace();
// }
// }
// });
handlerThreadPool.submit(new Runnable() {
@Override
public void run() {
// we want to read the stdout of the process
BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
try {
while (null != (line = stdout.readLine())) {
System.err.printf("[stderr] %s%n", line);
toolRunnerPage.appendConsoleOut(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
handlerThreadPool.submit(new Runnable() {
@Override
public void run() {
// we want to read the stderr of the process
BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String line;
try {
while (null != (line = stderr.readLine())) {
System.err.printf("[stderr] %s%n", line);
toolRunnerPage.appendConsoleErr(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
// wait for the process to terminate
int exitCode = proc.waitFor();
System.out.printf("Process terminated with exit code %d%n", exitCode);
handlerThreadPool.shutdown();
}
// done with all projects.
// wait for close.
toolRunnerPage.queryCloseDialog();
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
}
} catch (IOException | ArchiveException | CompressorException e) {
e.printStackTrace();
Status s = new Status(ERROR, NpmExporterActivator.PLUGIN_ID, "Error occured during export.", e);
N4JSActivator.getInstance().getLog().log(s);
return false;
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// successfully done, then store relevant history:
exportPage.finish();
if (runTools()) {
toolRunnerPage.finish();
}
return true;
}
use of org.apache.commons.compress.archivers.ArchiveException in project incubator-gobblin by apache.
the class AzkabanJobHelper method addFilesToZip.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "OBL_UNSATISFIED_OBLIGATION", justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs")
private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException {
try {
@Cleanup OutputStream archiveStream = new FileOutputStream(zipFile);
@Cleanup ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
for (File fileToAdd : filesToAdd) {
ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName());
archive.putArchiveEntry(entry);
@Cleanup BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd));
IOUtils.copy(input, archive);
archive.closeArchiveEntry();
}
archive.finish();
} catch (ArchiveException e) {
throw new IOException("Issue with creating archive", e);
}
}
use of org.apache.commons.compress.archivers.ArchiveException in project datashare by ICIJ.
the class Plugin method install.
@Override
public void install(File pluginFile, Path pluginsDir) throws IOException {
File[] candidateFiles = ofNullable(pluginsDir.toFile().listFiles((file, s) -> file.isDirectory())).orElse(new File[0]);
List<File> previousVersionInstalled = getPreviousVersionInstalled(candidateFiles, getBaseName(getUrlFileName()));
if (previousVersionInstalled.size() > 0) {
logger.info("removing previous versions {}", previousVersionInstalled);
for (File file : previousVersionInstalled) FileUtils.deleteDirectory(file);
}
logger.info("installing plugin from file {} into {}", pluginFile, pluginsDir);
InputStream is = new BufferedInputStream(new FileInputStream(pluginFile));
if (pluginFile.getName().endsWith("gz")) {
is = new BufferedInputStream(new GZIPInputStream(is));
}
try (ArchiveInputStream zippedArchiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(is)) {
ArchiveEntry entry;
while ((entry = zippedArchiveInputStream.getNextEntry()) != null) {
final File outputFile = new File(pluginsDir.toFile(), entry.getName());
if (entry.isDirectory()) {
if (!outputFile.exists()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
}
}
} else {
final OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(zippedArchiveInputStream, outputFileStream);
outputFileStream.close();
}
}
} catch (ArchiveException e) {
throw new RuntimeException(e);
}
if (isTemporaryFile(pluginFile))
pluginFile.delete();
}
Aggregations