Search in sources :

Example 1 with SnifferManager

use of org.glassfish.internal.deployment.SnifferManager in project Payara by payara.

the class DOLUtils method getSniffersForModule.

/**
 * get sniffer list for sub modules of an ear application
 */
private static Collection<Sniffer> getSniffersForModule(ServiceLocator habitat, ReadableArchive archive, ModuleDescriptor md, Application app) throws Exception {
    ArchiveHandler handler = habitat.getService(ArchiveHandler.class, md.getModuleType().toString());
    SnifferManager snifferManager = habitat.getService(SnifferManager.class);
    List<URI> classPathURIs = handler.getClassPathURIs(archive);
    classPathURIs.addAll(getLibraryJarURIs(app, archive));
    Types types = archive.getParentArchive().getExtraData(Types.class);
    DeployCommandParameters parameters = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, DeployCommandParameters.class);
    Properties appProps = archive.getParentArchive().getArchiveMetaData(DeploymentProperties.APP_PROPS, Properties.class);
    ExtendedDeploymentContext context = new DeploymentContextImpl(null, archive, parameters, habitat.<ServerEnvironment>getService(ServerEnvironment.class));
    if (appProps != null) {
        context.getAppProps().putAll(appProps);
    }
    context.setArchiveHandler(handler);
    context.addTransientAppMetaData(Types.class.getName(), types);
    Collection<Sniffer> sniffers = snifferManager.getSniffers(context, classPathURIs, types);
    context.postDeployClean(true);
    String type = getTypeFromModuleType(md.getModuleType());
    Sniffer mainSniffer = null;
    for (Sniffer sniffer : sniffers) {
        if (sniffer.getModuleType().equals(type)) {
            mainSniffer = sniffer;
        }
    }
    // to add the appropriate sniffer
    if (mainSniffer == null) {
        mainSniffer = snifferManager.getSniffer(type);
        sniffers.add(mainSniffer);
    }
    String[] incompatibleTypes = mainSniffer.getIncompatibleSnifferTypes();
    List<String> allIncompatTypes = addAdditionalIncompatTypes(mainSniffer, incompatibleTypes);
    List<Sniffer> sniffersToRemove = new ArrayList<>();
    for (Sniffer sniffer : sniffers) {
        for (String incompatType : allIncompatTypes) {
            if (sniffer.getModuleType().equals(incompatType)) {
                deplLogger.log(Level.WARNING, INCOMPATIBLE_TYPE, new Object[] { type, md.getArchiveUri(), incompatType });
                sniffersToRemove.add(sniffer);
            }
        }
    }
    sniffers.removeAll(sniffersToRemove);
    // store the module sniffer information so we don't need to
    // recalculate them later
    Hashtable sniffersTable = archive.getParentArchive().getExtraData(Hashtable.class);
    if (sniffersTable == null) {
        sniffersTable = new Hashtable<String, Collection<Sniffer>>();
        archive.getParentArchive().setExtraData(Hashtable.class, sniffersTable);
    }
    sniffersTable.put(md.getArchiveUri(), sniffers);
    return sniffers;
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) Types(org.glassfish.hk2.classmodel.reflect.Types) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) SnifferManager(org.glassfish.internal.deployment.SnifferManager) Sniffer(org.glassfish.api.container.Sniffer) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Collection(java.util.Collection)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)1 Sniffer (org.glassfish.api.container.Sniffer)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)1 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)1 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)1 Types (org.glassfish.hk2.classmodel.reflect.Types)1 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)1 SnifferManager (org.glassfish.internal.deployment.SnifferManager)1