Search in sources :

Example 11 with WritableArchive

use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.

the class FileArchive method createSubArchive.

/**
 * create or obtain an embedded archive within this abstraction.
 *
 * @param name name of the embedded archive.
 */
@Override
public WritableArchive createSubArchive(String name) throws IOException {
    String subEntryName = getFileSubArchivePath(name);
    File subEntry = new File(subEntryName);
    if (!subEntry.exists()) {
        // time to create a new sub directory
        if (!subEntry.exists() && !subEntry.mkdirs()) {
            throw new IOException("Unable to create directory for " + subEntry.getAbsolutePath());
        }
        deplLogger.log(DEBUG_LEVEL, "FileArchive.createSubArchive created dirs for {0}", subEntry.getAbsolutePath());
    } else {
        deplLogger.log(DEBUG_LEVEL, "FileArchive.createSubArchive found existing dir for {0}", subEntry.getAbsolutePath());
        /*
             * This subdirectory already exists, so it might be marked as
             * stale. Because this invocation is creating the subarchive in
             * the current archive, the subdirectory is no longer stale.
             */
        staleFileManager().recordValidEntry(subEntry);
    }
    final WritableArchive result = archiveFactory.createArchive(subEntry);
    if (result instanceof AbstractReadableArchive) {
        ((AbstractReadableArchive) result).setParentArchive(this);
    }
    return result;
}
Also used : JarFile(java.util.jar.JarFile) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 12 with WritableArchive

use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.

the class FileArchiveTest method createAndPopulateArchive.

private ReadableArchive createAndPopulateArchive(final Set<String> entryNames) throws Exception {
    // new FileArchive();
    WritableArchive instance = archiveFactory.createArchive(archiveDir.toURI());
    instance.create(archiveDir.toURI());
    /*
         * Add some entries.
         */
    for (String entryName : entryNames) {
        instance.putNextEntry(entryName);
        instance.closeEntry();
    }
    instance.close();
    return archiveFactory.openArchive(archiveDir);
}
Also used : WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 13 with WritableArchive

use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.

the class FileArchiveTest method createAndPopulateSubarchive.

private ReadableArchive createAndPopulateSubarchive(final WritableArchive parent, final String subarchiveName, final Set<String> entryNames) throws Exception {
    final WritableArchive result = parent.createSubArchive(subarchiveName);
    for (String entryName : entryNames) {
        result.putNextEntry(entryName);
        result.closeEntry();
    }
    result.close();
    final ReadableArchive readableParent = archiveFactory.openArchive(parent.getURI());
    return readableParent.getSubArchive(subarchiveName);
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 14 with WritableArchive

use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.

the class UpgradeStartup method processModule.

// repackage a module and return it as a jar file
private File processModule(File moduleDir, String targetParentDir, String suffix) throws IOException {
    String moduleName = moduleDir.getName();
    // sub module in ear case
    if (moduleName.endsWith("_jar") || moduleName.endsWith("_war") || moduleName.endsWith("_rar")) {
        suffix = "." + moduleName.substring(moduleName.length() - 3);
        moduleName = moduleName.substring(0, moduleName.lastIndexOf('_'));
    }
    ReadableArchive source = archiveFactory.openArchive(moduleDir);
    File tempJar = new File(targetParentDir, moduleName + suffix);
    if (tempJar.exists()) {
        boolean isDeleted = tempJar.delete();
        if (!isDeleted) {
            logger.log(Level.WARNING, "Error in deleting file " + tempJar.getAbsolutePath());
        }
    }
    WritableArchive target = archiveFactory.createArchive("jar", tempJar);
    Enumeration<String> e = source.entries();
    while (e.hasMoreElements()) {
        String entryName = e.nextElement();
        if (isSigFile(entryName)) {
            logger.log(Level.INFO, "Excluding signature file: " + entryName + " from repackaged module: " + moduleName + "\n");
            continue;
        }
        InputStream sis = source.getEntry(entryName);
        if (sis != null) {
            InputStream is = new BufferedInputStream(sis);
            OutputStream os = null;
            try {
                os = target.putNextEntry(entryName);
                FileUtils.copy(is, os, source.getEntrySize(entryName));
            } finally {
                if (os != null) {
                    target.closeEntry();
                }
                is.close();
            }
        }
    }
    // last is manifest if existing.
    Manifest m = source.getManifest();
    if (m != null) {
        processManifest(m, moduleName);
        OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
        m.write(os);
        target.closeEntry();
    }
    source.close();
    target.close();
    return tempJar;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Aggregations

WritableArchive (org.glassfish.api.deployment.archive.WritableArchive)14 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)9 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)3 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)2 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)2 DOLUtils.setExtensionArchivistForSubArchivist (com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist)2 IOException (java.io.IOException)2 Enumeration (java.util.Enumeration)2 Vector (java.util.Vector)2 JarFile (java.util.jar.JarFile)2 Archivist (com.sun.enterprise.deployment.archivist.Archivist)1 DeploymentPlanArchive (com.sun.enterprise.deployment.deploy.shared.DeploymentPlanArchive)1 ApplicationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 LogRecord (java.util.logging.LogRecord)1 MultiException (org.glassfish.hk2.api.MultiException)1