use of org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry in project winery by eclipse.
the class YamlExporter method addManifest.
private String addManifest(IRepository repository, DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
String entryDefinitionsReference = getDefinitionsPathInsideCSAR(repository, id);
out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
StringBuilder stringBuilder = new StringBuilder();
// Setting Versions
stringBuilder.append(TOSCA_META_FILE_VERSION).append(": ").append(TOSCA_META_FILE_VERSION_VALUE).append("\n");
stringBuilder.append(CSAR_VERSION).append(": ").append(CSAR_VERSION_VALUE_FOR_YAML).append("\n");
stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
// Winery currently is unaware of tDefinitions, therefore, we use the
// name of the service template
stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
stringBuilder.append("\n");
assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
// Setting other files, mainly files belonging to artifacts
for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
final CsarEntry csarEntry = item.getValue();
final CsarContentProperties fileProperties = item.getKey();
stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
String mimeType;
if (csarEntry instanceof DocumentBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_XSD;
} else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof YAMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
} else if (csarEntry instanceof RemoteRefBasedCsarEntry) {
mimeType = repository.getMimeType((RemoteRefBasedCsarEntry) csarEntry);
} else {
mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
}
stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
stringBuilder.append("\n");
}
String manifestString = stringBuilder.toString();
out.write(manifestString.getBytes());
out.closeEntry();
return manifestString;
}
use of org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry in project winery by eclipse.
the class YamlToscaExportUtil method processDefinitionsElement.
@Override
protected Collection<DefinitionsChildId> processDefinitionsElement(IRepository repository, DefinitionsChildId tcId, CsarContentProperties definitionsFileProperties) throws RepositoryCorruptException, IOException {
if (!repository.exists(tcId)) {
String error = "Component instance " + tcId.toReadableString() + " does not exist.";
LOGGER.error(error);
throw new RepositoryCorruptException(error);
}
TDefinitions entryDefinitions = repository.getDefinitions(tcId);
this.getPrepareForExport(repository, tcId, entryDefinitions);
Collection<DefinitionsChildId> referencedDefinitionsChildIds = repository.getReferencedDefinitionsChildIds(tcId);
if (!EXPORT_NORMATIVE_TYPES) {
referencedDefinitionsChildIds.removeIf(id -> id.getQName().getNamespaceURI().startsWith("tosca"));
}
// adjust imports: add imports of definitions
Collection<TImport> imports = new ArrayList<>();
Map<String, QName> importDefinitions = new HashMap<>();
for (DefinitionsChildId id : referencedDefinitionsChildIds) {
this.addToImports(repository, id, imports);
String defName = YamlExporter.getDefinitionsName(repository, id).concat(Constants.SUFFIX_TOSCA_DEFINITIONS);
importDefinitions.put(defName, id.getQName());
}
entryDefinitions.getImport().addAll(imports);
entryDefinitions.setImportDefinitions(importDefinitions);
// END: Definitions modification
YAMLDefinitionsBasedCsarEntry entry = new YAMLDefinitionsBasedCsarEntry(repository, entryDefinitions);
// Custom Adjustments for Service Templates
YamlExportAdjustmentsBuilder adjustmentsBuilder = new YamlExportAdjustmentsBuilder(entry);
if (!EXPORT_NORMATIVE_TYPES) {
adjustmentsBuilder.removeNormativeTypeImports();
}
entry = adjustmentsBuilder.setMetadataName(tcId).build();
this.referencesToPathInCSARMap.put(definitionsFileProperties, entry);
return referencedDefinitionsChildIds;
}
Aggregations