Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 316404 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ptp/rm/proxy/core/Controller.java (-15 / +50 lines)
Lines 13-22 Link Here
13
package org.eclipse.ptp.rm.proxy.core;
13
package org.eclipse.ptp.rm.proxy.core;
14
14
15
import java.io.BufferedInputStream;
15
import java.io.BufferedInputStream;
16
import java.io.BufferedReader;
16
import java.io.File;
17
import java.io.File;
17
import java.io.FileInputStream;
18
import java.io.FileInputStream;
18
import java.io.IOException;
19
import java.io.InputStream;
19
import java.io.InputStream;
20
import java.io.InputStreamReader;
20
import java.util.ArrayList;
21
import java.util.ArrayList;
21
import java.util.Arrays;
22
import java.util.Arrays;
22
import java.util.HashSet;
23
import java.util.HashSet;
Lines 24-29 Link Here
24
import java.util.List;
25
import java.util.List;
25
import java.util.Queue;
26
import java.util.Queue;
26
import java.util.Set;
27
import java.util.Set;
28
import java.util.concurrent.Callable;
29
import java.util.concurrent.ExecutorService;
30
import java.util.concurrent.Executors;
31
import java.util.concurrent.Future;
27
import java.util.regex.Pattern;
32
import java.util.regex.Pattern;
28
33
29
import org.eclipse.ptp.proxy.event.IProxyEvent;
34
import org.eclipse.ptp.proxy.event.IProxyEvent;
Lines 31-36 Link Here
31
import org.eclipse.ptp.rm.proxy.core.element.ElementManager;
36
import org.eclipse.ptp.rm.proxy.core.element.ElementManager;
32
import org.eclipse.ptp.rm.proxy.core.element.IElement;
37
import org.eclipse.ptp.rm.proxy.core.element.IElement;
33
import org.eclipse.ptp.rm.proxy.core.event.IEventFactory;
38
import org.eclipse.ptp.rm.proxy.core.event.IEventFactory;
39
import org.eclipse.ptp.rm.proxy.core.messages.Messages;
34
import org.eclipse.ptp.rm.proxy.core.parser.IParser;
40
import org.eclipse.ptp.rm.proxy.core.parser.IParser;
35
import org.eclipse.ptp.utils.core.RangeSet;
41
import org.eclipse.ptp.utils.core.RangeSet;
36
42
Lines 78-83 Link Here
78
84
79
	private final AttributeDefinition attrDef;
85
	private final AttributeDefinition attrDef;
80
86
87
	private static ExecutorService fPool = Executors.newCachedThreadPool();
88
81
	/**
89
	/**
82
	 * Instantiates a new controller.
90
	 * Instantiates a new controller.
83
	 * 
91
	 * 
Lines 153-180 Link Here
153
	 * @throws Execption
161
	 * @throws Execption
154
	 */
162
	 */
155
	public Set<IElement> parse() throws Exception {
163
	public Set<IElement> parse() throws Exception {
156
		InputStream is = null;
157
		if (debugFiles != null) {
164
		if (debugFiles != null) {
158
			String file = debugFiles.poll();
165
			String file = debugFiles.poll();
159
			is = readFile(file);
166
			InputStream is = new BufferedInputStream(new FileInputStream(new File(file)));
160
			debugFiles.add(file);
167
			debugFiles.add(file);
161
		} else {
168
			return parser.parse(attrDef, is);
162
			is = readProgramOutput(command);
163
		}
169
		}
164
170
165
		return parser.parse(attrDef, is);
171
		String[] args = command.split(" "); //$NON-NLS-1$
166
	}
172
		Process p = Runtime.getRuntime().exec(args);
173
		final InputStream is = new BufferedInputStream(p.getInputStream());
174
		final BufferedReader err_is = new BufferedReader(new InputStreamReader(p.getErrorStream()));
167
175
168
	private InputStream readFile(String path) throws IOException {
176
		Callable<Set<IElement>> parseThread = new Callable<Set<IElement>>() {
169
		return new BufferedInputStream(new FileInputStream(new File(path)));
177
			public Set<IElement> call() throws Exception {
170
	}
178
				Set<IElement> ret = null;
179
				ret = parser.parse(attrDef, is);
180
				BufferedReader out_is = new BufferedReader(new InputStreamReader(is));
181
				String out;
182
				while ((out = out_is.readLine()) != null)
183
					/* read any additional unparsed output */
184
					System.out.println("UNPARSED " + command + ": " + out); //$NON-NLS-1$ //$NON-NLS-2$
185
				out_is.close();
186
				return ret;
187
			}
188
		};
189
		Callable<Object> stderrThread = new Callable<Object>() {
190
			public Object call() throws Exception {
191
				String err;
192
				while ((err = err_is.readLine()) != null)
193
					/* read any std error */
194
					System.err.println(command + ": " + err); //$NON-NLS-1$
195
				err_is.close();
196
				return null;
197
			}
198
		};
171
199
172
	private InputStream readProgramOutput(String string) throws IOException {
200
		// To avoid blocking it is importing to read all of stderr and stdout
173
		String[] args = string.split(" "); //$NON-NLS-1$
201
		// while parsing and afterwards
174
		Process p = Runtime.getRuntime().exec(args);
202
		// This is why we need to do it in threads
203
		Future<Set<IElement>> future = fPool.submit(parseThread);
204
		fPool.submit(stderrThread);
205
206
		Set<IElement> ret = future.get();
207
		p.waitFor();
208
		if (p.exitValue() != 0) {
209
			throw new Exception(command + Messages.getString("Controller.0") + p.exitValue()); //$NON-NLS-1$
210
		}
175
211
176
		// read the standard output of the command
212
		return ret;
177
		return new BufferedInputStream(p.getInputStream());
178
	}
213
	}
179
214
180
	/**
215
	/**
(-)src/org/eclipse/ptp/rm/proxy/core/messages/Messages.java (+21 lines)
Added Link Here
1
package org.eclipse.ptp.rm.proxy.core.messages;
2
3
import java.util.MissingResourceException;
4
import java.util.ResourceBundle;
5
6
public class Messages {
7
	private static final String BUNDLE_NAME = "org.eclipse.ptp.rm.proxy.core.messages.messages"; //$NON-NLS-1$
8
9
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
10
11
	private Messages() {
12
	}
13
14
	public static String getString(String key) {
15
		try {
16
			return RESOURCE_BUNDLE.getString(key);
17
		} catch (MissingResourceException e) {
18
			return '!' + key + '!';
19
		}
20
	}
21
}
(-)src/org/eclipse/ptp/rm/proxy/core/messages/messages.properties (+1 lines)
Added Link Here
1
Controller.0=\ finished with exit code 
(-)src/org/eclipse/ptp/rm/proxy/core/parser/XMLReader.java (-1 lines)
Lines 149-155 Link Here
149
		Set<IElement> elementList = null;
149
		Set<IElement> elementList = null;
150
		NodeList xmlNodes = null;
150
		NodeList xmlNodes = null;
151
		xmlNodes = getXMLChildren(in);
151
		xmlNodes = getXMLChildren(in);
152
		in.close();
153
		elementList = new HashSet<IElement>(xmlNodes.getLength());
152
		elementList = new HashSet<IElement>(xmlNodes.getLength());
154
		for (int i = 0; i < xmlNodes.getLength(); i++) {
153
		for (int i = 0; i < xmlNodes.getLength(); i++) {
155
			Node node = xmlNodes.item(i);
154
			Node node = xmlNodes.item(i);

Return to bug 316404