Search in sources :

Example 1 with ArchivedFileSet

use of org.codehaus.plexus.archiver.ArchivedFileSet in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method testArchiveCreationDockerfileWithArchiveAssembly.

@Test
public void testArchiveCreationDockerfileWithArchiveAssembly(@Injectable final TarArchiver tarArchiver, @Injectable final Logger logger) throws MojoExecutionException, NoSuchArchiverException {
    MojoParameters mojoParams = mockMojoParams(mockMavenProject());
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().dockerFile(DockerAssemblyManagerTest.class.getResource("/docker/Dockerfile.test").getPath()).assembly(new AssemblyConfiguration.Builder().mode(AssemblyMode.tar.name()).assemblyDef(new Assembly()).build()).build();
    buildImageConfiguration.initAndValidate(logger);
    File tarArchive = assemblyManager.createDockerTarArchive("test_image", mojoParams, buildImageConfiguration, logger, null);
    assertNotNull(tarArchive);
    new Verifications() {

        {
            archiverManager.getArchiver("tar");
            times = 1;
            List<FileSet> fileSets = new ArrayList<>();
            tarArchiver.addFileSet(withCapture(fileSets));
            assertEquals(1, fileSets.size());
            assertArrayEquals(new String[] { "target/**", "Dockerfile.test" }, fileSets.get(0).getExcludes());
            assertNull(fileSets.get(0).getIncludes());
            tarArchiver.addFile(new File("target/test_image/build/Dockerfile.test"), "Dockerfile.test");
            List<ArchivedFileSet> archivedFileSets = new ArrayList<>();
            tarArchiver.addArchivedFileSet(withCapture(archivedFileSets));
            assertEquals(1, archivedFileSets.size());
            assertEquals(new File("target/test_image/build/maven.tar"), archivedFileSets.get(0).getArchive());
            assertEquals("maven/", archivedFileSets.get(0).getPrefix());
        }
    };
}
Also used : FileSet(org.codehaus.plexus.archiver.FileSet) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) ArrayList(java.util.ArrayList) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) Verifications(mockit.Verifications) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) Test(org.junit.Test)

Example 2 with ArchivedFileSet

use of org.codehaus.plexus.archiver.ArchivedFileSet in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method testArchiveCreationDockerfileWithMultipleArchiveAssemblies.

@Test
public void testArchiveCreationDockerfileWithMultipleArchiveAssemblies(@Injectable final TarArchiver tarArchiver, @Injectable final Logger logger) throws MojoExecutionException, NoSuchArchiverException {
    MojoParameters mojoParams = mockMojoParams(mockMavenProject());
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().dockerFile(DockerAssemblyManagerTest.class.getResource("/docker/Dockerfile.test").getPath()).assemblies(Arrays.asList(new AssemblyConfiguration.Builder().name("first").mode(AssemblyMode.tar.name()).assemblyDef(new Assembly()).build(), new AssemblyConfiguration.Builder().name("second").mode(AssemblyMode.tar.name()).assemblyDef(new Assembly()).build())).build();
    buildImageConfiguration.initAndValidate(logger);
    File tarArchive = assemblyManager.createDockerTarArchive("test_image", mojoParams, buildImageConfiguration, logger, null);
    assertNotNull(tarArchive);
    new Verifications() {

        {
            archiverManager.getArchiver("tar");
            times = 1;
            List<FileSet> fileSets = new ArrayList<>();
            tarArchiver.addFileSet(withCapture(fileSets));
            assertEquals(1, fileSets.size());
            assertArrayEquals(new String[] { "target/**", "Dockerfile.test" }, fileSets.get(0).getExcludes());
            assertNull(fileSets.get(0).getIncludes());
            tarArchiver.addFile(new File("target/test_image/build/Dockerfile.test"), "Dockerfile.test");
            List<ArchivedFileSet> archivedFileSets = new ArrayList<>();
            tarArchiver.addArchivedFileSet(withCapture(archivedFileSets));
            assertEquals(2, archivedFileSets.size());
            assertEquals(new File("target/test_image/build/first.tar"), archivedFileSets.get(0).getArchive());
            assertEquals("first/", archivedFileSets.get(0).getPrefix());
            assertEquals(new File("target/test_image/build/second.tar"), archivedFileSets.get(1).getArchive());
            assertEquals("second/", archivedFileSets.get(1).getPrefix());
        }
    };
}
Also used : FileSet(org.codehaus.plexus.archiver.FileSet) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) ArrayList(java.util.ArrayList) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) Verifications(mockit.Verifications) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) Test(org.junit.Test)

Example 3 with ArchivedFileSet

use of org.codehaus.plexus.archiver.ArchivedFileSet in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method testArchiveCreationNoDockerfileWithExecutableAssemblies.

@Test
public void testArchiveCreationNoDockerfileWithExecutableAssemblies(@Mocked final PlexusIoResource resource, @Mocked final ArchiveEntry archiveEntry, @Mocked final TarArchiver tarArchiver, @Injectable final Logger logger) throws MojoExecutionException, NoSuchArchiverException, IOException {
    MojoParameters mojoParams = mockMojoParams(mockMavenProject());
    FileItem testFile = new FileItem();
    testFile.setDestName("test.txt");
    testFile.setSource("test.in");
    Assembly testAssembly = new Assembly();
    testAssembly.addFile(testFile);
    new Expectations() {

        {
            archiveEntry.getName();
            result = "test";
            archiveEntry.getMode();
            result = 0644;
            archiveEntry.getResource();
            result = resource;
            tarArchiver.getResources();
            result = new ResourceIterator() {

                boolean consumed = false;

                @Override
                public boolean hasNext() {
                    return !consumed;
                }

                @Override
                public ArchiveEntry next() {
                    if (consumed) {
                        return null;
                    }
                    consumed = true;
                    return archiveEntry;
                }
            };
        }
    };
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().assemblies(Collections.singletonList(new AssemblyConfiguration.Builder().name("first").mode(AssemblyMode.tar.name()).assemblyDef(testAssembly).permissions(AssemblyConfiguration.PermissionMode.exec.name()).build())).build();
    buildImageConfiguration.initAndValidate(logger);
    File tarArchive = assemblyManager.createDockerTarArchive("test_image", mojoParams, buildImageConfiguration, logger, null);
    assertNotNull(tarArchive);
    new Verifications() {

        {
            archiverManager.getArchiver("tar");
            times = 1;
            tarArchiver.addFile(new File("target/test_image/build/Dockerfile"), "Dockerfile");
            List<ArchivedFileSet> archivedFileSets = new ArrayList<>();
            tarArchiver.addArchivedFileSet(withCapture(archivedFileSets));
            assertEquals(1, archivedFileSets.size());
            assertEquals(new File("target/test_image/build/first.tar"), archivedFileSets.get(0).getArchive());
            assertEquals("first/", archivedFileSets.get(0).getPrefix());
            tarArchiver.addResource((PlexusIoResource) any, "test", 0755);
        }
    };
}
Also used : Expectations(mockit.Expectations) ArrayList(java.util.ArrayList) ArchiveEntry(org.codehaus.plexus.archiver.ArchiveEntry) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) Verifications(mockit.Verifications) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) FileItem(org.apache.maven.plugins.assembly.model.FileItem) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) ResourceIterator(org.codehaus.plexus.archiver.ResourceIterator) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) Test(org.junit.Test)

Example 4 with ArchivedFileSet

use of org.codehaus.plexus.archiver.ArchivedFileSet in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method testArchiveCreationNoDockerfileWithMultipleArchiveAssemblies.

@Test
public void testArchiveCreationNoDockerfileWithMultipleArchiveAssemblies(@Injectable final TarArchiver tarArchiver, @Injectable final Logger logger) throws MojoExecutionException, NoSuchArchiverException {
    MojoParameters mojoParams = mockMojoParams(mockMavenProject());
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().assemblies(Arrays.asList(new AssemblyConfiguration.Builder().name("first").mode(AssemblyMode.tar.name()).assemblyDef(new Assembly()).build(), new AssemblyConfiguration.Builder().name("second").mode(AssemblyMode.tar.name()).assemblyDef(new Assembly()).build())).build();
    buildImageConfiguration.initAndValidate(logger);
    File tarArchive = assemblyManager.createDockerTarArchive("test_image", mojoParams, buildImageConfiguration, logger, null);
    assertNotNull(tarArchive);
    new Verifications() {

        {
            archiverManager.getArchiver("tar");
            times = 1;
            tarArchiver.addFile(new File("target/test_image/build/Dockerfile"), "Dockerfile");
            List<ArchivedFileSet> archivedFileSets = new ArrayList<>();
            tarArchiver.addArchivedFileSet(withCapture(archivedFileSets));
            assertEquals(2, archivedFileSets.size());
            assertEquals(new File("target/test_image/build/first.tar"), archivedFileSets.get(0).getArchive());
            assertEquals("first/", archivedFileSets.get(0).getPrefix());
            assertEquals(new File("target/test_image/build/second.tar"), archivedFileSets.get(1).getArchive());
            assertEquals("second/", archivedFileSets.get(1).getPrefix());
        }
    };
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) ArrayList(java.util.ArrayList) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) Verifications(mockit.Verifications) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)4 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Verifications (mockit.Verifications)4 Assembly (org.apache.maven.plugins.assembly.model.Assembly)4 ArchivedFileSet (org.codehaus.plexus.archiver.ArchivedFileSet)4 Test (org.junit.Test)4 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)3 FileSet (org.codehaus.plexus.archiver.FileSet)2 Expectations (mockit.Expectations)1 FileItem (org.apache.maven.plugins.assembly.model.FileItem)1 ArchiveEntry (org.codehaus.plexus.archiver.ArchiveEntry)1 ResourceIterator (org.codehaus.plexus.archiver.ResourceIterator)1