forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r125498 - forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job
Date Tue, 18 Jan 2005 13:00:38 GMT
Author: rgardler
Date: Tue Jan 18 05:00:36 2005
New Revision: 125498

URL: http://svn.apache.org/viewcvs?view=rev&rev=125498
Log:
refactor server start technique, now able to shutdown server from GUI
Added:
   forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/AntBuildListener.java  
(contents, props changed)
Modified:
   forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java
   forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java
   forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java
   forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java

Added: forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/AntBuildListener.java
Url: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/AntBuildListener.java?view=auto&rev=125498
==============================================================================
--- (empty file)
+++ forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/AntBuildListener.java	Tue
Jan 18 05:00:36 2005
@@ -0,0 +1,74 @@
+package org.apache.forrest.eclipse.job;
+
+import org.apache.log4j.Logger;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildListener;
+
+/**
+ * A listener for Ant Builds, all events are logged to the standard logger.
+ */
+public class AntBuildListener implements BuildListener{
+	/**
+	 * Logger for this class
+	 */
+	private static final Logger logger = Logger
+			.getLogger(AntBuildListener.class);
+
+	/**
+	 * 
+	 */
+	public AntBuildListener() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
+	 */
+	public void buildFinished(BuildEvent event) {
+		logger.debug("Ant Finished Build: " + event.getMessage());
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
+	 */
+	public void buildStarted(BuildEvent event) {
+		logger.debug("Ant Started Build: " + event.getMessage());
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
+	 */
+	public void messageLogged(BuildEvent event) {
+		logger.debug("Anr Message: " + event.getMessage());
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
+	 */
+	public void targetFinished(BuildEvent event) {
+		logger.debug("Ant Target Finished: " + event.getMessage());
+	}
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
+	 */
+	public void targetStarted(BuildEvent event) {
+		logger.debug("Ant Target Started: " + event.getMessage());
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
+	 */
+	public void taskFinished(BuildEvent event) {
+		logger.debug("Ant Task Finished: " + event.getMessage());
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
+	 */
+	public void taskStarted(BuildEvent event) {
+		logger.debug("Ant Task Started: " + event.getMessage());
+
+	}
+}

Modified: forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java
Url: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java?view=diff&rev=125498&p1=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java&r1=125497&p2=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java&r2=125498
==============================================================================
--- forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java	(original)
+++ forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestJob.java	Tue Jan
18 05:00:36 2005
@@ -7,7 +7,14 @@
 package org.apache.forrest.eclipse.job;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.ListIterator;
+import java.util.Vector;
 
 import org.apache.forrest.eclipse.ForrestPlugin;
 import org.apache.forrest.eclipse.preference.ForrestPreferences;
@@ -17,60 +24,72 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 
 /**
  * @author Ross Gardler
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ * 
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Style - Code Templates
  */
 public abstract class ForrestJob extends Job {
 	private static final String CONCURRENT_ANT_BUILDS = "Concurrent Ant builds are possible
if you specify to build in a separate JRE.";
+
 	private static final String VALIDATION_ERROR_MESSAGE = "Could not validate document";
+
 	/**
 	 * Logger for this class
 	 */
 	protected static final Logger logger = Logger.getLogger(ForrestJob.class);
 
 	public static final int EXCEPTION_UNIDENTIFIED = 1001;
+
 	public static final int EXCEPTION_VALIDATION = 1010;
+
 	public static final int EXCEPTION_ANT_RUNNING = 1020;
 
 	protected String workingDir;
-	
+
 	/**
 	 * @param name
 	 */
 	public ForrestJob(String name) {
 		super(name);
-		
+
 		ForrestPlugin plugin = ForrestPlugin.getDefault();
 		URL urlPluginDir = plugin.getBundle().getEntry("/");
+		// FIXME: Make this path relative to the project 
 		String strLog4jConf = "D:\\projects\\burrokeet\\forrestplugin\\conf\\log4j.xml";
 		DOMConfigurator.configure(strLog4jConf);
 	}
 
 	/**
-	 * Run ant as a normal executable, that is wait for completion and
-	 * retuen a status.
-	 * @param monitor - the monitor to report execution progress
-	 * @param cmdString  - the command string to pass to ant
+	 * Run ant as a normal executable, that is wait for completion and retuen a
+	 * status.
+	 * 
+	 * @param monitor -
+	 *            the monitor to report execution progress
+	 * @param cmdString -
+	 *            the command string to pass to ant
 	 * @return Status of the execution.
 	 */
 	protected 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);
-			String antFile = fhome + File.separatorChar + "main" + File.separatorChar + "forrest.build.xml";
+					.getString(ForrestPreferences.FORREST_HOME);
+			String antFile = fhome + File.separatorChar + "main"
+					+ File.separatorChar + "forrest.build.xml";
 			AntRunner runner = new AntRunner();
+			runner.setCustomClasspath(getAntClasspath());
+			runner.addBuildListener(AntBuildListener.class.getName());
 			try {
 				runner.setBuildFileLocation(antFile);
 				runner.setArguments(cmdString);
@@ -80,24 +99,89 @@
 				String userMsg;
 				String errMsg = e.getMessage();
 				if (errMsg.indexOf(VALIDATION_ERROR_MESSAGE) > 0) {
-					String file = errMsg.substring(errMsg.indexOf(VALIDATION_ERROR_MESSAGE));
+					String file = errMsg.substring(errMsg
+							.indexOf(VALIDATION_ERROR_MESSAGE));
 					userMsg = "Invalid XML Document: " + file;
-					status = new Status(Status.ERROR, ForrestPlugin.ID, ForrestRunner.EXCEPTION_VALIDATION,
userMsg, e);
+					status = new Status(Status.ERROR, ForrestPlugin.ID,
+							ForrestRunner.EXCEPTION_VALIDATION, userMsg, e);
 				} else if (errMsg.endsWith(CONCURRENT_ANT_BUILDS)) {
 					userMsg = "Can only run one Site operation at a time";
-					status = new Status(Status.ERROR, ForrestPlugin.ID, EXCEPTION_ANT_RUNNING, userMsg,
e);
+					status = new Status(Status.ERROR, ForrestPlugin.ID,
+							EXCEPTION_ANT_RUNNING, userMsg, e);
 				} else {
 					userMsg = "Forrest Server Exception";
-					status = new Status(Status.ERROR, ForrestPlugin.ID, ForrestRunner.EXCEPTION_UNIDENTIFIED,
userMsg, e);
+					status = new Status(Status.ERROR, ForrestPlugin.ID,
+							ForrestRunner.EXCEPTION_UNIDENTIFIED, userMsg, e);
 				}
 				logger.error("run(IProgressMonitor) - " + userMsg, e);
 			}
 		}
-	
+
 		if (logger.isDebugEnabled()) {
 			logger.debug("runAnt(IProgressMonitor, String) - end");
 		}
 		return status;
 	}
+	
+	private URL[] getAntClasspath() {
+		Vector vctURLs = new Vector();
+		String forrestHome = ForrestManager.FORREST_HOME;
+
+		try {
+			// FIXME: cache the classpath
+            // add Forrest ANT jars
+			vctURLs.add(new File(ForrestManager.FORREST_ANTTASK_CLASSES).toURL());
+			ArrayList fileList = ForrestManager.getLibFiles(ForrestManager.FORREST_ANT);
+			ListIterator itr = fileList.listIterator();
+			while (itr.hasNext()) {
+				vctURLs.add(((File)itr.next()).toURL());
+			}
+			
+			// Add the path to the Plugin classes
+			String className = this.getClass().getName();
+			if (!className.startsWith("/")) {
+				className = "/" + className;
+			}
+			className = className.replace('.', '/');			
+			String classLocation = this.getClass().getClassLoader().getResource(className + ".class").toExternalForm();
+			URL classURL = Platform.resolve(new URL(classLocation.substring(0, classLocation.indexOf(className))));
+			vctURLs.add(classURL);
+			
+			// Add Plugin jars
+			URL installURL = Platform.getBundle(ForrestPlugin.ID).getEntry("/");
+			String location = Platform.resolve(installURL).getFile();
+			fileList = ForrestManager.getLibFiles(location);
+			itr = fileList.listIterator();
+			while (itr.hasNext()) {
+				vctURLs.add(((File)itr.next()).toURL());
+			}
+			
+			// add Forrest jars
+			File[] files = ForrestManager.getClasspathFiles();
+			URL[] urls = new URL[files.length];
+			for (int i = 0; i < files.length; i++) {
+				urls[i] = files[i].toURL();
+			}
+			vctURLs.addAll(Arrays.asList(urls));
+		} catch (FileNotFoundException e) {
+			logger.error("getClasspathURLS()", e);
+
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (MalformedURLException e) {
+			logger.error("getClasspathURLS()", e);
+
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (IOException e) {
+			logger.error("getClasspathURLS(), cannot resolve URL", e);
+			
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 
-}
+		URL[] urls = new URL[vctURLs.size()];
+		URL[] returnURLArray = (URL[]) vctURLs.toArray(urls);
+		return returnURLArray;
+	}
+}
\ No newline at end of file

Modified: forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java
Url: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java?view=diff&rev=125498&p1=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java&r1=125497&p2=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java&r2=125498
==============================================================================
--- forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java	(original)
+++ forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestManager.java	Tue
Jan 18 05:00:36 2005
@@ -15,8 +15,24 @@
  */
 package org.apache.forrest.eclipse.job;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.forrest.eclipse.ForrestPlugin;
+import org.apache.forrest.eclipse.preference.ForrestPreferences;
 import org.apache.log4j.Logger;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.LoadProperties;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
 
 /**
  * Manages instances of Forrest that are running on the local server.
@@ -28,40 +44,119 @@
 	private static final Logger logger = Logger.getLogger(ForrestManager.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;
-	
+
 	private static final ForrestManager INSTANCE = new ForrestManager();
+
+	// FIXME: dir configuration should be in preferences and should be set by
+	// reading forrest.properties
+
+	public static final String FORREST_HOME = ForrestPlugin.getDefault()
+			.getPluginPreferences().getString(ForrestPreferences.FORREST_HOME);
+	
+	public static final String FORREST_CORE_LIB = FORREST_HOME
+			+ File.separator + "lib" + File.separator + "core" + File.separator;
+
+	public static final String FORREST_ENDORSED_LIB = FORREST_HOME
+			+ File.separator + "lib" + File.separator + "endorsed"
+			+ File.separator;
+
+	public static final String FORREST_OPTIONAL_LIB = FORREST_HOME
+			+ File.separator + "lib" + File.separator + "optional"
+			+ File.separator;
+
+	public static final String JETTY_LIB = FORREST_HOME
+			+ File.separator + "tools" + File.separator + "jetty"
+			+ File.separator;
+	
+	public static final String FORREST_CORE_WEBAPP = FORREST_HOME
+			+ File.separatorChar + "main" + File.separatorChar + "webapp";
+	
+	public static final String FORREST_JAR = FORREST_HOME
+	+ File.separatorChar + "build" + File.separatorChar + "xml-forrest.jar";
+
+	public static final String FORREST_CLASSES = FORREST_CORE_WEBAPP
+			+ File.separator + "WEB-INF" + File.separator + "classes" + File.separator;
+
+	public static final String FORREST_LIB = FORREST_HOME
+			+ File.separator + "build" + File.separator + "xml-forrest.jar";
+
+	public static final String FORREST_ANT = FORREST_HOME
+			+ File.separator + "tools" + File.separator + "ant" + File.separator;
+	
+	public static final String FORREST_ANTTASK_CLASSES = FORREST_HOME
+			+ File.separator + "tools" + File.separator + "anttasks" + File.separator;
+
+	private static final String FORREST_DEFAULT_PROPERTIES_FILE = FORREST_CORE_WEBAPP
+	+ File.separatorChar + "default-forrest.properties";
+	
+	private static ILaunch serverLaunch;
 	
 	/**
-	 * Create a manager, this is not intended to be called from your code.
-	 * Use Manager.getInstance() instead. 
+	 * Create a manager, this is not intended to be called from your code. Use
+	 * Manager.getInstance() instead.
 	 */
 	private ForrestManager() {
 		super();
-		// TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * Get the properties for a working directory
+	 * @param workingDir the working dir of the project
+	 * @return the properties for this project
+	 * @throws IOException if unable to read either the defaults file or the project file
+	 * @TODO Cache the project properties file
+	 * @refactor Move project creation code to own method
+	 */
+	public Hashtable getProperties(String workingDir) throws IOException {
+		// TODO: keep a record of the projects created, this is how we will cache the properties
+		Project project = new Project();
+		project.setName(workingDir);
+		
+		LoadProperties props = new LoadProperties();
+		props.setProject(project);
+		
+		project.setProperty("project.home", workingDir);
+		
+		props.setSrcFile(new File(workingDir + File.separatorChar + "forrest.properties"));
+		props.execute();
+		
+		props.setSrcFile(new File(FORREST_DEFAULT_PROPERTIES_FILE));
+		props.execute();
+		
+		return project.getProperties();
 	}
 	
+
 	public static ForrestManager getInstance() {
 		return ForrestManager.INSTANCE;
 	}
-	
+
 	/**
-	 * Create a Forrest Job. 
-	 * @param workingDir - the directory on which the job is to work
-	 * @param cmd - the command the job is to carry out
+	 * Create a Forrest Job.
+	 * 
+	 * @param workingDir -
+	 *            the directory on which the job is to work
+	 * @param cmd -
+	 *            the command the job is to carry out
 	 * @return
 	 */
 	public Job getForrestJob(String workingDir, String cmd) {
 		Job theJob;
 		if (cmd.equals(COMMAND_STOP)) {
 			theJob = new ForrestStopper(workingDir);
-		} else if (cmd.equals(COMMAND_START)){
+		} else if (cmd.equals(COMMAND_START)) {
 			theJob = new ForrestRunner(workingDir);
 		} else if (cmd.equals(COMMAND_BUILD)) {
 			theJob = new ForrestBuilder(workingDir);
@@ -71,4 +166,89 @@
 		return theJob;
 	}
 
-}
+	/**
+	 * Get an array of Files to be placed in the
+	 * classpath for Forrest.
+	 * 
+	 * @return an array of Files
+	 */
+	protected static File[] getClasspathFiles() {
+		Vector vctFiles = new Vector();
+
+		try {
+			// FIXME: cache the classpath
+			// add Forrest classes
+			vctFiles.add(new File(FORREST_CLASSES));
+			vctFiles.add(new File(FORREST_JAR));
+			// add core libs
+			vctFiles.addAll(getLibFiles(FORREST_CORE_LIB));
+			//			 add endorsed libs
+			vctFiles.addAll(getLibFiles(FORREST_ENDORSED_LIB));
+			//			 add optional libs
+			vctFiles.addAll(getLibFiles(FORREST_OPTIONAL_LIB));
+			//			 add jetty libs
+			vctFiles.addAll(getLibFiles(JETTY_LIB));
+		} catch (FileNotFoundException e) {
+			logger.error("getClasspathFiles()", e);
+
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		File[] files = new File[vctFiles.size()];
+		File[] returnFileArray = (File[]) vctFiles.toArray(files);
+		return returnFileArray;
+	}
+
+	/**
+	 * Return an array of URLs that point to lib files.
+	 * 
+	 * @param dir -
+	 *            directory in which to look for libs
+	 * @return ArrayList of URLs
+	 * @throws FileNotFoundException -
+	 *             if the directory doesn't exist
+	 */
+	static public ArrayList getLibFiles(String dir) throws FileNotFoundException {
+		File directory = new File(dir);
+		ArrayList result = new ArrayList();
+		List dirs = Arrays.asList(directory.listFiles());
+		Iterator filesIter = dirs.iterator();
+		File file = null;
+
+		while (filesIter.hasNext()) {
+			file = (File) filesIter.next();
+
+			if (file.isDirectory()) {
+				List deeperList = getLibFiles(file.toString());
+				result.addAll(deeperList);
+			} else if (file.toString().endsWith(".jar")
+					|| file.toString().endsWith(".zip")) {
+				result.add(file);
+			}
+		}
+		
+		return result;
+	}
+
+	/**
+	 * Stop the server for the given project
+	 * 
+	 * @param projectDir
+	 * @throws InterruptedException
+	 * @throws DebugException
+	 */
+	public static void stopServer(String projectDir)
+			throws DebugException {
+		serverLaunch.terminate();
+	}
+
+	/**
+	 * Set the server launch.
+	 * @param launch - the launch
+	 */
+	public static void setServerLaunch(ILaunch launch) {
+		serverLaunch = launch;
+	}
+	
+}
\ No newline at end of file

Modified: forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java
Url: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java?view=diff&rev=125498&p1=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java&r1=125497&p2=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java&r2=125498
==============================================================================
--- forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java	(original)
+++ forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestRunner.java	Tue
Jan 18 05:00:36 2005
@@ -16,28 +16,44 @@
 package org.apache.forrest.eclipse.job;
 
 import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
 
 import org.apache.forrest.eclipse.ForrestPlugin;
 import org.apache.forrest.eclipse.preference.ForrestPreferences;
 import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
 
 
 /**
- * Run a version of FOrrest
+ * Run a version of Forrest
  */
-public class ForrestRunner extends ForrestJob  {
+public class ForrestRunner extends ForrestJob implements IJavaLaunchConfigurationConstants{
 	/**
 	 * Logger for this class
 	 */
 	protected static final Logger logger = Logger.getLogger(ForrestRunner.class);
 	
 	private static final int EXCEPTION_UNABLE_TO_START = 2010;
-	private static final int EXCEPTION_UNABLE_TO_STOP = 2020;
 	
 	/**
-	 * Create a Forrest runner that will run a JEtty server on a given directory
+	 * Create a Forrest runner that will run a Jetty server on a given directory
 	 * @param workingDir - the working directory for the command
 	 */
 	protected ForrestRunner(String workingDir) {
@@ -46,7 +62,7 @@
 		this.workingDir = workingDir;
 	}
 	
-	/* (non-Javadoc)
+	/* Run the Forrest server in a separate thread and return that thread to the Forrest manager.
 	 * @see java.lang.Runnable#run()
 	 */
 	public IStatus run(IProgressMonitor monitor) {
@@ -54,7 +70,8 @@
 			logger.debug("run(IProgressMonitor) - start");
 		}
 		
-		IStatus status = null;
+		monitor.subTask("Initialising project");
+		IStatus status = Status.OK_STATUS;
 		String fhome = ForrestPlugin.getDefault().getPluginPreferences()
 		  .getString(ForrestPreferences.FORREST_HOME);
 		StringBuffer sb = new StringBuffer("-Dproject.home=");
@@ -62,9 +79,87 @@
 		sb.append(" -Dbasedir=");
 		sb.append(fhome + File.separatorChar + "main");
 		sb.append(" ");
-		sb.append("run");
-		
-		status = runAnt(monitor, sb.toString());    
+		sb.append("init");		
+		status = runAnt(monitor, sb.toString());
+			
+		monitor.subTask("Starting Server");
+		if(status.isOK()) {
+			ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+			ILaunchConfigurationType type =
+			      manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
+			ILaunchConfiguration[] configurations;
+			ILaunchConfigurationWorkingCopy workingCopy;
+			try {
+				configurations = manager.getLaunchConfigurations(type);
+				for (int i = 0; i < configurations.length; i++) {
+			      ILaunchConfiguration configuration = configurations[i];
+			      if (configuration.getName().equals("Start Jetty")) {
+			         configuration.delete();
+			         break;
+			      }
+			   }
+			   workingCopy = type.newInstance(null, "Start Jetty");
+			   workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME,
+	              "org.mortbay.jetty.Server");
+			   // TODO: allow project specific jettyconf.xml
+			   String args = ForrestManager.FORREST_CORE_WEBAPP + File.separatorChar + "jettyconf.xml";
+			   workingCopy.setAttribute(ATTR_PROGRAM_ARGUMENTS, args);
+			   
+			   List classpath = new ArrayList();
+			   
+			   File[] files = ForrestManager.getClasspathFiles();
+			   IPath classpathEntryPath;
+			   IRuntimeClasspathEntry classpathEntry;
+			   for (int i = 0; i < files.length; i++) {
+				   classpathEntryPath = new Path(files[i].getAbsolutePath());
+				   classpathEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(classpathEntryPath);
+				   classpathEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
+				   classpath.add(classpathEntry.getMemento());
+			   }
+			   
+			   IPath systemLibsPath = new Path(JavaRuntime.JRE_CONTAINER);
+			   IRuntimeClasspathEntry systemLibsEntry =
+			      JavaRuntime.newRuntimeContainerClasspathEntry(systemLibsPath,
+			         IRuntimeClasspathEntry.STANDARD_CLASSES);
+			   classpath.add(systemLibsEntry.getMemento());
+			   
+			   workingCopy.setAttribute(ATTR_CLASSPATH, classpath);
+			   workingCopy.setAttribute(ATTR_DEFAULT_CLASSPATH, false);
+			   
+			   ForrestManager forrestManager = ForrestManager.getInstance();
+			   Hashtable props = forrestManager.getProperties(workingDir);
+			   
+			   String propName;
+			   String propValue;
+			   StringBuffer sbVars = new StringBuffer();
+			   for (Enumeration e = props.keys() ; e.hasMoreElements() ;) {
+		         propName = (String)e.nextElement();
+		         propValue = (String)props.get(propName);
+			   	 sbVars.append("-D");
+			   	 sbVars.append(propName);
+			   	 sbVars.append("=");
+			   	 sbVars.append(propValue);
+			   	 sbVars.append(" ");
+		         if (logger.isInfoEnabled()) {
+					logger.info("Project property  : " + propName + " = " + propValue);
+				 } 
+		       }
+			   
+			   String strEndorsedLibs = "-Djava.endorsed.dirs=\"" + ForrestManager.FORREST_ENDORSED_LIB
+ "\"";
+			   workingCopy.setAttribute(ATTR_VM_ARGUMENTS,
+			        sbVars.toString() + strEndorsedLibs);
+			   
+			   workingCopy.setAttribute(ATTR_WORKING_DIRECTORY, ForrestManager.FORREST_CORE_WEBAPP);
+			   
+			   ILaunchConfiguration jettyConfig = workingCopy.doSave();
+			   //DebugUITools.launch(configuration, ILaunchManager.RUN_MODE);
+			   ForrestManager.setServerLaunch( jettyConfig.launch(ILaunchManager.RUN_MODE, monitor));
+			} catch (CoreException e) {
+				logger.error("run(IProgressMonitor)", e);
+			} catch (IOException e) {
+				logger.error("run(IProgressMonitor)", e);
+			}
+		}
 		
 		if (logger.isDebugEnabled()) {
 			logger.debug("run(IProgressMonitor) - end");

Modified: forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java
Url: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java?view=diff&rev=125498&p1=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java&r1=125497&p2=forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java&r2=125498
==============================================================================
--- forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java	(original)
+++ forrest/trunk/tools/eclipse/src/org/apache/forrest/eclipse/job/ForrestStopper.java	Tue
Jan 18 05:00:36 2005
@@ -15,9 +15,12 @@
  */
 package org.apache.forrest.eclipse.job;
 
+import org.apache.forrest.eclipse.ForrestPlugin;
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
 
 
 /**
@@ -29,6 +32,8 @@
 	 */
 	protected static final Logger logger = Logger.getLogger(ForrestStopper.class);
 	
+	private static final int EXCEPTION_UNABLE_TO_STOP = 3010;
+	
 	/**
 	 * Create a Forrest runner that will run a JEtty server on a given directory
 	 * @param workingDir - the working directory for the command
@@ -49,8 +54,15 @@
 		
 		IStatus status = null;
 
-		logger.warn("run() - Forrest server not stopped", null);
-	
+		try {
+			ForrestManager.stopServer(workingDir);
+			logger.info("run() - Forrest server stopped");
+			status = Status.OK_STATUS;
+		} catch (DebugException e) {
+			logger.error("run(IProgressMonitor)", e);
+			status = new Status(Status.ERROR, ForrestPlugin.ID, ForrestStopper.EXCEPTION_UNABLE_TO_STOP,
"Unable to stop Forrest Server", e);
+		}
+		
 		if (logger.isDebugEnabled()) {
 			logger.debug("run(IProgressMonitor) - end");
 		}

Mime
View raw message