use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class EarPersistenceArchivist method open.
/**
* Reads persistence.xml from spec defined pu roots of an ear.
* Spec defined pu roots are - (1)Non component jars in root of ear (2)jars in lib of ear
*/
@Override
public Object open(Archivist main, ReadableArchive earArchive, final RootDeploymentDescriptor descriptor) throws IOException, SAXParseException {
if (deplLogger.isLoggable(Level.FINE)) {
deplLogger.logp(Level.FINE, "EarArchivist", "readPersistenceDeploymentDescriptors", "archive = {0}", earArchive.getURI());
}
Map<String, ReadableArchive> probablePersitenceArchives = new HashMap<>();
try {
if (!(descriptor instanceof Application)) {
return null;
}
final Application app = Application.class.cast(descriptor);
// TODO: need to compute includeRoot, not hard-code it, in the next invocation. The flag should be set to true if operating in v2 compatibility mode false otherwise.
// Check with Hong how to get hold of the flag here?
EARBasedPersistenceHelper.addLibraryAndTopLevelCandidates(earArchive, app, true, /* includeRoot */
probablePersitenceArchives);
for (Map.Entry<String, ReadableArchive> pathToArchiveEntry : probablePersitenceArchives.entrySet()) {
readPersistenceDeploymentDescriptor(main, pathToArchiveEntry.getValue(), pathToArchiveEntry.getKey(), descriptor);
}
} finally {
for (Archive subArchive : probablePersitenceArchives.values()) {
subArchive.close();
}
}
return null;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class DescriptorFactory method createApplicationDescriptor.
/**
* Returns the parsed DOL object from archive
*
* @param archiveFile original archive file
* @param destRootDir root destination directory where the application
* should be expanded under in case of archive deployment
* @param parentCl parent classloader
*
* @return the parsed DOL object
*/
public ResultHolder createApplicationDescriptor(File archiveFile, File destRootDir, ClassLoader parentCl) throws IOException {
ReadableArchive archive = null;
Application application = null;
try {
Descriptor.setBoundsChecking(false);
archive = archiveFactory.openArchive(archiveFile);
ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
ActionReport dummyReport = new HTMLActionReporter();
String appName = DeploymentUtils.getDefaultEEName(archiveFile.getName());
DeployCommandParameters params = new DeployCommandParameters();
params.name = appName;
ExtendedDeploymentContext context = new DeploymentContextImpl(dummyReport, archive, params, env);
context.setArchiveHandler(archiveHandler);
if (!archiveFile.isDirectory()) {
// expand archive
File destDir = new File(destRootDir, appName);
if (destDir.exists()) {
FileUtils.whack(destDir);
}
destDir.mkdirs();
archiveHandler.expand(archive, archiveFactory.createArchive(destDir), context);
archive.close();
archive = archiveFactory.openArchive(destDir);
context.setSource(archive);
}
// issue 14564
context.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE);
String archiveType = context.getArchiveHandler().getArchiveType();
ClassLoader cl = archiveHandler.getClassLoader(parentCl, context);
Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
if (archivist == null) {
throw new IOException("Cannot determine the Java EE module type for " + archive.getURI());
}
archivist.setAnnotationProcessingRequested(true);
String xmlValidationLevel = dasConfig.getDeployXmlValidation();
archivist.setXMLValidationLevel(xmlValidationLevel);
if (xmlValidationLevel.equals("none")) {
archivist.setXMLValidation(false);
}
archivist.setRuntimeXMLValidation(false);
try {
application = applicationFactory.openArchive(appName, archivist, archive, true);
} catch (SAXParseException e) {
throw new IOException(e);
}
if (application != null) {
application.setClassLoader(cl);
application.visit((ApplicationVisitor) new ApplicationValidator());
}
} finally {
if (archive != null) {
archive.close();
}
// We need to reset it after descriptor building
Descriptor.setBoundsChecking(true);
}
ResultHolder result = new ResultHolder();
result.application = application;
result.archive = archive;
return result;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class EarDeployer method subContext.
private ExtendedDeploymentContext subContext(final Application application, final DeploymentContext context, final String moduleUri) {
ExtendedDeploymentContext moduleContext = ((ExtendedDeploymentContext) context).getModuleDeploymentContexts().get(moduleUri);
if (moduleContext != null) {
return moduleContext;
}
final ReadableArchive subArchive;
try {
subArchive = context.getSource().getSubArchive(moduleUri);
subArchive.setParentArchive(context.getSource());
} catch (IOException ioe) {
deplLogger.log(Level.WARNING, ERROR_OCCURRED, ioe);
return null;
}
final Properties moduleProps = getModuleProps(context, moduleUri);
ActionReport subReport = context.getActionReport().addSubActionsReport();
moduleContext = new DeploymentContextImpl(subReport, context.getSource(), context.getCommandParameters(OpsParams.class), env) {
@Override
public ClassLoader getClassLoader() {
try {
if (context.getClassLoader() == null) {
return null;
}
EarClassLoader appCl = EarClassLoader.class.cast(context.getClassLoader());
if (((ExtendedDeploymentContext) context).getPhase() == Phase.PREPARE) {
return appCl;
} else {
return appCl.getModuleClassLoader(moduleUri);
}
} catch (ClassCastException e) {
return context.getClassLoader();
}
}
@Override
public ClassLoader getFinalClassLoader() {
try {
EarClassLoader finalEarCL = (EarClassLoader) context.getFinalClassLoader();
return finalEarCL.getModuleClassLoader(moduleUri);
} catch (ClassCastException e) {
return context.getClassLoader();
}
}
@Override
public ReadableArchive getSource() {
return subArchive;
}
@Override
public Properties getAppProps() {
return context.getAppProps();
}
@Override
public <U extends OpsParams> U getCommandParameters(Class<U> commandParametersType) {
return context.getCommandParameters(commandParametersType);
}
@Override
public void addTransientAppMetaData(String metaDataKey, Object metaData) {
context.addTransientAppMetaData(metaDataKey, metaData);
}
@Override
public <T> T getTransientAppMetaData(String metaDataKey, Class<T> metadataType) {
return context.getTransientAppMetaData(metaDataKey, metadataType);
}
@Override
public Properties getModuleProps() {
return moduleProps;
}
@Override
public ReadableArchive getOriginalSource() {
try {
File appRoot = context.getSourceDir();
File origModuleFile = new File(appRoot, moduleUri);
return archiveFactory.openArchive(origModuleFile);
} catch (IOException ioe) {
return null;
}
}
@Override
public File getScratchDir(String subDirName) {
String modulePortion = Util.getURIName(getSource().getURI());
return (new File(super.getScratchDir(subDirName), modulePortion));
}
@Override
public <T> T getModuleMetaData(Class<T> metadataType) {
try {
return metadataType.cast(application.getModuleByUri(moduleUri));
} catch (Exception e) {
// let's first try the extensions mechanisms...
if (RootDeploymentDescriptor.class.isAssignableFrom(metadataType)) {
for (RootDeploymentDescriptor extension : application.getModuleByUri(moduleUri).getExtensionsDescriptors((Class<RootDeploymentDescriptor>) metadataType)) {
// we assume there can only be one type of
if (extension != null) {
try {
return metadataType.cast(extension);
} catch (Exception e1) {
// next one...
}
}
}
}
return context.getModuleMetaData(metadataType);
}
}
};
((ExtendedDeploymentContext) context).getModuleDeploymentContexts().put(moduleUri, moduleContext);
moduleContext.setParentContext((ExtendedDeploymentContext) context);
moduleContext.setModuleUri(moduleUri);
ArchiveHandler subHandler = context.getModuleArchiveHandlers().get(moduleUri);
moduleContext.setArchiveHandler(subHandler);
return moduleContext;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class AppClientDeployerHelper method JAROfExpandedSubmodule.
/**
* If the specified URI is for an expanded submodule, makes a copy of
* the submodule as a JAR and returns the URI for the copy.
* @param classPathElement
* @return URI to the safe copy of the submodule, relative to the top level
* if the classPathElement is for a submodule; null otherwise
*/
File JAROfExpandedSubmodule(final URI candidateSubmoduleURI) throws IOException {
ReadableArchive source = new FileArchive();
source.open(dc().getSource().getParentArchive().getURI().resolve(expandedDirURI(candidateSubmoduleURI)));
OutputJarArchive target = new OutputJarArchive();
target.create(dc().getScratchDir("xml").toURI().resolve(candidateSubmoduleURI));
/*
* Copy the manifest explicitly because the ReadableArchive
* entries() method omits it.
*/
Manifest mf = source.getManifest();
OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
mf.write(os);
target.closeEntry();
copyArchive(source, target, Collections.EMPTY_SET);
target.close();
return new File(target.getURI());
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class AppClientDeployerHelper method generateAppClientFacade.
protected final void generateAppClientFacade() throws IOException, URISyntaxException {
OutputJarArchive facadeArchive = new OutputJarArchive();
/*
* Make sure the directory subtree to contain the facade exists. If the
* client URI within the EAR contains a directory then that directory
* probably does not exist in the generated dir for this app...not yet
* anyway...it is about to exist.
*/
final File facadeFile = new File(facadeServerURI(dc));
if (!facadeFile.getParentFile().exists()) {
if (!facadeFile.getParentFile().mkdirs()) {
final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.errormkdirs");
throw new IOException(MessageFormat.format(msg, facadeFile.getAbsolutePath()));
}
}
facadeArchive.create(facadeServerURI(dc));
ReadableArchive source = dc.getSource();
Manifest sourceManifest = source.getManifest();
if (sourceManifest == null) {
final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.noManifest");
throw new IOException(MessageFormat.format(msg, source.getURI().toASCIIString()));
}
Manifest facadeManifest = facadeArchive.getManifest();
initGeneratedManifest(sourceManifest, facadeManifest, facadeClassPath(), PUScanTargets(), application);
/*
* If the developer's app client JAR contains a splash screen, copy
* it from the original JAR to the facade so the Java launcher can
* display it when the app client is launched.
*/
final Attributes srcMainAttrs = sourceManifest.getMainAttributes();
if (srcMainAttrs == null) {
final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.noMainAttrs");
throw new IOException(MessageFormat.format(msg, source.getURI().toASCIIString()));
}
String splash = srcMainAttrs.getValue(AppClientDeployer.SPLASH_SCREEN_IMAGE);
if (splash != null) {
copy(source, facadeArchive, splash);
}
/*
* Write the manifest to the facade.
*/
OutputStream os = facadeArchive.putNextEntry(JarFile.MANIFEST_NAME);
facadeManifest.write(os);
facadeArchive.closeEntry();
/*
* Write the updated descriptors to the facade.
*/
writeUpdatedDescriptors(source, facadeArchive, appClientDesc);
/*
* Because of how persistence units are discovered and added to the
* app client DOL object when the archivist reads the descriptor file,
* add any META-INF/persistence.xml file from the developer's client
* to the client facade. (The generated descriptor and the
* persistence.xml files need to be in the same archive.)
*/
copyPersistenceUnitXML(source, facadeArchive);
copyMainClass(facadeArchive);
addTopLevelContentToClientFacade(facadeArchive);
facadeArchive.close();
}
Aggregations