Skip to content

Commit

Permalink
Make it portable with JDK5
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1703 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
alesj committed Feb 25, 2009
1 parent d46e416 commit 9682599
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 64 deletions.
Expand Up @@ -2,6 +2,7 @@

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
Expand All @@ -18,33 +19,33 @@
import org.jboss.webbeans.tck.integration.jbossas.util.DeploymentProperties;

/**
*
*
* @author jeffgenender
* @author Pete Muir
*
*/
public abstract class AbstractContainersImpl implements Configurable, Containers
{

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";
public static final String JBOSS_AS_DIR_PROPERTY_NAME = "jboss-as.dir";
public static final String JBOSS_BOOT_TIMEOUT_PROPERTY_NAME = "jboss.boot.timeout";
public static final String FORCE_RESTART_PROPERTY_NAME = "jboss.force.restart";

private static Logger log = Logger.getLogger(AbstractContainersImpl.class);

private final DeploymentProperties properties;

private Configuration configuration;
protected String jbossHome;
private String jbossHttpUrl;
private boolean jbossWasStarted;
private long bootTimeout;
private String javaOpts;

public AbstractContainersImpl()
{
this.properties = new DeploymentProperties();
Expand All @@ -53,21 +54,21 @@ public AbstractContainersImpl()
protected static void copy(InputStream inputStream, File file) throws IOException
{
OutputStream os = new FileOutputStream(file);
try
try
{
byte[] buf = new byte[1024];
int i = 0;
while ((i = inputStream.read(buf)) != -1)
while ((i = inputStream.read(buf)) != -1)
{
os.write(buf, 0, i);
}
}
finally
}
finally
{
os.close();
}
}
}

public void setConfiguration(Configuration configuration)
{
this.configuration = configuration;
Expand All @@ -91,14 +92,14 @@ protected boolean isJBossUp()
return false;
}
}
catch (Exception e)
catch (Exception e)
{
return false;
}
log.info("Successfully connected to JBoss AS at " + jbossHttpUrl);
return true;
}

public void setup() throws IOException
{
String jbossAsPath = properties.getStringValue(JBOSS_AS_DIR_PROPERTY_NAME, "../jboss-as", false);
Expand All @@ -110,14 +111,14 @@ public void setup() throws IOException
File buildProperties = new File(jbossAsDir, "build.properties");
if (buildProperties.exists())
{
System.getProperties().load(new FileReader(buildProperties));
loadProperties(buildProperties);
}
File localBuildProperties = new File(jbossAsDir, "local.build.properties");
if (localBuildProperties.exists())
{
System.getProperties().load(new FileReader(localBuildProperties));
loadProperties(localBuildProperties);
}
}
}
}
jbossHome = properties.getStringValue(JBOSS_HOME_PROPERTY_NAME, null, true);
javaOpts = properties.getStringValue(JAVA_OPTS_PROPERTY_NAME, "", false);
Expand Down Expand Up @@ -152,7 +153,7 @@ public void setup() throws IOException
boolean interrupted = false;
while (timeoutTime > System.currentTimeMillis())
{
if (isJBossUp())
if (isJBossUp())
{
log.info("Started JBoss instance");
return;
Expand Down Expand Up @@ -180,12 +181,25 @@ public void setup() throws IOException
return;
}
}

public String getJbossHome()

protected void loadProperties(File file) throws IOException
{
InputStream is = new FileInputStream(file);
try
{
System.getProperties().load(is);
}
finally
{
is.close();
}
}

public String getJbossHome()
{
return jbossHome;
}

public void cleanup() throws IOException
{
if (jbossWasStarted)
Expand All @@ -194,20 +208,20 @@ public void cleanup() throws IOException
shutDownJBoss();
}
}

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

private void launch(String scriptFileName, String params) throws IOException
{
String osName = System.getProperty("os.name");
Runtime runtime = Runtime.getRuntime();

Process p = null;
if (osName.startsWith("Windows"))
if (osName.startsWith("Windows"))
{
String command[] = {
"cmd.exe",
Expand All @@ -216,7 +230,7 @@ private void launch(String scriptFileName, String params) throws IOException
};
p = runtime.exec(command);
}
else
else
{
String command[] = {
"sh",
Expand All @@ -229,30 +243,30 @@ private void launch(String scriptFileName, String params) throws IOException
dump(p.getInputStream());
}

protected void dump(final InputStream is)
protected void dump(final InputStream is)
{
new Thread(new Runnable()
new Thread(new Runnable()
{
public void run()
public void run()
{
try
try
{
DataOutputStream out = new DataOutputStream(new FileOutputStream(configuration.getOutputDirectory() + File.separator + "jboss.log"));
int c;
while((c = is.read()) != -1)
while((c = is.read()) != -1)
{
out.writeByte(c);
}
is.close();
out.close();
}
catch(IOException e)
catch(IOException e)
{
System.err.println("Error Writing/Reading Streams.");
}
}
}).start();
}


}
Expand Up @@ -10,12 +10,12 @@

public class JBossTestServicesContainersImpl extends AbstractContainersImpl
{

private Logger log = Logger.getLogger(JBossTestServicesContainersImpl.class);

private final JBossTestServices testServices;
private final File tmpdir;

public JBossTestServicesContainersImpl() throws Exception
{
this.testServices = new JBossTestServices(JBossTestServicesContainersImpl.class);
Expand All @@ -25,7 +25,7 @@ public JBossTestServicesContainersImpl() throws Exception
tmpdir.mkdir();
tmpdir.deleteOnExit();
}

public void deploy(InputStream archiveStream, String name) throws DeploymentException, IOException
{
File archive = new File(tmpdir, name);
Expand All @@ -38,9 +38,9 @@ public void deploy(InputStream archiveStream, String name) throws DeploymentExce
catch (Exception e)
{
throw new DeploymentException("Error deploying " + name, e);
}
}
}

public void undeploy(String name) throws IOException
{
try
Expand All @@ -49,14 +49,16 @@ public void undeploy(String name) throws IOException
}
catch (Exception e)
{
throw new IOException("Error undeploying " + name, e);
IOException ioe = new IOException("Error undeploying " + name);
ioe.initCause(e);
throw ioe;
}
}

private String getTmpArchiveName(String name)
{
File file = new File(tmpdir, name);
return file.toURI().toString();
}

}

0 comments on commit 9682599

Please sign in to comment.