Search in sources :

Example 1 with AppClientArchivist

use of com.sun.enterprise.deployment.archivist.AppClientArchivist in project Payara by payara.

the class ClassFileAppClientInfo method massageDescriptor.

@Override
protected void massageDescriptor() throws IOException, AnnotationProcessorException {
    ApplicationClientDescriptor appClient = getDescriptor();
    appClient.setMainClassName(classFileFromCommandLine);
    appClient.getModuleDescriptor().setStandalone(true);
    FileArchive fa = new FileArchive();
    fa.open(new File(classFileFromCommandLine).toURI());
    new AppClientArchivist().processAnnotations(appClient, fa);
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) File(java.io.File)

Example 2 with AppClientArchivist

use of com.sun.enterprise.deployment.archivist.AppClientArchivist in project Payara by payara.

the class FacadeLaunchable method getDescriptor.

/**
 * Return the augmented descriptor constructed during deployment and
 * stored in the facade client JAR.
 * @param loader
 * @return
 * @throws java.io.IOException
 * @throws org.xml.sax.SAXParseException
 */
public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXParseException {
    if (acDesc == null) {
        /*
             * To support managed beans, perform anno processing which requires
             * a class loader.  But we don't want to load the application
             * classes using the main class loader yet because we need to find
             * set up transformation of application classes by transformers from
             * persistence (perhaps).  So create a temporary loader just to
             * load the descriptor.
             */
        final AppClientArchivist archivist = getArchivist();
        /*
             * Anno processing is currently file-based.  But during Java Web
             * Start launches, the JARs which Java Web Start has downloaded are
             * not accessible as File objects.  Until the anno processing is
             * generalized we suppress the anno processing during Java Web
             * Start launches.
             */
        archivist.setAnnotationProcessingRequested(!isJWSLaunch);
        final ACCClassLoader tempLoader = AccessController.doPrivileged(new PrivilegedAction<ACCClassLoader>() {

            @Override
            public ACCClassLoader run() {
                return new ACCClassLoader(loader.getURLs(), loader.getParent());
            }
        });
        archivist.setClassLoader(tempLoader);
        acDesc = archivist.open(combinedRA, mainClassNameToLaunch);
        archivist.setDescriptor(acDesc);
        // acDesc = LaunchableUtil.openWithAnnoProcessingAndTempLoader(
        // arch, loader, facadeClientRA, clientRA);
        Application.createVirtualApplication(null, acDesc.getModuleDescriptor());
        final Manifest facadeMF = combinedRA.getManifest();
        final Attributes mainAttrs = facadeMF.getMainAttributes();
        final String appName = mainAttrs.getValue(GLASSFISH_APP_NAME);
        acDesc.getApplication().setAppName(appName);
        /*
             * Save the class loader for later use.
             */
        this.classLoader = loader;
    }
    return acDesc;
}
Also used : Attributes(java.util.jar.Attributes) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ACCAppClientArchivist(org.glassfish.appclient.common.ACCAppClientArchivist) Manifest(java.util.jar.Manifest)

Example 3 with AppClientArchivist

use of com.sun.enterprise.deployment.archivist.AppClientArchivist in project Payara by payara.

the class MainClassLaunchable method getDescriptor.

public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXParseException {
    /*
         * There is no developer-provided descriptor possible so just
         * use a default one.
         */
    if (acDesc == null) {
        ReadableArchive tempArchive = null;
        final ACCClassLoader tempLoader = AccessController.doPrivileged(new PrivilegedAction<ACCClassLoader>() {

            @Override
            public ACCClassLoader run() {
                return new ACCClassLoader(loader.getURLs(), loader.getParent());
            }
        });
        tempArchive = createArchive(tempLoader, mainClass);
        final AppClientArchivist acArchivist = getArchivist(tempArchive, tempLoader);
        archivist.setClassLoader(tempLoader);
        archivist.setDescriptor(acDesc);
        archivist.setAnnotationProcessingRequested(true);
        acDesc = acArchivist.open(tempArchive);
        Application.createVirtualApplication(null, acDesc.getModuleDescriptor());
        acDesc.getApplication().setAppName(appNameFromMainClass(mainClass));
        this.classLoader = loader;
    }
    return acDesc;
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 4 with AppClientArchivist

use of com.sun.enterprise.deployment.archivist.AppClientArchivist in project Payara by payara.

the class FacadeLaunchable method selectFacadeFromGroup.

private static FacadeLaunchable selectFacadeFromGroup(final ServiceLocator habitat, final URI groupFacadeURI, final ArchiveFactory af, final String groupURIs, final String callerSpecifiedMainClassName, final String callerSpecifiedAppClientName, final String anchorDir) throws IOException, BootException, URISyntaxException, SAXParseException, UserError {
    String[] archiveURIs = groupURIs.split(" ");
    /*
         * Search the app clients in the group in order, checking each for
         * a match on either the caller-specified main class or the caller-specified
         * client name.
         */
    if (archiveURIs.length == 0) {
        final String msg = MessageFormat.format(logger.getResourceBundle().getString("appclient.noClientsInGroup"), groupFacadeURI);
        throw new UserError(msg);
    }
    /*
         * Save the client names and main classes in case we need them in an
         * error to the user.
         */
    final List<String> knownClientNames = new ArrayList<String>();
    final List<String> knownMainClasses = new ArrayList<String>();
    for (String uriText : archiveURIs) {
        URI clientFacadeURI = groupFacadeURI.resolve(uriText);
        ReadableArchive clientFacadeRA = af.openArchive(clientFacadeURI);
        Manifest facadeMF = clientFacadeRA.getManifest();
        if (facadeMF == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.noMFInFacade"), clientFacadeRA instanceof FileArchive ? 1 : 0, new File(clientFacadeRA.getURI().getPath()).getAbsolutePath()));
        }
        Attributes facadeMainAttrs = facadeMF.getMainAttributes();
        if (facadeMainAttrs == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), GLASSFISH_APPCLIENT));
        }
        final String gfAppClient = facadeMainAttrs.getValue(GLASSFISH_APPCLIENT);
        if (gfAppClient == null || gfAppClient.length() == 0) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), GLASSFISH_APPCLIENT));
        }
        URI clientURI = clientFacadeURI.resolve(gfAppClient);
        ReadableArchive clientRA = af.openArchive(clientURI);
        if (!clientRA.exists()) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.missingClient"), new File(clientRA.getURI().getSchemeSpecificPart()).getAbsolutePath()));
        }
        AppClientArchivist facadeClientArchivist = getArchivist(habitat);
        MultiReadableArchive combinedRA = openCombinedReadableArchive(habitat, clientFacadeRA, clientRA);
        final ApplicationClientDescriptor facadeClientDescriptor = facadeClientArchivist.open(combinedRA);
        final String moduleID = Launchable.LaunchableUtil.moduleID(groupFacadeURI, clientURI, facadeClientDescriptor);
        final Manifest clientMF = clientRA.getManifest();
        if (clientMF == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.noMFInFacade"), clientRA instanceof FileArchive ? 1 : 0, new File(clientRA.getURI().getSchemeSpecificPart()).getAbsolutePath()));
        }
        Attributes mainAttrs = clientMF.getMainAttributes();
        if (mainAttrs == null) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), Attributes.Name.MAIN_CLASS.toString()));
        }
        final String clientMainClassName = mainAttrs.getValue(Attributes.Name.MAIN_CLASS);
        if (clientMainClassName == null || clientMainClassName.length() == 0) {
            throw new UserError(MessageFormat.format(logger.getResourceBundle().getString("appclient.MFMissingEntry"), new File(clientFacadeRA.getURI().getPath()).getAbsolutePath(), Attributes.Name.MAIN_CLASS.toString()));
        }
        knownMainClasses.add(clientMainClassName);
        knownClientNames.add(moduleID);
        /*
             * Look for an entry corresponding to the
             * main class or app name the caller requested.  Treat as a%
             * special case if the user specifies no main class and no
             * app name - use the first app client present.  Also use the
             * first app client if there is only one present; warn if
             * the user specified a main class or a name but it does not
             * match the single app client that's present.
             */
        FacadeLaunchable facade = null;
        if (Launchable.LaunchableUtil.matchesAnyClass(clientRA, callerSpecifiedMainClassName)) {
            facade = new FacadeLaunchable(habitat, clientFacadeRA, facadeMainAttrs, clientRA, callerSpecifiedMainClassName, anchorDir);
            /*
                 * If the caller-specified class name does not match the
                 * Main-Class setting for this client archive then inform the user.
                 */
            if (!clientMainClassName.equals(callerSpecifiedMainClassName)) {
                logger.log(Level.INFO, MessageFormat.format(logger.getResourceBundle().getString("appclient.foundMainClassDiffFromManifest"), new Object[] { groupFacadeURI, moduleID, callerSpecifiedMainClassName, clientMainClassName }));
            }
        } else if (Launchable.LaunchableUtil.matchesName(moduleID, groupFacadeURI, facadeClientDescriptor, callerSpecifiedAppClientName)) {
            /*
                 * Get the main class name from the matching client JAR's manifest.
                 */
            facade = new FacadeLaunchable(habitat, clientFacadeRA, facadeMainAttrs, clientRA, clientMainClassName, anchorDir);
        } else if (archiveURIs.length == 1) {
            /*
                 * If only one client exists, use the main class recorded in
                 * the group facade unless the caller specified one.
                 */
            facade = new FacadeLaunchable(habitat, clientFacadeRA, facadeMainAttrs, clientRA, (callerSpecifiedMainClassName != null ? callerSpecifiedMainClassName : facadeMainAttrs.getValue(GLASSFISH_APPCLIENT_MAIN_CLASS)), anchorDir);
            /*
                 * If the user specified a main class or an app name then warn
                 * if that value does not match the one client we found - but
                 * go ahead an run it anyway.
                 */
            if ((callerSpecifiedMainClassName != null && !clientMainClassName.equals(callerSpecifiedMainClassName)) || (callerSpecifiedAppClientName != null && !Launchable.LaunchableUtil.matchesName(moduleID, groupFacadeURI, facadeClientDescriptor, callerSpecifiedAppClientName))) {
                logger.log(Level.WARNING, MessageFormat.format(logger.getResourceBundle().getString("appclient.singleNestedClientNoMatch"), new Object[] { groupFacadeURI, knownClientNames.toString(), knownMainClasses.toString(), callerSpecifiedMainClassName, callerSpecifiedAppClientName }));
            }
        }
        if (facade != null) {
            return facade;
        }
    }
    /*
         * No client facade matched the caller-provided selection (either
         * main class name or app client name), or there are multiple clients
         * but the caller did not specify either mainClass or name.
         * Yet we know we're working
         * with a group facade, so report the failure to find a matching
         * client as an error.
         */
    String msg;
    if ((callerSpecifiedAppClientName == null) && (callerSpecifiedMainClassName == null)) {
        final String format = logger.getResourceBundle().getString("appclient.multClientsNoChoice");
        msg = MessageFormat.format(format, knownMainClasses.toString(), knownClientNames.toString());
    } else {
        final String format = logger.getResourceBundle().getString("appclient.noMatchingClientInGroup");
        msg = MessageFormat.format(format, groupFacadeURI, callerSpecifiedMainClassName, callerSpecifiedAppClientName, knownMainClasses.toString(), knownClientNames.toString());
    }
    throw new UserError(msg);
}
Also used : ArrayList(java.util.ArrayList) Attributes(java.util.jar.Attributes) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ACCAppClientArchivist(org.glassfish.appclient.common.ACCAppClientArchivist) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) Manifest(java.util.jar.Manifest) URI(java.net.URI) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) File(java.io.File)

Example 5 with AppClientArchivist

use of com.sun.enterprise.deployment.archivist.AppClientArchivist in project Payara by payara.

the class MainClassLaunchable method getArchivist.

private AppClientArchivist getArchivist(final ReadableArchive clientRA, final ClassLoader classLoader) throws IOException {
    if (archivist == null) {
        ArchivistFactory af = Util.getArchivistFactory();
        /*
             * Get the archivist by type rather than by archive to avoid
             * having to set the URI to some fake URI that the archivist
             * factory would understand.
             */
        archivist = completeInit((AppClientArchivist) af.getArchivist(DOLUtils.carType()));
    }
    return archivist;
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ArchivistFactory(com.sun.enterprise.deployment.archivist.ArchivistFactory)

Aggregations

AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)10 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)3 ArchivistFactory (com.sun.enterprise.deployment.archivist.ArchivistFactory)3 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 Archivist (com.sun.enterprise.deployment.archivist.Archivist)2 File (java.io.File)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 ACCAppClientArchivist (org.glassfish.appclient.common.ACCAppClientArchivist)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 Application (com.sun.enterprise.deployment.Application)1 MultiReadableArchive (com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)1 URI (java.net.URI)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 ArchiveType (org.glassfish.api.deployment.archive.ArchiveType)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1 RootDeploymentDescriptor (org.glassfish.deployment.common.RootDeploymentDescriptor)1