use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class ApplicationArchivist method getApplicationFromIntrospection.
/**
* This method introspect an ear file and populate the Application object. We follow the Java EE platform specification,
* Section EE.8.4.2 to determine the type of the modules included in this application.
*
* @param archive
* the archive representing the application root
* @param directory
* whether this is a directory deployment
*/
private Application getApplicationFromIntrospection(ReadableArchive archive, boolean directory) {
// archive is a directory
String appRoot = archive.getURI().getSchemeSpecificPart();
if (appRoot.endsWith(File.separator)) {
appRoot = appRoot.substring(0, appRoot.length() - 1);
}
Application app = Application.createApplication();
app.setLoadedFromApplicationXml(false);
app.setVirtual(false);
// name of the file without its extension
String appName = appRoot.substring(appRoot.lastIndexOf(File.separatorChar) + 1);
app.setName(appName);
List<ReadableArchive> unknowns = new ArrayList<ReadableArchive>();
File[] files = getEligibleEntries(new File(appRoot), directory);
for (File subModule : files) {
ReadableArchive subArchive = null;
try {
try {
subArchive = archiveFactory.openArchive(subModule);
} catch (IOException ex) {
logger.log(Level.WARNING, ex.getMessage());
}
// for archive deployment, we check the sub archives by its
// file extension; for directory deployment, we check the sub
// directories by its name. We are now supporting directory
// names with both "_suffix" and ".suffix".
// Section EE.8.4.2.1.a
String name = subModule.getName();
String uri = deriveArchiveUri(appRoot, subModule, directory);
if ((!directory && name.endsWith(".war")) || (directory && (name.endsWith("_war") || name.endsWith(".war")))) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.warType());
// the context root will be set later after
// we process the sub modules
app.addModule(md);
} else // Section EE.8.4.2.1.b
if ((!directory && name.endsWith(".rar")) || (directory && (name.endsWith("_rar") || name.endsWith(".rar")))) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.rarType());
app.addModule(md);
} else if ((!directory && name.endsWith(".jar")) || (directory && (name.endsWith("_jar") || name.endsWith(".jar")))) {
try {
// Section EE.8.4.2.1.d.i
AppClientArchivist acArchivist = new AppClientArchivist();
if (acArchivist.hasStandardDeploymentDescriptor(subArchive) || acArchivist.hasRuntimeDeploymentDescriptor(subArchive) || acArchivist.getMainClassName(subArchive.getManifest()) != null) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.carType());
md.setManifest(subArchive.getManifest());
app.addModule(md);
continue;
}
// Section EE.8.4.2.1.d.ii
Archivist ejbArchivist = archivistFactory.get().getArchivist(DOLUtils.ejbType());
if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive) || ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.ejbType());
app.addModule(md);
continue;
}
} catch (IOException ex) {
logger.log(Level.WARNING, ex.getMessage());
}
// Still could not decide between an ejb and a library
unknowns.add(subArchive);
// Prevent this unknown archive from being closed in the
// finally block, because the same object will be used in
// the block below where unknowns are checked one more time.
subArchive = null;
} else {
// ignored
}
} finally {
if (subArchive != null) {
try {
subArchive.close();
} catch (IOException ioe) {
logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.errorClosingSubArch", "Error closing subarchive {0}", new Object[] { subModule.getAbsolutePath() }), ioe);
}
}
}
}
if (unknowns.size() > 0) {
AnnotationDetector detector = new AnnotationDetector(new EjbComponentAnnotationScanner());
for (int i = 0; i < unknowns.size(); i++) {
File jarFile = new File(unknowns.get(i).getURI().getSchemeSpecificPart());
try {
if (detector.hasAnnotationInArchive(unknowns.get(i))) {
String uri = deriveArchiveUri(appRoot, jarFile, directory);
// Section EE.8.4.2.1.d.ii, alas EJB
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<BundleDescriptor>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.ejbType());
app.addModule(md);
}
/*
* The subarchive was opened by the anno detector. Close it.
*/
unknowns.get(i).close();
} catch (IOException ex) {
logger.log(Level.WARNING, ex.getMessage());
}
}
}
return app;
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class TracerVisitor method accept.
@Override
public void accept(BundleDescriptor descriptor) {
if (descriptor instanceof Application) {
Application application = (Application) descriptor;
accept(application);
for (BundleDescriptor ebd : application.getBundleDescriptorsOfType(DOLUtils.ejbType())) {
ebd.visit(getSubDescriptorVisitor(ebd));
}
for (BundleDescriptor wbd : application.getBundleDescriptorsOfType(DOLUtils.warType())) {
// the validation step from bombing.
if (wbd != null) {
wbd.visit(getSubDescriptorVisitor(wbd));
}
}
for (BundleDescriptor cd : application.getBundleDescriptorsOfType(DOLUtils.rarType())) {
cd.visit(getSubDescriptorVisitor(cd));
}
for (BundleDescriptor acd : application.getBundleDescriptorsOfType(DOLUtils.carType())) {
acd.visit(getSubDescriptorVisitor(acd));
}
super.accept(descriptor);
} else {
super.accept(descriptor);
}
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class GetContextRootCommand method execute.
/**
* Entry point from the framework into the command execution
* @param context context for the command.
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
ApplicationInfo appInfo = appRegistry.get(appname);
if (appInfo != null) {
Application app = appInfo.getMetaData(Application.class);
if (app != null) {
// strip the version suffix (delimited by colon), if present
int versionSuffix = modulename.indexOf(':');
String versionLessModuleName = versionSuffix > 0 ? modulename.substring(0, versionSuffix) : modulename;
BundleDescriptor bundleDesc = app.getModuleByUri(versionLessModuleName);
if (bundleDesc != null && bundleDesc instanceof WebBundleDescriptor) {
String contextRoot = ((WebBundleDescriptor) bundleDesc).getContextRoot();
part.addProperty(DeploymentProperties.CONTEXT_ROOT, contextRoot);
part.setMessage(contextRoot);
}
}
}
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class ListSubComponentsCommand method getAppLevelComponents.
private Map<String, String> getAppLevelComponents(com.sun.enterprise.deployment.Application application, String type, Map<String, String> subComponentsMap) {
Map<String, String> subComponentList = new LinkedHashMap<String, String>();
if (application.isVirtual()) {
// for standalone module, get servlets or ejbs
BundleDescriptor bundleDescriptor = application.getStandaloneBundleDescriptor();
subComponentList = getModuleLevelComponents(bundleDescriptor, type, subComponentsMap);
} else {
// for ear case, get modules
Collection<ModuleDescriptor<BundleDescriptor>> modules = getSubModuleListForEar(application, type);
for (ModuleDescriptor module : modules) {
StringBuffer sb = new StringBuffer();
String moduleName = module.getArchiveUri();
sb.append("<");
String moduleType = getModuleType(module);
sb.append(moduleType);
sb.append(">");
subComponentList.put(moduleName, sb.toString());
subComponentsMap.put(module.getArchiveUri(), moduleType);
}
}
return subComponentList;
}
use of com.sun.enterprise.deployment.BundleDescriptor in project Payara by payara.
the class ListSubComponentsCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
String applicationName = modulename;
if (appname != null) {
applicationName = appname;
}
try {
VersioningUtils.checkIdentifier(applicationName);
} catch (VersioningSyntaxException ex) {
report.setMessage(ex.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (!deployment.isRegistered(applicationName)) {
report.setMessage(localStrings.getLocalString("application.notreg", "Application {0} not registered", applicationName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Application application = applications.getApplication(applicationName);
if (application.isLifecycleModule()) {
if (!terse) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
return;
}
ApplicationInfo appInfo = appRegistry.get(applicationName);
if (appInfo == null) {
report.setMessage(localStrings.getLocalString("application.not.enabled", "Application {0} is not in an enabled state", applicationName));
return;
}
com.sun.enterprise.deployment.Application app = appInfo.getMetaData(com.sun.enterprise.deployment.Application.class);
if (app == null) {
if (!terse) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
return;
}
Map<String, String> subComponents;
Map<String, String> subComponentsMap = new HashMap<String, String>();
if (appname == null) {
subComponents = getAppLevelComponents(app, type, subComponentsMap);
} else {
// strip the version suffix (delimited by colon), if present
int versionSuffix = modulename.indexOf(':');
String versionLessModuleName = versionSuffix > 0 ? modulename.substring(0, versionSuffix) : modulename;
BundleDescriptor bundleDesc = app.getModuleByUri(versionLessModuleName);
if (bundleDesc == null) {
report.setMessage(localStrings.getLocalString("listsubcomponents.invalidmodulename", "Invalid module name", appname, modulename));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
subComponents = getModuleLevelComponents(bundleDesc, type, subComponentsMap);
}
// the type param can only have values "ejbs" and "servlets"
if (type != null) {
if (!type.equals("servlets") && !type.equals("ejbs")) {
report.setMessage(localStrings.getLocalString("listsubcomponents.invalidtype", "The type option has invalid value {0}. It should have a value of servlets or ejbs.", type));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
List<String> subModuleInfos = new ArrayList<String>();
if (!app.isVirtual()) {
subModuleInfos = getSubModulesForEar(app, type);
}
int[] longestValue = new int[2];
for (Map.Entry<String, String> entry : subComponents.entrySet()) {
String key = entry.getKey();
if (key.length() > longestValue[0]) {
longestValue[0] = key.length();
}
String value = entry.getValue();
if (value.length() > longestValue[1]) {
longestValue[1] = value.length();
}
}
StringBuilder formattedLineBuf = new StringBuilder();
for (int j = 0; j < 2; j++) {
longestValue[j] += 2;
formattedLineBuf.append("%-").append(longestValue[j]).append("s");
}
String formattedLine = formattedLineBuf.toString();
if (!terse && subComponents.isEmpty()) {
part.setMessage(localStrings.getLocalString("listsubcomponents.no.elements.to.list", "Nothing to List."));
}
int i = 0;
for (String key : subComponents.keySet()) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(String.format(formattedLine, new Object[] { key, subComponents.get(key) }));
if (appname == null && !app.isVirtual()) {
// support for JSR88 client
if (subModuleInfos.get(i) != null) {
childPart.addProperty("moduleInfo", subModuleInfos.get(i));
}
}
if (resources) {
Module module = application.getModule(key);
if (module != null) {
ActionReport subReport = report.addSubActionsReport();
CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport, context.getSubject());
final ParameterMap parameters = new ParameterMap();
parameters.add("appname", application.getName());
parameters.add("modulename", module.getName());
inv.parameters(parameters).execute();
ActionReport.MessagePart subPart = subReport.getTopMessagePart();
for (ActionReport.MessagePart cp : subPart.getChildren()) {
ActionReport.MessagePart resourcesChildPart = childPart.addChild();
resourcesChildPart.setMessage(" " + cp.getMessage());
}
}
}
i++;
}
// add the properties for GUI to display
Set<String> keys = subComponentsMap.keySet();
for (String key : keys) {
part.addProperty(key, subComponentsMap.get(key));
}
// now this is the normal output for the list-sub-components command
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations