Search in sources :

Example 31 with ReadableArchive

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

the class ApplicationArchivist method readModulesDescriptors.

/**
 * read the modules deployment descriptor from this application object using the passed archive
 *
 * @param app
 *            application containing the list of modules.
 * @param appArchive
 *            containing the sub modules files.
 * @return true if everything went fine
 */
public boolean readModulesDescriptors(Application app, ReadableArchive appArchive) throws IOException, SAXParseException {
    List<ModuleDescriptor> nonexistentModules = new ArrayList<>();
    List<ModuleDescriptor> sortedModules = sortModules(app);
    for (ModuleDescriptor aModule : sortedModules) {
        if (aModule.getArchiveUri().indexOf(' ') != -1) {
            throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.unsupporturi", "Unsupported module URI {0}, it contains space(s)", new Object[] { aModule.getArchiveUri() }));
        }
        if (getDefaultLogger().isLoggable(FINE)) {
            getDefaultLogger().fine("Opening sub-module " + aModule);
        }
        BundleDescriptor descriptor = null;
        Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
        newArchivist.initializeContext(this);
        newArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
        newArchivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
        newArchivist.setAnnotationProcessingRequested(annotationProcessingRequested);
        ReadableArchive embeddedArchive = appArchive.getSubArchive(aModule.getArchiveUri());
        if (embeddedArchive == null) {
            throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.nosuchmodule", "Could not find sub module [{0}] as defined in application.xml", new Object[] { aModule.getArchiveUri() }));
        }
        embeddedArchive.setParentArchive(appArchive);
        setExtensionArchivistForSubArchivist(habitat, embeddedArchive, aModule, app, newArchivist);
        if (aModule.getAlternateDescriptor() != null) {
            // The module use alternate deployement descriptor, ignore the DDs in the archive.
            InputStream is = appArchive.getEntry(aModule.getAlternateDescriptor());
            DeploymentDescriptorFile ddFile = newArchivist.getStandardDDFile();
            ddFile.setXMLValidation(newArchivist.getXMLValidation());
            ddFile.setXMLValidationLevel(newArchivist.getXMLValidationLevel());
            if (appArchive.getURI() != null) {
                ddFile.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
            }
            descriptor = (BundleDescriptor) ddFile.read(is);
            descriptor.setApplication(app);
            is.close();
            // TODO : JD need to be revisited for EAR files with Alternative descriptors, what does
            // it mean for sub components.
            Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions = new HashMap<>();
            List<ExtensionsArchivist> extensionsArchivists = newArchivist.getExtensionArchivists();
            if (extensionsArchivists != null) {
                for (ExtensionsArchivist extension : extensionsArchivists) {
                    Object rdd = extension.open(newArchivist, embeddedArchive, descriptor);
                    if (rdd instanceof RootDeploymentDescriptor) {
                        extensions.put(extension, (RootDeploymentDescriptor) rdd);
                    }
                }
            }
            newArchivist.postStandardDDsRead(descriptor, embeddedArchive, extensions);
            newArchivist.readAnnotations(embeddedArchive, descriptor, extensions);
            newArchivist.postAnnotationProcess(descriptor, embeddedArchive);
            newArchivist.postOpen(descriptor, embeddedArchive);
            // Now reads the runtime deployment descriptor...
            if (isHandlingRuntimeInfo()) {
                readAlternativeRuntimeDescriptor(appArchive, embeddedArchive, newArchivist, descriptor, aModule.getAlternateDescriptor());
                // Read extensions runtime deployment descriptors if any
                for (Map.Entry<ExtensionsArchivist, RootDeploymentDescriptor> extension : extensions.entrySet()) {
                    // After standard DD and annotations are processed we should have an extension descriptor now
                    if (extension.getValue() != null) {
                        extension.getKey().readRuntimeDeploymentDescriptor(newArchivist, embeddedArchive, extension.getValue());
                    }
                }
            }
        } else {
            // Open the subarchive to get the deployment descriptor...
            descriptor = newArchivist.open(embeddedArchive, app);
        }
        embeddedArchive.close();
        if (descriptor != null) {
            descriptor.getModuleDescriptor().setArchiveUri(aModule.getArchiveUri());
            aModule.setModuleName(descriptor.getModuleDescriptor().getModuleName());
            aModule.setDescriptor(descriptor);
            descriptor.setApplication(app);
            aModule.setManifest(newArchivist.getManifest());
            // For optional application.xml case, set the context root as module name for web modules
            if (!appArchive.exists("META-INF/application.xml")) {
                if (aModule.getModuleType().equals(DOLUtils.warType())) {
                    WebBundleDescriptor wbd = (WebBundleDescriptor) descriptor;
                    if (wbd.getContextRoot() != null && !wbd.getContextRoot().equals("")) {
                        aModule.setContextRoot(wbd.getContextRoot());
                    } else {
                        aModule.setContextRoot(aModule.getModuleName());
                    }
                }
            }
        } else {
            // Display a message only if we had a handle on the sub archive
            return false;
        }
    }
    // don't get processed further
    for (ModuleDescriptor nonexistentModule : nonexistentModules) {
        app.removeModule(nonexistentModule);
    }
    return true;
}
Also used : DOLUtils.setExtensionArchivistForSubArchivist(com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) ApplicationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) RootDeploymentDescriptor(org.glassfish.deployment.common.RootDeploymentDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with ReadableArchive

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

the class ApplicationArchivist method copyInto.

/**
 * Copy this archivist to a new abstract archive
 *
 * @param a
 *            the deployment descriptor for an application
 * @param source
 *            the source archive
 * @param target
 *            the target archive
 * @param overwriteManifest
 *            if true, the manifest in source archive overwrites the one in target
 */
public void copyInto(Application a, ReadableArchive source, WritableArchive target, boolean overwriteManifest) throws IOException {
    Vector<String> entriesAdded = new Vector<>();
    for (ModuleDescriptor aModule : a.getModules()) {
        entriesAdded.add(aModule.getArchiveUri());
        ReadableArchive subSource = source.getSubArchive(aModule.getArchiveUri());
        WritableArchive subTarget = target.createSubArchive(aModule.getArchiveUri());
        Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
        ReadableArchive subArchive = archiveFactory.openArchive(subTarget.getURI());
        subSource.setParentArchive(subArchive);
        newArchivist.copyInto(subSource, subTarget, overwriteManifest);
        target.closeEntry(subTarget);
        String subModulePath = subSource.getURI().getSchemeSpecificPart();
        String parentPath = source.getURI().getSchemeSpecificPart();
        if (subModulePath.startsWith(parentPath)) {
            subModulePath = subModulePath.substring(parentPath.length() + File.separator.length());
            for (Enumeration<String> subEntries = subSource.entries(); subEntries.hasMoreElements(); ) {
                String anEntry = subEntries.nextElement();
                entriesAdded.add(subModulePath + "/" + anEntry);
            }
        }
        subSource.close();
        subArchive.close();
    }
    super.copyInto(source, target, entriesAdded, overwriteManifest);
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) DOLUtils.setExtensionArchivistForSubArchivist(com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Vector(java.util.Vector) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 33 with ReadableArchive

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

the class Archivist method copyAnEntry.

// only copy the entry if the destination archive does not have this entry
public void copyAnEntry(ReadableArchive in, WritableArchive out, String entryName) throws IOException {
    InputStream is = null;
    InputStream is2 = null;
    ReadableArchive in2 = archiveFactory.openArchive(out.getURI());
    try {
        is = in.getEntry(entryName);
        is2 = in2.getEntry(entryName);
        if (is != null && is2 == null) {
            OutputStream os = out.putNextEntry(entryName);
            ArchivistUtils.copyWithoutClose(is, os);
        }
    } finally {
        /*
             *Close any streams that were opened.
             */
        in2.close();
        if (is != null) {
            is.close();
        }
        if (is2 != null) {
            is2.close();
        }
        out.closeEntry();
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 34 with ReadableArchive

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

the class Archivist method writeContents.

/**
 * writes the content of an archive to a JarFile
 *
 * @param out jar output stream to write to
 */
protected void writeContents(WritableArchive out) throws IOException {
    ReadableArchive in = archiveFactory.openArchive(new File(path));
    writeContents(in, out);
    in.close();
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) JarFile(java.util.jar.JarFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)

Example 35 with ReadableArchive

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

the class Archivist method open.

/**
 * open a new archive file using a file descriptor
 *
 * @param file the archive to open
 */
public T open(File file) throws IOException, SAXParseException {
    path = file.getAbsolutePath();
    ReadableArchive archive = archiveFactory.openArchive(file);
    T descriptor = open(archive);
    archive.close();
    // attempt validation
    validate(null);
    return descriptor;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Aggregations

ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)97 IOException (java.io.IOException)46 File (java.io.File)28 URI (java.net.URI)18 ActionReport (org.glassfish.api.ActionReport)17 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)14 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)12 WritableArchive (org.glassfish.api.deployment.archive.WritableArchive)12 Application (com.sun.enterprise.deployment.Application)10 JarFile (java.util.jar.JarFile)10 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 ArrayList (java.util.ArrayList)9 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)9 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)8 Logger (java.util.logging.Logger)8 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)7 Manifest (java.util.jar.Manifest)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5