use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class WebServicesDeployer method copyExtraFilesToGeneratedFolder.
/**
* This is to be used for file publishing only. In case of wsdlImports and wsdlIncludes we need to
* copy the nested wsdls from applications folder to the generated/xml folder
*/
private void copyExtraFilesToGeneratedFolder(DeploymentContext context) throws IOException {
Archivist archivist = habitat.getService(Archivist.class);
ReadableArchive archive = archiveFactory.openArchive(context.getSourceDir());
WritableArchive archive2 = archiveFactory.createArchive(context.getScratchDir("xml"));
// copy the additional webservice elements etc
archivist.copyExtraElements(archive, archive2);
}
use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class UpgradeStartup method repackageApplication.
private File repackageApplication(File appDir, String targetParentDir, String suffix) throws IOException {
String appName = appDir.getName();
ReadableArchive source = archiveFactory.openArchive(appDir);
File tempEar = new File(targetParentDir, appName + suffix);
if (tempEar.exists()) {
boolean isDeleted = tempEar.delete();
if (!isDeleted) {
logger.log(Level.WARNING, "Error in deleting file " + tempEar.getAbsolutePath());
}
}
WritableArchive target = archiveFactory.createArchive("jar", tempEar);
Collection<String> directoryEntries = source.getDirectories();
List<String> subModuleEntries = new ArrayList<String>();
List<String> entriesToExclude = new ArrayList<String>();
// first put all the sub module jars to the target archive
for (String directoryEntry : directoryEntries) {
if (directoryEntry.endsWith("_jar") || directoryEntry.endsWith("_war") || directoryEntry.endsWith("_rar")) {
subModuleEntries.add(directoryEntry);
File moduleJar = processModule(new File(appDir, directoryEntry), targetParentDir, null);
OutputStream os = null;
InputStream is = new BufferedInputStream(new FileInputStream(moduleJar));
try {
os = target.putNextEntry(moduleJar.getName());
FileUtils.copy(is, os, moduleJar.length());
} finally {
if (os != null) {
target.closeEntry();
}
is.close();
}
}
}
// basically all sub module entries should be excluded
for (String subModuleEntry : subModuleEntries) {
Enumeration<String> ee = source.entries(subModuleEntry);
while (ee.hasMoreElements()) {
String eeEntryName = ee.nextElement();
entriesToExclude.add(eeEntryName);
}
}
// now copy the rest of the entries
Enumeration<String> e = source.entries();
while (e.hasMoreElements()) {
String entryName = e.nextElement();
if (!entriesToExclude.contains(entryName)) {
InputStream sis = source.getEntry(entryName);
if (isSigFile(entryName)) {
logger.log(Level.INFO, "Excluding signature file: " + entryName + " from repackaged application: " + appName + "\n");
continue;
}
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, appName);
OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
m.write(os);
target.closeEntry();
}
source.close();
target.close();
return tempEar;
}
use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class ArchiveFactory method createArchive.
public WritableArchive createArchive(String protocol, URI path) throws IOException {
try {
WritableArchive archive = habitat.getService(WritableArchive.class, protocol);
if (archive == null) {
deplLogger.log(Level.SEVERE, IMPLEMENTATION_NOT_FOUND, protocol);
throw new MalformedURLException("Protocol not supported : " + protocol);
}
archive.create(path);
return archive;
} catch (MultiException e) {
LogRecord lr = new LogRecord(Level.SEVERE, IMPLEMENTATION_NOT_FOUND);
lr.setParameters(new Object[] { protocol });
lr.setThrown(e);
deplLogger.log(lr);
throw new MalformedURLException("Protocol not supported : " + protocol);
}
}
use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class ApplicationArchivist method copyInto.
/**
* Copy this archivist to a new abstract archive
*
* @param a
* the deployment descriptor for an application
* @param source
* the source archive
* @param target
* the target archive
* @param overwriteManifest
* if true, the manifest in source archive overwrites the one in target
*/
public void copyInto(Application a, ReadableArchive source, WritableArchive target, boolean overwriteManifest) throws IOException {
Vector<String> entriesAdded = new Vector<>();
for (ModuleDescriptor aModule : a.getModules()) {
entriesAdded.add(aModule.getArchiveUri());
ReadableArchive subSource = source.getSubArchive(aModule.getArchiveUri());
WritableArchive subTarget = target.createSubArchive(aModule.getArchiveUri());
Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
ReadableArchive subArchive = archiveFactory.openArchive(subTarget.getURI());
subSource.setParentArchive(subArchive);
newArchivist.copyInto(subSource, subTarget, overwriteManifest);
target.closeEntry(subTarget);
String subModulePath = subSource.getURI().getSchemeSpecificPart();
String parentPath = source.getURI().getSchemeSpecificPart();
if (subModulePath.startsWith(parentPath)) {
subModulePath = subModulePath.substring(parentPath.length() + File.separator.length());
for (Enumeration<String> subEntries = subSource.entries(); subEntries.hasMoreElements(); ) {
String anEntry = subEntries.nextElement();
entriesAdded.add(subModulePath + "/" + anEntry);
}
}
subSource.close();
subArchive.close();
}
super.copyInto(source, target, entriesAdded, overwriteManifest);
}
use of org.glassfish.api.deployment.archive.WritableArchive in project Payara by payara.
the class EarHandler method expand.
@Override
public void expand(ReadableArchive source, WritableArchive target, DeploymentContext context) throws IOException {
// expand the top level first so we could read application.xml
super.expand(source, target, context);
ReadableArchive source2 = null;
try {
/*
* We know that the expansion is into a directory, so we should know that target is a FileArchive which is also readable
* as-is.
*/
source2 = (FileArchive) target;
ApplicationHolder holder = getApplicationHolder(source2, context, false);
// now start to expand the sub modules
for (ModuleDescriptor md : holder.app.getModules()) {
String moduleUri = md.getArchiveUri();
ReadableArchive subArchive = null;
WritableArchive subTarget = null;
ReadableArchive subArchiveToExpand = null;
try {
subArchive = source2.getSubArchive(moduleUri);
if (subArchive == null) {
_logger.log(Level.WARNING, "Exception while locating sub archive: " + moduleUri);
continue;
}
// optimize performance by retrieving the archive handler
// based on module type first
ArchiveHandler subHandler = getArchiveHandlerFromModuleType(md.getModuleType());
if (subHandler == null) {
subHandler = deployment.getArchiveHandler(subArchive);
}
context.getModuleArchiveHandlers().put(moduleUri, subHandler);
if (subHandler != null) {
subTarget = target.createSubArchive(FileUtils.makeFriendlyFilenameExtension(moduleUri));
/*
* A subarchive might be packaged as a subdirectory (instead of a nested JAR) in an EAR. If so and if it has the same
* name as the directory into which we'll expand the submodule, make sure it is also of the correct archive type (i.e.,
* directory and not JAR) in which case we don't need to expand it because the developer already did so before
* packaging.
*/
subArchiveToExpand = chooseSubArchiveToExpand(moduleUri, subTarget, subArchive, source2);
if (subArchiveToExpand != null) {
subHandler.expand(subArchiveToExpand, subTarget, context);
} else {
/*
* The target for expansion is the same URI as the subarchive. Make sure they are the same type; if so, we just skip the
* expansion. Otherwise, we would leave a JAR where the rest of deployment expects a subdirectory so throw an exception
* in that case.
*/
if (!areSameStorageType(subTarget, subArchive)) {
final String msg = MessageFormat.format(_logger.getResourceBundle().getString("enterprise.deployment.backend.badSubModPackaging"), subArchive.getURI().toASCIIString(), subArchive.getClass().getName());
throw new RuntimeException(msg);
}
}
// Keep the original submodule file because the app client deployer needs it.
/*
* // delete the original module file File origSubArchiveFile = new File( target.getURI().getSchemeSpecificPart(),
* moduleUri); origSubArchiveFile.delete();
*/
}
} catch (IOException ioe) {
_logger.log(Level.FINE, "Exception while processing " + moduleUri, ioe);
} finally {
try {
if (subArchive != null) {
subArchive.close();
}
if (subTarget != null) {
subTarget.close();
}
if (subArchiveToExpand != null) {
subArchiveToExpand.close();
}
} catch (IOException ioe) {
// ignore
}
}
}
} finally {
if (source2 != null) {
source2.close();
}
}
}
Aggregations