예제 #1
0
 protected List<FlavorPresets> computePresets(FlavorDescriptor flavor, List<String> flavors) {
   List<FlavorPresets> presets = new ArrayList<FlavorPresets>();
   if (flavor != null) {
     List<FlavorPresets> localPresets = flavor.getPresets();
     if (localPresets != null) {
       presets.addAll(localPresets);
     }
     String extendsFlavorName = flavor.getExtendsFlavor();
     if (!StringUtils.isBlank(extendsFlavorName)) {
       if (flavors.contains(extendsFlavorName)) {
         // cyclic dependency => abort
         log.error("Cyclic dependency detected in flavor '" + flavor.getName() + "' hierarchy");
         return presets;
       } else {
         // retrieve the extended presets
         flavors.add(flavor.getName());
         FlavorDescriptor extendedFlavor = getFlavor(extendsFlavorName);
         if (extendedFlavor != null) {
           List<FlavorPresets> parentPresets = computePresets(extendedFlavor, flavors);
           if (parentPresets != null) {
             presets.addAll(0, parentPresets);
           }
         } else {
           log.warn("Extended flavor '" + extendsFlavorName + "' not found");
         }
       }
     }
   }
   return presets;
 }
예제 #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);
  }