use of com.sun.enterprise.deployment.util.ApplicationValidator 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. If the archive is a standalone module, this API will
* create an empty application and add the standalone module to it
*
* @param appName the application moduleID
* @param archivist to use to open the archive file
* @param in the input archive
* @param handleRuntimeInfo set to true to read configuration deployment descriptors
* @return the application object
*/
public Application openArchive(String appName, Archivist archivist, ReadableArchive in, boolean handleRuntimeInfo) throws IOException, SAXParseException {
// we are not reading the runtime deployment descriptor now...
archivist.setHandleRuntimeInfo(false);
BundleDescriptor descriptor = archivist.open(in);
Application application;
if (descriptor instanceof Application) {
application = (Application) descriptor;
application.setAppName(appName);
application.setRegistrationName(appName);
} else {
if (descriptor == null) {
logger.log(Level.SEVERE, localStrings.getLocalString("enterprise.deployment.cannotreadDDs", "Cannot read the Deployment Descriptors for module {0}", new Object[] { in.getURI() }));
return null;
}
ModuleDescriptor newModule = archivist.createModuleDescriptor(descriptor);
newModule.setArchiveUri(in.getURI().getSchemeSpecificPart());
application = Application.createVirtualApplication(appName, newModule);
}
// now read the runtime deployment descriptor
if (handleRuntimeInfo) {
// now read the runtime deployment descriptors from the original jar file
archivist.setHandleRuntimeInfo(true);
archivist.readRuntimeDeploymentDescriptor(in, (BundleDescriptor) descriptor);
}
// validate
if (application != null) {
application.setClassLoader(archivist.getClassLoader());
application.visit((ApplicationVisitor) new ApplicationValidator());
}
return application;
}
use of com.sun.enterprise.deployment.util.ApplicationValidator 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;
}
Aggregations