Skip to content

Commit

Permalink
Start to factor out the Bootstrap API
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1561 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Feb 17, 2009
1 parent beaf5b3 commit 78e005b
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 461 deletions.
Expand Up @@ -25,7 +25,7 @@
public abstract class AbstractContainersImpl implements Configurable, Containers
{

public static String JAVA_OPTS = "-ea";
public static String JAVA_OPTS = " -ea";

public static final String JBOSS_HOME_PROPERTY_NAME = "jboss.home";
public static final String JAVA_OPTS_PROPERTY_NAME = "java.opts";
Expand Down Expand Up @@ -145,7 +145,7 @@ public void setup() throws IOException
if (!isJBossUp())
{
jbossWasStarted = true;
launch(jbossHome, "run", "");
launch("run", "");
log.info("Starting JBoss instance");
// Wait for JBoss to come up
long timeoutTime = System.currentTimeMillis() + bootTimeout;
Expand All @@ -172,7 +172,7 @@ public void setup() throws IOException
}
// If we got this far something went wrong
log.warn("Unable to connect to JBoss instance after " + bootTimeout + "ms, giving up!");
launch(jbossHome, "shutdown", "-S");
launch("shutdown", "-S");
throw new IllegalStateException("Error connecting to JBoss instance");
}
else
Expand All @@ -192,11 +192,11 @@ public void cleanup() throws IOException

private void shutDownJBoss() throws IOException
{
launch(jbossHome, "shutdown", "-S");
launch("shutdown", "-S");
log.info("Shut down JBoss AS");
}

private static void launch(String jbossHome, String scriptFileName, String params) throws IOException
private void launch(String scriptFileName, String params) throws IOException
{
String osName = System.getProperty("os.name");
Runtime runtime = Runtime.getRuntime();
Expand All @@ -207,7 +207,7 @@ private static void launch(String jbossHome, String scriptFileName, String param
String command[] = {
"cmd.exe",
"/C",
"set JAVA_OPTS=" + JAVA_OPTS + " & cd " + jbossHome + "\\bin & " + scriptFileName + ".bat " + params
"set JAVA_OPTS=" + javaOpts + " & cd /D " + jbossHome + "\\bin & " + scriptFileName + ".bat " + params
};
p = runtime.exec(command);
}
Expand All @@ -216,7 +216,7 @@ private static void launch(String jbossHome, String scriptFileName, String param
String command[] = {
"sh",
"-c",
"cd /D " + jbossHome + "/bin;set JAVA_OPTS=" + JAVA_OPTS + " ./" + scriptFileName + ".sh " + params
"cd " + jbossHome + "/bin;JAVA_OPTS=" + javaOpts + " ./" + scriptFileName + ".sh " + params
};
p = runtime.exec(command);
}
Expand All @@ -232,7 +232,7 @@ public void run()
{
try
{
DataOutputStream out = new DataOutputStream(new FileOutputStream(System.getProperty("java.io.tmpdir") + "jboss.log"));
DataOutputStream out = new DataOutputStream(new FileOutputStream(System.getProperty("java.io.tmpdir") + File.separator + "jboss.log"));
int c;
while((c = is.read()) != -1)
{
Expand Down
Expand Up @@ -7,7 +7,7 @@
import org.jboss.jsr299.tck.api.DeploymentException;
import org.jboss.jsr299.tck.spi.StandaloneContainers;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.mock.MockBootstrap;
import org.jboss.webbeans.mock.MockLifecycle;
import org.jboss.webbeans.mock.MockWebBeanDiscovery;

public class StandaloneContainersImpl implements StandaloneContainers
Expand All @@ -22,20 +22,19 @@ public void deploy(List<Class<? extends Annotation>> enabledDeploymentTypes, Ite
{
try
{
MockBootstrap bootstrap = new MockBootstrap();
ManagerImpl manager = bootstrap.getManager();
MockLifecycle lifecycle = new MockLifecycle();
ManagerImpl manager = lifecycle.getBootstrap().getManager();
if (enabledDeploymentTypes != null)
{
manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
MockWebBeanDiscovery discovery = new MockWebBeanDiscovery();
MockWebBeanDiscovery discovery = lifecycle.getWebBeanDiscovery();
discovery.setWebBeanClasses(classes);
if (beansXml != null)
{
discovery.setWebBeansXmlFiles(beansXml);
}
bootstrap.setWebBeanDiscovery(discovery);
bootstrap.boot();
lifecycle.beginApplication();
}
catch (Exception e)
{
Expand Down
@@ -0,0 +1,85 @@
package org.jboss.webbeans.bootstrap.api;

import javax.inject.manager.Manager;

import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;

/**
* Bootstrap API for Web Beans.
*
* @author Pete Muir
*
*/
public interface Bootstrap
{

/**
* Set the Web Bean Discovery to use
*
* @param webBeanDiscovery
*/
public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery);

/**
* Set the EjbDiscovery to use
*
* @param ejbDiscovery
*/
public void setEjbDiscovery(EjbDiscovery ejbDiscovery);

/**
* Set the EjbResolver to use
*
* @param ejbResolver
*/
public void setEjbResolver(EjbResolver ejbResolver);

/**
* Set the NamingContext to use.
*
* By default @{link org.jboss.webbeans.resources.DefaultNamingContext} will
* be used
*
* @param namingContext
*/
public void setNamingContext(NamingContext namingContext);

/**
* Set the ResourceLoader to use. By default @{link
* org.jboss.webbeans.resources.DefaultResourceLoader} will be used
*
* @param resourceLoader
*/
public void setResourceLoader(ResourceLoader resourceLoader);

/**
* Initialize the bootstrap:
* <ul>
* <li>Create the manager and bind it to JNDI</li>
* </ul>
*/
public void initialize();

/**
* Get the manager being used for bootstrap.
*
* @return the manager. Unless {@link #initialize()} has been called, this
* method will return null.
*/
public Manager getManager();

/**
* Starts the boot process.
*
* Discovers the beans and registers them with the getManager(). Also
* resolves the injection points. Before running {@link #boot()} the contexts
* should be available
*
*/
public void boot();

}
@@ -0,0 +1,69 @@
package org.jboss.webbeans.bootstrap.api.helpers;

import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;

public abstract class AbstractBootstrap implements Bootstrap
{

private WebBeanDiscovery webBeanDiscovery;
private ResourceLoader resourceLoader;
private NamingContext namingContext;
private EjbResolver ejbResolver;
private EjbDiscovery ejbDiscovery;

public void setEjbDiscovery(EjbDiscovery ejbDiscovery)
{
this.ejbDiscovery = ejbDiscovery;
}

public void setEjbResolver(EjbResolver ejbResolver)
{
this.ejbResolver = ejbResolver;
}

public void setNamingContext(NamingContext namingContext)
{
this.namingContext = namingContext;
}

public void setResourceLoader(ResourceLoader resourceLoader)
{
this.resourceLoader = resourceLoader;
}

public void setWebBeanDiscovery(WebBeanDiscovery webBeanDiscovery)
{
this.webBeanDiscovery = webBeanDiscovery;
}

public WebBeanDiscovery getWebBeanDiscovery()
{
return webBeanDiscovery;
}

public ResourceLoader getResourceLoader()
{
return resourceLoader;
}

public NamingContext getNamingContext()
{
return namingContext;
}

public EjbResolver getEjbResolver()
{
return ejbResolver;
}

public EjbDiscovery getEjbDiscovery()
{
return ejbDiscovery;
}

}
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.jboss.webbeans.resource;
package org.jboss.webbeans.resources.spi.helpers;

import java.util.ArrayList;
import java.util.List;
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.ServletBootstrap;
import org.jboss.webbeans.servlet.ServletInitialization;
import org.jboss.webbeans.util.DeploymentProperties;
import org.jboss.webbeans.util.Reflections;

Expand All @@ -36,11 +36,11 @@
* @author Pete Muir
*
*/
public abstract class PropertiesBasedBootstrap extends WebBeansBootstrap
public abstract class PropertiesBasedInitialization
{

// The log provider
private static final LogProvider log = Logging.getLogProvider(ServletBootstrap.class);
private static final LogProvider log = Logging.getLogProvider(ServletInitialization.class);

/**
* Returns any class constructor from the merged list defined by the
Expand Down Expand Up @@ -99,13 +99,4 @@ protected static <T> T newInstance(Constructor<T> constructor, Object... paramet
}
}

/**
* Gets the deployment properties
*
* @return The deployment properties
*
* @see org.jboss.webbeans.util.DeploymentProperties
*/
protected abstract DeploymentProperties getDeploymentProperties();

}

0 comments on commit 78e005b

Please sign in to comment.