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