vmassol 2002/08/27 15:55:37
Modified: anttasks/src/java/org/apache/cactus/ant
StartServerHelper.java
Log:
new coding conventions
Revision Changes Path
1.7 +53 -31
jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/StartServerHelper.java
Index: StartServerHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/StartServerHelper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StartServerHelper.java 21 Jul 2002 11:48:58 -0000 1.6
+++ StartServerHelper.java 27 Aug 2002 22:55:37 -0000 1.7
@@ -56,18 +56,19 @@
*/
package org.apache.cactus.ant;
-import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
-import java.io.ByteArrayOutputStream;
+
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.CallTarget;
-import org.apache.tools.ant.Project;
/**
* A helper class for an Ant Task that does the following :
@@ -106,19 +107,19 @@
private boolean isServerAlreadyStarted = false;
/**
- * @return true if the server has already been started.
+ * @param theTask the Ant task that is calling this helper
*/
- public boolean isServerAlreadyStarted()
+ public StartServerHelper(Task theTask)
{
- return this.isServerAlreadyStarted;
+ this.task = theTask;
}
/**
- * @param theTask the Ant task that is calling this helper
+ * @return true if the server has already been started.
*/
- public StartServerHelper(Task theTask)
+ public boolean isServerAlreadyStarted()
{
- this.task = theTask;
+ return this.isServerAlreadyStarted;
}
/**
@@ -127,25 +128,31 @@
public void execute() throws BuildException
{
// Verify that a test URL has been specified
- if (this.testURL == null) {
+ if (this.testURL == null)
+ {
throw new BuildException("A testURL attribute must be specified");
}
// Verify that a start target has been specified
- if (this.startTarget == null) {
+ if (this.startTarget == null)
+ {
throw new BuildException("A startTarget Ant target name must "
+ "be specified");
}
// Try connecting in case the server is already running. If so, does
// nothing
- if (isURLCallable()) {
+ if (isURLCallable())
+ {
// Server is already running. Record this information so that we
// don't stop it afterwards.
this.isServerAlreadyStarted = true;
this.task.log("Server is already running", Project.MSG_DEBUG);
+
return;
- } else {
+ }
+ else
+ {
this.task.log("Server is not running", Project.MSG_DEBUG);
}
@@ -155,17 +162,20 @@
thread.start();
+
// Wait a few ms more (just to make sure the servlet engine is
// ready to accept connections)
sleep(1000);
// Continuously try calling the test URL until it succeeds
- while (true) {
-
+ while (true)
+ {
this.task.log("Checking if server is up ...", Project.MSG_DEBUG);
- if (!isURLCallable()) {
+ if (!isURLCallable())
+ {
sleep(500);
+
continue;
}
@@ -174,6 +184,7 @@
break;
}
+
// Wait a few ms more (just to be sure !)
sleep(500);
@@ -190,9 +201,12 @@
*/
private void sleep(int theMs) throws BuildException
{
- try {
+ try
+ {
Thread.sleep(theMs);
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e)
+ {
throw new BuildException("Interruption during sleep", e);
}
}
@@ -205,19 +219,23 @@
{
boolean isURLCallable = false;
- try {
- HttpURLConnection connection =
+ try
+ {
+ HttpURLConnection connection =
(HttpURLConnection) this.testURL.openConnection();
+
connection.connect();
readFully(connection);
connection.disconnect();
isURLCallable = true;
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
// Log an information in debug mode
-
// Get stacktrace text
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(baos);
+
e.printStackTrace(writer);
writer.close();
@@ -236,20 +254,21 @@
* @exception IOException if an error happens during the read
*/
static void readFully(HttpURLConnection theConnection)
- throws IOException
+ throws IOException
{
// Only read if there is data to read ... The problem is that not
// all servers return a content-length header. If there is no header
// getContentLength() returns -1. It seems to work and it seems
// that all servers that return no content-length header also do
// not block on read() operations !
-
- if (theConnection.getContentLength() != 0) {
-
+ if (theConnection.getContentLength() != 0)
+ {
byte[] buf = new byte[256];
InputStream is = theConnection.getInputStream();
- while (-1 != is.read(buf)) {
+
+ while (-1 != is.read(buf))
+ {
}
}
}
@@ -262,6 +281,7 @@
{
// Call the Ant target using the "antcall" task.
CallTarget callee;
+
callee = (CallTarget) (this.task.getProject().createTask("antcall"));
callee.setOwningTarget(this.task.getOwningTarget());
callee.setTaskName(this.task.getTaskName());
@@ -282,9 +302,12 @@
*/
public void setTestURL(String theTestURL)
{
- try {
+ try
+ {
this.testURL = new URL(theTestURL);
- } catch (MalformedURLException e) {
+ }
+ catch (MalformedURLException e)
+ {
throw new BuildException("Bad URL [" + theTestURL + "]", e);
}
@@ -298,5 +321,4 @@
{
this.startTarget = theStartTarget;
}
-
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>