use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class DeployerEjbTest method getDeployedApp.
private AppInfo getDeployedApp() throws Exception {
final Collection<AppInfo> appInfos = getAppInfos();
AppInfo appInfo = null;
final File file = warArchive.get();
if (appInfos.size() < 2) {
appInfo = getAppInfo();
} else {
final String name = file.getName().toLowerCase();
for (final AppInfo info : appInfos) {
if (name.contains(info.appId.toLowerCase())) {
appInfo = info;
}
}
}
return appInfo;
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class DeployerEjbTest method testDeployWarSave.
@Test
public void testDeployWarSave() throws Exception {
final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps();
Assert.assertTrue("Found more than one app", deployedApps.size() < 2);
final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml");
Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists());
getAppInfo();
Assert.assertTrue("Failed to find: " + deployments.getAbsolutePath(), deployments.exists());
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class DeployerEjbTest method testReload.
@Test
public void testReload() throws Exception {
final AppInfo appInfo = getDeployedApp();
final Deployer deployer = getDeployer();
deployer.reload(appInfo.path);
final Collection<AppInfo> deployedApps = deployer.getDeployedApps();
boolean found = false;
for (final AppInfo app : deployedApps) {
if (app.path.equals(appInfo.path)) {
found = true;
}
}
Assert.assertTrue("Failed to find app after redeploy", found);
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class DeployerEjbTest method testDeployWarNoSave.
@Test
public void testDeployWarNoSave() throws Exception {
final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps();
Assert.assertTrue("Found more than one app", deployedApps.size() < 2);
final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml");
if (deployments.exists()) {
Files.delete(deployments);
}
Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists());
final Properties p = new Properties();
p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString());
getAppInfo(p);
Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists());
}
use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.
the class Container method deploy.
public Container deploy(final DeploymentRequest request) {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final SystemInstance systemInstance = SystemInstance.get();
String contextRoot = request.context == null ? "" : request.context;
if (!contextRoot.isEmpty() && !contextRoot.startsWith("/")) {
contextRoot = "/" + request.context;
}
File jarLocation = request.docBase == null || !request.docBase.isDirectory() ? fakeRootDir() : request.docBase;
final WebModule webModule = new WebModule(new WebApp(), contextRoot, loader, jarLocation.getAbsolutePath(), contextRoot.replace("/", ""));
if (request.docBase == null) {
webModule.getProperties().put("fakeJarLocation", "true");
}
webModule.setUrls(request.jarList);
webModule.setAddedUrls(Collections.<URL>emptyList());
webModule.setRarUrls(Collections.<URL>emptyList());
webModule.setScannableUrls(request.jarList);
final AnnotationFinder finder;
try {
Filter filter = configuration.getClassesFilter();
if (filter == null && (request.jarList.size() <= 4 || "true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.embedded.filter-container-classes")))) {
filter = new ContainerClassesFilter(configuration.getProperties());
}
final Archive archive;
if (request.archive == null) {
archive = new WebappAggregatedArchive(webModule, request.jarList, // see org.apache.openejb.config.DeploymentsResolver.ClasspathSearcher.cleanUpUrlSet()
filter);
} else if (WebappAggregatedArchive.class.isInstance(request.archive)) {
archive = request.archive;
} else {
archive = new WebappAggregatedArchive(request.archive, request.jarList);
}
finder = new FinderFactory.OpenEJBAnnotationFinder(archive).link();
SystemInstance.get().fireEvent(new TomEEEmbeddedScannerCreated(finder));
webModule.setFinder(finder);
} catch (final Exception e) {
throw new IllegalArgumentException(e);
}
final File beansXml = new File(request.docBase, "WEB-INF/beans.xml");
if (beansXml.exists()) {
// add it since it is not in the scanned path by default
try {
webModule.getAltDDs().put("beans.xml", beansXml.toURI().toURL());
} catch (final MalformedURLException e) {
// no-op
}
}
// else no classpath finding since we'll likely find it
DeploymentLoader.addBeansXmls(webModule);
final AppModule app = new AppModule(loader, null);
app.setStandloneWebModule();
app.setStandaloneModule(true);
app.setModuleId(webModule.getModuleId());
try {
final Map<String, URL> webDescriptors = DeploymentLoader.getWebDescriptors(jarLocation);
if (webDescriptors.isEmpty()) {
// likely so let's try to find them in the classpath
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final Collection<String> metaDir = asList("META-INF/tomee/", "META-INF/");
for (final String dd : asList("app-ctx.xml", "module.properties", "application.properties", "env-entries.properties", NewLoaderLogic.EXCLUSION_FILE, "web.xml", "ejb-jar.xml", "openejb-jar.xml", "validation.xml")) {
if (Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.embedded.descriptors.classpath." + dd + ".skip")) || webDescriptors.containsKey(dd)) {
continue;
}
for (final String meta : metaDir) {
final URL url = classLoader.getResource(meta + dd);
if (url != null) {
webDescriptors.put(dd, url);
break;
}
}
}
}
webDescriptors.remove("beans.xml");
webModule.getAltDDs().putAll(webDescriptors);
DeploymentLoader.addWebModule(webModule, app);
DeploymentLoader.addWebModuleDescriptors(new File(webModule.getJarLocation()).toURI().toURL(), webModule, app);
} catch (final Exception e) {
throw new IllegalStateException(e);
}
if (!SystemInstance.isInitialized() || Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.embedded.add-callers", "true"))) {
addCallersAsEjbModule(loader, app, request.additionalCallers);
}
systemInstance.addObserver(new StandardContextCustomizer(configuration, webModule, request.keepClassloader));
if (systemInstance.getComponent(AnnotationDeployer.FolderDDMapper.class) == null) {
systemInstance.setComponent(AnnotationDeployer.FolderDDMapper.class, new AnnotationDeployer.FolderDDMapper() {
@Override
public File getDDFolder(final File dir) {
try {
return isMaven(dir) || isGradle(dir) ? new File(request.docBase, "WEB-INF") : null;
} catch (final RuntimeException re) {
// folder doesn't exist -> test is stopped which is expected
return null;
}
}
private boolean isGradle(final File dir) {
return dir.getName().equals("classes") && dir.getParentFile().getName().equals("target");
}
private boolean isMaven(final File dir) {
return dir.getName().equals("main") && dir.getParentFile().getName().equals("classes") && dir.getParentFile().getParentFile().getName().equals("build");
}
});
}
try {
final AppInfo appInfo = configurationFactory.configureApplication(app);
systemInstance.getComponent(Assembler.class).createApplication(appInfo, loader);
} catch (final Exception e) {
throw new IllegalStateException(e);
}
return this;
}
Aggregations