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;
}
}
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);
}
}
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());
}
}
}
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);
}
}
}
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
}
}
}
Aggregations