use of org.eclipse.winery.repository.export.CsarContentProperties 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.export.CsarContentProperties in project winery by eclipse.
the class YamlToscaExportUtil method putRemoteRefAsReferencedItemInCsar.
/**
* Puts the given reference as item in the CSAR
* <p>
* Thereby, it uses the global variable referencesToPathInCSARMap
*/
protected String putRemoteRefAsReferencedItemInCsar(URL url, String typePath, String artifactName) {
RemoteRefBasedCsarEntry ref = new RemoteRefBasedCsarEntry(url);
String fileName = FilenameUtils.getName(url.getPath());
String type = StringUtils.removeEnd(typePath, "/");
String path = StringUtils.join(Arrays.asList(type, "files", artifactName, fileName), "/");
this.referencesToPathInCSARMap.put(new CsarContentProperties(path), ref);
return path;
}
use of org.eclipse.winery.repository.export.CsarContentProperties in project winery by eclipse.
the class YamlExporter method writeCsar.
/**
* Writes a complete CSAR containing all necessary things reachable from the given service template
*
* @param entryId the id of the service template to export
* @param out the output stream to write to
* @return the TOSCA meta file for the generated Csar
*/
@Override
public String writeCsar(DefinitionsChildId entryId, OutputStream out, Map<String, Object> exportConfiguration) throws IOException, RepositoryCorruptException {
LOGGER.trace("Starting CSAR export with {}", entryId.toString());
Map<CsarContentProperties, CsarEntry> refMap = new HashMap<>();
YamlToscaExportUtil exporter = new YamlToscaExportUtil();
ExportedState exportedState = new ExportedState();
DefinitionsChildId currentId = entryId;
Collection<DefinitionsChildId> referencedIds;
// Process definitions and referenced files
do {
String definitionsPathInsideCSAR = getDefinitionsPathInsideCSAR(repository, currentId);
CsarContentProperties definitionsFileProperties = new CsarContentProperties(definitionsPathInsideCSAR);
if (!YamlRepository.ROOT_TYPE_QNAME.equals(currentId.getQName())) {
referencedIds = exporter.processTOSCA(repository, currentId, definitionsFileProperties, refMap, exportConfiguration);
// for each entryId add license and readme files (if they exist) to the refMap
addLicenseAndReadmeFiles(currentId, refMap);
exportedState.flagAsExported(currentId);
exportedState.flagAsExportRequired(referencedIds);
}
currentId = exportedState.pop();
} while (currentId != null);
// Archive creation
try (final ZipOutputStream zos = new ZipOutputStream(out)) {
// write all referenced files
for (Map.Entry<CsarContentProperties, CsarEntry> entry : refMap.entrySet()) {
CsarContentProperties fileProperties = entry.getKey();
CsarEntry ref = entry.getValue();
LOGGER.trace("Creating {}", fileProperties.getPathInsideCsar());
if (ref instanceof RepositoryRefBasedCsarEntry && ((RepositoryRefBasedCsarEntry) ref).getReference().getParent() instanceof DirectoryId) {
addArtifactTemplateToZipFile(zos, (RepositoryRefBasedCsarEntry) ref, fileProperties);
} else {
addCsarEntryToArchive(zos, ref, fileProperties);
}
}
// create manifest file and add it to archive
return this.addManifest(repository, entryId, refMap, zos, exportConfiguration);
}
}
Aggregations