<commit_before>/*
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.jboss.forge.addon.manager.impl.catalog;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;

import org.jboss.forge.addon.manager.impl.catalog.AddonDescriptor.AddonDescriptorCategory;

/**
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ForgeAddonDescriptorCatalog implements AddonDescriptorCatalog
{
   private List<AddonDescriptor> descriptors;

   @Override
   public List<AddonDescriptor> getAddonDescriptors()
   {
      if (descriptors == null)
      {
         List<AddonDescriptor> found = new ArrayList<>();
         try
         {
            URL url = new URL("http://forge.jboss.org/api/addons");
            try (InputStream in = url.openStream();
                     JsonReader reader = Json.createReader(in))
            {
               JsonObject obj = reader.readObject();
               // We don't care about core addons as they are already installed
               AddonDescriptorCategory category = AddonDescriptorCategory.COMMUNITY;
               JsonArray addons = obj.getJsonArray(category.name().toLowerCase());
               int size = addons.size();
               for (int idx = 0; idx < size; idx++)
               {
                  JsonObject addon = addons.getJsonObject(idx);

                  String id = addon.getString("id");
                  String name = addon.getString("name");
                  String description = addon.getString("description");<commit_msg>FORGE-1817: Added source parameter<commit_after>/*
 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.jboss.forge.addon.manager.impl.catalog;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;

import org.jboss.forge.addon.manager.impl.catalog.AddonDescriptor.AddonDescriptorCategory;

/**
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ForgeAddonDescriptorCatalog implements AddonDescriptorCatalog
{
   private List<AddonDescriptor> descriptors;

   @Override
   public List<AddonDescriptor> getAddonDescriptors()
   {
      if (descriptors == null)
      {
         List<AddonDescriptor> found = new ArrayList<>();
         try
         {
            URL url = new URL("http://forge.jboss.org/api/addons?source=cmd");
            try (InputStream in = url.openStream();
                     JsonReader reader = Json.createReader(in))
            {
               JsonObject obj = reader.readObject();
               // We don't care about core addons as they are already installed
               AddonDescriptorCategory category = AddonDescriptorCategory.COMMUNITY;
               JsonArray addons = obj.getJsonArray(category.name().toLowerCase());
               int size = addons.size();
               for (int idx = 0; idx < size; idx++)
               {
                  JsonObject addon = addons.getJsonObject(idx);

                  String id = addon.getString("id");
                  String name = addon.getString("name");
                  String description = addon.getString("description");
{'fraction_non_alphanumeric': 0.11025358324145534, 'fraction_numerical': 0.006063947078280044, 'mean_word_length': 2.51988360814743, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5569025', 'n_tokens_mistral': 1018, 'n_tokens_neox': 980, 'n_words': 234}