1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Toolchains filtering implemented

This commit is contained in:
Oleg Krasilnikov 2007-04-27 15:27:51 +00:00
parent c7e6e87019
commit 6ffd53dea0
4 changed files with 122 additions and 6 deletions

View file

@ -14,12 +14,16 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.managedbuilder.core.IInputType;
import org.eclipse.cdt.managedbuilder.core.ITargetPlatform;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIImages;
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
import org.eclipse.cdt.ui.wizards.CNewWizard;
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
import org.eclipse.cdt.utils.Platform;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
@ -41,15 +45,31 @@ public abstract class AbstractCWizard extends CNewWizard {
listener = _listener;
}
protected boolean isValid(IToolChain tc) {
/**
* Checks whether toolchain can be displayed
* @param tc
* @return
*/
protected boolean isValid(IToolChain tc, boolean supportedOnly, IWizard w) {
// Check for langiuage compatibility first in any case
if (!isLanguageCompatible(tc, w))
return false;
// Do not do further check if all toolchains are permitted
if (!supportedOnly)
return true;
// Filter off unsupported and system toolchains
if (tc == null || !tc.isSupported() || tc.isAbstract() || tc.isSystemObject())
return false;
// Check for platform compatibility
ITargetPlatform tp = tc.getTargetPlatform();
if (tp != null) {
List osList = Arrays.asList(tc.getOSList());
if (osList.contains(ALL) || osList.contains(os)) {
List archList = Arrays.asList(tc.getArchList());
if (archList.contains(ALL) || archList.contains(arch))
if (archList.contains(ALL) || archList.contains(arch))
return true; // OS and ARCH fits
}
return false; // OS or ARCH does not fit
@ -57,7 +77,88 @@ public abstract class AbstractCWizard extends CNewWizard {
return true; // No platform: nothing to check
}
/* comment it out for now..
/**
* Checks toolchain for Language ID, Content type ID
* and Extensions, if they are required by wizard.
*
* @param tc - toolchain to check
* @param w - wizard which provides selection criteria
* @return
*/
protected boolean isLanguageCompatible(IToolChain tc, IWizard w) {
if (w == null)
return true;
if (!(w instanceof CDTCommonProjectWizard))
return true;
ITool[] tools = tc.getTools();
CDTCommonProjectWizard wz = (CDTCommonProjectWizard)w;
String[] langIDs = wz.getLanguageIDs();
String[] ctypeIDs = wz.getContentTypeIDs();
String[] exts = wz.getExtensions();
// nothing requied ?
if (empty(langIDs) && empty(ctypeIDs) && empty(exts))
return true;
for (int i=0; i<tools.length; i++) {
IInputType[] its = tools[i].getInputTypes();
// no input types - check only extensions
if (empty(its)) {
if (!empty(exts)) {
String[] s = tools[i].getAllInputExtensions();
if (contains(exts, s))
return true; // extension fits
}
continue;
}
// normal tool with existing input type(s)
for (int j = 0; j<its.length; j++) {
// Check language IDs
if (!empty(langIDs)) {
String lang = its[j].getLanguageId(tools[i]);
if (contains(langIDs, new String[] {lang})) {
return true; // Language ID fits
}
}
// Check content types
if (!empty(ctypeIDs)) {
String[] ct1 = its[j].getSourceContentTypeIds();
String[] ct2 = its[j].getHeaderContentTypeIds();
if (contains(ctypeIDs, ct1) ||
contains(ctypeIDs, ct2))
{
return true; // content type fits
}
}
// Check extensions
if (!empty(exts)) {
String[] ex1 =its[j].getHeaderExtensions(tools[i]);
String[] ex2 =its[j].getSourceExtensions(tools[i]);
if (contains(exts, ex1) ||
contains(exts, ex2)) {
return true; // extension fits fits
}
}
}
}
return false; // no one value fits to required
}
private boolean empty(Object[] s) {
return (s == null || s.length == 0);
}
private boolean contains(String[] s1, String[] s2) {
for (int i=0; i<s1.length; i++)
for (int j=0; j<s2.length; j++)
if (s1[i].equals(s2[j]))
return true;
return false;
}
/* comment it out for now..
protected boolean isSupportedForTemplate(TemplateInfo templateInfo, IToolChain tc) {
String[] tcIds = templateInfo.getToolChainIds();
if (tcIds.length != 0) {

View file

@ -49,7 +49,8 @@ public class ManagedBuildWizard extends AbstractCWizard {
if (tcs == null || tcs.length == 0) continue;
MBSWizardHandler h = new MBSWizardHandler(vs[i], parent, wizard);
for (int j=0; j<tcs.length; j++) {
if (!supportedOnly || isValid(tcs[j])) h.addTc(tcs[j]);
if (isValid(tcs[j], supportedOnly, wizard))
h.addTc(tcs[j]);
}
if (h.getToolChainsCount() > 0) {
items.add(new EntryDescriptor(vs[i].getId(), null, vs[i].getName(), true, h, null));
@ -74,7 +75,7 @@ public class ManagedBuildWizard extends AbstractCWizard {
for (int i=0; i<cfgs.length; i++) {
if (cfgs[i].isSystemObject()) continue;
IToolChain t = cfgs[i].getToolChain();
if (!supportedOnly || isValid(t)) {
if (isValid(t, supportedOnly, wizard)) {
tc = t;
break;
}

View file

@ -24,7 +24,8 @@ public class StdBuildWizard extends AbstractCWizard {
h.addTc(null); // add default toolchain
IToolChain[] tcs = ManagedBuildManager.getRealToolChains();
for (int i=0; i<tcs.length; i++)
if (!supportedOnly || isValid(tcs[i])) h.addTc(tcs[i]);
if (isValid(tcs[i], supportedOnly, wizard))
h.addTc(tcs[i]);
EntryDescriptor wd = new EntryDescriptor(NAME, null, NAME, false, h, null);
return new EntryDescriptor[] {wd};

View file

@ -46,6 +46,7 @@ implements IExecutableExtension, IWizardWithMemory
private static final String OP_ERROR= "CProjectWizard.op_error"; //$NON-NLS-1$
private static final String title= CUIPlugin.getResourceString(OP_ERROR + ".title"); //$NON-NLS-1$
private static final String message= CUIPlugin.getResourceString(OP_ERROR + ".message"); //$NON-NLS-1$
private static final String[] EMPTY_ARR = new String[0];
protected IConfigurationElement fConfigElement;
protected CDTMainWizardPage fMainPage;
@ -231,4 +232,16 @@ implements IExecutableExtension, IWizardWithMemory
public IPath getLastProjectLocation() {
return lastProjectLocation;
}
// Methods below should provide data for language check
public String[] getLanguageIDs (){
return EMPTY_ARR;
}
public String[] getContentTypeIDs (){
return EMPTY_ARR;
}
public String[] getExtensions (){
return EMPTY_ARR;
}
}