Search in sources :

Example 6 with WritableArchive

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

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

the class DescriptorArchivist method write.

/**
 * writes an application deployment descriptors
 * @param the application object
 * @param the abstract archive
 */
public void write(Application application, ReadableArchive in, WritableArchive out) throws IOException {
    if (application.isVirtual()) {
        ModuleDescriptor aModule = (ModuleDescriptor) application.getModules().iterator().next();
        Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
        write((BundleDescriptor) aModule.getDescriptor(), moduleArchivist, in, out);
    } else {
        // let's start by writing out all submodules deployment descriptors
        for (ModuleDescriptor aModule : application.getModules()) {
            Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
            WritableArchive moduleArchive = out.createSubArchive(aModule.getArchiveUri());
            ReadableArchive moduleArchive2 = in.getSubArchive(aModule.getArchiveUri());
            write((BundleDescriptor) aModule.getDescriptor(), moduleArchivist, moduleArchive2, moduleArchive);
        }
        // now let's write the application descriptor
        ApplicationArchivist archivist = archivistProvider.get();
        archivist.setDescriptor(application);
        archivist.writeDeploymentDescriptors(in, out);
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 8 with WritableArchive

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

the class DolProvider method saveAppDescriptor.

protected void saveAppDescriptor(Application application, DeploymentContext context) throws IOException {
    if (application != null) {
        ReadableArchive archive = archiveFactory.openArchive(context.getSourceDir());
        boolean isMkdirs = context.getScratchDir("xml").mkdirs();
        if (isMkdirs) {
            WritableArchive archive2 = archiveFactory.createArchive(context.getScratchDir("xml"));
            descriptorArchivist.write(application, archive, archive2);
            // copy the additional webservice elements etc
            applicationArchivist.copyExtraElements(archive, archive2);
        } else {
            context.getLogger().log(Level.WARNING, "Error in creating directory " + context.getScratchDir("xml").getAbsolutePath());
        }
    }
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 9 with WritableArchive

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

the class DolProvider method handleDeploymentPlan.

protected void handleDeploymentPlan(File deploymentPlan, Archivist archivist, ReadableArchive sourceArchive, ApplicationHolder holder) throws IOException {
    // file does not overwrite the one in the original archive
    if (deploymentPlan != null) {
        DeploymentPlanArchive dpa = new DeploymentPlanArchive();
        dpa.setParentArchive(sourceArchive);
        dpa.open(deploymentPlan.toURI());
        // need to revisit for ear case
        WritableArchive targetArchive = archiveFactory.createArchive(sourceArchive.getURI());
        if (archivist instanceof ApplicationArchivist) {
            ((ApplicationArchivist) archivist).copyInto(holder.app, dpa, targetArchive, false);
        } else {
            archivist.copyInto(dpa, targetArchive, false);
        }
    }
}
Also used : DeploymentPlanArchive(com.sun.enterprise.deployment.deploy.shared.DeploymentPlanArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 10 with WritableArchive

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

the class MTProvisionCommand method expandCustomizationJar.

private void expandCustomizationJar(File tenantDir) throws IOException {
    if (!tenantDir.exists() && !tenantDir.mkdirs()) {
    // TODO Handle this situation properly -- issue reported by findbugs
    }
    if (customizations == null) {
        return;
    }
    ReadableArchive cusArchive = null;
    WritableArchive expandedArchive = null;
    try {
        expandedArchive = archiveFactory.createArchive(tenantDir);
        cusArchive = archiveFactory.openArchive(customizations);
        DeploymentUtils.expand(cusArchive, expandedArchive);
    } finally {
        try {
            if (cusArchive != null) {
                cusArchive.close();
            }
            if (expandedArchive != null) {
                expandedArchive.close();
            }
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Aggregations

WritableArchive (org.glassfish.api.deployment.archive.WritableArchive)14 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)9 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)3 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)2 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)2 DOLUtils.setExtensionArchivistForSubArchivist (com.sun.enterprise.deployment.util.DOLUtils.setExtensionArchivistForSubArchivist)2 IOException (java.io.IOException)2 Enumeration (java.util.Enumeration)2 Vector (java.util.Vector)2 JarFile (java.util.jar.JarFile)2 Archivist (com.sun.enterprise.deployment.archivist.Archivist)1 DeploymentPlanArchive (com.sun.enterprise.deployment.deploy.shared.DeploymentPlanArchive)1 ApplicationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 LogRecord (java.util.logging.LogRecord)1 MultiException (org.glassfish.hk2.api.MultiException)1