Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 31f97c798525a6e316ba0a043de1a3014cf41c8b (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
/*******************************************************************************
 * Copyright (c) 2015 QNX Software Systems 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
 *******************************************************************************/
package org.eclipse.cdt.build.core.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.build.core.IToolChain;
import org.eclipse.cdt.build.core.IToolChainManager;
import org.eclipse.cdt.build.core.IToolChainProvider;
import org.eclipse.cdt.build.core.IToolChainType;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;

public class ToolChainManager implements IToolChainManager {

	private Map<String, IConfigurationElement> typeElements;
	private Map<String, IToolChainType> types;
	private Map<String, Map<String, IToolChain>> toolChains;

	private void init() {
		if (typeElements == null) {
			typeElements = new HashMap<>();
			types = new HashMap<>();

			// Load the types
			IExtensionRegistry registry = Platform.getExtensionRegistry();
			IExtensionPoint typesPoint = registry.getExtensionPoint(Activator.getId() + ".toolChainType"); //$NON-NLS-1$
			for (IConfigurationElement element : typesPoint.getConfigurationElements()) {
				String id = element.getAttribute("id"); //$NON-NLS-1$
				typeElements.put(id, element);
			}

			// Load the discovered toolchains
			toolChains = new HashMap<>();
			IExtensionPoint providersPoint = registry.getExtensionPoint(Activator.getId() + ".toolChainProvider"); //$NON-NLS-1$
			for (IConfigurationElement element : providersPoint.getConfigurationElements()) {
				// TODO check for enablement
				try {
					IToolChainProvider provider = (IToolChainProvider) element.createExecutableExtension("class"); //$NON-NLS-1$
					for (IToolChain toolChain : provider.getToolChains()) {
						String typeId = toolChain.getType().getId();
						Map<String, IToolChain> tcs = toolChains.get(typeId);
						if (tcs == null) {
							tcs = new HashMap<>();
							toolChains.put(typeId, tcs);
						}
						tcs.put(toolChain.getName(), toolChain);
					}
				} catch (CoreException e) {
					Activator.log(e);
				}
			}
		}
	}

	@Override
	public IToolChainType getToolChainType(String id) {
		init();
		IToolChainType type = types.get(id);
		if (type == null) {
			IConfigurationElement element = typeElements.get(id);
			if (element != null) {
				try {
					type = (IToolChainType) element.createExecutableExtension("class"); //$NON-NLS-1$
					types.put(id, type);
				} catch (CoreException e) {
					Activator.log(e);
				}
			}
		}
		return type;
	}

	@Override
	public IToolChain getToolChain(String typeId, String name) {
		init();
		Map<String, IToolChain> tcs = toolChains.get(typeId);
		return tcs != null ? tcs.get(name) : null;
	}

	@Override
	public Collection<IToolChain> getToolChainsSupporting(ILaunchTarget target) {
		init();

		List<IToolChain> supportingtcs = new ArrayList<>();
		for (Map<String, IToolChain> tcs : toolChains.values()) {
			for (IToolChain tc : tcs.values()) {
				if (tc.supports(target)) {
					supportingtcs.add(tc);
				}
			}
		}
		return supportingtcs;
	}

}

Back to the top