Java 类com.facebook.buck.model.Flavored 实例源码

项目:buck    文件:UnexpectedFlavorException.java   
private static ImmutableSet<Flavor> getInvalidFlavors(Flavored flavored, BuildTarget target) {
  ImmutableSet.Builder<Flavor> builder = ImmutableSet.builder();
  for (Flavor flavor : target.getFlavors()) {
    if (!flavored.hasFlavors(ImmutableSet.of(flavor))) {
      builder.add(flavor);
    }
  }
  return builder.build();
}
项目:buck    文件:AuditFlavorsCommand.java   
private void printFlavors(
    ImmutableList<TargetNode<?, ?>> targetNodes, CommandRunnerParams params) {
  DirtyPrintStreamDecorator stdout = params.getConsole().getStdOut();
  for (TargetNode<?, ?> node : targetNodes) {
    Description<?> description = node.getDescription();
    stdout.println(node.getBuildTarget().getFullyQualifiedName());
    if (description instanceof Flavored) {
      Optional<ImmutableSet<FlavorDomain<?>>> flavorDomains =
          ((Flavored) description).flavorDomains();
      if (flavorDomains.isPresent()) {
        for (FlavorDomain<?> domain : flavorDomains.get()) {
          ImmutableSet<UserFlavor> userFlavors =
              RichStream.from(domain.getFlavors().stream())
                  .filter(UserFlavor.class)
                  .collect(ImmutableSet.toImmutableSet());
          if (userFlavors.isEmpty()) {
            continue;
          }
          stdout.printf(" %s\n", domain.getName());
          for (UserFlavor flavor : userFlavors) {
            String flavorLine = String.format("  %s", flavor.getName());
            String flavorDescription = flavor.getDescription();
            if (flavorDescription.length() > 0) {
              flavorLine += String.format(" -> %s", flavorDescription);
            }
            flavorLine += "\n";
            stdout.printf(flavorLine);
          }
        }
      } else {
        stdout.println(" unknown");
      }
    } else {
      stdout.println(" no flavors");
    }
  }
}
项目:buck    文件:AuditFlavorsCommand.java   
private void printJsonFlavors(
    ImmutableList<TargetNode<?, ?>> targetNodes, CommandRunnerParams params) throws IOException {
  DirtyPrintStreamDecorator stdout = params.getConsole().getStdOut();
  SortedMap<String, SortedMap<String, SortedMap<String, String>>> targetsJson = new TreeMap<>();
  for (TargetNode<?, ?> node : targetNodes) {
    Description<?> description = node.getDescription();
    SortedMap<String, SortedMap<String, String>> flavorDomainsJson = new TreeMap<>();

    if (description instanceof Flavored) {
      Optional<ImmutableSet<FlavorDomain<?>>> flavorDomains =
          ((Flavored) description).flavorDomains();
      if (flavorDomains.isPresent()) {
        for (FlavorDomain<?> domain : flavorDomains.get()) {
          ImmutableSet<UserFlavor> userFlavors =
              RichStream.from(domain.getFlavors().stream())
                  .filter(UserFlavor.class)
                  .collect(ImmutableSet.toImmutableSet());
          if (userFlavors.isEmpty()) {
            continue;
          }
          SortedMap<String, String> flavorsJson =
              userFlavors
                  .stream()
                  .collect(
                      ImmutableSortedMap.toImmutableSortedMap(
                          Ordering.natural(), UserFlavor::getName, UserFlavor::getDescription));
          flavorDomainsJson.put(domain.getName(), flavorsJson);
        }
      } else {
        flavorDomainsJson.put("unknown", new TreeMap<>());
      }
    }
    String targetName = node.getBuildTarget().getFullyQualifiedName();
    targetsJson.put(targetName, flavorDomainsJson);
  }

  ObjectMappers.WRITER.writeValue(stdout, targetsJson);
}
项目:buck    文件:MultiarchFileTest.java   
@Test
public void shouldAllowMultiplePlatformFlavors() {
  assertTrue(
      ((Flavored) description)
          .hasFlavors(
              ImmutableSet.of(
                  InternalFlavor.of("iphoneos-i386"), InternalFlavor.of("iphoneos-x86_64"))));
}
项目:buck-cutom    文件:Parser.java   
@Nullable
public TargetNode<?> get(BuildTarget buildTarget) {
  // Fast path.
  TargetNode<?> toReturn = memoizedTargetNodes.get(buildTarget);
  if (toReturn != null) {
    return toReturn;
  }

  BuildTarget unflavored = buildTarget.getUnflavoredTarget();
  List<Map<String, Object>> rules = state.getRawRules(unflavored.getBuildFilePath());
  for (Map<String, Object> map : rules) {

    if (!buildTarget.getShortNameOnly().equals(map.get("name"))) {
      continue;
    }

    BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(map);
    targetsToFile.put(
        unflavored,
        normalize(Paths.get((String) map.get("buck.base_path")))
            .resolve("BUCK").toAbsolutePath());

    Description<?> description = repository.getDescription(buildRuleType);
    if (description == null) {
      throw new HumanReadableException("Unrecognized rule %s while parsing %s%s.",
          buildRuleType,
          BuildTarget.BUILD_TARGET_PREFIX,
          unflavored.getBuildFilePath());
    }

    if ((description instanceof Flavored) &&
        !((Flavored) description).hasFlavor(buildTarget.getFlavor())) {
      throw new HumanReadableException("Unrecognized flavor in target %s while parsing %s%s.",
          buildTarget,
          BuildTarget.BUILD_TARGET_PREFIX,
          buildTarget.getBuildFilePath());
    }

    BuildRuleFactoryParams factoryParams = new BuildRuleFactoryParams(
        map,
        repository.getFilesystem(),
        buildTargetParser,
        // Although we store the rule by its unflavoured name, when we construct it, we need the
        // flavour.
        buildTarget,
        ruleKeyBuilderFactory);
    TargetNode<?> targetNode;
    try {
      targetNode = new TargetNode<>(description, factoryParams);
    } catch (NoSuchBuildTargetException e) {
      //
      throw new HumanReadableException(e);
    }

    TargetNode<?> existingTargetNode = memoizedTargetNodes.put(buildTarget, targetNode);
    if (existingTargetNode != null) {
      throw new HumanReadableException("Duplicate definition for " + unflavored);
    }

    // PMD considers it bad form to return while in a loop.
  }

  return memoizedTargetNodes.get(buildTarget);
}
项目:buck    文件:JsFlavorValidationCommonTest.java   
private Flavored getTestInstance() {
  return TEST_DATA.get(description);
}