[seam-commits] Seam SVN: r11591 - in branches/community/Seam_2_2/src/test/ftest: seamgen and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Oct 16 04:10:42 EDT 2009
Author: oskutka at redhat.com
Date: 2009-10-16 04:10:41 -0400 (Fri, 16 Oct 2009)
New Revision: 11591
Modified:
branches/community/Seam_2_2/src/test/ftest/ftest.properties
branches/community/Seam_2_2/src/test/ftest/seamgen/build.xml
branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java
branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/utils/SeamGenAdapter.java
Log:
JBSEAM-4445 Use rutime.exec to call ant targets in functional tests
Modified: branches/community/Seam_2_2/src/test/ftest/ftest.properties
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/ftest.properties 2009-10-15 08:31:47 UTC (rev 11590)
+++ branches/community/Seam_2_2/src/test/ftest/ftest.properties 2009-10-16 08:10:41 UTC (rev 11591)
@@ -100,3 +100,4 @@
test.package=com.example.test
richfaces.skin=classic
icefaces.home=
+ant.exec=/usr/bin/ant
Modified: branches/community/Seam_2_2/src/test/ftest/seamgen/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/seamgen/build.xml 2009-10-15 08:31:47 UTC (rev 11590)
+++ branches/community/Seam_2_2/src/test/ftest/seamgen/build.xml 2009-10-16 08:10:41 UTC (rev 11591)
@@ -46,7 +46,6 @@
<path id="classpath.build">
<fileset dir="${root.lib.dir}">
<include name="testng.jar"/>
- <include name="gen/ant.jar"/>
</fileset>
<fileset dir="${ftest.lib.dir}" includes="**/*.jar" />
</path>
Modified: branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java 2009-10-15 08:31:47 UTC (rev 11590)
+++ branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java 2009-10-16 08:10:41 UTC (rev 11591)
@@ -57,7 +57,8 @@
protected static String SEAMGEN_BUILDFILE;
protected static String SEAMGEN_PROPERTIES_FILE;
protected static String WORKSPACE;
-
+ protected static String ANT_EXECUTABLE;
+
// container specific properties
protected static String CONTAINER;
protected static String CONTAINER_LOCATION;
@@ -132,7 +133,7 @@
setSeamGenProperties();
- seamGen = new SeamGenAdapter(SEAMGEN_BUILDFILE);
+ seamGen = new SeamGenAdapter(ANT_EXECUTABLE, SEAMGEN_BUILDFILE);
seamGen.setExplode(explode);
}
@@ -156,6 +157,7 @@
ftestProperties.load(new FileInputStream(SEAM_FTEST_PROPERTIES_FILE));
WORKSPACE = getProperty(ftestProperties,"workspace.home");
+ ANT_EXECUTABLE = getProperty(ftestProperties, "ant.exec");
// container specific
CONTAINER = getProperty(ftestProperties, "container", "jboss5");
@@ -310,4 +312,4 @@
dir.mkdir();
}
}
-}
\ No newline at end of file
+}
Modified: branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/utils/SeamGenAdapter.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/utils/SeamGenAdapter.java 2009-10-15 08:31:47 UTC (rev 11590)
+++ branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/utils/SeamGenAdapter.java 2009-10-16 08:10:41 UTC (rev 11591)
@@ -21,15 +21,13 @@
*/
package org.jboss.seam.test.functional.seamgen.utils;
-import java.io.File;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.PrintStream;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DefaultLogger;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.ProjectHelper;
-import org.apache.tools.ant.input.InputHandler;
-import org.apache.tools.ant.input.InputRequest;
+import org.jboss.seam.test.functional.seamgen.SeamGenTest;
/**
* This class wraps seam-gen ant script in order to be easily usable from Java.
@@ -43,60 +41,83 @@
public class SeamGenAdapter
{
- private String buildfile;
- private DefaultLogger log;
- private boolean explode = true;
+ protected String buildfile;
+ protected boolean explode = true;
+ protected PrintStream out, err;
+ protected String antExecutable;
- public SeamGenAdapter(String buildfile)
+ public SeamGenAdapter(String antExecutable, String buildfile)
{
- this(buildfile, System.out, System.err);
+ this(antExecutable, buildfile, System.out, System.err);
}
- public SeamGenAdapter(String buildfile, PrintStream out, PrintStream err)
+ public SeamGenAdapter(String antExecutable, String buildfile, PrintStream out, PrintStream err)
{
+ this.antExecutable = antExecutable;
this.buildfile = buildfile;
- log = new DefaultLogger();
- log.setOutputPrintStream(out);
- log.setErrorPrintStream(err);
- log.setMessageOutputLevel(Project.MSG_INFO);
+ this.err = err;
+ this.out = out;
}
- public Project getAntCall()
+ private String getAntCommand(String task)
{
- Project ant = new Project();
- ant.init();
- ProjectHelper.configureProject(ant, new File(buildfile));
- ant.addBuildListener(log);
- return ant;
+ return antExecutable + " -f " + buildfile + " " + task;
}
+ protected void executeAntTarget(String task)
+ {
+ executeAntTarget(task, null);
+ }
+
+ protected void executeAntTarget(String task, String[] properties)
+ {
+ try
+ {
+ OutputStreamFeeder feeder = null;
+ String antExecutable = getAntCommand(task);
+ Process process = Runtime.getRuntime().exec((antExecutable));
+ if (properties != null && properties.length > 0)
+ {
+ feeder = new OutputStreamFeeder(process.getOutputStream(), out, properties);
+ feeder.start();
+ }
+ // Associate the stdout InputStreamEater with the properties feeder to
+ // have the feeder type in a line from the properties whenever the eater
+ // encounters an input challenge.
+ (new InputStreamEater(process.getInputStream(), out, feeder)).start();
+ (new InputStreamEater(process.getErrorStream(), err, null)).start();
+ process.waitFor();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException(e.toString());
+ }
+ }
+
public void createProject()
{
- getAntCall().executeTarget("create-project");
+ executeAntTarget("create-project");
}
public void deleteProject()
{
- getAntCall().executeTarget("delete-project");
+ executeAntTarget("delete-project");
}
public void newAction(String[] properties)
{
- Project project = getAntCall();
- project.setInputHandler(getInputHandler(properties));
- project.executeTarget("new-action");
+ executeAntTarget("new-action", properties);
}
public void newForm(String[] properties)
{
- Project project = getAntCall();
- project.setInputHandler(getInputHandler(properties));
- project.executeTarget("new-form");
+ executeAntTarget("new-form", properties);
}
public void generateEntities()
{
- getAntCall().executeTarget("generate");
+ executeAntTarget("generate");
}
/**
@@ -107,11 +128,11 @@
{
if (explode)
{
- getAntCall().executeTarget("explode");
+ executeAntTarget("explode");
}
else
{
- getAntCall().executeTarget("deploy");
+ executeAntTarget("deploy");
}
}
@@ -123,11 +144,11 @@
{
if (explode)
{
- getAntCall().executeTarget("unexplode");
+ executeAntTarget("unexplode");
}
else
{
- getAntCall().executeTarget("undeploy");
+ executeAntTarget("undeploy");
}
}
@@ -135,7 +156,7 @@
{
if (explode)
{
- getAntCall().executeTarget("explode");
+ executeAntTarget("explode");
}
else
{
@@ -145,48 +166,14 @@
public void restart()
{
- getAntCall().executeTarget("restart");
+ executeAntTarget("restart");
}
public void addIdentityManagement()
{
- getAntCall().executeTarget("add-identity-management");
+ executeAntTarget("add-identity-management");
}
- private InputHandler getInputHandler(final String[] properties)
- {
- return new InputHandler()
- {
- public void handleInput(InputRequest request) throws BuildException
- {
- if (request.getPrompt().contains("Enter the Seam component name"))
- {
- request.setInput(properties[0]);
- }
- else if (request.getPrompt().contains("Enter the local interface name"))
- {
- request.setInput(properties[1]);
- }
- else if (request.getPrompt().contains("Enter the bean class name"))
- {
- request.setInput(properties[2]);
- }
- else if (request.getPrompt().contains("Enter the action method name"))
- {
- request.setInput(properties[3]);
- }
- else if (request.getPrompt().contains("Enter the page name"))
- {
- request.setInput(properties[4]);
- }
- else
- {
- throw new RuntimeException("Unexpected prompt " + request.getPrompt());
- }
- }
- };
- }
-
public boolean isExplode()
{
return explode;
@@ -201,4 +188,95 @@
this.explode = explode;
}
+ /**
+ * EatInputStreamData class is used for handling InputStream (stdout, stderr)
+ * of an ant sub-process. When it encounters an input challenge, it notifies
+ * the associated {@link OutputStreamFeeder} to provide the input.
+ *
+ */
+ class InputStreamEater extends Thread
+ {
+ private static final String INPUT_CHALLENGE = "[input]";
+ private BufferedReader stream;
+ private OutputStreamFeeder feederToNotify;
+ private PrintStream out;
+
+ public InputStreamEater(InputStream stream, PrintStream out, OutputStreamFeeder feederToNotify)
+ {
+ this.stream = new BufferedReader(new InputStreamReader(stream));
+ this.out = out;
+ this.feederToNotify = feederToNotify;
+ setDaemon(true);
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ String line;
+ while ((line = stream.readLine()) != null)
+ {
+ out.println(line);
+ if (feederToNotify != null && line.contains(INPUT_CHALLENGE))
+ {
+ // notify OutputStreamFeeder to send an input
+ feederToNotify.feed();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ /**
+ * OutputStreamFeeder class is used for feeding OutputStream (stdin) of an
+ * ant sub-process with appropriate inputs. It waits for a notification from
+ * the associated {@link InputStreamEater} object.
+ *
+ */
+ class OutputStreamFeeder extends Thread
+ {
+
+ PrintStream stream, out;
+ String[] food;
+
+ public OutputStreamFeeder(OutputStream stream, PrintStream out, String[] food)
+ {
+ this.stream = new PrintStream(stream);
+ this.food = food;
+ this.out = out;
+ setDaemon(true);
+ }
+
+ @Override
+ public synchronized void run()
+ {
+ try
+ {
+ for (int i = 0; i < food.length; i++)
+ {
+ // wait for a notification from EatInputStreamData
+ wait();
+ stream.println(food[i]);
+ stream.flush();
+ out.println("Typed: " + food[i]);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public synchronized void feed()
+ {
+ this.notify();
+ }
+
+ }
}
More information about the seam-commits
mailing list