ManifestContents parseManifest() { checkForRogueNewlinesProceedingInput(); boolean cont = eatSection(true); // cont indicates whether the visitor // decided to stop processing early while (tokenStream.hasMore() && cont) { cont = eatSection(false); } if (cont) { confirmEnd(); } return visitor.getManifestContents(); }
while (maybeEatNewline()) { cont = eatNameAttribute(); while (!maybeEatNewline() && tokenStream.hasMore() && cont) { eatAttribute(isMain);
public void eatVersionInfo() { if (maybeEatHeaderName("Manifest-Version")) { eatColon(); eatVersionNumber(); eatNewline(); } else { // The problem will have been reported - jump out of here which will // treat this (whatever it is...) as a regular header } }
protected ProvenanceVerification verifyFileInManifest(ModelProvenanceElement element, String fileId, String checksum) throws SerializationException { // 1. parse element.state as ManifestContent ManifestContents manifestContents = new RecoveringManifestParser() .parse(element.getFingerprint()); if (manifestContents.getSectionNames().contains(fileId)) { String storedHash = manifestContents.getAttributesForSection(fileId).get(TOSCAMetaFileAttributes.HASH); if (Objects.isNull(storedHash)) { return NO_HASH_AVAILABLE; } else if (storedHash.equals(checksum)) { // 2.1 if section == fileId and hash == checksum -> file verified return VERIFIED; } else { return INVALID; } } return ID_NOT_FOUND; }
private void fillFilesOfModel(ModelProvenanceElement model) { // 1. parse element.state as ManifestContent RecoveringManifestParser genericParser = new RecoveringManifestParser(); ManifestContents manifestContents = genericParser.parse(model.getFingerprint()); // 2. parse the ManifestContent as a TOSCAMetaFile TOSCAMetaFileParser parser = new TOSCAMetaFileParser(); TOSCAMetaFile toscaMetaFile = parser.parse(manifestContents, genericParser.getProblems().size()); //3. retrieve files from meta file Objects.requireNonNull(toscaMetaFile); List<FileProvenanceElement> result = toscaMetaFile .getFileBlocks() .stream() .map( fileSection -> { FileProvenanceElement fileElement = new FileProvenanceElement(model); fileElement.setFileHash(fileSection.get(TOSCAMetaFileAttributes.HASH)); fileElement.setAddressInImmutableStorage(fileSection.get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS)); fileElement.setFileName(fileSection.get(TOSCAMetaFileAttributes.NAME)); return fileElement; } ) .sorted(Comparator.comparing(FileProvenanceElement::getFileName)) .collect(Collectors.toList()); model.setFiles(result); } }
public static ManifestContents getManifest(Reader reader) { ManifestParser parser = new RecoveringManifestParser(); try { ManifestContents manifest = parser.parse(reader); if (parser.foundProblems()) { for (ManifestProblem problem : parser.getProblems()) { System.err.println(problem.toStringWithContext()); System.err.println(); } throw new RuntimeException("There was a problem with the manifest"); } return manifest; } catch (IOException e) { throw new RuntimeException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // Nothing to do } } } }
/** * Expects to eat "Name" ":" "<value>" * @return continue? */ public boolean eatNameAttribute() { boolean cont; if (maybeEatHeaderName("Name")) { eatColon(); Token valueToken = tokenStream.next(); tokenStream.next(); // newline cont = visitor.visitSection(false, valueToken.value()); if (!cont) { return false; } visitor.visitHeader(NAME_HEADER, valueToken.value()); } else { Token token = tokenStream.peek(); // ERROR: they didn't supply a Name. Report an error and treat this // as a regular attribute cont = visitor.visitSection(false, null); // still the start of a // section, just has no // name recordProblem(ManifestProblemKind.MISSING_NAME_HEADER, token.getStartOffset(), token.getEndOffset(), token.value()); } return cont; }
for (ModelProvenanceElement modelProvenanceElement : historyElements) { if (Objects.nonNull(modelProvenanceElement.getFingerprint())) { ManifestContents manifestContents = new RecoveringManifestParser() .parse(modelProvenanceElement.getFingerprint());
parser = new RecoveringManifestParser(); reader = new FileReader(toscaMetaFile.toFile()); TOSCAMetaFileParser.LOGGER.debug("Parsing TOSCA meta file \"{}\"...", toscaMetaFile.getFileName().toString());