Search in sources :

Example 86 with ReadableArchive

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

the class ApplicationArchivist method readRuntimeDeploymentDescriptor.

/**
 * Read the runtime deployment descriptors (can contained in one or many file) set the corresponding information in the
 * passed descriptor. By default, the runtime deployment descriptors are all contained in the xml file characterized
 * with the path returned by
 *
 * @param archive
 *            the input archive
 * @param descriptor
 *            the initialized deployment descriptor
 */
@Override
public void readRuntimeDeploymentDescriptor(ReadableArchive archive, Application descriptor) throws IOException, SAXParseException {
    if (descriptor != null) {
        // each modules first...
        for (ModuleDescriptor md : descriptor.getModules()) {
            Archivist archivist = archivistFactory.get().getArchivist(md.getModuleType());
            archivist.initializeContext(this);
            archivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
            archivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
            ReadableArchive subArchive = archive.getSubArchive(md.getArchiveUri());
            if (md.getAlternateDescriptor() != null) {
                DOLUtils.readAlternativeRuntimeDescriptor(archive, subArchive, archivist, (BundleDescriptor) md.getDescriptor(), md.getAlternateDescriptor());
            } else {
                archivist.readRuntimeDeploymentDescriptor(subArchive, (BundleDescriptor) md.getDescriptor());
            }
        }
    }
    // for the application
    super.readRuntimeDeploymentDescriptor(archive, descriptor);
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) DOLUtils.setExtensionArchivistForSubArchivist(com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 87 with ReadableArchive

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

the class Archivist method renameTmp.

/**
 * rename a tmp file
 *
 * @param from name
 * @param to name
 */
protected boolean renameTmp(String from, String to) throws IOException {
    ReadableArchive finalArchive = archiveFactory.openArchive(new File(to));
    finalArchive.delete();
    ReadableArchive tmpArchive = archiveFactory.openArchive(new File(from));
    boolean success = tmpArchive.renameTo(to);
    if (!success) {
        throw new IOException("Error renaming JAR");
    }
    return success;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) JarFile(java.util.jar.JarFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)

Example 88 with ReadableArchive

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

the class Archivist method write.

/**
 * save the archive
 *
 * @param in archive to copy old elements from
 * @param outPath the file to use
 */
public void write(ReadableArchive in, String outPath) throws IOException {
    ReadableArchive oldArchive = null;
    try {
        oldArchive = archiveFactory.openArchive(new File(outPath));
    } catch (IOException ioe) {
    // there could be many reasons why we cannot open this archive,
    // we should continue
    }
    WritableArchive out = null;
    BufferedOutputStream bos = null;
    try {
        File outputFile = null;
        if (oldArchive != null && oldArchive.exists() && !(oldArchive instanceof WritableArchive)) {
            // this is a rewrite, get a temp file name...
            // I am creating a tmp file just to get a name
            outputFile = getTempFile(outPath);
            outputFile.delete();
            out = archiveFactory.createArchive(outputFile);
            oldArchive.close();
        } else {
            out = archiveFactory.createArchive(new File(outPath));
        }
        // write archivist content
        writeContents(in, out);
        out.close();
        in.close();
        // if we were using a temp file, time to rewrite the original
        if (outputFile != null) {
            ReadableArchive finalArchive = archiveFactory.openArchive(new File(outPath));
            finalArchive.delete();
            ReadableArchive tmpArchive = archiveFactory.openArchive(outputFile);
            tmpArchive.renameTo(outPath);
        }
    } catch (IOException ioe) {
        // cleanup
        if (out != null) {
            try {
                out.close();
            // out.delete(); <-- OutputJarArchive.delete isn't supported.
            } catch (IOException outIoe) {
            // ignore exceptions here, otherwise this will end up masking the real
            // IOException in 'ioe'.
            }
        }
        // propagate exception
        throw ioe;
    }
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) JarFile(java.util.jar.JarFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 89 with ReadableArchive

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

the class PersistenceArchivist method getProbablePersistenceRoots.

/**
 * Gets probable persitence roots from given parentArchive using given subArchiveRootScanner
 * @param parentArchive the parentArchive within which probable persitence roots need to be scanned
 * @param subArchivePURootScanner the scanner instance used for the scan
 * @see com.sun.enterprise.deployment.archivist.EarPersistenceArchivist.SubArchivePURootScanner
 * @return Map of puroot path to probable puroot archive.
 */
protected static Map<String, ReadableArchive> getProbablePersistenceRoots(ReadableArchive parentArchive, SubArchivePURootScanner subArchivePURootScanner) {
    Map<String, ReadableArchive> probablePersitenceArchives = new HashMap<>();
    ReadableArchive archiveToScan = subArchivePURootScanner.getSubArchiveToScan(parentArchive);
    if (archiveToScan != null) {
        // The subarchive exists
        Enumeration<String> entries = archiveToScan.entries();
        String puRootPrefix = subArchivePURootScanner.getPurRootPrefix();
        while (entries.hasMoreElements()) {
            String entry = entries.nextElement();
            if (subArchivePURootScanner.isProbablePuRootJar(entry)) {
                ReadableArchive puRootArchive = getSubArchive(archiveToScan, entry, false);
                if (puRootArchive != null) {
                    String puRoot = puRootPrefix + entry;
                    probablePersitenceArchives.put(puRoot, puRootArchive);
                }
            }
        }
    }
    return probablePersitenceArchives;
}
Also used : HashMap(java.util.HashMap) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 90 with ReadableArchive

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

the class ApplicationFactory method openArchive.

/**
 * Open a jar file and return an application object for the modules contained
 * in the archive/directory. If the archive/directory is a standalone module, this API will
 * create an empty application and add the standalone module to it
 *
 * @param archivist         to use to open the archive file
 * @param jarFile           the archive file
 * @param handleRuntimeInfo set to true to read configuration deployment descriptors
 * @return the application object
 */
public Application openArchive(Archivist archivist, URI jarFile, boolean handleRuntimeInfo) throws IOException, SAXParseException {
    // never read the runtime deployment descriptor before the
    // module type is found and the application object created
    ReadableArchive archive = archiveFactory.openArchive(jarFile);
    Application application = openArchive(archivist, archive, handleRuntimeInfo);
    archive.close();
    return application;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) Application(com.sun.enterprise.deployment.Application)

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