/**
 *  Copyright (c) 2015-2017 Angelo ZERR.
 *  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:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 *  
 */
package ts.eclipse.ide.angular2.internal.cli.terminal;

import ts.eclipse.ide.angular2.internal.cli.jobs.NgServeJob;
import ts.eclipse.ide.terminal.interpreter.AbstractCommandInterpreter;

/**
 * "ng serve" interpreter to open a WebBrowser when trace "NG Live Development
 * Server is running on http://localhost:4200. **" appears.
 *
 */
public class NgServeCommandInterpreter extends AbstractCommandInterpreter {

	private static final String SERVING_ON = "Server is running on ";

	public NgServeCommandInterpreter(String workingDir) {
		super(workingDir);
	}

	@Override
	public void execute(String newWorkingDir) {
		// Do nothing, the open of web browser is done when trace "Serving on
		// http://localhost:4200/"
		// is found.
	}

	@Override
	public void onTrace(String line) {
		int startIndex = line.indexOf(SERVING_ON);
		if (startIndex != -1) {
			// ** NG Live Development Server is running on http://localhost:4200. **
			startIndex += SERVING_ON.length();
			int endIndex = line.indexOf(".", startIndex);
			if (endIndex == -1) {
				endIndex = line.indexOf(" ", startIndex);
			}
			final String serverURL = line.substring(startIndex, endIndex != -1 ? endIndex : line.length())
					.trim();
			// Open a Web Browser with the given server URL
			new NgServeJob(serverURL).schedule();

		}
	}

}

@@ -863,47 +863,25 @@
 ing 
-SERVING_ON = %22Server is running on 
+HTTP = %22http
 %22;%0D%0A
+%09
 %0D%0A%09p
@@ -1200,80 +1200,95 @@
 %0D%0A%09%09
-int startIndex = line.indexOf(SERVING_ON);%0D%0A%09%09if (startIndex != -1) %7B
+// track %0D%0A%09%09// ** NG Live Development Server is running on http://localhost:4200. **
 %0D%0A
-%09
 %09%09//
@@ -1317,35 +1317,37 @@
 t Server is 
-run
+liste
 ning on 
 http://local
@@ -1326,32 +1326,69 @@
 is listening on 
+localhost:4200, open your browser on 
 http://localhost
@@ -1396,17 +1396,19 @@
 4200
-.
  **%0D%0A%09%09
-%09
+int 
 star
@@ -1418,31 +1418,59 @@
 dex 
-+
 = 
-SERVING_ON.length();
+line.indexOf(HTTP);%0D%0A%09%09if (startIndex != -1) %7B%09%09%09
 %0D%0A%09%09
@@ -1762,16 +1762,16 @@
 er URL%0D%0A
+
 %09%09%09new N
@@ -1804,18 +1804,16 @@
 ule();%0D%0A
-%0D%0A
 %09%09%7D%0D%0A%09%7D%0D

Fix ng serve which opens browser.