Search in sources :

Example 1 with ArchiveEntry

use of org.codehaus.plexus.archiver.ArchiveEntry 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;
}
Also used : ArchiveEntry(org.codehaus.plexus.archiver.ArchiveEntry) ResourceIterator(org.codehaus.plexus.archiver.ResourceIterator)

Example 2 with ArchiveEntry

use of org.codehaus.plexus.archiver.ArchiveEntry 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;
}
Also used : TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) PlexusIoResource(org.codehaus.plexus.components.io.resources.PlexusIoResource) ArchiveEntry(org.codehaus.plexus.archiver.ArchiveEntry) ResourceIterator(org.codehaus.plexus.archiver.ResourceIterator)

Example 3 with ArchiveEntry

use of org.codehaus.plexus.archiver.ArchiveEntry in project sofa-ark by alipay.

the class ArkPluginMojo method addExportIndex.

private void addExportIndex(Archiver archiver) throws MojoExecutionException {
    List<ArchiveEntry> archiveEntries = getLibFileArchiveEntries(archiver);
    List<String> exportClasses = new ArrayList<>();
    for (ArchiveEntry archiveEntry : archiveEntries) {
        if (this.exported.getPackages() != null) {
            exportClasses.addAll(scanJar(archiveEntry, this.exported.getPackages()));
        }
    }
    if (this.exported.getClasses() != null) {
        exportClasses.addAll(this.exported.getClasses());
    }
    StringBuilder sb = new StringBuilder(8092);
    for (String clazz : exportClasses) {
        sb.append(clazz).append('\n');
    }
    addArkPluginConfig(archiver, "conf/export.index", sb.toString());
    this.getLog().info(String.format("Generate conf/export.index, total export classes count: %d", exportClasses.size()));
}
Also used : ArchiveEntry(org.codehaus.plexus.archiver.ArchiveEntry)

Aggregations

ArchiveEntry (org.codehaus.plexus.archiver.ArchiveEntry)3 ResourceIterator (org.codehaus.plexus.archiver.ResourceIterator)2 TarArchiver (org.codehaus.plexus.archiver.tar.TarArchiver)1 PlexusIoResource (org.codehaus.plexus.components.io.resources.PlexusIoResource)1