Search in sources :

Example 1 with AnnotationDetector

use of com.sun.enterprise.deployment.util.AnnotationDetector in project Payara by payara.

the class StandAloneAppClientInfo method mainClassContainsPURefcAnnotations.

protected boolean mainClassContainsPURefcAnnotations(ApplicationClientDescriptor acDescr) throws MalformedURLException, ClassNotFoundException, IOException, URISyntaxException {
    AnnotationDetector annoDetector = new AnnotationDetector(new AppClientPersistenceDependencyAnnotationScanner());
    // e.g. FROM a.b.Foo or Foo TO a/b/Foo.class or Foo.class
    String mainClassEntryName = acDescr.getMainClassName().replace('.', '/') + ".class";
    return classContainsAnnotation(mainClassEntryName, annoDetector, appClientArchive, acDescr);
}
Also used : AnnotationDetector(com.sun.enterprise.deployment.util.AnnotationDetector) AppClientPersistenceDependencyAnnotationScanner(com.sun.enterprise.deployment.annotation.introspection.AppClientPersistenceDependencyAnnotationScanner)

Example 2 with AnnotationDetector

use of com.sun.enterprise.deployment.util.AnnotationDetector in project Payara by payara.

the class ApplicationArchivist method getApplicationFromIntrospection.

/**
 * This method introspect an ear file and populate the Application object. We follow the Java EE platform specification,
 * Section EE.8.4.2 to determine the type of the modules included in this application.
 *
 * @param archive
 *            the archive representing the application root
 * @param directory
 *            whether this is a directory deployment
 */
private Application getApplicationFromIntrospection(ReadableArchive archive, boolean directory) {
    // archive is a directory
    String appRoot = archive.getURI().getSchemeSpecificPart();
    if (appRoot.endsWith(File.separator)) {
        appRoot = appRoot.substring(0, appRoot.length() - 1);
    }
    Application app = Application.createApplication();
    app.setLoadedFromApplicationXml(false);
    app.setVirtual(false);
    // name of the file without its extension
    String appName = appRoot.substring(appRoot.lastIndexOf(File.separatorChar) + 1);
    app.setName(appName);
    List<ReadableArchive> unknowns = new ArrayList<>();
    File[] files = getEligibleEntries(new File(appRoot), directory);
    for (File subModule : files) {
        ReadableArchive subArchive = null;
        try {
            try {
                subArchive = archiveFactory.openArchive(subModule);
            } catch (IOException ex) {
                logger.log(Level.WARNING, ex.getMessage());
            }
            // for archive deployment, we check the sub archives by its
            // file extension; for directory deployment, we check the sub
            // directories by its name. We are now supporting directory
            // names with both "_suffix" and ".suffix".
            // Section EE.8.4.2.1.a
            String name = subModule.getName();
            String uri = deriveArchiveUri(appRoot, subModule, directory);
            if ((!directory && name.endsWith(".war")) || (directory && (name.endsWith("_war") || name.endsWith(".war")))) {
                ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
                md.setArchiveUri(uri);
                md.setModuleType(DOLUtils.warType());
                // the context root will be set later after
                // we process the sub modules
                app.addModule(md);
            } else // Section EE.8.4.2.1.b
            if ((!directory && name.endsWith(".rar")) || (directory && (name.endsWith("_rar") || name.endsWith(".rar")))) {
                ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
                md.setArchiveUri(uri);
                md.setModuleType(DOLUtils.rarType());
                app.addModule(md);
            } else if ((!directory && name.endsWith(".jar")) || (directory && (name.endsWith("_jar") || name.endsWith(".jar")))) {
                try {
                    // Section EE.8.4.2.1.d.i
                    AppClientArchivist acArchivist = new AppClientArchivist();
                    if (acArchivist.hasStandardDeploymentDescriptor(subArchive) || acArchivist.hasRuntimeDeploymentDescriptor(subArchive) || acArchivist.getMainClassName(subArchive.getManifest()) != null) {
                        ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
                        md.setArchiveUri(uri);
                        md.setModuleType(DOLUtils.carType());
                        md.setManifest(subArchive.getManifest());
                        app.addModule(md);
                        continue;
                    }
                    // Section EE.8.4.2.1.d.ii
                    Archivist ejbArchivist = archivistFactory.get().getArchivist(DOLUtils.ejbType());
                    if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive) || ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) {
                        ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
                        md.setArchiveUri(uri);
                        md.setModuleType(DOLUtils.ejbType());
                        app.addModule(md);
                        continue;
                    }
                } catch (IOException ex) {
                    logger.log(Level.WARNING, ex.getMessage());
                }
                // Still could not decide between an ejb and a library
                unknowns.add(subArchive);
                // Prevent this unknown archive from being closed in the
                // finally block, because the same object will be used in
                // the block below where unknowns are checked one more time.
                subArchive = null;
            } else {
            // ignored
            }
        } finally {
            if (subArchive != null) {
                try {
                    subArchive.close();
                } catch (IOException ioe) {
                    logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.errorClosingSubArch", "Error closing subarchive {0}", new Object[] { subModule.getAbsolutePath() }), ioe);
                }
            }
        }
    }
    if (unknowns.size() > 0) {
        AnnotationDetector detector = new AnnotationDetector(new EjbComponentAnnotationScanner());
        for (int i = 0; i < unknowns.size(); i++) {
            File jarFile = new File(unknowns.get(i).getURI().getSchemeSpecificPart());
            try {
                if (detector.hasAnnotationInArchive(unknowns.get(i))) {
                    String uri = deriveArchiveUri(appRoot, jarFile, directory);
                    // Section EE.8.4.2.1.d.ii, alas EJB
                    ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
                    md.setArchiveUri(uri);
                    md.setModuleType(DOLUtils.ejbType());
                    app.addModule(md);
                }
                /*
                     * The subarchive was opened by the anno detector. Close it.
                     */
                unknowns.get(i).close();
            } catch (IOException ex) {
                logger.log(Level.WARNING, ex.getMessage());
            }
        }
    }
    return app;
}
Also used : DOLUtils.setExtensionArchivistForSubArchivist(com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist) EjbComponentAnnotationScanner(com.sun.enterprise.deployment.annotation.introspection.EjbComponentAnnotationScanner) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AnnotationDetector(com.sun.enterprise.deployment.util.AnnotationDetector) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor) ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) ApplicationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile) File(java.io.File) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)

Aggregations

AnnotationDetector (com.sun.enterprise.deployment.util.AnnotationDetector)2 Application (com.sun.enterprise.deployment.Application)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 AppClientPersistenceDependencyAnnotationScanner (com.sun.enterprise.deployment.annotation.introspection.AppClientPersistenceDependencyAnnotationScanner)1 EjbComponentAnnotationScanner (com.sun.enterprise.deployment.annotation.introspection.EjbComponentAnnotationScanner)1 ApplicationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile)1 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)1 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)1 DOLUtils.setExtensionArchivistForSubArchivist (com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1