use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final Path subDirectories = Paths.get("d1", "d2");
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "d1", "d2", "file.txt"), artifactTemplateSourceDirectoryId);
assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
assertEquals(Optional.of(subDirectories), repositoryFileReference.getSubDirectory());
assertEquals("file.txt", repositoryFileReference.getFileName());
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class BackendUtilsTest method synchronizeReferencesRemovesNonExistentFileAndDoesNotRemoveUrls.
@Test
public void synchronizeReferencesRemovesNonExistentFileAndDoesNotRemoveUrls() throws Exception {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://example.org", "test-artifact-template", false);
// alternative test implementation: Use git-based repository
// this test at hand is closer to the implementation, but easier to write
IRepository repository = mock(IRepository.class);
ArtifactTemplateFilesDirectoryId artifactTemplateFilesDirectoryId = new ArtifactTemplateFilesDirectoryId(artifactTemplateId);
when(repository.getContainedFiles(artifactTemplateFilesDirectoryId)).thenReturn(Collections.emptySortedSet());
TArtifactTemplate artifactTemplate = createArtifactTemplateWithReferenceToAnUrlAndANonExistentFile();
when(repository.getElement(artifactTemplateId)).thenReturn(artifactTemplate);
TArtifactTemplate synchronizhedArtifactTemplate = BackendUtils.synchronizeReferences(repository, artifactTemplateId);
assertEquals(createArtifactTemplateWithSingleReferenceToAnUrl(), synchronizhedArtifactTemplate);
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class CsarExporterTest method csarIsValidZipForArtifactTemplateWithFilesAndSources.
@Test
public void csarIsValidZipForArtifactTemplateWithFilesAndSources() throws Exception {
Map<String, Object> exportConfiguration = new HashMap<>();
exportConfiguration.put(INCLUDE_HASHES.name(), null);
try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ArtifactTemplateId("http://plain.winery.opentosca.org/artifacttemplates", "ArtifactTemplateWithFilesAndSources-ArtifactTypeWithoutProperties", false), exportConfiguration);
ZipInputStream zis = new ZipInputStream(inputStream)) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
assertNotNull(name);
assertFalse(name.contains("\\"), "name contains backslashes");
}
}
}
use of org.eclipse.winery.model.ids.definitions.ArtifactTemplateId in project winery by eclipse.
the class CsarExporterTest method metafileDoesNotContainUnnecessaryFileAttributes.
@Test
public void metafileDoesNotContainUnnecessaryFileAttributes() throws Exception {
// create an empty configuration object
Map<String, Object> exportConfiguration = new HashMap<>();
try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ArtifactTemplateId("http://plain.winery.opentosca.org/artifacttemplates", "ArtifactTemplateWithFilesAndSources-ArtifactTypeWithoutProperties", false), exportConfiguration);
ZipInputStream zis = new ZipInputStream(inputStream)) {
ManifestContents manifestContents = parseManifest(zis);
assertNotNull(manifestContents);
for (String section : manifestContents.getSectionNames()) {
assertNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.HASH));
assertNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
}
}
}
use of org.eclipse.winery.model.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 csarEntry Reference to the file that should be added to the archive
* @param fileProperties Describing the path to the file inside the archive
* @throws IOException thrown when the temporary directory can not be created
*/
protected void addArtifactTemplateToZipFile(ZipOutputStream zos, RepositoryRefBasedCsarEntry csarEntry, CsarContentProperties fileProperties) throws IOException {
GitInfo gitInfo = BackendUtils.getGitInformation((DirectoryId) csarEntry.getReference().getParent(), repository);
if (gitInfo == null) {
addCsarEntryToArchive(zos, csarEntry, fileProperties);
return;
}
// TODO: This is not quite correct. The files should reside checked out at "source/"
// TODO: Hash all these git files (to be included in the provenance)
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/" + EncodingUtil.URLencode(((ArtifactTemplateId) csarEntry.getReference().getParent().getParent()).getQName().getNamespaceURI()) + "/" + ((ArtifactTemplateId) csarEntry.getReference().getParent().getParent()).getQName().getLocalPart() + "/files/";
TArtifactTemplate template = BackendUtils.getTArtifactTemplate((DirectoryId) csarEntry.getReference().getParent(), repository);
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);
}
}
Aggregations