示例#1
0
  @Test
  public void extractSourcePaths() {
    ImmutableSortedSet.Builder<SourcePath> files = ImmutableSortedSet.naturalOrder();
    ImmutableMap.Builder<SourcePath, String> perFileCompileFlags = ImmutableMap.builder();

    ImmutableList<Either<SourcePath, Pair<SourcePath, String>>> input =
        ImmutableList.of(
            newEntry("foo.m"),
            newEntry("bar.m", "-flag1 -flag2"),
            newEntry("baz.m"),
            newEntry("quox.m", "-flag1"));

    RuleUtils.extractSourcePaths(files, perFileCompileFlags, input);
    assertEquals(
        ImmutableSortedSet.<SourcePath>of(
            new FileSourcePath("foo.m"),
            new FileSourcePath("bar.m"),
            new FileSourcePath("baz.m"),
            new FileSourcePath("quox.m")),
        files.build());
    assertEquals(
        ImmutableMap.<SourcePath, String>of(
            new FileSourcePath("bar.m"), "-flag1 -flag2",
            new FileSourcePath("quox.m"), "-flag1"),
        perFileCompileFlags.build());
  }
示例#2
0
  private ImmutableSortedSet<Path> getRecordedOutputDirsAndFiles() throws IOException {
    final ImmutableSortedSet.Builder<Path> paths = ImmutableSortedSet.naturalOrder();

    // Add files from output directories.
    for (final Path output : pathsToOutputs) {
      projectFilesystem.walkRelativeFileTree(
          output,
          new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                throws IOException {
              paths.add(file);
              return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                throws IOException {
              paths.add(dir);
              return FileVisitResult.CONTINUE;
            }
          });
    }

    return paths.build();
  }
示例#3
0
  @Override
  public IHand build(String handString) {
    if (handString.length() % 2 != 0) {
      throw new RuntimeException("Hand string has odd number of characters");
    }

    java.util.ArrayList<String> cardStrings = new java.util.ArrayList<String>();

    String remainingString = handString;

    int strIndex = handString.length() - 2;

    while (remainingString.length() > 0) {
      cardStrings.add(remainingString.substring(strIndex));
      remainingString = remainingString.substring(0, strIndex);
      strIndex -= 2;
    }

    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    for (String cardString : cardStrings) {
      builder.add(Card.fromString(cardString));
    }

    return new SortedHand(builder.build());
  }
示例#4
0
 /** Convert a set of input file paths as strings to {@link Path} objects. */
 public static ImmutableSortedSet<Path> asPaths(Iterable<String> paths) {
   ImmutableSortedSet.Builder<Path> builder = ImmutableSortedSet.naturalOrder();
   for (String path : paths) {
     builder.add(Paths.get(path));
   }
   return builder.build();
 }
 private static ImmutableSortedSet<Method> findAllBenchmarkMethods(
     Class<?> benchmarkClass, Instrument instrument) throws InvalidBenchmarkException {
   ImmutableSortedSet.Builder<Method> result =
       ImmutableSortedSet.orderedBy(
           Ordering.natural()
               .onResultOf(
                   new Function<Method, String>() {
                     @Override
                     public String apply(Method method) {
                       return method.getName();
                     }
                   }));
   Set<String> benchmarkMethodNames = new HashSet<String>();
   Set<String> overloadedMethodNames = new TreeSet<String>();
   for (Method method : benchmarkClass.getDeclaredMethods()) {
     if (instrument.isBenchmarkMethod(method)) {
       method.setAccessible(true);
       result.add(method);
       if (!benchmarkMethodNames.add(method.getName())) {
         overloadedMethodNames.add(method.getName());
       }
     }
   }
   if (!overloadedMethodNames.isEmpty()) {
     throw new InvalidBenchmarkException(
         "Overloads are disallowed for benchmark methods, found overloads of %s in benchmark %s",
         overloadedMethodNames, benchmarkClass);
   }
   return result.build();
 }
示例#6
0
  @Override
  public RuleKeyBuilder appendToRuleKey(RuleKeyBuilder builder) {
    // Build a sorted set so that metaInfDirectory contents are listed in a canonical order.
    ImmutableSortedSet.Builder<Path> paths = ImmutableSortedSet.naturalOrder();
    BuildRules.addInputsToSortedSet(metaInfDirectory, paths, directoryTraverser);

    return builder.setReflectively("metaInfDirectory", paths.build());
  }
示例#7
0
 public ImmutableSet<QueryTarget> getTargetsFromBuildTargetsContainer(
     Iterable<? extends HasBuildTarget> buildTargetsContainer) {
   ImmutableSortedSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
   for (HasBuildTarget hasBuildTarget : buildTargetsContainer) {
     builder.add(getOrCreateQueryBuildTarget(hasBuildTarget.getBuildTarget()));
   }
   return builder.build();
 }
示例#8
0
 @Override
 protected List<String> create(String[] elements) {
   Comparator<String> comparator = createExplicitComparator(elements);
   ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.orderedBy(comparator);
   builder.add(BEFORE_FIRST);
   builder.add(elements);
   builder.add(AFTER_LAST);
   return builder.build().asList().subList(1, elements.length + 1);
 }
 public static View deserialiseView(ByteBuf buf) {
   int id = buf.readInt();
   int memsize = buf.readInt();
   ImmutableSortedSet.Builder<Address> addrs = ImmutableSortedSet.naturalOrder();
   for (int i = 0; i < memsize; i++) {
     Address addr = (Address) AddressSerializer.INSTANCE.fromBinary(buf, Optional.absent());
     addrs.add(addr);
   }
   return new View(addrs.build(), id);
 }
 private static ImmutableSortedSet<String> getAllLetters() {
   ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
   CharsetEncoder ce = Charset.forName("US-ASCII").newEncoder();
   for (char c = 0; c < Character.MAX_VALUE; c++) {
     if (ce.canEncode(c)) {
       builder.add(("" + c).toLowerCase());
     }
   }
   return builder.build();
 }
示例#11
0
  @Override
  public RuleKey.Builder appendToRuleKey(RuleKey.Builder builder) throws IOException {
    ImmutableSortedSet.Builder<String> metaInfFiles = ImmutableSortedSet.naturalOrder();
    addMetaInfContents(metaInfFiles);

    return super.appendToRuleKey(builder)
        .set("mainClass", mainClass)
        .set("manifestFile", manifestFile)
        .set("metaInfDirectory", metaInfFiles.build());
  }
示例#12
0
 private static Iterable<Artifact> getMergeeManifests(
     Iterable<ResourceContainer> resourceContainers) {
   ImmutableSortedSet.Builder<Artifact> builder =
       ImmutableSortedSet.orderedBy(Artifact.EXEC_PATH_COMPARATOR);
   for (ResourceContainer r : resourceContainers) {
     if (r.isManifestExported()) {
       builder.add(r.getManifest());
     }
   }
   return builder.build();
 }
示例#13
0
  @Override
  public IHand build(List<Card> cards) {
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    for (Card card : cards) {
      builder.add(card);
    }

    return new SortedHand(builder.build());
  }
 private static ImmutableSortedSet<String> getAllStringsOfLength(int length) {
   if (length == 1) {
     return getAllLetters();
   }
   ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
   for (String s : getAllStringsOfLength(length - 1)) {
     for (String t : getAllLetters()) {
       builder.add(s + t);
     }
   }
   return builder.build();
 }
示例#15
0
文件: Config.java 项目: neonichu/buck
  private static ImmutableSortedSet<Path> listFiles(Path root) throws IOException {
    if (!Files.isDirectory(root)) {
      return ImmutableSortedSet.of();
    }

    ImmutableSortedSet.Builder<Path> toReturn = ImmutableSortedSet.naturalOrder();

    try (DirectoryStream<Path> directory = Files.newDirectoryStream(root)) {
      toReturn.addAll(directory.iterator());
    }

    return toReturn.build();
  }
示例#16
0
  @Override
  public Iterable<String> getInputsToCompareToOutput() {
    // Build a sorted set so that metaInfDirectory contents are listed in a canonical order.
    ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();

    if (manifestFile != null) {
      builder.add(manifestFile);
    }

    addMetaInfContents(builder);

    return builder.build();
  }
示例#17
0
  private IHand generateRandomHighCard(StandardDeckFactory deckFactory) {

    ArrayList<Card> cards = pickNRandomDifferentCards(5);

    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());
    builder.add(cards.get(0));
    builder.add(cards.get(1));
    builder.add(cards.get(2));
    builder.add(cards.get(3));
    builder.add(cards.get(4));

    return new SortedHand(builder.build());
  }
示例#18
0
  private IHand generateRandomStraight() {

    Rank randomRank = Rank.getRandomRank(Rank.TEN);

    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(Card.from(randomRank, Suit.getRandomSuit()));
    builder.add(Card.from(randomRank.addToRank(1), Suit.getRandomSuit()));
    builder.add(Card.from(randomRank.addToRank(2), Suit.getRandomSuit()));
    builder.add(Card.from(randomRank.addToRank(3), Suit.SPADES));
    builder.add(Card.from(randomRank.addToRank(4), Suit.HEARTS));

    return new SortedHand(builder.build());
  }
示例#19
0
  private IHand generateRandomFlush(StandardDeckFactory deckFactory) {
    ArrayList<Card> cards = pickNRandomDifferentCards(5);

    Suit randomSuit = Suit.getRandomSuit();

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(Card.from(cards.get(0).rank(), randomSuit));
    builder.add(Card.from(cards.get(1).rank(), randomSuit));
    builder.add(Card.from(cards.get(2).rank(), randomSuit));
    builder.add(Card.from(cards.get(3).rank(), randomSuit));
    builder.add(Card.from(cards.get(4).rank(), randomSuit));

    return new SortedHand(builder.build());
  }
示例#20
0
  private IHand generateRandomPair(StandardDeckFactory deckFactory) {
    SortedHand randomHand = new SortedHand();

    ArrayList<Card> cards = pickNRandomDifferentCards(4);

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(deck.pickRandom(cards.get(0).rank()));
    builder.add(deck.pickRandom(cards.get(0).rank()));
    builder.add(cards.get(1));
    builder.add(cards.get(2));
    builder.add(cards.get(3));

    return new SortedHand(builder.build());
  }
示例#21
0
  private IHand generateRandomFourOfAKind(StandardDeckFactory deckFactory) {

    SortedHand randomHand = new SortedHand();

    Rank randomRank = Rank.getRandomRank();

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.pickRandom(randomRank));
    builder.add(deck.dealTopCard());

    return new SortedHand(builder.build());
  }
 private ImmutableSortedSet<BuildRule> getAdditionalAaptDeps(
     ImmutableSortedSet<BuildRule> resourceRules) {
   ImmutableSortedSet.Builder<BuildRule> builder =
       ImmutableSortedSet.<BuildRule>naturalOrder()
           .addAll(resourceRules)
           .addAll(
               getTargetsAsRules(
                   FluentIterable.from(androidResourceDepsFinder.getAssetOnlyAndroidResources())
                       .transform(HasBuildTarget.TO_TARGET)
                       .toList()))
           .addAll(
               getTargetsAsRules(
                   androidResourceDepsFinder.getAndroidTransitiveDependencies()
                       .nativeTargetsWithAssets));
   if (manifest instanceof BuildRuleSourcePath) {
     builder.add(((BuildRuleSourcePath) manifest).getRule());
   }
   return builder.build();
 }
示例#23
0
  @VisibleForTesting
  Iterable<TestRule> filterTestRules(
      BuckConfig buckConfig,
      ImmutableSet<BuildTarget> explicitBuildTargets,
      Iterable<TestRule> testRules) {

    ImmutableSortedSet.Builder<TestRule> builder =
        ImmutableSortedSet.orderedBy(
            new Comparator<TestRule>() {
              @Override
              public int compare(TestRule o1, TestRule o2) {
                return o1.getBuildTarget()
                    .getFullyQualifiedName()
                    .compareTo(o2.getBuildTarget().getFullyQualifiedName());
              }
            });

    for (TestRule rule : testRules) {
      boolean explicitArgument = explicitBuildTargets.contains(rule.getBuildTarget());
      boolean matchesLabel = isMatchedByLabelOptions(buckConfig, rule.getLabels());

      // We always want to run the rules that are given on the command line. Always. Unless we don't
      // want to.
      if (shouldExcludeWin() && !matchesLabel) {
        continue;
      }

      // The testRules Iterable contains transitive deps of the arguments given on the command line,
      // filter those out if such is the user's will.
      if (shouldExcludeTransitiveTests() && !explicitArgument) {
        continue;
      }

      // Normal behavior is to include all rules that match the given label as well as any that
      // were explicitly specified by the user.
      if (explicitArgument || matchesLabel) {
        builder.add(rule);
      }
    }

    return builder.build();
  }
示例#24
0
  private IHand generateRandomFullHouse(StandardDeckFactory deckFactory) {

    SortedHand randomHand = new SortedHand();

    Rank randomTrips = Rank.getRandomRank();
    Rank randomPair = null;
    while ((randomPair = Rank.getRandomRank()) == randomTrips) {}

    IDeck deck = deckFactory.build();
    ImmutableSortedSet.Builder<Card> builder =
        ImmutableSortedSet.orderedBy(new Card.RankThenSuitComparer());

    builder.add(deck.pickRandom(randomTrips));
    builder.add(deck.pickRandom(randomTrips));
    builder.add(deck.pickRandom(randomTrips));
    builder.add(deck.pickRandom(randomPair));
    builder.add(deck.pickRandom(randomPair));

    return new SortedHand(builder.build());
  }
 private ImmutableSortedSet<BuildRule> getAdditionalAaptDeps(
     SourcePathResolver resolver,
     ImmutableSortedSet<BuildRule> resourceRules,
     AndroidPackageableCollection packageableCollection) {
   ImmutableSortedSet.Builder<BuildRule> builder =
       ImmutableSortedSet.<BuildRule>naturalOrder()
           .addAll(resourceRules)
           .addAll(
               getTargetsAsRules(
                   FluentIterable.from(
                           packageableCollection
                               .getResourceDetails()
                               .getResourcesWithEmptyResButNonEmptyAssetsDir())
                       .transform(HasBuildTarget.TO_TARGET)
                       .toList()));
   Optional<BuildRule> manifestRule = resolver.getRule(manifest);
   if (manifestRule.isPresent()) {
     builder.add(manifestRule.get());
   }
   return builder.build();
 }
示例#26
0
 public JavaTest build(BuildRuleResolver resolver) {
   BuildRuleParams params =
       new FakeBuildRuleParamsBuilder(target)
           .setType(JavaTestDescription.TYPE)
           .setDeps(deps.build())
           .build();
   JavaTest test =
       new JavaTest(
           params,
           srcs.build(),
           resources.build(),
           labels.build(),
           contacts.build(),
           proguardConfig,
           /* additionalClasspathEntries */ ImmutableSet.<Path>of(),
           JavacOptions.DEFAULTS,
           vmArgs,
           sourcesUnderTest.build(),
           Optional.<Path>absent());
   resolver.addToIndex(test);
   return test;
 }
示例#27
0
  @Parameterized.Parameters
  public static Iterable<String> parameters() {
    ImmutableSortedSet.Builder<String> browsers = ImmutableSortedSet.naturalOrder();

    if (CommandLine.find("chromedriver") != null) {
      browsers.add("*googlechrome");
    }

    if (CommandLine.find("geckodriver") != null) {
      browsers.add("*firefox");
    }

    switch (Platform.getCurrent().family()) {
      case MAC:
        //        browsers.add("*safari");
        break;

      case WINDOWS:
        browsers.add("*MicrosoftEdge");
        break;
    }

    return browsers.build();
  }
示例#28
0
  public DocIndexMetaData build() {
    partitionedBy = getPartitionedBy();
    columnPolicy = getColumnPolicy();
    createColumnDefinitions();
    indices = createIndexDefinitions();
    columns = ImmutableList.copyOf(columnsBuilder.build());
    partitionedByColumns = partitionedByColumnsBuilder.build();

    for (Tuple<ColumnIdent, ReferenceInfo> sysColumn : DocSysColumns.forTable(ident)) {
      referencesBuilder.put(sysColumn.v1(), sysColumn.v2());
    }
    references = referencesBuilder.build();
    primaryKey = getPrimaryKey();
    routingCol = getRoutingCol();
    return this;
  }
示例#29
0
 private void add(
     ColumnIdent column,
     DataType type,
     ColumnPolicy columnPolicy,
     ReferenceInfo.IndexType indexType,
     boolean partitioned) {
   ReferenceInfo info = newInfo(column, type, columnPolicy, indexType);
   // don't add it if there is a partitioned equivalent of this column
   if (partitioned || !(partitionedBy != null && partitionedBy.contains(column))) {
     if (info.ident().isColumn()) {
       columnsBuilder.add(info);
     }
     referencesBuilder.put(info.ident().columnIdent(), info);
   }
   if (partitioned) {
     partitionedByColumnsBuilder.add(info);
   }
 }
示例#30
0
 public ContentQuery build() {
   if (publisher.isPresent()) {
     return new ContentQuery(publisher.get(), annotations.build(), selection);
   }
   return new ContentQuery(urls, ids, annotations.build(), selection);
 }