Search in sources :

Example 1 with Platform

use of com.twelvemonkeys.lang.Platform in project intellij-common by redhat-developer.

the class DownloadHelper method downloadInBackgroundManager.

private void downloadInBackgroundManager(String toolName, ToolsConfig.Platform platform, Path path, String cmd, CompletableFuture<String> result) {
    final Path dlFilePath = path.resolveSibling(platform.getDlFileName());
    ProgressManager.getInstance().run(new Task.Backgroundable(null, "Downloading " + toolName, false) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            try {
                HttpRequests.request(platform.getUrl().toString()).useProxy(true).connect(request -> {
                    downloadFile(request.getInputStream(), dlFilePath, progressIndicator, request.getConnection().getContentLength());
                    uncompress(dlFilePath, path);
                    return cmd;
                });
            } catch (IOException ignored) {
                result.completeExceptionally(new IOException("Error while setting tool " + toolName + "."));
            }
        }

        @Override
        public void onFinished() {
            if (!result.isCompletedExceptionally()) {
                result.complete(cmd);
            }
        }
    });
}
Also used : Path(java.nio.file.Path) StringUtils(org.apache.commons.lang.StringUtils) BufferedInputStream(java.io.BufferedInputStream) HttpRequests(com.intellij.util.io.HttpRequests) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) URL(java.net.URL) Platform(com.twelvemonkeys.lang.Platform) Computable(com.intellij.openapi.util.Computable) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) UnaryOperator(java.util.function.UnaryOperator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Task(com.intellij.openapi.progress.Task) Map(java.util.Map) Messages(com.intellij.openapi.ui.Messages) ArchiveInputStream(org.apache.commons.compress.archivers.ArchiveInputStream) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) ProgressManager(com.intellij.openapi.progress.ProgressManager) CompressorException(org.apache.commons.compress.compressors.CompressorException) Files(java.nio.file.Files) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) IOException(java.io.IOException) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) IOUtils(org.apache.commons.io.IOUtils) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) StringReader(java.io.StringReader) Paths(java.nio.file.Paths) CommonConstants(com.redhat.devtools.intellij.common.CommonConstants) ApplicationManager(com.intellij.openapi.application.ApplicationManager) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) FilenameUtils(org.apache.commons.io.FilenameUtils) InputStream(java.io.InputStream) Task(com.intellij.openapi.progress.Task) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException)

Example 2 with Platform

use of com.twelvemonkeys.lang.Platform in project intellij-common by redhat-developer.

the class DownloadHelper method getVersionFromPath.

private String getVersionFromPath(ToolsConfig.Tool tool, ToolsConfig.Platform platform) {
    String version = "";
    try {
        Pattern pattern = Pattern.compile(tool.getVersionExtractRegExp());
        String[] arguments = tool.getVersionCmd().split(" ");
        String output = ExecHelper.execute(platform.getCmdFileName(), false, arguments);
        try (BufferedReader reader = new BufferedReader(new StringReader(output))) {
            version = reader.lines().map(line -> pattern.matcher(line)).filter(matcher -> matcher.matches()).map(matcher -> matcher.group(1)).findFirst().orElse("");
        }
    } catch (IOException e) {
    }
    return version;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) BufferedInputStream(java.io.BufferedInputStream) HttpRequests(com.intellij.util.io.HttpRequests) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) URL(java.net.URL) Platform(com.twelvemonkeys.lang.Platform) Computable(com.intellij.openapi.util.Computable) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) UnaryOperator(java.util.function.UnaryOperator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Task(com.intellij.openapi.progress.Task) Map(java.util.Map) Messages(com.intellij.openapi.ui.Messages) ArchiveInputStream(org.apache.commons.compress.archivers.ArchiveInputStream) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) ProgressManager(com.intellij.openapi.progress.ProgressManager) CompressorException(org.apache.commons.compress.compressors.CompressorException) Files(java.nio.file.Files) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) IOException(java.io.IOException) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) IOUtils(org.apache.commons.io.IOUtils) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) StringReader(java.io.StringReader) Paths(java.nio.file.Paths) CommonConstants(com.redhat.devtools.intellij.common.CommonConstants) ApplicationManager(com.intellij.openapi.application.ApplicationManager) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) FilenameUtils(org.apache.commons.io.FilenameUtils) InputStream(java.io.InputStream) Pattern(java.util.regex.Pattern) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException)

Aggregations

ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 Task (com.intellij.openapi.progress.Task)2 Messages (com.intellij.openapi.ui.Messages)2 Computable (com.intellij.openapi.util.Computable)2 HttpRequests (com.intellij.util.io.HttpRequests)2 CommonConstants (com.redhat.devtools.intellij.common.CommonConstants)2 Platform (com.twelvemonkeys.lang.Platform)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 StringReader (java.io.StringReader)2 URL (java.net.URL)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2