Search in sources :

Example 1 with ReadableArchive

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

the class ResourceUtil method hasResourcesXML.

public static boolean hasResourcesXML(ReadableArchive archive, ServiceLocator locator) {
    boolean hasResourcesXML = false;
    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 && hasResourcesXML(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 2 with ReadableArchive

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

the class BeanDeploymentArchiveImpl method collectRarInfo.

private void collectRarInfo(ReadableArchive archive) throws IOException, ClassNotFoundException {
    if (logger.isLoggable(FINE)) {
        logger.log(FINE, CDILoggerInfo.COLLECTING_RAR_INFO, new Object[] { archive.getURI() });
    }
    Enumeration<String> entries = archive.entries();
    while (entries.hasMoreElements()) {
        String entry = entries.nextElement();
        if (entry.endsWith(JAR_SUFFIX)) {
            ReadableArchive jarArchive = archive.getSubArchive(entry);
            collectJarInfo(jarArchive, true, true);
        } else {
            handleEntry(archive, entry, true, true);
        }
    }
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 3 with ReadableArchive

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

the class DeploymentImpl method scanForLibJars.

// This method creates and returns a List of BeanDeploymentArchives for each
// Weld enabled jar under /lib of an existing Archive.
private List<RootBeanDeploymentArchive> scanForLibJars(ReadableArchive archive, Collection<EjbDescriptor> ejbs, DeploymentContext context) {
    List<ReadableArchive> libJars = null;
    ApplicationHolder holder = context.getModuleMetaData(ApplicationHolder.class);
    if ((holder != null) && (holder.app != null)) {
        String libDir = holder.app.getLibraryDirectory();
        if (libDir != null && !libDir.isEmpty()) {
            Enumeration<String> entries = archive.entries(libDir);
            while (entries.hasMoreElements()) {
                final String entryName = entries.nextElement();
                // if a jar is directly in lib dir and not WEB-INF/lib/foo/bar.jar
                if (DOLUtils.isScanningAllowed(holder.app, entryName) && entryName.endsWith(JAR_SUFFIX) && entryName.indexOf(SEPARATOR_CHAR, libDir.length() + 1) == -1) {
                    try {
                        ReadableArchive jarInLib = archive.getSubArchive(entryName);
                        if (jarInLib != null && (jarInLib.exists(META_INF_BEANS_XML) || WeldUtils.isImplicitBeanArchive(context, jarInLib))) {
                            if (libJars == null) {
                                libJars = new ArrayList<>();
                            }
                            libJars.add(jarInLib);
                        }
                    } catch (IOException e) {
                        logger.log(FINE, CDILoggerInfo.EXCEPTION_SCANNING_JARS, new Object[] { e });
                    }
                }
            }
        }
    }
    if (libJars != null) {
        String libDir = holder.app.getLibraryDirectory();
        for (ReadableArchive libJarArchive : libJars) {
            createLibJarBda(libJarArchive, ejbs, libDir);
        }
    }
    return libJarRootBdas;
}
Also used : ApplicationHolder(org.glassfish.javaee.core.deployment.ApplicationHolder) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 4 with ReadableArchive

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

the class ApplicationLoaderService method postConstruct.

/**
 * Starts the application loader service.
 *
 * Look at the list of applications installed in our local repository
 * Get a Deployer capable for each application found
 * Invoke the deployer load() method for each application.
 */
public void postConstruct() {
    assert env != null;
    try {
        logger.fine("Satisfying Optional Packages dependencies...");
        InstalledLibrariesResolver.initializeInstalledLibRegistry(env.getLibPath().getAbsolutePath());
    } catch (Exception e) {
        logger.log(Level.WARNING, KernelLoggerInfo.exceptionOptionalDepend, e);
    }
    DeploymentLifecycleStatsProvider dlsp = new DeploymentLifecycleStatsProvider();
    StatsProviderManager.register("deployment", PluginPoint.SERVER, "deployment/lifecycle", dlsp);
    deploymentTracingEnabled = System.getProperty("org.glassfish.deployment.trace");
    domain = habitat.getService(Domain.class);
    /*
         * Build a map that associates an application with its
         * order in domain.xml.  If the deployment-order attribute
         * is not used for any application, then the applications
         * are loaded in the order they occur in domain.xml.  Also, for
         * applications with the same deployment-order attribute,
         * the applications are loaded in the order they occur in domain.xml.
         * Otherwise, applications are loaded according to the
         * deploynment-order attribute.
         */
    systemApplications = domain.getSystemApplications();
    for (Application systemApp : systemApplications.getApplications()) {
        appOrderInfoMap.put(systemApp.getName(), Integer.valueOf(appOrder++));
    }
    List<Application> standaloneAdapters = applications.getApplicationsWithSnifferType(ServerTags.CONNECTOR, true);
    for (Application standaloneAdapter : standaloneAdapters) {
        appOrderInfoMap.put(standaloneAdapter.getName(), Integer.valueOf(appOrder++));
    }
    List<Application> allApplications = applications.getApplications();
    for (Application app : allApplications) {
        appOrderInfoMap.put(app.getName(), Integer.valueOf(appOrder++));
    }
    for (Application systemApp : systemApplications.getApplications()) {
        // check to see if we need to load up this system application
        if (Boolean.valueOf(systemApp.getDeployProperties().getProperty(ServerTags.LOAD_SYSTEM_APP_ON_STARTUP))) {
            if (deployment.isAppEnabled(systemApp) || loadAppOnDAS(systemApp.getName())) {
                Integer order = appOrderInfoMap.get(systemApp.getName());
                ApplicationOrderInfo info = new ApplicationOrderInfo(systemApp, order);
                DeploymentOrder.addApplicationDeployment(info);
            }
        }
    }
    // load standalone resource adapters first
    for (Application standaloneAdapter : standaloneAdapters) {
        // information is available on DAS
        if (deployment.isAppEnabled(standaloneAdapter) || loadAppOnDAS(standaloneAdapter.getName())) {
            DeploymentOrder.addApplicationDeployment(new ApplicationOrderInfo(standaloneAdapter, appOrderInfoMap.get(standaloneAdapter.getName()).intValue()));
        }
    }
    // then the rest of the applications
    for (Application app : allApplications) {
        if (app.isStandaloneModule() && app.containsSnifferType(ServerTags.CONNECTOR)) {
            continue;
        }
        // information is available on DAS
        if (Boolean.valueOf(app.getEnabled()) || loadAppOnDAS(app.getName())) {
            DeploymentOrder.addApplicationDeployment(new ApplicationOrderInfo(app, appOrderInfoMap.get(app.getName()).intValue()));
        }
    }
    List<Deployment.ApplicationDeployment> appDeployments = new ArrayList<>();
    // process the deployed applications
    Iterator iter = DeploymentOrder.getApplicationDeployments();
    while (iter.hasNext()) {
        Application app = (Application) iter.next();
        ApplicationRef appRef = server.getApplicationRef(app.getName());
        if (appRef != null) {
            // Does the application need to be run on this instance?
            appDeployments.addAll(processApplication(app, appRef));
        }
    }
    // does the user want us to run a particular application
    String defaultParam = env.getStartupContext().getArguments().getProperty("default");
    if (defaultParam != null) {
        initializeRuntimeDependencies();
        File sourceFile;
        if (defaultParam.equals(".")) {
            sourceFile = new File(System.getProperty("user.dir"));
        } else {
            sourceFile = new File(defaultParam);
        }
        if (sourceFile.exists()) {
            sourceFile = sourceFile.getAbsoluteFile();
            ReadableArchive sourceArchive = null;
            try {
                sourceArchive = archiveFactoryProvider.get().openArchive(sourceFile);
                DeployCommandParameters parameters = new DeployCommandParameters(sourceFile);
                parameters.name = sourceFile.getName();
                parameters.enabled = Boolean.TRUE;
                parameters.origin = DeployCommandParameters.Origin.deploy;
                ActionReport report = new HTMLActionReporter();
                if (!sourceFile.isDirectory()) {
                    // ok we need to explode the directory somwhere and remember to delete it on shutdown
                    final File tmpFile = File.createTempFile(sourceFile.getName(), "");
                    final String path = tmpFile.getAbsolutePath();
                    if (!tmpFile.delete()) {
                        logger.log(Level.WARNING, KernelLoggerInfo.cantDeleteTempFile, path);
                    }
                    File tmpDir = new File(path);
                    FileUtils.deleteOnExit(tmpDir);
                    events.register(new org.glassfish.api.event.EventListener() {

                        public void event(Event event) {
                            if (event.is(EventTypes.SERVER_SHUTDOWN)) {
                                if (tmpFile.exists()) {
                                    FileUtils.whack(tmpFile);
                                }
                            }
                        }
                    });
                    if (tmpDir.mkdirs()) {
                        ArchiveHandler handler = deployment.getArchiveHandler(sourceArchive);
                        final String appName = handler.getDefaultApplicationName(sourceArchive);
                        DeploymentContextImpl dummyContext = new DeploymentContextImpl(report, logger, sourceArchive, parameters, env);
                        handler.expand(sourceArchive, archiveFactoryProvider.get().createArchive(tmpDir), dummyContext);
                        sourceArchive = archiveFactoryProvider.get().openArchive(tmpDir);
                        logger.log(Level.INFO, KernelLoggerInfo.sourceNotDirectory, tmpDir.getAbsolutePath());
                        parameters.name = appName;
                    }
                }
                ExtendedDeploymentContext depContext = deployment.getBuilder(logger, parameters, report).source(sourceArchive).build();
                Deployment.ApplicationDeployment appDeployment = deployment.prepare(null, depContext);
                if (appDeployment == null) {
                    logger.log(Level.SEVERE, KernelLoggerInfo.cantFindApplicationInfo, sourceFile.getAbsolutePath());
                } else {
                    appDeployments.add(appDeployment);
                }
            } catch (RuntimeException | IOException e) {
                logger.log(Level.SEVERE, KernelLoggerInfo.deployException, e);
            } finally {
                if (sourceArchive != null) {
                    try {
                        sourceArchive.close();
                    } catch (IOException ioe) {
                    // ignore
                    }
                }
            }
        }
    }
    events.send(new Event<>(Deployment.ALL_APPLICATIONS_LOADED, null), false);
    for (Deployment.ApplicationDeployment depl : appDeployments) {
        deployment.initialize(depl.appInfo, depl.appInfo.getSniffers(), depl.context);
    }
    events.send(new Event<>(Deployment.ALL_APPLICATIONS_PROCESSED, null));
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ActionReport(org.glassfish.api.ActionReport) DeploymentLifecycleStatsProvider(org.glassfish.deployment.monitor.DeploymentLifecycleStatsProvider) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) DeploymentContextImpl(org.glassfish.deployment.common.DeploymentContextImpl) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HTMLActionReporter(com.sun.enterprise.admin.report.HTMLActionReporter) Event(org.glassfish.api.event.EventListener.Event) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 5 with ReadableArchive

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

the class ApplicationLoaderService method loadApplicationForTenants.

private List<Deployment.ApplicationDeployment> loadApplicationForTenants(Application app, ApplicationRef appRef, ActionReport report) {
    if (app.getAppTenants() == null) {
        return Collections.unmodifiableList(Collections.emptyList());
    }
    List<Deployment.ApplicationDeployment> appDeployments = new ArrayList<>();
    for (AppTenant tenant : app.getAppTenants().getAppTenant()) {
        DeployCommandParameters commandParams = app.getDeployParameters(appRef);
        commandParams.contextroot = tenant.getContextRoot();
        commandParams.target = server.getName();
        commandParams.name = DeploymentUtils.getInternalNameForTenant(app.getName(), tenant.getTenant());
        commandParams.enabled = Boolean.TRUE;
        commandParams.origin = DeployCommandParameters.Origin.load;
        ActionReport subReport = report.addSubActionsReport();
        ReadableArchive archive = null;
        try {
            URI uri = new URI(app.getLocation());
            File file = new File(uri);
            if (file.exists()) {
                archive = archiveFactoryProvider.get().openArchive(file);
                ExtendedDeploymentContext deploymentContext = deployment.getBuilder(KernelLoggerInfo.getLogger(), commandParams, subReport).source(archive).build();
                deploymentContext.getAppProps().putAll(app.getDeployProperties());
                deploymentContext.getAppProps().putAll(tenant.getDeployProperties());
                deploymentContext.setModulePropsMap(app.getModulePropertiesMap());
                deploymentContext.setTenant(tenant.getTenant(), app.getName());
                appDeployments.add(deployment.prepare(deployment.getSniffersFromApp(app), deploymentContext));
            } else {
                logger.log(Level.SEVERE, KernelLoggerInfo.notFoundInOriginalLocation, app.getLocation());
            }
        } catch (Throwable e) {
            subReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            subReport.setMessage(e.getMessage());
            subReport.setFailureCause(e);
        } finally {
            try {
                if (archive != null) {
                    archive.close();
                }
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return Collections.unmodifiableList(appDeployments);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) URI(java.net.URI) File(java.io.File)

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