Permalink
Browse files

Revert "[AS7-6172] Consolidate embedded server API"

Breaks EJB Embedded runner, needed by TCK
This reverts commit 2bd88a3.
  • Loading branch information...
1 parent 280e0cb commit bb63bd192e99a277a823b7a0c4f459e586ad4bd5 @n1hility n1hility committed Jan 7, 2013
@@ -20,13 +20,7 @@
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
-
-<!--
- Set these VM properties in your IDE debugger
- -Djava.util.logging.manager=org.jboss.logmanager.LogManager
- -Djboss.home=${workspace_loc:jboss-as-build}/target/jboss-as-7.2.0.Alpha1-SNAPSHOT
--->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -111,13 +105,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <!-- Fork every test because it will launch a separate AS instance -->
- <forkMode>always</forkMode>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
- <jboss.home>${jboss.home}</jboss.home>
+ <jboss.home>${basedir}/target/jbossas</jboss.home>
<module.path>${jboss.home}/modules</module.path>
- <bundle.path>${jboss.home}/bundles</bundle.path>
+ <bundle.path>${jboss.home}/modules</bundle.path>
</systemPropertyVariables>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
@@ -16,11 +16,18 @@
*/
package org.jboss.as.arquillian.container.embedded;
+import java.io.File;
+import java.util.logging.LogManager;
+
import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
import org.jboss.arquillian.container.spi.client.container.LifecycleException;
import org.jboss.as.arquillian.container.CommonDeployableContainer;
-import org.jboss.as.embedded.EmbeddedServerFactory;
-import org.jboss.as.embedded.StandaloneServer;
+import org.jboss.modules.Module;
+import org.jboss.modules.ModuleClassLoader;
+import org.jboss.modules.ModuleIdentifier;
+import org.jboss.modules.ModuleLoadException;
+import org.jboss.modules.ModuleLoader;
+import org.jboss.modules.log.JDKModuleLogger;
/**
* {@link DeployableContainer} implementation to bootstrap JBoss Logging (installing the LogManager if possible), use the JBoss
@@ -29,41 +36,191 @@
*
* @author <a href="mailto:alr@jboss.org">Andrew Lee Rubinger</a>
* @author <a href="mailto:mmatloka@gmail.com">Michal Matloka</a>
- * @author Thomas.Diesler@jboss.com
*/
public final class EmbeddedDeployableContainer extends CommonDeployableContainer<EmbeddedContainerConfiguration> {
+ private static final String MODULE_ID_LOGMANAGER = "org.jboss.logmanager";
+ private static final String MODULE_ID_VFS = "org.jboss.vfs";
+ private static final String SYSPROP_KEY_CLASS_PATH = "java.class.path";
+ private static final String SYSPROP_KEY_MODULE_PATH = "module.path";
+ private static final String SYSPROP_KEY_BUNDLE_PATH = "jboss.bundles.dir";
+ private static final String SYSPROP_KEY_LOGMANAGER = "java.util.logging.manager";
+ private static final String SYSPROP_KEY_JBOSS_HOME_DIR = "jboss.home.dir";
+ private static final String SYSPROP_VALUE_JBOSS_LOGMANAGER = "org.jboss.logmanager.LogManager";
+
/**
* Hook to the server; used in start/stop, created by setup
*/
- private StandaloneServer server;
+ private StandaloneServerIndirection server;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.as.arquillian.container.CommonDeployableContainer#setup(org.jboss.as.arquillian.container.CommonContainerConfiguration)
+ */
@Override
public void setup(final EmbeddedContainerConfiguration config) {
super.setup(config);
- server = EmbeddedServerFactory.create(config.getJbossHome(), config.getModulePath(), config.getBundlePath());
+
+ final ModuleLoader moduleLoader = setupModuleLoader(config.getModulePath());
+
+ setupBundlePath(config.getBundlePath());
+
+ setupVfsModule(moduleLoader);
+
+ setupLoggingSystem(moduleLoader);
+
+ setupServer(moduleLoader, config.getJbossHome());
+ }
+
+ /**
+ * Creates/obtains the boot {@link ModuleLoader} for the specified, required modules path
+ *
+ * @param modulePath
+ * @return module loader
+ */
+ private ModuleLoader setupModuleLoader(final String modulePath) {
+ if (modulePath == null || modulePath.isEmpty()) {
+ throw new IllegalStateException("Module path must be defined in the configuration");
+ }
+
+ final File modulesDir = new File(modulePath);
+ if (!modulesDir.isDirectory()) {
+ throw new IllegalStateException("Invalid modules directory: " + modulesDir);
+ }
+
+ final String classPath = SecurityActions.getSystemProperty(SYSPROP_KEY_CLASS_PATH);
+ try {
+ // Set up sysprop env
+ SecurityActions.clearSystemProperty(SYSPROP_KEY_CLASS_PATH);
+ SecurityActions.setSystemProperty(SYSPROP_KEY_MODULE_PATH, modulesDir.getAbsolutePath());
+
+ // Get the module loader
+ final ModuleLoader moduleLoader = Module.getBootModuleLoader();
+ return moduleLoader;
+ } finally {
+ // Return to previous state for classpath prop
+ SecurityActions.setSystemProperty(SYSPROP_KEY_CLASS_PATH, classPath);
+ }
+ }
+
+ /**
+ * Set bundle path
+ *
+ * @param bundlePath
+ */
+ private void setupBundlePath(final String bundlePath) {
+ if (bundlePath == null || bundlePath.isEmpty()) {
+ throw new IllegalStateException("Bundle path must be defined in the configuration");
+ }
+
+ final File bundlesDir = new File(bundlePath);
+ if (!bundlesDir.isDirectory()) {
+ throw new IllegalStateException("Invalid bundles directory: " + bundlesDir);
+ }
+ SecurityActions.setSystemProperty(SYSPROP_KEY_BUNDLE_PATH, bundlePath);
}
+ /**
+ * Register URL Stream Handlers for the VFS Module
+ *
+ * @param moduleLoader
+ */
+ private void setupVfsModule(final ModuleLoader moduleLoader) {
+ final ModuleIdentifier vfsModuleID = ModuleIdentifier.create(MODULE_ID_VFS);
+ final Module vfsModule;
+
+ try {
+ vfsModule = moduleLoader.loadModule(vfsModuleID);
+ } catch (final ModuleLoadException mle) {
+ throw new RuntimeException("Could not load VFS module", mle);
+ }
+
+ Module.registerURLStreamHandlerFactoryModule(vfsModule);
+ }
+
+ /**
+ * Initialize the Logging system
+ *
+ * @param moduleLoader
+ */
+ private void setupLoggingSystem(ModuleLoader moduleLoader) {
+ final ModuleIdentifier logModuleId = ModuleIdentifier.create(MODULE_ID_LOGMANAGER);
+ final Module logModule;
+ try {
+ logModule = moduleLoader.loadModule(logModuleId);
+ } catch (final ModuleLoadException mle) {
+ throw new RuntimeException("Could not load logging module", mle);
+ }
+
+ final ModuleClassLoader logModuleClassLoader = logModule.getClassLoader();
+ final ClassLoader tccl = SecurityActions.getContextClassLoader();
+ try {
+ SecurityActions.setContextClassLoader(logModuleClassLoader);
+ SecurityActions.setSystemProperty(SYSPROP_KEY_LOGMANAGER, SYSPROP_VALUE_JBOSS_LOGMANAGER);
+
+ final Class<?> actualLogManagerClass = LogManager.getLogManager().getClass();
+ if (actualLogManagerClass == LogManager.class) {
+ System.err
+ .println("Could not load JBoss LogManager; the LogManager or Logging subsystem has likely been accessed prior to this initialization.");
+ } else {
+ Module.setModuleLogger(new JDKModuleLogger());
+ }
+ } finally {
+ // Reset TCCL
+ SecurityActions.setContextClassLoader(tccl);
+ }
+ }
+
+ /**
+ * Create and set the server
+ *
+ * @param moduleLoader
+ * @param jbossHomePath
+ */
+ private void setupServer(final ModuleLoader moduleLoader, final String jbossHomePath) {
+ if (jbossHomePath == null || jbossHomePath.isEmpty()) {
+ throw new IllegalStateException("JBoss home path must be defined");
+ }
+
+ final File jbossHome = new File(jbossHomePath);
+ if (!jbossHome.isDirectory()) {
+ throw new IllegalStateException("Invalid jboss home directory: " + jbossHome);
+ }
+
+ // Embedded Server wants this, too. Seems redundant, but supply it.
+ SecurityActions.setSystemProperty(SYSPROP_KEY_JBOSS_HOME_DIR, jbossHome.getAbsolutePath());
+ this.server = new StandaloneServerIndirection(moduleLoader, jbossHome);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.arquillian.container.spi.client.container.DeployableContainer#getConfigurationClass()
+ */
@Override
public Class<EmbeddedContainerConfiguration> getConfigurationClass() {
return EmbeddedContainerConfiguration.class;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.as.arquillian.container.CommonDeployableContainer#startInternal()
+ */
@Override
protected void startInternal() throws LifecycleException {
- try {
- server.start();
- } catch (Throwable e) {
- throw new LifecycleException("Could not invoke start on: " + server, e);
- }
+ // The comment here in AS4/5 used to be "Go get a cup of coffee", but this is FAST now. ;)
+ server.start();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.as.arquillian.container.CommonDeployableContainer#stopInternal()
+ */
@Override
protected void stopInternal() throws LifecycleException {
- try {
- server.stop();
- } catch (Throwable e) {
- throw new LifecycleException("Could not invoke stop on: " + server, e);
- }
+ this.server.stop();
}
}
Oops, something went wrong.

0 comments on commit bb63bd1

Please sign in to comment.