Search in sources :

Example 91 with ReadableArchive

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

the class DescriptorArchivist method write.

/**
 * writes an application deployment descriptors
 * @param the application object
 * @param the abstract archive
 */
public void write(Application application, ReadableArchive in, WritableArchive out) throws IOException {
    if (application.isVirtual()) {
        ModuleDescriptor aModule = (ModuleDescriptor) application.getModules().iterator().next();
        Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
        write((BundleDescriptor) aModule.getDescriptor(), moduleArchivist, in, out);
    } else {
        // let's start by writing out all submodules deployment descriptors
        for (ModuleDescriptor aModule : application.getModules()) {
            Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
            WritableArchive moduleArchive = out.createSubArchive(aModule.getArchiveUri());
            ReadableArchive moduleArchive2 = in.getSubArchive(aModule.getArchiveUri());
            write((BundleDescriptor) aModule.getDescriptor(), moduleArchivist, moduleArchive2, moduleArchive);
        }
        // now let's write the application descriptor
        ApplicationArchivist archivist = archivistProvider.get();
        archivist.setDescriptor(application);
        archivist.writeDeploymentDescriptors(in, out);
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 92 with ReadableArchive

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

the class DolProvider method processDOL.

private Application processDOL(DeploymentContext dc) throws IOException {
    ReadableArchive sourceArchive = dc.getSource();
    sourceArchive.setExtraData(Types.class, dc.getTransientAppMetaData(Types.class.getName(), Types.class));
    sourceArchive.setExtraData(Parser.class, dc.getTransientAppMetaData(Parser.class.getName(), Parser.class));
    Optional<ApplicationState> appState = hotDeployService.getApplicationState(dc);
    appState.ifPresent(state -> sourceArchive.setExtraData(ApplicationState.class, state));
    ClassLoader cl = dc.getClassLoader();
    DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
    sourceArchive.addArchiveMetaData(DeploymentProperties.APP_PROPS, dc.getAppProps());
    sourceArchive.addArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, params);
    String name = params.name();
    String archiveType = dc.getArchiveHandler().getArchiveType();
    Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
    if (archivist == null) {
        // an empty Application object
        return Application.createApplication();
    }
    archivist.setAnnotationProcessingRequested(true);
    String xmlValidationLevel = dasConfig.getDeployXmlValidation();
    archivist.setXMLValidationLevel(xmlValidationLevel);
    if (xmlValidationLevel.equals("none")) {
        archivist.setXMLValidation(false);
    }
    archivist.setRuntimeXMLValidationLevel(xmlValidationLevel);
    if (xmlValidationLevel.equals("none")) {
        archivist.setRuntimeXMLValidation(false);
    }
    Collection<Sniffer> sniffers = dc.getTransientAppMetaData(DeploymentProperties.SNIFFERS, Collection.class);
    archivist.setExtensionArchivists(archivistFactory.getExtensionsArchivists(sniffers, archivist.getModuleType()));
    ApplicationHolder holder = dc.getModuleMetaData(ApplicationHolder.class);
    File deploymentPlan = params.deploymentplan;
    handleDeploymentPlan(deploymentPlan, archivist, sourceArchive, holder);
    long start = System.currentTimeMillis();
    Application application = appState.map(state -> state.getModuleMetaData(Application.class)).orElse(holder != null ? holder.app : null);
    if (application != null) {
        application.setAppName(name);
        application.setClassLoader(cl);
        application.setRoleMapper(null);
        if (application.isVirtual()) {
            ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
            md.setModuleName(name);
            if (appState.map(ApplicationState::isActive).orElse(false)) {
                application.getStandaloneBundleDescriptor().setClassLoader(cl);
                dc.addModuleMetaData(application.getStandaloneBundleDescriptor());
                for (RootDeploymentDescriptor extension : application.getStandaloneBundleDescriptor().getExtensionsDescriptors()) {
                    extension.setClassLoader(cl);
                    dc.addModuleMetaData(extension);
                }
            }
        }
        try {
            applicationFactory.openWith(application, sourceArchive, archivist);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
    } else {
        // and it's a standalone module
        try {
            application = applicationFactory.openArchive(name, archivist, sourceArchive, true);
            application.setAppName(name);
            ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
            md.setModuleName(name);
        } catch (SAXParseException e) {
            throw new IOException(e);
        }
    }
    application.setRegistrationName(name);
    sourceArchive.removeExtraData(Types.class);
    sourceArchive.removeExtraData(Parser.class);
    Logger.getAnonymousLogger().log(FINE, "DOL Loading time{0}", System.currentTimeMillis() - start);
    return application;
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) FileUtils(com.sun.enterprise.util.io.FileUtils) ApplicationMetaDataProvider(org.glassfish.api.deployment.ApplicationMetaDataProvider) Provider(javax.inject.Provider) Util(com.sun.enterprise.deployment.deploy.shared.Util) ClassLoaderHierarchy(org.glassfish.internal.api.ClassLoaderHierarchy) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Level(java.util.logging.Level) ActionReport(org.glassfish.api.ActionReport) Inject(javax.inject.Inject) ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ApplicationInfoProvider(org.glassfish.internal.deployment.ApplicationInfoProvider) LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) HTMLActionReporter(com.sun.enterprise.admin.report.HTMLActionReporter) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive) Sniffer(org.glassfish.api.container.Sniffer) HotDeployService(fish.payara.nucleus.hotdeploy.HotDeployService) PreDestroy(org.glassfish.hk2.api.PreDestroy) DeploymentTracing(org.glassfish.internal.deployment.DeploymentTracing) Types(org.glassfish.hk2.classmodel.reflect.Types) FINE(java.util.logging.Level.FINE) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Module(com.sun.enterprise.config.serverbeans.Module) Collection(java.util.Collection) IOException(java.io.IOException) com.sun.enterprise.deployment.archivist(com.sun.enterprise.deployment.archivist) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) Logger(java.util.logging.Logger) File(java.io.File) DeploymentPlanArchive(com.sun.enterprise.deployment.deploy.shared.DeploymentPlanArchive) Parser(org.glassfish.hk2.classmodel.reflect.Parser) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) Service(org.jvnet.hk2.annotations.Service) MetaData(org.glassfish.api.deployment.MetaData) Domain(com.sun.enterprise.config.serverbeans.Domain) InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) org.glassfish.deployment.common(org.glassfish.deployment.common) Optional(java.util.Optional) Application(com.sun.enterprise.deployment.Application) Deployment(org.glassfish.internal.deployment.Deployment) Types(org.glassfish.hk2.classmodel.reflect.Types) ApplicationState(fish.payara.nucleus.hotdeploy.ApplicationState) Sniffer(org.glassfish.api.container.Sniffer) IOException(java.io.IOException) Parser(org.glassfish.hk2.classmodel.reflect.Parser) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) SAXParseException(org.xml.sax.SAXParseException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File) Application(com.sun.enterprise.deployment.Application)

Example 93 with ReadableArchive

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

the class DolProvider method saveAppDescriptor.

protected void saveAppDescriptor(Application application, DeploymentContext context) throws IOException {
    if (application != null) {
        ReadableArchive archive = archiveFactory.openArchive(context.getSourceDir());
        boolean isMkdirs = context.getScratchDir("xml").mkdirs();
        if (isMkdirs) {
            WritableArchive archive2 = archiveFactory.createArchive(context.getScratchDir("xml"));
            descriptorArchivist.write(application, archive, archive2);
            // copy the additional webservice elements etc
            applicationArchivist.copyExtraElements(archive, archive2);
        } else {
            context.getLogger().log(Level.WARNING, "Error in creating directory " + context.getScratchDir("xml").getAbsolutePath());
        }
    }
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 94 with ReadableArchive

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

the class JavaEEDeployer method getModuleClassPath.

/**
 * Returns the classpath associated with this module
 * Can be used to compile generated cmp classes,
 * rmi stubs etc.
 *
 * @return the classpath for this module
 */
protected String getModuleClassPath(DeploymentContext ctx) {
    // get the base module classpath
    // this includes the system classpath and deploy time lib libraries
    StringBuilder classpath = new StringBuilder(ASClassLoaderUtil.getModuleClassPath(habitat, ctx));
    try {
        // add the module dir
        classpath.append(ctx.getSourceDir().toPath().toString());
        classpath.append(File.pathSeparator);
        // add the stubs dir
        classpath.append(ctx.getScratchDir("ejb").toPath().toString());
        classpath.append(File.pathSeparator);
        // add the ear lib libraries if it's ear
        Application app = ctx.getModuleMetaData(Application.class);
        if (!app.isVirtual()) {
            ReadableArchive parentArchive = ctx.getSource().getParentArchive();
            String compatProp = ctx.getAppProps().getProperty(DeploymentProperties.COMPATIBILITY);
            List<URL> earLibURLs = ASClassLoaderUtil.getAppLibDirLibrariesAsList(new File(parentArchive.getURI()), app.getLibraryDirectory(), compatProp);
            for (URL url : earLibURLs) {
                classpath.append(Paths.get(url.toURI()).toString());
                classpath.append(File.pathSeparator);
            }
        }
    } catch (Exception e) {
    // log a warning
    }
    return classpath.toString();
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) File(java.io.File) URL(java.net.URL) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException)

Example 95 with ReadableArchive

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

the class OpenApiService method registerApp.

public void registerApp(String applicationId, DeploymentContext ctx) {
    final WebBundleDescriptorImpl descriptor = ctx.getModuleMetaData(WebBundleDescriptorImpl.class);
    final String contextRoot = descriptor.getContextRoot();
    final ReadableArchive archive = ctx.getSource();
    final ClassLoader classLoader = ctx.getClassLoader();
    documents.put(applicationId, new OpenAPISupplier(applicationId, contextRoot, archive, classLoader));
    cachedResult = null;
}
Also used : WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) 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