Search in sources :

Example 1 with GeneratorException

use of com.intellij.platform.templates.github.GeneratorException in project intellij-community by JetBrains.

the class GithubTagListProvider method getCachedTags.

@Nullable
public ImmutableSet<GithubTagInfo> getCachedTags() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    File cacheFile = getTagsCacheFile();
    if (cacheFile.isFile()) {
        try {
            ImmutableSet<GithubTagInfo> tags = readTagsFromFile(cacheFile);
            LOG.info(getGeneratorName() + "tag info list has been successfully read from cache file " + cacheFile.getAbsolutePath());
            return tags;
        } catch (GeneratorException e) {
            LOG.warn("Can't read cache file " + cacheFile.getAbsolutePath(), e);
        }
    }
    return null;
}
Also used : GithubTagInfo(com.intellij.platform.templates.github.GithubTagInfo) GeneratorException(com.intellij.platform.templates.github.GeneratorException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GeneratorException

use of com.intellij.platform.templates.github.GeneratorException in project intellij-community by JetBrains.

the class GithubTagListProvider method toGithubTagList.

@NotNull
private static ImmutableSet<GithubTagInfo> toGithubTagList(@NotNull JsonElement jsonElement) throws GeneratorException {
    if (jsonElement instanceof JsonArray) {
        JsonArray array = (JsonArray) jsonElement;
        ImmutableSet.Builder<GithubTagInfo> tags = ImmutableSet.builder();
        for (JsonElement element : array) {
            if (element instanceof JsonObject) {
                JsonObject obj = (JsonObject) element;
                JsonElement nameElement = obj.get("name");
                String name = null;
                if (nameElement != null) {
                    name = nameElement.getAsString();
                }
                String zipball = null;
                JsonElement zipballElement = obj.get("zipball_url");
                if (zipballElement != null) {
                    zipball = zipballElement.getAsString();
                }
                if (name != null && zipball != null) {
                    tags.add(new GithubTagInfo(name, zipball));
                }
            } else {
                throw new GeneratorException("Unexpected child element " + element.getClass().getName());
            }
        }
        return tags.build();
    } else {
        throw new GeneratorException("jsonElement is expected be instance of " + JsonArray.class.getName());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) GithubTagInfo(com.intellij.platform.templates.github.GithubTagInfo) ImmutableSet(com.google.common.collect.ImmutableSet) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) GeneratorException(com.intellij.platform.templates.github.GeneratorException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GeneratorException

use of com.intellij.platform.templates.github.GeneratorException in project intellij-community by JetBrains.

the class GithubTagListProvider method parseContent.

@NotNull
private static ImmutableSet<GithubTagInfo> parseContent(@NotNull String tagFileContent) throws GeneratorException {
    if (tagFileContent.trim().isEmpty()) {
        throw new GeneratorException("Can not parse fetched version list: got empty response");
    }
    final JsonElement jsonElement;
    try {
        JsonParser jsonParser = new JsonParser();
        jsonElement = jsonParser.parse(tagFileContent);
    } catch (Exception e) {
        throw new GeneratorException("Can not parse fetched version list: malformed JSON was received");
    }
    return toGithubTagList(jsonElement);
}
Also used : JsonElement(com.google.gson.JsonElement) GeneratorException(com.intellij.platform.templates.github.GeneratorException) GeneratorException(com.intellij.platform.templates.github.GeneratorException) IOException(java.io.IOException) JsonParser(com.google.gson.JsonParser) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GeneratorException

use of com.intellij.platform.templates.github.GeneratorException in project intellij-community by JetBrains.

the class AbstractGithubTagDownloadedProjectGenerator method unpackToDir.

private void unpackToDir(@Nullable Project project, @NotNull File extractToDir, @NotNull GithubTagInfo tag) throws GeneratorException {
    File zipArchiveFile = getCacheFile(tag);
    String primaryUrl = getPrimaryZipArchiveUrlForDownload(tag);
    boolean downloaded = false;
    if (primaryUrl != null) {
        try {
            downloadAndUnzip(project, primaryUrl, zipArchiveFile, extractToDir, false);
            downloaded = true;
        } catch (GeneratorException e) {
            LOG.info("Can't download " + primaryUrl, e);
            FileUtil.delete(zipArchiveFile);
        }
    }
    if (!downloaded) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new GeneratorException("Download " + tag.getZipballUrl() + " is skipped in unit test mode");
        }
        downloadAndUnzip(project, tag.getZipballUrl(), zipArchiveFile, extractToDir, true);
    }
}
Also used : GeneratorException(com.intellij.platform.templates.github.GeneratorException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 5 with GeneratorException

use of com.intellij.platform.templates.github.GeneratorException in project intellij-community by JetBrains.

the class GithubDownloadUtil method downloadContentToFileWithProgressSynchronously.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public static void downloadContentToFileWithProgressSynchronously(@Nullable Project project, @NotNull final String url, @NotNull String progressTitle, @NotNull final File outputFile, @NotNull final String userName, @NotNull final String repositoryName, final boolean retryOnError) throws GeneratorException {
    Outcome<File> outcome = DownloadUtil.provideDataWithProgressSynchronously(project, progressTitle, "Downloading zip archive" + DownloadUtil.CONTENT_LENGTH_TEMPLATE + " ...", () -> {
        ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
        downloadAtomically(progress, url, outputFile, userName, repositoryName);
        return outputFile;
    }, () -> {
        if (!retryOnError) {
            return false;
        }
        return IOExceptionDialog.showErrorDialog("Download Error", "Can not download '" + url + "'");
    });
    File out = outcome.get();
    if (out != null) {
        return;
    }
    Exception e = outcome.getException();
    if (e != null) {
        throw new GeneratorException("Can not fetch content from " + url, e);
    }
    throw new GeneratorException("Download was cancelled");
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneratorException(com.intellij.platform.templates.github.GeneratorException) File(java.io.File) GeneratorException(com.intellij.platform.templates.github.GeneratorException) IOException(java.io.IOException)

Aggregations

GeneratorException (com.intellij.platform.templates.github.GeneratorException)5 File (java.io.File)3 JsonElement (com.google.gson.JsonElement)2 GithubTagInfo (com.intellij.platform.templates.github.GithubTagInfo)2 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Nullable (org.jetbrains.annotations.Nullable)1