1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

Implement ordering of toolchains.

Introduce toolchain types independent of providers.

Change-Id: I2cf3145920fcf4e7132468b6e653d7ea3e211127
This commit is contained in:
Doug Schaefer 2017-11-06 22:39:52 -05:00
parent 9a9e80e115
commit 76e1842644
15 changed files with 501 additions and 342 deletions

View file

@ -15,6 +15,14 @@
class="org.eclipse.cdt.build.gcc.core.GCCUserToolChainProvider"
id="org.eclipse.cdt.build.gcc.core.provider.user">
</provider>
<type
id="org.eclipse.cdt.build.gcc"
name="GCC">
</type>
<type
id="org.eclipse.cdt.build.clang"
name="clang">
</type>
</extension>
</plugin>

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2015, 2017 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.gcc.core;
import java.nio.file.Path;
import org.eclipse.cdt.core.build.IToolChainProvider;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
/**
* The Clang toolchain. There's little different from the GCC toolchain other
* than the toolchain type and name.
*
* @author dschaefer
*
*/
public class ClangToolChain extends GCCToolChain {
private static final String TYPE_ID = "org.eclipse.cdt.build.clang"; //$NON-NLS-1$
public ClangToolChain(IToolChainProvider provider, Path pathToToolChain, String arch,
IEnvironmentVariable[] envVars) {
super(provider, pathToToolChain, arch, envVars);
}
@Override
public String getTypeId() {
return TYPE_ID;
}
}

View file

@ -51,6 +51,8 @@ import org.eclipse.core.runtime.PlatformObject;
*/
public class GCCToolChain extends PlatformObject implements IToolChain {
public static final String TYPE_ID = "org.eclipse.cdt.build.gcc"; //$NON-NLS-1$
private final IToolChainProvider provider;
private final String id;
private final Path path;
@ -144,6 +146,11 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
this.envVars = envVars;
}
@Override
public String getTypeId() {
return TYPE_ID;
}
public Path getPath() {
return path;
}
@ -165,21 +172,20 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
@Override
public String getName() {
StringBuilder name = new StringBuilder("GCC"); //$NON-NLS-1$
StringBuilder name = new StringBuilder(); // $NON-NLS-1$
String os = getProperty(ATTR_OS);
if (os != null) {
name.append(' ');
name.append(os);
name.append(' ');
}
String arch = getProperty(ATTR_ARCH);
if (arch != null) {
name.append(' ');
name.append(arch);
name.append(' ');
}
if (path != null) {
name.append(' ');
name.append(path.toString());
}

View file

@ -15,7 +15,6 @@ import java.io.Writer;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -201,16 +200,6 @@ public class GCCUserToolChainProvider implements IUserToolChainProvider {
manager.removeToolChain(toolChain);
}
@Override
public IToolChain getToolChain(String id) throws CoreException {
Collection<IToolChain> tcs = manager.getToolChains(PROVIDER_ID, id);
if (tcs.isEmpty()) {
return null;
} else {
return tcs.iterator().next();
}
}
private void saveJsonFile() throws IOException {
try (Writer writer = new FileWriter(getJsonFile())) {
writer.write(new Gson().toJson(toolChains));

View file

@ -1,74 +1,77 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.core" version="2">
<resource path="src/org/eclipse/cdt/core/build/ICBuildConfiguration.java" type="org.eclipse.cdt.core.build.ICBuildConfiguration">
<filter id="403767336">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="TOOLCHAIN_ID"/>
</message_arguments>
</filter>
<filter id="403767336">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="TOOLCHAIN_TYPE"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="getLaunchMode()"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="getProperty(String)"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="removeProperty(String)"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="setProperty(String, String)"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/cdt/core/build/ICBuildConfigurationProvider.java" type="org.eclipse.cdt.core.build.ICBuildConfigurationProvider">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfigurationProvider"/>
<message_argument value="getSupportedToolchains(Collection&lt;IToolChain&gt;)"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/cdt/core/build/IToolChainProvider.java" type="org.eclipse.cdt.core.build.IToolChainProvider">
<filter comment="This interface is still pretty new. Assuming low risk." id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChainProvider"/>
<message_argument value="addToolChain(IToolChain)"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChainProvider"/>
<message_argument value="getToolChain(String)"/>
</message_arguments>
</filter>
<filter comment="Newish interface. Assuming low risk." id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChainProvider"/>
<message_argument value="removeToolChain(IToolChain)"/>
</message_arguments>
</filter>
<filter comment="This is a newish interface. Assuming low risk." id="1211105284">
<message_arguments>
<message_argument value="removeToolChain(IToolChain)"/>
</message_arguments>
</filter>
</resource>
</component>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.core" version="2">
<resource path="src/org/eclipse/cdt/core/build/ICBuildConfiguration.java" type="org.eclipse.cdt.core.build.ICBuildConfiguration">
<filter id="403767336">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="TOOLCHAIN_ID"/>
</message_arguments>
</filter>
<filter id="403767336">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="TOOLCHAIN_TYPE"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="getLaunchMode()"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="getProperty(String)"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="removeProperty(String)"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfiguration"/>
<message_argument value="setProperty(String, String)"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/cdt/core/build/ICBuildConfigurationProvider.java" type="org.eclipse.cdt.core.build.ICBuildConfigurationProvider">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.ICBuildConfigurationProvider"/>
<message_argument value="getSupportedToolchains(Collection&lt;IToolChain&gt;)"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/cdt/core/build/IToolChain.java" type="org.eclipse.cdt.core.build.IToolChain">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChain"/>
<message_argument value="getTypeId()"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/cdt/core/build/IToolChainProvider.java" type="org.eclipse.cdt.core.build.IToolChainProvider">
<filter comment="This interface is still pretty new. Assuming low risk." id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChainProvider"/>
<message_argument value="addToolChain(IToolChain)"/>
</message_arguments>
</filter>
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChainProvider"/>
<message_argument value="getToolChain(String)"/>
</message_arguments>
</filter>
<filter comment="Newish interface. Assuming low risk." id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.build.IToolChainProvider"/>
<message_argument value="removeToolChain(IToolChain)"/>
</message_arguments>
</filter>
</resource>
</component>

View file

@ -1,109 +1,132 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.core" id="ToolChainProvider" name="Tool Chain Provider"/>
</appInfo>
<documentation>
A toolchain provider provides automatically discovered toolchains when requested. Providers have enablement to make sure they aren&apos;t called unless there&apos;s a good chance they have toolchains to offer.
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="provider"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="provider">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.core.build.IToolChainProvider"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.core" id="ToolChainProvider" name="Tool Chain Provider"/>
</appInfo>
<documentation>
A toolchain provider provides automatically discovered toolchains when requested. Providers have enablement to make sure they aren&apos;t called unless there&apos;s a good chance they have toolchains to offer.
</documentation>
</annotation>
<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="provider"/>
<element ref="type"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="provider">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.core.build.IToolChainProvider"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="type">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View file

@ -23,7 +23,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -119,11 +118,8 @@ public abstract class CBuildConfiguration extends PlatformObject
if (tc == null) {
// check for other versions
Collection<IToolChain> tcs = toolChainManager.getToolChains(typeId, id);
if (!tcs.isEmpty()) {
// TODO grab the newest version
tc = tcs.iterator().next();
} else {
tc = toolChainManager.getToolChain(typeId, id);
if (tc == null) {
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID,
CCorePlugin.STATUS_BUILD_CONFIG_NOT_VALID,
String.format(Messages.CBuildConfiguration_ToolchainMissing, config.getName()),

View file

@ -62,8 +62,10 @@ public interface IToolChain extends IAdaptable {
/**
* The version of the toolchain
*
* @deprecated the version doesn't matter. id's for a given type must be unique.
* @return toolchain version
*/
@Deprecated
String getVersion();
/**
@ -73,6 +75,18 @@ public interface IToolChain extends IAdaptable {
*/
String getName();
/**
* The type id for the toolchain. The combination of type id and toolchain id
* uniquely identify the toolchain in the system.
*
* @since 6.4
*/
default String getTypeId() {
// Subclasses really need to override this. There can be multiple providers for
// a given toolchain type.
return getProvider().getId();
}
/**
* Returns an property of the toolchain. Used to determine applicability of
* a toolchain for a given situation.

View file

@ -32,10 +32,19 @@ public interface IToolChainManager {
*/
IToolChainProvider getProvider(String providerId) throws CoreException;
/**
* Return the UI label for the toolchain type.
*
* @param id
* type toolchain type id
* @return name of the type
* @since 6.4
*/
String getToolChainTypeName(String typeId);
/**
* Return the toolchain from the given provider with the given id and version.
*
* @deprecated Version is now irrelevant. id's are unique.
* @param providerId
* id of provider
* @param id
@ -44,6 +53,7 @@ public interface IToolChainManager {
* version of toolchain
* @return the toolchain
* @throws CoreException
* @deprecated version is now irrelevant. id's are unique.
*/
@Deprecated
default IToolChain getToolChain(String providerId, String id, String version) throws CoreException {
@ -51,17 +61,17 @@ public interface IToolChainManager {
}
/**
* Return the toolChain from the given provider with the given id.
* Return the toolChain with the given type and id.
*
* @param providerId
* id of provider
* @param typeId
* id of toolchain type
* @param id
* id of toolchain
* @return the toolchain
* @throws CoreException
* @since 6.4
*/
IToolChain getToolChain(String providerId, String id) throws CoreException;
IToolChain getToolChain(String typeId, String id) throws CoreException;
/**
* Return the toolchains provided by the given provider
@ -70,8 +80,12 @@ public interface IToolChainManager {
* id of provider
* @return toolchains the provider provides
* @throws CoreException
* @deprecated we no longer organize toolchains by provider id.
*/
Collection<IToolChain> getToolChains(String providerId) throws CoreException;
@Deprecated
default Collection<IToolChain> getToolChains(String providerId) throws CoreException {
return null;
}
/**
* Return all versions of toolchains with the given id provided by the given
@ -83,8 +97,12 @@ public interface IToolChainManager {
* id of toolchains
* @return toolchains with the given id provided by the provider
* @throws CoreException
* @deprecated toolchains no longer have multiple versions per id
*/
Collection<IToolChain> getToolChains(String providerId, String id) throws CoreException;
@Deprecated
default Collection<IToolChain> getToolChains(String providerId, String id) throws CoreException {
return null;
}
/**
* Returns the list of toolchains that have the given properties.

View file

@ -36,28 +36,16 @@ public interface IToolChainProvider {
/**
* Called by the manager to dynamically create the toolchain.
*
* @deprecated We have dropped the concept of version. All ids must be unique.
* @param id
* the id of the toolchain
* @param version
* the version of the toolchain
* @return the toolchain initialized with the settings.
* @deprecated providers do not manage toolchains, call
* IToolManager.getToolChain() instead.
*/
@Deprecated
default IToolChain getToolChain(String id, String version) throws CoreException {
return getToolChain(id);
}
/**
* Called by the manager to dynamically create the toolchain.
*
* @param id
* the id of the toolchain
* @return the toolchain initialized with the settings.
* @since 6.4
*/
default IToolChain getToolChain(String id) throws CoreException {
// By default, assumes all toolchains were added at init time.
return null;
}

View file

@ -9,6 +9,7 @@ package org.eclipse.cdt.internal.core.build;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -24,12 +25,16 @@ import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
public class ToolChainManager implements IToolChainManager {
private Map<String, IConfigurationElement> providerElements;
private Map<String, IToolChainProvider> providers;
private Map<List<String>, IToolChain> toolChains;
private Map<String, Map<String, IToolChain>> toolChains;
private Map<String, String> toolChainTypeNames = new HashMap<>();
private List<IToolChain> orderedToolChains;
private List<ISafeRunnable> listeners = new ArrayList<>();
@ -49,39 +54,110 @@ public class ToolChainManager implements IToolChainManager {
// Load the discovered toolchains
toolChains = new HashMap<>();
orderedToolChains = new ArrayList<>();
for (IConfigurationElement element : providerElements.values()) {
// TODO check for enablement
switch (element.getName()) {
case "provider": //$NON-NLS-1$
// TODO check for enablement
try {
IToolChainProvider provider = (IToolChainProvider) element
.createExecutableExtension("class"); //$NON-NLS-1$
providers.put(element.getAttribute("id"), provider); //$NON-NLS-1$
provider.init(this);
} catch (CoreException e) {
CCorePlugin.log(e);
}
break;
case "type": //$NON-NLS-1$
toolChainTypeNames.put(element.getAttribute("id"), element.getAttribute("name")); //$NON-NLS-1$ //$NON-NLS-2$
break;
}
}
orderedToolChains = new ArrayList<>();
Preferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID)
.node(getClass().getSimpleName()).node("order"); //$NON-NLS-1$
String nString = prefs.get("n", ""); //$NON-NLS-1$ //$NON-NLS-2$
if (!nString.isEmpty()) {
try {
IToolChainProvider provider = (IToolChainProvider) element
.createExecutableExtension("class"); //$NON-NLS-1$
providers.put(element.getAttribute("id"), provider); //$NON-NLS-1$
provider.init(this);
} catch (CoreException e) {
int n = Integer.parseInt(nString);
for (int i = 0; i < n; ++i) {
String typeId = prefs.get(Integer.toString(i) + ".type", ""); //$NON-NLS-1$ //$NON-NLS-2$
String id = prefs.get(Integer.toString(i) + ".id", ""); //$NON-NLS-1$ //$NON-NLS-2$
IToolChain toolChain = getToolChain(typeId, id);
if (toolChain != null) {
orderedToolChains.add(toolChain);
}
}
} catch (NumberFormatException e) {
CCorePlugin.log(e);
} catch (CoreException e) {
CCorePlugin.log(e.getStatus());
}
}
for (Map<String, IToolChain> type : toolChains.values()) {
for (IToolChain toolChain : type.values()) {
if (!orderedToolChains.contains(toolChain)) {
orderedToolChains.add(toolChain);
}
}
}
}
}
private List<String> getId(IToolChain toolChain) {
List<String> id = new ArrayList<>(3);
id.add(toolChain.getProvider().getId());
id.add(toolChain.getId());
return id;
@Override
public String getToolChainTypeName(String typeId) {
init();
String name = toolChainTypeNames.get(typeId);
return name != null ? name : typeId;
}
private void saveToolChainOrder() {
Preferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID)
.node(getClass().getSimpleName()).node("order"); //$NON-NLS-1$
prefs.put("n", Integer.toString(orderedToolChains.size())); //$NON-NLS-1$
int i = 0;
for (IToolChain toolChain : orderedToolChains) {
prefs.put(Integer.toString(i) + ".type", toolChain.getTypeId()); //$NON-NLS-1$
prefs.put(Integer.toString(i) + ".id", toolChain.getId()); //$NON-NLS-1$
i++;
}
try {
prefs.flush();
} catch (BackingStoreException e) {
CCorePlugin.log(e);
}
}
@Override
public void addToolChain(IToolChain toolChain) {
orderedToolChains.add(toolChain);
toolChains.put(getId(toolChain), toolChain);
Map<String, IToolChain> type = toolChains.get(toolChain.getTypeId());
if (type == null) {
type = new HashMap<>();
toolChains.put(toolChain.getTypeId(), type);
}
type.put(toolChain.getId(), toolChain);
if (orderedToolChains != null) {
// is null at init time where order will be established later
orderedToolChains.add(toolChain);
saveToolChainOrder();
}
fireChange();
}
@Override
public void removeToolChain(IToolChain toolChain) {
orderedToolChains.remove(toolChain);
toolChains.remove(getId(toolChain));
Map<String, IToolChain> type = toolChains.get(toolChain.getTypeId());
if (type != null) {
type.remove(toolChain.getId());
}
if (orderedToolChains.remove(toolChain)) {
saveToolChainOrder();
}
fireChange();
}
@ -100,95 +176,47 @@ public class ToolChainManager implements IToolChainManager {
}
@Override
public IToolChain getToolChain(String providerId, String id) throws CoreException {
public IToolChain getToolChain(String typeId, String id) throws CoreException {
init();
List<String> tid = new ArrayList<>(3);
tid.add(providerId);
tid.add(id);
IToolChain toolChain = toolChains.get(tid);
if (toolChain != null) {
return toolChain;
}
// Try the provider
IToolChainProvider realProvider = providers.get(providerId);
if (realProvider != null) {
toolChain = realProvider.getToolChain(id);
if (toolChain != null) {
toolChains.put(getId(toolChain), toolChain);
return toolChain;
}
}
return null;
Map<String, IToolChain> type = toolChains.get(typeId);
return type != null ? type.get(id) : null;
}
@Override
public Collection<IToolChain> getToolChainsMatching(Map<String, String> properties) {
init();
List<IToolChain> tcs = new ArrayList<>();
for (IToolChain toolChain : toolChains.values()) {
boolean matches = true;
for (Map.Entry<String, String> property : properties.entrySet()) {
String tcProperty = toolChain.getProperty(property.getKey());
if (tcProperty != null) {
if (!property.getValue().equals(tcProperty)) {
matches = false;
break;
for (Map<String, IToolChain> type : toolChains.values()) {
for (IToolChain toolChain : type.values()) {
boolean matches = true;
for (Map.Entry<String, String> property : properties.entrySet()) {
String tcProperty = toolChain.getProperty(property.getKey());
if (tcProperty != null) {
if (!property.getValue().equals(tcProperty)) {
matches = false;
break;
}
}
}
if (matches) {
tcs.add(toolChain);
}
}
if (matches) {
tcs.add(toolChain);
}
}
// Allow 32-bit compilers on 64-bit machines
// TODO is there a cleaner way to do this?
if ("x86_64".equals(properties.get(IToolChain.ATTR_ARCH))) { //$NON-NLS-1$
Map<String, String> properties32 = new HashMap<>(properties);
properties32.put(IToolChain.ATTR_ARCH, "x86"); //$NON-NLS-1$
tcs.addAll(getToolChainsMatching(properties32));
}
return tcs;
}
@Override
public Collection<IToolChain> getToolChains(String providerId) {
init();
List<IToolChain> tcs = new ArrayList<>();
for (IToolChain toolChain : toolChains.values()) {
if (toolChain.getProvider().getId().equals(providerId)) {
tcs.add(toolChain);
}
}
return tcs;
}
@Override
public Collection<IToolChain> getToolChains(String providerId, String id) throws CoreException {
init();
List<IToolChain> tcs = new ArrayList<>();
for (IToolChain toolChain : toolChains.values()) {
if (toolChain.getProvider().getId().equals(providerId) && toolChain.getId().equals(id)) {
tcs.add(toolChain);
}
}
return tcs;
}
@Override
public Collection<IToolChain> getAllToolChains() throws CoreException {
init();
return orderedToolChains;
return Collections.unmodifiableCollection(orderedToolChains);
}
@Override
public void setToolChainOrder(List<IToolChain> orderedToolchains) throws CoreException {
// TODO Auto-generated method stub
this.orderedToolChains = orderedToolchains;
saveToolChainOrder();
}
@Override

View file

@ -79,6 +79,7 @@ public final class CUIMessages extends NLS {
public static String ToolChainPreferencePage_Remove1;
public static String ToolChainPreferencePage_RemoveToolchain;
public static String ToolChainPreferencePage_Toolchains;
public static String ToolChainPreferencePage_Type;
public static String ToolChainPreferencePage_Up;
public static String ToolChainPreferencePage_UserDefinedToolchains;
public static String OptionalMessageDialog_dontShowAgain;

View file

@ -79,6 +79,7 @@ ToolChainPreferencePage_Remove=Remove
ToolChainPreferencePage_Remove1=Remove
ToolChainPreferencePage_RemoveToolchain=Remove Toolchain
ToolChainPreferencePage_Toolchains=Toolchains
ToolChainPreferencePage_Type=Type
ToolChainPreferencePage_Up=Up
ToolChainPreferencePage_UserDefinedToolchains=User Defined Toolchains

View file

@ -69,7 +69,9 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
private Button userEdit;
private Button userRemove;
private IToolChainManager manager = CUIPlugin.getService(IToolChainManager.class);
private List<IToolChain> toolChains;
private static IToolChainManager manager = CUIPlugin.getService(IToolChainManager.class);
private ISafeRunnable tcListener = () -> Display.getDefault().asyncExec(() -> {
availTable.refresh();
@ -90,10 +92,12 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
IToolChain toolChain = (IToolChain) element;
switch (columnIndex) {
case 0:
return toolChain.getName();
return manager.getToolChainTypeName(toolChain.getTypeId());
case 1:
return toolChain.getProperty(IToolChain.ATTR_OS);
return toolChain.getName();
case 2:
return toolChain.getProperty(IToolChain.ATTR_OS);
case 3:
return toolChain.getProperty(IToolChain.ATTR_ARCH);
}
return null;
@ -118,25 +122,19 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
availGroup.setLayout(new GridLayout(2, false));
availTable = createToolChainTable(availGroup);
availTable.setLabelProvider(new TableLabelProvider());
availTable.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
return toolChains.toArray();
}
});
availTable.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateButtons();
}
});
availTable.setLabelProvider(new TableLabelProvider());
availTable.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
try {
return manager.getAllToolChains().toArray();
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
return new Object[0];
}
}
});
Composite availButtonComp = new Composite(availGroup, SWT.NONE);
availButtonComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
@ -145,10 +143,38 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
availUp = new Button(availButtonComp, SWT.PUSH);
availUp.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
availUp.setText(CUIMessages.ToolChainPreferencePage_Up);
availUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int i = availTable.getTable().getSelectionIndex();
if (i < 1) {
return;
}
IToolChain tc = toolChains.get(i - 1);
toolChains.set(i - 1, toolChains.get(i));
toolChains.set(i, tc);
availTable.refresh();
}
});
availDown = new Button(availButtonComp, SWT.PUSH);
availDown.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
availDown.setText(CUIMessages.ToolChainPreferencePage_Down);
availDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int i = availTable.getTable().getSelectionIndex();
if (i < 0 || i > toolChains.size() - 2) {
return;
}
IToolChain tc = toolChains.get(i + 1);
toolChains.set(i + 1, toolChains.get(i));
toolChains.set(i, tc);
availTable.refresh();
}
});
Group userGroup = new Group(control, SWT.NONE);
userGroup.setText(CUIMessages.ToolChainPreferencePage_UserDefinedToolchains);
@ -156,12 +182,6 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
userGroup.setLayout(new GridLayout(2, false));
userTable = createToolChainTable(userGroup);
userTable.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateButtons();
}
});
userTable.setLabelProvider(new TableLabelProvider());
userTable.setContentProvider(new IStructuredContentProvider() {
@Override
@ -179,6 +199,12 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
return tcs.toArray();
}
});
userTable.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateButtons();
}
});
Composite userButtonComp = new Composite(userGroup, SWT.NONE);
userButtonComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
@ -256,6 +282,13 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
}
});
toolChains = new ArrayList<IToolChain>();
try {
toolChains.addAll(manager.getAllToolChains());
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
}
availTable.setInput(manager);
userTable.setInput(manager);
updateButtons();
@ -269,6 +302,24 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
super.dispose();
}
@Override
public boolean performOk() {
if (!super.performOk()) {
return false;
}
try {
if (!toolChains.equals(manager.getAllToolChains())) {
manager.setToolChainOrder(toolChains);
}
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
return false;
}
return true;
}
private TableViewer createToolChainTable(Composite parent) {
Composite tableComp = new Composite(parent, SWT.NONE);
tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@ -280,9 +331,13 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
TableColumnLayout tableLayout = new TableColumnLayout();
TableColumn tableTypeColumn = new TableColumn(table, SWT.LEAD);
tableTypeColumn.setText(CUIMessages.ToolChainPreferencePage_Type);
tableLayout.setColumnData(tableTypeColumn, new ColumnWeightData(2));
TableColumn tableNameColumn = new TableColumn(table, SWT.LEAD);
tableNameColumn.setText(CUIMessages.ToolChainPreferencePage_Name);
tableLayout.setColumnData(tableNameColumn, new ColumnWeightData(6));
tableLayout.setColumnData(tableNameColumn, new ColumnWeightData(10));
TableColumn tableOSColumn = new TableColumn(table, SWT.LEAD);
tableOSColumn.setText(CUIMessages.ToolChainPreferencePage_OS);
@ -298,9 +353,9 @@ public class ToolChainPreferencePage extends PreferencePage implements IWorkbenc
}
private void updateButtons() {
boolean availSelected = availTable.getTable().getSelectionCount() > 0;
availUp.setEnabled(availSelected);
availDown.setEnabled(availSelected);
int i = availTable.getTable().getSelectionIndex();
availUp.setEnabled(i > 0);
availDown.setEnabled(i >= 0 && i < toolChains.size() - 2);
boolean userSelected = userTable.getTable().getSelectionCount() > 0;
userEdit.setEnabled(userSelected);

View file

@ -12,7 +12,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.build.IToolChainProvider;
import org.eclipse.cdt.msw.build.Activator;
@ -72,10 +71,4 @@ public class MSVCToolChainProvider implements IToolChainProvider {
}
}
@Override
public IToolChain getToolChain(String id, String version) throws CoreException {
// TODO Auto-generated method stub
return IToolChainProvider.super.getToolChain(id, version);
}
}