Search in sources :

Example 1 with TOSCA_META_VERSION

use of org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.TOSCA_META_VERSION in project winery by eclipse.

the class CsarExporter method addManifest.

private String addManifest(DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
    String entryDefinitionsReference = CsarExporter.getDefinitionsPathInsideCSAR(repository, id);
    out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
    StringBuilder stringBuilder = new StringBuilder();
    // Setting Versions
    stringBuilder.append(TOSCA_META_VERSION).append(": 1.0").append("\n");
    stringBuilder.append(CSAR_VERSION).append(": 1.0").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 DefinitionsBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
        } else {
            mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
        }
        stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
        if (exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_HASHES.name()) && Objects.nonNull(fileProperties.getFileHash())) {
            stringBuilder.append(HASH).append(": ").append(fileProperties.getFileHash()).append("\n");
        }
        if (exportConfiguration.containsKey(CsarExportConfiguration.STORE_IMMUTABLY.name()) && Objects.nonNull(fileProperties.getImmutableAddress())) {
            stringBuilder.append(IMMUTABLE_ADDRESS).append(": ").append(fileProperties.getImmutableAddress()).append("\n");
        }
        stringBuilder.append("\n");
    }
    String manifestString = stringBuilder.toString();
    out.write(manifestString.getBytes());
    out.closeEntry();
    return manifestString;
}
Also used : SortedSet(java.util.SortedSet) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) LoggerFactory(org.slf4j.LoggerFactory) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) DirectoryStream(java.nio.file.DirectoryStream) ServiceTemplateSelfServiceFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ServiceTemplateSelfServiceFilesDirectoryId) SelfServiceMetaDataUtils(org.eclipse.winery.repository.backend.SelfServiceMetaDataUtils) SelfContainmentPackager(org.eclipse.winery.repository.backend.selfcontainmentpackager.SelfContainmentPackager) IdNames(org.eclipse.winery.model.ids.IdNames) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Duration(java.time.Duration) Map(java.util.Map) TOSCA_META_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.TOSCA_META_VERSION) GenericId(org.eclipse.winery.model.ids.GenericId) Util(org.eclipse.winery.repository.common.Util) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CREATED_BY(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CREATED_BY) ENTRY_DEFINITIONS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.ENTRY_DEFINITIONS) Collection(java.util.Collection) Constants(org.eclipse.winery.common.Constants) IMMUTABLE_ADDRESS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS) Options(org.eclipse.winery.model.selfservice.Application.Options) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) CSAR_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CSAR_VERSION) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) HASH(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.HASH) NAME(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.NAME) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) ZipOutputStream(java.util.zip.ZipOutputStream) ApplicationOption(org.eclipse.winery.model.selfservice.ApplicationOption) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) LocalDateTime(java.time.LocalDateTime) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) Application(org.eclipse.winery.model.selfservice.Application) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) OutputStream(java.io.OutputStream) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Environments(org.eclipse.winery.common.configuration.Environments) GitInfo(org.eclipse.winery.repository.GitInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ExecutionException(java.util.concurrent.ExecutionException) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId) Paths(java.nio.file.Paths) SelfServiceMetaDataId(org.eclipse.winery.repository.datatypes.ids.elements.SelfServiceMetaDataId) HashingUtil(org.eclipse.winery.common.HashingUtil) Git(org.eclipse.jgit.api.Git) InputStream(java.io.InputStream) CONTENT_TYPE(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CONTENT_TYPE) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) ZipEntry(java.util.zip.ZipEntry) Map(java.util.Map) HashMap(java.util.HashMap) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 DirectoryStream (java.nio.file.DirectoryStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Duration (java.time.Duration)1 LocalDateTime (java.time.LocalDateTime)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 SortedSet (java.util.SortedSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1