You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by rg...@apache.org on 2004/12/13 18:41:42 UTC

svn commit: r111726 - /forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java

Author: rgardler
Date: Mon Dec 13 09:41:41 2004
New Revision: 111726

URL: http://svn.apache.org/viewcvs?view=rev&rev=111726
Log:
some refactoring for more readable code
Modified:
   forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java

Modified: forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java
Url: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java?view=diff&rev=111726&p1=forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java&r1=111725&p2=forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java&r2=111726
==============================================================================
--- forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java	(original)
+++ forrest/trunk/tools/eclipse/src/org/apache/forrest/ForrestRunner.java	Mon Dec 13 09:41:41 2004
@@ -44,16 +44,26 @@
 	 */
 	private static final Logger logger = Logger.getLogger(ForrestRunner.class);
 
+
+	public static final String COMMAND_BUILD = "site";
+	public static final String COMMAND_START = "run";
 	public static final String COMMAND_STOP = "stop";
 	
+	private static final int UNKOWN_COMMAND = 0;
+	private static final int BUILD = 1;
+	private static final int START = 2;
+	private static final int STOP = 3;
+	
 	public static final int EXCEPTION_UNIDENTIFIED = 1001;
 	public static final int EXCEPTION_UNABLE_TO_STOP = 1010;
+	public static final int EXCEPTION_UNKOWN_COMMAND = 1020;
 	
 	private int stop_port = Integer.getInteger("STOP.PORT",8079).intValue();
 	private String _key = System.getProperty("STOP.KEY","mortbay");
 	
 	private static ForrestRunner INSTANCE;
-	protected String cmdString;
+	private int commandCode;
+	private String workingDir;
 	
 	/**
 	 * Create a Forrest runner to execute a specified command on a given directory
@@ -69,18 +79,15 @@
 		DOMConfigurator.configure(strLog4jConf);
 		
 		if (cmd.equals(COMMAND_STOP)) {
-			cmdString=COMMAND_STOP;
+			commandCode = STOP;
+		} else if (cmd.equals(COMMAND_START)){
+			commandCode = START;
+		} else if (cmd.equals(COMMAND_BUILD)) {
+			commandCode = BUILD;
 		} else {
-			String fhome = ForrestPlugin.getDefault().getPluginPreferences()
-			  .getString(ForrestPreferences.FORREST_HOME);
-			StringBuffer sb = new StringBuffer("-Dproject.home=");
-			sb.append(workingDir);
-			sb.append(" -Dbasedir=");
-			sb.append(fhome + File.separatorChar + "main");
-			sb.append(" ");
-			sb.append(cmd);
-			cmdString = sb.toString();
+			commandCode = UNKOWN_COMMAND;
 		}
+		this.workingDir = workingDir;
 		INSTANCE = this;
 	}
 	
@@ -91,12 +98,76 @@
 		if (logger.isDebugEnabled()) {
 			logger.debug("run(IProgressMonitor) - start");
 		}
-		
 		IStatus status;
+		String cmdString = null;
+		
+		if (commandCode == STOP) {
+	    	status = this.stop();
+		} else if (commandCode != UNKOWN_COMMAND){
+		    status = runAnt(monitor, getAntCommand());
+		} else {
+			status = new Status(Status.ERROR, null, ForrestRunner.EXCEPTION_UNKOWN_COMMAND, "Unkown Forrest Command", null);
+		}
+
+		if (logger.isDebugEnabled()) {
+			logger.debug("run(IProgressMonitor) - end");
+		}
+		return status;
+	}
+	
+	/**
+	 * @return a string that is passed to ANT as a command
+	 */
+	private String getAntCommand() {
+		if (logger.isDebugEnabled()) {
+			logger.debug("getAntCommand(int) - start");
+		}
+
+		String cmdString;
+		String fhome = ForrestPlugin.getDefault().getPluginPreferences()
+		  .getString(ForrestPreferences.FORREST_HOME);
+		StringBuffer sb = new StringBuffer("-Dproject.home=");
+		sb.append(workingDir);
+		sb.append(" -Dbasedir=");
+		sb.append(fhome + File.separatorChar + "main");
+		sb.append(" ");
+		
+		switch (commandCode) {
+			case START:
+				sb.append(COMMAND_START);
+				break;
+		    case STOP:
+		    	sb = null;
+				break;
+		    case BUILD:
+		    	sb.append(COMMAND_BUILD);
+		}
 		
-		if (cmdString.equals("COMMAND_STOP")) {
-			status = this.stop();
+		if (sb != null) {
+			cmdString = sb.toString();
 		} else {
+			cmdString = null;
+		}
+		
+		if (logger.isDebugEnabled()) {
+			logger.debug("getAntCommand(int) - end");
+		}
+		return cmdString;
+	}
+
+	/**
+	 * @param monitor
+	 * @param cmdString
+	 * @return
+	 */
+	private IStatus runAnt(IProgressMonitor monitor, String cmdString) {
+		if (logger.isDebugEnabled()) {
+			logger.debug("runAnt(IProgressMonitor, String) - start");
+		}
+
+		IStatus status = Status.OK_STATUS;
+		
+		if (cmdString != null) {
 			String fhome = ForrestPlugin.getDefault().getPluginPreferences()
 			  .getString(ForrestPreferences.FORREST_HOME);
 			AntRunner runner = new AntRunner();
@@ -104,9 +175,8 @@
 			try {
 				runner.setBuildFileLocation(antFile);
 				runner.setArguments(cmdString);
-				logger.info("run() - Running ANT with command string = " + cmdString);
+				logger.info("Running ANT with command string = " + cmdString);
 				runner.run(monitor);
-				status = Status.OK_STATUS;
 			} catch (CoreException e) {
 				logger.error("run(IProgressMonitor)", e);
 				status = new Status(Status.ERROR, null, ForrestRunner.EXCEPTION_UNIDENTIFIED, "Forrest Exception", null);
@@ -114,23 +184,9 @@
 		}
 
 		if (logger.isDebugEnabled()) {
-			logger.debug("run(IProgressMonitor) - end");
+			logger.debug("runAnt(IProgressMonitor, String) - end");
 		}
 		return status;
-	}
-	
-	/**
-	 * Start this version of Forrest.
-	 *
-	 */
-	public void start(){
-		if (logger.isDebugEnabled()) {
-			logger.debug("start() - start");
-		}
-
-		if (logger.isDebugEnabled()) {
-			logger.debug("start() - end");
-		}
 	}
 	
 	/**