Search in sources :

Example 1 with ClientArtifactsManager

use of org.glassfish.deployment.common.ClientArtifactsManager in project Payara by payara.

the class StaticRmiStubGenerator method ejbc.

/**
 * Generates and compiles the necessary impl classes, stubs and skels.
 *
 * <pre>
 *
 * This method makes the following assumptions:
 *    - the deployment descriptor xmls are registered with Config
 *    - the class paths are registered with Config
 *
 * @@@
 * In case of re-deployment, the following steps should happen before:
 *    - rename the src dir from previous deployment (ex. /app/pet-old)
 *    - rename the stubs dir from previous deployment (ex. /stub/pet-old)
 *    - explode the ear file (ex. /app/petstore)
 *    - register the deployment descriptor xml with config
 *    - register the class path with config
 *
 * After successful completion of this method, the old src and sutbs
 * directories may be deleted.
 *
 * </pre>
 *
 * @param    deploymentCtx
 *
 * @return   array of the client stubs files as zip items or empty array
 */
public void ejbc(DeploymentContext deploymentCtx) throws Exception {
    // stubs dir for the current deployment
    File stubsDir = deploymentCtx.getScratchDir("ejb");
    String explodedDir = deploymentCtx.getSource().getURI().getSchemeSpecificPart();
    // deployment descriptor object representation
    EjbBundleDescriptor ejbBundle = deploymentCtx.getModuleMetaData(EjbBundleDescriptor.class);
    long startTime = now();
    // class path to be used for this application during javac & rmic
    String classPath = deploymentCtx.getTransientAppMetaData(CMPDeployer.MODULE_CLASSPATH, String.class);
    // Warning: A class loader is passed in while constructing the
    // application object
    final ClassLoader jcl = ejbBundle.getClassLoader();
    // stubs dir is used as repository for code generator
    final String gnrtrTMP = stubsDir.getCanonicalPath();
    // ---- EJB DEPLOYMENT DESCRIPTORS -------------------------------
    // The main use-case we want to support is the one where existing
    // stand-alone java clients that access ejbs hosted in our appserver
    // directly through CosNaming need the generated stubs.  We don't want to
    // force them to run rmic themselves so it's better for them
    // just to tell us during the deployment of an ejb client app
    // or ejb app that we should run rmic and put the stubs in the
    // client.jar.  Turning on the deployment-time rmic flag ONLY
    // controls the generation of rmic stubs.  Dynamic stubs will be used
    // in the server, in the Application Client container, and in
    // stand-alone clients that instantiate our naming provider.
    progress(localStrings.getStringWithDefault("generator.processing_beans", "Processing beans..."));
    // ---- END OF EJB DEPLOYMENT DESCRIPTORS --------------------------
    // ---- RMIC ALL STUB CLASSES --------------------------------------
    Set<String> allStubClasses = new HashSet<String>();
    // stubs classes for ejbs within this app that need rmic
    Set<String> ejbStubClasses = getStubClasses(jcl, ejbBundle);
    allStubClasses.addAll(ejbStubClasses);
    // Compile and RMIC all Stubs
    rmic(classPath, allStubClasses, stubsDir, gnrtrTMP, explodedDir);
    _logger.log(Level.INFO, "[RMIC] RMIC execution time: " + (now() - startTime) + " msec");
    // ---- END OF RMIC ALL STUB CLASSES -------------------------------
    // Create list of all server files and client files
    List<String> allClientFiles = new ArrayList<String>();
    // assemble the client files
    addGeneratedFiles(allStubClasses, allClientFiles, stubsDir);
    ClientArtifactsManager cArtifactsManager = ClientArtifactsManager.get(deploymentCtx);
    for (String file : allClientFiles) {
        cArtifactsManager.add(stubsDir, new File(file));
    }
    _logger.log(Level.INFO, "ejbc.end", deploymentCtx.getModuleMetaData(Application.class).getRegistrationName());
    _logger.log(Level.INFO, "[RMIC] Total time: " + (now() - startTime) + " msec");
}
Also used : ClientArtifactsManager(org.glassfish.deployment.common.ClientArtifactsManager) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor)

Example 2 with ClientArtifactsManager

use of org.glassfish.deployment.common.ClientArtifactsManager in project Payara by payara.

the class AppClientGroupFacadeGenerator method generateAndRecordEARFacadeContents.

/**
 * Generates content for the top-level generated client JAR from the
 * app clients in this app.
 * <p>
 * Higher-level logic will actually create the client JAR, because the need
 * for a client JAR can be triggered by other deployers (EJB for generated
 * stubs and web services), not only app clients.
 * @param dc
 * @param appScratchDir
 * @param facadeFileName
 * @param appClientGroupList
 * @throws IOException
 */
private void generateAndRecordEARFacadeContents(final DeploymentContext dc, final String appClientGroupList) throws IOException {
    final ClientArtifactsManager clientArtifactsManager = ClientArtifactsManager.get(dc);
    final Manifest manifest = new Manifest();
    Attributes mainAttrs = manifest.getMainAttributes();
    mainAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    mainAttrs.put(Attributes.Name.MAIN_CLASS, GLASSFISH_APPCLIENT_GROUP_FACADE_CLASS_NAME);
    mainAttrs.put(GLASSFISH_APPCLIENT_GROUP, appClientGroupList);
    // Now manifest is ready to be written.
    final File manifestFile = File.createTempFile("groupMF", ".MF");
    // facadeArchive.putNextEntry(JarFile.MANIFEST_NAME);
    final OutputStream manifestOutputStream = new BufferedOutputStream(new FileOutputStream(manifestFile));
    try {
        manifest.write(manifestOutputStream);
    } finally {
        manifestOutputStream.close();
    }
    clientArtifactsManager.add(manifestFile, JarFile.MANIFEST_NAME, true);
    writeMainClass(clientArtifactsManager);
    /*
         * If the EAR contains a permissions file we need to make sure it's added
         * to the group-level generated facade JAR.
         */
    final File permissionsFile = getPermissionsFile();
    if (permissionsFile.canRead()) {
        clientArtifactsManager.add(permissionsFile, PERMISSIONS_XML_PATH, false);
    }
/*
         * Higher-level code will copy the files generated here plus other deployers' 
         * artifacts - such as generated stubs - into the generated client JAR
         * which the app client deployer views as the group facade.
         * Each client's individual facade JARs then refer
         * to the group facade in their Class-Path so they can see the stubs.
         * This also allows Java SE clients to add the group facade JAR to
         * the runtime class path and see the stubs.  (This allows users who
         * did this in v2 to use the same technique.)
         */
}
Also used : ClientArtifactsManager(org.glassfish.deployment.common.ClientArtifactsManager) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile)

Example 3 with ClientArtifactsManager

use of org.glassfish.deployment.common.ClientArtifactsManager in project Payara by payara.

the class JaxRpcRICodegen method addArtifactsForAppClient.

private void addArtifactsForAppClient() {
    ClientArtifactsManager cArtifactsManager = ClientArtifactsManager.get(context);
    for (int i = 0; i < files.size(); i++) {
        URI baseURI = context.getScratchDir("ejb").toURI();
        File file = new File(files.get(i));
        URI artifact = baseURI.relativize(file.toURI());
        // Fix for issue 9734
        if (!cArtifactsManager.contains(baseURI, artifact)) {
            cArtifactsManager.add(baseURI, artifact);
        }
    }
}
Also used : ClientArtifactsManager(org.glassfish.deployment.common.ClientArtifactsManager) URI(java.net.URI) JaxrpcMappingDeploymentDescriptorFile(com.sun.enterprise.deployment.io.JaxrpcMappingDeploymentDescriptorFile) File(java.io.File)

Aggregations

ClientArtifactsManager (org.glassfish.deployment.common.ClientArtifactsManager)3 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 JaxrpcMappingDeploymentDescriptorFile (com.sun.enterprise.deployment.io.JaxrpcMappingDeploymentDescriptorFile)1 File (java.io.File)1 URI (java.net.URI)1 Attributes (java.util.jar.Attributes)1 JarFile (java.util.jar.JarFile)1 Manifest (java.util.jar.Manifest)1