Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 42ac20286323df97e98def1293bd26579dbfbbbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*******************************************************************************
 * Copyright (c) 2010, 2011 Broadcom Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * Alex Collins (Broadcom Corp.)
 *******************************************************************************/
package org.eclipse.cdt.internal.ui.buildconsole;

import java.io.IOException;

import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.core.IErrorMarkeredOutputStream;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

/**
 * Adapter that wraps a project console and the global console to allow builders
 * to send their build output to a single IConsole object
 */
class MultiBuildConsoleAdapter implements IConsole {

	private final IConsole fProjectConsole;
	private final IConsole fGlobalConsole;

	private static class BuildOutputStreamAdapter extends ConsoleOutputStream implements IErrorMarkeredOutputStream {
		private final BuildOutputStream one;
		private final BuildOutputStream two;

		public BuildOutputStreamAdapter(BuildOutputStream one, BuildOutputStream two) {
			this.one = one;
			this.two = two;
		}

		@Override
		public synchronized String readBuffer() {
			return one.readBuffer();
		}

		@Override
		public synchronized void write(int c) throws IOException {
			one.write(c);
			two.write(c);
		}

		@Override
		public synchronized void write(byte[] b, int off, int len) throws IOException {
			one.write(b, off, len);
			two.write(b, off, len);
		}

		@Override
		public synchronized void write(String msg) throws IOException {
			one.write(msg);
			two.write(msg);
		}

		@Override
		public void write(String s, ProblemMarkerInfo marker) throws IOException {
			one.write(s, marker);
			two.write(s, marker);
		}

		@Override
		public void flush() throws IOException {
			one.flush();
			two.flush();
		}

		@Override
		public void close() throws IOException {
			one.flush();
			two.flush();
			one.close();
			two.close();
		}

	}

	public MultiBuildConsoleAdapter(IConsole projectConsole, IConsole globalConsole) {
		fProjectConsole = projectConsole;
		fGlobalConsole = globalConsole;
	}

	@Override
	public void start(IProject project) {
		fProjectConsole.start(project);
	}

	@Override
	public ConsoleOutputStream getOutputStream() throws CoreException {
		return new BuildOutputStreamAdapter((BuildOutputStream) fProjectConsole.getOutputStream(),
				(BuildOutputStream) fGlobalConsole.getOutputStream());
	}

	@Override
	public ConsoleOutputStream getInfoStream() throws CoreException {
		return new BuildOutputStreamAdapter((BuildOutputStream) fProjectConsole.getInfoStream(),
				(BuildOutputStream) fGlobalConsole.getInfoStream());
	}

	@Override
	public ConsoleOutputStream getErrorStream() throws CoreException {
		return new BuildOutputStreamAdapter((BuildOutputStream) fProjectConsole.getErrorStream(),
				(BuildOutputStream) fGlobalConsole.getErrorStream());
	}

}

Back to the top