use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId in project winery by eclipse.
the class ToscaExportUtil method prepareForExport.
/**
* Determines the referenced definition children Ids and also updates the references in the Artifact Template
*
* @return a collection of referenced definition child Ids
*/
private void prepareForExport(IRepository repository, ArtifactTemplateId id) throws RepositoryCorruptException, IOException {
// Export files
// This method is called BEFORE the concrete definitions element is written.
// Therefore, we adapt the content of the attached files to the really existing files
BackendUtils.synchronizeReferences(id);
DirectoryId fileDir = new ArtifactTemplateFilesDirectoryId(id);
SortedSet<RepositoryFileReference> files = repository.getContainedFiles(fileDir);
for (RepositoryFileReference ref : files) {
// Even if writing a TOSCA only (!this.writingCSAR),
// we put the virtual path in the TOSCA
// Reason: Winery is mostly used as a service and local storage
// reference to not make sense
// The old implementation had absolutePath.toUri().toString();
// there, but this does not work when using a cloud blob store.
this.putRefAsReferencedItemInCsar(ref);
}
}
use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId in project winery by eclipse.
the class CsarImporter method adjustArtifactTemplate.
/**
* Adjusts the given artifact template to conform with the repository format
* <p>
* We import the files given at the artifact references
*/
private void adjustArtifactTemplate(Path rootPath, TOSCAMetaFile tmf, ArtifactTemplateId atid, TArtifactTemplate ci, final List<String> errors) {
ArtifactReferences refs = ci.getArtifactReferences();
if (refs == null) {
// no references stored - break
return;
}
List<TArtifactReference> refList = refs.getArtifactReference();
Iterator<TArtifactReference> iterator = refList.iterator();
while (iterator.hasNext()) {
TArtifactReference ref = iterator.next();
String reference = ref.getReference();
// URLs are stored encoded -> undo the encoding
reference = Util.URLdecode(reference);
URI refURI;
try {
refURI = new URI(reference);
} catch (URISyntaxException e) {
errors.add(String.format("Invalid URI %1$s", ref));
continue;
}
if (refURI.isAbsolute()) {
// We have to do nothing
continue;
}
// we remove the current element as it will be handled during the export
iterator.remove();
Path path = rootPath.resolve(reference);
if (!Files.exists(path)) {
errors.add(String.format("Reference %1$s not found", reference));
return;
}
Set<Path> allFiles;
if (Files.isRegularFile(path)) {
allFiles = new HashSet<>();
allFiles.add(path);
} else {
if (!Files.isDirectory(path)) {
LOGGER.error("path {} is not a directory", path);
}
Path localRoot = rootPath.resolve(path);
List<Object> includeOrExclude = ref.getIncludeOrExclude();
if (includeOrExclude.get(0) instanceof TArtifactReference.Exclude) {
// Implicit semantics of an exclude listed first:
// include all files and then exclude the files matched by the pattern
allFiles = this.getAllFiles(localRoot);
} else {
// semantics if include listed as first:
// same as listed at other places
allFiles = new HashSet<>();
}
for (Object object : includeOrExclude) {
if (object instanceof TArtifactReference.Include) {
this.handleInclude((TArtifactReference.Include) object, localRoot, allFiles);
} else {
assert (object instanceof TArtifactReference.Exclude);
this.handleExclude((TArtifactReference.Exclude) object, localRoot, allFiles);
}
}
}
DirectoryId fileDir = new ArtifactTemplateFilesDirectoryId(atid);
this.importAllFiles(rootPath, allFiles, fileDir, tmf, errors);
}
if (refList.isEmpty()) {
// everything is imported and is a file stored locally
// we don't need the references stored locally: they are generated on the fly when exporting
ci.setArtifactReferences(null);
}
}
Aggregations