use of org.eclipse.winery.model.tosca.TArtifactReference in project winery by eclipse.
the class BackendUtils method synchronizeReferences.
public static void synchronizeReferences(ArtifactTemplateId id) throws IOException {
TArtifactTemplate template = RepositoryFactory.getRepository().getElement(id);
DirectoryId fileDir = new ArtifactTemplateFilesDirectoryId(id);
SortedSet<RepositoryFileReference> files = RepositoryFactory.getRepository().getContainedFiles(fileDir);
if (files.isEmpty()) {
// clear artifact references
template.setArtifactReferences(null);
} else {
TArtifactTemplate.ArtifactReferences artifactReferences = new TArtifactTemplate.ArtifactReferences();
template.setArtifactReferences(artifactReferences);
List<TArtifactReference> artRefList = artifactReferences.getArtifactReference();
for (RepositoryFileReference ref : files) {
// determine path
// path relative from the root of the CSAR is ok (COS01, line 2663)
// double encoded - see ADR-0003
String path = Util.getUrlPath(ref);
// put path into data structure
// we do not use Include/Exclude as we directly reference a concrete file
TArtifactReference artRef = new TArtifactReference();
artRef.setReference(path);
artRefList.add(artRef);
}
}
BackendUtils.persist(id, template);
}
use of org.eclipse.winery.model.tosca.TArtifactReference in project winery by eclipse.
the class CsarExporter method addWorkingTreeToArchive.
/**
* Adds a working tree to an archive
*
* @param file The current directory to add
* @param zos Output stream of the archive
* @param template Template of the artifact
* @param rootDir The root of the working tree
* @param archivePath The path inside the archive to the working tree
*/
private void addWorkingTreeToArchive(File file, ArchiveOutputStream zos, TArtifactTemplate template, Path rootDir, String archivePath) {
if (file.isDirectory()) {
if (file.getName().equals(".git")) {
return;
}
File[] files = file.listFiles();
if (files != null) {
for (File f : files) {
addWorkingTreeToArchive(f, zos, template, rootDir, archivePath);
}
}
} else {
boolean foundInclude = false;
boolean included = false;
boolean excluded = false;
for (TArtifactReference artifactReference : template.getArtifactReferences().getArtifactReference()) {
for (Object includeOrExclude : artifactReference.getIncludeOrExclude()) {
if (includeOrExclude instanceof TArtifactReference.Include) {
foundInclude = true;
TArtifactReference.Include include = (TArtifactReference.Include) includeOrExclude;
String reference = artifactReference.getReference();
if (reference.endsWith("/")) {
reference += include.getPattern();
} else {
reference += "/" + include.getPattern();
}
reference = reference.substring(1);
included |= BackendUtils.isGlobMatch(reference, rootDir.relativize(file.toPath()));
} else if (includeOrExclude instanceof TArtifactReference.Exclude) {
TArtifactReference.Exclude exclude = (TArtifactReference.Exclude) includeOrExclude;
String reference = artifactReference.getReference();
if (reference.endsWith("/")) {
reference += exclude.getPattern();
} else {
reference += "/" + exclude.getPattern();
}
reference = reference.substring(1);
excluded |= BackendUtils.isGlobMatch(reference, rootDir.relativize(file.toPath()));
}
}
}
if ((!foundInclude || included) && !excluded) {
try (InputStream is = new FileInputStream(file)) {
ArchiveEntry archiveEntry = new ZipArchiveEntry(archivePath + rootDir.relativize(Paths.get(file.getAbsolutePath())));
zos.putArchiveEntry(archiveEntry);
IOUtils.copy(is, zos);
zos.closeArchiveEntry();
} catch (Exception e) {
CsarExporter.LOGGER.error("Could not copy file to ZIP outputstream", e);
}
}
}
}
Aggregations