use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class EJBContainerProviderImpl method getRequestedEJBModuleOrLibrary.
/**
* @returns DeploymentElement if this file represents an EJB module or a library.
* Returns null if it's an EJB module which name is not present in the list of requested
* module names.
*/
private DeploymentElement getRequestedEJBModuleOrLibrary(File file, Map<String, Boolean> moduleNames) throws Exception {
DeploymentElement result = null;
String fileName = file.getName();
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("... Testing ... " + fileName);
}
ReadableArchive archive = null;
InputStream is = null;
try {
boolean isEJBModule = false;
String moduleName = DeploymentUtils.getDefaultEEName(fileName);
archive = archiveFactory.openArchive(file);
is = getDeploymentDescriptor(archive);
if (is != null) {
isEJBModule = true;
EjbDeploymentDescriptorFile eddf = new EjbDeploymentDescriptorFile();
eddf.setXMLValidation(false);
EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) eddf.read(is);
ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
moduleDesc.setArchiveUri(fileName);
moduleName = moduleDesc.getModuleName();
} else {
GenericAnnotationDetector detector = new GenericAnnotationDetector(ejbAnnotations);
isEJBModule = detector.hasAnnotationInArchive(archive);
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("... is EJB module: " + isEJBModule);
if (isEJBModule) {
_logger.fine("... is Requested EJB module [" + moduleName + "]: " + (moduleNames.isEmpty() || moduleNames.containsKey(moduleName)));
}
}
if (!isEJBModule || moduleNames.isEmpty()) {
result = new DeploymentElement(file, isEJBModule, moduleName);
} else if (moduleNames.containsKey(moduleName) && !moduleNames.get(moduleName)) {
// Is a requested EJB module and was not found already
result = new DeploymentElement(file, isEJBModule, moduleName);
moduleNames.put(moduleName, true);
}
return result;
} finally {
if (archive != null)
archive.close();
if (is != null)
is.close();
}
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class ResourceUtil method hasPayaraResourcesXML.
public static boolean hasPayaraResourcesXML(ReadableArchive archive, ServiceLocator locator) {
boolean hasResourcesXML = false;
if (archive != null) {
try {
if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.earType(), locator)) {
// handle top-level META-INF/glassfish-resources.xml
if (archive.exists(PAYARA_RESOURCES_XML_META_INF)) {
return true;
}
// check sub-module level META-INF/glassfish-resources.xml and WEB-INF/glassfish-resources.xml
Enumeration<String> entries = archive.entries();
while (entries.hasMoreElements()) {
String element = entries.nextElement();
if (element.endsWith(".jar") || element.endsWith(".war") || element.endsWith(".rar") || element.endsWith("_jar") || element.endsWith("_war") || element.endsWith("_rar")) {
ReadableArchive subArchive = archive.getSubArchive(element);
boolean answer = (subArchive != null && hasPayaraResourcesXML(subArchive, locator));
if (subArchive != null) {
subArchive.close();
}
if (answer) {
return true;
}
}
}
} else {
if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.warType(), locator)) {
return archive.exists(PAYARA_RESOURCES_XML_WEB_INF);
} else {
return archive.exists(PAYARA_RESOURCES_XML_META_INF);
}
}
} catch (IOException ioe) {
// ignore
}
}
return hasResourcesXML;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class ResourceUtil method hasGlassfishResourcesXML.
public static boolean hasGlassfishResourcesXML(ReadableArchive archive, ServiceLocator locator) {
boolean hasResourcesXML = false;
if (archive != null) {
try {
if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.earType(), locator)) {
// handle top-level META-INF/glassfish-resources.xml
if (archive.exists(RESOURCES_XML_META_INF)) {
return true;
}
// check sub-module level META-INF/glassfish-resources.xml and WEB-INF/glassfish-resources.xml
Enumeration<String> entries = archive.entries();
while (entries.hasMoreElements()) {
String element = entries.nextElement();
if (element.endsWith(".jar") || element.endsWith(".war") || element.endsWith(".rar") || element.endsWith("_jar") || element.endsWith("_war") || element.endsWith("_rar")) {
ReadableArchive subArchive = archive.getSubArchive(element);
boolean answer = (subArchive != null && hasGlassfishResourcesXML(subArchive, locator));
if (subArchive != null) {
subArchive.close();
}
if (answer) {
return true;
}
}
}
} else {
if (DeploymentUtils.isArchiveOfType(archive, DOLUtils.warType(), locator)) {
return archive.exists(RESOURCES_XML_WEB_INF);
} else {
return archive.exists(RESOURCES_XML_META_INF);
}
}
} catch (IOException ioe) {
// ignore
}
}
return hasResourcesXML;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class WeldCompositeSniffer method scanLibDir.
// This method returns true if at least one /lib jar is a Weld archive
// A more thorough scan is done in WeldDeployer to extract all Weld archives
// under the /lib directory.
private boolean scanLibDir(ReadableArchive archive, String libLocation, DeploymentContext context) {
boolean entryPresent = false;
if (libLocation != null && !libLocation.isEmpty()) {
Enumeration<String> entries = archive.entries(libLocation);
while (entries.hasMoreElements() && !entryPresent) {
String entryName = entries.nextElement();
// if a jar in lib dir and not WEB-INF/lib/foo/bar.jar
if (entryName.endsWith(WeldUtils.JAR_SUFFIX) && entryName.indexOf(WeldUtils.SEPARATOR_CHAR, libLocation.length() + 1) == -1) {
try {
ReadableArchive jarInLib = archive.getSubArchive(entryName);
entryPresent = isArchiveCDIEnabled(context, jarInLib, WeldUtils.META_INF_BEANS_XML);
if (!entryPresent) {
entryPresent = WeldUtils.isImplicitBeanArchive(context, jarInLib);
}
jarInLib.close();
if (entryPresent)
break;
} catch (IOException e) {
}
}
}
}
return entryPresent;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class WeldCompositeSniffer method handles.
public boolean handles(DeploymentContext context) {
ArchiveType archiveType = habitat.getService(ArchiveType.class, context.getArchiveHandler().getArchiveType());
if (archiveType != null && !supportsArchiveType(archiveType)) {
return false;
}
boolean isWeldApplication = false;
ApplicationHolder holder = context.getModuleMetaData(ApplicationHolder.class);
ReadableArchive appRoot = context.getSource();
if ((holder != null) && (holder.app != null)) {
isWeldApplication = scanLibDir(appRoot, holder.app.getLibraryDirectory(), context);
}
return isWeldApplication;
}
Aggregations