use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class FileArchive method createSubArchive.
/**
* create or obtain an embedded archive within this abstraction.
*
* @param name name of the embedded archive.
*/
@Override
public WritableArchive createSubArchive(String name) throws IOException {
String subEntryName = getFileSubArchivePath(name);
File subEntry = new File(subEntryName);
if (!subEntry.exists()) {
// time to create a new sub directory
if (!subEntry.exists() && !subEntry.mkdirs()) {
throw new IOException("Unable to create directory for " + subEntry.getAbsolutePath());
}
deplLogger.log(DEBUG_LEVEL, "FileArchive.createSubArchive created dirs for {0}", subEntry.getAbsolutePath());
} else {
deplLogger.log(DEBUG_LEVEL, "FileArchive.createSubArchive found existing dir for {0}", subEntry.getAbsolutePath());
/*
* This subdirectory already exists, so it might be marked as
* stale. Because this invocation is creating the subarchive in
* the current archive, the subdirectory is no longer stale.
*/
staleFileManager().recordValidEntry(subEntry);
}
final WritableArchive result = archiveFactory.createArchive(subEntry);
if (result instanceof AbstractReadableArchive) {
((AbstractReadableArchive) result).setParentArchive(this);
}
return result;
}
use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class FileArchiveTest method createAndPopulateArchive.
private ReadableArchive createAndPopulateArchive(final Set<String> entryNames) throws Exception {
// new FileArchive();
WritableArchive instance = archiveFactory.createArchive(archiveDir.toURI());
instance.create(archiveDir.toURI());
/*
* Add some entries.
*/
for (String entryName : entryNames) {
instance.putNextEntry(entryName);
instance.closeEntry();
}
instance.close();
return archiveFactory.openArchive(archiveDir);
}
use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class FileArchiveTest method createAndPopulateSubarchive.
private ReadableArchive createAndPopulateSubarchive(final WritableArchive parent, final String subarchiveName, final Set<String> entryNames) throws Exception {
final WritableArchive result = parent.createSubArchive(subarchiveName);
for (String entryName : entryNames) {
result.putNextEntry(entryName);
result.closeEntry();
}
result.close();
final ReadableArchive readableParent = archiveFactory.openArchive(parent.getURI());
return readableParent.getSubArchive(subarchiveName);
}
use of org.glassfish.api.deployment.archive.WritableArchive 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;
}
Aggregations