Search in sources :

Example 51 with ReadableArchive

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

the class EJBContainerProviderImpl method getRequestedEJBModuleOrLibrary.

/**
 * @returns DeploymentElement if this file represents an EJB module or a library.
 * Returns null if it's an EJB module which name is not present in the list of requested
 * module names.
 */
private DeploymentElement getRequestedEJBModuleOrLibrary(File file, Map<String, Boolean> moduleNames) throws Exception {
    DeploymentElement result = null;
    String fileName = file.getName();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("... Testing ... " + fileName);
    }
    ReadableArchive archive = null;
    InputStream is = null;
    try {
        boolean isEJBModule = false;
        String moduleName = DeploymentUtils.getDefaultEEName(fileName);
        archive = archiveFactory.openArchive(file);
        is = getDeploymentDescriptor(archive);
        if (is != null) {
            isEJBModule = true;
            EjbDeploymentDescriptorFile eddf = new EjbDeploymentDescriptorFile();
            eddf.setXMLValidation(false);
            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) eddf.read(is);
            ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
            moduleDesc.setArchiveUri(fileName);
            moduleName = moduleDesc.getModuleName();
        } else {
            GenericAnnotationDetector detector = new GenericAnnotationDetector(ejbAnnotations);
            isEJBModule = detector.hasAnnotationInArchive(archive);
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("... is EJB module: " + isEJBModule);
            if (isEJBModule) {
                _logger.fine("... is Requested EJB module [" + moduleName + "]: " + (moduleNames.isEmpty() || moduleNames.containsKey(moduleName)));
            }
        }
        if (!isEJBModule || moduleNames.isEmpty()) {
            result = new DeploymentElement(file, isEJBModule, moduleName);
        } else if (moduleNames.containsKey(moduleName) && !moduleNames.get(moduleName)) {
            // Is a requested EJB module and was not found already
            result = new DeploymentElement(file, isEJBModule, moduleName);
            moduleNames.put(moduleName, true);
        }
        return result;
    } finally {
        if (archive != null)
            archive.close();
        if (is != null)
            is.close();
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) EjbDeploymentDescriptorFile(org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GenericAnnotationDetector(org.glassfish.deployment.common.GenericAnnotationDetector) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 52 with ReadableArchive

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

the class ResourceUtil method hasPayaraResourcesXML.

public static boolean hasPayaraResourcesXML(ReadableArchive archive, ServiceLocator locator) {
    boolean hasResourcesXML = false;
    if (archive != null) {
        try {
            if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.earType(), locator)) {
                // handle top-level META-INF/glassfish-resources.xml
                if (archive.exists(PAYARA_RESOURCES_XML_META_INF)) {
                    return true;
                }
                // check sub-module level META-INF/glassfish-resources.xml and WEB-INF/glassfish-resources.xml
                Enumeration<String> entries = archive.entries();
                while (entries.hasMoreElements()) {
                    String element = entries.nextElement();
                    if (element.endsWith(".jar") || element.endsWith(".war") || element.endsWith(".rar") || element.endsWith("_jar") || element.endsWith("_war") || element.endsWith("_rar")) {
                        ReadableArchive subArchive = archive.getSubArchive(element);
                        boolean answer = (subArchive != null && hasPayaraResourcesXML(subArchive, locator));
                        if (subArchive != null) {
                            subArchive.close();
                        }
                        if (answer) {
                            return true;
                        }
                    }
                }
            } else {
                if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.warType(), locator)) {
                    return archive.exists(PAYARA_RESOURCES_XML_WEB_INF);
                } else {
                    return archive.exists(PAYARA_RESOURCES_XML_META_INF);
                }
            }
        } catch (IOException ioe) {
        // ignore
        }
    }
    return hasResourcesXML;
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 53 with ReadableArchive

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

the class ResourceUtil method hasGlassfishResourcesXML.

public static boolean hasGlassfishResourcesXML(ReadableArchive archive, ServiceLocator locator) {
    boolean hasResourcesXML = false;
    if (archive != null) {
        try {
            if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.earType(), locator)) {
                // handle top-level META-INF/glassfish-resources.xml
                if (archive.exists(RESOURCES_XML_META_INF)) {
                    return true;
                }
                // check sub-module level META-INF/glassfish-resources.xml and WEB-INF/glassfish-resources.xml
                Enumeration<String> entries = archive.entries();
                while (entries.hasMoreElements()) {
                    String element = entries.nextElement();
                    if (element.endsWith(".jar") || element.endsWith(".war") || element.endsWith(".rar") || element.endsWith("_jar") || element.endsWith("_war") || element.endsWith("_rar")) {
                        ReadableArchive subArchive = archive.getSubArchive(element);
                        boolean answer = (subArchive != null && hasGlassfishResourcesXML(subArchive, locator));
                        if (subArchive != null) {
                            subArchive.close();
                        }
                        if (answer) {
                            return true;
                        }
                    }
                }
            } else {
                if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.warType(), locator)) {
                    return archive.exists(RESOURCES_XML_WEB_INF);
                } else {
                    return archive.exists(RESOURCES_XML_META_INF);
                }
            }
        } catch (IOException ioe) {
        // ignore
        }
    }
    return hasResourcesXML;
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 54 with ReadableArchive

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

the class WeldCompositeSniffer method scanLibDir.

// This method returns true if at least one /lib jar is a Weld archive
// A more thorough scan is done in WeldDeployer to extract all Weld archives
// under the /lib directory.
private boolean scanLibDir(ReadableArchive archive, String libLocation, DeploymentContext context) {
    boolean entryPresent = false;
    if (libLocation != null && !libLocation.isEmpty()) {
        Enumeration<String> entries = archive.entries(libLocation);
        while (entries.hasMoreElements() && !entryPresent) {
            String entryName = entries.nextElement();
            // if a jar in lib dir and not WEB-INF/lib/foo/bar.jar
            if (entryName.endsWith(WeldUtils.JAR_SUFFIX) && entryName.indexOf(WeldUtils.SEPARATOR_CHAR, libLocation.length() + 1) == -1) {
                try {
                    ReadableArchive jarInLib = archive.getSubArchive(entryName);
                    entryPresent = isArchiveCDIEnabled(context, jarInLib, WeldUtils.META_INF_BEANS_XML);
                    if (!entryPresent) {
                        entryPresent = WeldUtils.isImplicitBeanArchive(context, jarInLib);
                    }
                    jarInLib.close();
                    if (entryPresent)
                        break;
                } catch (IOException e) {
                }
            }
        }
    }
    return entryPresent;
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 55 with ReadableArchive

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

the class WeldCompositeSniffer method handles.

public boolean handles(DeploymentContext context) {
    ArchiveType archiveType = habitat.getService(ArchiveType.class, context.getArchiveHandler().getArchiveType());
    if (archiveType != null && !supportsArchiveType(archiveType)) {
        return false;
    }
    boolean isWeldApplication = false;
    ApplicationHolder holder = context.getModuleMetaData(ApplicationHolder.class);
    ReadableArchive appRoot = context.getSource();
    if ((holder != null) && (holder.app != null)) {
        isWeldApplication = scanLibDir(appRoot, holder.app.getLibraryDirectory(), context);
    }
    return isWeldApplication;
}
Also used : ApplicationHolder(org.glassfish.javaee.core.deployment.ApplicationHolder) ArchiveType(org.glassfish.api.deployment.archive.ArchiveType) 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