All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glassfish.api.deployment.DeploymentContext Maven / Gradle / Ivy

There is a newer version: 8.0.0-JDK17-M7
Show newest version
/*
 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package org.glassfish.api.deployment;

import java.io.File;
import java.lang.instrument.ClassFileTransformer;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.glassfish.api.ActionReport;
import org.glassfish.api.ExecutionContext;
import org.glassfish.api.deployment.archive.ArchiveHandler;
import org.glassfish.api.deployment.archive.ReadableArchive;

/**
 * Useful services for Deployer service implementation
 *
 * @author Jerome Dochez
 */
public interface DeploymentContext extends ApplicationContext, ExecutionContext {

    /**
     * Application bits, at the raw level. Deployer's should avoid using such low level access as it binds the deployer to a
     * particular directory layout. Instead Deployers should use the class loader obtained via the getClassLoader() API
     *
     * @return Abstraction to the application's source archive.
     */
    ReadableArchive getSource();

    /**
     * During the prepare phase, when a deployer need to have access to the class loader that will be used to load the
     * application in the runtime container, it can call this API during the prepare phase. Otherswise, deployers should use
     * the getClassLoader API.
     *
     * If a deployers needs to have access to the classloader during the prepare phase
     *
     *
     * @return the final class loader
     */
    ClassLoader getFinalClassLoader();

    /**
     * Returns the DeployCommand parameters
     *
     * @param opsParamsType expected deployment operation parameters type.
     * @return the command parameters
     */
     U getCommandParameters(Class opsParamsType);

    /**
     * Returns a scratch directory that can be used to store things in. The scratch directory will be persisted accross
     * server restart but not accross redeployment of the same application
     *
     * @param subDirName the sub directory name of the scratch dir
     * @return the specific scratch subdirectory for this application based on passed in subDirName. Returns the root
     * scratch dir if the passed in value is null.
     */
    File getScratchDir(String subDirName);

    /**
     * Returns the directory where the original applications bits should be stored. This is useful when users deploy an
     * archive file that need to be unzipped somewhere for the container to work with.
     *
     * @return the source directory for this application
     */
    File getSourceDir();

    /**
     * Stores a descriptor for the module in the context so other deployer's can have access to it. Module meta-data is
     * usual not persistent which mean that any modification to it will not be available at the next server restart and will
     * need to be reset.
     *
     * @param metaData the meta data itself
     */
    void addModuleMetaData(Object metaData);

    /**
     * Returns the meta data associated with a module type.
     *
     * @param metadataType type of the meta date.
     * @return instance of T or null
     */
     T getModuleMetaData(Class metadataType);

    /**
     * Gets the archive handlers for modules
     *
     * @return a map containing module archive handlers
     */
    Map getModuleArchiveHandlers();

    /**
     * Stores application level metadata in the context so other deployer's can have access to it. The transient meta-data
     * is not persistent which mean that any modification to it will not be available at the next server restart and will
     * need to be reset.
     *
     * @param metaDataKey key of the meta date.
     * @param metaData the meta data itself
     */
    void addTransientAppMetaData(String metaDataKey, Object metaData);

    /**
     * Returns the meta data for the given key
     *
     * @param metaDataKey key of the meta date.
     * @param metadataType type of the meta date.
     * @return instance of T or null
     */
     T getTransientAppMetaData(String metaDataKey, Class metadataType);

    /**
     * Add a new ClassFileTransformer to the context. Once all the deployers potentially invalidating the application class
     * loader (as indicated by the
     *
     * @link {MetaData.invalidatesClassLoader()}) the deployment backend will recreate the application's class loader
     * registering all the ClassTransformers added by the deployers to this context.
     *
     * @param transformer the new class file transformer to register to the new application class loader
     * @throws UnsupportedOperationException if the class loader we use does not support the registration of a
     * ClassFileTransformer. In such case, the deployer should either fail deployment or revert to a mode without the
     * bytecode enhancement feature.
     */
    void addTransformer(ClassFileTransformer transformer);

    /**
     * Returns all the metadata associated with this deployment
     *
     * @return collection of metadata added to the context
     */
    Collection getModuleMetadata();

    /**
     * Returns all the transient app metadata associated with this deployment
     *
     * @return collection of metadata added to the context
     */
    Map getTransientAppMetadata();

    /**
     * Returns the archive handler that's associated with this context
     *
     * @return archive handler
     */
    ArchiveHandler getArchiveHandler();

    /**
     * Gets the original source archive In case of archive deployment, this will return the archive before expanding. In
     * case of directory deployment, this will return the same thing as getSource()
     *
     * @return the original source archive
     */
    ReadableArchive getOriginalSource();

    /**
     * Gets the module properties for modules
     *
     * @return a map containing module properties
     */
    Map getModulePropsMap();

    /**
     * Gets the action report for this context
     *
     * @return an action report
     */
    ActionReport getActionReport();

    /**
     * gets the app-libs specified for this archive
* This list includes --libraries as well EXTENSION_LIST specified in the manifest entries * * @return list of library URIs * @throws URISyntaxException when unable to get the library URIs */ List getAppLibs() throws URISyntaxException; }