Search in sources :

Example 1 with ExportedState

use of org.eclipse.winery.repository.export.ExportedState 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);
    }
}
Also used : RemoteRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) YAMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) HashMap(java.util.HashMap) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CsarContentProperties(org.eclipse.winery.repository.export.CsarContentProperties) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) ZipOutputStream(java.util.zip.ZipOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) ExportedState(org.eclipse.winery.repository.export.ExportedState)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 DirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId)1 CsarContentProperties (org.eclipse.winery.repository.export.CsarContentProperties)1 ExportedState (org.eclipse.winery.repository.export.ExportedState)1 CsarEntry (org.eclipse.winery.repository.export.entries.CsarEntry)1 DefinitionsBasedCsarEntry (org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry)1 DocumentBasedCsarEntry (org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry)1 RemoteRefBasedCsarEntry (org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry)1 RepositoryRefBasedCsarEntry (org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry)1 XMLDefinitionsBasedCsarEntry (org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry)1 YAMLDefinitionsBasedCsarEntry (org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry)1