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;
}
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());
}
}
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);
}
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);
}
}
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");
}
Aggregations