Search in sources :

Example 81 with ReadableArchive

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

the class SnifferManagerImpl method getSniffers.

/**
 * Returns a collection of sniffers that recognized some parts of the
 * passed archive as components their container handle.
 *
 * If no sniffer recognize the passed archive, an empty collection is
 * returned.
 *
 * @param context the deployment context
 * @return possibly empty collection of sniffers that handle the passed
 * archive.
 */
public Collection<Sniffer> getSniffers(DeploymentContext context) {
    ReadableArchive archive = context.getSource();
    ArchiveHandler handler = context.getArchiveHandler();
    List<URI> uris = handler.getClassPathURIs(archive);
    Types types = context.getTransientAppMetaData(Types.class.getName(), Types.class);
    return getSniffers(context, uris, types);
}
Also used : ArchiveHandler(org.glassfish.api.deployment.archive.ArchiveHandler) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) URI(java.net.URI)

Example 82 with ReadableArchive

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

the class UpgradeStartup method processModule.

// repackage a module and return it as a jar file
private File processModule(File moduleDir, String targetParentDir, String suffix) throws IOException {
    String moduleName = moduleDir.getName();
    // sub module in ear case
    if (moduleName.endsWith("_jar") || moduleName.endsWith("_war") || moduleName.endsWith("_rar")) {
        suffix = "." + moduleName.substring(moduleName.length() - 3);
        moduleName = moduleName.substring(0, moduleName.lastIndexOf('_'));
    }
    ReadableArchive source = archiveFactory.openArchive(moduleDir);
    File tempJar = new File(targetParentDir, moduleName + suffix);
    if (tempJar.exists()) {
        boolean isDeleted = tempJar.delete();
        if (!isDeleted) {
            logger.log(Level.WARNING, "Error in deleting file " + tempJar.getAbsolutePath());
        }
    }
    WritableArchive target = archiveFactory.createArchive("jar", tempJar);
    Enumeration<String> e = source.entries();
    while (e.hasMoreElements()) {
        String entryName = e.nextElement();
        if (isSigFile(entryName)) {
            logger.log(Level.INFO, "Excluding signature file: " + entryName + " from repackaged module: " + moduleName + "\n");
            continue;
        }
        InputStream sis = source.getEntry(entryName);
        if (sis != null) {
            InputStream is = new BufferedInputStream(sis);
            OutputStream os = null;
            try {
                os = target.putNextEntry(entryName);
                FileUtils.copy(is, os, source.getEntrySize(entryName));
            } finally {
                if (os != null) {
                    target.closeEntry();
                }
                is.close();
            }
        }
    }
    // last is manifest if existing.
    Manifest m = source.getManifest();
    if (m != null) {
        processManifest(m, moduleName);
        OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
        m.write(os);
        target.closeEntry();
    }
    source.close();
    target.close();
    return tempJar;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 83 with ReadableArchive

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

the class MicroProfileSniffer method handles.

@Override
public boolean handles(DeploymentContext context) {
    final ReadableArchive archive = context.getSource();
    final String archivePath = archive.getURI().getPath();
    // Ignore system applications
    if (archivePath.contains("glassfish/lib/install")) {
        return false;
    }
    if (archivePath.contains("h2db/bin")) {
        return false;
    }
    if (archivePath.contains("mq/lib")) {
        return false;
    }
    return handles(archive);
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 84 with ReadableArchive

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

the class ACCPersistenceArchivist method addOtherNondeployedScanTargets.

private void addOtherNondeployedScanTargets(final ReadableArchive clientArchive, final ApplicationClientDescriptor acDescr, final Map<String, ReadableArchive> candidates) {
    /*
         * The archive is a non-deployed one.  We know from an earlier check
         * that this is not a stand-alone app client, so we can use the
         * app client archive's parent archive to get to the containing EAR for
         * use in a subarchive scanner.
         */
    final ReadableArchive earArchive = clientArchive.getParentArchive();
    EARBasedPersistenceHelper.addLibraryAndTopLevelCandidates(earArchive, acDescr.getApplication(), true, candidates);
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)

Example 85 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive 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

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