Search in sources :

Example 16 with WritableArchive

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

the class EarHandler method expand.

@Override
public void expand(ReadableArchive source, WritableArchive target, DeploymentContext context) throws IOException {
    // expand the top level first so we could read application.xml
    super.expand(source, target, context);
    ReadableArchive source2 = null;
    try {
        /*
             * We know that the expansion is into a directory, so we should know that target is a FileArchive which is also readable
             * as-is.
             */
        source2 = (FileArchive) target;
        ApplicationHolder holder = getApplicationHolder(source2, context, false);
        // now start to expand the sub modules
        for (ModuleDescriptor md : holder.app.getModules()) {
            String moduleUri = md.getArchiveUri();
            ReadableArchive subArchive = null;
            WritableArchive subTarget = null;
            ReadableArchive subArchiveToExpand = null;
            try {
                subArchive = source2.getSubArchive(moduleUri);
                if (subArchive == null) {
                    _logger.log(Level.WARNING, "Exception while locating sub archive: " + moduleUri);
                    continue;
                }
                // optimize performance by retrieving the archive handler
                // based on module type first
                ArchiveHandler subHandler = getArchiveHandlerFromModuleType(md.getModuleType());
                if (subHandler == null) {
                    subHandler = deployment.getArchiveHandler(subArchive);
                }
                context.getModuleArchiveHandlers().put(moduleUri, subHandler);
                if (subHandler != null) {
                    subTarget = target.createSubArchive(FileUtils.makeFriendlyFilenameExtension(moduleUri));
                    /*
                         * A subarchive might be packaged as a subdirectory (instead of a nested JAR) in an EAR. If so and if it has the same
                         * name as the directory into which we'll expand the submodule, make sure it is also of the correct archive type (i.e.,
                         * directory and not JAR) in which case we don't need to expand it because the developer already did so before
                         * packaging.
                         */
                    subArchiveToExpand = chooseSubArchiveToExpand(moduleUri, subTarget, subArchive, source2);
                    if (subArchiveToExpand != null) {
                        subHandler.expand(subArchiveToExpand, subTarget, context);
                    } else {
                        /*
                             * The target for expansion is the same URI as the subarchive. Make sure they are the same type; if so, we just skip the
                             * expansion. Otherwise, we would leave a JAR where the rest of deployment expects a subdirectory so throw an exception
                             * in that case.
                             */
                        if (!areSameStorageType(subTarget, subArchive)) {
                            final String msg = MessageFormat.format(_logger.getResourceBundle().getString("enterprise.deployment.backend.badSubModPackaging"), subArchive.getURI().toASCIIString(), subArchive.getClass().getName());
                            throw new RuntimeException(msg);
                        }
                    }
                // Keep the original submodule file because the app client deployer needs it.
                /*
                         * // delete the original module file File origSubArchiveFile = new File( target.getURI().getSchemeSpecificPart(),
                         * moduleUri); origSubArchiveFile.delete();
                         */
                }
            } catch (IOException ioe) {
                _logger.log(Level.FINE, "Exception while processing " + moduleUri, ioe);
            } finally {
                try {
                    if (subArchive != null) {
                        subArchive.close();
                    }
                    if (subTarget != null) {
                        subTarget.close();
                    }
                    if (subArchiveToExpand != null) {
                        subArchiveToExpand.close();
                    }
                } catch (IOException ioe) {
                // ignore
                }
            }
        }
    } finally {
        if (source2 != null) {
            source2.close();
        }
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) AbstractArchiveHandler(com.sun.enterprise.deploy.shared.AbstractArchiveHandler) ApplicationHolder(org.glassfish.javaee.core.deployment.ApplicationHolder) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Aggregations

WritableArchive (org.glassfish.api.deployment.archive.WritableArchive)16 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)11 IOException (java.io.IOException)4 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)4 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 File (java.io.File)2 Vector (java.util.Vector)2 JarFile (java.util.jar.JarFile)2 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)2 AbstractArchiveHandler (com.sun.enterprise.deploy.shared.AbstractArchiveHandler)1 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 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 Enumeration (java.util.Enumeration)1