use of org.codehaus.plexus.archiver.ResourceIterator in project sofa-ark by alipay.
the class ArkPluginMojo method getLibFileArchiveEntries.
private List<ArchiveEntry> getLibFileArchiveEntries(Archiver archiver) {
ResourceIterator resourceIterator = archiver.getResources();
List<ArchiveEntry> result = new ArrayList<>();
while (resourceIterator.hasNext()) {
ArchiveEntry archiveEntry = resourceIterator.next();
if (archiveEntry.getType() == ArchiveEntry.FILE) {
String name = archiveEntry.getName();
if (name.startsWith("lib/") && name.endsWith(".jar")) {
if (name.indexOf("/") == name.lastIndexOf("/") && name.contains("/")) {
result.add(archiveEntry);
}
}
}
}
return result;
}
use of org.codehaus.plexus.archiver.ResourceIterator in project docker-maven-plugin by fabric8io.
the class AllFilesExecCustomizer method customize.
@Override
public TarArchiver customize(TarArchiver archiver) throws IOException {
log.warn("/--------------------- SECURITY WARNING ---------------------\\");
log.warn("|You are building a Docker image with normalized permissions.|");
log.warn("|All files and directories added to build context will have |");
log.warn("|'-rwxr-xr-x' permissions. It is recommended to double check |");
log.warn("|and reset permissions for sensitive files and directories. |");
log.warn("\\------------------------------------------------------------/");
TarArchiver newArchiver = new TarArchiver();
newArchiver.setDestFile(archiver.getDestFile());
newArchiver.setLongfile(TarLongFileMode.posix);
ResourceIterator resources = archiver.getResources();
while (resources.hasNext()) {
ArchiveEntry ae = resources.next();
String fileName = ae.getName();
PlexusIoResource resource = ae.getResource();
String name = StringUtils.replace(fileName, File.separatorChar, '/');
// See docker source:
// https://github.com/docker/docker/blob/3d13fddd2bc4d679f0eaa68b0be877e5a816ad53/pkg/archive/archive_windows.go#L45
int mode = ae.getMode() & 0777;
int newMode = mode;
newMode &= 0755;
newMode |= 0111;
if (newMode != mode) {
log.debug("Changing permissions of '%s' from %o to %o.", name, mode, newMode);
}
newArchiver.addResource(resource, name, newMode);
}
archiver = newArchiver;
return archiver;
}
use of org.codehaus.plexus.archiver.ResourceIterator 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);
}
};
}
Aggregations