@Override
  public List<String> onTabComplete(
      CommandSender sebder, Command command, String label, String[] args) {
    if (args.length == 0) {
      return ImmutableList.of("module", "debug", "reload");
    }

    if (args.length == 1) {
      Builder<String> list = ImmutableList.builder();
      for (String string : Arrays.asList("module", "debug", "reload")) {
        if (string.startsWith(args[0])) {
          list.add(string);
        }
      }
      return list.build();
    }

    if (args.length == 2) {
      Builder<String> list = ImmutableList.builder();
      for (String string : Arrays.asList("unload", "load", "reload", "debug")) {
        if (string.startsWith(args[0])) {
          list.add(string);
        }
      }
      return list.build();
    }

    return ImmutableList.of();
  }
示例#2
0
  /**
   * Gets the context of this event within a stream
   *
   * @return the context in struct form
   */
  public StructDefinition getContext() {

    /* Most common case so far */
    if (fStreamContext == null) {
      return fEventContext;
    }

    /* streamContext is not null, but the context of the event is null */
    if (fEventContext == null) {
      return fStreamContext;
    }

    // TODO: cache if this is a performance issue

    /* The stream context and event context are assigned. */
    StructDeclaration mergedDeclaration = new StructDeclaration(1);

    Builder<String> builder = ImmutableList.<String>builder();
    List<Definition> fieldValues = new ArrayList<>();

    /* Add fields from the stream */
    for (String fieldName : fStreamContext.getFieldNames()) {
      Definition definition = fStreamContext.getDefinition(fieldName);
      mergedDeclaration.addField(fieldName, definition.getDeclaration());
      builder.add(fieldName);
      fieldValues.add(definition);
    }

    ImmutableList<String> fieldNames = builder.build();
    /*
     * Add fields from the event context, overwrite the stream ones if
     * needed.
     */
    for (String fieldName : fEventContext.getFieldNames()) {
      Definition definition = fEventContext.getDefinition(fieldName);
      mergedDeclaration.addField(fieldName, definition.getDeclaration());
      if (fieldNames.contains(fieldName)) {
        fieldValues.set((fieldNames.indexOf(fieldName)), definition);
      } else {
        builder.add(fieldName);
        fieldValues.add(definition);
      }
    }
    fieldNames = builder.build();
    StructDefinition mergedContext =
        new StructDefinition(
            mergedDeclaration,
            this,
            "context", //$NON-NLS-1$
            fieldNames,
            fieldValues.toArray(new Definition[fieldValues.size()]));
    return mergedContext;
  }
 private static List<URI> getTrackerUris(List<TorrentTracker> trackers) {
   Builder<URI> builder = ImmutableList.builder();
   for (TorrentTracker tracker : trackers) {
     builder.add(tracker.getURI());
   }
   return builder.build();
 }
  public PublicRepositoryI(
      RepositoryDao repositoryDao,
      ChecksumProviderFactory checksumProviderFactory,
      String checksumAlgorithmSupported,
      String pathRules)
      throws ServerError {
    this.repositoryDao = repositoryDao;
    this.checksumProviderFactory = checksumProviderFactory;
    this.repoUuid = null;

    final Builder<ChecksumAlgorithm> checksumAlgorithmsBuilder = ImmutableList.builder();
    for (final String term : checksumAlgorithmSupported.split(",")) {
      if (StringUtils.isNotBlank(term)) {
        checksumAlgorithmsBuilder.add(ChecksumAlgorithmMapper.getChecksumAlgorithm(term.trim()));
      }
    }
    this.checksumAlgorithms = checksumAlgorithmsBuilder.build();
    if (this.checksumAlgorithms.isEmpty()) {
      throw new IllegalArgumentException("a checksum algorithm must be supported");
    }

    final Set<String> terms = new HashSet<String>();
    for (final String term : pathRules.split(",")) {
      if (StringUtils.isNotBlank(term)) {
        terms.add(term.trim());
      }
    }
    final String[] termArray = terms.toArray(new String[terms.size()]);
    try {
      this.filePathRestrictions = FilePathRestrictionInstance.getFilePathRestrictions(termArray);
    } catch (NullPointerException e) {
      throw new ServerError(null, null, "unknown rule set named in: " + pathRules);
    }
  }
 private ImmutableList<Path> conditionallyCopy(ImmutableList<Path> roots) throws IOException {
   final Builder<Path> builder = ImmutableList.builder();
   for (Path root : roots) {
     Preconditions.checkArgument(
         root.startsWith(workingDirectory),
         root + " must start with root " + workingDirectory + " from " + roots);
     Preconditions.checkArgument(
         !root.equals(workingDirectory),
         "Cannot deduplicate root directory: " + root + " from " + roots);
     if (!seen.containsKey(root)) {
       seen.put(root, null);
       final Path newRoot = out.resolve(workingDirectory.relativize(root));
       Files.walkFileTree(
           root,
           ImmutableSet.of(FileVisitOption.FOLLOW_LINKS),
           Integer.MAX_VALUE,
           new ConditionalCopyVisitor(newRoot, root, seen, hashFunction));
       builder.add(newRoot);
     } else {
       // Duplicated directories are ok -- multiple files from different libraries
       // can reside in the same directory, but duplicate files should not be seen mulitple times.
     }
   }
   return builder.build();
 }
示例#6
0
  static byte[] encode(RSAPrivateCrtKey key) {
    List<BigInteger> seq =
        ImmutableList.<BigInteger>builder()
            .add(BigInteger.valueOf(0)) // version
            .add(key.getModulus())
            .add(key.getPublicExponent())
            .add(key.getPrivateExponent())
            .add(key.getPrimeP())
            .add(key.getPrimeQ())
            .add(key.getPrimeExponentP())
            .add(key.getPrimeExponentQ())
            .add(key.getCrtCoefficient())
            .build();
    int length = 0;
    for (BigInteger part : seq) {
      byte[] bytes = part.toByteArray();
      length += 1 + calculateBodyLength(bytes.length) + bytes.length;
    }

    Builder<Byte> output = ImmutableList.<Byte>builder();
    output.add((byte) (SEQUENCE | CONSTRUCTED));
    writeLength(output, length);
    for (BigInteger part : seq) {
      byte[] bytes = part.toByteArray();
      output.add((byte) TAG);
      writeLength(output, bytes.length);
      output.addAll(Bytes.asList(bytes));
    }
    return Bytes.toArray(output.build());
  }
 public ImmutableList<CFApplication> getApplicationsWithBasicInfo() {
   Builder<CFApplication> builder = ImmutableList.builder();
   for (MockCFApplication app : appsByName.values()) {
     builder.add(app.getBasicInfo());
   }
   return builder.build();
 }
示例#8
0
 public void computeBranding() {
   if (brandings == null) {
     Builder brd = ImmutableList.<String>builder();
     brd.add(Loader.instance().getMCVersionString());
     brd.add(Loader.instance().getMCPVersionString());
     brd.add("FML v" + Loader.instance().getFMLVersionString());
     String forgeBranding = (String) callForgeMethod("getBrandingVersion");
     if (!Strings.isNullOrEmpty(forgeBranding)) {
       brd.add(forgeBranding);
     }
     if (sidedDelegate != null) {
       brd.addAll(sidedDelegate.getAdditionalBrandingInformation());
     }
     try {
       Properties props = new Properties();
       props.load(getClass().getClassLoader().getResourceAsStream("fmlbranding.properties"));
       brd.add(props.getProperty("fmlbranding"));
     } catch (Exception ex) {
       // Ignore - no branding file found
     }
     int tModCount = Loader.instance().getModList().size();
     int aModCount = Loader.instance().getActiveModList().size();
     brd.add(
         String.format(
             "%d mod%s loaded, %d mod%s active",
             tModCount, tModCount != 1 ? "s" : "", aModCount, aModCount != 1 ? "s" : ""));
     brandings = brd.build();
   }
 }
示例#9
0
 private static List<SimplifiedLog> create(
     int amount, Level level, String hostName, boolean random) {
   Builder<SimplifiedLog> builder = ImmutableList.builder();
   for (int i = 0; i < amount; i++) {
     builder.add((random) ? create(level, hostName) : createPrepared(level, i));
   }
   return builder.build();
 }
 /** @return List of crawlelements. */
 protected ImmutableList<CrawlElement> getCrawlElements() {
   Builder<CrawlElement> builder = ImmutableList.builder();
   for (Form form : this.forms) {
     CrawlElement crawlTag = form.getCrawlElement();
     if (crawlTag != null) {
       builder.add(crawlTag);
     }
   }
   return builder.build();
 }
示例#11
0
 @VisibleForTesting
 final void initPatterns() {
   Builder<WildcardPattern> builder = ImmutableList.builder();
   for (String pattern :
       settings.getStringArray(CoreProperties.PROJECT_COVERAGE_EXCLUSIONS_PROPERTY)) {
     builder.add(WildcardPattern.create(pattern));
   }
   resourcePatterns = builder.build();
   log("Excluded sources for coverage: ", resourcePatterns);
 }
        @Override
        protected RevTree read(ObjectId id, BufferedReader reader, TYPE type) throws IOException {
          Preconditions.checkArgument(TYPE.TREE.equals(type), "Wrong type: %s", type.name());
          Builder<Node> features = ImmutableList.builder();
          Builder<Node> trees = ImmutableList.builder();
          TreeMap<Integer, Bucket> subtrees = Maps.newTreeMap();
          long size = Long.parseLong(parseLine(requireLine(reader), "size"));
          int numTrees = Integer.parseInt(parseLine(requireLine(reader), "numtrees"));
          String line;
          while ((line = reader.readLine()) != null) {
            Preconditions.checkArgument(!line.isEmpty(), "Empty tree element definition");
            ArrayList<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line));
            String nodeType = tokens.get(0);
            if (nodeType.equals(TextWriter.TreeNode.REF.name())) {
              Node entryRef = parseNodeLine(line);
              if (entryRef.getType().equals(TYPE.TREE)) {
                trees.add(entryRef);
              } else {
                features.add(entryRef);
              }
            } else if (nodeType.equals(TextWriter.TreeNode.BUCKET.name())) {
              Preconditions.checkArgument(tokens.size() == 4, "Wrong bucket definition: %s", line);
              Integer idx = Integer.parseInt(tokens.get(1));
              ObjectId bucketId = ObjectId.valueOf(tokens.get(2));
              Envelope bounds = parseBBox(tokens.get(3));
              Bucket bucket = Bucket.create(bucketId, bounds);
              subtrees.put(idx, bucket);
            } else {
              throw new IllegalArgumentException("Wrong tree element definition: " + line);
            }
          }

          RevTree tree;
          if (subtrees.isEmpty()) {
            tree = RevTreeImpl.createLeafTree(id, size, features.build(), trees.build());
          } else {
            tree = RevTreeImpl.createNodeTree(id, size, numTrees, subtrees);
          }
          return tree;
        }
  @Override
  public AbstractArrayDefinition createDefinition(
      @Nullable IDefinitionScope definitionScope, String fieldName, BitBuffer input)
      throws CTFException {
    IDefinition lenDef = null;

    if (definitionScope != null) {
      lenDef = definitionScope.lookupDefinition(getLengthName());
    }

    if (lenDef == null) {
      throw new CTFException("Sequence length field not found"); // $NON-NLS-1$
    }

    if (!(lenDef instanceof IntegerDefinition)) {
      throw new CTFException("Sequence length field not integer"); // $NON-NLS-1$
    }

    IntegerDefinition lengthDefinition = (IntegerDefinition) lenDef;

    if (lengthDefinition.getDeclaration().isSigned()) {
      throw new CTFException("Sequence length must not be signed"); // $NON-NLS-1$
    }

    long length = lengthDefinition.getValue();
    if ((length > Integer.MAX_VALUE)
        || (!input.canRead((int) length * fElemType.getMaximumSize()))) {
      throw new CTFException("Sequence length too long " + length); // $NON-NLS-1$
    }

    if (isAlignedBytes()) {
      // Don't create "useless" definitions
      byte[] data = new byte[(int) length];
      input.get(data);
      return new ByteArrayDefinition(this, definitionScope, fieldName, data);
    }
    Collection<String> collection = fPaths.get(fieldName);
    while (collection.size() < length) {
      fPaths.put(fieldName, fieldName + '[' + collection.size() + ']');
    }
    List<String> paths = (List<String>) fPaths.get(fieldName);
    Builder<Definition> definitions = new ImmutableList.Builder<>();
    for (int i = 0; i < length; i++) {
      /* We should not have inserted any null values */
      String elemName = checkNotNull(paths.get(i));
      definitions.add(fElemType.createDefinition(definitionScope, elemName, input));
    }
    List<Definition> list = checkNotNull(definitions.build());
    return new ArrayDefinition(this, definitionScope, fieldName, list);
  }
  public List<String> getNonFemaleExclusiveElectedCandidateNames(String officeName) {
    List<WebElement> li =
        webDriver.findElements(
            By.xpath(
                "//h1[contains(text(), '"
                    + officeName
                    + "')]/parent::section"
                    + "/h2[contains(text(), 'offen')]/following-sibling::ul[1]/li"));
    Builder<String> builder = ImmutableList.builder();
    for (WebElement webElement : li) {
      builder.add(webElement.getText());
    }

    return builder.build();
  }
 private static List<TorrentTracker> parseTrackers(String encodedTrackers)
     throws InvalidDataException {
   if (encodedTrackers == null) {
     return Collections.emptyList();
   }
   Builder<TorrentTracker> builder = ImmutableList.builder();
   for (String tracker : encodedTrackers.split(" ")) {
     try {
       URI uri = URIUtils.toURI(tracker);
       builder.add(new LimeXMLTorrentTracker(uri));
     } catch (URISyntaxException use) {
       throw new InvalidDataException("torrent xml with invalid tracker: " + encodedTrackers, use);
     }
   }
   return builder.build();
 }
  private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) {
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());

    AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId);
    Builder<SlotStatusRepresentation> builder = ImmutableList.builder();
    for (UUID slotId : slotIds) {
      SlotStatus slotStatus = agentStatus.getSlotStatus(slotId);
      builder.add(
          SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO));
      assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT);
    }
    assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build());
    assertNull(
        response
            .getMetadata()
            .get("Content-Type")); // content type is set by jersey based on @Produces
  }
  private static List<PatternConstraint> uniquePatterns(final StringTypeDefinition type) {
    final List<PatternConstraint> constraints = type.getPatternConstraints();
    if (constraints.isEmpty()) {
      return constraints;
    }

    final Builder<PatternConstraint> builder = ImmutableList.builder();
    boolean filtered = false;
    for (PatternConstraint c : constraints) {
      if (containsConstraint(type.getBaseType(), c)) {
        filtered = true;
      } else {
        builder.add(c);
      }
    }

    return filtered ? builder.build() : constraints;
  }
示例#18
0
 public @Bean LakeviewFileValidator lakeviewFileValidator() {
   Clock clock = new SystemClock();
   Builder<LakeviewFeedValidationRule> validationRules = ImmutableList.builder();
   validationRules.add(new CompletenessValidationRule(contentLister, 200));
   validationRules.add(new HeirarchyValidationRule());
   validationRules.add(new UpToDateValidationRule(1, clock));
   // We need to find better candidates for this, as we don't see updates to these brands
   // validationRules.add(new
   // RecentUpdateToBrandValidationRule("http://channel4.com/en-GB/TVSeries/deal-or-no-deal", 5,
   // clock));
   // validationRules.add(new
   // RecentUpdateToBrandValidationRule("http://channel4.com/en-GB/TVSeries/countdown", 5, clock));
   return new LakeviewFileValidator(
       lakeviewContentFetcher(),
       lakeviewFeedCompiler(),
       lakeviewFeedOutputter(),
       validationRules.build(),
       log);
 }
示例#19
0
  private static List<?> deserializeGlobs(List<?> matches, Build.Attribute attrPb) {
    if (attrPb.getGlobCriteriaCount() == 0) {
      return matches;
    }

    Builder<GlobCriteria> criteriaBuilder = ImmutableList.builder();
    for (Build.GlobCriteria criteriaPb : attrPb.getGlobCriteriaList()) {
      if (criteriaPb.hasGlob() && criteriaPb.getGlob()) {
        criteriaBuilder.add(
            GlobCriteria.fromGlobCall(
                ImmutableList.copyOf(criteriaPb.getIncludeList()),
                ImmutableList.copyOf(criteriaPb.getExcludeList())));
      } else {
        criteriaBuilder.add(
            GlobCriteria.fromList(ImmutableList.copyOf(criteriaPb.getIncludeList())));
      }
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    GlobList<?> result = new GlobList(criteriaBuilder.build(), matches);
    return result;
  }
示例#20
0
 public static <T> List<T> readList(ByteBuf bb, int length, OFMessageReader<T> reader)
     throws OFParseError {
   int end = bb.readerIndex() + length;
   Builder<T> builder = ImmutableList.<T>builder();
   if (logger.isTraceEnabled())
     logger.trace("readList(length={}, reader={})", length, reader.getClass());
   while (bb.readerIndex() < end) {
     T read = reader.readFrom(bb);
     if (logger.isTraceEnabled())
       logger.trace("readList: read={}, left={}", read, end - bb.readerIndex());
     builder.add(read);
   }
   if (bb.readerIndex() != end) {
     throw new IllegalStateException(
         "Overread length: length="
             + length
             + " overread by "
             + (bb.readerIndex() - end)
             + " reader: "
             + reader);
   }
   return builder.build();
 }
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    try {
      repairErroneousBuilderEntry(project);
      reorderBuilderEntries(project);

      final ImmutableList<String> newIDs =
          project.hasNature(ViatraQueryNature.NATURE_ID)
              ? ImmutableList.<String>of()
              : ImmutableList.of(ViatraQueryNature.NATURE_ID);
      Builder<String> builder = ImmutableList.<String>builder();
      for (String ID : MigratorConstants.INCORRECT_NATURE_IDS) {
        if (project.hasNature(ID)) {
          builder.add(ID);
        }
      }

      final ImmutableList<String> oldIDs = builder.build();

      if (newIDs.size() + oldIDs.size() > 0) {
        ProjectGenerationHelper.updateNatures(project, newIDs, oldIDs, monitor);
      }
      removeGlobalEiq(project);
      renamePatternDefinitionFiles(project);

      if (PDE.hasPluginNature(project)) {
        removeExpressionExtensions(project);
        ProjectGenerationHelper.ensurePackageImports(
            project, ImmutableList.<String>of("org.apache.log4j"));
      }
      project.build(IncrementalProjectBuilder.CLEAN_BUILD, monitor);
    } catch (CoreException e) {
      return new Status(
          IStatus.ERROR, ViatraQueryGUIPlugin.PLUGIN_ID, "Error updating project natures", e);
    }
    return Status.OK_STATUS;
  }
 @Override
 public Iterable<Image> listImages() {
   Credentials defaultCredentials = new Credentials("root", null);
   // initializing as a List, as ImmutableSet does not allow you to put duplicates
   Builder<Image> images = ImmutableList.<Image>builder();
   int id = 1;
   for (boolean is64Bit : new boolean[] {true, false})
     for (Entry<OsFamily, Map<String, String>> osVersions : this.osToVersionMap.entrySet()) {
       for (String version : ImmutableSet.copyOf(osVersions.getValue().values())) {
         String desc = String.format("stub %s %s", osVersions.getKey(), is64Bit);
         images.add(
             new ImageBuilder()
                 .ids(id++ + "")
                 .name(osVersions.getKey().name())
                 .location(location.get())
                 .operatingSystem(
                     new OperatingSystem(osVersions.getKey(), desc, version, null, desc, is64Bit))
                 .description(desc)
                 .defaultCredentials(defaultCredentials)
                 .build());
       }
     }
   return images.build();
 }
  @Override
  public void configure() {
    MongoChannelGroupStore channelGroupStore = new MongoChannelGroupStore(mongo());
    MongoLookupEntryStore lookupEntryStore = contentLookupEntryStore();
    MongoContentResolver contentResolver = contentResolver();
    BroadcastBooster booster =
        new ChannelGroupBroadcastChannelBooster(
            mongoChannelGroupStore(), channelResolver(), priorityChannelGroup);
    CachingChannelStore channelStore =
        new CachingChannelStore(
            new MongoChannelStore(mongo(), channelGroupStore, channelGroupStore));
    SimpleScheduler simplescheduler = new SimpleScheduler();

    channelStore.start();
    LuceneContentIndex index =
        new LuceneContentIndex(
            new File(luceneDir), contentResolver, booster, channelStore, backupDirectory);

    IndexBackupScheduledTask indexBackupTask = new IndexBackupScheduledTask(index);
    simplescheduler.schedule(indexBackupTask, RepetitionRules.every(Duration.standardHours(24)));

    Builder<HealthProbe> probes = ImmutableList.builder();

    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3);
    ReloadingContentBootstrapper mongoBootstrapper =
        new ReloadingContentBootstrapper(
            index,
            mongoBootstrapper(),
            scheduler,
            Boolean.valueOf(luceneIndexAtStartup),
            180,
            TimeUnit.MINUTES);
    probes.add(new LuceneSearcherProbe("mongo-lucene", mongoBootstrapper));

    ReloadingContentBootstrapper cassandraBootstrapper = null;
    if (Boolean.valueOf(enableCassandra)) {
      cassandraBootstrapper =
          new ReloadingContentBootstrapper(
              index,
              cassandraBootstrapper(),
              scheduler,
              Boolean.valueOf(luceneIndexAtStartup),
              7,
              TimeUnit.DAYS);
      probes.add(new LuceneSearcherProbe("cassandra-lucene", cassandraBootstrapper));
    }

    ReloadingContentBootstrapper musicBootStrapper = null;
    if (Boolean.valueOf(enableMusic)) {
      musicBootStrapper =
          new ReloadingContentBootstrapper(
              index, musicBootstrapper(), scheduler, true, 120, TimeUnit.MINUTES);
      probes.add(new LuceneSearcherProbe("mongo-music", musicBootStrapper));
    }

    bind("/system/health", new HealthController(probes.build()));
    bind("/titles", new SearchServlet(new JsonSearchResultsView(), index));
    bind("/debug/document", new DocumentController(index));
    bind(
        "/index",
        new ContentIndexController(
            new LookupResolvingContentResolver(contentResolver, lookupEntryStore), index));
    bind("/system/backup", new BackupController(index));

    mongoBootstrapper.startAsync();

    if (cassandraBootstrapper != null) {
      cassandraBootstrapper.startAsync();
    }

    if (musicBootStrapper != null) {
      musicBootStrapper.startAsync();
    }
  }
示例#24
0
  private RexNode convert(final ExprNodeGenericFuncDesc func) throws SemanticException {
    ExprNodeDesc tmpExprNode;
    RexNode tmpRN;

    List<RexNode> childRexNodeLst = new LinkedList<RexNode>();
    Builder<RelDataType> argTypeBldr = ImmutableList.<RelDataType>builder();

    // TODO: 1) Expand to other functions as needed 2) What about types other than primitive.
    TypeInfo tgtDT = null;
    GenericUDF tgtUdf = func.getGenericUDF();

    boolean isNumeric =
        (tgtUdf instanceof GenericUDFBaseBinary
            && func.getTypeInfo().getCategory() == Category.PRIMITIVE
            && (PrimitiveGrouping.NUMERIC_GROUP
                == PrimitiveObjectInspectorUtils.getPrimitiveGrouping(
                    ((PrimitiveTypeInfo) func.getTypeInfo()).getPrimitiveCategory())));
    boolean isCompare = !isNumeric && tgtUdf instanceof GenericUDFBaseCompare;

    if (isNumeric) {
      tgtDT = func.getTypeInfo();

      assert func.getChildren().size() == 2;
      // TODO: checking 2 children is useless, compare already does that.
    } else if (isCompare && (func.getChildren().size() == 2)) {
      tgtDT =
          FunctionRegistry.getCommonClassForComparison(
              func.getChildren().get(0).getTypeInfo(), func.getChildren().get(1).getTypeInfo());
    }

    for (ExprNodeDesc childExpr : func.getChildren()) {
      tmpExprNode = childExpr;
      if (tgtDT != null
          && TypeInfoUtils.isConversionRequiredForComparison(tgtDT, childExpr.getTypeInfo())) {
        if (isCompare) {
          // For compare, we will convert requisite children
          tmpExprNode = ParseUtils.createConversionCast(childExpr, (PrimitiveTypeInfo) tgtDT);
        } else if (isNumeric) {
          // For numeric, we'll do minimum necessary cast - if we cast to the type
          // of expression, bad things will happen.
          PrimitiveTypeInfo minArgType = ExprNodeDescUtils.deriveMinArgumentCast(childExpr, tgtDT);
          tmpExprNode = ParseUtils.createConversionCast(childExpr, minArgType);
        } else {
          throw new AssertionError("Unexpected " + tgtDT + " - not a numeric op or compare");
        }
      }
      argTypeBldr.add(TypeConverter.convert(tmpExprNode.getTypeInfo(), cluster.getTypeFactory()));
      tmpRN = convert(tmpExprNode);
      childRexNodeLst.add(tmpRN);
    }

    // See if this is an explicit cast.
    RexNode expr = null;
    RelDataType retType = null;
    expr = handleExplicitCast(func, childRexNodeLst);

    if (expr == null) {
      // This is not a cast; process the function.
      retType = TypeConverter.convert(func.getTypeInfo(), cluster.getTypeFactory());
      SqlOperator calciteOp =
          SqlFunctionConverter.getCalciteOperator(
              func.getFuncText(), func.getGenericUDF(), argTypeBldr.build(), retType);
      expr = cluster.getRexBuilder().makeCall(calciteOp, childRexNodeLst);
    } else {
      retType = expr.getType();
    }

    // TODO: Cast Function in Calcite have a bug where it infer type on cast throws
    // an exception
    if (flattenExpr
        && (expr instanceof RexCall)
        && !(((RexCall) expr).getOperator() instanceof SqlCastFunction)) {
      RexCall call = (RexCall) expr;
      expr =
          cluster
              .getRexBuilder()
              .makeCall(
                  retType,
                  call.getOperator(),
                  RexUtil.flatten(call.getOperands(), call.getOperator()));
    }

    return expr;
  }
示例#25
0
  @Subscribe
  public void constructMod(FMLConstructionEvent event) {
    try {
      ModClassLoader modClassLoader = event.getModClassLoader();
      modClassLoader.addFile(source);
      modClassLoader.clearNegativeCacheFor(candidate.getClassList());
      Class<?> clazz = Class.forName(className, true, modClassLoader);

      Certificate[] certificates = clazz.getProtectionDomain().getCodeSource().getCertificates();
      int len = 0;
      if (certificates != null) {
        len = certificates.length;
      }
      Builder<String> certBuilder = ImmutableList.<String>builder();
      for (int i = 0; i < len; i++) {
        certBuilder.add(CertificateHelper.getFingerprint(certificates[i]));
      }

      ImmutableList<String> certList = certBuilder.build();
      sourceFingerprints = ImmutableSet.copyOf(certList);

      String expectedFingerprint = (String) descriptor.get("certificateFingerprint");

      fingerprintNotPresent = true;

      if (expectedFingerprint != null && !expectedFingerprint.isEmpty()) {
        if (!sourceFingerprints.contains(expectedFingerprint)) {
          Level warnLevel = Level.SEVERE;
          if (source.isDirectory()) {
            warnLevel = Level.FINER;
          }
          FMLLog.log(
              getModId(),
              warnLevel,
              "The mod %s is expecting signature %s for source %s, however there is no signature matching that description",
              getModId(),
              expectedFingerprint,
              source.getName());
        } else {
          certificate = certificates[certList.indexOf(expectedFingerprint)];
          fingerprintNotPresent = false;
        }
      }

      CustomProperty[] props = (CustomProperty[]) descriptor.get("customProperties");
      if (props != null && props.length > 0) {
        com.google.common.collect.ImmutableMap.Builder<String, String> builder =
            ImmutableMap.<String, String>builder();
        for (CustomProperty p : props) {
          builder.put(p.k(), p.v());
        }
        customModProperties = builder.build();
      } else {
        customModProperties = EMPTY_PROPERTIES;
      }

      Method factoryMethod = gatherAnnotations(clazz);
      modInstance = getLanguageAdapter().getNewInstance(this, clazz, modClassLoader, factoryMethod);
      isNetworkMod =
          FMLNetworkHandler.instance().registerNetworkMod(this, clazz, event.getASMHarvestedData());
      if (fingerprintNotPresent) {
        eventBus.post(
            new FMLFingerprintViolationEvent(
                source.isDirectory(),
                source,
                ImmutableSet.copyOf(this.sourceFingerprints),
                expectedFingerprint));
      }
      ProxyInjector.inject(
          this,
          event.getASMHarvestedData(),
          FMLCommonHandler.instance().getSide(),
          getLanguageAdapter());
      processFieldAnnotations(event.getASMHarvestedData());
    } catch (Throwable e) {
      controller.errorOccurred(this, e);
      Throwables.propagateIfPossible(e);
    }
  }