protected Injector setupInjector(
      NamedConfigParametersModule configModule, Module... otherModules) {
    try {
      final ImmutableList.Builder<Module> modules = ImmutableList.builder();
      modules.add(configModule);
      modules.addAll(getSharedBindingsModules());
      modules.addAll(getCommandBindings());
      modules.addAll(Arrays.asList(otherModules));
      modules.add(
          new Module() {
            @Override
            public void configure(Binder binder) {
              binder
                  .bind(String.class)
                  .annotatedWith(Names.named("BootstrapCommand"))
                  .toInstance(commandName);
            }
          });

      return GuiceInjectorHolder.createInjector(modules.build());
    } catch (CreationException e) {
      annotateInjectorCreationException(e);
      return null;
    } catch (Exception e) {
      LOG.error("Injector creation failed!", e);
      return null;
    }
  }
Exemple #2
0
 private void addResourceProcessingSteps(
     Path sourcePath, Path destinationPath, ImmutableList.Builder<Step> stepsBuilder) {
   String sourcePathExtension =
       Files.getFileExtension(sourcePath.toString()).toLowerCase(Locale.US);
   switch (sourcePathExtension) {
     case "plist":
     case "stringsdict":
       LOG.debug("Converting plist %s to binary plist %s", sourcePath, destinationPath);
       stepsBuilder.add(
           new PlistProcessStep(
               sourcePath,
               destinationPath,
               ImmutableMap.<String, NSObject>of(),
               ImmutableMap.<String, NSObject>of(),
               PlistProcessStep.OutputFormat.BINARY));
       break;
     case "xib":
       String compiledNibFilename =
           Files.getNameWithoutExtension(destinationPath.toString()) + ".nib";
       Path compiledNibPath = destinationPath.getParent().resolve(compiledNibFilename);
       LOG.debug("Compiling XIB %s to NIB %s", sourcePath, destinationPath);
       stepsBuilder.add(
           new IbtoolStep(ibtool.getCommandPrefix(getResolver()), sourcePath, compiledNibPath));
       break;
     default:
       stepsBuilder.add(CopyStep.forFile(sourcePath, destinationPath));
       break;
   }
 }
Exemple #3
0
 private ImmutableList<ColumnIdent> getPrimaryKey() {
   Map<String, Object> metaMap = getNested(defaultMappingMap, "_meta");
   if (metaMap != null) {
     ImmutableList.Builder<ColumnIdent> builder = ImmutableList.builder();
     Object pKeys = metaMap.get("primary_keys");
     if (pKeys != null) {
       if (pKeys instanceof String) {
         builder.add(ColumnIdent.fromPath((String) pKeys));
         return builder.build();
       } else if (pKeys instanceof Collection) {
         Collection keys = (Collection) pKeys;
         if (!keys.isEmpty()) {
           for (Object pkey : keys) {
             builder.add(ColumnIdent.fromPath(pkey.toString()));
           }
           return builder.build();
         }
       }
     }
   }
   if (getCustomRoutingCol() == null && partitionedByList.isEmpty()) {
     hasAutoGeneratedPrimaryKey = true;
     return ImmutableList.of(ID_IDENT);
   }
   return ImmutableList.of();
 }
  private static ImmutableList<Token> buildTokens(List<Tok> toks) {
    ImmutableList.Builder<Token> tokens = ImmutableList.builder();
    int k = 0;
    int kN = toks.size();

    while (k < kN) {
      // Remaining non-tokens before the token go here.
      ImmutableList.Builder<Tok> toksBefore = ImmutableList.builder();

      while (!toks.get(k).isToken()) {
        toksBefore.add(toks.get(k++));
      }
      Tok tok = toks.get(k++);

      // Non-tokens starting on the same line go here too.
      ImmutableList.Builder<Tok> toksAfter = ImmutableList.builder();
      while (k < kN && !"\n".equals(toks.get(k).getText()) && !toks.get(k).isToken()) {
        Tok nonTokenAfter = toks.get(k++);
        toksAfter.add(nonTokenAfter);
        if (nonTokenAfter.getText().contains("\n")) {
          break;
        }
      }
      tokens.add(new Token(toksBefore.build(), tok, toksAfter.build()));
    }
    return tokens.build();
  }
Exemple #5
0
  public static Optional<TypeSignature> getCommonSuperTypeSignature(
      TypeSignature firstType, TypeSignature secondType) {
    // Special handling for UnknownType is necessary because we forbid cast between types with
    // different number of type parameters.
    // Without this, cast from null to map<bigint, bigint> will not be allowed.
    if (UnknownType.NAME.equals(firstType.getBase())) {
      return Optional.of(secondType);
    }
    if (UnknownType.NAME.equals(secondType.getBase())) {
      return Optional.of(firstType);
    }

    List<TypeSignatureParameter> firstTypeTypeParameters = firstType.getParameters();
    List<TypeSignatureParameter> secondTypeTypeParameters = secondType.getParameters();
    if (firstTypeTypeParameters.size() != secondTypeTypeParameters.size()) {
      return Optional.empty();
    }

    Optional<String> commonSuperTypeBase =
        getCommonSuperTypeBase(firstType.getBase(), secondType.getBase());
    if (!commonSuperTypeBase.isPresent()) {
      return Optional.empty();
    }

    ImmutableList.Builder<TypeSignatureParameter> typeParameters = ImmutableList.builder();
    for (int i = 0; i < firstTypeTypeParameters.size(); i++) {
      TypeSignatureParameter firstParameter = firstTypeTypeParameters.get(i);
      TypeSignatureParameter secondParameter = secondTypeTypeParameters.get(i);

      if (firstParameter.getKind() == secondParameter.getKind()
          && firstParameter.getKind() == ParameterKind.LONG_LITERAL) {
        typeParameters.add(
            TypeSignatureParameter.of(
                Math.max(firstParameter.getLongLiteral(), secondParameter.getLongLiteral())));
      } else if (isCovariantParameterPosition(commonSuperTypeBase.get(), i)) {
        Optional<TypeSignature> firstParameterSignature =
            firstParameter.getTypeSignatureOrNamedTypeSignature();
        Optional<TypeSignature> secondParameterSignature =
            secondParameter.getTypeSignatureOrNamedTypeSignature();
        if (!firstParameterSignature.isPresent() || !secondParameterSignature.isPresent()) {
          return Optional.empty();
        }

        Optional<TypeSignature> commonSuperType =
            getCommonSuperTypeSignature(
                firstParameterSignature.get(), secondParameterSignature.get());
        if (!commonSuperType.isPresent()) {
          return Optional.empty();
        }
        typeParameters.add(TypeSignatureParameter.of(commonSuperType.get()));
      } else {
        if (!firstParameter.equals(secondParameter)) {
          return Optional.empty();
        }
        typeParameters.add(firstParameter);
      }
    }

    return Optional.of(new TypeSignature(commonSuperTypeBase.get(), typeParameters.build()));
  }
  protected List<String> buildArguments() {
    ImmutableList.Builder<String> builder = ImmutableList.builder();

    builder.add("-host").add(settings.getHost());
    builder.add("-port").add(String.format("%s", launcherPort));
    if (settings.getDisplay() != null && settings.getDisplay() > 0) {
      builder.add("-display").add(String.format(":%s", settings.getDisplay()));
    }
    if (settings.logging().getLevel() != Level.OFF) {
      builder.add("-console"); // TODO(andreastt): Allow for file logging
      builder
          .add("-verbosity")
          .add(toLauncherLoggingLevel(settings.logging().getLevel()).toString());
    }
    if (settings.getProduct() != OperaProduct.ALL) {
      builder.add("-profile").add(settings.getProduct().getDescriptionString());
    }
    if (settings.getBackend() != null && !settings.getBackend().isEmpty()) {
      builder.add("-backend").add(settings.getBackend());
    }
    if (settings.hasDetach()) {
      builder.add("-noquit");
    }
    builder.add("-bin").add(settings.getBinary().getAbsolutePath());

    // The launcher will pass on any extra arguments to Opera
    for (OperaArgument argument : settings.arguments()) {
      builder.add(settings.arguments().sign() + argument.getArgument());
      if (argument.getValue() != null && !argument.getValue().isEmpty()) {
        builder.add(argument.getValue());
      }
    }

    return builder.build();
  }
  public static List<Double> audioAnalysis(
      String deviceName, String channel, long averages, NodeContext context) {
    AudioSource source = (AudioSource) context.getData().get(deviceName + ".source");
    if (source == null) return ImmutableList.of();
    FFT fft = new FFT(source.bufferSize(), source.sampleRate());
    fft.window(FFT.HANN);

    if (averages > 0) fft.linAverages((int) averages);

    if (channel.equals("left")) {
      fft.forward(source.left);
    } else if (channel.equals("right")) {
      fft.forward(source.right);
    } else {
      fft.forward(source.mix);
    }

    ImmutableList.Builder<Double> b = new ImmutableList.Builder<Double>();
    if (averages == 0) {
      for (int i = 0; i < fft.specSize(); i++) b.add((double) fft.getBand(i));
    } else {
      for (int i = 0; i < fft.avgSize(); i++) b.add((double) fft.getAvg(i));
    }
    return b.build();
  }
  private void checkForBrokenMethodCalls(
      CheckerState state,
      Artifact artifact,
      DeclaredClass clazz,
      DeclaredMethod method,
      ImmutableList.Builder<Conflict> builder) {
    for (CalledMethod calledMethod : method.methodCalls()) {
      final ClassTypeDescriptor owningClass = calledMethod.owner();
      final DeclaredClass calledClass = state.knownClasses().get(owningClass);

      if (calledClass == null) {
        builder.add(
            conflict(
                ConflictCategory.CLASS_NOT_FOUND,
                "Class not found: " + owningClass,
                dependency(clazz, method, calledMethod),
                artifact.name(),
                state.sourceMappings().get(owningClass)));
      } else if (missingMethod(calledMethod, calledClass, state.knownClasses())) {
        builder.add(
            conflict(
                ConflictCategory.METHOD_SIGNATURE_NOT_FOUND,
                "Method not found: " + calledMethod.pretty(),
                dependency(clazz, method, calledMethod),
                artifact.name(),
                state.sourceMappings().get(owningClass)));
      }
    }
  }
  private void checkForBrokenFieldAccess(
      CheckerState state,
      Artifact artifact,
      DeclaredClass clazz,
      DeclaredMethod method,
      ImmutableList.Builder<Conflict> builder) {
    for (AccessedField field : method.fieldAccesses()) {
      final ClassTypeDescriptor owningClass = field.owner();
      final DeclaredClass calledClass = state.knownClasses().get(owningClass);

      DeclaredField declaredField =
          new DeclaredFieldBuilder().descriptor(field.descriptor()).name(field.name()).build();

      if (calledClass == null) {
        builder.add(
            conflict(
                ConflictCategory.CLASS_NOT_FOUND,
                "Class not found: " + owningClass,
                dependency(clazz, method, field),
                artifact.name(),
                state.sourceMappings().get(owningClass)));
      } else if (missingField(declaredField, calledClass, state.knownClasses())) {
        builder.add(
            conflict(
                ConflictCategory.FIELD_NOT_FOUND,
                "Field not found: " + field.name(),
                dependency(clazz, method, field),
                artifact.name(),
                state.sourceMappings().get(owningClass)));
      } else {
        // Everything is ok!

      }
    }
  }
 @Override
 public ImmutableList<FundsMutationSubject> nameLikeSearch(String str) {
   final ImmutableList.Builder<FundsMutationSubject> builder = ImmutableList.builder();
   table
       .values()
       .stream()
       .forEach(
           subject -> {
             final int length = str.length();
             if (length > 0) {
               if (str.charAt(0) == '%') {
                 if (str.charAt(length - 1) == '%') {
                   if (length > 2) {
                     if (subject.name.contains(str.substring(1, length - 1))) {
                       builder.add(subject);
                     }
                   } else {
                     builder.add(subject);
                   }
                 } else if (subject.name.endsWith(str.substring(1))) {
                   builder.add(subject);
                 }
               } else if (str.charAt(length - 1) == '%') {
                 if (subject.name.startsWith(str.substring(0, length - 1))) {
                   builder.add(subject);
                 }
               } else if (str.equals(subject.name)) {
                 builder.add(subject);
               }
             }
           });
   return builder.build();
 }
  /** Deletes a job from ZooKeeper. Ensures that job is not currently running anywhere. */
  @Override
  public Job removeJob(final JobId id) throws JobDoesNotExistException, JobStillDeployedException {
    log.info("removing job: id={}", id);
    final ZooKeeperClient client = provider.get("removeJob");
    final Job job = getJob(client, id);
    if (job == null) {
      throw new JobDoesNotExistException(id);
    }
    // TODO (dano): handle retry failures
    try {
      final ImmutableList.Builder<ZooKeeperOperation> operations = ImmutableList.builder();
      final UUID jobCreationOperationId = getJobCreation(client, id);
      if (jobCreationOperationId != null) {
        operations.add(delete(Paths.configJobCreation(id, jobCreationOperationId)));
      }
      operations.add(
          delete(Paths.configJobHosts(id)),
          delete(Paths.configJobRefShort(id)),
          delete(Paths.configJob(id)));
      client.transaction(operations.build());
    } catch (final NoNodeException e) {
      throw new JobDoesNotExistException(id);
    } catch (final NotEmptyException e) {
      throw new JobStillDeployedException(id, listJobHosts(client, id));
    } catch (final KeeperException e) {
      throw new HeliosRuntimeException("removing job " + id + " failed", e);
    }

    return job;
  }
Exemple #12
0
  private Item getBasicFilmWithoutBroadcast(ProgData progData) {
    ImmutableList.Builder<String> uris = ImmutableList.builder();

    Optional<String> rtFilmIdentifier = rtFilmIdentifierFor(progData);

    // Previously when constructing the uri we would failover to ProgId if the rtFilmIdentifier
    // was missing but still write to the same namespace. To avoid creating duplicates we have
    // to replicate this old behavior and use the rtFilmIdentifier for resolution when its
    // available

    String legacyFilmUri =
        rtFilmIdentifier.isPresent()
            ? PaHelper.getLegacyFilmUri(rtFilmIdentifier.get())
            : PaHelper.getLegacyFilmUri(progData.getProgId());

    uris.add(legacyFilmUri);
    uris.add(PaHelper.getAlias(progData.getProgId()));
    uris.add(PaHelper.getFilmUri(identifierFor(progData)));
    Map<String, Identified> resolvedContent =
        contentResolver.findByUris(uris.build()).asResolvedMap();

    Film film = getFilmFromResolvedContent(progData, resolvedContent, legacyFilmUri);

    if (progData.getFilmYear() != null
        && MoreStrings.containsOnlyAsciiDigits(progData.getFilmYear())) {
      film.setYear(Integer.parseInt(progData.getFilmYear()));
    }
    return film;
  }
  /**
   * Parse a string delimited by comma into a list of object instances depending on
   *
   * <pre>itemParser</pre>
   *
   * .
   *
   * @param str String delimited by comma
   * @param itemParser A function to transform a string to an object.
   * @param <T> Type to be transformed from a string
   * @return List of object instances
   */
  static <T> List<T> parseList(String str, Function<String, T> itemParser) {
    if (!str.contains(",")) { // if just one item
      return ImmutableList.of(itemParser.apply(str));
    }

    final ImmutableList.Builder<T> fields = ImmutableList.builder();
    final Stack<Character> stack = new Stack<>();
    int paramStartIdx = 0;
    for (int i = 0; i < str.length(); i++) {
      char c = str.charAt(i);

      if (c == '<' || c == '[' || c == '(') {
        stack.push(c);
      } else if (c == '>') {
        Assert.assertCondition(stack.pop() == '<', "Bad signature: '%s'", str);
      } else if (c == ']') {
        Assert.assertCondition(stack.pop() == '[', "Bad signature: '%s'", str);
      } else if (c == ')') {
        Assert.assertCondition(stack.pop() == '(', "Bad signature: '%s'", str);
      } else if (c == ',') {
        if (stack.isEmpty()) { // ensure outermost type parameters
          fields.add(itemParser.apply(str.substring(paramStartIdx, i)));
          paramStartIdx = i + 1;
        }
      }
    }

    Assert.assertCondition(stack.empty(), "Bad signature: '%s'", str);
    if (paramStartIdx < str.length()) {
      fields.add(itemParser.apply(str.substring(paramStartIdx, str.length())));
    }

    return fields.build();
  }
Exemple #14
0
  public static List<String> commonLinkAndCompileFlagsForClang(
      ObjcProvider provider, ObjcConfiguration configuration) {
    ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
    if (Platform.forArch(configuration.getIosCpu()) == Platform.SIMULATOR) {
      builder.add("-mios-simulator-version-min=" + configuration.getMinimumOs());
    } else {
      builder.add("-miphoneos-version-min=" + configuration.getMinimumOs());
    }

    if (configuration.generateDebugSymbols()) {
      builder.add("-g");
    }

    return builder
        .add("-arch", configuration.getIosCpu())
        .add("-isysroot", sdkDir(configuration))
        // TODO(bazel-team): Pass framework search paths to Xcodegen.
        .add("-F", sdkDir(configuration) + "/Developer/Library/Frameworks")
        // As of sdk8.1, XCTest is in a base Framework dir
        .add("-F", frameworkDir(configuration))
        // Add custom (non-SDK) framework search paths. For each framework foo/bar.framework,
        // include "foo" as a search path.
        .addAll(
            Interspersing.beforeEach(
                "-F",
                PathFragment.safePathStrings(uniqueParentDirectories(provider.get(FRAMEWORK_DIR)))))
        .build();
  }
 @Override
 public SubPlanBuilder visitUnion(UnionNode node, Void context) {
   if (createSingleNodePlan) {
     ImmutableList.Builder<PlanNode> sourceBuilder = ImmutableList.builder();
     for (PlanNode source : node.getSources()) {
       sourceBuilder.add(source.accept(this, context).getRoot());
     }
     UnionNode unionNode =
         new UnionNode(node.getId(), sourceBuilder.build(), node.getSymbolMapping());
     return createSingleNodePlan(unionNode);
   } else {
     ImmutableList.Builder<SubPlan> sourceBuilder = ImmutableList.builder();
     ImmutableList.Builder<PlanFragmentId> fragmentIdBuilder = ImmutableList.builder();
     for (int i = 0; i < node.getSources().size(); i++) {
       PlanNode subPlan = node.getSources().get(i);
       SubPlanBuilder current = subPlan.accept(this, context);
       current.setRoot(
           new SinkNode(idAllocator.getNextId(), current.getRoot(), node.sourceOutputLayout(i)));
       fragmentIdBuilder.add(current.getId());
       sourceBuilder.add(current.build());
     }
     ExchangeNode exchangeNode =
         new ExchangeNode(
             idAllocator.getNextId(), fragmentIdBuilder.build(), node.getOutputSymbols());
     return createSingleNodePlan(exchangeNode).setChildren(sourceBuilder.build());
   }
 }
 public ArtifactCache createArtifactCache(
     Optional<String> currentWifiSsid, BuckEventBus buckEventBus) {
   ImmutableList<String> modes = getArtifactCacheModes();
   if (modes.isEmpty()) {
     return new NoopArtifactCache();
   }
   ImmutableList.Builder<ArtifactCache> builder = ImmutableList.builder();
   boolean useDistributedCache = isWifiUsableForDistributedCache(currentWifiSsid);
   try {
     for (String mode : modes) {
       switch (ArtifactCacheNames.valueOf(mode)) {
         case dir:
           ArtifactCache dirArtifactCache = createDirArtifactCache();
           buckEventBus.register(dirArtifactCache);
           builder.add(dirArtifactCache);
           break;
         case http:
           if (useDistributedCache) {
             ArtifactCache httpArtifactCache = createHttpArtifactCache(buckEventBus);
             builder.add(httpArtifactCache);
           }
           break;
       }
     }
   } catch (IllegalArgumentException e) {
     throw new HumanReadableException("Unusable cache.mode: '%s'", modes.toString());
   }
   ImmutableList<ArtifactCache> artifactCaches = builder.build();
   if (artifactCaches.size() == 1) {
     // Don't bother wrapping a single artifact cache in MultiArtifactCache.
     return artifactCaches.get(0);
   } else {
     return new MultiArtifactCache(artifactCaches);
   }
 }
  @Override
  public List<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext)
      throws IOException {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();

    String outputDirectory = getOutputDirectory();
    Step mkdir = new MkdirStep(outputDirectory);
    commands.add(mkdir);

    ImmutableSet<String> includePaths;
    if (metaInfDirectory != null) {
      String stagingRoot = outputDirectory + "/meta_inf_staging";
      String stagingTarget = stagingRoot + "/META-INF";

      MakeCleanDirectoryStep createStagingRoot = new MakeCleanDirectoryStep(stagingRoot);
      commands.add(createStagingRoot);

      MkdirAndSymlinkFileStep link = new MkdirAndSymlinkFileStep(metaInfDirectory, stagingTarget);
      commands.add(link);

      includePaths =
          ImmutableSet.<String>builder()
              .add(stagingRoot)
              .addAll(getTransitiveClasspathEntries().values())
              .build();
    } else {
      includePaths = ImmutableSet.copyOf(getTransitiveClasspathEntries().values());
    }

    String outputFile = getOutputFile();
    Step jar = new JarDirectoryStep(outputFile, includePaths, mainClass, manifestFile);
    commands.add(jar);

    return commands.build();
  }
  @Override
  public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
    checkArgument(!isNullOrEmpty(tableMetadata.getOwner()), "Table owner is null or empty");

    SchemaTableName schemaTableName = tableMetadata.getTable();
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();

    ImmutableList.Builder<String> columnNames = ImmutableList.builder();
    ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();

    buildColumnInfo(tableMetadata, columnNames, columnTypes);

    ImmutableList.Builder<FieldSchema> partitionKeys = ImmutableList.builder();
    ImmutableList.Builder<FieldSchema> columns = ImmutableList.builder();

    List<String> names = columnNames.build();
    List<String> typeNames =
        columnTypes
            .build()
            .stream()
            .map(HiveType::toHiveType)
            .map(HiveType::getHiveTypeName)
            .collect(toList());

    for (int i = 0; i < names.size(); i++) {
      if (tableMetadata.getColumns().get(i).isPartitionKey()) {
        partitionKeys.add(new FieldSchema(names.get(i), typeNames.get(i), null));
      } else {
        columns.add(new FieldSchema(names.get(i), typeNames.get(i), null));
      }
    }

    Path targetPath = getTargetPath(schemaName, tableName, schemaTableName);

    HiveStorageFormat hiveStorageFormat = getHiveStorageFormat(session, this.hiveStorageFormat);
    SerDeInfo serdeInfo = new SerDeInfo();
    serdeInfo.setName(tableName);
    serdeInfo.setSerializationLib(hiveStorageFormat.getSerDe());

    StorageDescriptor sd = new StorageDescriptor();
    sd.setLocation(targetPath.toString());

    sd.setCols(columns.build());
    sd.setSerdeInfo(serdeInfo);
    sd.setInputFormat(hiveStorageFormat.getInputFormat());
    sd.setOutputFormat(hiveStorageFormat.getOutputFormat());

    Table table = new Table();
    table.setDbName(schemaName);
    table.setTableName(tableName);
    table.setOwner(tableMetadata.getOwner());
    table.setTableType(TableType.MANAGED_TABLE.toString());
    String tableComment = "Created by Presto";
    table.setParameters(ImmutableMap.of("comment", tableComment));
    table.setPartitionKeys(partitionKeys.build());
    table.setSd(sd);

    metastore.createTable(table);
  }
 public void testComplexBuilder() {
   List<Integer> colorElem = asList(0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF);
   ImmutableList.Builder<Integer> webSafeColorsBuilder = ImmutableList.builder();
   for (Integer red : colorElem) {
     for (Integer green : colorElem) {
       for (Integer blue : colorElem) {
         webSafeColorsBuilder.add((red << 16) + (green << 8) + blue);
       }
     }
   }
   ImmutableList<Integer> webSafeColors = webSafeColorsBuilder.build();
   assertEquals(216, webSafeColors.size());
   Integer[] webSafeColorArray = webSafeColors.toArray(new Integer[webSafeColors.size()]);
   assertEquals(0x000000, (int) webSafeColorArray[0]);
   assertEquals(0x000033, (int) webSafeColorArray[1]);
   assertEquals(0x000066, (int) webSafeColorArray[2]);
   assertEquals(0x003300, (int) webSafeColorArray[6]);
   assertEquals(0x330000, (int) webSafeColorArray[36]);
   assertEquals(0x000066, (int) webSafeColors.get(2));
   assertEquals(0x003300, (int) webSafeColors.get(6));
   ImmutableList<Integer> addedColor = webSafeColorsBuilder.add(0x00BFFF).build();
   assertEquals(
       "Modifying the builder should not have changed any already" + " built sets",
       216,
       webSafeColors.size());
   assertEquals("the new array should be one bigger than webSafeColors", 217, addedColor.size());
   Integer[] appendColorArray = addedColor.toArray(new Integer[addedColor.size()]);
   assertEquals(0x00BFFF, (int) appendColorArray[216]);
 }
Exemple #20
0
    @Override
    public PlanNode visitExchange(
        ExchangeNode exchange, RewriteContext<FragmentProperties> context) {
      ImmutableList.Builder<SubPlan> builder = ImmutableList.builder();
      if (exchange.getType() == ExchangeNode.Type.GATHER) {
        context.get().setSingleNodeDistribution();

        for (int i = 0; i < exchange.getSources().size(); i++) {
          FragmentProperties childProperties = new FragmentProperties();
          childProperties.setUnpartitionedOutput();
          childProperties.setOutputLayout(exchange.getInputs().get(i));

          builder.add(buildSubPlan(exchange.getSources().get(i), childProperties, context));
        }
      } else if (exchange.getType() == ExchangeNode.Type.REPARTITION) {
        context.get().setFixedDistribution();

        FragmentProperties childProperties =
            new FragmentProperties()
                .setPartitionedOutput(exchange.getPartitionKeys(), exchange.getHashSymbol())
                .setOutputLayout(Iterables.getOnlyElement(exchange.getInputs()));

        builder.add(
            buildSubPlan(
                Iterables.getOnlyElement(exchange.getSources()), childProperties, context));
      } else if (exchange.getType() == ExchangeNode.Type.REPARTITION_WITH_NULL_REPLICATION) {
        context.get().setFixedDistribution();

        FragmentProperties childProperties =
            new FragmentProperties()
                .setPartitionedOutput(exchange.getPartitionKeys(), exchange.getHashSymbol())
                .replicateNulls()
                .setOutputLayout(Iterables.getOnlyElement(exchange.getInputs()));

        builder.add(
            buildSubPlan(
                Iterables.getOnlyElement(exchange.getSources()), childProperties, context));
      } else if (exchange.getType() == ExchangeNode.Type.REPLICATE) {
        FragmentProperties childProperties = new FragmentProperties();
        childProperties.setUnpartitionedOutput();
        childProperties.setOutputLayout(Iterables.getOnlyElement(exchange.getInputs()));

        builder.add(
            buildSubPlan(
                Iterables.getOnlyElement(exchange.getSources()), childProperties, context));
      }

      List<SubPlan> children = builder.build();
      context.get().addChildren(children);

      List<PlanFragmentId> childrenIds =
          children
              .stream()
              .map(SubPlan::getFragment)
              .map(PlanFragment::getId)
              .collect(toImmutableList());

      return new RemoteSourceNode(exchange.getId(), childrenIds, exchange.getOutputSymbols());
    }
  private static ImmutableList<String> getBuiltFiles(String fileName) {
    ImmutableList.Builder<String> builtFiles = ImmutableList.builder();

    builtFiles.add(fileName.replaceFirst(".ts$", ".js"));
    builtFiles.add(fileName.replaceFirst(".ts$", ".js.map"));

    return builtFiles.build();
  }
Exemple #22
0
 protected static Iterable<String> createIncludeFlags(Iterable<String> includePaths) {
   ImmutableList.Builder<String> includeFlags = ImmutableList.builder();
   for (String includePath : includePaths) {
     includeFlags.add("-isystem");
     includeFlags.add(includePath);
   }
   return includeFlags.build();
 }
 /**
  * Splits UUID arguments into two arguments, one UUID and one String. This is done so that both a
  * UUID and String with-constructor will be crated for this parameter
  */
 protected static ImmutableList<Arguments> splitUuidOptionalArgument(final Arguments arg) {
   final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
   builder.add(arg);
   if (arg.getType().equals("UUID")) {
     builder.add(new Arguments("String", arg.getName()));
   }
   return builder.build();
 }
Exemple #24
0
  @Override
  public ImmutableList<Step> getBuildSteps(
      BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();

    final Path pathToNativeLibs = getPathToNativeLibsDir();
    steps.add(new MakeCleanDirectoryStep(pathToNativeLibs));

    final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir();
    steps.add(new MakeCleanDirectoryStep(pathToNativeLibsAssets));

    for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) {
      copyNativeLibrary(
          getProjectFilesystem(),
          getResolver().getPath(nativeLibDir),
          pathToNativeLibs,
          cpuFilters,
          steps);
    }

    addStepsForCopyingNativeLibrariesOrAssets(filteredNativeLibraries, pathToNativeLibs, steps);
    addStepsForCopyingNativeLibrariesOrAssets(
        filteredNativeLibrariesAssets, pathToNativeLibsAssets, steps);

    final Path pathToMetadataTxt = getPathToMetadataTxt();
    steps.add(
        new AbstractExecutionStep("hash_native_libs") {
          @Override
          public int execute(ExecutionContext context) {
            ProjectFilesystem filesystem = context.getProjectFilesystem();
            ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
            try {
              for (Path nativeLib : filesystem.getFilesUnderPath(pathToNativeLibs)) {
                String filesha1 = filesystem.computeSha1(nativeLib);
                Path relativePath = pathToNativeLibs.relativize(nativeLib);
                metadataLines.add(String.format("%s %s", relativePath.toString(), filesha1));
              }

              for (Path nativeLib : filesystem.getFilesUnderPath(pathToNativeLibsAssets)) {
                String filesha1 = filesystem.computeSha1(nativeLib);
                Path relativePath = pathToNativeLibsAssets.relativize(nativeLib);
                metadataLines.add(String.format("%s %s", relativePath.toString(), filesha1));
              }
              filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt);
            } catch (IOException e) {
              context.logError(e, "There was an error hashing native libraries.");
              return 1;
            }
            return 0;
          }
        });

    buildableContext.recordArtifact(pathToNativeLibs);
    buildableContext.recordArtifact(pathToNativeLibsAssets);
    buildableContext.recordArtifact(pathToMetadataTxt);

    return steps.build();
  }
 private ExtraActoolArgs extraActoolArgs() {
   ImmutableList.Builder<String> extraArgs = ImmutableList.builder();
   if (attributes.appIcon() != null) {
     extraArgs.add("--app-icon", attributes.appIcon());
   }
   if (attributes.launchImage() != null && !ObjcRuleClasses.useLaunchStoryboard(ruleContext)) {
     extraArgs.add("--launch-image", attributes.launchImage());
   }
   return new ExtraActoolArgs(extraArgs.build());
 }
 private static List<Integer> getHashChannels(RowPagesBuilder probe, RowPagesBuilder build) {
   ImmutableList.Builder<Integer> hashChannels = ImmutableList.builder();
   if (probe.getHashChannel().isPresent()) {
     hashChannels.add(probe.getHashChannel().get());
   }
   if (build.getHashChannel().isPresent()) {
     hashChannels.add(probe.getTypes().size() + build.getHashChannel().get());
   }
   return hashChannels.build();
 }
 private ExtraActoolArgs extraActoolArgs() {
   ImmutableList.Builder<String> extraArgs = ImmutableList.builder();
   if (attributes.appIcon() != null) {
     extraArgs.add("--app-icon", attributes.appIcon());
   }
   if (attributes.launchImage() != null) {
     extraArgs.add("--launch-image", attributes.launchImage());
   }
   return new ExtraActoolArgs(extraArgs.build());
 }
 /**
  * Splits a constructor in two if the constructor contains a parameter of type UUID. The first
  * constructor is unchanged, while the second constructor has all UUID parameters converted into
  * strings. If the constructor does not have a UUID parameter, then the original constructor is
  * returned.
  */
 protected static ImmutableList<RequestConstructor> splitUuidConstructor(
     final RequestConstructor constructor) {
   final ImmutableList.Builder<RequestConstructor> builder = ImmutableList.builder();
   builder.add(constructor);
   if (!containsType(constructor.getParameters(), "UUID")) {
     return builder.build();
   }
   builder.add(convertUuidConstructorToStringConstructor(constructor));
   return builder.build();
 }
 /**
  * Gets all the class variables to properly generate the variables and their getter functions.
  * This consists of all constructor arguments and optional arguments being converted into
  * variables.
  */
 @Override
 public ImmutableList<Variable> toClassVariableArguments(final Ds3Request ds3Request) {
   final ImmutableList.Builder<Variable> builder = ImmutableList.builder();
   for (final Arguments arg : toConstructorArgumentsList(ds3Request)) {
     builder.add(new Variable(arg.getName(), arg.getType(), true));
   }
   for (final Arguments arg : toOptionalArgumentsList(ds3Request.getOptionalQueryParams())) {
     builder.add(new Variable(arg.getName(), arg.getType(), false));
   }
   return builder.build();
 }
Exemple #30
0
  @Override
  protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> cmdBuilder = ImmutableList.builder();

    cmdBuilder.add(AR).add("-q") /* do not check for existing objects */.add(outputFile.toString());
    for (Path src : srcs) {
      cmdBuilder.add(src.toString());
    }

    return cmdBuilder.build();
  }