Package org.glassfish.internal.deployment

Examples of org.glassfish.internal.deployment.ExtendedDeploymentContext


            return null;
        }

        commandParams._type = app.archiveType();

        final ExtendedDeploymentContext deploymentContext =
                getBuilder(logger, commandParams, report).source(appInfo.getSource()).build();

        deploymentContext.getAppProps().putAll(
            app.getDeployProperties());
        deploymentContext.setModulePropsMap(
            app.getModulePropertiesMap());

        if (commandParams.properties != null) {
            deploymentContext.getAppProps().putAll(commandParams.properties);
        }

        unload(appInfo, deploymentContext);
        return deploymentContext;
    }
View Full Code Here


                throw new Exception(localStrings.getLocalString("fnf", "File not found {0}", file.getAbsolutePath()));
            }

            archive = archiveFactory.openArchive(file);

            final ExtendedDeploymentContext deploymentContext =
                getBuilder(logger, commandParams, report).source(archive).build();

            Properties appProps = deploymentContext.getAppProps();
            appProps.putAll(contextProps);
            savedAppConfig.store(appProps);

            if (modulePropsMap != null) {
                deploymentContext.setModulePropsMap(modulePropsMap);
            }

            deploy(getSniffersFromApp(app), deploymentContext);
            return deploymentContext;
        } finally {
View Full Code Here

        }

        try {
            doOnAllBundles(application, new BundleBlock<ModuleInfo>() {
                public ModuleInfo doBundle(ModuleDescriptor bundle) throws Exception {
                    ExtendedDeploymentContext sContext = subContext(application, context, bundle.getArchiveUri());
                    ModuleInfo info = prepareBundle(bundle, application,
                        sContext);
                    if (info == null) {
                        sContext.getActionReport().setActionExitCode(ActionReport.ExitCode.WARNING);
                        String msg = localStrings.getLocalString("skipmoduleprocessing", "Skipped processing for module {0} as its module type was not recognized", bundle.getArchiveUri());
                        sContext.getActionReport().setMessage(msg);
                        deplLogger.log(Level.WARNING,
                                       UNRECOGNIZED_MODULE_TYPE,
                                       bundle.getArchiveUri());
                        return null;
                    }
View Full Code Here

        public T doBundle(ModuleDescriptor bundle) throws Exception;
    }
   
    private ExtendedDeploymentContext subContext(final Application application, final DeploymentContext context, final String moduleUri) {
               
                ExtendedDeploymentContext moduleContext = ((ExtendedDeploymentContext)context).getModuleDeploymentContexts().get(moduleUri);
                if (moduleContext != null) {
                    return moduleContext;
                }


                final ReadableArchive subArchive;
                try {
                    subArchive = context.getSource().getSubArchive(moduleUri);
                    subArchive.setParentArchive(context.getSource());
                } catch(IOException ioe) {
                    deplLogger.log(Level.WARNING,
                                   ERROR_OCCURRED,
                                   ioe)
                    return null;
                }
               
                final Properties moduleProps =
                    getModuleProps(context, moduleUri);

                ActionReport subReport =
                    context.getActionReport().addSubActionsReport();
                moduleContext = new DeploymentContextImpl(subReport, context.getSource(),
                        context.getCommandParameters(OpsParams.class), env) {

                    @Override
                    public ClassLoader getClassLoader() {
                        try {
                            if (context.getClassLoader() == null) {
                                return null;
                            }
                            EarClassLoader appCl = EarClassLoader.class.cast(context.getClassLoader());
                            if (((ExtendedDeploymentContext)context).
                                getPhase() == Phase.PREPARE) {
                                return appCl;
                            } else {
                                return appCl.getModuleClassLoader(moduleUri);
                            }
                        } catch (ClassCastException e) {
                            return context.getClassLoader();
                        }                       
                    }

                    @Override
                    public ClassLoader getFinalClassLoader() {
                        try {
                            EarClassLoader finalEarCL = (EarClassLoader) context.getFinalClassLoader();
                            return finalEarCL.getModuleClassLoader(moduleUri);
                        } catch (ClassCastException e) {
                            return context.getClassLoader();
                        }
                    }
                    @Override
                    public ReadableArchive getSource() {
                        return subArchive;
                    }

                    @Override
                    public Properties getAppProps() {
                        return context.getAppProps();
                    }

                    @Override
                    public <U extends OpsParams> U getCommandParameters(Class<U> commandParametersType) {
                        return context.getCommandParameters(commandParametersType);
                    }

                    @Override
                    public void addTransientAppMetaData(String metaDataKey,
                        Object metaData) {
                        context.addTransientAppMetaData(metaDataKey,
                            metaData);
                    }

                    @Override
                    public  <T> T getTransientAppMetaData(String metaDataKey,
                        Class<T> metadataType) {
                        return context.getTransientAppMetaData(metaDataKey,
                            metadataType);
                    }

                    @Override
                    public Properties getModuleProps() {
                        return moduleProps;
                    }

                    @Override
                    public ReadableArchive getOriginalSource() {
                        try {
                            File appRoot = context.getSourceDir();
                            File origModuleFile = new File(appRoot, moduleUri);
                            return archiveFactory.openArchive(
                                origModuleFile);
                        } catch (IOException ioe) {
                            return null;
                        }
                    }

                    @Override
                    public File getScratchDir(String subDirName) {
                        String modulePortion = Util.getURIName(
                            getSource().getURI());
                        return (new File(super.getScratchDir(subDirName),
                            modulePortion));
                    }

                    @Override
                    public <T> T getModuleMetaData(Class<T> metadataType) {
                        try {
                            return metadataType.cast(application.getModuleByUri(moduleUri));
                        } catch (Exception e) {
                            // let's first try the extensions mechanisms...
                            if (RootDeploymentDescriptor.class.isAssignableFrom(metadataType)) {
                                for (RootDeploymentDescriptor extension  : application.getModuleByUri(moduleUri).getExtensionsDescriptors((Class<RootDeploymentDescriptor>) metadataType)) {
                                    // we assume there can only be one type of
                                    if (extension!=null) {
                                        try {
                                            return metadataType.cast(extension);
                                        } catch (Exception e1) {
                                            // next one...
                                        }
                                    }
                                }
                               
                            }

                            return context.getModuleMetaData(metadataType);
                        }
                    }
                };

                ((ExtendedDeploymentContext)context).getModuleDeploymentContexts().put(moduleUri, moduleContext);
                moduleContext.setParentContext((ExtendedDeploymentContext)context);
                moduleContext.setModuleUri(moduleUri);
                ArchiveHandler subHandler = context.getModuleArchiveHandlers().get(moduleUri);
                moduleContext.setArchiveHandler(subHandler);

                return moduleContext;
    }
View Full Code Here

        String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
        deployParams.target = targetName;
        deployParams.name = "mejb";
        ActionReport report = habitat.getService(ActionReport.class, "plain");
        Deployment deployment = habitat.getService(Deployment.class);
        ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
        deployment.deploy(dc);

        if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
            throw new RuntimeException("Failed to deploy MEJB app: " +
                    report.getFailureCause());
View Full Code Here

                    if (handler!=null) {
                        ActionReport subReport =
                            context.getActionReport().addSubActionsReport();
                        // todo : this is a hack, once again,
                        // the handler is assuming a file:// url
                        ExtendedDeploymentContext subContext =
                            new DeploymentContextImpl(subReport,
                            sub,
                            context.getCommandParameters(
                                DeployCommandParameters.class), env) {

                            @Override
                            public File getScratchDir(String subDirName) {
                                String modulePortion = Util.getURIName(
                                    getSource().getURI());
                                return (new File(super.getScratchDir(
                                    subDirName), modulePortion));
                            }
                        };

                        // sub context will store the root archive handler also
                        // so we can figure out the enclosing archive type
                        subContext.setArchiveHandler
                            (context.getArchiveHandler());

                        subContext.setParentContext((ExtendedDeploymentContext)context);

                        sub.setParentArchive(context.getSource());

                        ClassLoader subCl = handler.getClassLoader(cl, subContext);
View Full Code Here

     * @param archive the archive for the application
     */
    public Application processDeploymentMetaData(ReadableArchive archive) throws Exception {
        FileArchive expandedArchive = null;
        File tmpFile = null;
        ExtendedDeploymentContext context = null;
        Logger logger = Logger.getAnonymousLogger();
        ClassLoader cl = null;
        try {
            String archiveName = Util.getURIName(archive.getURI());
            ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
            if (archiveHandler==null) {
                throw new IllegalArgumentException(localStrings.getLocalString("deploy.unknownarchivetype","Archive type of {0} was not recognized", archiveName));
            }

            DeployCommandParameters parameters = new DeployCommandParameters(new File(archive.getURI()));
            ActionReport report = new HTMLActionReporter();
            context = new DeploymentContextImpl(report, archive, parameters, env);
            context.setArchiveHandler(archiveHandler);
            String appName = archiveHandler.getDefaultApplicationName(archive, context);
            parameters.name = appName;

            if (archive instanceof InputJarArchive) {
                // we need to expand the archive first in this case
                tmpFile = File.createTempFile(
                    archiveName,"");
                String path = tmpFile.getAbsolutePath();
                if (!tmpFile.delete()) {
                    logger.log(Level.WARNING, "cannot.delete.temp.file", new Object[] {path});
                }
                File tmpDir = new File(path);
                tmpDir.deleteOnExit();

                if (!tmpDir.exists() && !tmpDir.mkdirs()) {
                  throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());
                }
                expandedArchive = (FileArchive)archiveFactory.createArchive(tmpDir);
                archiveHandler.expand(archive, expandedArchive, context);
                context.setSource(expandedArchive);
            }

            context.setPhase(DeploymentContextImpl.Phase.PREPARE);
            ClassLoaderHierarchy clh = clhProvider.get();
            context.createDeploymentClassLoader(clh, archiveHandler);
            cl = context.getClassLoader();
            deployment.getDeployableTypes(context);
            deployment.getSniffers(archiveHandler, null, context);
            return processDOL(context);
        } finally  {
            if (cl != null && cl instanceof PreDestroy) {
                try {
                    PreDestroy.class.cast(cl).preDestroy();
                } catch (Exception e) {
                    // ignore
                }
            }
            if (context != null) {
                context.postDeployClean(true);
            }
            if (expandedArchive != null) {
                try {
                    expandedArchive.close();
                } catch (Exception e) {
View Full Code Here

            String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());

            DeployCommandParameters params = new DeployCommandParameters();
            params.name = appName;

            ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
            context.setArchiveHandler(archiveHandler);

            if (!archiveFile.isDirectory()) {
                // expand archive
                File destDir = new File(destRootDir, appName);
                if (destDir.exists()) {
                    FileUtils.whack(destDir);
                }
                destDir.mkdirs();
                archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
                archive.close();
                archive = archiveFactory.openArchive(destDir);
                context.setSource(archive);
            }

            context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE); // issue 14564
            String archiveType = context.getArchiveHandler().getArchiveType();
            ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
            Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
            if (archivist == null) {
                throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
            }
View Full Code Here

                params.target = _ejbContainerUtil.getServerEnvironment().getInstanceName();

                ActionReport report = _ejbContainerUtil.getServices().
                        getService(ActionReport.class, "plain");
                Deployment deployment = _ejbContainerUtil.getDeployment();
                ExtendedDeploymentContext dc = deployment.getBuilder(
                        logger, params, report).source(app).build();
                dc.addTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, resourceName);
                Properties appProps = dc.getAppProps();
                appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL);

                deployment.deploy(dc);

                if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
View Full Code Here

                        } else {
                            params.origin = OpsParams.Origin.load;
                            params.target = env.getInstanceName();
                        }

                        ExtendedDeploymentContext dc = deployment.getBuilder(logger, params, report).source(app).build();
                        Properties appProps = dc.getAppProps();
                        appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL);

                        deployment.deploy(dc);

                        if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
View Full Code Here

TOP

Related Classes of org.glassfish.internal.deployment.ExtendedDeploymentContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.