Esempio n. 1
0
 protected Map<String, Map<String, String>> getPresetsByCat(FlavorDescriptor flavor) {
   String flavorName = flavor.getName();
   List<FlavorPresets> presets = computePresets(flavor, new ArrayList<String>());
   Map<String, Map<String, String>> presetsByCat = new HashMap<String, Map<String, String>>();
   if (presets != null) {
     for (FlavorPresets myPreset : presets) {
       String content = myPreset.getContent();
       if (content == null) {
         log.error(
             "Null content for preset with source '"
                 + myPreset.getSrc()
                 + "' in flavor '"
                 + flavorName
                 + "'");
       } else {
         String cat = myPreset.getCategory();
         Map<String, String> allEntries;
         if (presetsByCat.containsKey(cat)) {
           allEntries = presetsByCat.get(cat);
         } else {
           allEntries = new HashMap<String, String>();
         }
         try {
           Map<String, String> newEntries =
               PaletteParser.parse(content.getBytes(), myPreset.getSrc());
           if (newEntries != null) {
             allEntries.putAll(newEntries);
           }
           if (allEntries.isEmpty()) {
             presetsByCat.remove(cat);
           } else {
             presetsByCat.put(cat, allEntries);
           }
         } catch (PaletteParseException e) {
           log.error(
               String.format(
                   "Could not parse palette for " + "preset with source '%s' in flavor '%s'",
                   myPreset.getSrc(), flavorName),
               e);
         }
       }
     }
   }
   return presetsByCat;
 }
Esempio n. 2
0
  protected void registerFlavor(FlavorDescriptor flavor, RuntimeContext extensionContext) {
    // set flavor presets files content
    List<FlavorPresets> presets = flavor.getPresets();
    if (presets != null) {
      for (FlavorPresets myPreset : presets) {
        String src = myPreset.getSrc();
        URL url = getUrlFromPath(src, extensionContext);
        if (url == null) {
          log.error(String.format("Could not find resource at '%s'", src));
        } else {
          String content;
          try {
            content = new String(FileUtils.readBytes(url));
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
          myPreset.setContent(content);
        }
      }
    }

    // set flavor sass variables
    List<SassImport> sassVars = flavor.getSassImports();
    if (sassVars != null) {
      for (SassImport var : sassVars) {
        String src = var.getSrc();
        URL url = getUrlFromPath(src, extensionContext);
        if (url == null) {
          log.error(String.format("Could not find resource at '%s'", src));
        } else {
          String content;
          try {
            content = new String(FileUtils.readBytes(url));
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
          var.setContent(content);
        }
      }
    }

    flavorReg.addContribution(flavor);
  }