Search in sources :

Example 31 with ArtifactTemplateId

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());
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 32 with ArtifactTemplateId

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);
}
Also used : ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 33 with ArtifactTemplateId

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");
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 34 with ArtifactTemplateId

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));
        }
    }
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 35 with ArtifactTemplateId

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);
    }
}
Also used : Path(java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) GitInfo(org.eclipse.winery.repository.GitInfo) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)

Aggregations

ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)36 QName (javax.xml.namespace.QName)20 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)13 IOException (java.io.IOException)10 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)10 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)9 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)9 RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)9 Test (org.junit.jupiter.api.Test)9 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)8 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)8 ArrayList (java.util.ArrayList)7 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)7 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)7 Path (java.nio.file.Path)6 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)6 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 InputStream (java.io.InputStream)5 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)5