示例#1
0
 public HashCode getOutputHash(FileHashCache fileHashCache) throws IOException {
   Hasher hasher = Hashing.md5().newHasher();
   for (Path path : getRecordedPaths()) {
     hasher.putBytes(fileHashCache.get(path).asBytes());
   }
   return hasher.hash();
 }
示例#2
0
  private String etag(MarkdownFile srcmd, @Nullable MarkdownFile navmd) {
    byte[] b = new byte[Constants.OBJECT_ID_LENGTH];
    Hasher h = Hashing.sha1().newHasher();
    h.putInt(ETAG_GEN);

    renderer.getTemplateHash(SOY_FILE).writeBytesTo(b, 0, b.length);
    h.putBytes(b);

    if (navmd != null) {
      navmd.id.copyRawTo(b, 0);
      h.putBytes(b);
    }

    srcmd.id.copyRawTo(b, 0);
    h.putBytes(b);
    return h.hash().toString();
  }
 private static HashCode hashPath(Path file, final Hasher hasher) throws IOException {
   byte[] tmpBuffer = new byte[512];
   final InputStream in = Files.newInputStream(file);
   for (int read = in.read(tmpBuffer); read > 0; read = in.read(tmpBuffer)) {
     hasher.putBytes(tmpBuffer, 0, read);
   }
   final HashCode fileHash = hasher.hash();
   in.close();
   return fileHash;
 }
 @Override
 public int read(@Nonnull final byte[] bytes, final int off, final int len) throws IOException {
   int numRead = in.read(bytes, off, len);
   if (numRead != -1) {
     for (Hasher hasher : hashers.values()) {
       hasher.putBytes(bytes, off, numRead);
     }
     count += numRead;
   }
   return numRead;
 }
 @Override
 public int hashCode() {
   HashFunction hf = Hashing.goodFastHash(32);
   Hasher h = hf.newHasher();
   h.putInt(slots.size());
   for (int i = 0; i < slots.size(); i++) {
     h.putInt(slots.get(i).size());
     for (int j = 0; j < slots.size(); j++) {
       h.putBytes(slots.get(i).get(j).getLowerRange());
       h.putBytes(slots.get(i).get(j).getUpperRange());
     }
   }
   return h.hash().asInt();
 }
示例#6
0
  private void deserializeRule(DeserializationContext context, Build.Rule rulePb)
      throws PackageDeserializationException, InterruptedException {
    Location ruleLocation = EmptyLocation.INSTANCE;
    RuleClass ruleClass = packageDeserializationEnvironment.getRuleClass(rulePb, ruleLocation);
    Map<String, ParsedAttributeValue> attributeValues = new HashMap<>();
    AttributesToDeserialize attrToDeserialize =
        packageDeserializationEnvironment.attributesToDeserialize();

    Hasher hasher = Hashing.md5().newHasher();
    for (Build.Attribute attrPb : rulePb.getAttributeList()) {
      Type<?> type = ruleClass.getAttributeByName(attrPb.getName()).getType();
      attributeValues.put(attrPb.getName(), deserializeAttribute(type, attrPb));
      if (attrToDeserialize.addSyntheticAttributeHash) {
        // TODO(bazel-team): This might give false positives because of explicit vs implicit.
        hasher.putBytes(attrPb.toByteArray());
      }
    }
    AttributeContainerWithoutLocation attributeContainer =
        new AttributeContainerWithoutLocation(ruleClass, hasher.hash());

    Label ruleLabel = deserializeLabel(rulePb.getName());
    try {
      Rule rule =
          createRuleWithParsedAttributeValues(
              ruleClass,
              ruleLabel,
              context.packageBuilder,
              ruleLocation,
              attributeValues,
              NullEventHandler.INSTANCE,
              attributeContainer);
      context.packageBuilder.addRule(rule);

      // Remove the attribute after it is added to package in order to pass the validations
      // and be able to compute all the outputs.
      if (attrToDeserialize != DESERIALIZE_ALL_ATTRS) {
        for (String attrName : attributeValues.keySet()) {
          Attribute attribute = ruleClass.getAttributeByName(attrName);
          if (!(attrToDeserialize.shouldKeepAttributeWithName.apply(attrName)
              || BuildType.isLabelType(attribute.getType()))) {
            attributeContainer.clearIfNotLabel(attrName);
          }
        }
      }

      Preconditions.checkState(!rule.containsErrors());
    } catch (NameConflictException | LabelSyntaxException e) {
      throw new PackageDeserializationException(e);
    }
  }
示例#7
0
 private void putByteSquence(ByteSequence data, Hasher hasher) {
   hasher.putBytes(data.getBackingArray(), data.offset(), data.length());
 }
示例#8
0
文件: RuleKey.java 项目: Nouhi/buck
 private Builder feed(byte[] bytes) {
   hasher.putBytes(bytes);
   return this;
 }
 private <T extends Value> HashCode taskHash(Task task) {
   Hasher hasher = Hash.newHasher();
   hasher.putBytes(smoothJarHash.asBytes());
   hasher.putBytes(task.hash().asBytes());
   return hasher.hash();
 }