use of org.codehaus.plexus.archiver.FileSet in project docker-maven-plugin by fabric8io.
the class MappingTrackArchiver method getAssemblyFiles.
/**
* Get all files depicted by this assembly.
*
* @return assembled files
*/
public AssemblyFiles getAssemblyFiles(MavenSession session) {
AssemblyFiles ret = new AssemblyFiles(new File(getDestFile().getParentFile(), assemblyName));
// Where the 'real' files are copied to
for (Addition addition : added) {
Object resource = addition.resource;
File target = new File(ret.getAssemblyDirectory(), addition.destination);
if (resource instanceof File && addition.destination != null) {
addFileEntry(ret, session, (File) resource, target);
} else if (resource instanceof PlexusIoFileResource) {
addFileEntry(ret, session, ((PlexusIoFileResource) resource).getFile(), target);
} else if (resource instanceof FileSet) {
FileSet fs = (FileSet) resource;
DirectoryScanner ds = new DirectoryScanner();
File base = addition.directory;
ds.setBasedir(base);
ds.setIncludes(fs.getIncludes());
ds.setExcludes(fs.getExcludes());
ds.setCaseSensitive(fs.isCaseSensitive());
ds.scan();
for (String f : ds.getIncludedFiles()) {
File source = new File(base, f);
File subTarget = new File(target, f);
addFileEntry(ret, session, source, subTarget);
}
} else {
throw new IllegalStateException("Unknown resource type " + resource.getClass() + ": " + resource);
}
}
return ret;
}
use of org.codehaus.plexus.archiver.FileSet in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManagerTest method testArchiveCreationDockerfileNoAssembly.
@Test
public void testArchiveCreationDockerfileNoAssembly(@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()).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(2, fileSets.size());
assertEquals("build", fileSets.get(0).getDirectory().getName());
assertNull(fileSets.get(0).getIncludes());
assertNull(fileSets.get(0).getExcludes());
assertArrayEquals(new String[] { "target/**", "Dockerfile.test" }, fileSets.get(1).getExcludes());
assertNull(fileSets.get(1).getIncludes());
}
};
}
use of org.codehaus.plexus.archiver.FileSet 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());
}
};
}
use of org.codehaus.plexus.archiver.FileSet 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());
}
};
}
use of org.codehaus.plexus.archiver.FileSet in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManagerTest method testArchiveCreationDockerfileWithDirAssembly.
@Test
public void testArchiveCreationDockerfileWithDirAssembly(@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.dir.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;
List<FileSet> fileSets = new ArrayList<>();
tarArchiver.addFileSet(withCapture(fileSets));
assertEquals(2, fileSets.size());
assertEquals("build", fileSets.get(0).getDirectory().getName());
assertNull(fileSets.get(0).getIncludes());
assertNull(fileSets.get(0).getExcludes());
assertArrayEquals(new String[] { "target/**", "Dockerfile.test" }, fileSets.get(1).getExcludes());
assertNull(fileSets.get(1).getIncludes());
}
};
}
Aggregations