Merge "Bug 480021: EASE scripts for working with Jython and Eclipse ICE"
diff --git a/JavaScript Snippets/Launch Module Examples/01 simple launch.js b/JavaScript Snippets/Launch Module Examples/01 simple launch.js
new file mode 100644
index 0000000..62e2c1e
--- /dev/null
+++ b/JavaScript Snippets/Launch Module Examples/01 simple launch.js
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jonah Graham and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: Jonah Graham - initial API and implementation
+ * 
+ * name			: Launch Module Example 1
+ * description	: In this first example, we simply launch the Client in Debug mode.
+ ******************************************************************************/
+
+// load the Launch module, this populates the namespace with all the methods defined in the Launch module.
+loadModule("/System/Launch")
+
+// launch the existing launch configuration “Client” in debug mode.
+launch("Client", "debug")
diff --git a/JavaScript Snippets/Launch Module Examples/02 launch group.js b/JavaScript Snippets/Launch Module Examples/02 launch group.js
new file mode 100644
index 0000000..62e5e66
--- /dev/null
+++ b/JavaScript Snippets/Launch Module Examples/02 launch group.js
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jonah Graham and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: Jonah Graham - initial API and implementation
+ * 
+ * name			: Launch Module Example 2
+ * description	: In this example, we prepare our environment with the Prepare” 
+ *                configuration, then launch the “Server” and “Client” configurations.
+ ******************************************************************************/
+
+// load the Launch module
+loadModule("/System/Launch")
+
+// launch the Prepare configuration
+prepare = launch("Prepare")
+// Busy-wait until the Prepare launch has terminated
+while (!prepare.isTerminated()) {
+	java.lang.Thread.sleep(1)
+}
+
+// launch the server
+launch("Server")
+// Wait 3 seconds for the server to be ready
+java.lang.Thread.sleep(3000)
+
+// launch the client in Debug mode
+launch("Client", "debug")
diff --git a/JavaScript Snippets/Launch Module Examples/03 terminate server when client terminates.js b/JavaScript Snippets/Launch Module Examples/03 terminate server when client terminates.js
new file mode 100644
index 0000000..06bdd78
--- /dev/null
+++ b/JavaScript Snippets/Launch Module Examples/03 terminate server when client terminates.js
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jonah Graham and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: Jonah Graham - initial API and implementation
+ * 
+ * name			: Launch Module Example 3
+ * description	: Example 1 and 2 are a promising start, but do not
+ *                yet add any new functionality to Eclipse. So what
+ *                do you do if you want the server to stop automatically
+ *                when you finish debugging your client. Well that is
+ *                really easy now, just monitor the client launch and
+ *                terminate the server.
+ ******************************************************************************/
+
+// load the Launch module
+loadModule("/System/Launch")
+
+// launch the Prepare configuration
+prepare = launch("Prepare")
+// Busy-wait until the Prepare launch has terminated
+while (!prepare.isTerminated()) {
+	java.lang.Thread.sleep(1)
+}
+
+// launch the Server, but keep a handle of the ILaunch
+server = launch("Server")
+// Wait 3 seconds for the server to be ready
+java.lang.Thread.sleep(3000)
+
+// launch the Client
+client = launch("Client", "debug")
+// Busy-wait until the Client debug session launch has terminated
+while (!client.isTerminated()) {
+	java.lang.Thread.sleep(1)
+}
+// terminate the server
+server.terminate()
diff --git a/JavaScript Snippets/Launch Module Examples/README.md b/JavaScript Snippets/Launch Module Examples/README.md
new file mode 100644
index 0000000..222feb4
--- /dev/null
+++ b/JavaScript Snippets/Launch Module Examples/README.md
@@ -0,0 +1,18 @@
+# The Launch Module Examples
+
+For these examples you need to create three launch configurations for your tools tools
+(the name of the launch configuration is the quoted string in the list):
+
+* “Prepare” – An External Tools configuration which prepares my test environment
+* “Server” – A PyDev supplied, Python Run configuration to launch my Python server
+* “Client” – A Java configuration to launch my Java client
+
+## Running The Examples
+
+1. Create three launch configurations named as above
+2. Right-click on the desired script (e.g. 01 simple launch.js)
+3. Choose Run As –> EASE Script
+
+Alternatively paste the lines from the examples into the Rhino Script Shell
+console. You get auto-completion of the names of the launch configurations
+and the launch modes too!
\ No newline at end of file