Search in sources :

Example 1 with GithubTagInfo

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

the class GithubProjectGeneratorPeer method createSortedTagList.

@NotNull
private static List<GithubTagInfo> createSortedTagList(@NotNull Collection<GithubTagInfo> tags) {
    List<GithubTagInfo> sortedTags = ContainerUtil.newArrayList(tags);
    Collections.sort(sortedTags, (tag1, tag2) -> {
        GithubTagInfo.Version v1 = tag1.getVersion();
        GithubTagInfo.Version v2 = tag2.getVersion();
        return v2.compareTo(v1);
    });
    for (GithubTagInfo tag : sortedTags) {
        tag.setRecentTag(false);
    }
    if (!sortedTags.isEmpty()) {
        sortedTags.get(0).setRecentTag(true);
    }
    return sortedTags;
}
Also used : GithubTagInfo(com.intellij.platform.templates.github.GithubTagInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GithubTagInfo

use of com.intellij.platform.templates.github.GithubTagInfo 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 3 with GithubTagInfo

use of com.intellij.platform.templates.github.GithubTagInfo 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 4 with GithubTagInfo

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

the class GithubProjectGeneratorPeer method validate.

@Override
@Nullable
public ValidationInfo validate() {
    GithubTagInfo tag = myReloadableComboBoxPanel.getSelectedValue();
    if (tag != null) {
        return null;
    }
    String errorMessage = StringUtil.notNullize(myReloadableComboBoxPanel.getErrorComponent().getText());
    if (errorMessage.isEmpty()) {
        errorMessage = "Versions have not been loaded yet.";
    }
    return new ValidationInfo(errorMessage);
}
Also used : GithubTagInfo(com.intellij.platform.templates.github.GithubTagInfo) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GithubTagInfo (com.intellij.platform.templates.github.GithubTagInfo)4 GeneratorException (com.intellij.platform.templates.github.GeneratorException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 File (java.io.File)1