use of org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser in project winery by eclipse.
the class AccountabilityManagerImpl method fillFilesOfModel.
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);
}
use of org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser in project winery by eclipse.
the class TOSCAMetaFileParser method parse.
/**
* Parses and validates the <code>toscaMetaFile</code>.
*
* @param toscaMetaFile path to the metadata file to process
* @return <code>TOSCAMetaFile</code> that gives access to the content of
* the TOSCA meta file. If the given file doesn't exist or is invalid <code>null</code>.
*/
public TOSCAMetaFile parse(Path toscaMetaFile) {
FileReader reader = null;
ManifestParser parser;
ManifestContents manifestContent;
TOSCAMetaFile toscaMetaFileContent = null;
try {
parser = new RecoveringManifestParser();
reader = new FileReader(toscaMetaFile.toFile());
TOSCAMetaFileParser.LOGGER.debug("Parsing TOSCA meta file \"{}\"...", toscaMetaFile.getFileName().toString());
manifestContent = parser.parse(reader);
reader.close();
// counts the errors during parsing
int numErrors = 0;
for (ManifestProblem problem : parser.getProblems()) {
this.logManifestProblem(problem);
numErrors++;
}
toscaMetaFileContent = this.parse(manifestContent, numErrors);
} catch (FileNotFoundException exc) {
TOSCAMetaFileParser.LOGGER.error("\"{}\" doesn't exist or is not a file.", toscaMetaFile, exc);
} catch (IOException exc) {
TOSCAMetaFileParser.LOGGER.error("An IO Exception occured.", exc);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException exc) {
TOSCAMetaFileParser.LOGGER.warn("An IOException occured.", exc);
}
}
}
return toscaMetaFileContent;
}
use of org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser in project winery by eclipse.
the class CsarExporterTest method testCsarFilesAreMentionedInTheManifest.
@Test
public void testCsarFilesAreMentionedInTheManifest() throws Exception {
Map<String, Object> exportConfiguration = new HashMap<>();
exportConfiguration.put(INCLUDE_HASHES.name(), null);
try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false), exportConfiguration);
ZipInputStream zis = new ZipInputStream(inputStream)) {
ZipEntry entry;
List<String> elementsList = new ArrayList<>();
ManifestContents manifestContents = null;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
elementsList.add(name);
assertNotNull(name);
assertFalse(name.contains("\\"), "name contains backslashes");
if ("TOSCA-Metadata/TOSCA.meta".equals(name)) {
byte[] bytes = IOUtils.toByteArray(zis);
String s = new String(bytes, StandardCharsets.UTF_8);
manifestContents = new RecoveringManifestParser().parse(s);
}
}
assertNotNull(manifestContents);
for (String section : manifestContents.getSectionNames()) {
// ensures that the file is contained in the archive
assertTrue(elementsList.remove(section), "Contains element " + section);
}
// ensures that the manifest was part of the archive
assertTrue(elementsList.remove("TOSCA-Metadata/TOSCA.meta"));
// ensures that every file in the archive is listed in the manifest
assertEquals(0, elementsList.size());
}
}
use of org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser in project winery by eclipse.
the class CsarExporterTest method parseManifest.
private ManifestContents parseManifest(ZipInputStream zis) throws IOException {
ZipEntry entry;
ManifestContents manifestContents = null;
while ((entry = zis.getNextEntry()) != null) {
if ("TOSCA-Metadata/TOSCA.meta".equals(entry.getName())) {
byte[] bytes = IOUtils.toByteArray(zis);
String s = new String(bytes, StandardCharsets.UTF_8);
manifestContents = new RecoveringManifestParser().parse(s);
}
}
return manifestContents;
}
use of org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser in project winery by eclipse.
the class AccountabilityManagerImpl method getHistoryOfSingleFile.
protected List<FileProvenanceElement> getHistoryOfSingleFile(List<ModelProvenanceElement> historyElements, String fileId, AuthorizationInfo authorizationInfo) {
List<FileProvenanceElement> history = new ArrayList<>();
if (Objects.nonNull(historyElements) && historyElements.size() > 0) {
for (ModelProvenanceElement modelProvenanceElement : historyElements) {
if (Objects.nonNull(modelProvenanceElement.getFingerprint())) {
ManifestContents manifestContents = new RecoveringManifestParser().parse(modelProvenanceElement.getFingerprint());
for (String name : manifestContents.getSectionNames()) {
if (name.equals(fileId)) {
modelProvenanceElement.setAuthorizedFlag(authorizationInfo);
modelProvenanceElement.setAuthorName(authorizationInfo.getRealWorldIdentity(modelProvenanceElement.getAuthorAddress()).orElseGet(String::new));
FileProvenanceElement currentFile = new FileProvenanceElement(modelProvenanceElement);
currentFile.setAddressInImmutableStorage(manifestContents.getAttributesForSection(name).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
currentFile.setFileHash(TOSCAMetaFileAttributes.HASH + "-" + manifestContents.getAttributesForSection(name).get(TOSCAMetaFileAttributes.HASH));
currentFile.setFileName(fileId);
history.add(currentFile);
break;
}
}
}
}
}
if (history.size() > 0)
return history;
return null;
}
Aggregations