use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TComplianceRule complianceRule = this.getElement(id);
// TODO extend to required Structure
if (complianceRule.getIdentifier() != null) {
for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// There may be multiple DAs/IAs referencing the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
final TNodeTypeImplementation element = this.getElement(id);
// DAs
TDeploymentArtifacts deploymentArtifacts = element.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts.getDeploymentArtifact()) {
QName qname;
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
ids.add(new ArtifactTypeId(da.getArtifactType()));
}
}
// IAs
return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class CsarExporter method addArtifactTemplateToZipFile.
/**
* Special handling for artifact template directories source and files
*
* @param zos Output stream for the archive that should contain the file
* @param ref Reference to the file that should be added to the archive
* @param archivePath Path to the file inside the archive
* @throws IOException thrown when the temporary directory can not be created
*/
private void addArtifactTemplateToZipFile(ArchiveOutputStream zos, IGenericRepository repository, RepositoryFileReference ref, String archivePath) throws IOException {
GitInfo gitInfo = BackendUtils.getGitInformation((DirectoryId) ref.getParent());
if (gitInfo == null) {
try (InputStream is = repository.newInputStream(ref)) {
if (is != null) {
ArchiveEntry archiveEntry = new ZipArchiveEntry(archivePath);
zos.putArchiveEntry(archiveEntry);
IOUtils.copy(is, zos);
zos.closeArchiveEntry();
}
} catch (Exception e) {
CsarExporter.LOGGER.error("Could not copy file to ZIP outputstream", e);
}
return;
}
// TODO: This is not quite correct. The files should reside checked out at "source/"
Path tempDir = Files.createTempDirectory(WINERY_TEMP_DIR_PREFIX);
try {
Git git = Git.cloneRepository().setURI(gitInfo.URL).setDirectory(tempDir.toFile()).call();
git.checkout().setName(gitInfo.BRANCH).call();
String path = "artifacttemplates/" + Util.URLencode(((ArtifactTemplateId) ref.getParent().getParent()).getQName().getNamespaceURI()) + "/" + ((ArtifactTemplateId) ref.getParent().getParent()).getQName().getLocalPart() + "/files/";
TArtifactTemplate template = BackendUtils.getTArtifactTemplate((DirectoryId) ref.getParent());
addWorkingTreeToArchive(zos, template, tempDir, path);
} catch (GitAPIException e) {
CsarExporter.LOGGER.error(String.format("Error while cloning repo: %s / %s", gitInfo.URL, gitInfo.BRANCH), e);
} finally {
deleteDirectory(tempDir);
}
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class FilebasedRepositoryTest method referenceCountIsOneForBaobab.
@Test
public void referenceCountIsOneForBaobab() throws Exception {
this.setRevisionTo("5b7f106ab79a9ba137ece9167a79753dfc64ac84");
final ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://winery.opentosca.org/test/artifacttemplates/fruits", "baobab_bananaInterface_IA", false);
Assert.assertEquals(1, this.repository.getReferenceCount(artifactTemplateId));
}
use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class FilebasedRepositoryTest method allFilesCorrectlyImported.
@Test
public void allFilesCorrectlyImported() throws Exception {
this.setRevisionTo("5b7f106ab79a9ba137ece9167a79753dfc64ac84");
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
Path workingDir = Files.createTempDirectory("winery");
final Path subDir = workingDir.resolve(subDirectories);
Files.createDirectories(subDir);
Path tempFile = subDir.resolve("test.txt");
Files.createFile(tempFile);
BackendUtils.importDirectory(workingDir, this.repository, artifactTemplateSourceDirectoryId);
RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
Assert.assertTrue(repository.exists(ref));
}
Aggregations