mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Merge remote-tracking branch 'cdt/master' into sd90
This commit is contained in:
commit
4c419cc214
147 changed files with 19986 additions and 151 deletions
14
build/org.eclipse.cdt.make.core.tests/plugin.xml
Normal file
14
build/org.eclipse.cdt.make.core.tests/plugin.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
id="org.eclipse.cdt.make.core.tests.ErrorParsers"
|
||||
name="org.eclipse.cdt.make.core.tests ErrorParsers"
|
||||
point="org.eclipse.cdt.core.ErrorParser">
|
||||
<errorparser
|
||||
class="org.eclipse.cdt.make.core.scannerconfig.GCCBuildCommandParser$GCCBuildCommandPatternHighlighter"
|
||||
id="org.eclipse.cdt.core.tests.make.core.GCCBuildCommandPatternHighlighter"
|
||||
name="Test Plugin GCC BOP Patterns Highlighter">
|
||||
</errorparser>
|
||||
</extension>
|
||||
</plugin>
|
|
@ -0,0 +1,26 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.scannerdiscovery;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class AllSD80Tests extends TestSuite {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new AllSD80Tests();
|
||||
}
|
||||
|
||||
public AllSD80Tests() {
|
||||
super(AllSD80Tests.class.getName());
|
||||
|
||||
addTestSuite(GCCBuildCommandParserTest.class);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2009 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.scannerdiscovery;
|
||||
|
|
|
@ -182,5 +182,14 @@
|
|||
class="org.eclipse.cdt.make.internal.core.dataprovider.MakeConfigurationDataProvider"
|
||||
/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider
|
||||
class="org.eclipse.cdt.make.core.scannerconfig.GCCBuildCommandParser"
|
||||
id="org.eclipse.cdt.make.core.build.command.parser.gcc"
|
||||
name="CDT GCC Build Output Parser"
|
||||
parameter="(gcc)|([gc]\+\+)">
|
||||
</provider>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.core.scannerconfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.IErrorParser2;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.errorparsers.RegexErrorParser;
|
||||
import org.eclipse.cdt.core.errorparsers.RegexErrorPattern;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
|
||||
public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner implements
|
||||
ILanguageSettingsBuildOutputScanner {
|
||||
|
||||
private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$
|
||||
private static final int OPTION_GROUP = 0;
|
||||
|
||||
/**
|
||||
* Note: design patterns to keep file group the same and matching {@link #FILE_GROUP}
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
private static final String[] PATTERN_TEMPLATES = {
|
||||
"\\s*\"?${COMPILER_PATTERN}\"?.*\\s" + "()([^'\"\\s]*\\.${EXTENSIONS_PATTERN})(\\s.*)?[\r\n]*", // compiling unquoted file
|
||||
"\\s*\"?${COMPILER_PATTERN}\"?.*\\s" + "(['\"])(.*\\.${EXTENSIONS_PATTERN})\\${COMPILER_GROUPS+1}(\\s.*)?[\r\n]*" // compiling quoted file
|
||||
};
|
||||
private static final int FILE_GROUP = 2;
|
||||
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
private String getCompilerCommandPattern() {
|
||||
String parameter = getCustomParameter();
|
||||
return "(" + parameter + ")";
|
||||
}
|
||||
|
||||
private int adjustFileGroup() {
|
||||
return countGroups(getCompilerCommandPattern()) + FILE_GROUP;
|
||||
}
|
||||
|
||||
private String makePattern(String template) {
|
||||
@SuppressWarnings("nls")
|
||||
String pattern = template
|
||||
.replace("${COMPILER_PATTERN}", getCompilerCommandPattern())
|
||||
.replace("${EXTENSIONS_PATTERN}", getPatternFileExtensions())
|
||||
.replace("${COMPILER_GROUPS+1}", new Integer(countGroups(getCompilerCommandPattern()) + 1).toString());
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parseForResourceName(String line) {
|
||||
if (line==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (String template : PATTERN_TEMPLATES) {
|
||||
String pattern = makePattern(template);
|
||||
Matcher fileMatcher = Pattern.compile(pattern).matcher(line);
|
||||
if (fileMatcher.matches()) {
|
||||
int fileGroup = adjustFileGroup();
|
||||
String sourceFileName = fileMatcher.group(fileGroup);
|
||||
return sourceFileName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> parseForOptions(String line) {
|
||||
if (line==null || currentResource==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> options = new ArrayList<String>();
|
||||
Matcher optionMatcher = OPTIONS_PATTERN.matcher(line);
|
||||
while (optionMatcher.find()) {
|
||||
String option = optionMatcher.group(OPTION_GROUP);
|
||||
if (option!=null) {
|
||||
options.add(option);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
// This is redundant but let us keep it here to navigate in java code easier
|
||||
@Override
|
||||
public boolean processLine(String line, ErrorParserManager epm) {
|
||||
return super.processLine(line, epm);
|
||||
}
|
||||
|
||||
// TODO - test cases
|
||||
@Override
|
||||
public void shutdown() {
|
||||
LanguageSettingsManager.buildResourceTree(this, currentCfgDescription, currentLanguageId, currentProject);
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trivial Error Parser which allows highlighting of output lines matching the patterns
|
||||
* of this parser. Intended for better troubleshooting experience.
|
||||
* Implementers are supposed to add the error parser as an extension. Initialize with
|
||||
* build command parser extension ID.
|
||||
*/
|
||||
protected static abstract class AbstractBuildCommandPatternHighlighter extends RegexErrorParser implements IErrorParser2 {
|
||||
public AbstractBuildCommandPatternHighlighter(String buildCommandParserPluginExtension) {
|
||||
init(buildCommandParserPluginExtension);
|
||||
}
|
||||
|
||||
protected void init(String buildCommandParserId) {
|
||||
AbstractBuildCommandParser buildCommandParser = (AbstractBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(buildCommandParserId);
|
||||
for (String template : PATTERN_TEMPLATES) {
|
||||
String pattern = buildCommandParser.makePattern(template);
|
||||
String fileExpr = "$"+buildCommandParser.adjustFileGroup(); //$NON-NLS-1$
|
||||
String descExpr = "$0"; //$NON-NLS-1$
|
||||
addPattern(new RegexErrorPattern(pattern, fileExpr, null, descExpr, null, IMarkerGenerator.SEVERITY_WARNING, true));
|
||||
}
|
||||
}
|
||||
|
||||
public int getProcessLineBehaviour() {
|
||||
return KEEP_LONGLINES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,847 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.core.scannerconfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.utils.EFSExtensionManager;
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSettingsSerializable implements
|
||||
ILanguageSettingsOutputScanner {
|
||||
|
||||
protected static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$
|
||||
|
||||
protected ICConfigurationDescription currentCfgDescription = null;
|
||||
protected IProject currentProject = null;
|
||||
protected IResource currentResource = null;
|
||||
protected String currentLanguageId = null;
|
||||
|
||||
protected ErrorParserManager errorParserManager = null;
|
||||
protected String parsedResourceName = null;
|
||||
protected boolean isResolvingPaths = true;
|
||||
|
||||
protected static abstract class AbstractOptionParser {
|
||||
protected final Pattern pattern;
|
||||
protected final String patternStr;
|
||||
protected String nameExpression;
|
||||
protected String valueExpression;
|
||||
protected int extraFlag = 0;
|
||||
protected int kind = 0;
|
||||
private String parsedName;
|
||||
private String parsedValue;
|
||||
|
||||
public AbstractOptionParser(int kind, String pattern, String nameExpression, String valueExpression, int extraFlag) {
|
||||
this.kind = kind;
|
||||
this.patternStr = pattern;
|
||||
this.nameExpression = nameExpression;
|
||||
this.valueExpression = valueExpression;
|
||||
this.extraFlag = extraFlag;
|
||||
|
||||
this.pattern = Pattern.compile(pattern);
|
||||
}
|
||||
|
||||
public ICLanguageSettingEntry createEntry(String name, String value, int flag) {
|
||||
return (ICLanguageSettingEntry) CDataUtil.createEntry(kind, name, value, null, flag | extraFlag);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: explain
|
||||
*/
|
||||
protected String extractOption(String input) {
|
||||
@SuppressWarnings("nls")
|
||||
String option = input.replaceFirst("(" + patternStr + ").*", "$1");
|
||||
return option;
|
||||
}
|
||||
|
||||
protected String parseStr(Matcher matcher, String str) {
|
||||
if (str != null)
|
||||
return matcher.replaceAll(str);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isPathKind() {
|
||||
return kind == ICSettingEntry.INCLUDE_PATH || kind == ICSettingEntry.INCLUDE_FILE
|
||||
|| kind == ICSettingEntry.MACRO_FILE || kind == ICSettingEntry.LIBRARY_PATH;
|
||||
}
|
||||
|
||||
public boolean parseOption(String option) {
|
||||
String opt = extractOption(option);
|
||||
Matcher matcher = pattern.matcher(opt);
|
||||
boolean isMatch = matcher.matches();
|
||||
if (isMatch) {
|
||||
parsedName = parseStr(matcher, nameExpression);
|
||||
parsedValue = parseStr(matcher, valueExpression);
|
||||
}
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class IncludePathOptionParser extends AbstractOptionParser {
|
||||
public IncludePathOptionParser(String pattern, String nameExpression) {
|
||||
super(ICLanguageSettingEntry.INCLUDE_PATH, pattern, nameExpression, nameExpression, 0);
|
||||
}
|
||||
public IncludePathOptionParser(String pattern, String nameExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.INCLUDE_PATH, pattern, nameExpression, nameExpression, extraFlag);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class IncludeFileOptionParser extends AbstractOptionParser {
|
||||
public IncludeFileOptionParser(String pattern, String nameExpression) {
|
||||
super(ICLanguageSettingEntry.INCLUDE_FILE, pattern, nameExpression, nameExpression, 0);
|
||||
}
|
||||
public IncludeFileOptionParser(String pattern, String nameExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.INCLUDE_FILE, pattern, nameExpression, nameExpression, extraFlag);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class MacroOptionParser extends AbstractOptionParser {
|
||||
public MacroOptionParser(String pattern, String nameExpression, String valueExpression) {
|
||||
super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, valueExpression, 0);
|
||||
}
|
||||
public MacroOptionParser(String pattern, String nameExpression, String valueExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, valueExpression, extraFlag);
|
||||
}
|
||||
public MacroOptionParser(String pattern, String nameExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, null, extraFlag);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class MacroFileOptionParser extends AbstractOptionParser {
|
||||
public MacroFileOptionParser(String pattern, String nameExpression) {
|
||||
super(ICLanguageSettingEntry.MACRO_FILE, pattern, nameExpression, nameExpression, 0);
|
||||
}
|
||||
public MacroFileOptionParser(String pattern, String nameExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.MACRO_FILE, pattern, nameExpression, nameExpression, extraFlag);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class LibraryPathOptionParser extends AbstractOptionParser {
|
||||
public LibraryPathOptionParser(String pattern, String nameExpression) {
|
||||
super(ICLanguageSettingEntry.LIBRARY_PATH, pattern, nameExpression, nameExpression, 0);
|
||||
}
|
||||
public LibraryPathOptionParser(String pattern, String nameExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.LIBRARY_PATH, pattern, nameExpression, nameExpression, extraFlag);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class LibraryFileOptionParser extends AbstractOptionParser {
|
||||
public LibraryFileOptionParser(String pattern, String nameExpression) {
|
||||
super(ICLanguageSettingEntry.LIBRARY_FILE, pattern, nameExpression, nameExpression, 0);
|
||||
}
|
||||
public LibraryFileOptionParser(String pattern, String nameExpression, int extraFlag) {
|
||||
super(ICLanguageSettingEntry.LIBRARY_FILE, pattern, nameExpression, nameExpression, extraFlag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the line returning the resource name as appears in the output.
|
||||
* This is the resource where {@link ICLanguageSettingEntry} list is being added.
|
||||
*
|
||||
* @param line - one input line from the output stripped from end of line characters.
|
||||
* @return the resource name as appears in the output or {@code null}.
|
||||
* Note that {@code null} can have different semantics and can mean "no resource found"
|
||||
* or "applicable to any resource". By default "no resource found" is used in this
|
||||
* abstract class but extenders can handle otherwise.
|
||||
*/
|
||||
protected abstract String parseForResourceName(String line);
|
||||
|
||||
/**
|
||||
* Parse the line returning the list of substrings to be treated each as input to
|
||||
* the option parsers. It is assumed that each substring presents one
|
||||
* {@link ICLanguageSettingEntry} (for example compiler options {@code -I/path} or
|
||||
* {@code -DMACRO=1}.
|
||||
*
|
||||
* @param line - one input line from the output stripped from end of line characters.
|
||||
* @return list of substrings representing language settings entries.
|
||||
*/
|
||||
protected abstract List<String> parseForOptions(String line);
|
||||
|
||||
/**
|
||||
* @return array of option parsers defining how to parse a string to
|
||||
* {@link ICLanguageSettingEntry}.
|
||||
* See {@link AbstractOptionParser} and its specific extenders.
|
||||
*/
|
||||
protected abstract AbstractOptionParser[] getOptionParsers();
|
||||
|
||||
public boolean isResolvingPaths() {
|
||||
return isResolvingPaths;
|
||||
}
|
||||
|
||||
public void setResolvingPaths(boolean resolvePaths) {
|
||||
this.isResolvingPaths = resolvePaths;
|
||||
}
|
||||
|
||||
|
||||
public void startup(ICConfigurationDescription cfgDescription) throws CoreException {
|
||||
currentCfgDescription = cfgDescription;
|
||||
currentProject = cfgDescription != null ? cfgDescription.getProjectDescription().getProject() : null;
|
||||
}
|
||||
|
||||
public boolean processLine(String line) {
|
||||
return processLine(line, null);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
// release resources for garbage collector
|
||||
currentCfgDescription = null;
|
||||
currentProject = null;
|
||||
currentResource = null;
|
||||
currentLanguageId = null;
|
||||
|
||||
errorParserManager = null;
|
||||
parsedResourceName = null;
|
||||
}
|
||||
|
||||
public boolean processLine(String line, ErrorParserManager epm) {
|
||||
errorParserManager = epm;
|
||||
parsedResourceName = parseForResourceName(line);
|
||||
|
||||
currentLanguageId = determineLanguage(parsedResourceName);
|
||||
if (!isLanguageInScope(currentLanguageId))
|
||||
return false;
|
||||
|
||||
currentResource = findResource(parsedResourceName);
|
||||
|
||||
/**
|
||||
* URI of directory where the build is happening. This URI could point to a remote filesystem
|
||||
* for remote builds. Most often it is the same filesystem as for currentResource but
|
||||
* it can be different filesystem (and different URI schema).
|
||||
*/
|
||||
URI buildDirURI = null;
|
||||
|
||||
/**
|
||||
* Where source tree starts if mapped. This kind of mapping is useful for example in cases when
|
||||
* the absolute path to the source file on the remote system is simulated inside a project in the
|
||||
* workspace.
|
||||
* This URI is rooted on the same filesystem where currentResource resides. In general this filesystem
|
||||
* (or even URI schema) does not have to match that of buildDirURI.
|
||||
*/
|
||||
URI mappedRootURI = null;
|
||||
|
||||
if (isResolvingPaths) {
|
||||
mappedRootURI = getMappedRootURI(currentResource, parsedResourceName);
|
||||
buildDirURI = getBuildDirURI(mappedRootURI);
|
||||
}
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
||||
List<String> options = parseForOptions(line);
|
||||
if (options!=null) {
|
||||
for (String option : options) {
|
||||
for (AbstractOptionParser optionParser : getOptionParsers()) {
|
||||
try {
|
||||
if (optionParser.parseOption(option)) {
|
||||
ICLanguageSettingEntry entry = null;
|
||||
if (isResolvingPaths && optionParser.isPathKind()) {
|
||||
URI baseURI = new Path(optionParser.parsedName).isAbsolute() ? mappedRootURI : buildDirURI;
|
||||
entry = createResolvedPathEntry(optionParser, optionParser.parsedName, 0, baseURI);
|
||||
} else {
|
||||
entry = optionParser.createEntry(optionParser.parsedName, optionParser.parsedValue, 0);
|
||||
}
|
||||
|
||||
if (entry != null && !entries.contains(entry)) {
|
||||
entries.add(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// protect from rogue parsers extending this class
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entries.size() > 0) {
|
||||
setSettingEntries(entries);
|
||||
} else {
|
||||
setSettingEntries(null);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void setSettingEntries(List<ICLanguageSettingEntry> entries) {
|
||||
setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries);
|
||||
|
||||
// TODO - for debugging only, eventually remove
|
||||
IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName()
|
||||
+ " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource);
|
||||
MakeCorePlugin.log(status);
|
||||
}
|
||||
|
||||
protected String determineLanguage(String parsedResourceName) {
|
||||
if (parsedResourceName==null)
|
||||
return null;
|
||||
|
||||
String fileName = new Path(parsedResourceName).lastSegment().toString();
|
||||
IContentTypeManager manager = Platform.getContentTypeManager();
|
||||
IContentType contentType = manager.findContentTypeFor(fileName);
|
||||
if (contentType==null)
|
||||
return null;
|
||||
|
||||
ILanguage lang = LanguageManager.getInstance().getLanguage(contentType);
|
||||
if (lang==null)
|
||||
return null;
|
||||
|
||||
return lang.getId();
|
||||
}
|
||||
|
||||
protected boolean isLanguageInScope(String languageId) {
|
||||
List<String> languageIds = getLanguageScope();
|
||||
return languageIds == null || languageIds.contains(languageId);
|
||||
}
|
||||
|
||||
protected String getPatternFileExtensions() {
|
||||
IContentTypeManager manager = Platform.getContentTypeManager();
|
||||
|
||||
Set<String> fileExts = new HashSet<String>();
|
||||
|
||||
IContentType contentTypeCpp = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$
|
||||
fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
|
||||
|
||||
IContentType contentTypeC = manager.getContentType("org.eclipse.cdt.core.cSource"); //$NON-NLS-1$
|
||||
fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
|
||||
|
||||
String pattern = expressionLogicalOr(fileExts);
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser,
|
||||
String parsedPath, int flag, URI baseURI) {
|
||||
|
||||
ICLanguageSettingEntry entry;
|
||||
String resolvedPath = null;
|
||||
|
||||
URI uri = determineMappedURI(parsedPath, baseURI);
|
||||
IResource rc = null;
|
||||
if (uri != null && uri.isAbsolute()) {
|
||||
rc = findResourceForLocationURI(uri, optionParser.kind, currentProject);
|
||||
}
|
||||
if (rc != null) {
|
||||
IPath path = rc.getFullPath();
|
||||
resolvedPath = path.toString();
|
||||
flag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED;
|
||||
} else {
|
||||
IPath path = getFilesystemLocation(uri);
|
||||
if (path != null && new File(path.toString()).exists()) {
|
||||
resolvedPath = path.toString();
|
||||
}
|
||||
if (resolvedPath == null) {
|
||||
Set<String> referencedProjectsNames = new LinkedHashSet<String>();
|
||||
if (currentCfgDescription!=null) {
|
||||
Map<String,String> refs = currentCfgDescription.getReferenceInfo();
|
||||
referencedProjectsNames.addAll(refs.keySet());
|
||||
}
|
||||
IResource resource = resolveResourceInWorkspace(parsedPath, currentProject, referencedProjectsNames);
|
||||
if (resource != null) {
|
||||
path = resource.getFullPath();
|
||||
resolvedPath = path.toString();
|
||||
flag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED;
|
||||
}
|
||||
}
|
||||
if (resolvedPath==null && path!=null) {
|
||||
resolvedPath = path.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (resolvedPath==null) {
|
||||
resolvedPath = parsedPath;
|
||||
}
|
||||
|
||||
entry = optionParser.createEntry(resolvedPath, resolvedPath, flag);
|
||||
return entry;
|
||||
}
|
||||
|
||||
private IResource findResource(String parsedResourceName) {
|
||||
if (parsedResourceName==null)
|
||||
return null;
|
||||
|
||||
IResource sourceFile = null;
|
||||
|
||||
// try ErrorParserManager
|
||||
if (errorParserManager != null) {
|
||||
sourceFile = errorParserManager.findFileName(parsedResourceName);
|
||||
}
|
||||
// try to find absolute path in the workspace
|
||||
if (sourceFile == null && new Path(parsedResourceName).isAbsolute()) {
|
||||
URI uri = org.eclipse.core.filesystem.URIUtil.toURI(parsedResourceName);
|
||||
sourceFile = findFileForLocationURI(uri, currentProject);
|
||||
}
|
||||
// try path relative to build dir from configuration
|
||||
if (sourceFile == null && currentCfgDescription != null) {
|
||||
IPath builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD();
|
||||
if (builderCWD!=null) {
|
||||
IPath path = builderCWD.append(parsedResourceName);
|
||||
URI uri = org.eclipse.core.filesystem.URIUtil.toURI(path);
|
||||
sourceFile = findFileForLocationURI(uri, currentProject);
|
||||
}
|
||||
}
|
||||
// try path relative to the project
|
||||
if (sourceFile == null && currentProject != null) {
|
||||
sourceFile = currentProject.findMember(parsedResourceName);
|
||||
}
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
protected URI getBuildDirURI(URI mappedRootURI) {
|
||||
URI buildDirURI = null;
|
||||
|
||||
URI cwdURI = null;
|
||||
if (currentResource!=null && parsedResourceName!=null && !new Path(parsedResourceName).isAbsolute()) {
|
||||
cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName);
|
||||
}
|
||||
if (cwdURI == null && errorParserManager != null) {
|
||||
cwdURI = errorParserManager.getWorkingDirectoryURI();
|
||||
}
|
||||
|
||||
String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null;
|
||||
if (cwdPath != null && mappedRootURI != null) {
|
||||
buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath);
|
||||
} else {
|
||||
buildDirURI = cwdURI;
|
||||
}
|
||||
|
||||
if (buildDirURI == null && currentCfgDescription != null) {
|
||||
IPath builderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD();
|
||||
buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD);
|
||||
}
|
||||
|
||||
if (buildDirURI == null && currentProject != null) {
|
||||
buildDirURI = currentProject.getLocationURI();
|
||||
}
|
||||
|
||||
if (buildDirURI == null && currentResource != null) {
|
||||
IContainer container;
|
||||
if (currentResource instanceof IContainer) {
|
||||
container = (IContainer) currentResource;
|
||||
} else {
|
||||
container = currentResource.getParent();
|
||||
}
|
||||
buildDirURI = container.getLocationURI();
|
||||
}
|
||||
return buildDirURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine URI on the local filesystem considering possible mapping.
|
||||
*
|
||||
* @param pathStr - path to the resource, can be absolute or relative
|
||||
* @param baseURI - base {@link URI} where path to the resource is rooted
|
||||
* @return {@link URI} of the resource
|
||||
*/
|
||||
private static URI determineMappedURI(String pathStr, URI baseURI) {
|
||||
URI uri = null;
|
||||
|
||||
if (baseURI==null) {
|
||||
if (new Path(pathStr).isAbsolute()) {
|
||||
uri = resolvePathFromBaseLocation(pathStr, Path.ROOT);
|
||||
}
|
||||
} else if (baseURI.getScheme().equals(EFS.SCHEME_FILE)) {
|
||||
// location on the local filesystem
|
||||
IPath baseLocation = org.eclipse.core.filesystem.URIUtil.toPath(baseURI);
|
||||
// careful not to use Path here but 'pathStr' as String as we want to properly navigate symlinks
|
||||
uri = resolvePathFromBaseLocation(pathStr, baseLocation);
|
||||
} else {
|
||||
// location on a remote filesystem
|
||||
IPath path = new Path(pathStr); // use canonicalized path here, in particular replace all '\' with '/' for Windows paths
|
||||
URI remoteUri = EFSExtensionManager.getDefault().append(baseURI, path.toString());
|
||||
if (remoteUri!=null) {
|
||||
String localPath = EFSExtensionManager.getDefault().getMappedPath(remoteUri);
|
||||
if (localPath!=null) {
|
||||
uri = org.eclipse.core.filesystem.URIUtil.toURI(localPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uri == null) {
|
||||
// if everything fails just wrap string to URI
|
||||
uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
private static IResource resolveResourceInWorkspace(String parsedName, IProject preferredProject, Set<String> referencedProjectsNames) {
|
||||
IPath path = new Path(parsedName);
|
||||
if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return null;
|
||||
}
|
||||
|
||||
// prefer current project
|
||||
if (preferredProject!=null) {
|
||||
List<IResource> result = findPathInFolder(path, preferredProject);
|
||||
int size = result.size();
|
||||
if (size==1) { // found the one
|
||||
return result.get(0);
|
||||
} else if (size>1) { // ambiguous
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
|
||||
// then prefer referenced projects
|
||||
if (referencedProjectsNames.size() > 0) {
|
||||
IResource rc = null;
|
||||
for (String prjName : referencedProjectsNames) {
|
||||
IProject prj = root.getProject(prjName);
|
||||
if (prj.isOpen()) {
|
||||
List<IResource> result = findPathInFolder(path, prj);
|
||||
int size = result.size();
|
||||
if (size==1 && rc==null) {
|
||||
rc = result.get(0);
|
||||
} else if (size > 0) {
|
||||
// ambiguous
|
||||
rc = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rc!=null) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
// then check all other projects in workspace
|
||||
IProject[] projects = root.getProjects();
|
||||
if (projects.length > 0) {
|
||||
IResource rc = null;
|
||||
for (IProject prj : projects) {
|
||||
if (!prj.equals(preferredProject) && !referencedProjectsNames.contains(prj.getName()) && prj.isOpen()) {
|
||||
List<IResource> result = findPathInFolder(path, prj);
|
||||
int size = result.size();
|
||||
if (size==1 && rc==null) {
|
||||
rc = result.get(0);
|
||||
} else if (size > 0) {
|
||||
// ambiguous
|
||||
rc = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rc!=null) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
// not found or ambiguous
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<IResource> findPathInFolder(IPath path, IContainer folder) {
|
||||
List<IResource> paths = new ArrayList<IResource>();
|
||||
IResource resource = folder.findMember(path);
|
||||
if (resource != null) {
|
||||
paths.add(resource);
|
||||
}
|
||||
|
||||
try {
|
||||
for (IResource res : folder.members()) {
|
||||
if (res instanceof IContainer) {
|
||||
paths.addAll(findPathInFolder(path, (IContainer) res));
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
private static IResource findFileForLocationURI(URI uri, IProject preferredProject) {
|
||||
IResource sourceFile;
|
||||
IResource result = null;
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
IResource[] resources = root.findFilesForLocationURI(uri);
|
||||
if (resources.length > 0) {
|
||||
result = resources[0];
|
||||
if (preferredProject!=null) {
|
||||
for (IResource rc : resources) {
|
||||
if (rc.getProject().equals(preferredProject)) {
|
||||
result = rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceFile = result;
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
private static URI findBaseLocationURI(URI fileURI, String relativeFileName) {
|
||||
URI cwdURI = null;
|
||||
String path = fileURI.getPath();
|
||||
|
||||
String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$
|
||||
|
||||
// start removing segments from the end of the path
|
||||
for (int i = segments.length - 1; i >= 0; i--) {
|
||||
String lastSegment = segments[i];
|
||||
if (lastSegment.length() > 0 && !lastSegment.equals(".")) { //$NON-NLS-1$
|
||||
if (lastSegment.equals("..")) { //$NON-NLS-1$
|
||||
// navigating ".." in the other direction is ambiguous, bailing out
|
||||
return null;
|
||||
} else {
|
||||
if (path.endsWith("/" + lastSegment)) { //$NON-NLS-1$
|
||||
int pos = path.lastIndexOf(lastSegment);
|
||||
path = path.substring(0, pos);
|
||||
continue;
|
||||
} else {
|
||||
// ouch, relativeFileName does not match fileURI, bailing out
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(),
|
||||
fileURI.getPort(), path, fileURI.getQuery(), fileURI.getFragment());
|
||||
} catch (URISyntaxException e) {
|
||||
// It should be valid URI here or something is wrong
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
|
||||
return cwdURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* In case when absolute path is mapped to the source tree in a project
|
||||
* this function will try to figure mapping and return "mapped root",
|
||||
* i.e URI where the root path would be mapped. The mapped root will be
|
||||
* used to prepend to other "absolute" paths where appropriate.
|
||||
*
|
||||
* @param sourceFile - a resource referred by parsed path
|
||||
* @param parsedResourceName - path as appears in the output
|
||||
* @return mapped path as URI
|
||||
*/
|
||||
protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) {
|
||||
if (currentResource==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
URI fileURI = sourceFile.getLocationURI();
|
||||
String mappedRoot = "/"; //$NON-NLS-1$
|
||||
|
||||
if (parsedResourceName!=null) {
|
||||
IPath parsedSrcPath = new Path(parsedResourceName);
|
||||
if (parsedSrcPath.isAbsolute()) {
|
||||
IPath absPath = sourceFile.getLocation();
|
||||
int absSegmentsCount = absPath.segmentCount();
|
||||
int relSegmentsCount = parsedSrcPath.segmentCount();
|
||||
if (absSegmentsCount >= relSegmentsCount) {
|
||||
IPath ending = absPath.removeFirstSegments(absSegmentsCount - relSegmentsCount);
|
||||
ending = ending.setDevice(parsedSrcPath.getDevice()).makeAbsolute();
|
||||
if (ending.equals(parsedSrcPath.makeAbsolute())) {
|
||||
mappedRoot = absPath.removeLastSegments(relSegmentsCount).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
URI uri = EFSExtensionManager.getDefault().createNewURIFromPath(fileURI, mappedRoot);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* The manipulations here are done to resolve "../" navigation for symbolic links where "link/.." cannot
|
||||
* be collapsed as it must follow the real filesystem path. {@link java.io.File#getCanonicalPath()} deals
|
||||
* with that correctly but {@link Path} or {@link URI} try to normalize the path which would be incorrect
|
||||
* here.
|
||||
*/
|
||||
private static URI resolvePathFromBaseLocation(String name, IPath baseLocation) {
|
||||
String pathName = name;
|
||||
if (baseLocation != null && !baseLocation.isEmpty()) {
|
||||
pathName = pathName.replace(File.separatorChar, '/');
|
||||
String device = new Path(pathName).getDevice();
|
||||
if (device==null || device.equals(baseLocation.getDevice())) {
|
||||
if (device != null && device.length() > 0) {
|
||||
pathName = pathName.substring(device.length());
|
||||
}
|
||||
|
||||
baseLocation = baseLocation.addTrailingSeparator();
|
||||
if (pathName.startsWith("/")) { //$NON-NLS-1$
|
||||
pathName = pathName.substring(1);
|
||||
}
|
||||
pathName = baseLocation.toString() + pathName;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(pathName);
|
||||
file = file.getCanonicalFile();
|
||||
return file.toURI();
|
||||
} catch (IOException e) {
|
||||
// if error just leave it as is
|
||||
}
|
||||
|
||||
URI uri = org.eclipse.core.filesystem.URIUtil.toURI(pathName);
|
||||
return uri;
|
||||
}
|
||||
|
||||
private static IResource findResourceForLocationURI(URI uri, int kind, IProject preferredProject) {
|
||||
if (uri==null)
|
||||
return null;
|
||||
|
||||
IResource resource = null;
|
||||
|
||||
switch (kind) {
|
||||
case ICSettingEntry.INCLUDE_PATH:
|
||||
case ICSettingEntry.LIBRARY_PATH:
|
||||
resource = findContainerForLocationURI(uri, preferredProject);
|
||||
break;
|
||||
case ICSettingEntry.INCLUDE_FILE:
|
||||
case ICSettingEntry.MACRO_FILE:
|
||||
resource = findFileForLocationURI(uri, preferredProject);
|
||||
break;
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
private static IResource findContainerForLocationURI(URI uri, IProject preferredProject) {
|
||||
IResource resource = null;
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
IResource[] resources = root.findContainersForLocationURI(uri);
|
||||
if (resources.length > 0) {
|
||||
for (IResource rc : resources) {
|
||||
if ((rc instanceof IProject || rc instanceof IFolder)) { // treat IWorkspaceRoot as non-workspace path
|
||||
IProject prj = rc instanceof IProject ? (IProject)rc : rc.getProject();
|
||||
if (prj.equals(preferredProject)) {
|
||||
resource = rc;
|
||||
break;
|
||||
}
|
||||
if (resource==null) {
|
||||
resource=rc; // to be deterministic the first qualified resource has preference
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
private static IPath getFilesystemLocation(URI uri) {
|
||||
if (uri==null)
|
||||
return null;
|
||||
|
||||
// EFSExtensionManager mapping
|
||||
String pathStr = EFSExtensionManager.getDefault().getMappedPath(uri);
|
||||
uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr);
|
||||
|
||||
try {
|
||||
File file = new java.io.File(uri);
|
||||
String canonicalPathStr = file.getCanonicalPath();
|
||||
return new Path(canonicalPathStr);
|
||||
} catch (Exception e) {
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
private static String expressionLogicalOr(Set<String> fileExts) {
|
||||
String pattern = "(";
|
||||
for (String ext : fileExts) {
|
||||
if (pattern.length() != 1)
|
||||
pattern += "|";
|
||||
pattern += "(" + Pattern.quote(ext) + ")";
|
||||
ext = ext.toUpperCase();
|
||||
if (!fileExts.contains(ext)) {
|
||||
pattern += "|(" + Pattern.quote(ext) + ")";
|
||||
}
|
||||
}
|
||||
pattern += ")";
|
||||
return pattern;
|
||||
}
|
||||
|
||||
protected static int countGroups(String str) {
|
||||
@SuppressWarnings("nls")
|
||||
int count = str.replaceAll("[^\\(]", "").length();
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element serialize(Element parentElement) {
|
||||
Element elementProvider = super.serialize(parentElement);
|
||||
elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths));
|
||||
return elementProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Element providerNode) {
|
||||
super.load(providerNode);
|
||||
|
||||
String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS);
|
||||
if (expandRelativePathsValue!=null)
|
||||
isResolvingPaths = Boolean.parseBoolean(expandRelativePathsValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + (isResolvingPaths ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractLanguageSettingsOutputScanner other = (AbstractLanguageSettingsOutputScanner) obj;
|
||||
if (isResolvingPaths != other.isResolvingPaths)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.core.scannerconfig;
|
||||
|
||||
|
||||
import org.eclipse.cdt.core.errorparsers.RegexErrorPattern;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
|
||||
public class GCCBuildCommandParser extends AbstractBuildCommandParser implements
|
||||
ILanguageSettingsEditableProvider {
|
||||
@SuppressWarnings("nls")
|
||||
static final AbstractOptionParser[] optionParsers = {
|
||||
new IncludePathOptionParser("-I\\s*([\"'])(.*)\\1", "$2"),
|
||||
new IncludePathOptionParser("-I\\s*([^\\s\"']*)", "$1"),
|
||||
new IncludeFileOptionParser("-include\\s*([\"'])(.*)\\1", "$2"),
|
||||
new IncludeFileOptionParser("-include\\s*([^\\s\"']*)", "$1"),
|
||||
new MacroOptionParser("-D\\s*([\"'])([^=]*)(=(.*))?\\1", "$2", "$4"),
|
||||
new MacroOptionParser("-D\\s*([^\\s=\"']*)=(\\\\([\"']))(.*?)\\2", "$1", "$3$4$3"),
|
||||
new MacroOptionParser("-D\\s*([^\\s=\"']*)=([\"'])(.*?)\\2", "$1", "$3"),
|
||||
new MacroOptionParser("-D\\s*([^\\s=\"']*)(=([^\\s\"']*))?", "$1", "$3"),
|
||||
new MacroOptionParser("-U\\s*([^\\s=\"']*)", "$1", ICSettingEntry.UNDEFINED),
|
||||
new MacroFileOptionParser("-macros\\s*([\"'])(.*)\\1", "$2"),
|
||||
new MacroFileOptionParser("-macros\\s*([^\\s\"']*)", "$1"),
|
||||
new LibraryPathOptionParser("-L\\s*([\"'])(.*)\\1", "$2"),
|
||||
new LibraryPathOptionParser("-L\\s*([^\\s\"']*)", "$1"),
|
||||
new LibraryFileOptionParser("-l\\s*([^\\s\"']*)", "lib$1.a"), };
|
||||
|
||||
@Override
|
||||
protected AbstractOptionParser[] getOptionParsers() {
|
||||
return optionParsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GCCBuildCommandParser cloneShallow() throws CloneNotSupportedException {
|
||||
return (GCCBuildCommandParser) super.cloneShallow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GCCBuildCommandParser clone() throws CloneNotSupportedException {
|
||||
return (GCCBuildCommandParser) super.clone();
|
||||
}
|
||||
|
||||
public static class GCCBuildCommandPatternHighlighter extends AbstractBuildCommandParser.AbstractBuildCommandPatternHighlighter {
|
||||
// ID of the parser taken from the extension point
|
||||
private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$
|
||||
|
||||
public GCCBuildCommandPatternHighlighter() {
|
||||
super(GCC_BUILD_COMMAND_PARSER_EXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
GCCBuildCommandPatternHighlighter that = new GCCBuildCommandPatternHighlighter();
|
||||
that.setId(getId());
|
||||
that.setName(getName());
|
||||
for (RegexErrorPattern pattern : getPatterns()) {
|
||||
that.addPattern((RegexErrorPattern)pattern.clone());
|
||||
}
|
||||
return that;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.core.scannerconfig;
|
||||
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.IErrorParser;
|
||||
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
|
||||
|
||||
/**
|
||||
* Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having
|
||||
* no access from CDT core to build packages.
|
||||
*/
|
||||
public interface ILanguageSettingsBuildOutputScanner extends ILanguageSettingsOutputScanner, IErrorParser {
|
||||
|
||||
/**
|
||||
* This method is expected to populate this.settingEntries with specific values
|
||||
* parsed from supplied lines.
|
||||
*/
|
||||
public boolean processLine(String line, ErrorParserManager epm);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.core.scannerconfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public interface ILanguageSettingsBuiltinSpecsDetector extends ILanguageSettingsProvider {
|
||||
public List<String> getLanguageScope();
|
||||
public void run(IProject project, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException;
|
||||
public void run(ICConfigurationDescription cfgDescription, String languageId, IPath workingDirectory, String[] env, IProgressMonitor monitor) throws CoreException, IOException;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.core.scannerconfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.ICConsoleParser;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* TODO: Is this interface superfluous?
|
||||
*/
|
||||
public interface ILanguageSettingsOutputScanner extends ILanguageSettingsProvider, ICConsoleParser {
|
||||
|
||||
// Inherited from ICConsoleParser
|
||||
public void startup(ICConfigurationDescription cfgDescription) throws CoreException;
|
||||
public boolean processLine(String line);
|
||||
public void shutdown();
|
||||
|
||||
// Inherited from ICLanguageSettingsProvider
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
||||
}
|
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/inspect_system.gif
Normal file
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/inspect_system.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 553 B |
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/log_obj.gif
Normal file
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/log_obj.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 335 B |
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/search.gif
Normal file
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/search.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 347 B |
|
@ -44,6 +44,9 @@ PreferenceBuildSettings.name=Settings
|
|||
ErrorParsersTab.name=Error Parsers
|
||||
ErrorParsersTab.tooltip=Error Parsers scan build output and report errors in Problems view
|
||||
|
||||
LanguageSettingsProvidersTab.name=Discovery
|
||||
LanguageSettingsProvidersTab.tooltip=Language settings providers
|
||||
|
||||
PreferenceMakeProject.name=New Make Projects
|
||||
PreferenceMake.name=Make Targets
|
||||
PreferenceMakefileEditor.name=Makefile Editor
|
||||
|
|
|
@ -470,6 +470,14 @@
|
|||
tooltip="%ErrorParsersTab.tooltip"
|
||||
weight="020">
|
||||
</tab>
|
||||
<tab
|
||||
class="org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderTab"
|
||||
icon="icons/obj16/search.gif"
|
||||
name="%LanguageSettingsProvidersTab.name"
|
||||
parent="org.eclipse.cdt.make.internal.ui.preferences.BuildSettingsPreferencePage"
|
||||
tooltip="%LanguageSettingsProvidersTab.tooltip"
|
||||
weight="000">
|
||||
</tab>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
|
@ -532,4 +540,27 @@
|
|||
</description>
|
||||
</fontDefinition>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.LanguageSettingsProviderAssociation">
|
||||
<class-association
|
||||
class="org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector"
|
||||
icon="icons/obj16/inspect_system.gif">
|
||||
</class-association>
|
||||
<class-association
|
||||
icon="icons/obj16/log_obj.gif"
|
||||
class="org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner">
|
||||
</class-association>
|
||||
<class-association
|
||||
class="org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser"
|
||||
icon="icons/obj16/log_obj.gif"
|
||||
page="org.eclipse.cdt.make.internal.ui.preferences.GCCBuildCommandParserOptionPage">
|
||||
</class-association>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.CBuildConsole">
|
||||
<CBuildConsole
|
||||
id="org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole"
|
||||
class="org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole">
|
||||
</CBuildConsole>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,370 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage;
|
||||
import org.eclipse.cdt.internal.ui.newui.StatusMessageLine;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* Options page for TODO
|
||||
*
|
||||
*/
|
||||
public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSettingProviderOptionPage {
|
||||
private boolean fEditable;
|
||||
|
||||
private Text inputCommand;
|
||||
|
||||
private StatusMessageLine fStatusLine;
|
||||
private Button runOnceRadioButton;
|
||||
private Button runEveryBuildRadioButton;
|
||||
private Button expandRelativePathCheckBox;
|
||||
private Button applyToProjectCheckBox;
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
// Composite optionsPageComposite = new Composite(composite, SWT.NULL);
|
||||
fEditable = parent.isEnabled();
|
||||
|
||||
final Composite composite = new Composite(parent, SWT.NONE);
|
||||
{
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
layout.marginWidth = 1;
|
||||
layout.marginHeight = 1;
|
||||
layout.marginRight = 1;
|
||||
composite.setLayout(layout);
|
||||
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
Dialog.applyDialogFont(composite);
|
||||
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 2;
|
||||
composite.setLayoutData(gd);
|
||||
}
|
||||
|
||||
|
||||
// Group groupRun = new Group(composite, SWT.SHADOW_ETCHED_IN);
|
||||
//// groupRun.setText("Language Settings Provider Options");
|
||||
//
|
||||
// GridLayout gridLayoutRun = new GridLayout();
|
||||
//// GridLayout gridLayoutRun = new GridLayout(2, true);
|
||||
//// gridLayoutRun.makeColumnsEqualWidth = false;
|
||||
//// gridLayoutRun.marginRight = -10;
|
||||
//// gridLayoutRun.marginLeft = -4;
|
||||
// groupRun.setLayout(gridLayoutRun);
|
||||
//// GridData gdRun = new GridData(GridData.FILL_HORIZONTAL);
|
||||
//// gdRun.horizontalSpan = 2;
|
||||
//// groupRun.setLayoutData(gdRun);
|
||||
|
||||
AbstractBuildCommandParser provider = getRawProvider();
|
||||
// {
|
||||
// runOnceRadioButton = new Button(groupRun, SWT.RADIO);
|
||||
// runOnceRadioButton.setText("Run only once"); //$NON-NLS-1$
|
||||
// // b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$
|
||||
// GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
// gd.horizontalSpan = 3;
|
||||
// runOnceRadioButton.setLayoutData(gd);
|
||||
// runOnceRadioButton.setSelection(provider.isRunOnce());
|
||||
// runOnceRadioButton.setEnabled(fEditable);
|
||||
// runOnceRadioButton.addSelectionListener(new SelectionAdapter() {
|
||||
// @Override
|
||||
// public void widgetSelected(SelectionEvent evt) {
|
||||
// boolean runOnceEnabled = runOnceRadioButton.getSelection();
|
||||
// if (runOnceEnabled) {
|
||||
// AbstractBuildCommandParser provider = getRawProvider();
|
||||
// if (runOnceEnabled != provider.isRunOnce()) {
|
||||
// AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId);
|
||||
// selectedProvider.setRunOnce(runOnceEnabled);
|
||||
// providerTab.refreshItem(selectedProvider);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// }
|
||||
// {
|
||||
// runEveryBuildRadioButton = new Button(groupRun, SWT.RADIO);
|
||||
// runEveryBuildRadioButton.setText("Activate on every build"); //$NON-NLS-1$
|
||||
// runEveryBuildRadioButton.setSelection(!provider.isRunOnce());
|
||||
// runEveryBuildRadioButton.setEnabled(fEditable);
|
||||
// GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
// gd.horizontalSpan = 3;
|
||||
// runEveryBuildRadioButton.setLayoutData(gd);
|
||||
// runEveryBuildRadioButton.addSelectionListener(new SelectionAdapter() {
|
||||
// @Override
|
||||
// public void widgetSelected(SelectionEvent evt) {
|
||||
// boolean runEveryBuildEnabled = runEveryBuildRadioButton.getSelection();
|
||||
// if (runEveryBuildEnabled) {
|
||||
// AbstractBuildCommandParser provider = getRawProvider();
|
||||
// if (runEveryBuildEnabled != !provider.isRunOnce()) {
|
||||
// AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId);
|
||||
// selectedProvider.setRunOnce(!runEveryBuildEnabled);
|
||||
// providerTab.refreshItem(selectedProvider);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// Compiler specs command
|
||||
{
|
||||
Label label = ControlFactory.createLabel(composite, "Compiler command pattern:");
|
||||
GridData gd = new GridData();
|
||||
gd.horizontalSpan = 1;
|
||||
label.setLayoutData(gd);
|
||||
label.setEnabled(fEditable);
|
||||
}
|
||||
|
||||
{
|
||||
inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER);
|
||||
String customParameter = provider.getCustomParameter();
|
||||
inputCommand.setText(customParameter!=null ? customParameter : "");
|
||||
|
||||
GridData gd = new GridData();
|
||||
gd.horizontalSpan = 1;
|
||||
gd.grabExcessHorizontalSpace = true;
|
||||
gd.horizontalAlignment = SWT.FILL;
|
||||
inputCommand.setLayoutData(gd);
|
||||
inputCommand.setEnabled(fEditable);
|
||||
|
||||
inputCommand.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
String text = inputCommand.getText();
|
||||
AbstractBuildCommandParser provider = getRawProvider();
|
||||
if (!text.equals(provider.getCustomParameter())) {
|
||||
AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setCustomParameter(text);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// {
|
||||
// Button button = ControlFactory.createPushButton(composite, "Browse...");
|
||||
// button.setEnabled(fEditable);
|
||||
// button.addSelectionListener(new SelectionAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void widgetSelected(SelectionEvent evt) {
|
||||
//// handleAddr2LineButtonSelected();
|
||||
// //updateLaunchConfigurationDialog();
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// }
|
||||
|
||||
// {
|
||||
// final Button button = new Button(composite, SWT.PUSH);
|
||||
// button.setFont(parent.getFont());
|
||||
// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear";
|
||||
// button.setText(text);
|
||||
//// button.addSelectionListener(this);
|
||||
// GridData data = new GridData();
|
||||
// data.horizontalSpan = 2;
|
||||
//// data.horizontalAlignment = GridData.BEGINNING;
|
||||
//// data.widthHint = 60;
|
||||
// button.setLayoutData(data);
|
||||
// // TODO
|
||||
// button.setEnabled(fEditable && !fProvider.isEmpty());
|
||||
//
|
||||
// button.addSelectionListener(new SelectionAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void widgetSelected(SelectionEvent evt) {
|
||||
// if (fProvider.isEmpty()) {
|
||||
// // TODO
|
||||
// } else {
|
||||
// fProvider.clear();
|
||||
// }
|
||||
// // TODO
|
||||
// button.setEnabled(fEditable && !fProvider.isEmpty());
|
||||
// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear";
|
||||
// button.setText(text);
|
||||
// button.pack();
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// }
|
||||
|
||||
// // Compiler specs command
|
||||
// {
|
||||
// Label label = ControlFactory.createLabel(composite, "Parsing rules:");
|
||||
// GridData gd = new GridData();
|
||||
// gd.horizontalSpan = 2;
|
||||
// label.setLayoutData(gd);
|
||||
//// Label newLabel = new Label(composite, SWT.NONE);
|
||||
////// ((GridData) newLabel.getLayoutData()).horizontalSpan = 1;
|
||||
//// newLabel.setText("Command to get compiler specs:");
|
||||
// }
|
||||
|
||||
|
||||
// createPatternsTable(group, composite);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
|
||||
// group.setText(DialogsMessages.RegexErrorParserOptionPage_Title);
|
||||
//
|
||||
// GridLayout gridLayout = new GridLayout(2, true);
|
||||
// gridLayout.makeColumnsEqualWidth = false;
|
||||
// gridLayout.marginRight = -10;
|
||||
// gridLayout.marginLeft = -4;
|
||||
// group.setLayout(gridLayout);
|
||||
// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
//
|
||||
// Composite composite = new Composite(group, SWT.NONE);
|
||||
// GridLayout layout = new GridLayout();
|
||||
// layout.numColumns = 2;
|
||||
// layout.marginWidth = 1;
|
||||
// layout.marginHeight = 1;
|
||||
// layout.marginRight = 1;
|
||||
// composite.setLayout(layout);
|
||||
// composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
// Dialog.applyDialogFont(composite);
|
||||
//
|
||||
// if (!fEditable)
|
||||
// createLinkToPreferences(composite);
|
||||
//
|
||||
// createPatternsTable(group, composite);
|
||||
//
|
||||
// if (fEditable) {
|
||||
// createButtons(composite);
|
||||
// }
|
||||
|
||||
{
|
||||
expandRelativePathCheckBox = new Button(composite, SWT.CHECK);
|
||||
expandRelativePathCheckBox.setText("Use heuristics to resolve paths");
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 2;
|
||||
expandRelativePathCheckBox.setLayoutData(gd);
|
||||
|
||||
expandRelativePathCheckBox.setSelection(provider.isResolvingPaths());
|
||||
expandRelativePathCheckBox.setEnabled(fEditable);
|
||||
expandRelativePathCheckBox.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean enabled = expandRelativePathCheckBox.getSelection();
|
||||
AbstractBuildCommandParser provider = getRawProvider();
|
||||
if (enabled != provider.isResolvingPaths()) {
|
||||
AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setResolvingPaths(enabled);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
widgetSelected(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
applyToProjectCheckBox = new Button(composite, SWT.CHECK);
|
||||
applyToProjectCheckBox.setText("Apply discovered settings on project level");
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 2;
|
||||
applyToProjectCheckBox.setLayoutData(gd);
|
||||
|
||||
// applyToProjectCheckBox.setSelection(provider.isExpandRelativePaths());
|
||||
// applyToProjectCheckBox.setEnabled(fEditable);
|
||||
applyToProjectCheckBox.setSelection(false);
|
||||
applyToProjectCheckBox.setEnabled(false);
|
||||
applyToProjectCheckBox.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean enabled = applyToProjectCheckBox.getSelection();
|
||||
AbstractBuildCommandParser provider = getRawProvider();
|
||||
if (enabled != provider.isResolvingPaths()) {
|
||||
AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setResolvingPaths(enabled);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
widgetSelected(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// // Status line
|
||||
// if (fEditable) {
|
||||
// fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2);
|
||||
// IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)");
|
||||
// fStatusLine.setErrorStatus(status);
|
||||
// }
|
||||
|
||||
setControl(composite);
|
||||
}
|
||||
|
||||
private AbstractBuildCommandParser getRawProvider() {
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getRawProvider(providerTab.getProvider(providerId));
|
||||
Assert.isTrue(provider instanceof AbstractBuildCommandParser);
|
||||
return (AbstractBuildCommandParser) provider;
|
||||
}
|
||||
|
||||
private AbstractBuildCommandParser getWorkingCopy(String providerId) {
|
||||
ILanguageSettingsProvider provider = providerTab.getWorkingCopy(providerId);
|
||||
Assert.isTrue(provider instanceof AbstractBuildCommandParser);
|
||||
return (AbstractBuildCommandParser) provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
// handled by LanguageSettingsProviderTab
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performDefaults() {
|
||||
// handled by LanguageSettingsProviderTab
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.scannerconfig;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.buildconsole.CBuildConsole;
|
||||
import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProviderAssociation;
|
||||
|
||||
public class ScannerDiscoveryConsole extends CBuildConsole {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param consoleId - a console ID is expected here which then is used as menu context ID.
|
||||
* @param defaultIconUrl - if {@code LanguageSettingsProviderAssociation} extension point
|
||||
* defines URL by provider id, {@code defaultIconUrl} will be ignored and the URL from the extension
|
||||
* point will be used. If not, supplied {@code defaultIconUrl} will be used.
|
||||
*/
|
||||
@Override
|
||||
public void init(String consoleId, String name, URL defaultIconUrl) {
|
||||
URL iconUrl = LanguageSettingsProviderAssociation.getImageUrl(consoleId);
|
||||
if (iconUrl==null) {
|
||||
iconUrl = defaultIconUrl;
|
||||
}
|
||||
|
||||
super.init(consoleId, name, iconUrl);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.build.core.scannerconfig.tests.CfgScannerConfigProfileManagerTests;
|
||||
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest;
|
||||
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
|
@ -59,6 +60,7 @@ public class AllManagedBuildTests {
|
|||
// build.core.scannerconfig.tests
|
||||
suite.addTest(CfgScannerConfigProfileManagerTests.suite());
|
||||
suite.addTestSuite(GCCSpecsConsoleParserTest.class);
|
||||
suite.addTestSuite(GCCBuiltinSpecsDetectorTest.class);
|
||||
|
||||
// managedbuilder.core.tests
|
||||
suite.addTest(ManagedBuildCoreTests20.suite());
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.build.core.scannerconfig.tests;
|
||||
|
||||
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCBuiltinSpecsDetectorTest;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class AllSD80Tests extends TestSuite {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new AllSD80Tests();
|
||||
}
|
||||
|
||||
public AllSD80Tests() {
|
||||
super(AllSD80Tests.class.getName());
|
||||
|
||||
addTestSuite(GCCBuiltinSpecsDetectorTest.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,746 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.build.core.scannerconfig.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryPathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector;
|
||||
import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector;
|
||||
import org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetectorCygwin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class GCCBuiltinSpecsDetectorTest extends TestCase {
|
||||
private static final String PROVIDER_ID = "provider.id";
|
||||
private static final String PROVIDER_NAME = "provider name";
|
||||
private static final String LANGUAGE_ID = "language.test.id";
|
||||
private static final String LANGUAGE_ID_C = "org.eclipse.cdt.core.gcc";
|
||||
private static final String LANGUAGE_ID_CPP = "org.eclipse.cdt.core.g++";
|
||||
private static final String CUSTOM_PARAMETER = "customParameter";
|
||||
private static final String ELEM_TEST = "test";
|
||||
|
||||
// those attributes must match that in AbstractBuiltinSpecsDetector
|
||||
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
|
||||
private static final String ATTR_RUN_ONCE = "run-once"; //$NON-NLS-1$
|
||||
|
||||
private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector {
|
||||
@Override
|
||||
protected String getToolchainId() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected List<String> parseForOptions(String line) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected AbstractOptionParser[] getOptionParsers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
ResourceHelper.cleanUp();
|
||||
}
|
||||
|
||||
private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) {
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager();
|
||||
// project description
|
||||
ICProjectDescription projectDescription = mngr.getProjectDescription(project);
|
||||
assertNotNull(projectDescription);
|
||||
assertEquals(1, projectDescription.getConfigurations().length);
|
||||
// configuration description
|
||||
ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations();
|
||||
return cfgDescriptions;
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception {
|
||||
// define mock detector
|
||||
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector();
|
||||
|
||||
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null);
|
||||
assertEquals(PROVIDER_ID, detector.getId());
|
||||
assertEquals(PROVIDER_NAME, detector.getName());
|
||||
assertEquals(null, detector.getLanguageScope());
|
||||
assertEquals(null, detector.getSettingEntries(null, null, null));
|
||||
assertEquals(null, detector.getCustomParameter());
|
||||
|
||||
List<String> languages = new ArrayList<String>();
|
||||
languages.add(LANGUAGE_ID);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
entries.add(entry);
|
||||
|
||||
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER);
|
||||
assertEquals(PROVIDER_ID, detector.getId());
|
||||
assertEquals(PROVIDER_NAME, detector.getName());
|
||||
assertEquals(languages, detector.getLanguageScope());
|
||||
assertEquals(entries, detector.getSettingEntries(null, null, null));
|
||||
assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter());
|
||||
|
||||
assertEquals(true, detector.isRunOnce());
|
||||
detector.setRunOnce(false);
|
||||
assertEquals(false, detector.isRunOnce());
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception {
|
||||
// define mock detector
|
||||
class MockDetectorCloneable extends MockBuiltinSpecsDetector implements Cloneable {
|
||||
@Override
|
||||
public MockDetectorCloneable clone() throws CloneNotSupportedException {
|
||||
return (MockDetectorCloneable) super.clone();
|
||||
}
|
||||
@Override
|
||||
public MockDetectorCloneable cloneShallow() throws CloneNotSupportedException {
|
||||
return (MockDetectorCloneable) super.cloneShallow();
|
||||
}
|
||||
}
|
||||
|
||||
// create instance to compare to
|
||||
MockDetectorCloneable detector = new MockDetectorCloneable();
|
||||
|
||||
List<String> languages = new ArrayList<String>();
|
||||
languages.add(LANGUAGE_ID);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
entries.add(entry);
|
||||
|
||||
// check clone after initialization
|
||||
MockDetectorCloneable clone0 = detector.clone();
|
||||
assertTrue(detector.equals(clone0));
|
||||
|
||||
// configure provider
|
||||
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER);
|
||||
assertEquals(true, detector.isRunOnce());
|
||||
detector.setRunOnce(false);
|
||||
assertFalse(detector.equals(clone0));
|
||||
|
||||
// check another clone after configuring
|
||||
{
|
||||
MockDetectorCloneable clone = detector.clone();
|
||||
assertTrue(detector.equals(clone));
|
||||
}
|
||||
|
||||
// check custom parameter
|
||||
{
|
||||
MockDetectorCloneable clone = detector.clone();
|
||||
clone.setCustomParameter("changed");
|
||||
assertFalse(detector.equals(clone));
|
||||
}
|
||||
|
||||
// check language scope
|
||||
{
|
||||
MockDetectorCloneable clone = detector.clone();
|
||||
clone.setLanguageScope(null);
|
||||
assertFalse(detector.equals(clone));
|
||||
}
|
||||
|
||||
// check 'run once' flag
|
||||
{
|
||||
MockDetectorCloneable clone = detector.clone();
|
||||
boolean runOnce = clone.isRunOnce();
|
||||
clone.setRunOnce( ! runOnce );
|
||||
assertFalse(detector.equals(clone));
|
||||
}
|
||||
|
||||
// check console flag
|
||||
{
|
||||
MockDetectorCloneable clone = detector.clone();
|
||||
boolean isConsoleEnabled = clone.isConsoleEnabled();
|
||||
clone.setConsoleEnabled( ! isConsoleEnabled );
|
||||
assertFalse(detector.equals(clone));
|
||||
}
|
||||
|
||||
// check entries
|
||||
{
|
||||
MockDetectorCloneable clone = detector.clone();
|
||||
clone.setSettingEntries(null, null, null, null);
|
||||
assertFalse(detector.equals(clone));
|
||||
}
|
||||
|
||||
// check cloneShallow()
|
||||
{
|
||||
MockDetectorCloneable detector2 = detector.clone();
|
||||
MockDetectorCloneable clone = detector2.cloneShallow();
|
||||
assertFalse(detector2.equals(clone));
|
||||
detector2.setSettingEntries(null, null, null, null);
|
||||
assertTrue(detector2.equals(clone));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testAbstractBuiltinSpecsDetector_Serialize() throws Exception {
|
||||
{
|
||||
// create empty XML
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
|
||||
// load it to new provider
|
||||
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector();
|
||||
detector.load(rootElement);
|
||||
assertEquals(true, detector.isRunOnce());
|
||||
assertEquals(false, detector.isConsoleEnabled());
|
||||
}
|
||||
|
||||
Element elementProvider;
|
||||
{
|
||||
// define mock detector
|
||||
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector();
|
||||
assertEquals(true, detector.isRunOnce());
|
||||
assertEquals(false, detector.isConsoleEnabled());
|
||||
|
||||
// redefine the settings
|
||||
detector.setRunOnce(false);
|
||||
assertEquals(false, detector.isRunOnce());
|
||||
detector.setConsoleEnabled(true);
|
||||
assertEquals(true, detector.isConsoleEnabled());
|
||||
|
||||
// serialize in XML
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
elementProvider = detector.serialize(rootElement);
|
||||
String xmlString = XmlUtil.toString(doc);
|
||||
|
||||
assertTrue(xmlString.contains(ATTR_RUN_ONCE));
|
||||
assertTrue(xmlString.contains(ATTR_CONSOLE));
|
||||
}
|
||||
{
|
||||
// create another instance of the provider
|
||||
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector();
|
||||
assertEquals(true, detector.isRunOnce());
|
||||
assertEquals(false, detector.isConsoleEnabled());
|
||||
|
||||
// load element
|
||||
detector.load(elementProvider);
|
||||
assertEquals(false, detector.isRunOnce());
|
||||
assertEquals(true, detector.isConsoleEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception {
|
||||
{
|
||||
// test AbstractBuiltinSpecsDetector.run(...);
|
||||
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector();
|
||||
detector.run((IProject)null, null, null, null, null);
|
||||
// Do not test with (ICConfigurationDescription)null as it is not allowed
|
||||
}
|
||||
|
||||
{
|
||||
// test AbstractBuiltinSpecsDetector.processLine(...) flow
|
||||
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector();
|
||||
detector.startup(null);
|
||||
detector.processLine(null);
|
||||
detector.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_RunConfiguration() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() {
|
||||
@Override
|
||||
protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor,
|
||||
OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException {
|
||||
printLine(consoleOut, "#define MACRO VALUE");
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
|
||||
|
||||
detector.run(cfgDescription, LANGUAGE_ID, null, null, null);
|
||||
assertFalse(detector.isEmpty());
|
||||
|
||||
List<ICLanguageSettingEntry> noentries = detector.getSettingEntries(null, null, null);
|
||||
assertNull(noentries);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_RunProject() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector() {
|
||||
@Override
|
||||
protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor,
|
||||
OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException {
|
||||
printLine(consoleOut, "#define MACRO VALUE");
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
|
||||
|
||||
detector.run(project, LANGUAGE_ID, null, null, null);
|
||||
assertFalse(detector.isEmpty());
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, LANGUAGE_ID);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_RunOnce() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
// Define mock detector which collects number of entries equal to count
|
||||
AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() {
|
||||
int count=0;
|
||||
@Override
|
||||
public boolean processLine(String line) {
|
||||
count++;
|
||||
for (int i=0;i<count;i++) {
|
||||
detectedSettingEntries.add(new CMacroEntry("MACRO", ""+count, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor,
|
||||
OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException {
|
||||
printLine(consoleOut, "dummy line");
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// set to run with each build
|
||||
detector.setRunOnce(false);
|
||||
assertEquals(false, detector.isRunOnce());
|
||||
|
||||
// run first time
|
||||
detector.run(project, LANGUAGE_ID_C, null, null, null);
|
||||
{
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C);
|
||||
assertEquals(1, entries.size());
|
||||
}
|
||||
|
||||
// run second time
|
||||
detector.run(project, LANGUAGE_ID_C, null, null, null);
|
||||
{
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C);
|
||||
assertEquals(2, entries.size());
|
||||
}
|
||||
|
||||
// set to run once
|
||||
detector.setRunOnce(true);
|
||||
assertEquals(true, detector.isRunOnce());
|
||||
assertFalse(detector.isEmpty());
|
||||
|
||||
detector.run(project, LANGUAGE_ID_C, null, null, null);
|
||||
{
|
||||
// should not collect when provider is not empty
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C);
|
||||
assertEquals(2, entries.size());
|
||||
}
|
||||
|
||||
detector.run(cfgDescription, LANGUAGE_ID_C, null, null, null);
|
||||
{
|
||||
// should not collect when provider is not empty
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, LANGUAGE_ID_C);
|
||||
assertEquals(2, entries.size());
|
||||
}
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_Launch() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
|
||||
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() {
|
||||
@Override
|
||||
public boolean processLine(String line) {
|
||||
// pretending that we parsed the line
|
||||
detectedSettingEntries.add(new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
|
||||
detector.setCustomParameter("echo #define MACRO VALUE");
|
||||
|
||||
detector.run(cfgDescription, LANGUAGE_ID, null, null, null);
|
||||
|
||||
List<ICLanguageSettingEntry> noentries = detector.getSettingEntries(null, null, null);
|
||||
assertNull(noentries);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testAbstractBuiltinSpecsDetector_GroupSettings() throws Exception {
|
||||
// define benchmarks
|
||||
final CIncludePathEntry includePath_1 = new CIncludePathEntry("/include/path_1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CIncludePathEntry includePath_2 = new CIncludePathEntry("/include/path_2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CIncludeFileEntry includeFile_1 = new CIncludeFileEntry(new Path("/include.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CIncludeFileEntry includeFile_2 = new CIncludeFileEntry(new Path("/include.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CMacroEntry macro_1 = new CMacroEntry("MACRO_1", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CMacroEntry macro_2 = new CMacroEntry("MACRO_2", "", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY |ICSettingEntry.UNDEFINED);
|
||||
final CMacroFileEntry macroFile_1 = new CMacroFileEntry(new Path("/macro.file1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CMacroFileEntry macroFile_2 = new CMacroFileEntry(new Path("/macro.file2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CLibraryPathEntry libraryPath_1 = new CLibraryPathEntry(new Path("/lib/path_1"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CLibraryPathEntry libraryPath_2 = new CLibraryPathEntry(new Path("/lib/path_2"), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CLibraryFileEntry libraryFile_1 = new CLibraryFileEntry("lib_1.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
|
||||
// Define mock detector adding unorganized entries
|
||||
AbstractBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() {
|
||||
@Override
|
||||
public boolean processLine(String line) {
|
||||
detectedSettingEntries.add(libraryFile_1);
|
||||
detectedSettingEntries.add(libraryPath_1);
|
||||
detectedSettingEntries.add(macroFile_1);
|
||||
detectedSettingEntries.add(macro_1);
|
||||
detectedSettingEntries.add(includeFile_1);
|
||||
detectedSettingEntries.add(includePath_1);
|
||||
|
||||
detectedSettingEntries.add(includePath_2);
|
||||
detectedSettingEntries.add(includeFile_2);
|
||||
detectedSettingEntries.add(macro_2);
|
||||
detectedSettingEntries.add(macroFile_2);
|
||||
detectedSettingEntries.add(libraryPath_2);
|
||||
detectedSettingEntries.add(libraryFile_2);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// run specs detector
|
||||
detector.startup(null);
|
||||
detector.processLine("");
|
||||
detector.shutdown();
|
||||
|
||||
|
||||
// compare benchmarks, expected well-sorted
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
|
||||
int i=0;
|
||||
assertEquals(includePath_1, entries.get(i++));
|
||||
assertEquals(includePath_2, entries.get(i++));
|
||||
assertEquals(includeFile_1, entries.get(i++));
|
||||
assertEquals(includeFile_2, entries.get(i++));
|
||||
assertEquals(macro_1, entries.get(i++));
|
||||
assertEquals(macro_2, entries.get(i++));
|
||||
assertEquals(macroFile_1, entries.get(i++));
|
||||
assertEquals(macroFile_2, entries.get(i++));
|
||||
assertEquals(libraryPath_1, entries.get(i++));
|
||||
assertEquals(libraryPath_2, entries.get(i++));
|
||||
assertEquals(libraryFile_1, entries.get(i++));
|
||||
assertEquals(libraryFile_2, entries.get(i++));
|
||||
|
||||
assertEquals(12, entries.size());
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_NoValue() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_ResolvedCommand() throws Exception {
|
||||
class MockGCCBuiltinSpecsDetector extends GCCBuiltinSpecsDetector {
|
||||
@Override
|
||||
public String resolveCommand(String languageId) throws CoreException {
|
||||
return super.resolveCommand(languageId);
|
||||
}
|
||||
}
|
||||
{
|
||||
MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector();
|
||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||
detector.setCustomParameter("${COMMAND} -E -P -v -dD ${INPUTS}");
|
||||
|
||||
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
|
||||
assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD "));
|
||||
assertTrue(resolvedCommand.endsWith("spec.c"));
|
||||
detector.shutdown();
|
||||
}
|
||||
{
|
||||
MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector();
|
||||
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
|
||||
detector.setCustomParameter("${COMMAND} -E -P -v -dD file.${EXT}");
|
||||
|
||||
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
|
||||
assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD "));
|
||||
assertTrue(resolvedCommand.endsWith("file.c"));
|
||||
detector.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_NoArgs() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO VALUE");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_Const() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO (3)");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "(3)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_EmptyArgList() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO() VALUE");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO()", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_ParamUnused() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO(X) VALUE");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO(X)", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_ParamSpace() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO(P1, P2) VALUE(P1, P2)");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO(P1, P2)", "VALUE(P1, P2)", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Macro_ArgsNoValue() throws Exception {
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#define MACRO(P1, P2) ");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
ICLanguageSettingEntry expected = new CMacroEntry("MACRO(P1, P2)", null, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Includes() throws Exception {
|
||||
// Create model project and folders to test
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProject(projectName);
|
||||
IPath tmpPath = ResourceHelper.createTemporaryFolder();
|
||||
ResourceHelper.createFolder(project, "/misplaced/include1");
|
||||
ResourceHelper.createFolder(project, "/local/include");
|
||||
ResourceHelper.createFolder(project, "/usr/include");
|
||||
ResourceHelper.createFolder(project, "/usr/include2");
|
||||
ResourceHelper.createFolder(project, "/misplaced/include2");
|
||||
ResourceHelper.createFolder(project, "/System/Library/Frameworks");
|
||||
ResourceHelper.createFolder(project, "/Library/Frameworks");
|
||||
ResourceHelper.createFolder(project, "/misplaced/include3");
|
||||
String loc = tmpPath.toString();
|
||||
|
||||
GCCBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
detector.startup(null);
|
||||
|
||||
detector.processLine(" "+loc+"/misplaced/include1");
|
||||
detector.processLine("#include \"...\" search starts here:");
|
||||
detector.processLine(" "+loc+"/local/include");
|
||||
detector.processLine("#include <...> search starts here:");
|
||||
detector.processLine(" "+loc+"/usr/include");
|
||||
detector.processLine(" "+loc+"/usr/include/../include2");
|
||||
detector.processLine(" "+loc+"/missing/folder");
|
||||
detector.processLine(" "+loc+"/Library/Frameworks (framework directory)");
|
||||
detector.processLine("End of search list.");
|
||||
detector.processLine(" "+loc+"/misplaced/include2");
|
||||
detector.processLine("Framework search starts here:");
|
||||
detector.processLine(" "+loc+"/System/Library/Frameworks");
|
||||
detector.processLine("End of framework search list.");
|
||||
detector.processLine(" "+loc+"/misplaced/include3");
|
||||
detector.shutdown();
|
||||
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
assertEquals(new CIncludePathEntry(loc+"/local/include", ICSettingEntry.LOCAL | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
entries.get(0));
|
||||
assertEquals(new CIncludePathEntry(loc+"/usr/include", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
entries.get(1));
|
||||
assertEquals(new CIncludePathEntry(loc+"/usr/include2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
entries.get(2));
|
||||
assertEquals(new CIncludePathEntry(loc+"/missing/folder", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
entries.get(3));
|
||||
assertEquals(new CIncludePathEntry(loc+"/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
entries.get(4));
|
||||
assertEquals(new CIncludePathEntry(loc+"/System/Library/Frameworks", ICSettingEntry.FRAMEWORKS_MAC | ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
entries.get(5));
|
||||
assertEquals(6, entries.size());
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Includes_SymbolicLinkUp() throws Exception {
|
||||
// do not test on systems where symbolic links are not supported
|
||||
if (!ResourceHelper.isSymbolicLinkSupported())
|
||||
return;
|
||||
|
||||
// Create model project and folders to test
|
||||
String projectName = getName();
|
||||
@SuppressWarnings("unused")
|
||||
IProject project = ResourceHelper.createCDTProject(projectName);
|
||||
// create link on the filesystem
|
||||
IPath dir1 = ResourceHelper.createTemporaryFolder();
|
||||
IPath dir2 = dir1.removeLastSegments(1);
|
||||
IPath linkPath = dir1.append("linked");
|
||||
ResourceHelper.createSymbolicLink(linkPath, dir2);
|
||||
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetector();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#include <...> search starts here:");
|
||||
detector.processLine(" "+linkPath.toString()+"/..");
|
||||
detector.processLine("End of search list.");
|
||||
detector.shutdown();
|
||||
|
||||
// check populated entries
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
CIncludePathEntry expected = new CIncludePathEntry(dir2.removeLastSegments(1), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
|
||||
assertEquals(expected, entries.get(0));
|
||||
assertEquals(1, entries.size());
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Cygwin_NoProject() throws Exception {
|
||||
String windowsLocation;
|
||||
String cygwinLocation = "/usr/include";
|
||||
try {
|
||||
windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// Skip the test if Cygwin is not available.
|
||||
return;
|
||||
}
|
||||
assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null);
|
||||
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetectorCygwin();
|
||||
|
||||
detector.startup(null);
|
||||
detector.processLine("#include <...> search starts here:");
|
||||
detector.processLine(" /usr/include");
|
||||
detector.processLine("End of search list.");
|
||||
detector.shutdown();
|
||||
|
||||
// check populated entries
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
assertEquals(new CIncludePathEntry(new Path(windowsLocation), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0));
|
||||
assertEquals(1, entries.size());
|
||||
|
||||
}
|
||||
|
||||
public void testGCCBuiltinSpecsDetector_Cygwin_Configuration() throws Exception {
|
||||
String windowsLocation;
|
||||
String cygwinLocation = "/usr/include";
|
||||
try {
|
||||
windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// Skip the test if Cygwin is not available.
|
||||
return;
|
||||
}
|
||||
assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null);
|
||||
|
||||
|
||||
// Create model project and folders to test
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
AbstractBuiltinSpecsDetector detector = new GCCBuiltinSpecsDetectorCygwin();
|
||||
|
||||
detector.startup(cfgDescription);
|
||||
detector.processLine("#include <...> search starts here:");
|
||||
detector.processLine(" /usr/include");
|
||||
detector.processLine("End of search list.");
|
||||
detector.shutdown();
|
||||
|
||||
// check populated entries
|
||||
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null);
|
||||
assertEquals(new CIncludePathEntry(new Path(windowsLocation), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY), entries.get(0));
|
||||
assertEquals(1, entries.size());
|
||||
}
|
||||
|
||||
}
|
|
@ -308,6 +308,7 @@
|
|||
</managedBuildRevision>
|
||||
<configuration
|
||||
id="org.eclipse.cdt.build.core.emptycfg"
|
||||
languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;${Toolchain}"
|
||||
name="%cfg1_empty">
|
||||
</configuration>
|
||||
|
||||
|
@ -597,6 +598,25 @@
|
|||
</run>
|
||||
</application>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider
|
||||
class="org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetector"
|
||||
id="org.eclipse.cdt.managedbuilder.core.gcc.specs.detector"
|
||||
name="CDT GCC Builtin Compiler Settings"
|
||||
parameter="${COMMAND} -E -P -v -dD ${INPUTS}">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.managedbuilder.internal.scannerconfig.GCCBuiltinSpecsDetectorCygwin"
|
||||
id="org.eclipse.cdt.managedbuilder.core.cygwin.gcc.specs.detector"
|
||||
name="CDT GCC Builtin Compiler Settings Cygwin"
|
||||
parameter="sh -c "${COMMAND} -E -P -v -dD ${INPUTS}"">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
</extension>
|
||||
<extension
|
||||
id="headlessSettings"
|
||||
name="HeadlessBuilder Additional Settings"
|
||||
|
@ -605,5 +625,13 @@
|
|||
class="org.eclipse.cdt.managedbuilder.internal.core.HeadlessBuilderExternalSettingsProvider">
|
||||
</provider>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider
|
||||
class="org.eclipse.cdt.managedbuilder.internal.scannerconfig.MBSLanguageSettingsProvider"
|
||||
id="org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"
|
||||
name="CDT Managed Build Setting Entries">
|
||||
</provider>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -263,7 +263,16 @@ Specifying this attribute is fully equivalent to specifying the "org.eclips
|
|||
<attribute name="errorParsers" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The semi-colon separated list of the default error parsers to be used with this configuration. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. The list of error parsers to be used may be changed by the user on a per-configuration basis. When specified, this overrides the tool-chain errorParsers attribute.
|
||||
The semi-colon separated list of the default error parsers to be used with this configuration. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. The list of error parsers to be used may be changed by the user on a per-configuration basis. When specified, this overrides the tool-chain errorParsers attribute.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="languageSettingsProviders" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Semicolon-separated list of providers ID implementing ILanguageSettingProvider interface.
|
||||
This field could be amended with toolchain-level providers list by using ${Toolchain} keyword. Provider ID can be prefixed with "*", in this case shared instance of the provider defined on workspace level is used. Also provider ID can be prefixed with "-" which will cause id to be removed from the preceeding list including providers defined with ${Toolchain} keyword.
|
||||
If this field is not specified, "*org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider" (MBS Language Settings Provider) is used by default.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
@ -405,7 +414,15 @@ Specifying this attribute is fully equivalent to specifying the "org.eclips
|
|||
<attribute name="errorParsers" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The semi-colon separated list of the default error parsers to be used with this tool-chain. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. When specified, this overrides the tool errorParsers attributes of the tool children of the tool-chain and the builder child of the tool-chain.
|
||||
The semi-colon separated list of the default error parsers to be used with this tool-chain. The list is ordered with the first error parser on the list invoked first, the second error parser second, and so on. The list may contain the error parsers defined by CDT and/or other installed error parser extensions. When specified, this overrides the tool errorParsers attributes of the tool children of the tool-chain and the builder child of the tool-chain.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="languageSettingsProviders" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Semicolon-separated list of providers ID implementing ILanguageSettingProvider interface. Provider ID can be prefixed with "*", in this case shared instance of the provider defined on workspace level is used.
|
||||
This list could be adjusted on configuration level in the corresponding attribute.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
@ -732,14 +749,14 @@ The pathConverter of a toolchain applies for all tools of the toolchain except i
|
|||
<attribute name="customBuildStep" type="boolean">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Specifies whether this Tool represents a user-define custom build step. The default is false. When True, the default value of the commandLinePattern attribute changes to “$(command)”.
|
||||
Specifies whether this Tool represents a user-define custom build step. The default is false. When True, the default value of the commandLinePattern attribute changes to “$(command)�.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="announcement" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Specifies a string that is written to the build output prior to each invocation of the tool. The default value is “Invoking tool-name (tool-id)…”
|
||||
Specifies a string that is written to the build output prior to each invocation of the tool. The default value is “Invoking tool-name (tool-id)…�
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
|
@ -1066,7 +1083,7 @@ Overrides language id specified with the languageId attribute.
|
|||
<attribute name="primaryInputType" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The id of the input type that is used in determining the build “rules” for the output type and for the default name of the output file. The default is the input type with primaryInput == true.
|
||||
The id of the input type that is used in determining the build “rules� for the output type and for the default name of the output file. The default is the input type with primaryInput == true.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
@ -1080,7 +1097,7 @@ Overrides language id specified with the languageId attribute.
|
|||
<attribute name="outputPrefix" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Some tools produce files with a special prefix that must be specified. For example, a librarian on POSIX systems expects the output to be libtarget.a, so 'lib' would be the prefix. The default is to use the Tool “outputPrefix” attribute if primaryOutput is True, otherwise the default is an empty string. This attribute supports MBS configuration context macros.
|
||||
Some tools produce files with a special prefix that must be specified. For example, a librarian on POSIX systems expects the output to be libtarget.a, so 'lib' would be the prefix. The default is to use the Tool “outputPrefix� attribute if primaryOutput is True, otherwise the default is an empty string. This attribute supports MBS configuration context macros.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
@ -2016,11 +2033,11 @@ If the "buildPathResolver" attribute is specified, the "pathDelim
|
|||
<documentation>
|
||||
Represents the applicability type for this enablement.
|
||||
Can contain the following values:
|
||||
UI_VISIBILITY – the given enablement expression specifies whether the option is to be visible in UI,
|
||||
UI_ENABLEMENT – the given enablement expression specifies the enable state of the controls that represent the option in UI,
|
||||
CMD_USAGE – the given enablement expression specifies whether the option is to be used in command line
|
||||
UI_VISIBILITY – the given enablement expression specifies whether the option is to be visible in UI,
|
||||
UI_ENABLEMENT – the given enablement expression specifies the enable state of the controls that represent the option in UI,
|
||||
CMD_USAGE – the given enablement expression specifies whether the option is to be used in command line
|
||||
CONTAINER_ATTRIBUTE - the given enablement expressions specifies thecontainer attribute value
|
||||
ALL – this value means the combination of all the above values.
|
||||
ALL – this value means the combination of all the above values.
|
||||
|
||||
Several types could be specified simultaneously using the "|" as a delimiter, e.g.:
|
||||
type="UI_VISIBILITY|CMD_USAGE"
|
||||
|
@ -2154,7 +2171,7 @@ Default value is true.
|
|||
<attribute name="value" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Specifies the expected value. If the current option value matches the value specified in this attribute, the checkOption element is treated as true, otherwise – as false.
|
||||
Specifies the expected value. If the current option value matches the value specified in this attribute, the checkOption element is treated as true, otherwise – as false.
|
||||
The expected value could be specified either as a string that may contain build macros or as a regular expression. During the comparison, the build macros are resolved and the option value is checked to match the resulting string or regular expression. The way the expected value is specified and treated depends on the value of the isRegex attribute
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
@ -2169,14 +2186,14 @@ The expected value could be specified either as a string that may contain build
|
|||
<attribute name="otherOptionId" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The id of the option which is to be compared with the option specified with the “optionId” attribute. The default is the id of the option that holds this expression. If the “value” attribute is specified, both the “otherOptionId” and the “otherHolderId” attributes are ignored. When searching for the option to be checked, MBS will examine all the options the holder contains along with all superclasses of each option to find the option with the specified id.
|
||||
The id of the option which is to be compared with the option specified with the “optionId� attribute. The default is the id of the option that holds this expression. If the “value� attribute is specified, both the “otherOptionId� and the “otherHolderId� attributes are ignored. When searching for the option to be checked, MBS will examine all the options the holder contains along with all superclasses of each option to find the option with the specified id.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="otherHolderId" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The option holder id that holds the option specified with the “otherOptionId” attribute. The default is the id of the holder that holds the container of this expression. If the “value” attribute is specified, both the “otherOptionId” and the “otherHolderId” attributes are ingnored. When searching for the needed holder, MBS will examine all the holders the current configuration contains along with all superclasses of each holder in order to find the holder with the specified id.
|
||||
The option holder id that holds the option specified with the “otherOptionId� attribute. The default is the id of the holder that holds the container of this expression. If the “value� attribute is specified, both the “otherOptionId� and the “otherHolderId� attributes are ingnored. When searching for the needed holder, MBS will examine all the holders the current configuration contains along with all superclasses of each holder in order to find the holder with the specified id.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
@ -2200,7 +2217,7 @@ The expected value could be specified either as a string that may contain build
|
|||
<attribute name="value" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Specifies the expected value. If the current string specified in the “string” attribute matches the value specified in this attribute, the checkString element is treated as true, otherwise – as false.
|
||||
Specifies the expected value. If the current string specified in the “string� attribute matches the value specified in this attribute, the checkString element is treated as true, otherwise – as false.
|
||||
The expected value could be specified either as a string that might contain the build macros or as a regular expression.
|
||||
The way the value is specified and treated depends on the value of the isRegex attribute.
|
||||
</documentation>
|
||||
|
|
|
@ -10,8 +10,14 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.build.internal.core.scannerconfig2;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext;
|
||||
import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile;
|
||||
|
@ -44,4 +50,34 @@ public class CfgScannerConfigProfileManager {
|
|||
return new CfgInfoContext(cfg).toInfoContext();
|
||||
return new InfoContext(project);
|
||||
}
|
||||
|
||||
public static boolean disableScannerDiscovery(IConfiguration cfg) {
|
||||
boolean isChanged = false;
|
||||
|
||||
ICfgScannerConfigBuilderInfo2Set info2set = getCfgScannerConfigBuildInfo(cfg);
|
||||
Map<CfgInfoContext, IScannerConfigBuilderInfo2> infoMap = info2set.getInfoMap();
|
||||
Collection<IScannerConfigBuilderInfo2> infos = infoMap.values();
|
||||
for (IScannerConfigBuilderInfo2 info2 : infos) {
|
||||
isChanged = isChanged || info2.isAutoDiscoveryEnabled();
|
||||
info2.setAutoDiscoveryEnabled(false);
|
||||
}
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
public static boolean disableScannerDiscovery(ICProjectDescription prjDescription) {
|
||||
boolean isChanged = false;
|
||||
|
||||
ICConfigurationDescription[] cfgDescs = prjDescription.getConfigurations();
|
||||
if (cfgDescs!=null) {
|
||||
for (ICConfigurationDescription cfgDesc : cfgDescs) {
|
||||
IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDesc);
|
||||
boolean changed=CfgScannerConfigProfileManager.disableScannerDiscovery(cfg);
|
||||
if (changed) {
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return isChanged;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,15 +25,23 @@ import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set
|
|||
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.ICConsoleParser;
|
||||
import org.eclipse.cdt.core.ICommandLauncher;
|
||||
import org.eclipse.cdt.core.IConsoleParser;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.resources.RefreshScopeManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
|
||||
|
@ -114,6 +122,23 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
break;
|
||||
}
|
||||
|
||||
URI workingDirectoryURI = ManagedBuildManager.getBuildLocationURI(configuration, builder);
|
||||
final String pathFromURI = EFSExtensionManager.getDefault().getPathFromURI(workingDirectoryURI);
|
||||
if(pathFromURI == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, ManagedMakeMessages.getString("ManagedMakeBuilder.message.error"), null)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
IPath workingDirectory = new Path(pathFromURI);
|
||||
|
||||
// Set the environment
|
||||
Map<String, String> envMap = getEnvironment(builder);
|
||||
String[] env = getEnvStrings(envMap);
|
||||
|
||||
ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration);
|
||||
if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) {
|
||||
ManagedBuildManager.runBuiltinSpecsDetectors(cfgDescription, workingDirectory, env, monitor);
|
||||
}
|
||||
|
||||
consoleHeader[1] = configuration.getName();
|
||||
consoleHeader[2] = project.getName();
|
||||
buf.append(NEWLINE);
|
||||
|
@ -135,14 +160,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
if (markers != null)
|
||||
workspace.deleteMarkers(markers);
|
||||
|
||||
URI workingDirectoryURI = ManagedBuildManager.getBuildLocationURI(configuration, builder);
|
||||
final String pathFromURI = EFSExtensionManager.getDefault().getPathFromURI(workingDirectoryURI);
|
||||
if(pathFromURI == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, ManagedMakeMessages.getString("ManagedMakeBuilder.message.error"), null)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
IPath workingDirectory = new Path(pathFromURI);
|
||||
|
||||
String[] targets = getTargets(kind, builder);
|
||||
if (targets.length != 0 && targets[targets.length - 1].equals(builder.getCleanBuildTarget()))
|
||||
isClean = true;
|
||||
|
@ -153,9 +170,6 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
// Print the command for visual interaction.
|
||||
launcher.showCommand(true);
|
||||
|
||||
// Set the environment
|
||||
Map<String, String> envMap = getEnvironment(builder);
|
||||
String[] env = getEnvStrings(envMap);
|
||||
String[] buildArguments = targets;
|
||||
|
||||
String[] newArgs = CommandLineUtil.argumentsToArray(builder.getBuildArguments());
|
||||
|
@ -175,9 +189,15 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
OutputStream stderr = streamMon;
|
||||
|
||||
// Sniff console output for scanner info
|
||||
ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, project, configuration, workingDirectory, markerGenerator, null);
|
||||
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
||||
OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream());
|
||||
OutputStream consoleOut = stdout;
|
||||
OutputStream consoleErr = stderr;
|
||||
if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) {
|
||||
ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, project, configuration, workingDirectory, markerGenerator, null, epm);
|
||||
if (sniffer!=null) {
|
||||
consoleOut = sniffer.getOutputStream();
|
||||
consoleErr = sniffer.getErrorStream();
|
||||
}
|
||||
}
|
||||
Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory, monitor);
|
||||
if (p != null) {
|
||||
try {
|
||||
|
@ -193,6 +213,14 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
errMsg = launcher.getErrorMessage();
|
||||
monitor.subTask(ManagedMakeMessages.getResourceString("MakeBuilder.Updating_project")); //$NON-NLS-1$
|
||||
|
||||
// AG: FIXME
|
||||
// try {
|
||||
// LanguageSettingsManager.serialize(cfgDescription);
|
||||
// } catch (CoreException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
try {
|
||||
// Do not allow the cancel of the refresh, since the builder is external
|
||||
// to Eclipse, files may have been created/modified and we will be out-of-sync.
|
||||
|
@ -245,6 +273,11 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
cos.close();
|
||||
if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) {
|
||||
LanguageSettingsManager_TBD.serializeWorkspaceProviders();
|
||||
ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
|
@ -337,10 +370,11 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
IConfiguration cfg,
|
||||
IPath workingDirectory,
|
||||
IMarkerGenerator markerGenerator,
|
||||
IScannerInfoCollector collector){
|
||||
IScannerInfoCollector collector,
|
||||
ErrorParserManager epm){
|
||||
ICfgScannerConfigBuilderInfo2Set container = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg);
|
||||
Map<CfgInfoContext, IScannerConfigBuilderInfo2> map = container.getInfoMap();
|
||||
List<IScannerInfoConsoleParser> clParserList = new ArrayList<IScannerInfoConsoleParser>();
|
||||
List<IConsoleParser> clParserList = new ArrayList<IConsoleParser>();
|
||||
|
||||
if(container.isPerRcTypeDiscovery()){
|
||||
for (IResourceInfo rcInfo : cfg.getResourceInfos()) {
|
||||
|
@ -370,9 +404,25 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
contributeToConsoleParserList(project, map, new CfgInfoContext(cfg), workingDirectory, markerGenerator, collector, clParserList);
|
||||
}
|
||||
|
||||
ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg);
|
||||
List<ILanguageSettingsProvider> lsProviders = cfgDescription.getLanguageSettingProviders();
|
||||
for (ILanguageSettingsProvider lsProvider : lsProviders) {
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(lsProvider);
|
||||
if (rawProvider instanceof ICConsoleParser && !(rawProvider instanceof ILanguageSettingsBuiltinSpecsDetector)) {
|
||||
ICConsoleParser consoleParser = (ICConsoleParser) rawProvider;
|
||||
try {
|
||||
consoleParser.startup(cfgDescription);
|
||||
clParserList.add(consoleParser);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(clParserList.size() != 0){
|
||||
return new ConsoleOutputSniffer(outputStream, errorStream,
|
||||
clParserList.toArray(new IScannerInfoConsoleParser[clParserList.size()]));
|
||||
IConsoleParser[] parsers = clParserList.toArray(new IConsoleParser[clParserList.size()]);
|
||||
return new ConsoleOutputSniffer(outputStream, errorStream, parsers, epm);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -385,7 +435,7 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
IPath workingDirectory,
|
||||
IMarkerGenerator markerGenerator,
|
||||
IScannerInfoCollector collector,
|
||||
List<IScannerInfoConsoleParser> parserList){
|
||||
List<IConsoleParser> parserList){
|
||||
IScannerConfigBuilderInfo2 info = map.get(context);
|
||||
InfoContext ic = context.toInfoContext();
|
||||
boolean added = false;
|
||||
|
@ -416,5 +466,4 @@ public class ExternalBuildRunner extends AbstractBuildRunner {
|
|||
|
||||
return added;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont
|
|||
// Schema element names
|
||||
public static final String CONFIGURATION_ELEMENT_NAME = "configuration"; //$NON-NLS-1$
|
||||
public static final String ERROR_PARSERS = "errorParsers"; //$NON-NLS-1$
|
||||
public static final String LANGUAGE_SETTINGS_PROVIDERS = "languageSettingsProviders";
|
||||
public static final String EXTENSION = "artifactExtension"; //$NON-NLS-1$
|
||||
public static final String PARENT = "parent"; //$NON-NLS-1$
|
||||
|
||||
|
@ -170,6 +171,8 @@ public interface IConfiguration extends IBuildObject, IBuildObjectPropertiesCont
|
|||
*/
|
||||
public String[] getErrorParserList();
|
||||
|
||||
public String getDefaultLanguageSettingsProvidersIds();
|
||||
|
||||
/**
|
||||
* Projects have C or CC natures. Tools can specify a filter so they are not
|
||||
* misapplied to a project. This method allows the caller to retrieve a list
|
||||
|
|
|
@ -53,6 +53,8 @@ public interface IToolChain extends IBuildObject, IHoldsOptions {
|
|||
// The attribute name for the scanner info collector
|
||||
public static final String SCANNER_CONFIG_PROFILE_ID = "scannerConfigDiscoveryProfileId"; //$NON-NLS-1$
|
||||
|
||||
public static final String LANGUAGE_SETTINGS_PROVIDERS = "languageSettingsProviders";
|
||||
|
||||
/**
|
||||
* Returns the configuration that is the parent of this tool-chain.
|
||||
*
|
||||
|
@ -261,6 +263,13 @@ public interface IToolChain extends IBuildObject, IHoldsOptions {
|
|||
*/
|
||||
public void setErrorParserIds(String ids);
|
||||
|
||||
/**
|
||||
* Returns the default language settings providers IDs.
|
||||
*
|
||||
* @return the default language settings providers IDs separated by semicolon or {@code null} if none.
|
||||
*/
|
||||
public String getDefaultLanguageSettingsProvidersIds();
|
||||
|
||||
/**
|
||||
* Returns the scanner config discovery profile id or <code>null</code> if none.
|
||||
*
|
||||
|
|
|
@ -13,14 +13,26 @@ package org.eclipse.cdt.managedbuilder.core;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuildOutputScanner;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
|
||||
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildDescription;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStateManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.DescriptionBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.internal.buildmodel.IBuildModelBuilder;
|
||||
|
@ -35,6 +47,7 @@ import org.eclipse.core.resources.IResourceDelta;
|
|||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
|
@ -61,6 +74,21 @@ public class InternalBuildRunner extends AbstractBuildRunner {
|
|||
private static final String NOTHING_BUILT = "ManagedMakeBuilder.message.no.build"; //$NON-NLS-1$
|
||||
private static final String BUILD_ERROR = "ManagedMakeBuilder.message.error"; //$NON-NLS-1$
|
||||
|
||||
|
||||
// TODO: same function is present in CommandBuilder and BuildProcessManager
|
||||
private String[] mapToStringArray(Map<String, String> map){
|
||||
if(map == null)
|
||||
return null;
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
for (Entry<String, String> entry : map.entrySet()) {
|
||||
list.add(entry.getKey() + '=' + entry.getValue());
|
||||
}
|
||||
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean invokeBuild(int kind, IProject project, IConfiguration configuration,
|
||||
IBuilder builder, IConsole console, IMarkerGenerator markerGenerator,
|
||||
|
@ -96,6 +124,16 @@ public class InternalBuildRunner extends AbstractBuildRunner {
|
|||
|
||||
// Get a build console for the project
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
IBuildDescription des = BuildDescriptionManager.createBuildDescription(configuration, cBS, delta, flags);
|
||||
|
||||
IPath workingDirectory = des.getDefaultBuildDirLocation();
|
||||
String[] env = null;
|
||||
if (des instanceof BuildDescription) {
|
||||
Map<String, String> envMap = ((BuildDescription)des).getEnvironment();
|
||||
env = mapToStringArray(envMap);
|
||||
}
|
||||
|
||||
consoleOutStream = console.getOutputStream();
|
||||
String[] consoleHeader = new String[3];
|
||||
if(buildIncrementaly)
|
||||
|
@ -119,11 +157,28 @@ public class InternalBuildRunner extends AbstractBuildRunner {
|
|||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) {
|
||||
ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(configuration);
|
||||
ManagedBuildManager.runBuiltinSpecsDetectors(cfgDescription, workingDirectory, env, monitor);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
if (provider instanceof ILanguageSettingsBuildOutputScanner) {
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String msg = ManagedMakeMessages.getFormattedString("BOP Language Settings Provider [{0}] is not supported by Internal Builder.", provider.getName());
|
||||
buf.append("**** "+msg+" ****");
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
ManagedBuilderCorePlugin.error(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
consoleOutStream.write(buf.toString().getBytes());
|
||||
consoleOutStream.flush();
|
||||
|
||||
IBuildDescription des = BuildDescriptionManager.createBuildDescription(configuration, cBS, delta, flags);
|
||||
|
||||
DescriptionBuilder dBuilder = null;
|
||||
if (!isParallel)
|
||||
dBuilder = new DescriptionBuilder(des, buildIncrementaly, resumeOnErr, cBS);
|
||||
|
@ -193,6 +248,12 @@ public class InternalBuildRunner extends AbstractBuildRunner {
|
|||
consoleOutStream.flush();
|
||||
epmOutputStream.close();
|
||||
epmOutputStream = null;
|
||||
if (kind!=IncrementalProjectBuilder.CLEAN_BUILD) {
|
||||
LanguageSettingsManager_TBD.serializeWorkspaceProviders();
|
||||
ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(prjDescription);
|
||||
}
|
||||
|
||||
// Generate any error markers that the build has discovered
|
||||
monitor.subTask(ManagedMakeMessages
|
||||
.getResourceString(MARKERS));
|
||||
|
@ -240,5 +301,4 @@ public class InternalBuildRunner extends AbstractBuildRunner {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,17 +49,27 @@ import javax.xml.transform.stream.StreamResult;
|
|||
|
||||
import org.eclipse.cdt.core.AbstractCExtension;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.XmlStorageUtil;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector;
|
||||
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
|
||||
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyManager;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener;
|
||||
|
@ -149,6 +159,7 @@ import org.w3c.dom.ProcessingInstruction;
|
|||
*/
|
||||
public class ManagedBuildManager extends AbstractCExtension {
|
||||
|
||||
public static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider";
|
||||
// private static final QualifiedName buildInfoProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "managedBuildInfo"); //$NON-NLS-1$
|
||||
private static final String ROOT_NODE_NAME = "ManagedProjectBuildInfo"; //$NON-NLS-1$
|
||||
public static final String SETTINGS_FILE_NAME = ".cdtbuild"; //$NON-NLS-1$
|
||||
|
@ -4714,4 +4725,138 @@ public class ManagedBuildManager extends AbstractCExtension {
|
|||
return true; // no target platform - nothing to check.
|
||||
}
|
||||
|
||||
private static String getLanguageSettingsProvidersStr(IToolChain toolchain) {
|
||||
for (;toolchain!=null;toolchain=toolchain.getSuperClass()) {
|
||||
String providersIdsStr = toolchain.getDefaultLanguageSettingsProvidersIds();
|
||||
if (providersIdsStr!=null) {
|
||||
return providersIdsStr;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String getLanguageSettingsProvidersStr(IConfiguration cfg) {
|
||||
for (;cfg!=null;cfg=cfg.getParent()) {
|
||||
String providersIdsStr = cfg.getDefaultLanguageSettingsProvidersIds();
|
||||
if (providersIdsStr!=null) {
|
||||
return providersIdsStr;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static List<ILanguageSettingsProvider> getLanguageSettingsProviders(IConfiguration cfg) {
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
|
||||
String providersIdsStr = getLanguageSettingsProvidersStr(cfg);
|
||||
if (providersIdsStr!=null) {
|
||||
if (providersIdsStr.contains("${Toolchain}")) {
|
||||
IToolChain toolchain = cfg.getToolChain();
|
||||
String toolchainProvidersIds = getLanguageSettingsProvidersStr(toolchain);
|
||||
if (toolchainProvidersIds==null) {
|
||||
toolchainProvidersIds="";
|
||||
}
|
||||
providersIdsStr = providersIdsStr.replaceAll("\\$\\{Toolchain\\}", toolchainProvidersIds);
|
||||
}
|
||||
List<String> providersIds = Arrays.asList(providersIdsStr.split(String.valueOf(LanguageSettingsManager_TBD.PROVIDER_DELIMITER)));
|
||||
for (String id : providersIds) {
|
||||
id = id.trim();
|
||||
ILanguageSettingsProvider provider = null;
|
||||
if (id.startsWith("*")) {
|
||||
id = id.substring(1);
|
||||
provider = LanguageSettingsManager.getWorkspaceProvider(id);
|
||||
} else if (id.startsWith("-")) {
|
||||
id = id.substring(1);
|
||||
for (ILanguageSettingsProvider pr : providers) {
|
||||
if (pr.getId().equals(id)) {
|
||||
providers.remove(pr);
|
||||
// Has to break as the collection is invalidated
|
||||
// TODO: remove all elements or better use unique list
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (id.length()>0){
|
||||
provider = LanguageSettingsManager.getExtensionProviderCopy(id);
|
||||
}
|
||||
if (provider!=null) {
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (providers.isEmpty()) {
|
||||
// Add MBS provider for unsuspecting toolchains (backward compatibility)
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(MBS_LANGUAGE_SETTINGS_PROVIDER);
|
||||
providers.add(provider);
|
||||
}
|
||||
|
||||
if (!isProviderThere(providers, LanguageSettingsManager_TBD.PROVIDER_UI_USER)) {
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(LanguageSettingsManager_TBD.PROVIDER_UI_USER);
|
||||
providers.add(0, provider);
|
||||
}
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
private static boolean isProviderThere(List<ILanguageSettingsProvider> providers, String id) {
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
if (provider.getId().equals(id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO - better home?
|
||||
*/
|
||||
static public void runBuiltinSpecsDetectors(ICConfigurationDescription cfgDescription, IPath workingDirectory,
|
||||
String[] env, IProgressMonitor monitor) {
|
||||
IProject project = cfgDescription.getProjectDescription().getProject();
|
||||
ICFolderDescription rootFolderDescription = cfgDescription.getRootFolderDescription();
|
||||
List<String> languageIds = new ArrayList<String>();
|
||||
for (ICLanguageSetting languageSetting : rootFolderDescription.getLanguageSettings()) {
|
||||
String id = languageSetting.getLanguageId();
|
||||
if (id!=null) {
|
||||
languageIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
for (ILanguageSettingsProvider provider : cfgDescription.getLanguageSettingProviders()) {
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
if (rawProvider instanceof ILanguageSettingsBuiltinSpecsDetector) {
|
||||
ILanguageSettingsBuiltinSpecsDetector detector = (ILanguageSettingsBuiltinSpecsDetector)rawProvider;
|
||||
boolean isWorkspaceProvider = LanguageSettingsManager.isWorkspaceProvider(provider);
|
||||
for (String languageId : languageIds) {
|
||||
if (detector.getLanguageScope()==null || detector.getLanguageScope().contains(languageId)) {
|
||||
try {
|
||||
if (isWorkspaceProvider) {
|
||||
detector.run(project, languageId, workingDirectory, env, monitor);
|
||||
} else {
|
||||
detector.run(cfgDescription, languageId, workingDirectory, env, monitor);
|
||||
}
|
||||
// detector.shutdown() is called from ConsoleOutputSniffer
|
||||
} catch (Throwable e) {
|
||||
IStatus status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Internal error in BuiltinSpecsDetector "+detector.getId(), e);
|
||||
MakeCorePlugin.log(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// AG: FIXME
|
||||
// LanguageSettingsManager.serialize(cfgDescription);
|
||||
// AG: FIXME - rather send event that ls settings changed
|
||||
ICProject icProject = CoreModel.getDefault().create(project);
|
||||
ICElement[] tuSelection = new ICElement[] {icProject};
|
||||
try {
|
||||
CCorePlugin.getIndexManager().update(tuSelection, IIndexManager.UPDATE_ALL | IIndexManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT);
|
||||
} catch (CoreException e) {
|
||||
IStatus status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Error updating CDT index", e);
|
||||
ManagedBuilderCorePlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ import java.util.Set;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.resources.ACBuilder;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
|
@ -145,6 +147,7 @@ public class CommonBuilder extends ACBuilder {
|
|||
private final IConfiguration fCfg;
|
||||
private final IBuilder fBuilder;
|
||||
private IConsole fConsole;
|
||||
|
||||
CfgBuildInfo(IBuilder builder, boolean isForegound){
|
||||
this.fBuilder = builder;
|
||||
this.fCfg = builder.getParent().getParent();
|
||||
|
|
|
@ -105,6 +105,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
|
|||
private String cleanCommand;
|
||||
private String artifactExtension;
|
||||
private String errorParserIds;
|
||||
private String defaultLanguageSettingsProvidersIds;
|
||||
private String prebuildStep;
|
||||
private String postbuildStep;
|
||||
private String preannouncebuildStep;
|
||||
|
@ -784,6 +785,9 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
|
|||
// Get the semicolon separated list of IDs of the error parsers
|
||||
errorParserIds = SafeStringInterner.safeIntern(element.getAttribute(ERROR_PARSERS));
|
||||
|
||||
// Get the initial/default language setttings providers IDs
|
||||
defaultLanguageSettingsProvidersIds = SafeStringInterner.safeIntern(element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS));
|
||||
|
||||
// Get the artifact extension
|
||||
artifactExtension = SafeStringInterner.safeIntern(element.getAttribute(EXTENSION));
|
||||
|
||||
|
@ -1425,6 +1429,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild
|
|||
return set;
|
||||
}
|
||||
|
||||
public String getDefaultLanguageSettingsProvidersIds() {
|
||||
return defaultLanguageSettingsProvidersIds;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.core.IConfiguration#setArtifactExtension(java.lang.String)
|
||||
*/
|
||||
|
|
|
@ -403,6 +403,11 @@ public class MultiConfiguration extends MultiItemsHolder implements
|
|||
return s;
|
||||
}
|
||||
|
||||
public String getDefaultLanguageSettingsProvidersIds() {
|
||||
ManagedBuilderCorePlugin.error("Default Language Settings Providers are not supported in multiconfiguration mode");
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getFilteredTools()
|
||||
*/
|
||||
|
|
|
@ -85,6 +85,7 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv
|
|||
private String targetToolIds;
|
||||
private String secondaryOutputIds;
|
||||
private Boolean isAbstract;
|
||||
private String defaultLanguageSettingsProvidersIds;
|
||||
private String scannerConfigDiscoveryProfileId;
|
||||
private String versionsSupported;
|
||||
private String convertToId;
|
||||
|
@ -554,6 +555,9 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv
|
|||
// Get the target tool id
|
||||
targetToolIds = SafeStringInterner.safeIntern(element.getAttribute(TARGET_TOOL));
|
||||
|
||||
// Get the initial/default language setttings providers IDs
|
||||
defaultLanguageSettingsProvidersIds = element.getAttribute(LANGUAGE_SETTINGS_PROVIDERS);
|
||||
|
||||
// Get the scanner config discovery profile id
|
||||
scannerConfigDiscoveryProfileId = SafeStringInterner.safeIntern(element.getAttribute(SCANNER_CONFIG_PROFILE_ID));
|
||||
String tmp = element.getAttribute(RESOURCE_TYPE_BASED_DISCOVERY);
|
||||
|
@ -1501,6 +1505,10 @@ public class ToolChain extends HoldsOptions implements IToolChain, IMatchKeyProv
|
|||
setDirty(true);
|
||||
}
|
||||
|
||||
public String getDefaultLanguageSettingsProvidersIds() {
|
||||
return defaultLanguageSettingsProvidersIds;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.core.IToolChain#getScannerConfigDiscoveryProfileId()
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,506 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.managedbuilder.internal.scannerconfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CommandLauncher;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.ICommandLauncher;
|
||||
import org.eclipse.cdt.core.IConsoleParser;
|
||||
import org.eclipse.cdt.core.model.ILanguageDescriptor;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.AbstractLanguageSettingsOutputScanner;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ILanguageSettingsBuiltinSpecsDetector;
|
||||
import org.eclipse.cdt.make.internal.core.MakeMessages;
|
||||
import org.eclipse.cdt.make.internal.core.StreamMonitor;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCMarkerGenerator;
|
||||
import org.eclipse.cdt.managedbuilder.core.IInputType;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||
import org.eclipse.cdt.utils.CommandLineUtil;
|
||||
import org.eclipse.cdt.utils.PathUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ILanguageSettingsBuiltinSpecsDetector {
|
||||
private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$
|
||||
private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$
|
||||
private static final String PATH_ENV = "PATH"; //$NON-NLS-1$
|
||||
private static final String ATTR_RUN_ONCE = "run-once"; //$NON-NLS-1$
|
||||
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
|
||||
|
||||
protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$
|
||||
protected static final String SPEC_FILE_MACRO = "${INPUTS}"; //$NON-NLS-1$
|
||||
protected static final String SPEC_EXT_MACRO = "${EXT}"; //$NON-NLS-1$
|
||||
protected static final String SPEC_FILE_BASE = "spec."; //$NON-NLS-1$
|
||||
|
||||
private String currentCommandResolved = null;
|
||||
protected List<ICLanguageSettingEntry> detectedSettingEntries = null;
|
||||
|
||||
private boolean runOnce = true;
|
||||
private boolean isConsoleEnabled = false;
|
||||
protected java.io.File specFile = null;
|
||||
protected boolean preserveSpecFile = false;
|
||||
|
||||
protected URI mappedRootURI = null;
|
||||
protected URI buildDirURI = null;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
protected abstract String getToolchainId();
|
||||
|
||||
@Override
|
||||
public void configureProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) {
|
||||
super.configureProvider(id, name, languages, entries, customParameter);
|
||||
|
||||
runOnce = true;
|
||||
}
|
||||
|
||||
public void setRunOnce(boolean once) {
|
||||
runOnce = once;
|
||||
}
|
||||
|
||||
public boolean isRunOnce() {
|
||||
return runOnce;
|
||||
}
|
||||
|
||||
public void setConsoleEnabled(boolean enable) {
|
||||
isConsoleEnabled = enable;
|
||||
}
|
||||
|
||||
public boolean isConsoleEnabled() {
|
||||
return isConsoleEnabled;
|
||||
}
|
||||
|
||||
protected String resolveCommand(String languageId) throws CoreException {
|
||||
String cmd = getCustomParameter();
|
||||
|
||||
if (cmd!=null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) {
|
||||
String toolchainId = getToolchainId();
|
||||
ITool tool = getTool(toolchainId, languageId);
|
||||
if (tool==null) {
|
||||
IStatus status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Provider "+getId()
|
||||
+" unable to find the compiler tool for language " + languageId
|
||||
+ "in toolchain " + toolchainId);
|
||||
throw new CoreException(status);
|
||||
}
|
||||
|
||||
if (cmd.contains(COMPILER_MACRO)) {
|
||||
String compiler = getCompilerCommand(tool);
|
||||
cmd = cmd.replace(COMPILER_MACRO, compiler);
|
||||
}
|
||||
if (cmd.contains(SPEC_FILE_MACRO)) {
|
||||
String specFileName = getSpecFile(languageId, tool);
|
||||
cmd = cmd.replace(SPEC_FILE_MACRO, specFileName);
|
||||
}
|
||||
if (cmd.contains(SPEC_EXT_MACRO)) {
|
||||
String specFileExt = getSpecExt(languageId, tool);
|
||||
cmd = cmd.replace(SPEC_EXT_MACRO, specFileExt);
|
||||
}
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Override
|
||||
protected String parseForResourceName(String line) {
|
||||
// This works as if workspace-wide
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String determineLanguage(String parsedResourceName) {
|
||||
// language id is supposed to be set by run(), just return it
|
||||
return currentLanguageId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) {
|
||||
if (mappedRootURI==null) {
|
||||
mappedRootURI = super.getMappedRootURI(sourceFile, parsedResourceName);
|
||||
}
|
||||
return mappedRootURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI getBuildDirURI(URI mappedRootURI) {
|
||||
if (buildDirURI==null) {
|
||||
buildDirURI = super.getBuildDirURI(mappedRootURI);
|
||||
}
|
||||
return buildDirURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startup(ICConfigurationDescription cfgDescription) throws CoreException {
|
||||
// for workspace provider cfgDescription is used to figure out the current project for build console
|
||||
currentCfgDescription = cfgDescription;
|
||||
if (cfgDescription!=null) {
|
||||
currentProject = cfgDescription.getProjectDescription().getProject();
|
||||
}
|
||||
|
||||
detectedSettingEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||
currentCommandResolved = customParameter;
|
||||
|
||||
specFile = null;
|
||||
|
||||
currentCommandResolved = resolveCommand(currentLanguageId);
|
||||
|
||||
mappedRootURI = null;
|
||||
buildDirURI = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
buildDirURI = null;
|
||||
mappedRootURI = null;
|
||||
|
||||
if (detectedSettingEntries!=null && detectedSettingEntries.size()>0) {
|
||||
setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, detectedSettingEntries);
|
||||
|
||||
IStatus status = new Status(IStatus.INFO, MakeCorePlugin.PLUGIN_ID, getClass().getSimpleName()
|
||||
+ " collected " + detectedSettingEntries.size() + " entries" + " for language " + currentLanguageId);
|
||||
ManagedBuilderCorePlugin.log(status);
|
||||
}
|
||||
detectedSettingEntries = null;
|
||||
|
||||
if (specFile!=null && !preserveSpecFile) {
|
||||
specFile.delete();
|
||||
specFile = null;
|
||||
}
|
||||
|
||||
currentCommandResolved = null;
|
||||
}
|
||||
|
||||
public void run(IProject project, String languageId, IPath workingDirectory, String[] env,
|
||||
IProgressMonitor monitor) throws CoreException, IOException {
|
||||
if (isRunOnce() && !isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentProject = project;
|
||||
currentLanguageId = languageId;
|
||||
startup(null);
|
||||
|
||||
run(workingDirectory, env, monitor);
|
||||
}
|
||||
|
||||
public void run(ICConfigurationDescription cfgDescription, String languageId, IPath workingDirectory,
|
||||
String[] env, IProgressMonitor monitor) throws CoreException, IOException {
|
||||
Assert.isNotNull(cfgDescription);
|
||||
|
||||
if (isRunOnce() && !isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentLanguageId = languageId;
|
||||
startup(cfgDescription);
|
||||
|
||||
run(workingDirectory, env, monitor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: test case for this function
|
||||
*/
|
||||
private void run(IPath workingDirectory, String[] env, IProgressMonitor monitor)
|
||||
throws CoreException, IOException {
|
||||
|
||||
IConsole console;
|
||||
if (isConsoleEnabled) {
|
||||
console = startProviderConsole();
|
||||
} else {
|
||||
// that looks in extension points registry and won't find the id
|
||||
console = CCorePlugin.getDefault().getConsole(MakeCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$
|
||||
}
|
||||
console.start(currentProject);
|
||||
OutputStream cos = console.getOutputStream();
|
||||
|
||||
ErrorParserManager epm = null;
|
||||
if (currentProject!=null) {
|
||||
epm = new ErrorParserManager(currentProject, new SCMarkerGenerator(), new String[] {GMAKE_ERROR_PARSER_ID});
|
||||
epm.setOutputStream(cos);
|
||||
}
|
||||
|
||||
if (monitor==null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 70), epm, 100);
|
||||
OutputStream stdout = streamMon;
|
||||
OutputStream stderr = streamMon;
|
||||
|
||||
String msg = "Running scanner discovery: " + getName();
|
||||
monitor.subTask(msg);
|
||||
printLine(stdout, "**** " + msg + " ****" + NEWLINE);
|
||||
|
||||
ConsoleOutputSniffer sniffer = new ConsoleOutputSniffer(stdout, stderr, new IConsoleParser[] { this });
|
||||
OutputStream consoleOut = sniffer.getOutputStream();
|
||||
OutputStream consoleErr = sniffer.getErrorStream();
|
||||
|
||||
boolean isSuccess = false;
|
||||
try {
|
||||
isSuccess = runProgram(currentCommandResolved, env, workingDirectory, monitor, consoleOut, consoleErr);
|
||||
} catch (Exception e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
if (!isSuccess) {
|
||||
try {
|
||||
consoleOut.close();
|
||||
} catch (IOException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
try {
|
||||
consoleErr.close();
|
||||
} catch (IOException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean runProgram(String command, String[] env, IPath workingDirectory, IProgressMonitor monitor,
|
||||
OutputStream consoleOut, OutputStream consoleErr) throws CoreException, IOException {
|
||||
|
||||
if (command==null || command.trim().length()==0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String errMsg = null;
|
||||
ICommandLauncher launcher = new CommandLauncher();
|
||||
|
||||
launcher.setProject(currentProject);
|
||||
|
||||
// Print the command for visual interaction.
|
||||
launcher.showCommand(true);
|
||||
|
||||
String[] cmdArray = CommandLineUtil.argumentsToArray(command);
|
||||
IPath program = new Path(cmdArray[0]);
|
||||
String[] args = new String[0];
|
||||
if (cmdArray.length>1) {
|
||||
args = new String[cmdArray.length-1];
|
||||
System.arraycopy(cmdArray, 1, args, 0, args.length);
|
||||
}
|
||||
|
||||
Process p = launcher.execute(program, args, env, workingDirectory, monitor);
|
||||
|
||||
if (p != null) {
|
||||
// Before launching give visual cues via the monitor
|
||||
monitor.subTask("Invoking command " + command);
|
||||
if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0))
|
||||
!= ICommandLauncher.OK) {
|
||||
errMsg = launcher.getErrorMessage();
|
||||
}
|
||||
} else {
|
||||
errMsg = launcher.getErrorMessage();
|
||||
}
|
||||
if (errMsg!=null) {
|
||||
String errorPrefix = MakeMessages.getString("ExternalScannerInfoProvider.Error_Prefix"); //$NON-NLS-1$
|
||||
|
||||
String msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Provider_Error", command);
|
||||
printLine(consoleErr, errorPrefix + msg + NEWLINE);
|
||||
|
||||
// Launching failed, trying to figure out possible cause
|
||||
String envPath = getEnvVar(env, PATH_ENV);
|
||||
if (!program.isAbsolute() && PathUtil.findProgramLocation(program.toString(), envPath) == null) {
|
||||
printLine(consoleErr, errMsg);
|
||||
msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", workingDirectory); //$NON-NLS-1$
|
||||
msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Program_Not_In_Path", program); //$NON-NLS-1$
|
||||
printLine(consoleErr, errorPrefix + msg + NEWLINE);
|
||||
printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else {
|
||||
printLine(consoleErr, errorPrefix + errMsg);
|
||||
msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", workingDirectory); //$NON-NLS-1$
|
||||
printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Override
|
||||
protected void setSettingEntries(List<ICLanguageSettingEntry> entries) {
|
||||
// Builtin specs detectors collect entries not per line but for the whole output
|
||||
if (entries!=null)
|
||||
detectedSettingEntries.addAll(entries);
|
||||
}
|
||||
|
||||
private IConsole startProviderConsole() {
|
||||
ILanguageDescriptor ld = LanguageManager.getInstance().getLanguageDescriptor(currentLanguageId);
|
||||
|
||||
String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId;
|
||||
String consoleName = getName() + ", " + ld.getName();
|
||||
URL defaultIcon = Platform.getBundle(PLUGIN_CDT_MAKE_UI_ID).getEntry("icons/obj16/inspect_system.gif");
|
||||
|
||||
IConsole console = CCorePlugin.getDefault().getConsole("org.eclipse.cdt.make.internal.ui.scannerconfig.ScannerDiscoveryConsole", consoleId, consoleName, defaultIcon);
|
||||
return console;
|
||||
}
|
||||
|
||||
private String getEnvVar(String[] envStrings, String envVar) {
|
||||
String envPath = null;
|
||||
if (envStrings!=null) {
|
||||
String varPrefix = envVar+'=';
|
||||
for (String envStr : envStrings) {
|
||||
if (envStr.startsWith(varPrefix)) {
|
||||
envPath = envStr.substring(varPrefix.length());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
envPath = System.getenv(envVar);
|
||||
}
|
||||
return envPath;
|
||||
}
|
||||
|
||||
private ITool getTool(String toolchainId, String languageId) {
|
||||
IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId);
|
||||
if (toolchain != null) {
|
||||
ITool[] tools = toolchain.getTools();
|
||||
for (ITool tool : tools) {
|
||||
IInputType[] inputTypes = tool.getInputTypes();
|
||||
for (IInputType inType : inputTypes) {
|
||||
String lang = inType.getLanguageId(tool);
|
||||
if (languageId.equals(lang))
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
}
|
||||
ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId);
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getCompilerCommand(ITool tool) {
|
||||
String compiler = tool.getToolCommand();
|
||||
if (compiler.length()==0) {
|
||||
String msg = "Unable to find compiler command in toolchain="+getToolchainId();
|
||||
ManagedBuilderCorePlugin.error(msg);
|
||||
}
|
||||
return compiler;
|
||||
}
|
||||
|
||||
private String getSpecFile(String languageId, ITool tool) {
|
||||
String ext = getSpecExt(languageId, tool);
|
||||
|
||||
String specFileName = SPEC_FILE_BASE + ext;
|
||||
IPath workingLocation = MakeCorePlugin.getWorkingDirectory();
|
||||
IPath fileLocation = workingLocation.append(specFileName);
|
||||
|
||||
specFile = new java.io.File(fileLocation.toOSString());
|
||||
// will preserve spec file if it was already there otherwise will delete upon finishing
|
||||
preserveSpecFile = specFile.exists();
|
||||
if (!preserveSpecFile) {
|
||||
try {
|
||||
specFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return fileLocation.toString();
|
||||
}
|
||||
|
||||
private String getSpecExt(String languageId, ITool tool) {
|
||||
String ext = "";
|
||||
String[] srcFileExtensions = tool.getAllInputExtensions();
|
||||
if (srcFileExtensions!=null && srcFileExtensions.length>0) {
|
||||
ext = srcFileExtensions[0];
|
||||
}
|
||||
if (ext.length()==0) {
|
||||
ManagedBuilderCorePlugin.error("Unable to find file extension for language "+languageId);
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
protected void printLine(OutputStream stream, String msg) throws IOException {
|
||||
stream.write((msg + NEWLINE).getBytes());
|
||||
stream.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element serialize(Element parentElement) {
|
||||
Element elementProvider = super.serialize(parentElement);
|
||||
elementProvider.setAttribute(ATTR_RUN_ONCE, Boolean.toString(runOnce));
|
||||
elementProvider.setAttribute(ATTR_CONSOLE, Boolean.toString(isConsoleEnabled));
|
||||
return elementProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Element providerNode) {
|
||||
super.load(providerNode);
|
||||
|
||||
String runOnceValue = XmlUtil.determineAttributeValue(providerNode, ATTR_RUN_ONCE);
|
||||
if (runOnceValue!=null)
|
||||
runOnce = Boolean.parseBoolean(runOnceValue);
|
||||
|
||||
String consoleValue = XmlUtil.determineAttributeValue(providerNode, ATTR_CONSOLE);
|
||||
if (consoleValue!=null)
|
||||
isConsoleEnabled = Boolean.parseBoolean(consoleValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + (runOnce ? 1231 : 1237);
|
||||
result = prime * result + (isConsoleEnabled ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (!(obj instanceof AbstractBuiltinSpecsDetector))
|
||||
return false;
|
||||
AbstractBuiltinSpecsDetector other = (AbstractBuiltinSpecsDetector) obj;
|
||||
if (runOnce != other.runOnce)
|
||||
return false;
|
||||
if (isConsoleEnabled != other.isConsoleEnabled)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.managedbuilder.internal.scannerconfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Class to detect built-in compiler settings. Note that currently this class is hardwired
|
||||
* to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}.
|
||||
*
|
||||
*/
|
||||
public class GCCBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector implements ILanguageSettingsEditableProvider {
|
||||
// must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point
|
||||
private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$
|
||||
|
||||
private enum State {NONE, EXPECTING_LOCAL_INCLUDE, EXPECTING_SYSTEM_INCLUDE, EXPECTING_FRAMEWORKS}
|
||||
private State state = State.NONE;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
private static final AbstractOptionParser[] optionParsers = {
|
||||
new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL),
|
||||
new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
new IncludePathOptionParser("#framework <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.FRAMEWORKS_MAC),
|
||||
new MacroOptionParser("#define (\\S*\\(.*?\\)) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
new MacroOptionParser("#define (\\S*) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
};
|
||||
|
||||
@Override
|
||||
protected String getToolchainId() {
|
||||
return GCC_TOOLCHAIN_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractOptionParser[] getOptionParsers() {
|
||||
return optionParsers;
|
||||
}
|
||||
|
||||
private List<String> makeList(final String line) {
|
||||
return new ArrayList<String>() {{ add(line); }};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> parseForOptions(String line) {
|
||||
line = line.trim();
|
||||
|
||||
// contribution of -dD option
|
||||
if (line.startsWith("#define")) {
|
||||
return makeList(line);
|
||||
}
|
||||
|
||||
// contribution of includes
|
||||
if (line.equals("#include \"...\" search starts here:")) {
|
||||
state = State.EXPECTING_LOCAL_INCLUDE;
|
||||
} else if (line.equals("#include <...> search starts here:")) {
|
||||
state = State.EXPECTING_SYSTEM_INCLUDE;
|
||||
} else if (line.startsWith("End of search list.")) {
|
||||
state = State.NONE;
|
||||
} else if (line.equals("Framework search starts here:")) {
|
||||
state = State.EXPECTING_FRAMEWORKS;
|
||||
} else if (line.startsWith("End of framework search list.")) {
|
||||
state = State.NONE;
|
||||
} else if (state==State.EXPECTING_LOCAL_INCLUDE) {
|
||||
// making that up for the parser to figure out
|
||||
line = "#include \""+line+"\"";
|
||||
return makeList(line);
|
||||
} else {
|
||||
String frameworkIndicator = "(framework directory)";
|
||||
if (state==State.EXPECTING_SYSTEM_INCLUDE) {
|
||||
// making that up for the parser to figure out
|
||||
if (line.contains(frameworkIndicator)) {
|
||||
line = "#framework <"+line.replace(frameworkIndicator, "").trim()+">";
|
||||
} else {
|
||||
line = "#include <"+line+">";
|
||||
}
|
||||
return makeList(line);
|
||||
} else if (state==State.EXPECTING_FRAMEWORKS) {
|
||||
// making that up for the parser to figure out
|
||||
line = "#framework <"+line.replace(frameworkIndicator, "").trim()+">";
|
||||
return makeList(line);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startup(ICConfigurationDescription cfgDescription) throws CoreException {
|
||||
super.startup(cfgDescription);
|
||||
|
||||
state = State.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
state = State.NONE;
|
||||
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GCCBuiltinSpecsDetector cloneShallow() throws CloneNotSupportedException {
|
||||
return (GCCBuiltinSpecsDetector) super.cloneShallow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GCCBuiltinSpecsDetector clone() throws CloneNotSupportedException {
|
||||
return (GCCBuiltinSpecsDetector) super.clone();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.managedbuilder.internal.scannerconfig;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* Class to detect built-in compiler settings.
|
||||
* The paths are converted to cygwin "filesystem" representation. Then
|
||||
*
|
||||
*/
|
||||
public class GCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetector {
|
||||
private static final URI CYGWIN_ROOT;
|
||||
static {
|
||||
try {
|
||||
CYGWIN_ROOT = new URI("cygwin:/"); //$NON-NLS-1$
|
||||
} catch (URISyntaxException e) {
|
||||
// hey we know this works
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
private static final AbstractOptionParser[] optionParsers = {
|
||||
new IncludePathOptionParser("#include \"(\\S.*)\"", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.LOCAL),
|
||||
new IncludePathOptionParser("#include <(\\S.*)>", "$1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
new MacroOptionParser("#define (\\S*\\(.*?\\)) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
new MacroOptionParser("#define (\\S*) *(.*)", "$1", "$2", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY),
|
||||
};
|
||||
|
||||
@Override
|
||||
protected AbstractOptionParser[] getOptionParsers() {
|
||||
return optionParsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) {
|
||||
if (mappedRootURI==null) {
|
||||
mappedRootURI = super.getMappedRootURI(sourceFile, parsedResourceName);
|
||||
if (mappedRootURI==null) {
|
||||
mappedRootURI = CYGWIN_ROOT;
|
||||
}
|
||||
}
|
||||
return mappedRootURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI getBuildDirURI(URI mappedRootURI) {
|
||||
if (buildDirURI==null) {
|
||||
buildDirURI = super.getBuildDirURI(mappedRootURI);
|
||||
if (buildDirURI==null) {
|
||||
buildDirURI = CYGWIN_ROOT;
|
||||
}
|
||||
}
|
||||
return buildDirURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GCCBuiltinSpecsDetectorCygwin cloneShallow() throws CloneNotSupportedException {
|
||||
return (GCCBuiltinSpecsDetectorCygwin) super.cloneShallow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GCCBuiltinSpecsDetectorCygwin clone() throws CloneNotSupportedException {
|
||||
return (GCCBuiltinSpecsDetectorCygwin) super.clone();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.managedbuilder.internal.scannerconfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
//public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsEditableProvider {
|
||||
public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider {
|
||||
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
|
||||
IPath projectPath = rc.getProjectRelativePath();
|
||||
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false);
|
||||
|
||||
List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>();
|
||||
for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) {
|
||||
if (languageSetting!=null) {
|
||||
String id = languageSetting.getLanguageId();
|
||||
if (id!=null && id.equals(languageId)) {
|
||||
int kindsBits = languageSetting.getSupportedEntryKinds();
|
||||
for (int kind=1;kind<=kindsBits;kind<<=1) {
|
||||
if ((kindsBits & kind) != 0) {
|
||||
list.addAll(languageSetting.getSettingEntriesList(kind));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// System.err.println("languageSetting id=null: name=" + languageSetting.getName());
|
||||
}
|
||||
} else {
|
||||
System.err.println("languageSetting=null: rcDescription=" + rcDescription.getName());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private ICLanguageSetting[] getLanguageSettings(ICResourceDescription rcDescription) {
|
||||
ICLanguageSetting[] array = null;
|
||||
switch (rcDescription.getType()) {
|
||||
case ICSettingBase.SETTING_PROJECT:
|
||||
case ICSettingBase.SETTING_CONFIGURATION:
|
||||
case ICSettingBase.SETTING_FOLDER:
|
||||
ICFolderDescription foDes = (ICFolderDescription)rcDescription;
|
||||
array = foDes.getLanguageSettings();
|
||||
break;
|
||||
case ICSettingBase.SETTING_FILE:
|
||||
ICFileDescription fiDes = (ICFileDescription)rcDescription;
|
||||
ICLanguageSetting ls = fiDes.getLanguageSetting();
|
||||
if (ls!=null) {
|
||||
array = new ICLanguageSetting[] { ls };
|
||||
}
|
||||
}
|
||||
if (array==null) {
|
||||
array = new ICLanguageSetting[0];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId,
|
||||
List<ICLanguageSettingEntry> entries) {
|
||||
|
||||
// lang.setSettingEntries(kind, entries);
|
||||
IPath projectPath = rc.getProjectRelativePath();
|
||||
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false);
|
||||
|
||||
for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) {
|
||||
if (languageSetting!=null) {
|
||||
String id = languageSetting.getLanguageId();
|
||||
if (id!=null && id.equals(languageId)) {
|
||||
int kindsBits = languageSetting.getSupportedEntryKinds();
|
||||
for (int kind=1;kind<=kindsBits;kind<<=1) {
|
||||
if ((kindsBits & kind) != 0) {
|
||||
List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>(entries.size());
|
||||
for (ICLanguageSettingEntry entry : entries) {
|
||||
if (entry.getKind()==kind) {
|
||||
list.add(entry);
|
||||
}
|
||||
}
|
||||
languageSetting.setSettingEntries(kind, list);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// System.err.println("languageSetting id=null: name=" + languageSetting.getName());
|
||||
}
|
||||
} else {
|
||||
System.err.println("languageSetting=null: rcDescription=" + rcDescription.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1673,10 +1673,11 @@
|
|||
|
||||
<toolChain
|
||||
archList="all"
|
||||
osList="linux,hpux,aix,qnx"
|
||||
id="cdt.managedbuild.toolchain.gnu.base"
|
||||
languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;*org.eclipse.cdt.managedbuilder.core.gcc.specs.detector"
|
||||
name="%ToolChainName.Linux"
|
||||
targetTool="cdt.managedbuild.tool.gnu.c.linker;cdt.managedbuild.tool.gnu.cpp.linker;cdt.managedbuild.tool.gnu.archiver"
|
||||
id="cdt.managedbuild.toolchain.gnu.base">
|
||||
osList="linux,hpux,aix,qnx"
|
||||
targetTool="cdt.managedbuild.tool.gnu.c.linker;cdt.managedbuild.tool.gnu.cpp.linker;cdt.managedbuild.tool.gnu.archiver">
|
||||
<targetPlatform
|
||||
id="cdt.managedbuild.target.gnu.platform.base"
|
||||
name="%PlatformName.Dbg"
|
||||
|
@ -1741,6 +1742,7 @@
|
|||
configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.gnu.cygwin.GnuCygwinConfigurationEnvironmentSupplier"
|
||||
id="cdt.managedbuild.toolchain.gnu.cygwin.base"
|
||||
isToolChainSupported="org.eclipse.cdt.managedbuilder.gnu.cygwin.IsGnuCygwinToolChainSupported"
|
||||
languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;*org.eclipse.cdt.managedbuilder.core.cygwin.gcc.specs.detector"
|
||||
name="%ToolChainName.Cygwin"
|
||||
osList="win32"
|
||||
targetTool="cdt.managedbuild.tool.gnu.cpp.linker.cygwin.base;cdt.managedbuild.tool.gnu.c.linker.cygwin.base;cdt.managedbuild.tool.gnu.archiver">
|
||||
|
@ -1810,6 +1812,7 @@
|
|||
configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.gnu.mingw.MingwEnvironmentVariableSupplier"
|
||||
id="cdt.managedbuild.toolchain.gnu.mingw.base"
|
||||
isToolChainSupported="org.eclipse.cdt.managedbuilder.gnu.mingw.MingwIsToolChainSupported"
|
||||
languageSettingsProviders="org.eclipse.cdt.make.core.build.command.parser.gcc;*org.eclipse.cdt.managedbuilder.core.gcc.specs.detector"
|
||||
name="%ToolChainName.MinGW"
|
||||
osList="win32"
|
||||
targetTool="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base;cdt.managedbuild.tool.gnu.c.linker.mingw.base;cdt.managedbuild.tool.gnu.archiver">
|
||||
|
@ -2051,9 +2054,9 @@
|
|||
</toolChain>
|
||||
|
||||
<configuration
|
||||
id="cdt.managedbuild.config.gnu.base"
|
||||
cleanCommand="rm -rf"
|
||||
>
|
||||
id="cdt.managedbuild.config.gnu.base"
|
||||
languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.make.core.build.command.parser.gcc">
|
||||
<enablement type="CONTAINER_ATTRIBUTE"
|
||||
attribute="artifactExtension"
|
||||
value="so"
|
||||
|
@ -2448,10 +2451,10 @@
|
|||
</projectType>
|
||||
|
||||
<configuration
|
||||
id="cdt.managedbuild.config.gnu.cygwin.base"
|
||||
cleanCommand="rm -rf"
|
||||
artifactExtension="exe"
|
||||
>
|
||||
cleanCommand="rm -rf"
|
||||
id="cdt.managedbuild.config.gnu.cygwin.base"
|
||||
languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.make.core.build.command.parser.gcc">
|
||||
<enablement type="CONTAINER_ATTRIBUTE"
|
||||
attribute="artifactExtension"
|
||||
value="dll"
|
||||
|
@ -2846,10 +2849,10 @@
|
|||
</projectType>
|
||||
|
||||
<configuration
|
||||
id="cdt.managedbuild.config.gnu.mingw.base"
|
||||
cleanCommand="rm -rf"
|
||||
artifactExtension="exe"
|
||||
>
|
||||
cleanCommand="rm -rf"
|
||||
id="cdt.managedbuild.config.gnu.mingw.base"
|
||||
languageSettingsProviders="org.eclipse.cdt.ui.user.LanguageSettingsProvider;org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider;${Toolchain};-org.eclipse.cdt.make.core.build.command.parser.gcc">
|
||||
<enablement type="CONTAINER_ATTRIBUTE"
|
||||
attribute="artifactExtension"
|
||||
value="dll"
|
||||
|
|
|
@ -181,6 +181,11 @@ public class TestConfiguration implements IConfiguration {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String getDefaultLanguageSettingsProvidersIds() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITool[] getFilteredTools() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
@ -15,14 +15,14 @@ import org.eclipse.cdt.core.settings.model.extension.CTargetPlatformData;
|
|||
import org.eclipse.cdt.managedbuilder.core.IBuilder;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOutputType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter;
|
||||
import org.eclipse.cdt.managedbuilder.core.IOutputType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
|
||||
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.internal.core.HoldsOptions;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.HoldsOptions;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier;
|
||||
import org.osgi.framework.Version;
|
||||
|
||||
|
@ -320,6 +320,11 @@ public class TestToolchain extends HoldsOptions implements IToolChain {
|
|||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultLanguageSettingsProvidersIds() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
BIN
build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/mbs.gif
Normal file
BIN
build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/mbs.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 380 B |
BIN
build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/search.gif
Normal file
BIN
build/org.eclipse.cdt.managedbuilder.ui/icons/obj16/search.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 347 B |
|
@ -92,6 +92,7 @@ Source.location=Source Location
|
|||
Output.location=Output Location
|
||||
Binary.parsers=Binary Parsers
|
||||
Error.parsers=Error Parsers
|
||||
Language.settings.providers=Discovery
|
||||
Data.hierarchy=Data Hierarchy
|
||||
Preferred.toolchains=Preferred Toolchains
|
||||
Wizard.defaults=Wizard Defaults
|
||||
|
|
|
@ -648,5 +648,16 @@
|
|||
</description>
|
||||
</wizard>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.LanguageSettingsProviderAssociation">
|
||||
<id-association
|
||||
id="org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider"
|
||||
icon="icons/obj16/mbs.gif">
|
||||
</id-association>
|
||||
<class-association
|
||||
class="org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector"
|
||||
page="org.eclipse.cdt.managedbuilder.ui.preferences.BuiltinSpecsDetectorOptionPage">
|
||||
</class-association>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -210,6 +210,8 @@ public class Messages extends NLS {
|
|||
public static String PropertyPageDefsTab_8;
|
||||
public static String PropertyPageDefsTab_9;
|
||||
public static String PropertyPageDefsTab_showIncludeFileTab;
|
||||
public static String PropertyPageDefsTab_showProvidersTab;
|
||||
public static String RefreshPolicyExceptionDialog_addButtonLabel;
|
||||
public static String RefreshPolicyExceptionDialog_addDialogLabel;
|
||||
public static String RefreshPolicyExceptionDialog_AddExceptionInfoDialog_message;
|
||||
public static String RefreshPolicyExceptionDialog_AddExceptionInfoDialog_title;
|
||||
|
|
|
@ -272,6 +272,7 @@ PropertyPageDefsTab_7=Show disc. page names if they are unique. Else show profil
|
|||
PropertyPageDefsTab_8=Always show names + profile IDs
|
||||
PropertyPageDefsTab_9=Always show profile IDs only
|
||||
PropertyPageDefsTab_showIncludeFileTab=Display "Include Files" tab
|
||||
PropertyPageDefsTab_showProvidersTab=Display new experimental Scanner Discovery Providers tabs
|
||||
ProjectConvert_convertersList=Converters List
|
||||
|
||||
AbstractPrefPage_0=\ Preference settings will be applied to new projects \n only when there were no toolchains selected.
|
||||
|
|
|
@ -0,0 +1,325 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.managedbuilder.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage;
|
||||
import org.eclipse.cdt.internal.ui.newui.StatusMessageLine;
|
||||
import org.eclipse.cdt.managedbuilder.internal.scannerconfig.AbstractBuiltinSpecsDetector;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* Options page for TODO
|
||||
*
|
||||
*/
|
||||
public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettingProviderOptionPage {
|
||||
private boolean fEditable;
|
||||
|
||||
private Text inputCommand;
|
||||
|
||||
private StatusMessageLine fStatusLine;
|
||||
private Button runOnceRadioButton;
|
||||
private Button runEveryBuildRadioButton;
|
||||
private Button allocateConsoleCheckBox;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
// Composite optionsPageComposite = new Composite(composite, SWT.NULL);
|
||||
fEditable = parent.isEnabled();
|
||||
|
||||
final Composite composite = new Composite(parent, SWT.NONE);
|
||||
{
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
layout.marginWidth = 1;
|
||||
layout.marginHeight = 1;
|
||||
layout.marginRight = 1;
|
||||
composite.setLayout(layout);
|
||||
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
Dialog.applyDialogFont(composite);
|
||||
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 2;
|
||||
composite.setLayoutData(gd);
|
||||
}
|
||||
|
||||
|
||||
Group groupRun = new Group(composite, SWT.SHADOW_ETCHED_IN);
|
||||
// groupRun.setText("Language Settings Provider Options");
|
||||
|
||||
GridLayout gridLayoutRun = new GridLayout();
|
||||
// GridLayout gridLayoutRun = new GridLayout(2, true);
|
||||
// gridLayoutRun.makeColumnsEqualWidth = false;
|
||||
// gridLayoutRun.marginRight = -10;
|
||||
// gridLayoutRun.marginLeft = -4;
|
||||
groupRun.setLayout(gridLayoutRun);
|
||||
// GridData gdRun = new GridData(GridData.FILL_HORIZONTAL);
|
||||
// gdRun.horizontalSpan = 2;
|
||||
// groupRun.setLayoutData(gdRun);
|
||||
|
||||
AbstractBuiltinSpecsDetector provider = getRawProvider();
|
||||
{
|
||||
runOnceRadioButton = new Button(groupRun, SWT.RADIO);
|
||||
runOnceRadioButton.setText("Run only once"); //$NON-NLS-1$
|
||||
// b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 3;
|
||||
runOnceRadioButton.setLayoutData(gd);
|
||||
runOnceRadioButton.setSelection(provider.isRunOnce());
|
||||
runOnceRadioButton.setEnabled(fEditable);
|
||||
runOnceRadioButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent evt) {
|
||||
boolean runOnceEnabled = runOnceRadioButton.getSelection();
|
||||
if (runOnceEnabled) {
|
||||
AbstractBuiltinSpecsDetector provider = getRawProvider();
|
||||
if (runOnceEnabled != provider.isRunOnce()) {
|
||||
AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setRunOnce(runOnceEnabled);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
{
|
||||
runEveryBuildRadioButton = new Button(groupRun, SWT.RADIO);
|
||||
runEveryBuildRadioButton.setText("Activate on every build"); //$NON-NLS-1$
|
||||
runEveryBuildRadioButton.setSelection(!provider.isRunOnce());
|
||||
runEveryBuildRadioButton.setEnabled(fEditable);
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 3;
|
||||
runEveryBuildRadioButton.setLayoutData(gd);
|
||||
runEveryBuildRadioButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent evt) {
|
||||
boolean runEveryBuildEnabled = runEveryBuildRadioButton.getSelection();
|
||||
if (runEveryBuildEnabled) {
|
||||
AbstractBuiltinSpecsDetector provider = getRawProvider();
|
||||
if (runEveryBuildEnabled != !provider.isRunOnce()) {
|
||||
AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setRunOnce(!runEveryBuildEnabled);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Compiler specs command
|
||||
{
|
||||
Label label = ControlFactory.createLabel(composite, "Command to get compiler specs:");
|
||||
GridData gd = new GridData();
|
||||
gd.horizontalSpan = 2;
|
||||
label.setLayoutData(gd);
|
||||
label.setEnabled(fEditable);
|
||||
}
|
||||
|
||||
{
|
||||
inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER);
|
||||
String customParameter = provider.getCustomParameter();
|
||||
inputCommand.setText(customParameter!=null ? customParameter : "");
|
||||
inputCommand.setEnabled(fEditable);
|
||||
inputCommand.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
String text = inputCommand.getText();
|
||||
AbstractBuiltinSpecsDetector provider = getRawProvider();
|
||||
if (!text.equals(provider.getCustomParameter())) {
|
||||
AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setCustomParameter(text);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
Button button = ControlFactory.createPushButton(composite, "Browse...");
|
||||
button.setEnabled(fEditable);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent evt) {
|
||||
// handleAddr2LineButtonSelected();
|
||||
//updateLaunchConfigurationDialog();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// {
|
||||
// final Button button = new Button(composite, SWT.PUSH);
|
||||
// button.setFont(parent.getFont());
|
||||
// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear";
|
||||
// button.setText(text);
|
||||
//// button.addSelectionListener(this);
|
||||
// GridData data = new GridData();
|
||||
// data.horizontalSpan = 2;
|
||||
//// data.horizontalAlignment = GridData.BEGINNING;
|
||||
//// data.widthHint = 60;
|
||||
// button.setLayoutData(data);
|
||||
// // TODO
|
||||
// button.setEnabled(fEditable && !fProvider.isEmpty());
|
||||
//
|
||||
// button.addSelectionListener(new SelectionAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void widgetSelected(SelectionEvent evt) {
|
||||
// if (fProvider.isEmpty()) {
|
||||
// // TODO
|
||||
// } else {
|
||||
// fProvider.clear();
|
||||
// }
|
||||
// // TODO
|
||||
// button.setEnabled(fEditable && !fProvider.isEmpty());
|
||||
// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear";
|
||||
// button.setText(text);
|
||||
// button.pack();
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// }
|
||||
|
||||
// // Compiler specs command
|
||||
// {
|
||||
// Label label = ControlFactory.createLabel(composite, "Parsing rules:");
|
||||
// GridData gd = new GridData();
|
||||
// gd.horizontalSpan = 2;
|
||||
// label.setLayoutData(gd);
|
||||
//// Label newLabel = new Label(composite, SWT.NONE);
|
||||
////// ((GridData) newLabel.getLayoutData()).horizontalSpan = 1;
|
||||
//// newLabel.setText("Command to get compiler specs:");
|
||||
// }
|
||||
|
||||
|
||||
// createPatternsTable(group, composite);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
|
||||
// group.setText(DialogsMessages.RegexErrorParserOptionPage_Title);
|
||||
//
|
||||
// GridLayout gridLayout = new GridLayout(2, true);
|
||||
// gridLayout.makeColumnsEqualWidth = false;
|
||||
// gridLayout.marginRight = -10;
|
||||
// gridLayout.marginLeft = -4;
|
||||
// group.setLayout(gridLayout);
|
||||
// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
//
|
||||
// Composite composite = new Composite(group, SWT.NONE);
|
||||
// GridLayout layout = new GridLayout();
|
||||
// layout.numColumns = 2;
|
||||
// layout.marginWidth = 1;
|
||||
// layout.marginHeight = 1;
|
||||
// layout.marginRight = 1;
|
||||
// composite.setLayout(layout);
|
||||
// composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
// Dialog.applyDialogFont(composite);
|
||||
//
|
||||
// if (!fEditable)
|
||||
// createLinkToPreferences(composite);
|
||||
//
|
||||
// createPatternsTable(group, composite);
|
||||
//
|
||||
// if (fEditable) {
|
||||
// createButtons(composite);
|
||||
// }
|
||||
|
||||
{
|
||||
allocateConsoleCheckBox = new Button(composite, SWT.CHECK);
|
||||
allocateConsoleCheckBox.setText("Allocate console in the Console View");
|
||||
allocateConsoleCheckBox.setSelection(provider.isConsoleEnabled());
|
||||
allocateConsoleCheckBox.setEnabled(fEditable);
|
||||
allocateConsoleCheckBox.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean enabled = allocateConsoleCheckBox.getSelection();
|
||||
AbstractBuiltinSpecsDetector provider = getRawProvider();
|
||||
if (enabled != provider.isConsoleEnabled()) {
|
||||
AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId);
|
||||
selectedProvider.setConsoleEnabled(enabled);
|
||||
providerTab.refreshItem(selectedProvider);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
widgetSelected(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// // Status line
|
||||
// if (fEditable) {
|
||||
// fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2);
|
||||
// IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)");
|
||||
// fStatusLine.setErrorStatus(status);
|
||||
// }
|
||||
|
||||
setControl(composite);
|
||||
}
|
||||
|
||||
private AbstractBuiltinSpecsDetector getRawProvider() {
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getRawProvider(providerTab.getProvider(providerId));
|
||||
Assert.isTrue(provider instanceof AbstractBuiltinSpecsDetector);
|
||||
return (AbstractBuiltinSpecsDetector) provider;
|
||||
}
|
||||
|
||||
private AbstractBuiltinSpecsDetector getWorkingCopy(String providerId) {
|
||||
ILanguageSettingsProvider provider = providerTab.getWorkingCopy(providerId);
|
||||
Assert.isTrue(provider instanceof AbstractBuiltinSpecsDetector);
|
||||
return (AbstractBuiltinSpecsDetector) provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performApply(IProgressMonitor monitor) throws CoreException {
|
||||
// handled by LanguageSettingsProviderTab
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performDefaults() {
|
||||
// handled by LanguageSettingsProviderTab
|
||||
}
|
||||
|
||||
}
|
|
@ -12,9 +12,9 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
|
||||
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
|
||||
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -38,6 +38,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
|
|||
private Button show_mng;
|
||||
private Button show_tool;
|
||||
private Button show_exp;
|
||||
private Button show_providers_tab; // temporary checkbox for scanner discovery Providers tab
|
||||
private Button show_tipbox;
|
||||
|
||||
private Button b_0;
|
||||
|
@ -74,6 +75,11 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
|
|||
show_exp.setText(Messages.PropertyPageDefsTab_10);
|
||||
show_exp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
show_providers_tab = new Button(usercomp, SWT.CHECK);
|
||||
show_providers_tab.setText(Messages.PropertyPageDefsTab_showProvidersTab + ", " //$NON-NLS-1$
|
||||
+ org.eclipse.cdt.internal.ui.newui.Messages.CDTMainWizardPage_TrySD90);
|
||||
show_providers_tab.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
show_tipbox = new Button(usercomp, SWT.CHECK);
|
||||
show_tipbox.setText(Messages.PropertyPageDefsTab_16);
|
||||
show_tipbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
@ -117,6 +123,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
|
|||
show_mng.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOMNG));
|
||||
show_tool.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOTOOLM));
|
||||
show_exp.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_EXPORT));
|
||||
show_providers_tab.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS));
|
||||
show_tipbox.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_TIPBOX));
|
||||
|
||||
switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_DISC_NAMES)) {
|
||||
|
@ -140,6 +147,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
|
|||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOMNG, !show_mng.getSelection());
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOTOOLM, !show_tool.getSelection());
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_EXPORT, show_exp.getSelection());
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS, !show_providers_tab.getSelection());
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_TIPBOX, show_tipbox.getSelection());
|
||||
int x = 0;
|
||||
if (b_1.getSelection()) x = 1;
|
||||
|
@ -160,6 +168,7 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
|
|||
show_mng.setSelection(true);
|
||||
show_tool.setSelection(true);
|
||||
show_exp.setSelection(false);
|
||||
show_providers_tab.setSelection(false);
|
||||
show_tipbox.setSelection(false);
|
||||
b_0.setSelection(true);
|
||||
b_1.setSelection(false);
|
||||
|
|
|
@ -30,6 +30,7 @@ public class WizardDefaultsTab extends AbstractCPropertyTab {
|
|||
|
||||
private Button show_sup;
|
||||
private Button show_oth;
|
||||
private Button checkBoxTryNewSD;
|
||||
|
||||
@Override
|
||||
public void createControls(Composite parent) {
|
||||
|
@ -44,20 +45,27 @@ public class WizardDefaultsTab extends AbstractCPropertyTab {
|
|||
show_oth.setText(Messages.WizardDefaultsTab_1);
|
||||
show_oth.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
checkBoxTryNewSD = new Button(usercomp, SWT.CHECK);
|
||||
checkBoxTryNewSD.setText(org.eclipse.cdt.internal.ui.newui.Messages.CDTMainWizardPage_TrySD90);
|
||||
checkBoxTryNewSD.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP));
|
||||
show_oth.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_OTHERS));
|
||||
checkBoxTryNewSD.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_NEWSD));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOK() {
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOSUPP, !show_sup.getSelection());
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_OTHERS, show_oth.getSelection());
|
||||
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NEWSD, checkBoxTryNewSD.getSelection());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performDefaults() {
|
||||
show_sup.setSelection(true);
|
||||
show_oth.setSelection(false);
|
||||
checkBoxTryNewSD.setSelection(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,9 @@ import java.util.SortedMap;
|
|||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
|
@ -41,8 +44,8 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
|||
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin;
|
||||
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
|
||||
import org.eclipse.cdt.ui.templateengine.IWizardDataPage;
|
||||
import org.eclipse.cdt.ui.templateengine.Template;
|
||||
|
@ -549,6 +552,13 @@ public class MBSWizardHandler extends CWizardHandler {
|
|||
}
|
||||
|
||||
private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException {
|
||||
boolean isTryingNewSD = false;
|
||||
IWizardPage page = getStartingPage();
|
||||
if (page instanceof CDTMainWizardPage) {
|
||||
CDTMainWizardPage mainWizardPage = (CDTMainWizardPage)page;
|
||||
isTryingNewSD = mainWizardPage.isTryingNewSD();
|
||||
}
|
||||
|
||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
|
||||
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
|
||||
|
@ -594,9 +604,32 @@ public class MBSWizardHandler extends CWizardHandler {
|
|||
cfgDebug = cfgDes;
|
||||
if (cfgFirst == null) // select at least first configuration
|
||||
cfgFirst = cfgDes;
|
||||
|
||||
if (isTryingNewSD) {
|
||||
CfgScannerConfigProfileManager.disableScannerDiscovery(config);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ManagedBuildManager.getLanguageSettingsProviders(config);
|
||||
cfgDes.setLanguageSettingProviders(providers);
|
||||
} else {
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDes.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
monitor.worked(work);
|
||||
}
|
||||
mngr.setProjectDescription(project, des);
|
||||
|
||||
// FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment
|
||||
if (isTryingNewSD) {
|
||||
des = mngr.getProjectDescription(project);
|
||||
boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des);
|
||||
|
||||
if (isChanged) {
|
||||
mngr.setProjectDescription(project, des);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,10 +11,16 @@
|
|||
package org.eclipse.cdt.managedbuilder.ui.wizards;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
|
@ -68,6 +74,7 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN
|
|||
final String locationStr = page.getLocation();
|
||||
final boolean isCPP = page.isCPP();
|
||||
final IToolChain toolChain = page.getToolChain();
|
||||
final boolean isTryingNewSD = page.isTryingNewSD();
|
||||
|
||||
IRunnableWithProgress op = new WorkspaceModifyOperation() {
|
||||
@Override
|
||||
|
@ -109,13 +116,39 @@ public class NewMakeProjFromExisting extends Wizard implements IImportWizard, IN
|
|||
IBuilder builder = config.getEditableBuilder();
|
||||
builder.setManagedBuildOn(false);
|
||||
CConfigurationData data = config.getConfigurationData();
|
||||
projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
|
||||
ICConfigurationDescription cfgDes = projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
|
||||
|
||||
if (isTryingNewSD) {
|
||||
CfgScannerConfigProfileManager.disableScannerDiscovery(config);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ManagedBuildManager.getLanguageSettingsProviders(config);
|
||||
cfgDes.setLanguageSettingProviders(providers);
|
||||
} else {
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDes.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
|
||||
monitor.worked(1);
|
||||
|
||||
pdMgr.setProjectDescription(project, projDesc);
|
||||
|
||||
// FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment
|
||||
if (isTryingNewSD) {
|
||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription des = mngr.getProjectDescription(project);
|
||||
boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des);
|
||||
|
||||
if (isChanged) {
|
||||
mngr.setProjectDescription(project, des);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ManagedBuilderUIPlugin.log(e);
|
||||
}
|
||||
|
||||
monitor.done();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,6 +19,8 @@ import java.util.Map;
|
|||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
@ -52,6 +54,9 @@ public class NewMakeProjFromExistingPage extends WizardPage {
|
|||
List tcList;
|
||||
Map<String, IToolChain> tcMap = new HashMap<String, IToolChain>();
|
||||
|
||||
private Button checkBoxTryNewSD;
|
||||
|
||||
|
||||
protected NewMakeProjFromExistingPage() {
|
||||
super(Messages.NewMakeProjFromExistingPage_0);
|
||||
setTitle(Messages.NewMakeProjFromExistingPage_1);
|
||||
|
@ -71,6 +76,21 @@ public class NewMakeProjFromExistingPage extends WizardPage {
|
|||
addLanguageSelector(comp);
|
||||
addToolchainSelector(comp);
|
||||
|
||||
checkBoxTryNewSD = new Button(comp, SWT.CHECK);
|
||||
checkBoxTryNewSD.setText(org.eclipse.cdt.internal.ui.newui.Messages.CDTMainWizardPage_TrySD90);
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalSpan = 2;
|
||||
checkBoxTryNewSD.setLayoutData(gd);
|
||||
|
||||
|
||||
// restore settings from preferences
|
||||
boolean isTryNewSD = true;
|
||||
boolean contains = CUIPlugin.getDefault().getPreferenceStore().contains(CDTPrefUtil.KEY_NEWSD);
|
||||
if (contains) {
|
||||
isTryNewSD = CDTPrefUtil.getBool(CDTPrefUtil.KEY_NEWSD);
|
||||
}
|
||||
checkBoxTryNewSD.setSelection(isTryNewSD);
|
||||
|
||||
setControl(comp);
|
||||
}
|
||||
|
||||
|
@ -208,4 +228,7 @@ public class NewMakeProjFromExistingPage extends WizardPage {
|
|||
return selection.length != 0 ? tcMap.get(selection[0]) : null;
|
||||
}
|
||||
|
||||
public boolean isTryingNewSD() {
|
||||
return checkBoxTryNewSD.getSelection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,14 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.ui.wizards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
|
@ -24,10 +31,12 @@ import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
|||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
|
||||
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.wizard.IWizard;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
/**
|
||||
|
@ -71,6 +80,14 @@ public class STDWizardHandler extends MBSWizardHandler {
|
|||
|
||||
private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
|
||||
boolean isTryingNewSD = false;
|
||||
IWizardPage page = getStartingPage();
|
||||
if (page instanceof CDTMainWizardPage) {
|
||||
CDTMainWizardPage mainWizardPage = (CDTMainWizardPage)page;
|
||||
isTryingNewSD = mainWizardPage.isTryingNewSD();
|
||||
}
|
||||
|
||||
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
|
||||
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
|
||||
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
|
||||
|
@ -99,10 +116,33 @@ public class STDWizardHandler extends MBSWizardHandler {
|
|||
}
|
||||
cfg.setArtifactName(mProj.getDefaultArtifactName());
|
||||
CConfigurationData data = cfg.getConfigurationData();
|
||||
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
|
||||
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
|
||||
|
||||
if (isTryingNewSD) {
|
||||
CfgScannerConfigProfileManager.disableScannerDiscovery(cfg);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = ManagedBuildManager.getLanguageSettingsProviders(cfg);
|
||||
cfgDes.setLanguageSettingProviders(providers);
|
||||
} else {
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(ManagedBuildManager.MBS_LANGUAGE_SETTINGS_PROVIDER);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDes.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
monitor.worked(work);
|
||||
}
|
||||
mngr.setProjectDescription(project, des);
|
||||
|
||||
// FIXME if scanner discovery is empty it is "fixed" deeply inside setProjectDescription(), taking the easy road here for the moment
|
||||
if (isTryingNewSD) {
|
||||
des = mngr.getProjectDescription(project);
|
||||
boolean isChanged = CfgScannerConfigProfileManager.disableScannerDiscovery(des);
|
||||
|
||||
if (isChanged) {
|
||||
mngr.setProjectDescription(project, des);
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean canCreateWithoutToolchain() { return true; }
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.internal.tests.filesystem.ram;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.cdt.core.EFSExtensionProvider;
|
||||
|
||||
/**
|
||||
* Test stub to test EFSExtensionProvider mappings.
|
||||
*
|
||||
*/
|
||||
public class MemoryEFSExtensionProvider extends EFSExtensionProvider {
|
||||
|
||||
public String getMappedPath(URI locationURI) {
|
||||
|
||||
String path = locationURI.getPath();
|
||||
if (path.contains("/BeingMappedFrom/Folder")) {
|
||||
return path.replaceFirst("/BeingMappedFrom/Folder", "/LocallyMappedTo/Folder");
|
||||
}
|
||||
|
||||
return super.getMappedPath(locationURI);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
|
||||
public class AllLanguageSettingsProvidersTests {
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(AllLanguageSettingsProvidersTests.class.getName());
|
||||
|
||||
suite.addTest(LanguageSettingsExtensionsTests.suite());
|
||||
suite.addTest(LanguageSettingsManagerTests.suite());
|
||||
suite.addTest(LanguageSettingsSerializableTests.suite());
|
||||
suite.addTest(LanguageSettingsPersistenceProjectTests.suite());
|
||||
suite.addTest(LanguageSettingsScannerInfoProviderTests.suite());
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,324 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryPathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
* Test cases testing LanguageSettingsProvider functionality
|
||||
*/
|
||||
public class LanguageSettingsExtensionsTests extends TestCase {
|
||||
// These should match corresponding entries defined in plugin.xml
|
||||
private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider";
|
||||
private static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Language Settings Base Provider";
|
||||
private static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id";
|
||||
private static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter";
|
||||
private static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider";
|
||||
private static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Language Settings Provider";
|
||||
private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass";
|
||||
private static final String EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER = "custom parameter subclass";
|
||||
private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider";
|
||||
private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider";
|
||||
|
||||
// These are made up
|
||||
private static final String PROVIDER_0 = "test.provider.0.id";
|
||||
private static final String PROVIDER_NAME_0 = "test.provider.0.name";
|
||||
private static final String LANG_ID = "test.lang.id";
|
||||
private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0"));
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param name - name of the test.
|
||||
*/
|
||||
public LanguageSettingsExtensionsTests(String name) {
|
||||
super(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return - new TestSuite.
|
||||
*/
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LanguageSettingsExtensionsTests.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* main function of the class.
|
||||
*
|
||||
* @param args - arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that regular ICLanguageSettingsProvider extension defined in plugin.xml is accessible.
|
||||
*/
|
||||
public void testExtension() throws Exception {
|
||||
{
|
||||
List<ILanguageSettingsProvider> providers = LanguageSettingsManager.getWorkspaceProviders();
|
||||
List<String> ids = new ArrayList<String>();
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
ids.add(provider.getId());
|
||||
}
|
||||
assertTrue("extension " + EXTENSION_BASE_PROVIDER_ID + " not found", ids.contains(EXTENSION_BASE_PROVIDER_ID));
|
||||
}
|
||||
|
||||
{
|
||||
// test provider not in the list
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy("missing.povider");
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
|
||||
assertNull(rawProvider);
|
||||
}
|
||||
|
||||
// get test plugin extension provider
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_PROVIDER_ID);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
|
||||
// get raw extension provider
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
|
||||
assertTrue(rawProvider instanceof LanguageSettingsBaseProvider);
|
||||
LanguageSettingsBaseProvider provider = (LanguageSettingsBaseProvider)rawProvider;
|
||||
assertEquals(EXTENSION_BASE_PROVIDER_ID, provider.getId());
|
||||
assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName());
|
||||
assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getCustomParameter());
|
||||
|
||||
// attempt to get entries for wrong language
|
||||
assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID));
|
||||
|
||||
// benchmarks matching extension point definition
|
||||
List<ICLanguageSettingEntry> entriesExt = new ArrayList<ICLanguageSettingEntry>();
|
||||
entriesExt.add(new CIncludePathEntry("/usr/include/",
|
||||
ICSettingEntry.BUILTIN
|
||||
| ICSettingEntry.LOCAL
|
||||
| ICSettingEntry.RESOLVED
|
||||
| ICSettingEntry.VALUE_WORKSPACE_PATH
|
||||
| ICSettingEntry.UNDEFINED
|
||||
));
|
||||
entriesExt.add(new CMacroEntry("TEST_DEFINE", "100", 0));
|
||||
entriesExt.add(new CIncludeFileEntry("/include/file.inc", 0));
|
||||
entriesExt.add(new CLibraryPathEntry("/usr/lib/", 0));
|
||||
entriesExt.add(new CLibraryFileEntry("libdomain.a", 0));
|
||||
entriesExt.add(new CMacroFileEntry("/macro/file.mac", 0));
|
||||
|
||||
// retrieve entries from extension point
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, FILE_0, EXTENSION_BASE_PROVIDER_LANG_ID);
|
||||
for (int i=0;i<entriesExt.size();i++) {
|
||||
assertEquals("i="+i, entriesExt.get(i), actual.get(i));
|
||||
}
|
||||
assertEquals(entriesExt.size(), actual.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that subclassed LanguageSettingsBaseProvider extension defined in plugin.xml is accessible.
|
||||
*/
|
||||
public void testExtensionBaseProviderSubclass() throws Exception {
|
||||
// get test plugin extension provider
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_BASE_SUBCLASS_PROVIDER_ID);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
|
||||
// get raw extension provider
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
|
||||
assertTrue(rawProvider instanceof MockLanguageSettingsBaseProvider);
|
||||
MockLanguageSettingsBaseProvider provider = (MockLanguageSettingsBaseProvider)rawProvider;
|
||||
assertEquals(EXTENSION_BASE_SUBCLASS_PROVIDER_ID, provider.getId());
|
||||
assertEquals(EXTENSION_BASE_SUBCLASS_PROVIDER_PARAMETER, provider.getCustomParameter());
|
||||
|
||||
// Test for null languages
|
||||
assertNull(provider.getLanguageScope());
|
||||
|
||||
// benchmarks matching extension point definition
|
||||
List<ICLanguageSettingEntry> entriesExt = new ArrayList<ICLanguageSettingEntry>();
|
||||
entriesExt.add(new CIncludePathEntry("/usr/include/", ICSettingEntry.BUILTIN));
|
||||
|
||||
// retrieve entries from extension point
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, FILE_0, LANG_ID);
|
||||
for (int i=0;i<entriesExt.size();i++) {
|
||||
assertEquals("i="+i, entriesExt.get(i), actual.get(i));
|
||||
}
|
||||
assertEquals(entriesExt.size(), actual.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure extensions contributed through extension point created with proper ID/name.
|
||||
*/
|
||||
public void testExtensionCustomProvider() throws Exception {
|
||||
// get test plugin extension non-default provider
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_CUSTOM_PROVIDER_ID);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
|
||||
// get raw extension provider
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
|
||||
assertTrue(rawProvider instanceof MockLanguageSettingsProvider);
|
||||
|
||||
assertEquals(EXTENSION_CUSTOM_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(EXTENSION_CUSTOM_PROVIDER_NAME, rawProvider.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test for LanguageSettingsBaseProvider.
|
||||
*/
|
||||
public void testBaseProvider() throws Exception {
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
List<String> languages = new ArrayList<String>(2);
|
||||
languages.add("bogus.language.id");
|
||||
languages.add(LANG_ID);
|
||||
|
||||
// add default provider
|
||||
LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider(
|
||||
PROVIDER_0, PROVIDER_NAME_0, languages, entries);
|
||||
|
||||
{
|
||||
// attempt to get entries for wrong language
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, FILE_0, "wrong.lang.id");
|
||||
assertNull(actual);
|
||||
}
|
||||
|
||||
{
|
||||
// retrieve the entries
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, FILE_0, LANG_ID);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertNotSame(entries, actual);
|
||||
// retrieve languages
|
||||
List<String> actualLanguageIds = provider.getLanguageScope();
|
||||
for (String languageId: languages) {
|
||||
assertTrue(actualLanguageIds.contains(languageId));
|
||||
}
|
||||
assertEquals(languages.size(), actualLanguageIds.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
public void testSerializableProvider() throws Exception {
|
||||
// get test plugin extension for serializable provider
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
|
||||
// get raw extension provider
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
|
||||
assertTrue(rawProvider instanceof LanguageSettingsSerializable);
|
||||
LanguageSettingsSerializable provider = (LanguageSettingsSerializable) rawProvider;
|
||||
|
||||
assertEquals(null, provider.getLanguageScope());
|
||||
assertEquals("", provider.getCustomParameter());
|
||||
|
||||
List<ICLanguageSettingEntry> expected = new ArrayList<ICLanguageSettingEntry>();
|
||||
expected.add(new CMacroEntry("MACRO", "value", 0));
|
||||
assertEquals(expected, provider.getSettingEntries(null, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
public void testEditableProvider() throws Exception {
|
||||
// Non-editable providers cannot be copied so they are singletons
|
||||
{
|
||||
// get test plugin extension for serializable provider
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
|
||||
// get raw extension provider
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(providerExt);
|
||||
assertTrue(rawProvider instanceof LanguageSettingsSerializable);
|
||||
assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(rawProvider));
|
||||
|
||||
// compare with workspace provider
|
||||
ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp);
|
||||
assertSame(rawProvider, providerWspRaw);
|
||||
}
|
||||
|
||||
// Editable providers are retrieved by copy
|
||||
{
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertFalse(LanguageSettingsManager.isWorkspaceProvider(providerExt));
|
||||
assertTrue(providerExt instanceof ILanguageSettingsEditableProvider);
|
||||
assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerExt));
|
||||
|
||||
ILanguageSettingsProvider providerExt2 = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertNotSame(providerExt, providerExt2);
|
||||
assertEquals(providerExt, providerExt2);
|
||||
|
||||
ILanguageSettingsProvider providerWsp = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
ILanguageSettingsProvider providerWspRaw = LanguageSettingsManager.getRawProvider(providerWsp);
|
||||
assertNotSame(providerExt, providerWspRaw);
|
||||
assertEquals(providerExt, providerWspRaw);
|
||||
assertTrue(LanguageSettingsExtensionManager.equalsExtensionProvider(providerWspRaw));
|
||||
}
|
||||
|
||||
// Test shallow copy
|
||||
{
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getExtensionProviderCopy(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertNotNull(provider);
|
||||
assertTrue(provider instanceof ILanguageSettingsEditableProvider);
|
||||
|
||||
ILanguageSettingsProvider providerShallow = LanguageSettingsExtensionManager.getExtensionProviderShallow(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertNotNull(providerShallow);
|
||||
assertTrue(providerShallow instanceof ILanguageSettingsEditableProvider);
|
||||
assertFalse(provider.equals(providerShallow));
|
||||
|
||||
assertFalse(LanguageSettingsExtensionManager.equalsExtensionProvider(providerShallow));
|
||||
assertTrue(LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) providerShallow));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * LanguageSettingsBaseProvider is not allowed to be configured twice.
|
||||
// */
|
||||
// public void testBaseProviderConfigure() throws Exception {
|
||||
// // create LanguageSettingsBaseProvider
|
||||
// LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider();
|
||||
// List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
// entries.add(new CIncludePathEntry("/usr/include/", 0));
|
||||
// // configure it
|
||||
// provider.configureProvider("id", "name", null, entries, null);
|
||||
//
|
||||
// try {
|
||||
// // attempt to configure it twice should fail
|
||||
// provider.configureProvider("id", "name", null, entries, null);
|
||||
// fail("LanguageSettingsBaseProvider is not allowed to be configured twice");
|
||||
// } catch (UnsupportedOperationException e) {
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,904 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.testplugin.CModelMock;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescription;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
* Test cases testing LanguageSettingsProvider functionality
|
||||
*/
|
||||
public class LanguageSettingsManagerTests extends TestCase {
|
||||
// Should match id of extension point defined in plugin.xml
|
||||
private static final String EXTENSION_BASE_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider";
|
||||
private static final String EXTENSION_EDITABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.editable.language.settings.provider";
|
||||
private static final String EXTENSION_EDITABLE_PROVIDER_NAME = "Test Plugin Editable Language Settings Provider";
|
||||
|
||||
private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0"));
|
||||
private static final String CFG_ID = "test.configuration.id";
|
||||
private static final String LANG_ID = "test.lang.id";
|
||||
private static final String PROVIDER_0 = "test.provider.0.id";
|
||||
private static final String PROVIDER_1 = "test.provider.1.id";
|
||||
private static final String PROVIDER_2 = "test.provider.2.id";
|
||||
private static final String PROVIDER_NAME_0 = "test.provider.0.name";
|
||||
private static final String PROVIDER_NAME_1 = "test.provider.1.name";
|
||||
private static final String PROVIDER_NAME_2 = "test.provider.2.name";
|
||||
|
||||
class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription {
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
public MockConfigurationDescription(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
this.providers = new ArrayList<ILanguageSettingsProvider>(providers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
return providers;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider {
|
||||
private List<ICLanguageSettingEntry> entries;
|
||||
|
||||
public MockProvider(String id, String name, List<ICLanguageSettingEntry> entries) {
|
||||
super(id, name);
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param name - name of the test.
|
||||
*/
|
||||
public LanguageSettingsManagerTests(String name) {
|
||||
super(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
LanguageSettingsManager.setWorkspaceProviders(null);
|
||||
ResourceHelper.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return - new TestSuite.
|
||||
*/
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LanguageSettingsManagerTests.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* main function of the class.
|
||||
*
|
||||
* @param args - arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ICConfigurationDescription API (getters and setters).
|
||||
*/
|
||||
public void testConfigurationDescription_Providers() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// set providers
|
||||
ILanguageSettingsProvider provider1 = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null);
|
||||
ILanguageSettingsProvider provider2 = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, null);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider1);
|
||||
providers.add(provider2);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// get providers
|
||||
List<ILanguageSettingsProvider> actual = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(provider1, actual.get(0));
|
||||
assertEquals(provider2, actual.get(1));
|
||||
assertEquals(providers.size(), actual.size());
|
||||
assertNotSame(actual, providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure uniqueness of ids for providers kept in configuration description.
|
||||
*/
|
||||
public void testConfigurationDescription_ProvidersUniqueId() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project, true);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
// attempt to add duplicate providers
|
||||
MockProvider dupe1 = new MockProvider(PROVIDER_0, PROVIDER_NAME_1, null);
|
||||
MockProvider dupe2 = new MockProvider(PROVIDER_0, PROVIDER_NAME_2, null);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(dupe1);
|
||||
providers.add(dupe2);
|
||||
|
||||
try {
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
fail("cfgDescription.setLanguageSettingProviders() should not accept duplicate providers");
|
||||
} catch (Exception e) {
|
||||
// Exception is welcome here
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test various cases of ill-defined providers.
|
||||
*/
|
||||
public void testRudeProviders() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
// set impolite provider returning null by getSettingEntries()
|
||||
ILanguageSettingsProvider providerNull = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null);
|
||||
{
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(providerNull);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
// use provider returning null, no exception should be recorded
|
||||
{
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(providerNull, cfgDescription, FILE_0, LANG_ID);
|
||||
assertNotNull(actual);
|
||||
assertEquals(0, actual.size());
|
||||
}
|
||||
{
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, 0);
|
||||
assertNotNull(actual);
|
||||
assertEquals(0, actual.size());
|
||||
}
|
||||
|
||||
// set impolite provider returning null in getSettingEntries() array
|
||||
ILanguageSettingsProvider providerNull_2 = new MockProvider(PROVIDER_2, PROVIDER_NAME_2,
|
||||
new ArrayList<ICLanguageSettingEntry>() {
|
||||
{ // init via static initializer
|
||||
add(null);
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(providerNull);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
// use provider returning null as item in array
|
||||
{
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(providerNull_2, cfgDescription, FILE_0, LANG_ID);
|
||||
assertNotNull(actual);
|
||||
assertEquals(1, actual.size());
|
||||
}
|
||||
{
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, 0);
|
||||
assertNotNull(actual);
|
||||
assertEquals(0, actual.size());
|
||||
}
|
||||
|
||||
// use careless provider causing an exception
|
||||
{
|
||||
ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) {
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
throw new NullPointerException("Can you handle me?");
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(providerNPE, null, null, LANG_ID);
|
||||
assertNotNull(actual);
|
||||
assertEquals(0, actual.size());
|
||||
} catch (Throwable e) {
|
||||
fail("Exceptions are expected to be swallowed (after logging) but got " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test simple use case.
|
||||
*/
|
||||
public void testProvider_Basic() throws Exception {
|
||||
final ICConfigurationDescription modelCfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
final List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
// define provider returning entries when configuration id matches and null otherwise
|
||||
ILanguageSettingsProvider providerYes = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) {
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (cfgDescription.getId().equals(modelCfgDescription.getId())) {
|
||||
return entries;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
providers.add(providerYes);
|
||||
// define provider returning null when configuration id matches and some entries otherwise
|
||||
ILanguageSettingsProvider providerNo = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) {
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (cfgDescription.getId().equals(modelCfgDescription.getId())) {
|
||||
return null;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
};
|
||||
providers.add(providerNo);
|
||||
modelCfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
{
|
||||
// retrieve the entries with provider returning the given list
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(providerYes, modelCfgDescription, FILE_0, LANG_ID);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
|
||||
{
|
||||
// retrieve the entries with provider returning empty list
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(providerNo, modelCfgDescription, FILE_0, LANG_ID);
|
||||
assertEquals(0, actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test regular functionality with a few providers.
|
||||
*/
|
||||
public void testProvider_Regular() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// create couple of providers
|
||||
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries1.add(new CIncludePathEntry("value1", 1));
|
||||
entries1.add(new CIncludePathEntry("value2", 2));
|
||||
|
||||
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries2.add(new CIncludePathEntry("value1", 1));
|
||||
entries2.add(new CIncludePathEntry("value2", 2));
|
||||
entries2.add(new CIncludePathEntry("value3", 2));
|
||||
|
||||
ILanguageSettingsProvider provider1 = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, entries1);
|
||||
ILanguageSettingsProvider provider2 = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, entries2);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider1);
|
||||
providers.add(provider2);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
{
|
||||
// retrieve the entries for provider-1
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(provider1, cfgDescription, FILE_0, LANG_ID);
|
||||
assertNotSame(entries1, actual);
|
||||
|
||||
ICLanguageSettingEntry[] entriesArray = entries1.toArray(new ICLanguageSettingEntry[0]);
|
||||
ICLanguageSettingEntry[] actualArray = actual.toArray(new ICLanguageSettingEntry[0]);
|
||||
for (int i=0;i<entries1.size();i++) {
|
||||
assertEquals("i="+i, entriesArray[i], actualArray[i]);
|
||||
}
|
||||
assertEquals(entries1.size(), actual.size());
|
||||
}
|
||||
|
||||
{
|
||||
// retrieve the entries for provider-2
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(provider2, cfgDescription, FILE_0, LANG_ID);
|
||||
assertNotSame(entries2, actual);
|
||||
|
||||
ICLanguageSettingEntry[] entriesArray = entries2.toArray(new ICLanguageSettingEntry[0]);
|
||||
ICLanguageSettingEntry[] actualArray = actual.toArray(new ICLanguageSettingEntry[0]);
|
||||
for (int i=0;i<entries2.size();i++) {
|
||||
assertEquals("i="+i, entriesArray[i], actualArray[i]);
|
||||
}
|
||||
assertEquals(entries2.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProvider_ParentFolder() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
|
||||
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
final IFolder parentFolder = ResourceHelper.createFolder(project, "/ParentFolder/");
|
||||
assertNotNull(parentFolder);
|
||||
final IFile emptySettingsPath = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/empty");
|
||||
assertNotNull(emptySettingsPath);
|
||||
|
||||
// store the entries in parent folder
|
||||
final List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) {
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (rc.equals(parentFolder)) {
|
||||
return entries;
|
||||
}
|
||||
if (rc.equals(emptySettingsPath)) {
|
||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
{
|
||||
// retrieve entries for a derived resource (in a subfolder)
|
||||
IFile derived = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/resource");
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(provider, cfgDescription, derived, LANG_ID);
|
||||
// taken from parent folder
|
||||
assertEquals(entries.get(0),actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
|
||||
{
|
||||
// retrieve entries for not related resource
|
||||
IFile notRelated = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/AnotherFolder/Subfolder/resource"));
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(provider, cfgDescription, notRelated, LANG_ID);
|
||||
assertEquals(0, actual.size());
|
||||
}
|
||||
|
||||
{
|
||||
// test distinction between no settings and empty settings
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(provider, cfgDescription, emptySettingsPath, LANG_ID);
|
||||
// NOT taken from parent folder
|
||||
assertEquals(0, actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProvider_DefaultEntries() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project);
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
|
||||
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
final IFolder parentFolder = ResourceHelper.createFolder(project, "/ParentFolder/");
|
||||
assertNotNull(parentFolder);
|
||||
final IFile emptySettingsPath = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/empty");
|
||||
assertNotNull(emptySettingsPath);
|
||||
|
||||
// store the entries as default entries
|
||||
final List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, null) {
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (cfgDescription==null && rc==null) {
|
||||
return entries;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
{
|
||||
// retrieve entries for a resource
|
||||
IFile derived = ResourceHelper.createFile(project, "/ParentFolder/Subfolder/resource");
|
||||
List<ICLanguageSettingEntry> actual = LanguageSettingsManager
|
||||
.getSettingEntriesUpResourceTree(provider, cfgDescription, derived, LANG_ID);
|
||||
// default entries given
|
||||
assertEquals(entries.get(0),actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ability to get entries by kind.
|
||||
*/
|
||||
public void testEntriesByKind_Regular() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// contribute the entries
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
entries.add(new CMacroEntry("MACRO0", "value0",0));
|
||||
entries.add(new CIncludePathEntry("path1", 0));
|
||||
entries.add(new CMacroEntry("MACRO1", "value1",0));
|
||||
entries.add(new CIncludePathEntry("path2", 0));
|
||||
|
||||
ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider0);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// retrieve entries by kind
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
assertEquals(new CIncludePathEntry("path0", 0),includes.get(0));
|
||||
assertEquals(new CIncludePathEntry("path1", 0),includes.get(1));
|
||||
assertEquals(new CIncludePathEntry("path2", 0),includes.get(2));
|
||||
assertEquals(3, includes.size());
|
||||
|
||||
List<ICLanguageSettingEntry> macros = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.MACRO);
|
||||
assertEquals(new CMacroEntry("MACRO0", "value0",0), macros.get(0));
|
||||
assertEquals(new CMacroEntry("MACRO1", "value1",0), macros.get(1));
|
||||
assertEquals(2, macros.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test how conflicting entries are resolved.
|
||||
*/
|
||||
public void testEntriesByKind_ConflictingEntries() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// contribute the entries
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path", ICSettingEntry.BUILTIN));
|
||||
entries.add(new CIncludePathEntry("path", ICSettingEntry.UNDEFINED));
|
||||
entries.add(new CIncludePathEntry("path", 0));
|
||||
|
||||
ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider0);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// retrieve entries by kind, only first entry should be returned
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
assertEquals(1, includes.size());
|
||||
assertEquals(entries.get(0),includes.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check handling of {@link ICSettingEntry#UNDEFINED} flag.
|
||||
*/
|
||||
public void testEntriesByKind_Undefined() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// contribute the entries
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path", ICSettingEntry.UNDEFINED));
|
||||
entries.add(new CIncludePathEntry("path", 0));
|
||||
|
||||
ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider0);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// retrieve entries by kind, no entries should be returned
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
assertEquals(0, includes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check handling of local vs. system entries, see {@link ICSettingEntry#LOCAL} flag.
|
||||
*/
|
||||
public void testEntriesByKind_LocalAndSystem() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// contribute the entries
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
CIncludePathEntry localIncludeEntry = new CIncludePathEntry("path-local", ICSettingEntry.LOCAL);
|
||||
CIncludePathEntry systemIncludeEntry = new CIncludePathEntry("path-system", 0);
|
||||
entries.add(localIncludeEntry);
|
||||
entries.add(systemIncludeEntry);
|
||||
|
||||
ILanguageSettingsProvider provider0 = new MockProvider(PROVIDER_0, PROVIDER_NAME_0, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider0);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
{
|
||||
// retrieve local entries
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsExtensionManager
|
||||
.getLocalSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
assertEquals(localIncludeEntry, includes.get(0));
|
||||
assertEquals(1, includes.size());
|
||||
}
|
||||
|
||||
{
|
||||
// retrieve system entries
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsExtensionManager
|
||||
.getSystemSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
assertEquals(systemIncludeEntry, includes.get(0));
|
||||
assertEquals(1, includes.size());
|
||||
}
|
||||
|
||||
{
|
||||
// retrieve both local and system
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsExtensionManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
assertEquals(entries.get(0), includes.get(0));
|
||||
assertEquals(entries.get(1), includes.get(1));
|
||||
assertEquals(2, includes.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test conflicting entries contributed by different providers.
|
||||
*/
|
||||
public void testEntriesByKind_ConflictingProviders() throws Exception {
|
||||
ICConfigurationDescription cfgDescription = new MockConfigurationDescription(CFG_ID);
|
||||
|
||||
// contribute the entries
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
|
||||
// contribute the higher ranked entries
|
||||
List<ICLanguageSettingEntry> entriesHigh = new ArrayList<ICLanguageSettingEntry>();
|
||||
entriesHigh.add(new CIncludePathEntry("path0", ICSettingEntry.RESOLVED));
|
||||
entriesHigh.add(new CIncludePathEntry("path1", 0));
|
||||
entriesHigh.add(new CIncludePathEntry("path2", ICSettingEntry.UNDEFINED));
|
||||
ILanguageSettingsProvider highRankProvider = new MockProvider(PROVIDER_2, PROVIDER_NAME_2, entriesHigh);
|
||||
providers.add(highRankProvider);
|
||||
|
||||
// contribute the lower ranked entries
|
||||
List<ICLanguageSettingEntry> entriesLow = new ArrayList<ICLanguageSettingEntry>();
|
||||
entriesLow.add(new CIncludePathEntry("path0", ICSettingEntry.BUILTIN));
|
||||
entriesLow.add(new CIncludePathEntry("path1", ICSettingEntry.UNDEFINED));
|
||||
entriesLow.add(new CIncludePathEntry("path2", 0));
|
||||
entriesLow.add(new CIncludePathEntry("path3", 0));
|
||||
ILanguageSettingsProvider lowRankProvider = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, entriesLow);
|
||||
providers.add(lowRankProvider);
|
||||
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// retrieve entries by kind
|
||||
List<ICLanguageSettingEntry> includes = LanguageSettingsManager
|
||||
.getSettingEntriesByKind(cfgDescription, FILE_0, LANG_ID, ICSettingEntry.INCLUDE_PATH);
|
||||
// path0 is taken from higher priority provider
|
||||
assertEquals(entriesHigh.get(0),includes.get(0));
|
||||
// path1 disablement by lower priority provider is ignored
|
||||
assertEquals(entriesHigh.get(1),includes.get(1));
|
||||
// path2 is removed because of DISABLED flag of high priority provider
|
||||
// path3 gets there from low priority provider
|
||||
assertEquals(entriesLow.get(3),includes.get(2));
|
||||
assertEquals(3, includes.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ability to serialize providers for a configuration.
|
||||
*/
|
||||
public void testConfigurationDescription_SerializeProviders() throws Exception {
|
||||
// Create model project and accompanied descriptions
|
||||
String projectName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
|
||||
ICProjectDescription writableProjDescription = CoreModel.getDefault().getProjectDescription(project, true);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_BASE_PROVIDER_ID);
|
||||
assertNotNull(workspaceProvider);
|
||||
{
|
||||
// ensure no test provider is set yet
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// set test provider
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(workspaceProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
{
|
||||
// check that test provider got there
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(workspaceProvider, providers.get(0));
|
||||
}
|
||||
|
||||
{
|
||||
// serialize
|
||||
CoreModel.getDefault().setProjectDescription(project, writableProjDescription);
|
||||
// close and reopen the project
|
||||
project.close(null);
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
{
|
||||
// check that test provider got loaded
|
||||
ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project);
|
||||
ICConfigurationDescription[] loadedCfgDescriptions = prjDescription.getConfigurations();
|
||||
ICConfigurationDescription loadedCfgDescription = loadedCfgDescriptions[0];
|
||||
assertTrue(cfgDescription instanceof CConfigurationDescription);
|
||||
|
||||
List<ILanguageSettingsProvider> loadedProviders = loadedCfgDescription.getLanguageSettingProviders();
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(loadedProviders.get(0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a workspace provider basics.
|
||||
*/
|
||||
public void testWorkspaceProvider_Basic() throws Exception {
|
||||
// get workspace provider
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, provider.getId());
|
||||
assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, provider.getName());
|
||||
|
||||
// get raw provider
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertEquals(EXTENSION_EDITABLE_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(EXTENSION_EDITABLE_PROVIDER_NAME, rawProvider.getName());
|
||||
assertTrue(rawProvider instanceof LanguageSettingsSerializable);
|
||||
// assert they are not the same object
|
||||
assertNotSame(provider, rawProvider);
|
||||
|
||||
{
|
||||
// make sure entries are the same
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(1, entries.size()); // defined in the extension
|
||||
List<ICLanguageSettingEntry> rawEntries = rawProvider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries, rawEntries);
|
||||
}
|
||||
|
||||
{
|
||||
// set new entries to the raw provider
|
||||
List<ICLanguageSettingEntry> newEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||
newEntries.add(new CIncludePathEntry("path0", 0));
|
||||
newEntries.add(new CIncludePathEntry("path1", 0));
|
||||
((LanguageSettingsSerializable)rawProvider).setSettingEntries(null, null, null, newEntries);
|
||||
|
||||
// check that the workspace provider gets them too
|
||||
List<ICLanguageSettingEntry> newRawEntries = rawProvider.getSettingEntries(null, null, null);
|
||||
assertEquals(newEntries, newRawEntries);
|
||||
assertEquals(2, newEntries.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test workspace providers equality.
|
||||
*/
|
||||
public void testWorkspaceProvider_Equals() throws Exception {
|
||||
ILanguageSettingsProvider providerA = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
ILanguageSettingsProvider providerB = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
assertEquals(providerA, providerB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ability to replace underlying raw provider.
|
||||
*/
|
||||
public void testWorkspaceProvider_ReplaceRawProvider() throws Exception {
|
||||
// get sample workspace provider
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
{
|
||||
// check on its entries
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(1, entries.size()); // defined in the extension
|
||||
}
|
||||
|
||||
// define new entries for the raw provider
|
||||
List<ICLanguageSettingEntry> newEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||
newEntries.add(new CIncludePathEntry("path0", 0));
|
||||
newEntries.add(new CIncludePathEntry("path1", 0));
|
||||
newEntries.add(new CIncludePathEntry("path2", 0));
|
||||
|
||||
{
|
||||
// replace raw provider
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
LanguageSettingsSerializable newRawProvider = new LanguageSettingsSerializable(EXTENSION_EDITABLE_PROVIDER_ID, PROVIDER_NAME_0);
|
||||
newRawProvider.setSettingEntries(null, null, null, newEntries);
|
||||
providers.add(newRawProvider);
|
||||
LanguageSettingsManager.setWorkspaceProviders(providers);
|
||||
}
|
||||
|
||||
{
|
||||
// check that provider provides the new entries
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(newEntries.size(), entries.size());
|
||||
assertEquals(newEntries, entries);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ability to be called with workspace provider as well (NOOP).
|
||||
*/
|
||||
public void testWorkspaceProvider_ReplaceWithWorkspaceProvider() throws Exception {
|
||||
// get sample workspace provider
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_EDITABLE_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertNotSame(provider, rawProvider);
|
||||
|
||||
// attempt to "replace" with workspace provider (which is a wrapper around raw provider), should be NOOP
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
LanguageSettingsManager.setWorkspaceProviders(providers);
|
||||
ILanguageSettingsProvider newRawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertSame(rawProvider, newRawProvider);
|
||||
|
||||
// check for no side effect
|
||||
assertSame(provider, providers.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testBuildResourceTree_FileInFolder() throws Exception {
|
||||
// sample entries
|
||||
CMacroEntry entry = new CMacroEntry("MACRO", null, 0);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(entry);
|
||||
|
||||
// create resources
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
IFile file = ResourceHelper.createFile(project, "file.cpp");
|
||||
assertNotNull(file);
|
||||
|
||||
// create a provider and set the entries
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setSettingEntries(null, file, null, entries);
|
||||
// build the hierarchy
|
||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||
|
||||
// check that entries go to highest possible level
|
||||
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null));
|
||||
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testBuildResourceTree_FileInSubFolder() throws Exception {
|
||||
// sample entries
|
||||
CMacroEntry entry = new CMacroEntry("MACRO", null, 0);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(entry);
|
||||
|
||||
// create resources
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||
IFile file = ResourceHelper.createFile(project, "Folder/file.cpp");
|
||||
|
||||
// create a provider and set the entries
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setSettingEntries(null, file, null, entries);
|
||||
// build the hierarchy
|
||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||
|
||||
// check that entries go to highest possible level
|
||||
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null));
|
||||
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, null));
|
||||
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testBuildResourceTree_TwoSubFolders() throws Exception {
|
||||
// sample entries
|
||||
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries1.add(new CMacroEntry("MACRO_1", null, 0));
|
||||
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries2.add(new CMacroEntry("MACRO_2", null, 0));
|
||||
|
||||
// create resources
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
IFolder folder1 = ResourceHelper.createFolder(project, "Folder1");
|
||||
IFolder folder2 = ResourceHelper.createFolder(project, "Folder2");
|
||||
IFile file1 = ResourceHelper.createFile(project, "Folder1/file1.cpp");
|
||||
IFile file2 = ResourceHelper.createFile(project, "Folder2/file2.cpp");
|
||||
|
||||
// create a provider and set the entries
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setSettingEntries(null, file1, null, entries1);
|
||||
provider.setSettingEntries(null, file2, null, entries2);
|
||||
// build the hierarchy
|
||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||
|
||||
// check that entries go to highest possible level
|
||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder1, null));
|
||||
|
||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder2, null));
|
||||
|
||||
assertEquals(0, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null).size());
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testBuildResourceTree_IncrementalBuildFlippingSettings() throws Exception {
|
||||
// sample entries
|
||||
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries1.add(new CMacroEntry("MACRO_1", null, 0));
|
||||
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries2.add(new CMacroEntry("MACRO_2", null, 0));
|
||||
|
||||
// create resources
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
IFile file1 = ResourceHelper.createFile(project, "file1.cpp");
|
||||
IFile file2 = ResourceHelper.createFile(project, "file2.cpp");
|
||||
IFile file3 = ResourceHelper.createFile(project, "file3.cpp");
|
||||
|
||||
// create a provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
|
||||
// set the entries for the first 2 files
|
||||
provider.setSettingEntries(null, file1, null, entries1);
|
||||
provider.setSettingEntries(null, file2, null, entries1);
|
||||
// build the hierarchy
|
||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||
// double-check where the entries go
|
||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||
|
||||
// set the entries for the second+third files (with overlap)
|
||||
provider.setSettingEntries(null, file2, null, entries2);
|
||||
provider.setSettingEntries(null, file3, null, entries2);
|
||||
// build the hierarchy
|
||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
||||
// check where the entries go, it should not lose entries for the first file
|
||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file3, null));
|
||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,839 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.testplugin.CModelMock;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Test cases testing LanguageSettingsProvider functionality
|
||||
*/
|
||||
public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
||||
// Should match id of extension point defined in plugin.xml
|
||||
private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass";
|
||||
private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Base Provider Subclass";
|
||||
private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider";
|
||||
|
||||
private static final String CFG_ID = "test.configuration.id.0";
|
||||
private static final String CFG_ID_2 = "test.configuration.id.2";
|
||||
private static final String PROVIDER_0 = "test.provider.0.id";
|
||||
private static final String PROVIDER_2 = "test.provider.2.id";
|
||||
private static final String PROVIDER_NAME_0 = "test.provider.0.name";
|
||||
private static final String PROVIDER_NAME_2 = "test.provider.2.name";
|
||||
private static final String PROVIDER_ID_WSP = "test.provider.workspace.id";
|
||||
private static final String PROVIDER_NAME_WSP = "test.provider.workspace.name";
|
||||
private static final String CUSTOM_PARAMETER = "custom parameter";
|
||||
private static final String ELEM_TEST = "test";
|
||||
|
||||
private static CoreModel coreModel = CoreModel.getDefault();
|
||||
|
||||
class MockConfigurationDescription extends CModelMock.DummyCConfigurationDescription {
|
||||
List<ILanguageSettingsProvider> providers;
|
||||
public MockConfigurationDescription(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
this.providers = new ArrayList<ILanguageSettingsProvider>(providers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
return providers;
|
||||
}
|
||||
}
|
||||
class MockProjectDescription extends CModelMock.DummyCProjectDescription {
|
||||
ICConfigurationDescription[] cfgDescriptions;
|
||||
|
||||
public MockProjectDescription(ICConfigurationDescription[] cfgDescriptions) {
|
||||
this.cfgDescriptions = cfgDescriptions;
|
||||
}
|
||||
|
||||
public MockProjectDescription(ICConfigurationDescription cfgDescription) {
|
||||
this.cfgDescriptions = new ICConfigurationDescription[] { cfgDescription };
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICConfigurationDescription[] getConfigurations() {
|
||||
return cfgDescriptions;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICConfigurationDescription getConfigurationById(String id) {
|
||||
for (ICConfigurationDescription cfgDescription : cfgDescriptions) {
|
||||
if (cfgDescription.getId().equals(id))
|
||||
return cfgDescription;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockProvider extends LanguageSettingsSerializable {
|
||||
public MockProvider(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param name - name of the test.
|
||||
*/
|
||||
public LanguageSettingsPersistenceProjectTests(String name) {
|
||||
super(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
LanguageSettingsManager.setWorkspaceProviders(null);
|
||||
ResourceHelper.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return - new TestSuite.
|
||||
*/
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LanguageSettingsPersistenceProjectTests.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* main function of the class.
|
||||
*
|
||||
* @param args - arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) {
|
||||
ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager();
|
||||
// project description
|
||||
ICProjectDescription projectDescription = mngr.getProjectDescription(project);
|
||||
assertNotNull(projectDescription);
|
||||
assertEquals(1, projectDescription.getConfigurations().length);
|
||||
// configuration description
|
||||
ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
return cfgDescriptions;
|
||||
}
|
||||
|
||||
private ICConfigurationDescription getFirstConfigurationDescription(IProject project) {
|
||||
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
|
||||
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
return cfgDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception {
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// get the raw extension provider
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
LanguageSettingsSerializable extProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider);
|
||||
assertNotNull(extProvider);
|
||||
assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, extProvider.getId());
|
||||
|
||||
// add entries
|
||||
extProvider.setSettingEntries(null, null, null, entries);
|
||||
List<ICLanguageSettingEntry> actual = extProvider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
|
||||
// serialize language settings of workspace providers
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace();
|
||||
|
||||
// clear the provider
|
||||
extProvider.setSettingEntries(null, null, null, null);
|
||||
}
|
||||
|
||||
{
|
||||
// doublecheck it's clean
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertNull(actual);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the provider
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, provider.getId());
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testWorkspacePersistence_GlobalProvider() throws Exception {
|
||||
{
|
||||
// get the raw extension provider
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
LanguageSettingsSerializable rawProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider);
|
||||
assertNotNull(rawProvider);
|
||||
assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId());
|
||||
|
||||
// customize provider
|
||||
rawProvider.setCustomParameter(CUSTOM_PARAMETER);
|
||||
assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter());
|
||||
}
|
||||
{
|
||||
// save workspace provider (as opposed to raw provider)
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
providers.add(provider);
|
||||
LanguageSettingsManager.setWorkspaceProviders(providers);
|
||||
}
|
||||
{
|
||||
// check that it has not cleared
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
|
||||
LanguageSettingsSerializable rawProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider);
|
||||
assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testWorkspacePersistence_ShadowedExtensionProvider() throws Exception {
|
||||
{
|
||||
// get the raw extension provider
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
// confirm its type and name
|
||||
assertTrue(rawProvider instanceof LanguageSettingsBaseProvider);
|
||||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName());
|
||||
}
|
||||
{
|
||||
// replace extension provider
|
||||
ILanguageSettingsProvider provider = new MockLanguageSettingsSerializableProvider(EXTENSION_PROVIDER_ID, PROVIDER_NAME_0);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
// note that this will also serialize workspace providers
|
||||
LanguageSettingsManager.setWorkspaceProviders(providers);
|
||||
}
|
||||
{
|
||||
// doublecheck it's in the list
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider);
|
||||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, rawProvider.getName());
|
||||
}
|
||||
|
||||
{
|
||||
// re-load to check serialization
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider);
|
||||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, rawProvider.getName());
|
||||
}
|
||||
|
||||
{
|
||||
// reset workspace providers, that will also serialize
|
||||
LanguageSettingsManager.setWorkspaceProviders(null);
|
||||
}
|
||||
{
|
||||
// doublecheck original one is in the list
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertTrue(rawProvider instanceof LanguageSettingsBaseProvider);
|
||||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName());
|
||||
}
|
||||
{
|
||||
// re-load to check serialization
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertTrue(rawProvider instanceof LanguageSettingsBaseProvider);
|
||||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_SerializableProviderDOM() throws Exception {
|
||||
Element rootElement = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// create a provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
serializableProvider.setSettingEntries(null, null, null, entries);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(serializableProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// prepare DOM storage
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof LanguageSettingsSerializable);
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_TwoConfigurationsDOM() throws Exception {
|
||||
Element rootElement = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries2.add(new CIncludePathEntry("path2", 0));
|
||||
|
||||
{
|
||||
// create a project description with 2 configuration descriptions
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(
|
||||
new MockConfigurationDescription[] {
|
||||
new MockConfigurationDescription(CFG_ID),
|
||||
new MockConfigurationDescription(CFG_ID_2),
|
||||
});
|
||||
{
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
{
|
||||
// populate configuration 1 with provider
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription1);
|
||||
assertEquals(CFG_ID, cfgDescription1.getId());
|
||||
LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
provider1.setSettingEntries(null, null, null, entries);
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider1);
|
||||
cfgDescription1.setLanguageSettingProviders(providers);
|
||||
}
|
||||
{
|
||||
// populate configuration 2 with provider
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertNotNull(cfgDescription2);
|
||||
assertEquals(CFG_ID_2, cfgDescription2.getId());
|
||||
LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
provider2.setSettingEntries(null, null, null, entries2);
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider2);
|
||||
cfgDescription2.setLanguageSettingProviders(providers);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// doublecheck both configuration descriptions
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
{
|
||||
// doublecheck configuration 1
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription1);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription1.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertNotNull(provider);
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
{
|
||||
// doublecheck configuration 2
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertNotNull(cfgDescription2);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription2.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertNotNull(provider);
|
||||
List<ICLanguageSettingEntry> actual2 = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries2.get(0), actual2.get(0));
|
||||
assertEquals(entries2.size(), actual2.size());
|
||||
}
|
||||
}
|
||||
|
||||
// prepare DOM storage
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-create a project description and re-load language settings for each configuration
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(
|
||||
new MockConfigurationDescription[] {
|
||||
new MockConfigurationDescription(CFG_ID),
|
||||
new MockConfigurationDescription(CFG_ID_2),
|
||||
});
|
||||
// load
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(2, cfgDescriptions.length);
|
||||
{
|
||||
// check configuration 1
|
||||
ICConfigurationDescription cfgDescription1 = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription1);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription1.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertNotNull(provider);
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
{
|
||||
// check configuration 2
|
||||
ICConfigurationDescription cfgDescription2 = cfgDescriptions[1];
|
||||
assertNotNull(cfgDescription2);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription2.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertNotNull(provider);
|
||||
List<ICLanguageSettingEntry> actual2 = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries2.get(0), actual2.get(0));
|
||||
assertEquals(entries2.size(), actual2.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_SubclassedSerializableProviderDOM() throws Exception {
|
||||
Element rootElement = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// create a provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
LanguageSettingsSerializable serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0);
|
||||
serializableProvider.setSettingEntries(null, null, null, entries);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(serializableProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// prepare DOM storage
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof MockLanguageSettingsSerializableProvider);
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_ReferenceExtensionProviderDOM() throws Exception {
|
||||
Element rootElement = null;
|
||||
|
||||
// provider of other type (not LanguageSettingsSerializable) defined as an extension
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
|
||||
{
|
||||
// create cfg description
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// populate with provider defined as extension
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(providerExt);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// prepare DOM storage
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// and check the newly loaded provider which should be workspace provider
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertNotNull(provider);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(provider));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_OverrideExtensionProviderDOM() throws Exception {
|
||||
Element rootElement = null;
|
||||
|
||||
// provider set on workspace level overriding an extension
|
||||
String idExt = EXTENSION_PROVIDER_ID;
|
||||
ILanguageSettingsProvider providerExt = LanguageSettingsManager.getWorkspaceProvider(idExt);
|
||||
assertNotNull(providerExt);
|
||||
{
|
||||
// create cfg description
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// populate with provider overriding the extension (must be SerializableLanguageSettingsProvider or a class from another extension)
|
||||
ILanguageSettingsProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(providerOverride);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
|
||||
// prepare DOM storage
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// check the newly loaded provider
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertNotNull(provider);
|
||||
assertTrue(provider instanceof MockLanguageSettingsSerializableProvider);
|
||||
assertEquals(idExt, provider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, provider.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_MixedProvidersDOM() throws Exception {
|
||||
Element rootElement = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries_31 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries_31.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
List<ICLanguageSettingEntry> entries_32 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries_32.add(new CIncludePathEntry("path2", 0));
|
||||
|
||||
ILanguageSettingsProvider providerExt;
|
||||
ILanguageSettingsProvider providerWsp;
|
||||
{
|
||||
// Define providers a bunch
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
{
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// 1. Provider reference to extension from plugin.xml
|
||||
providerExt = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
|
||||
// 2. TODO Provider reference to provider defined in the project
|
||||
|
||||
// 3. Providers defined in a configuration
|
||||
// 3.1
|
||||
LanguageSettingsSerializable mockProvider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
mockProvider1.setSettingEntries(null, null, null, entries_31);
|
||||
// 3.2
|
||||
LanguageSettingsSerializable mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2);
|
||||
mockProvider2.setSettingEntries(null, null, null, entries_32);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(providerExt);
|
||||
providers.add(mockProvider1);
|
||||
providers.add(mockProvider2);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
// prepare DOM storage
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
XmlUtil.toString(doc);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
// 1. Provider reference to extension from plugin.xml
|
||||
ILanguageSettingsProvider provider0 = providers.get(0);
|
||||
assertTrue(LanguageSettingsManager.isWorkspaceProvider(provider0));
|
||||
|
||||
// 2. TODO Provider reference to provider defined in the project
|
||||
|
||||
// 3. Providers defined in a configuration
|
||||
// 3.1
|
||||
{
|
||||
ILanguageSettingsProvider provider1 = providers.get(1);
|
||||
assertTrue(provider1 instanceof LanguageSettingsSerializable);
|
||||
List<ICLanguageSettingEntry> actual = provider1.getSettingEntries(null, null, null);
|
||||
assertEquals(entries_31.get(0), actual.get(0));
|
||||
assertEquals(entries_31.size(), actual.size());
|
||||
}
|
||||
// 3.2
|
||||
{
|
||||
ILanguageSettingsProvider provider2 = providers.get(2);
|
||||
assertTrue(provider2 instanceof MockLanguageSettingsSerializableProvider);
|
||||
List<ICLanguageSettingEntry> actual = provider2.getSettingEntries(null, null, null);
|
||||
assertEquals(entries_32.get(0), actual.get(0));
|
||||
assertEquals(entries_32.size(), actual.size());
|
||||
}
|
||||
assertEquals(3, providers.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_RealProject() throws Exception {
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
String xmlStorageFileLocation;
|
||||
String xmlOutOfTheWay;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project);
|
||||
assertNotNull(writableProjDescription);
|
||||
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
// create a provider
|
||||
LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
mockProvider.setSettingEntries(cfgDescription, null, null, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
coreModel.setProjectDescription(project, writableProjDescription);
|
||||
IFile xmlStorageFile = project.getFile(".settings/language.settings.xml");
|
||||
assertTrue(xmlStorageFile.exists());
|
||||
xmlStorageFileLocation = xmlStorageFile.getLocation().toOSString();
|
||||
}
|
||||
{
|
||||
coreModel.getProjectDescription(project);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof LanguageSettingsSerializable);
|
||||
assertEquals(PROVIDER_0, provider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, provider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
{
|
||||
// Move storage out of the way
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlOutOfTheWay = xmlStorageFileLocation+".out-of-the-way";
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFile.renameTo(xmlFileOut);
|
||||
assertFalse(xmlFile.exists());
|
||||
assertTrue(xmlFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// clear configuration
|
||||
ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project);
|
||||
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
cfgDescription.setLanguageSettingProviders(new ArrayList<ILanguageSettingsProvider>());
|
||||
coreModel.setProjectDescription(project, writableProjDescription);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// re-check if it really took it
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
}
|
||||
{
|
||||
// open to double-check the data is not kept in some other kind of cache
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
// and close
|
||||
project.close(null);
|
||||
}
|
||||
|
||||
{
|
||||
// Move storage back
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlFile.delete();
|
||||
assertFalse("File "+xmlFile+ " still exist", xmlFile.exists());
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFileOut.renameTo(xmlFile);
|
||||
assertTrue("File "+xmlFile+ " does not exist", xmlFile.exists());
|
||||
assertFalse("File "+xmlFileOut+ " still exist", xmlFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// Remove project from internal cache
|
||||
CProjectDescriptionManager.getInstance().projectClosedRemove(project);
|
||||
// open project and check if providers are loaded
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider loadedProvider = providers.get(0);
|
||||
assertTrue(loadedProvider instanceof LanguageSettingsSerializable);
|
||||
assertEquals(PROVIDER_0, loadedProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, loadedProvider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,893 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
* Test cases testing LanguageSettingsProvider functionality
|
||||
*/
|
||||
public class LanguageSettingsScannerInfoProviderTests extends TestCase {
|
||||
private static final IFile FAKE_FILE = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0"));
|
||||
private static final String PROVIDER_ID = "test.provider.id";
|
||||
private static final String PROVIDER_ID_2 = "test.provider.id.2";
|
||||
private static final String PROVIDER_NAME = "test.provider.name";
|
||||
|
||||
private class MockProvider extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider {
|
||||
private final List<ICLanguageSettingEntry> entries;
|
||||
|
||||
public MockProvider(String id, String name, List<ICLanguageSettingEntry> entries) {
|
||||
super(id, name);
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param name - name of the test.
|
||||
*/
|
||||
public LanguageSettingsScannerInfoProviderTests(String name) {
|
||||
super(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
ResourceHelper.cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return - new TestSuite.
|
||||
*/
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LanguageSettingsScannerInfoProviderTests.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* main function of the class.
|
||||
*
|
||||
* @param args - arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets build working directory for DefaultSettingConfiguration being tested.
|
||||
*/
|
||||
private void setBuilderCWD(IProject project, IPath buildCWD) throws CoreException {
|
||||
CProjectDescriptionManager manager = CProjectDescriptionManager.getInstance();
|
||||
{
|
||||
ICProjectDescription prjDescription = manager.getProjectDescription(project, true);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
cfgDescription.getBuildSetting().setBuilderCWD(buildCWD);
|
||||
manager.setProjectDescription(project, prjDescription);
|
||||
// doublecheck builderCWD
|
||||
IPath actualBuildCWD = cfgDescription.getBuildSetting().getBuilderCWD();
|
||||
assertEquals(buildCWD, actualBuildCWD);
|
||||
}
|
||||
{
|
||||
// triplecheck builderCWD for different project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases when some objects are null.
|
||||
*/
|
||||
public void testNulls() throws Exception {
|
||||
{
|
||||
// Handle project==null
|
||||
IResource root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
assertNull(root.getProject());
|
||||
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(root);
|
||||
assertEquals(0, info.getIncludePaths().length);
|
||||
assertEquals(0, info.getDefinedSymbols().size());
|
||||
assertEquals(0, info.getIncludeFiles().length);
|
||||
assertEquals(0, info.getMacroFiles().length);
|
||||
assertEquals(0, info.getLocalIncludePath().length);
|
||||
}
|
||||
|
||||
{
|
||||
// Handle prjDescription==null
|
||||
IProject project = FAKE_FILE.getProject();
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNull(prjDescription);
|
||||
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(FAKE_FILE);
|
||||
assertEquals(0, info.getIncludePaths().length);
|
||||
assertEquals(0, info.getDefinedSymbols().size());
|
||||
assertEquals(0, info.getIncludeFiles().length);
|
||||
assertEquals(0, info.getMacroFiles().length);
|
||||
assertEquals(0, info.getLocalIncludePath().length);
|
||||
}
|
||||
|
||||
{
|
||||
// Handle language==null
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
IFile file = ResourceHelper.createFile(project, "file");
|
||||
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription);
|
||||
assertNull(language);
|
||||
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
assertEquals(0, info.getIncludePaths().length);
|
||||
assertEquals(0, info.getDefinedSymbols().size());
|
||||
assertEquals(0, info.getIncludeFiles().length);
|
||||
assertEquals(0, info.getMacroFiles().length);
|
||||
assertEquals(0, info.getLocalIncludePath().length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test empty scanner info.
|
||||
*/
|
||||
public void testEmpty() throws Exception {
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// confirm that language==null
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription);
|
||||
assertNotNull(language);
|
||||
|
||||
// test that the info is empty
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
assertEquals(0, info.getIncludePaths().length);
|
||||
assertEquals(0, info.getDefinedSymbols().size());
|
||||
assertEquals(0, info.getIncludeFiles().length);
|
||||
assertEquals(0, info.getMacroFiles().length);
|
||||
assertEquals(0, info.getLocalIncludePath().length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test regular cases.
|
||||
*/
|
||||
public void testRegular() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// sanity test of language
|
||||
ILanguage language = LanguageManager.getInstance().getLanguageForFile(file, cfgDescription);
|
||||
assertNotNull(language);
|
||||
|
||||
// contribute the entries
|
||||
IFolder includeFolder = ResourceHelper.createFolder(project, "/include-path");
|
||||
IFolder includeLocalFolder = ResourceHelper.createFolder(project, "/local-include-path");
|
||||
IFile macroFile = ResourceHelper.createFile(project, "macro-file");
|
||||
IFile includeFile = ResourceHelper.createFile(project, "include-file");
|
||||
|
||||
CIncludePathEntry includePathEntry = new CIncludePathEntry(includeFolder, 0);
|
||||
CIncludePathEntry includeLocalPathEntry = new CIncludePathEntry(includeLocalFolder, ICSettingEntry.LOCAL); // #include "..."
|
||||
CMacroEntry macroEntry = new CMacroEntry("MACRO", "value",0);
|
||||
CIncludeFileEntry includeFileEntry = new CIncludeFileEntry(includeFile, 0);
|
||||
CMacroFileEntry macroFileEntry = new CMacroFileEntry(macroFile, 0);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(includePathEntry);
|
||||
entries.add(includeLocalPathEntry);
|
||||
entries.add(macroEntry);
|
||||
entries.add(includeFileEntry);
|
||||
entries.add(macroFileEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test that the scannerInfoProvider gets the entries
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
Map<String, String> actualDefinedSymbols = info.getDefinedSymbols();
|
||||
String[] actualIncludeFiles = info.getIncludeFiles();
|
||||
String[] actualMacroFiles = info.getMacroFiles();
|
||||
String[] actualLocalIncludePath = info.getLocalIncludePath();
|
||||
// include paths
|
||||
assertEquals(includeFolder.getLocation(), new Path(actualIncludePaths[0]));
|
||||
assertEquals(1, actualIncludePaths.length);
|
||||
// macros
|
||||
assertEquals(macroEntry.getValue(), actualDefinedSymbols.get(macroEntry.getName()));
|
||||
assertEquals(1, actualDefinedSymbols.size());
|
||||
// include file
|
||||
assertEquals(includeFile.getLocation(), new Path(actualIncludeFiles[0]));
|
||||
assertEquals(1, actualIncludeFiles.length);
|
||||
// macro file
|
||||
assertEquals(macroFile.getLocation(), new Path(actualMacroFiles[0]));
|
||||
assertEquals(1, actualMacroFiles.length);
|
||||
// local include files
|
||||
assertEquals(includeLocalFolder.getLocation(), new Path(actualLocalIncludePath[0]));
|
||||
assertEquals(1, actualLocalIncludePath.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test "local" flag (#include "...").
|
||||
*/
|
||||
public void testLocal() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
IFolder incFolder = ResourceHelper.createFolder(project, "include");
|
||||
IFolder incFolder2 = ResourceHelper.createFolder(project, "include2");
|
||||
CIncludePathEntry includePathEntry = new CIncludePathEntry(incFolder, 0);
|
||||
CIncludePathEntry includeLocalPathEntry = new CIncludePathEntry(incFolder, ICSettingEntry.LOCAL); // #include "..."
|
||||
CIncludePathEntry includeLocalPathEntry2 = new CIncludePathEntry(incFolder2, ICSettingEntry.LOCAL); // #include "..."
|
||||
CIncludePathEntry includePathEntry2 = new CIncludePathEntry(incFolder2, 0);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(includePathEntry);
|
||||
entries.add(includeLocalPathEntry);
|
||||
// reverse order for incPath2
|
||||
entries.add(includeLocalPathEntry2);
|
||||
entries.add(includePathEntry2);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test that the scannerInfoProvider gets the entries
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
String[] actualLocalIncludePath = info.getLocalIncludePath();
|
||||
// include paths
|
||||
assertEquals(incFolder.getLocation(), new Path(actualIncludePaths[0]));
|
||||
assertEquals(incFolder2.getLocation(), new Path(actualIncludePaths[1]));
|
||||
assertEquals(2, actualIncludePaths.length);
|
||||
// local include files
|
||||
assertEquals(incFolder.getLocation(), new Path(actualLocalIncludePath[0]));
|
||||
assertEquals(incFolder2.getLocation(), new Path(actualLocalIncludePath[1]));
|
||||
assertEquals(2, actualLocalIncludePath.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Mac frameworks.
|
||||
*/
|
||||
public void testFramework() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
IFolder frameworkFolder = ResourceHelper.createFolder(project, "Fmwk");
|
||||
CIncludePathEntry frameworkPathEntry = new CIncludePathEntry(frameworkFolder, ICSettingEntry.FRAMEWORKS_MAC);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(frameworkPathEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test that the scannerInfoProvider gets the entries
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
// include paths
|
||||
assertEquals(frameworkFolder.getLocation().append("/__framework__.framework/Headers/__header__"),
|
||||
new Path(actualIncludePaths[0]));
|
||||
assertEquals(frameworkFolder.getLocation().append("/__framework__.framework/PrivateHeaders/__header__"),
|
||||
new Path(actualIncludePaths[1]));
|
||||
assertEquals(2, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test duplicate entries.
|
||||
*/
|
||||
public void testDuplicate() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
IFolder incFolder = ResourceHelper.createFolder(project, "include");
|
||||
CIncludePathEntry includePathEntry = new CIncludePathEntry(incFolder, 0);
|
||||
CIncludePathEntry includeLocalPathEntry = new CIncludePathEntry(incFolder, ICSettingEntry.LOCAL); // #include "..."
|
||||
CIncludePathEntry includePathEntry2 = new CIncludePathEntry(incFolder, 0);
|
||||
CIncludePathEntry includeLocalPathEntry2 = new CIncludePathEntry(incFolder, ICSettingEntry.LOCAL); // #include "..."
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(includePathEntry);
|
||||
entries.add(includeLocalPathEntry);
|
||||
entries.add(includePathEntry2);
|
||||
entries.add(includeLocalPathEntry2);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test that the scannerInfoProvider gets the entries
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
String[] actualLocalIncludePath = info.getLocalIncludePath();
|
||||
// include paths
|
||||
assertEquals(incFolder.getLocation(), new Path(actualIncludePaths[0]));
|
||||
assertEquals(1, actualIncludePaths.length);
|
||||
// local include files
|
||||
assertEquals(incFolder.getLocation(), new Path(actualLocalIncludePath[0]));
|
||||
assertEquals(1, actualLocalIncludePath.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test include path managed by eclipse as a workspace path.
|
||||
*/
|
||||
public void testWorkspacePath() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// create sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
// eclipse-managed folder in workspace
|
||||
IFolder incWorkspace_1 = ResourceHelper.createFolder(project, "include_1");
|
||||
IPath incWorkspaceLocation_1 = incWorkspace_1.getLocation();
|
||||
IFolder incWorkspace_2 = ResourceHelper.createFolder(project, "include_2");
|
||||
IPath incWorkspacePath_2 = incWorkspace_2.getFullPath();
|
||||
IPath incWorkspaceLocation_2 = incWorkspace_2.getLocation();
|
||||
IFolder incWorkspace_3 = ResourceHelper.createFolder(project, "include_3");
|
||||
// "relative" should make no difference for VALUE_WORKSPACE_PATH
|
||||
IPath incWorkspaceRelativePath_3 = incWorkspace_3.getFullPath().makeRelative();
|
||||
IPath incWorkspaceLocation_3 = incWorkspace_3.getLocation();
|
||||
// folder defined by absolute path on the filesystem
|
||||
IPath incFilesystem = ResourceHelper.createWorkspaceFolder("includeFilesystem");
|
||||
|
||||
// contribute the entries
|
||||
CIncludePathEntry incWorkspaceEntry_1 = new CIncludePathEntry(incWorkspace_1, 0);
|
||||
CIncludePathEntry incWorkspaceEntry_2 = new CIncludePathEntry(incWorkspacePath_2, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
|
||||
CIncludePathEntry incWorkspaceEntry_3 = new CIncludePathEntry(incWorkspaceRelativePath_3, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
|
||||
CIncludePathEntry incFilesystemEntry = new CIncludePathEntry(incFilesystem, 0);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(incWorkspaceEntry_1);
|
||||
entries.add(incWorkspaceEntry_2);
|
||||
entries.add(incWorkspaceEntry_3);
|
||||
entries.add(incFilesystemEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
|
||||
assertEquals(incWorkspaceLocation_1, new Path(actualIncludePaths[0]));
|
||||
assertEquals(incWorkspaceLocation_2, new Path(actualIncludePaths[1]));
|
||||
assertEquals(incWorkspaceLocation_3, new Path(actualIncludePaths[2]));
|
||||
assertEquals(incFilesystem, new Path(actualIncludePaths[3]));
|
||||
assertEquals(4, actualIncludePaths.length);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that device letter is prepended on filesystems that support that.
|
||||
*/
|
||||
public void testFilesystemPathNoDriveLetter() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
// change drive on build working directory
|
||||
String buildCwdDevice = project.getLocation().getDevice();
|
||||
|
||||
// // Test manually with a device which is different from project location device (path should exist)
|
||||
// IPath buildCWD = new Path("D:/build/path");
|
||||
// String buildCwdDevice = buildCWD.getDevice();
|
||||
|
||||
// get project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// create sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
// no-drive-letter folder defined by absolute path on the filesystem
|
||||
IPath incFilesystem = ResourceHelper.createWorkspaceFolder("includeFilesystem").setDevice(null);
|
||||
CIncludePathEntry incFilesystemEntry = new CIncludePathEntry(incFilesystem, 0);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(incFilesystemEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
|
||||
IPath expectedInclude = incFilesystem.setDevice(buildCwdDevice);
|
||||
assertEquals(expectedInclude, new Path(actualIncludePaths[0]));
|
||||
assertEquals(1, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test relative paths.
|
||||
*/
|
||||
public void testRelativePath() throws Exception {
|
||||
// create a project
|
||||
String prjName = getName();
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(prjName);
|
||||
String relativePath = "include";
|
||||
IFolder buildFolder = ResourceHelper.createFolder(project, "buildDir");
|
||||
IFolder relativeFolder = ResourceHelper.createFolder(project, "buildDir/"+relativePath);
|
||||
IFolder relativeFolderProjName = ResourceHelper.createFolder(project, "buildDir/"+prjName);
|
||||
String markedResolved = "-MarkedResolved";
|
||||
IFolder relativeFolderProjNameResolved = ResourceHelper.createFolder(project, "buildDir/" + prjName+markedResolved);
|
||||
IPath buildCWD=buildFolder.getLocation();
|
||||
setBuilderCWD(project, buildCWD);
|
||||
|
||||
// get project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// create sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
CIncludePathEntry incRelativeEntry = new CIncludePathEntry(new Path(relativePath), 0);
|
||||
CIncludePathEntry incProjNameEntry = new CIncludePathEntry(new Path("${ProjName}"), 0);
|
||||
CIncludePathEntry incProjNameMarkedResolvedEntry = new CIncludePathEntry(new Path("${ProjName}"+markedResolved), ICSettingEntry.RESOLVED);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(incRelativeEntry);
|
||||
entries.add(incProjNameEntry);
|
||||
entries.add(incProjNameMarkedResolvedEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
|
||||
// pair of entries, one from build dir another relative path
|
||||
assertEquals(relativeFolder.getLocation(), new Path(actualIncludePaths[0]));
|
||||
assertEquals(new Path(relativePath), new Path(actualIncludePaths[1]));
|
||||
|
||||
// pair of entries, one resolved from build dir another expanded relative path
|
||||
assertEquals(relativeFolderProjName.getLocation(), new Path(actualIncludePaths[2]));
|
||||
assertEquals(new Path(prjName), new Path(actualIncludePaths[3]));
|
||||
|
||||
// if marked RESOLVED only that path stays
|
||||
assertEquals(new Path("${ProjName}"+markedResolved), new Path(actualIncludePaths[4]));
|
||||
|
||||
assertEquals(5, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test relative paths - some combinations of dot paths.
|
||||
*/
|
||||
public void testRelativePathWithDots() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
// set build CWD
|
||||
IFolder buildFolder = ResourceHelper.createFolder(project, "buildDir");
|
||||
IPath buildCWD=buildFolder.getLocation();
|
||||
setBuilderCWD(project, buildCWD);
|
||||
|
||||
// define a few variations of paths
|
||||
String relativePath_dot = ".";
|
||||
String relativePath_dot_slash = "./";
|
||||
String relativePath_dot_slash_path = "./include";
|
||||
IFolder relativeFolder_dot_slash_path = ResourceHelper.createFolder(project, "buildDir/include");
|
||||
String relativePath_dotdot = "..";
|
||||
String relativePath_dotdot_slash = "../";
|
||||
String relativePath_dotdot_slash_path = "../include";
|
||||
IFolder relativeFolder_dotdot_slash_path = ResourceHelper.createFolder(project, "include");
|
||||
String locationPath_dotdot_path = buildCWD.toString()+"/../include2";
|
||||
IFolder incFolder_dotdot_slash_path = ResourceHelper.createFolder(project, "include2"); // "/ProjPath/buildDir/../include2"
|
||||
|
||||
// get project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// create sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
CIncludePathEntry incRelativeEntry_dot = new CIncludePathEntry(new Path(relativePath_dot), 0);
|
||||
CIncludePathEntry incRelativeEntry_dot_slash_path = new CIncludePathEntry(new Path(relativePath_dot_slash_path), 0);
|
||||
CIncludePathEntry incRelativeEntry_dotdot = new CIncludePathEntry(new Path(relativePath_dotdot), 0);
|
||||
CIncludePathEntry incRelativeEntry_dotdot_slash_path = new CIncludePathEntry(new Path(relativePath_dotdot_slash_path), 0);
|
||||
CIncludePathEntry incEntry_dotdot_path = new CIncludePathEntry(locationPath_dotdot_path, 0);
|
||||
// use LOCAL flag not to clash with plain dot entries
|
||||
CIncludePathEntry incRelativeEntry_dotdot_slash = new CIncludePathEntry(new Path(relativePath_dotdot_slash), ICSettingEntry.LOCAL);
|
||||
CIncludePathEntry incRelativeEntry_dot_slash = new CIncludePathEntry(new Path(relativePath_dot_slash), ICSettingEntry.LOCAL);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(incRelativeEntry_dot);
|
||||
entries.add(incRelativeEntry_dot_slash);
|
||||
entries.add(incRelativeEntry_dot_slash_path);
|
||||
entries.add(incRelativeEntry_dotdot);
|
||||
entries.add(incRelativeEntry_dotdot_slash);
|
||||
entries.add(incRelativeEntry_dotdot_slash_path);
|
||||
entries.add(incEntry_dotdot_path);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
String[] actualLocalIncludePaths = info.getLocalIncludePath();
|
||||
|
||||
IPath expectedLocation_dot = buildFolder.getLocation();
|
||||
IPath expectedLocation_dot_slash = buildFolder.getLocation();
|
||||
IPath expectedLocation_dot_slash_path = relativeFolder_dot_slash_path.getLocation();
|
||||
IPath expectedLocation_dotdot = project.getLocation();
|
||||
IPath expectedLocation_dotdot_slash = project.getLocation();
|
||||
IPath expectedLocation_dotdot_slash_path = relativeFolder_dotdot_slash_path.getLocation();
|
||||
|
||||
assertEquals(expectedLocation_dot, new Path(actualIncludePaths[0]));
|
||||
assertEquals(".", actualIncludePaths[1]);
|
||||
assertEquals(expectedLocation_dot_slash_path, new Path(actualIncludePaths[2]));
|
||||
assertEquals(new Path(relativePath_dot_slash_path), new Path(actualIncludePaths[3]));
|
||||
|
||||
assertEquals(expectedLocation_dotdot, new Path(actualIncludePaths[4]));
|
||||
assertEquals("..", actualIncludePaths[5]);
|
||||
assertEquals(expectedLocation_dotdot_slash_path, new Path(actualIncludePaths[6]));
|
||||
assertEquals(new Path(relativePath_dotdot_slash_path), new Path(actualIncludePaths[7]));
|
||||
assertTrue(actualIncludePaths[7].startsWith(".."));
|
||||
assertEquals(new Path(locationPath_dotdot_path), new Path(actualIncludePaths[8]));
|
||||
assertTrue(actualIncludePaths[8].contains(".."));
|
||||
assertEquals(9, actualIncludePaths.length);
|
||||
|
||||
assertEquals(expectedLocation_dot_slash, new Path(actualLocalIncludePaths[0]));
|
||||
assertEquals(new Path(relativePath_dot_slash), new Path(actualLocalIncludePaths[1]));
|
||||
assertTrue(actualLocalIncludePaths[1].startsWith("."));
|
||||
assertEquals(expectedLocation_dotdot_slash, new Path(actualLocalIncludePaths[2]));
|
||||
assertEquals(new Path(relativePath_dotdot_slash), new Path(actualLocalIncludePaths[3]));
|
||||
assertTrue(actualLocalIncludePaths[3].startsWith(".."));
|
||||
assertEquals(4, actualLocalIncludePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if build/environment variables are expanded
|
||||
*/
|
||||
public void testEnvironmentVars() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||
String envPathStr = "${ProjDirPath}/Folder";
|
||||
|
||||
// get project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// create sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
CIncludePathEntry incRelativeEntry = new CIncludePathEntry(envPathStr, 0);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(incRelativeEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
|
||||
IPath expectedLocation = folder.getLocation();
|
||||
assertEquals(expectedLocation, new Path(actualIncludePaths[0]));
|
||||
assertEquals(1, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test from parent folder's entries.
|
||||
*/
|
||||
public void testParentFolder() throws Exception {
|
||||
class MockProviderForResource extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider {
|
||||
private IResource rc;
|
||||
private final List<ICLanguageSettingEntry> entries;
|
||||
|
||||
public MockProviderForResource(IResource rc, List<ICLanguageSettingEntry> entries) {
|
||||
this.rc = rc;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (this.rc.equals(rc))
|
||||
return entries;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// sample file
|
||||
IFolder parentFolder = ResourceHelper.createFolder(project, "ParentFolder");
|
||||
IFile file = ResourceHelper.createFile(project, "ParentFolder/file.c");
|
||||
|
||||
// contribute the entries
|
||||
IFolder incFolder = ResourceHelper.createFolder(project, "include");
|
||||
CIncludePathEntry includePathEntry = new CIncludePathEntry(incFolder, 0);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(includePathEntry);
|
||||
|
||||
// add provider for parent folder
|
||||
ILanguageSettingsProvider provider = new MockProviderForResource(parentFolder, entries);
|
||||
assertNull(provider.getSettingEntries(cfgDescription, file, null));
|
||||
assertEquals(includePathEntry, provider.getSettingEntries(cfgDescription, parentFolder, null).get(0));
|
||||
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test that the scannerInfoProvider gets the entries for
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
// include paths
|
||||
assertEquals(incFolder.getLocation(), new Path(actualIncludePaths[0]));
|
||||
assertEquals(1, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resolved paths.
|
||||
*/
|
||||
public void testResolvedPath() throws Exception {
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||
String envPathStr = "${ProjDirPath}/Folder";
|
||||
|
||||
// get project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// create sample file
|
||||
IFile file = ResourceHelper.createFile(project, "file.c");
|
||||
|
||||
// contribute the entries
|
||||
CIncludePathEntry incRelativeEntry = new CIncludePathEntry(envPathStr, ICSettingEntry.RESOLVED);
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(incRelativeEntry);
|
||||
|
||||
// add provider to the configuration
|
||||
ILanguageSettingsProvider provider = new MockProvider(PROVIDER_ID, PROVIDER_NAME, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(file);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
|
||||
// test that RESOLVED entries are not modified
|
||||
IPath expectedLocation = new Path(envPathStr);
|
||||
assertEquals(expectedLocation, new Path(actualIncludePaths[0]));
|
||||
assertEquals(1, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
private List<String> getLanguages(IFolder folder, ICConfigurationDescription cfgDescription) {
|
||||
// Get first 2 languages
|
||||
IPath rcPath = folder.getProjectRelativePath();
|
||||
ICFolderDescription rcDes = (ICFolderDescription) cfgDescription.getResourceDescription(rcPath, false);
|
||||
ICLanguageSetting[] langSettings = rcDes.getLanguageSettings();
|
||||
assertNotNull(langSettings);
|
||||
|
||||
List<String> languageIds = new ArrayList<String>();
|
||||
for (ICLanguageSetting ls : langSettings) {
|
||||
String langId = ls.getLanguageId();
|
||||
if (langId!=null && !languageIds.contains(langId)) {
|
||||
languageIds.add(langId);
|
||||
}
|
||||
}
|
||||
return languageIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test composition of 2 languages.
|
||||
*/
|
||||
public void testResourceLanguages() throws Exception {
|
||||
class MockProviderLang extends LanguageSettingsBaseProvider implements ILanguageSettingsProvider {
|
||||
private final String langId;
|
||||
private final List<ICLanguageSettingEntry> entries;
|
||||
|
||||
public MockProviderLang(String id, String name, String langId, List<ICLanguageSettingEntry> entries) {
|
||||
super(id, name);
|
||||
this.langId = langId;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (langId==null || langId.equals(languageId))
|
||||
return entries;
|
||||
return new ArrayList<ICLanguageSettingEntry>();
|
||||
}
|
||||
}
|
||||
|
||||
// create a project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
|
||||
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||
|
||||
IFolder incFolderA = ResourceHelper.createFolder(project, "includeA");
|
||||
IFolder incFolderB = ResourceHelper.createFolder(project, "includeB");
|
||||
IFolder incFolderC = ResourceHelper.createFolder(project, "includeC");
|
||||
|
||||
// get project/configuration descriptions
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
assertNotNull(prjDescription);
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
// find 2 languages applicable to the folder
|
||||
List<String> languageIds = getLanguages(folder, cfgDescription);
|
||||
assertTrue(languageIds.size() >= 2);
|
||||
String langId1 = languageIds.get(0);
|
||||
String langId2 = languageIds.get(1);
|
||||
|
||||
// define overlapping entries
|
||||
CIncludePathEntry incEntryA = new CIncludePathEntry(incFolderA, 0);
|
||||
CIncludePathEntry incEntryB = new CIncludePathEntry(incFolderB, 0);
|
||||
CIncludePathEntry incEntryC = new CIncludePathEntry(incFolderC, 0);
|
||||
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries1.add(incEntryA);
|
||||
entries1.add(incEntryB);
|
||||
List<ICLanguageSettingEntry> entries2 = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries2.add(incEntryC);
|
||||
entries2.add(incEntryB);
|
||||
|
||||
// add providers to the configuration
|
||||
ILanguageSettingsProvider provider1 = new MockProviderLang(PROVIDER_ID, PROVIDER_NAME, langId1, entries1);
|
||||
ILanguageSettingsProvider provider2 = new MockProviderLang(PROVIDER_ID_2, PROVIDER_NAME, langId2, entries2);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider1);
|
||||
providers.add(provider2);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// test the entries received from the scannerInfoProvider
|
||||
LanguageSettingsScannerInfoProvider scannerInfoProvider = new LanguageSettingsScannerInfoProvider();
|
||||
ExtendedScannerInfo info = scannerInfoProvider.getScannerInformation(folder);
|
||||
String[] actualIncludePaths = info.getIncludePaths();
|
||||
|
||||
// Test that the result is the union of entries
|
||||
assertEquals(incFolderA.getLocation(), new Path(actualIncludePaths[0]));
|
||||
assertEquals(incFolderB.getLocation(), new Path(actualIncludePaths[1]));
|
||||
assertEquals(incFolderC.getLocation(), new Path(actualIncludePaths[2]));
|
||||
assertEquals(3, actualIncludePaths.length);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,19 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider;
|
||||
|
||||
|
||||
public class MockLanguageSettingsBaseProvider extends LanguageSettingsBaseProvider {
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
|
||||
|
||||
public class MockLanguageSettingsEditableProvider extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider {
|
||||
public MockLanguageSettingsEditableProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MockLanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException {
|
||||
return (MockLanguageSettingsEditableProvider) super.cloneShallow();
|
||||
}
|
||||
|
||||
public MockLanguageSettingsEditableProvider clone() throws CloneNotSupportedException {
|
||||
return (MockLanguageSettingsEditableProvider) super.clone();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
public class MockLanguageSettingsProvider extends AbstractExecutableExtensionBase
|
||||
implements ILanguageSettingsProvider {
|
||||
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||
|
||||
|
||||
public class MockLanguageSettingsSerializableProvider extends LanguageSettingsSerializable {
|
||||
public MockLanguageSettingsSerializableProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MockLanguageSettingsSerializableProvider(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.core.model.tests;
|
|||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.AllLanguageSettingsProvidersTests;
|
||||
import org.eclipse.cdt.core.settings.model.AllCProjectDescriptionTests;
|
||||
import org.eclipse.cdt.core.settings.model.PathSettingsContainerTests;
|
||||
|
||||
|
@ -60,6 +61,8 @@ public class AllCoreTests {
|
|||
suite.addTest(AsmModelBuilderTest.suite());
|
||||
suite.addTest(CModelBuilderBugsTest.suite());
|
||||
suite.addTest(Bug311189.suite());
|
||||
|
||||
suite.addTest(AllLanguageSettingsProvidersTests.suite());
|
||||
return suite;
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.cdt.core.index.IIndex;
|
|||
import org.eclipse.cdt.core.index.provider.IIndexProvider;
|
||||
import org.eclipse.cdt.core.internal.index.provider.test.DummyProviderTraces;
|
||||
import org.eclipse.cdt.core.internal.index.provider.test.Providers;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -704,6 +705,12 @@ class MockConfig implements ICConfigurationDescription {
|
|||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly, boolean keepModify) {}
|
||||
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {}
|
||||
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -159,6 +159,13 @@
|
|||
</run>
|
||||
</filesystem>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.EFSExtensionProvider">
|
||||
<EFSExtensionProvider
|
||||
class="org.eclipse.cdt.core.internal.tests.filesystem.ram.MemoryEFSExtensionProvider"
|
||||
scheme="mem">
|
||||
</EFSExtensionProvider>
|
||||
</extension>
|
||||
<extension
|
||||
id="RegexErrorParserId"
|
||||
name="Test Plugin RegexErrorParser"
|
||||
|
@ -183,6 +190,156 @@
|
|||
scheme="EFSExtensionProviderTestsScheme">
|
||||
</EFSExtensionProvider>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<!-- uncomment to test message about missing class in the log
|
||||
<provider
|
||||
class="org.eclipse.cdt.core.language.settings.providers.MissingClass"
|
||||
id="org.eclipse.cdt.core.tests.missing.language.settings.provider"
|
||||
name="Test Plugin Missing Language Settings Provider">
|
||||
</provider>
|
||||
-->
|
||||
<provider
|
||||
id="org.eclipse.cdt.core.tests.language.settings.base.provider"
|
||||
name="Test Plugin Language Settings Base Provider"
|
||||
parameter="custom parameter">
|
||||
<language-scope
|
||||
id="org.eclipse.cdt.core.tests.language.id">
|
||||
</language-scope>
|
||||
<entry
|
||||
kind="includePath"
|
||||
name="/usr/include/">
|
||||
<flag
|
||||
value="BUILTIN">
|
||||
</flag>
|
||||
<flag
|
||||
value="LOCAL">
|
||||
</flag>
|
||||
<flag
|
||||
value="VALUE_WORKSPACE_PATH">
|
||||
</flag>
|
||||
<flag
|
||||
value="RESOLVED">
|
||||
</flag>
|
||||
<flag
|
||||
value="UNDEFINED">
|
||||
</flag>
|
||||
</entry>
|
||||
<entry
|
||||
kind="macro"
|
||||
name="TEST_DEFINE"
|
||||
value="100">
|
||||
</entry>
|
||||
<entry
|
||||
kind="includeFile"
|
||||
name="/include/file.inc">
|
||||
</entry>
|
||||
<entry
|
||||
kind="libraryPath"
|
||||
name="/usr/lib/">
|
||||
</entry>
|
||||
<entry
|
||||
kind="libraryFile"
|
||||
name="libdomain.a">
|
||||
</entry>
|
||||
<entry
|
||||
kind="macroFile"
|
||||
name="/macro/file.mac">
|
||||
</entry>
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.core.language.settings.providers.MockLanguageSettingsProvider"
|
||||
id="org.eclipse.cdt.core.tests.custom.language.settings.provider"
|
||||
name="Test Plugin Language Settings Provider">
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.core.language.settings.providers.MockLanguageSettingsSerializableProvider"
|
||||
id="org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider"
|
||||
name="Test Plugin Serializable Language Settings Provider">
|
||||
<entry
|
||||
kind="macro"
|
||||
name="MACRO"
|
||||
value="value">
|
||||
</entry>
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.core.language.settings.providers.MockLanguageSettingsEditableProvider"
|
||||
id="org.eclipse.cdt.core.tests.custom.editable.language.settings.provider"
|
||||
name="Test Plugin Editable Language Settings Provider">
|
||||
<entry
|
||||
kind="macro"
|
||||
name="MACRO"
|
||||
value="value">
|
||||
</entry>
|
||||
</provider>
|
||||
<provider
|
||||
class="org.eclipse.cdt.core.language.settings.providers.MockLanguageSettingsBaseProvider"
|
||||
id="org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"
|
||||
name="Test Plugin Base Provider Subclass"
|
||||
parameter="custom parameter subclass">
|
||||
<entry
|
||||
kind="includePath"
|
||||
name="/usr/include/">
|
||||
<flag
|
||||
value="BUILTIN">
|
||||
</flag>
|
||||
</entry>
|
||||
</provider>
|
||||
<provider
|
||||
id="org.eclipse.cdt.core.tests.language.settings"
|
||||
name="Test Plugin Setting Entries UI Tester">
|
||||
<language-scope
|
||||
id="org.eclipse.cdt.core.gcc">
|
||||
</language-scope>
|
||||
<entry
|
||||
kind="includePath"
|
||||
name="/test/include/path">
|
||||
</entry>
|
||||
<entry
|
||||
kind="includePath"
|
||||
name="/test/workspace/include/path">
|
||||
<flag
|
||||
value="VALUE_WORKSPACE_PATH">
|
||||
</flag>
|
||||
</entry>
|
||||
<entry
|
||||
kind="includePath"
|
||||
name="/test/builtin/include/path">
|
||||
<flag
|
||||
value="BUILTIN">
|
||||
</flag>
|
||||
</entry>
|
||||
<entry
|
||||
kind="macro"
|
||||
name="MACRO"
|
||||
value="macro">
|
||||
</entry>
|
||||
<entry
|
||||
kind="macro"
|
||||
name="BUILTIN_MACRO"
|
||||
value="builtin-macro">
|
||||
<flag
|
||||
value="BUILTIN">
|
||||
</flag>
|
||||
</entry>
|
||||
<entry
|
||||
kind="includeFile"
|
||||
name="/test/includes/file">
|
||||
</entry>
|
||||
<entry
|
||||
kind="libraryPath"
|
||||
name="/test/library/path">
|
||||
</entry>
|
||||
<entry
|
||||
kind="libraryFile"
|
||||
name="/test/library/file">
|
||||
</entry>
|
||||
<entry
|
||||
kind="macroFile"
|
||||
name="/test/macro/file">
|
||||
</entry>
|
||||
</provider>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.RefreshExclusionFactory">
|
||||
<exclusionFactory
|
||||
|
|
|
@ -0,0 +1,416 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.testplugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.CConfigurationStatus;
|
||||
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingObject;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting;
|
||||
import org.eclipse.cdt.core.settings.model.WriteAccessException;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
|
||||
public class CModelMock {
|
||||
|
||||
/**
|
||||
* Dummy implementation of ICProjectDescription for testing.
|
||||
* Feel free to override the methods you are interested to mock.
|
||||
*
|
||||
*/
|
||||
public static class DummyCProjectDescription implements ICProjectDescription {
|
||||
|
||||
public ICSettingObject[] getChildSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfiguration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICSettingContainer getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICStorageElement getStorage(String id, boolean create)
|
||||
throws CoreException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeStorage(String id) throws CoreException {
|
||||
}
|
||||
|
||||
public ICStorageElement importStorage(String id, ICStorageElement el)
|
||||
throws UnsupportedOperationException, CoreException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly, boolean keepModify) {
|
||||
}
|
||||
|
||||
public int getConfigurationRelations() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setConfigurationRelations(int status) {
|
||||
}
|
||||
|
||||
public void useDefaultConfigurationRelations() {
|
||||
}
|
||||
|
||||
public boolean isDefaultConfigurationRelations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription[] getConfigurations() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getActiveConfiguration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setActiveConfiguration(ICConfigurationDescription cfg)
|
||||
throws WriteAccessException {
|
||||
}
|
||||
|
||||
public ICConfigurationDescription createConfiguration(String id,
|
||||
String name, ICConfigurationDescription base)
|
||||
throws CoreException, WriteAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription createConfiguration(
|
||||
String buildSystemId, CConfigurationData data)
|
||||
throws CoreException, WriteAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfigurationByName(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfigurationById(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeConfiguration(String name)
|
||||
throws WriteAccessException {
|
||||
}
|
||||
|
||||
public void removeConfiguration(ICConfigurationDescription cfg)
|
||||
throws WriteAccessException {
|
||||
}
|
||||
|
||||
public IProject getProject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getSessionProperty(QualifiedName name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSessionProperty(QualifiedName name, Object value) {
|
||||
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getDefaultSettingConfiguration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDefaultSettingConfiguration(
|
||||
ICConfigurationDescription cfg) {
|
||||
}
|
||||
|
||||
public boolean isCdtProjectCreating() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setCdtProjectCreated() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy implementation of ICConfigurationDescription for testing.
|
||||
* Feel free to override the methods you are interested to mock.
|
||||
*
|
||||
*/
|
||||
public static class DummyCConfigurationDescription implements ICConfigurationDescription {
|
||||
private String id;
|
||||
|
||||
public DummyCConfigurationDescription(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ICSettingObject[] getChildSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfiguration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICSettingContainer getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICStorageElement getStorage(String id, boolean create)
|
||||
throws CoreException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeStorage(String id) throws CoreException {
|
||||
}
|
||||
|
||||
public ICStorageElement importStorage(String id, ICStorageElement el)
|
||||
throws UnsupportedOperationException, CoreException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly, boolean keepModify) {
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDescription(String des) throws WriteAccessException {
|
||||
}
|
||||
|
||||
public ICProjectDescription getProjectDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICFolderDescription getRootFolderDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICFolderDescription[] getFolderDescriptions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICFileDescription[] getFileDescriptions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICResourceDescription[] getResourceDescriptions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICResourceDescription getResourceDescription(IPath path,
|
||||
boolean exactPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeResourceDescription(ICResourceDescription des)
|
||||
throws CoreException, WriteAccessException {
|
||||
}
|
||||
|
||||
public ICFileDescription createFileDescription(IPath path,
|
||||
ICResourceDescription base) throws CoreException,
|
||||
WriteAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICFolderDescription createFolderDescription(IPath path,
|
||||
ICFolderDescription base) throws CoreException,
|
||||
WriteAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getBuildSystemId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CConfigurationData getConfigurationData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setActive() throws WriteAccessException {
|
||||
}
|
||||
|
||||
public void setConfigurationData(String buildSystemId, CConfigurationData data) throws WriteAccessException {
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICTargetPlatformSetting getTargetPlatformSetting() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICSourceEntry[] getSourceEntries() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICSourceEntry[] getResolvedSourceEntries() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSourceEntries(ICSourceEntry[] entries) throws CoreException, WriteAccessException {
|
||||
}
|
||||
|
||||
public Map<String, String> getReferenceInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setReferenceInfo(Map<String, String> refs) throws WriteAccessException {
|
||||
}
|
||||
|
||||
public ICExternalSetting[] getExternalSettings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICExternalSetting createExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIds, String[] extensions,
|
||||
ICSettingEntry[] entries) throws WriteAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeExternalSetting(ICExternalSetting setting) throws WriteAccessException {
|
||||
}
|
||||
|
||||
public void removeExternalSettings() throws WriteAccessException {
|
||||
}
|
||||
|
||||
public ICBuildSetting getBuildSetting() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICdtVariablesContributor getBuildVariablesContributor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getSessionProperty(QualifiedName name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSessionProperty(QualifiedName name, Object value) {
|
||||
}
|
||||
|
||||
public void setName(String name) throws WriteAccessException {
|
||||
}
|
||||
|
||||
public ICConfigExtensionReference[] get(String extensionPointID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void remove(ICConfigExtensionReference ext) throws CoreException {
|
||||
}
|
||||
|
||||
public void remove(String extensionPoint) throws CoreException {
|
||||
}
|
||||
|
||||
public boolean isPreferenceConfiguration() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setExternalSettingsProviderIds(String[] ids) {
|
||||
}
|
||||
|
||||
public String[] getExternalSettingsProviderIds() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateExternalSettingsProviders(String[] ids) throws WriteAccessException {
|
||||
}
|
||||
|
||||
public CConfigurationStatus getConfigurationStatus() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
}
|
||||
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.core.index.export,
|
||||
org.eclipse.cdt.core.index.provider,
|
||||
org.eclipse.cdt.core.language,
|
||||
org.eclipse.cdt.core.language.settings.providers,
|
||||
org.eclipse.cdt.core.model,
|
||||
org.eclipse.cdt.core.model.util,
|
||||
org.eclipse.cdt.core.parser,
|
||||
|
@ -66,6 +67,7 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.internal.core.index.provider;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.indexer;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.language.settings.providers;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.debug.core,org.eclipse.cdt.debug.ui",
|
||||
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.parser;x-internal:=true,
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* Base interface to provide list of {@link ICLanguageSettingEntry}.
|
||||
* This interface is used to deliver additions to compiler options such as
|
||||
* include paths (-I) or preprocessor defines (-D) and others (see
|
||||
* {@link ICSettingEntry#INCLUDE_PATH} and other kinds).
|
||||
*
|
||||
* To define a provider like that use extension point
|
||||
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this
|
||||
* interface. CDT provides a few general use implementations such as
|
||||
* {@link LanguageSettingsBaseProvider} which could be used out of the box or
|
||||
* extended. See extension point schema description LanguageSettingsProvider.exsd
|
||||
* for more details.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
public interface ILanguageSettingsProvider {
|
||||
/**
|
||||
* Id is used to keep track of the providers internally. Use unique id
|
||||
* to represent the provider.
|
||||
*
|
||||
* @return Id of the provider.
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* Name is used to present the provider to the end user in UI.
|
||||
*
|
||||
* @return name of the provider.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Returns the list of setting entries for the given configuration description,
|
||||
* resource and language.
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id
|
||||
* (see {@link LanguageManager#getLanguageForFile(org.eclipse.core.resources.IFile, ICConfigurationDescription)}).
|
||||
*
|
||||
* @return the list of setting entries or {@code null} if no settings defined.
|
||||
*/
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId);
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* {@code LanguageSettingsBaseProvider} is a basic implementation of {@link ILanguageSettingsProvider}
|
||||
* defined in {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
|
||||
*
|
||||
* This implementation supports "static" list of entries for languages specified in
|
||||
* the extension point.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider {
|
||||
/** Language scope, i.e. list of languages the entries will be provided for. */
|
||||
protected List<String> languageScope = null;
|
||||
|
||||
/** Custom parameter. Intended for providers extending this class. */
|
||||
protected String customParameter = null;
|
||||
|
||||
/** List of entries defined by this provider. */
|
||||
private List<ICLanguageSettingEntry> entries = null;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public LanguageSettingsBaseProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Creates an "empty" provider.
|
||||
*
|
||||
* @param id - id of the provider.
|
||||
* @param name - name of the provider to be presented to a user.
|
||||
*/
|
||||
public LanguageSettingsBaseProvider(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id - id of the provider.
|
||||
* @param name - name of the provider to be presented to a user.
|
||||
* @param languages - list of languages the {@code entries} provided for.
|
||||
* {@code languages} can be {@code null}, in this case the {@code entries}
|
||||
* are provided for any language.
|
||||
* @param entries - the list of language settings entries this provider provides.
|
||||
* If {@code null} is passed, the provider creates an empty list.
|
||||
*/
|
||||
public LanguageSettingsBaseProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries) {
|
||||
super(id, name);
|
||||
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
|
||||
this.entries = cloneList(entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id - id of the provider.
|
||||
* @param name - name of the provider to be presented to a user.
|
||||
* @param languages - list of languages the {@code entries} provided for.
|
||||
* {@code languages} can be {@code null}, in this case the {@code entries}
|
||||
* are provided for any language.
|
||||
* @param entries - the list of language settings entries this provider provides.
|
||||
* If {@code null} is passed, the provider creates an empty list.
|
||||
* @param customParameter - a custom parameter as the means to customize
|
||||
* providers extending this class.
|
||||
*/
|
||||
public LanguageSettingsBaseProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) {
|
||||
super(id, name);
|
||||
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
|
||||
this.entries = cloneList(entries);
|
||||
this.customParameter = customParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to configure the provider. The initialization of provider from
|
||||
* the extension point is done in 2 steps. First, the class is created as
|
||||
* an executable extension using the default provider. Then this method is
|
||||
* used to configure the provider.
|
||||
*
|
||||
* FIXME It is not allowed to reconfigure the provider.
|
||||
*
|
||||
* @param id - id of the provider.
|
||||
* @param name - name of the provider to be presented to a user.
|
||||
* @param languages - list of languages the {@code entries} provided for.
|
||||
* {@code languages} can be {@code null}, in this case the {@code entries}
|
||||
* are provided for any language.
|
||||
* @param entries - the list of language settings entries this provider provides.
|
||||
* If {@code null} is passed, the provider creates an empty list.
|
||||
* @param customParameter - a custom parameter as the means to customize
|
||||
* providers extending this class from extension definition in {@code plugin.xml}.
|
||||
*
|
||||
* FIXME @throws UnsupportedOperationException if an attempt to reconfigure provider is made.
|
||||
*/
|
||||
public void configureProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) {
|
||||
// if (this.entries!=null)
|
||||
// throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$
|
||||
|
||||
setId(id);
|
||||
setName(name);
|
||||
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
|
||||
this.entries = cloneList(entries);
|
||||
this.customParameter = customParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id. If {@code null}, then entries defined for
|
||||
* the language scope are returned. See {@link #getLanguageScope()}
|
||||
*/
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
if (languageScope==null) {
|
||||
if (entries==null)
|
||||
return null;
|
||||
return Collections.unmodifiableList(entries);
|
||||
}
|
||||
for (String lang : languageScope) {
|
||||
if (lang.equals(languageId)) {
|
||||
if (entries==null)
|
||||
return null;
|
||||
return Collections.unmodifiableList(entries);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the list of languages this provider provides for.
|
||||
* If {@code null}, the provider provides for any language.
|
||||
*/
|
||||
public List<String> getLanguageScope() {
|
||||
if (languageScope==null)
|
||||
return null;
|
||||
return Collections.unmodifiableList(languageScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the custom parameter defined in the extension in {@code plugin.xml}.
|
||||
*/
|
||||
public String getCustomParameter() {
|
||||
return customParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entries
|
||||
* @return copy of the list of the entries.
|
||||
*/
|
||||
private List<ICLanguageSettingEntry> cloneList(List<ICLanguageSettingEntry> entries) {
|
||||
return entries!=null ? new ArrayList<ICLanguageSettingEntry>(entries) : null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.cdt.internal.core.LocalProjectScope;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* A collection of utility methods to manage language settings providers.
|
||||
* See {@link ILanguageSettingsProvider}.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
public class LanguageSettingsManager {
|
||||
/** @noreference This field is temporary and not intended to be referenced by clients. */
|
||||
public static String USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE = "enabled"; //$NON-NLS-1$
|
||||
public static boolean USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT = true;
|
||||
|
||||
private static final String PREFERENCES_QUALIFIER = CCorePlugin.PLUGIN_ID;
|
||||
private static final String LANGUAGE_SETTINGS_PROVIDERS_NODE = "languageSettingsProviders"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Returns the list of setting entries of the given provider
|
||||
* for the given configuration description, resource and language.
|
||||
* This method reaches to the parent folder of the resource recursively
|
||||
* in case the resource does not define the entries for the given provider.
|
||||
*
|
||||
* @param provider - language settings provider.
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
*
|
||||
* @return the list of setting entries. Never returns {@code null}
|
||||
* although individual providers return {@code null} if no settings defined.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
return LanguageSettingsExtensionManager.getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
||||
*
|
||||
* @param provider - language settings provider to build the tree for.
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param languageId - language ID.
|
||||
* @param project - the project which is considered the root of the resource tree.
|
||||
*/
|
||||
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IProject project) {
|
||||
LanguageSettingsExtensionManager.buildResourceTree(provider, cfgDescription, languageId, project);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of setting entries of a certain kind (such as include paths)
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
* @param kind - kind of language settings entries, such as
|
||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
// FIXME: get rid of callers PathEntryTranslator and DescriptionScannerInfoProvider
|
||||
public static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
return LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, languageId, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Language Settings Provider defined in the workspace. That includes user-defined
|
||||
* providers and after that providers defined as extensions via
|
||||
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
|
||||
* That returns actual object, any modifications will affect any configuration
|
||||
* referring to the provider.
|
||||
*
|
||||
* @param id - id of provider to find.
|
||||
* @return the provider or {@code null} if provider is not defined.
|
||||
*/
|
||||
public static ILanguageSettingsProvider getWorkspaceProvider(String id) {
|
||||
return LanguageSettingsProvidersSerializer.getWorkspaceProvider(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of language settings providers defined on workspace level.
|
||||
* That includes user-defined providers and after that providers defined as
|
||||
* extensions via {@code org.eclipse.cdt.core.LanguageSettingsProvider}
|
||||
* extension point.
|
||||
*/
|
||||
public static List<ILanguageSettingsProvider> getWorkspaceProviders() {
|
||||
return LanguageSettingsProvidersSerializer.getWorkspaceProviders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provider is defined on the workspace level.
|
||||
*
|
||||
* @param provider - provider to check.
|
||||
* @return {@code true} if the given provider is workspace provider, {@code false} otherwise.
|
||||
*/
|
||||
public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) {
|
||||
return LanguageSettingsProvidersSerializer.isWorkspaceProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO - helper method for often used chunk of code
|
||||
* @param provider
|
||||
* @return ILanguageSettingsProvider
|
||||
*/
|
||||
public static ILanguageSettingsProvider getRawProvider(ILanguageSettingsProvider provider) {
|
||||
if (LanguageSettingsManager.isWorkspaceProvider(provider)){
|
||||
provider = LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(provider.getId());
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set and store in workspace area user defined providers.
|
||||
*
|
||||
* @param providers - array of user defined workspace providers.
|
||||
* Note that those providers will shadow extension providers with the same ID.
|
||||
* All not shadowed extension providers will be added to the list to be present
|
||||
* as workspace providers. {@code null} is equivalent to passing an empty array
|
||||
* and so will reset workspace providers to match extension providers.
|
||||
* @throws CoreException in case of problems (such as problems with persistence).
|
||||
*/
|
||||
public static void setWorkspaceProviders(List<ILanguageSettingsProvider> providers) throws CoreException {
|
||||
LanguageSettingsProvidersSerializer.setWorkspaceProviders(providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Language Settings Provider defined via
|
||||
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
|
||||
*
|
||||
* @param id - ID of provider to find.
|
||||
* @return the copy of the provider if possible (i.e. for {@link ILanguageSettingsEditableProvider})
|
||||
* or workspace provider if provider is not copyable.
|
||||
*/
|
||||
public static ILanguageSettingsProvider getExtensionProviderCopy(String id) {
|
||||
ILanguageSettingsProvider provider = null;
|
||||
try {
|
||||
provider = LanguageSettingsExtensionManager.getExtensionProviderClone(id);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// from here falls to get workspace provider
|
||||
}
|
||||
if (provider==null)
|
||||
provider = LanguageSettingsManager.getWorkspaceProvider(id);
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
private static Preferences getPreferences(IProject project) {
|
||||
if (project == null)
|
||||
return InstanceScope.INSTANCE.getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE);
|
||||
else
|
||||
return new LocalProjectScope(project).getNode(PREFERENCES_QUALIFIER).node(LANGUAGE_SETTINGS_PROVIDERS_NODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Language Settings functionality is enabled for given project.
|
||||
*
|
||||
* @param project - project to check the preference
|
||||
* @return {@code true} if functionality is enabled
|
||||
*
|
||||
* @noreference This method is temporary and not intended to be referenced by clients.
|
||||
*/
|
||||
public static boolean isLanguageSettingsProvidersEnabled(IProject project) {
|
||||
Preferences pref = LanguageSettingsManager.getPreferences(project);
|
||||
return pref.getBoolean(LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable Language Settings functionality for the given project.
|
||||
*
|
||||
* @param project
|
||||
* @param value {@code true} to enable or {@code false} to disable the functionality.
|
||||
*
|
||||
* @noreference This method is temporary and not intended to be referenced by clients.
|
||||
*/
|
||||
public static void setLanguageSettingsProvidersEnabled(IProject project, boolean value) {
|
||||
Preferences pref = LanguageSettingsManager.getPreferences(project);
|
||||
pref.putBoolean(LanguageSettingsManager.USE_LANGUAGE_SETTINGS_PROVIDERS_PREFERENCE, value);
|
||||
try {
|
||||
pref.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsExtensionManager;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* This layer of language settings in TODO
|
||||
*
|
||||
* Duplicate entries are filtered where only first entry is preserved.
|
||||
*
|
||||
*/
|
||||
public class LanguageSettingsManager_TBD {
|
||||
public static final String PROVIDER_UNKNOWN = "org.eclipse.cdt.projectmodel.4.0.0";
|
||||
public static final String PROVIDER_UI_USER = "org.eclipse.cdt.ui.user.LanguageSettingsProvider";
|
||||
public static final char PROVIDER_DELIMITER = LanguageSettingsProvidersSerializer.PROVIDER_DELIMITER;
|
||||
|
||||
private static ICLanguageSetting[] getLanguageIds(ICResourceDescription rcDescription) {
|
||||
if (rcDescription instanceof ICFileDescription) {
|
||||
ICFileDescription fileDescription = (ICFileDescription)rcDescription;
|
||||
return new ICLanguageSetting[] {fileDescription.getLanguageSetting()};
|
||||
} else if (rcDescription instanceof ICFolderDescription) {
|
||||
ICFolderDescription folderDescription = (ICFolderDescription)rcDescription;
|
||||
return folderDescription.getLanguageSettings();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isCustomizedResource(ICConfigurationDescription cfgDescription, IResource rc) {
|
||||
if (rc instanceof IProject)
|
||||
return false;
|
||||
|
||||
for (ILanguageSettingsProvider provider: cfgDescription.getLanguageSettingProviders()) {
|
||||
// FIXME
|
||||
// if (!LanguageSettingsManager.isWorkspaceProvider(provider)) {
|
||||
if (provider instanceof ILanguageSettingsEditableProvider || provider instanceof LanguageSettingsSerializable) {
|
||||
ICResourceDescription rcDescription = cfgDescription.getResourceDescription(rc.getProjectRelativePath(), false);
|
||||
for (ICLanguageSetting languageSetting : getLanguageIds(rcDescription)) {
|
||||
String languageId = languageSetting.getLanguageId();
|
||||
if (languageId!=null) {
|
||||
List<ICLanguageSettingEntry> list = provider.getSettingEntries(cfgDescription, rc, languageId);
|
||||
if (list!=null) {
|
||||
List<ICLanguageSettingEntry> listDefault = provider.getSettingEntries(null, null, languageId);
|
||||
if (!list.equals(listDefault))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated // Shouldn't be API
|
||||
public static void serializeWorkspaceProviders() throws CoreException {
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace();
|
||||
}
|
||||
|
||||
public static boolean isReconfigured(ILanguageSettingsProvider provider) {
|
||||
if (provider instanceof ILanguageSettingsEditableProvider) {
|
||||
try {
|
||||
return ! LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) provider);
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Internal Error: cannot clone provider "+provider.getId(), e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEqualExtensionProvider(ILanguageSettingsProvider provider) {
|
||||
return LanguageSettingsExtensionManager.equalsExtensionProvider(provider);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,514 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.util.WeakHashSet;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
||||
public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
||||
private static final String ATTR_ID = "id"; //$NON-NLS-1$
|
||||
|
||||
private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$
|
||||
private static final String ELEM_LANGUAGE = "language"; //$NON-NLS-1$
|
||||
private static final String ELEM_RESOURCE = "resource"; //$NON-NLS-1$
|
||||
private static final String ATTR_PROJECT_PATH = "project-relative-path"; //$NON-NLS-1$
|
||||
|
||||
private static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$
|
||||
private static final String ATTR_KIND = "kind"; //$NON-NLS-1$
|
||||
private static final String ATTR_NAME = "name"; //$NON-NLS-1$
|
||||
private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
|
||||
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
|
||||
private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
|
||||
|
||||
private static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
|
||||
|
||||
private static WeakHashSet<List<ICLanguageSettingEntry>> lseListPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
||||
@Override
|
||||
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
|
||||
return super.add(list);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
private Map<String, // languageId
|
||||
Map<String, // resource project path
|
||||
List<ICLanguageSettingEntry>>> fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
|
||||
public LanguageSettingsSerializable() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LanguageSettingsSerializable(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public LanguageSettingsSerializable(Element elementProvider) {
|
||||
super();
|
||||
load(elementProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) {
|
||||
// do not pass entries to super, keep them in local storage
|
||||
super.configureProvider(id, name, languages, null, customParameter);
|
||||
|
||||
fStorage.clear();
|
||||
|
||||
if (entries!=null) {
|
||||
// note that these entries are intended to be retrieved by LanguageSettingsManager.getSettingEntriesUpResourceTree()
|
||||
// when the whole resource hierarchy has been traversed up
|
||||
setSettingEntries(null, null, null, entries);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the provider does not keep any settings yet or {@code false} if there are some.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return fStorage.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the language scope of the provider.
|
||||
*
|
||||
* @param languages - the list of languages this provider provides for.
|
||||
* If {@code null}, the provider provides for any language.
|
||||
*
|
||||
* @see #getLanguageScope()
|
||||
*/
|
||||
public void setLanguageScope(List <String> languages) {
|
||||
if (languages==null)
|
||||
this.languageScope = null;
|
||||
else
|
||||
this.languageScope = new ArrayList<String>(languages);
|
||||
}
|
||||
|
||||
public void setCustomParameter(String customParameter) {
|
||||
this.customParameter = customParameter;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
fStorage.clear();
|
||||
}
|
||||
|
||||
// TODO: look for refactoring this method
|
||||
private void setSettingEntriesInternal(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||
if (entries!=null) {
|
||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||
if (langMap==null) {
|
||||
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||
fStorage.put(languageId, langMap);
|
||||
}
|
||||
List<ICLanguageSettingEntry> sortedEntries = lseListPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
||||
langMap.put(rcProjectPath, sortedEntries);
|
||||
} else {
|
||||
// do not keep nulls in the tables
|
||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||
if (langMap!=null) {
|
||||
langMap.remove(rcProjectPath);
|
||||
if (langMap.size()==0) {
|
||||
fStorage.remove(languageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ICLanguageSettingEntry> sortEntries(List<ICLanguageSettingEntry> entries) {
|
||||
List<ICLanguageSettingEntry> sortedEntries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
Collections.sort(sortedEntries, new Comparator<ICLanguageSettingEntry>(){
|
||||
/**
|
||||
* This comparator sorts by kinds first and the macros are sorted additionally by name.
|
||||
*/
|
||||
public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) {
|
||||
int kind0 = entry0.getKind();
|
||||
int kind1 = entry1.getKind();
|
||||
if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) {
|
||||
return entry0.getName().compareTo(entry1.getName());
|
||||
}
|
||||
|
||||
return kind0 - kind1;
|
||||
}});
|
||||
|
||||
return sortedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets language settings entries for the provider.
|
||||
* Note that the entries are not persisted at that point. To persist use TODO
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id. If {@code null}, then entries are considered to be defined for
|
||||
* the language scope. See {@link #getLanguageScope()}
|
||||
* @param entries - language settings entries to set.
|
||||
*/
|
||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
|
||||
setSettingEntriesInternal(rcProjectPath, languageId, entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Note that this list is unmodifiable.
|
||||
*/
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||
if (langMap!=null) {
|
||||
String rcProjectPath = rc!=null ? rc.getProjectRelativePath().toString() : null;
|
||||
List<ICLanguageSettingEntry> entries = langMap.get(rcProjectPath);
|
||||
if (entries!=null)
|
||||
return entries;
|
||||
}
|
||||
|
||||
if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) {
|
||||
List<ICLanguageSettingEntry> entries = getSettingEntries(cfgDescription, rc, null);
|
||||
return entries;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
<provider id="provider.id" ...>
|
||||
<language-scope id="lang.id"/>
|
||||
<language id="lang.id">
|
||||
<resource project-relative-path="/">
|
||||
<entry flags="" kind="includePath" name="path"/>
|
||||
</resource>
|
||||
</language>
|
||||
</provider>
|
||||
*/
|
||||
// provider/configuration/language/resource/entry
|
||||
public Element serialize(Element parentElement) {
|
||||
Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, new String[] {
|
||||
ATTR_ID, getId(),
|
||||
ATTR_NAME, getName(),
|
||||
ATTR_CLASS, getClass().getCanonicalName(),
|
||||
ATTR_PARAMETER, getCustomParameter(),
|
||||
});
|
||||
|
||||
if (languageScope!=null) {
|
||||
for (String langId : languageScope) {
|
||||
XmlUtil.appendElement(elementProvider, ELEM_LANGUAGE_SCOPE, new String[] {ATTR_ID, langId});
|
||||
}
|
||||
}
|
||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : fStorage.entrySet()) {
|
||||
serializeLanguage(elementProvider, entryLang);
|
||||
}
|
||||
return elementProvider;
|
||||
}
|
||||
|
||||
private void serializeLanguage(Element parentElement, Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang) {
|
||||
String langId = entryLang.getKey();
|
||||
if (langId!=null) {
|
||||
Element elementLanguage = XmlUtil.appendElement(parentElement, ELEM_LANGUAGE, new String[] {ATTR_ID, langId});
|
||||
parentElement = elementLanguage;
|
||||
}
|
||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entryLang.getValue().entrySet()) {
|
||||
serializeResource(parentElement, entryRc);
|
||||
}
|
||||
}
|
||||
|
||||
private void serializeResource(Element parentElement, Entry<String, List<ICLanguageSettingEntry>> entryRc) {
|
||||
String rcProjectPath = entryRc.getKey();
|
||||
if (rcProjectPath!=null) {
|
||||
Element elementRc = XmlUtil.appendElement(parentElement, ELEM_RESOURCE, new String[] {ATTR_PROJECT_PATH, rcProjectPath});
|
||||
parentElement = elementRc;
|
||||
}
|
||||
serializeSettingEntries(parentElement, entryRc.getValue());
|
||||
}
|
||||
|
||||
private void serializeSettingEntries(Element parentElement, List<ICLanguageSettingEntry> settingEntries) {
|
||||
for (ICLanguageSettingEntry entry : settingEntries) {
|
||||
Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] {
|
||||
ATTR_KIND, LanguageSettingEntriesSerializer.kindToString(entry.getKind()),
|
||||
ATTR_NAME, entry.getName(),
|
||||
});
|
||||
switch(entry.getKind()) {
|
||||
case ICSettingEntry.MACRO:
|
||||
elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue());
|
||||
break;
|
||||
// case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||
// TODO: sourceAttachment fields need to be covered
|
||||
// break;
|
||||
}
|
||||
int flags = entry.getFlags();
|
||||
if (flags!=0) {
|
||||
// Element elementFlag =
|
||||
XmlUtil.appendElement(elementSettingEntry, ELEM_FLAG, new String[] {
|
||||
ATTR_VALUE, LanguageSettingEntriesSerializer.composeFlagsString(entry.getFlags())
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ICLanguageSettingEntry loadSettingEntry(Node parentElement) {
|
||||
String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND);
|
||||
String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME);
|
||||
|
||||
NodeList flagNodes = parentElement.getChildNodes();
|
||||
int flags = 0;
|
||||
for (int i=0;i<flagNodes.getLength();i++) {
|
||||
Node flagNode = flagNodes.item(i);
|
||||
if(flagNode.getNodeType() != Node.ELEMENT_NODE || !ELEM_FLAG.equals(flagNode.getNodeName()))
|
||||
continue;
|
||||
|
||||
String settingFlags = XmlUtil.determineAttributeValue(flagNode, ATTR_VALUE);
|
||||
int bitFlag = LanguageSettingEntriesSerializer.composeFlags(settingFlags);
|
||||
flags |= bitFlag;
|
||||
|
||||
}
|
||||
|
||||
String settingValue = null;
|
||||
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
||||
if (kind == ICSettingEntry.MACRO)
|
||||
settingValue = XmlUtil.determineAttributeValue(parentElement, ATTR_VALUE);
|
||||
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(kind, settingName, settingValue, null, flags);
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
// provider/configuration/language/resource/entry
|
||||
public void load(Element providerNode) {
|
||||
fStorage.clear();
|
||||
languageScope = null;
|
||||
|
||||
if (providerNode!=null) {
|
||||
String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID);
|
||||
String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME);
|
||||
String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER);
|
||||
this.setId(providerId);
|
||||
this.setName(providerName);
|
||||
this.setCustomParameter(providerParameter);
|
||||
|
||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||
NodeList nodes = providerNode.getChildNodes();
|
||||
for (int i=0;i<nodes.getLength();i++) {
|
||||
Node elementNode = nodes.item(i);
|
||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||
continue;
|
||||
|
||||
if (ELEM_LANGUAGE_SCOPE.equals(elementNode.getNodeName())) {
|
||||
loadLanguageScopeElement(elementNode);
|
||||
} else if (ELEM_LANGUAGE.equals(elementNode.getNodeName())) {
|
||||
loadLanguageElement(elementNode, null);
|
||||
} else if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
||||
loadResourceElement(elementNode, null, null);
|
||||
} else if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
||||
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
||||
if (entry!=null) {
|
||||
settings.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
// set settings
|
||||
if (settings.size()>0) {
|
||||
setSettingEntriesInternal(null, null, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLanguageScopeElement(Node parentNode) {
|
||||
if (languageScope==null) {
|
||||
languageScope = new ArrayList<String>();
|
||||
}
|
||||
String id = XmlUtil.determineAttributeValue(parentNode, ATTR_ID);
|
||||
languageScope.add(id);
|
||||
|
||||
}
|
||||
|
||||
private void loadLanguageElement(Node parentNode, String cfgId) {
|
||||
String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_ID);
|
||||
if (langId.length()==0) {
|
||||
langId=null;
|
||||
}
|
||||
|
||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||
NodeList nodes = parentNode.getChildNodes();
|
||||
for (int i=0;i<nodes.getLength();i++) {
|
||||
Node elementNode = nodes.item(i);
|
||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||
continue;
|
||||
|
||||
if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
||||
loadResourceElement(elementNode, cfgId, langId);
|
||||
} else if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
||||
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
||||
if (entry!=null) {
|
||||
settings.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
// set settings
|
||||
if (settings.size()>0) {
|
||||
setSettingEntriesInternal(null, langId, settings);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadResourceElement(Node parentNode, String cfgId, String langId) {
|
||||
String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH);
|
||||
|
||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||
NodeList nodes = parentNode.getChildNodes();
|
||||
for (int i=0;i<nodes.getLength();i++) {
|
||||
Node elementNode = nodes.item(i);
|
||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||
continue;
|
||||
|
||||
if (ELEM_ENTRY.equals(elementNode.getNodeName())) {
|
||||
ICLanguageSettingEntry entry = loadSettingEntry(elementNode);
|
||||
if (entry!=null) {
|
||||
settings.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set settings
|
||||
if (settings.size()>0) {
|
||||
setSettingEntriesInternal(rcProjectPath, langId, settings);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Map<String, List<ICLanguageSettingEntry>>> cloneStorage() {
|
||||
Map<String, // languageId
|
||||
Map<String, // resource String
|
||||
List<ICLanguageSettingEntry>>> storageClone = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
// Set<Entry<String, Map<String, Map<String, List<ICLanguageSettingEntry>>>>> entrySetCfg = fStorage.entrySet();
|
||||
// for (Entry<String, Map<String, Map<String, List<ICLanguageSettingEntry>>>> entryCfg : entrySetCfg) {
|
||||
// String cfgDescriptionId = entryCfg.getKey();
|
||||
// Map<String, Map<String, List<ICLanguageSettingEntry>>> mapLang = entryCfg.getValue();
|
||||
// Map<String, Map<String, List<ICLanguageSettingEntry>>> mapLangClone = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
Set<Entry<String, Map<String, List<ICLanguageSettingEntry>>>> entrySetLang = fStorage.entrySet();
|
||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : entrySetLang) {
|
||||
String langId = entryLang.getKey();
|
||||
Map<String, List<ICLanguageSettingEntry>> mapRc = entryLang.getValue();
|
||||
Map<String, List<ICLanguageSettingEntry>> mapRcClone = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||
Set<Entry<String, List<ICLanguageSettingEntry>>> entrySetRc = mapRc.entrySet();
|
||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) {
|
||||
String rcProjectPath = entryRc.getKey();
|
||||
List<ICLanguageSettingEntry> lsEntries = entryRc.getValue();
|
||||
// don't need to clone entries, they are from the pool
|
||||
mapRcClone.put(rcProjectPath, lsEntries);
|
||||
}
|
||||
// mapLangClone.put(langId, mapRcClone);
|
||||
storageClone.put(langId, mapRcClone);
|
||||
}
|
||||
// }
|
||||
return storageClone;
|
||||
}
|
||||
|
||||
protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException {
|
||||
LanguageSettingsSerializable clone = (LanguageSettingsSerializable)super.clone();
|
||||
if (languageScope!=null)
|
||||
clone.languageScope = new ArrayList<String>(languageScope);
|
||||
|
||||
clone.fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
return clone;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
protected LanguageSettingsSerializable clone() throws CloneNotSupportedException {
|
||||
LanguageSettingsSerializable clone = cloneShallow();
|
||||
clone.fStorage = cloneStorage();
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||
result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode());
|
||||
result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode());
|
||||
result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode());
|
||||
result = prime * result + getClass().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the objects are equal, {@code false } otherwise.
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LanguageSettingsSerializable other = (LanguageSettingsSerializable) obj;
|
||||
|
||||
String id = getId();
|
||||
String otherId = other.getId();
|
||||
if (id == null) {
|
||||
if (otherId != null)
|
||||
return false;
|
||||
} else if (!id.equals(otherId))
|
||||
return false;
|
||||
|
||||
String name = getName();
|
||||
String otherName = other.getName();
|
||||
if (name == null) {
|
||||
if (otherName != null)
|
||||
return false;
|
||||
} else if (!name.equals(otherName))
|
||||
return false;
|
||||
|
||||
if (languageScope == null) {
|
||||
if (other.languageScope != null)
|
||||
return false;
|
||||
} else if (!languageScope.equals(other.languageScope))
|
||||
return false;
|
||||
|
||||
if (customParameter == null) {
|
||||
if (other.customParameter != null)
|
||||
return false;
|
||||
} else if (!customParameter.equals(other.customParameter))
|
||||
return false;
|
||||
|
||||
if (fStorage == null) {
|
||||
if (other.fStorage != null)
|
||||
return false;
|
||||
} else if (!fStorage.equals(other.fStorage))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
// TODO: move ILanguageSettingsEditableProvider here
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
|
||||
public class LanguageSettingsSerializableEditable extends LanguageSettingsSerializable implements ILanguageSettingsEditableProvider {
|
||||
@Override
|
||||
public LanguageSettingsSerializableEditable clone() throws CloneNotSupportedException {
|
||||
return (LanguageSettingsSerializableEditable) super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LanguageSettingsSerializableEditable cloneShallow() throws CloneNotSupportedException {
|
||||
return (LanguageSettingsSerializableEditable) super.cloneShallow();
|
||||
}
|
||||
|
||||
}
|
|
@ -36,8 +36,9 @@ public abstract class ACExclusionFilterEntry extends ACPathEntry implements ICEx
|
|||
this.exclusionPatterns = exclusionPatterns != null ? (IPath[])exclusionPatterns.clone() : new IPath[0];
|
||||
}
|
||||
|
||||
/** @since 5.3 */
|
||||
@Override
|
||||
protected final boolean isFile() {
|
||||
public final boolean isFile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
public abstract class ACPathEntry extends ACSettingEntry
|
||||
implements ICPathEntry {
|
||||
public abstract class ACPathEntry extends ACSettingEntry implements ICPathEntry {
|
||||
// IPath fFullPath;
|
||||
// IPath fLocation;
|
||||
// private IPath fPath;
|
||||
|
@ -67,7 +66,10 @@ public abstract class ACPathEntry extends ACSettingEntry
|
|||
return null;
|
||||
}
|
||||
|
||||
protected abstract boolean isFile();
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
public abstract boolean isFile();
|
||||
|
||||
public IPath getLocation() {
|
||||
if(!isValueWorkspacePath())
|
||||
|
|
|
@ -51,30 +51,31 @@ public abstract class ACSettingEntry implements ICSettingEntry {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other){
|
||||
if(other == this)
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if(!(other instanceof ACSettingEntry))
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
ACSettingEntry e = (ACSettingEntry)other;
|
||||
|
||||
if(getKind() != e.getKind())
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
if(fFlags != e.fFlags)
|
||||
ACSettingEntry other = (ACSettingEntry) obj;
|
||||
if (fFlags != other.fFlags)
|
||||
return false;
|
||||
|
||||
if(!fName.equals(e.fName))
|
||||
if (fName == null) {
|
||||
if (other.fName != null)
|
||||
return false;
|
||||
} else if (!fName.equals(other.fName))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return getKind() + fFlags + fName.hashCode();
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + fFlags;
|
||||
result = prime * result + ((fName == null) ? 0 : fName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
|
|
|
@ -34,15 +34,28 @@ public final class CMacroEntry extends ACSettingEntry implements ICMacroEntry{
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if(!super.equals(other))
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
return fValue.equals(((CMacroEntry)other).fValue);
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
CMacroEntry other = (CMacroEntry) obj;
|
||||
if (fValue == null) {
|
||||
if (other.fValue != null)
|
||||
return false;
|
||||
} else if (!fValue.equals(other.fValue))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + fValue.hashCode();
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((fValue == null) ? 0 : fValue.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.settings.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider;
|
||||
|
@ -386,4 +388,29 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin
|
|||
void updateExternalSettingsProviders(String[] ids) throws WriteAccessException;
|
||||
|
||||
CConfigurationStatus getConfigurationStatus();
|
||||
|
||||
/**
|
||||
* Sets the list of language settings providers. Language settings providers are
|
||||
* used to supply language settings {@link ICLanguageSettingEntry} such as include paths
|
||||
* or preprocessor macros.
|
||||
*
|
||||
* @param providers the list of providers to assign to the configuration description.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers);
|
||||
|
||||
/**
|
||||
* Returns the list of language settings providers. Language settings providers are
|
||||
* used to supply language settings {@link ICLanguageSettingEntry} such as include paths
|
||||
* or preprocessor macros.
|
||||
*
|
||||
* @return the list of providers to assign to the configuration description. This
|
||||
* returns immutable list. Use {@link #setLanguageSettingProviders(List)} to change.
|
||||
* This method does not return {@code null}.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders();
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,21 @@ public interface ICSettingEntry {
|
|||
*/
|
||||
int RESOLVED = 1 << 4;
|
||||
|
||||
/**
|
||||
* Flag {@code UNDEFINED} indicates that the entry should not be defined.
|
||||
* It's main purpose to provide the means to negate entries defined elsewhere.
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
int UNDEFINED = 1 << 5;
|
||||
|
||||
/**
|
||||
* Flag {@code FRAMEWORKS_MAC} applies for path entries. Such a path entry will be treated
|
||||
* in a special way to imitate resolving paths by Apple's version of gcc, see bug 69529.
|
||||
* .
|
||||
*/
|
||||
int FRAMEWORKS_MAC = 1 << 6;
|
||||
|
||||
int INCLUDE_PATH = 1;
|
||||
int INCLUDE_FILE = 1 << 1;
|
||||
int MACRO = 1 << 2;
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.settings.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* This interface is used in UI to identify classes allowing user to modify settings externally
|
||||
* contrary to some subclasses of {@link LanguageSettingsSerializable} managing
|
||||
* their settings themselves and not providing such option to the user.
|
||||
*
|
||||
*/
|
||||
public interface ILanguageSettingsEditableProvider extends ILanguageSettingsProvider, Cloneable {
|
||||
|
||||
public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, List<ICLanguageSettingEntry> entries);
|
||||
public boolean isEmpty();
|
||||
public void clear();
|
||||
|
||||
public ILanguageSettingsEditableProvider cloneShallow() throws CloneNotSupportedException;
|
||||
public ILanguageSettingsEditableProvider clone() throws CloneNotSupportedException;
|
||||
}
|
|
@ -56,6 +56,7 @@ import org.eclipse.cdt.core.settings.model.extension.CResourceData;
|
|||
import org.eclipse.cdt.core.settings.model.extension.CTargetPlatformData;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFactory;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
|
||||
import org.eclipse.cdt.internal.core.parser.util.WeakHashSet;
|
||||
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
|
@ -75,6 +76,14 @@ public class CDataUtil {
|
|||
private static Random randomNumber;
|
||||
public static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
private static WeakHashSet<ICSettingEntry> languageSettingsPool = new WeakHashSet<ICSettingEntry>() {
|
||||
@Override
|
||||
public synchronized ICSettingEntry add(ICSettingEntry entry) {
|
||||
return super.add(entry);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static int genRandomNumber(){
|
||||
if (randomNumber == null) {
|
||||
// Set the random number seed
|
||||
|
@ -301,26 +310,37 @@ public class CDataUtil {
|
|||
|
||||
|
||||
public static ICSettingEntry createEntry(int kind, String name, String value, IPath[] exclusionPatterns, int flags, IPath srcPath, IPath srcRootPath, IPath srcPrefixMapping){
|
||||
ICSettingEntry entry = null;
|
||||
switch (kind){
|
||||
case ICLanguageSettingEntry.INCLUDE_PATH:
|
||||
return new CIncludePathEntry(name, flags);
|
||||
entry = new CIncludePathEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.MACRO:
|
||||
return new CMacroEntry(name, value, flags);
|
||||
entry = new CMacroEntry(name, value, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.INCLUDE_FILE:
|
||||
return new CIncludeFileEntry(name, flags);
|
||||
entry = new CIncludeFileEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.MACRO_FILE:
|
||||
return new CMacroFileEntry(name, flags);
|
||||
entry = new CMacroFileEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.LIBRARY_PATH:
|
||||
return new CLibraryPathEntry(name, flags);
|
||||
entry = new CLibraryPathEntry(name, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||
return new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping);
|
||||
entry = new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping);
|
||||
break;
|
||||
case ICLanguageSettingEntry.OUTPUT_PATH:
|
||||
return new COutputEntry(name, exclusionPatterns, flags);
|
||||
entry = new COutputEntry(name, exclusionPatterns, flags);
|
||||
break;
|
||||
case ICLanguageSettingEntry.SOURCE_PATH:
|
||||
return new CSourceEntry(name, exclusionPatterns, flags);
|
||||
}
|
||||
entry = new CSourceEntry(name, exclusionPatterns, flags);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return languageSettingsPool.add(entry);
|
||||
}
|
||||
|
||||
public static String[] getSourceExtensions(IProject project, CLanguageData data) {
|
||||
String[] exts = null;
|
||||
|
|
|
@ -59,6 +59,8 @@ public class LanguageSettingEntriesSerializer {
|
|||
public static final String LOCAL = "LOCAL"; //$NON-NLS-1$
|
||||
public static final String VALUE_WORKSPACE_PATH = "VALUE_WORKSPACE_PATH"; //$NON-NLS-1$
|
||||
public static final String RESOLVED = "RESOLVED"; //$NON-NLS-1$
|
||||
private static final String UNDEFINED = "UNDEFINED"; //$NON-NLS-1$
|
||||
private static final String FRAMEWORK = "FRAMEWORK"; //$NON-NLS-1$
|
||||
|
||||
public static final String FLAGS_SEPARATOR = "|"; //$NON-NLS-1$
|
||||
|
||||
|
@ -280,10 +282,22 @@ public class LanguageSettingEntriesSerializer {
|
|||
|
||||
buf.append(RESOLVED);
|
||||
}
|
||||
if((flags & ICLanguageSettingEntry.UNDEFINED) != 0){
|
||||
if(buf.length() != 0)
|
||||
buf.append(FLAGS_SEPARATOR);
|
||||
|
||||
buf.append(UNDEFINED);
|
||||
}
|
||||
if((flags & ICLanguageSettingEntry.FRAMEWORKS_MAC) != 0){
|
||||
if(buf.length() != 0)
|
||||
buf.append(FLAGS_SEPARATOR);
|
||||
|
||||
buf.append(FRAMEWORK);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static int composeFlags(String flagsString){
|
||||
public static int composeFlags(String flagsString){
|
||||
if(flagsString == null || flagsString.length() == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -302,6 +316,10 @@ public class LanguageSettingEntriesSerializer {
|
|||
flags |= ICLanguageSettingEntry.VALUE_WORKSPACE_PATH;
|
||||
if(RESOLVED.equals(f))
|
||||
flags |= ICLanguageSettingEntry.RESOLVED;
|
||||
if(UNDEFINED.equals(f))
|
||||
flags |= ICLanguageSettingEntry.UNDEFINED;
|
||||
if(FRAMEWORK.equals(f))
|
||||
flags |= ICLanguageSettingEntry.FRAMEWORKS_MAC;
|
||||
}
|
||||
|
||||
return flags;
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
|
@ -68,6 +69,7 @@ import org.eclipse.cdt.internal.core.CharOperation;
|
|||
import org.eclipse.cdt.internal.core.cdtvariables.CoreVariableSubstitutor;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.DefaultVariableContextInfo;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger;
|
||||
import org.eclipse.cdt.internal.core.model.APathEntry;
|
||||
import org.eclipse.cdt.internal.core.model.CModelStatus;
|
||||
import org.eclipse.cdt.internal.core.model.PathEntry;
|
||||
|
@ -2002,7 +2004,7 @@ public class PathEntryTranslator {
|
|||
}
|
||||
}
|
||||
|
||||
public static PathEntryCollector collectEntries(IProject project, ICConfigurationDescription des) {
|
||||
public static PathEntryCollector collectEntries(IProject project, final ICConfigurationDescription des) {
|
||||
CConfigurationData data = getCfgData(des);
|
||||
|
||||
ReferenceSettingsInfo refInfo = new ReferenceSettingsInfo(des);
|
||||
|
@ -2036,10 +2038,12 @@ public class PathEntryTranslator {
|
|||
public boolean visit(PathSettingsContainer container) {
|
||||
CResourceData data = (CResourceData)container.getValue();
|
||||
if (data != null) {
|
||||
AG_log(des, kinds, data); // AG FIXME REMOVEME
|
||||
|
||||
PathEntryCollector child = cr.createChild(container.getPath());
|
||||
for (int kind : kinds) {
|
||||
List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>();
|
||||
if (collectResourceDataEntries(kind, data, list)) {
|
||||
if (collectResourceDataEntries(des, kind, data, list)) {
|
||||
ICLanguageSettingEntry[] entries = list.toArray(new ICLanguageSettingEntry[list.size()]);
|
||||
child.setEntries(kind, entries, exportedSettings);
|
||||
}
|
||||
|
@ -2047,11 +2051,28 @@ public class PathEntryTranslator {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// AG FIXME REMOVEME
|
||||
private void AG_log(final ICConfigurationDescription des, final int[] kinds, CResourceData data) {
|
||||
String kindsStr="";
|
||||
for (int kind : kinds) {
|
||||
String kstr = LanguageSettingEntriesSerializer.kindToString(kind);
|
||||
if (kindsStr.length()==0) {
|
||||
kindsStr = kstr;
|
||||
} else {
|
||||
kindsStr += "|" + kstr;
|
||||
}
|
||||
}
|
||||
final IProject prj = des.getProjectDescription().getProject();
|
||||
String log_msg = "path="+prj+"/"+data.getPath()+", kind=["+kindsStr+"]"+" (PathEntryTranslator.collectEntries())";
|
||||
LanguageSettingsLogger.logInfo(log_msg);
|
||||
}
|
||||
|
||||
});
|
||||
return cr;
|
||||
}
|
||||
|
||||
private static boolean collectResourceDataEntries(int kind, CResourceData data, List<ICLanguageSettingEntry> list) {
|
||||
private static boolean collectResourceDataEntries(ICConfigurationDescription des, int kind, CResourceData data, List<ICLanguageSettingEntry> list) {
|
||||
CLanguageData[] lDatas = null;
|
||||
if (data instanceof CFolderData) {
|
||||
lDatas = ((CFolderData)data).getLanguageDatas();
|
||||
|
@ -2068,6 +2089,17 @@ public class PathEntryTranslator {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
IProject project = des.getProjectDescription().getProject();
|
||||
if (LanguageSettingsManager.isLanguageSettingsProvidersEnabled(project)) {
|
||||
IResource rc = getResource(project, data.getPath());
|
||||
for (CLanguageData lData : lDatas) {
|
||||
list.addAll(LanguageSettingsManager.getSettingEntriesByKind(des, rc, lData.getLanguageId(), kind));
|
||||
}
|
||||
return list.size()>0;
|
||||
|
||||
}
|
||||
// Legacy logic
|
||||
boolean supported = false;
|
||||
for (CLanguageData lData : lDatas) {
|
||||
if (collectLanguageDataEntries(kind, lData, list))
|
||||
|
@ -2092,4 +2124,14 @@ public class PathEntryTranslator {
|
|||
PathEntryCollector cr = collectEntries(project, cfg);
|
||||
return cr.getEntries(flags, cfg);
|
||||
}
|
||||
|
||||
private static IResource getResource(IProject project, IPath workspacePath) {
|
||||
IResource rc;
|
||||
if (project!=null) {
|
||||
rc = project.findMember(workspacePath);
|
||||
} else {
|
||||
rc = ResourcesPlugin.getWorkspace().getRoot().findMember(workspacePath);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,617 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
|
||||
/**
|
||||
* Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions
|
||||
*/
|
||||
public class LanguageSettingsExtensionManager {
|
||||
/** Name of the extension point for contributing language settings */
|
||||
final static String PROVIDER_EXTENSION_FULL_ID = "org.eclipse.cdt.core.LanguageSettingsProvider"; //$NON-NLS-1$
|
||||
final static String PROVIDER_EXTENSION_SIMPLE_ID = "LanguageSettingsProvider"; //$NON-NLS-1$
|
||||
|
||||
static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
||||
static final String ATTR_CLASS = "class"; //$NON-NLS-1$
|
||||
static final String ATTR_ID = "id"; //$NON-NLS-1$
|
||||
static final String ATTR_NAME = "name"; //$NON-NLS-1$
|
||||
static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
|
||||
|
||||
static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$
|
||||
|
||||
static final String ELEM_ENTRY = "entry"; //$NON-NLS-1$
|
||||
static final String ELEM_FLAG = "flag"; //$NON-NLS-1$
|
||||
static final String ATTR_KIND = "kind"; //$NON-NLS-1$
|
||||
static final String ATTR_VALUE = "value"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Extension providers loaded once. If the provider is editable (read cloneable)
|
||||
* external callers get copy rather than real instance.
|
||||
*/
|
||||
private static final LinkedHashMap<String, ILanguageSettingsProvider> fExtensionProviders = new LinkedHashMap<String, ILanguageSettingsProvider>();
|
||||
|
||||
/**
|
||||
* Providers loaded initially via static initializer.
|
||||
*/
|
||||
static {
|
||||
try {
|
||||
loadProviderExtensions();
|
||||
} catch (Throwable e) {
|
||||
CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load language settings providers contributed via the extension point.
|
||||
*/
|
||||
synchronized private static void loadProviderExtensions() {
|
||||
// sort by name - for the providers taken from platform extensions
|
||||
Set<ILanguageSettingsProvider> sortedProviders = new TreeSet<ILanguageSettingsProvider>(
|
||||
new Comparator<ILanguageSettingsProvider>() {
|
||||
public int compare(ILanguageSettingsProvider pr1, ILanguageSettingsProvider pr2) {
|
||||
return pr1.getName().compareTo(pr2.getName());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
loadProviderExtensions(Platform.getExtensionRegistry(), sortedProviders);
|
||||
|
||||
fExtensionProviders.clear();
|
||||
for (ILanguageSettingsProvider provider : sortedProviders) {
|
||||
fExtensionProviders.put(provider.getId(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load contributed extensions from extension registry.
|
||||
*
|
||||
* @param registry - extension registry
|
||||
* @param providers - resulting set of providers
|
||||
*/
|
||||
private static void loadProviderExtensions(IExtensionRegistry registry, Set<ILanguageSettingsProvider> providers) {
|
||||
providers.clear();
|
||||
IExtensionPoint extension = registry.getExtensionPoint(CCorePlugin.PLUGIN_ID, PROVIDER_EXTENSION_SIMPLE_ID);
|
||||
if (extension != null) {
|
||||
IExtension[] extensions = extension.getExtensions();
|
||||
for (IExtension ext : extensions) {
|
||||
for (IConfigurationElement cfgEl : ext.getConfigurationElements()) {
|
||||
ILanguageSettingsProvider provider = null;
|
||||
String id=null;
|
||||
try {
|
||||
if (cfgEl.getName().equals(ELEM_PROVIDER)) {
|
||||
id = determineAttributeValue(cfgEl, ATTR_ID);
|
||||
provider = createExecutableExtension(cfgEl);
|
||||
configureExecutableProvider(provider, cfgEl);
|
||||
providers.add(provider);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
CCorePlugin.log("Cannot load LanguageSettingsProvider extension id=" + id, e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String determineAttributeValue(IConfigurationElement ce, String attr) {
|
||||
String value = ce.getAttribute(attr);
|
||||
return value!=null ? value : ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates empty non-configured provider as executable extension from extension point definition.
|
||||
* If "class" attribute is empty {@link LanguageSettingsBaseProvider} is created.
|
||||
*
|
||||
* @param ce - configuration element with provider definition
|
||||
* @return new non-configured provider
|
||||
* @throws CoreException in case of failure
|
||||
*/
|
||||
private static ILanguageSettingsProvider createExecutableExtension(IConfigurationElement ce) throws CoreException {
|
||||
String ceClass = ce.getAttribute(ATTR_CLASS);
|
||||
ILanguageSettingsProvider provider = null;
|
||||
if (ceClass==null || ceClass.trim().length()==0 || ceClass.equals(LanguageSettingsBaseProvider.class.getCanonicalName())) {
|
||||
provider = new LanguageSettingsBaseProvider();
|
||||
} else {
|
||||
provider = (ILanguageSettingsProvider)ce.createExecutableExtension(ATTR_CLASS);
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure language settings provider with parameters defined in XML metadata.
|
||||
*
|
||||
* @param provider - empty non-configured provider.
|
||||
* @param ce - configuration element from registry representing XML.
|
||||
*/
|
||||
private static void configureExecutableProvider(ILanguageSettingsProvider provider, IConfigurationElement ce) {
|
||||
String ceId = determineAttributeValue(ce, ATTR_ID);
|
||||
String ceName = determineAttributeValue(ce, ATTR_NAME);
|
||||
String ceParameter = determineAttributeValue(ce, ATTR_PARAMETER);
|
||||
List<String> languages = null;
|
||||
List<ICLanguageSettingEntry> entries = null;
|
||||
|
||||
for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) {
|
||||
String langId = determineAttributeValue(ceLang, ATTR_ID);
|
||||
if (langId.trim().length()>0) {
|
||||
if (languages==null) {
|
||||
languages = new ArrayList<String>();
|
||||
}
|
||||
languages.add(langId);
|
||||
}
|
||||
}
|
||||
|
||||
for (IConfigurationElement ceEntry : ce.getChildren(ELEM_ENTRY)) {
|
||||
try {
|
||||
int entryKind = LanguageSettingEntriesSerializer.stringToKind(determineAttributeValue(ceEntry, ATTR_KIND));
|
||||
String entryName = determineAttributeValue(ceEntry, ATTR_NAME);
|
||||
String entryValue = determineAttributeValue(ceEntry, ATTR_VALUE);
|
||||
|
||||
int flags = 0;
|
||||
for (IConfigurationElement ceFlags : ceEntry.getChildren(ELEM_FLAG)) {
|
||||
int bitFlag = LanguageSettingEntriesSerializer.composeFlags(determineAttributeValue(ceFlags, ATTR_VALUE));
|
||||
flags |= bitFlag;
|
||||
}
|
||||
|
||||
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(
|
||||
entryKind, entryName, entryValue, null, flags);
|
||||
|
||||
if (entries == null)
|
||||
entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(entry);
|
||||
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Error creating language settings entry ", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
if (provider instanceof LanguageSettingsBaseProvider) {
|
||||
((LanguageSettingsBaseProvider) provider).configureProvider(ceId, ceName, languages, entries, ceParameter);
|
||||
} else if (provider instanceof AbstractExecutableExtensionBase) {
|
||||
((AbstractExecutableExtensionBase) provider).setId(ceId);
|
||||
((AbstractExecutableExtensionBase) provider).setName(ceName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates empty non-configured provider from extension point definition. The method will
|
||||
* inspect extension registry for extension point "org.eclipse.cdt.core.LanguageSettingsProvider"
|
||||
* to determine bundle and instantiate the class.
|
||||
* ID and name of provider are assigned from first extension point encountered.
|
||||
*
|
||||
* @param className - full qualified class name of provider.
|
||||
* @param registry - extension registry
|
||||
* @return new non-configured provider
|
||||
*/
|
||||
private static ILanguageSettingsProvider createProviderCarcass(String className, IExtensionRegistry registry) {
|
||||
if (className==null || className.length()==0) {
|
||||
return new LanguageSettingsBaseProvider();
|
||||
}
|
||||
|
||||
try {
|
||||
IExtensionPoint extension = registry.getExtensionPoint(CCorePlugin.PLUGIN_ID, PROVIDER_EXTENSION_SIMPLE_ID);
|
||||
if (extension != null) {
|
||||
IExtension[] extensions = extension.getExtensions();
|
||||
for (IExtension ext : extensions) {
|
||||
for (IConfigurationElement cfgEl : ext.getConfigurationElements()) {
|
||||
if (cfgEl.getName().equals(ELEM_PROVIDER) && className.equals(cfgEl.getAttribute(ATTR_CLASS))) {
|
||||
ILanguageSettingsProvider provider = createExecutableExtension(cfgEl);
|
||||
if (provider instanceof AbstractExecutableExtensionBase) {
|
||||
String ceId = determineAttributeValue(cfgEl, ATTR_ID);
|
||||
String ceName = determineAttributeValue(cfgEl, ATTR_NAME);
|
||||
((AbstractExecutableExtensionBase) provider).setId(ceId);
|
||||
((AbstractExecutableExtensionBase) provider).setName(ceName);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Error creating language settings provider.", e); //$NON-NLS-1$
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of language settings provider of given class name.
|
||||
*
|
||||
* @param className - class name to instantiate.
|
||||
* @return new instance of language settings provider.
|
||||
*/
|
||||
/*package*/ static ILanguageSettingsProvider getProviderInstance(String className) {
|
||||
if (className==null || className.equals(LanguageSettingsSerializable.class.getName())) {
|
||||
return new LanguageSettingsSerializable();
|
||||
}
|
||||
|
||||
ILanguageSettingsProvider provider = createProviderCarcass(className, Platform.getExtensionRegistry());
|
||||
if (provider==null) {
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to load provider class=" + className);
|
||||
CCorePlugin.log(new CoreException(status));
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Language Settings Provider defined via
|
||||
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
|
||||
*
|
||||
* @param id - ID of provider to find.
|
||||
* @return the clone of the provider or {@code null} if provider is not defined.
|
||||
* @throws CloneNotSupportedException if the provider is not cloneable
|
||||
*/
|
||||
public static ILanguageSettingsProvider getExtensionProviderClone(String id) throws CloneNotSupportedException {
|
||||
ILanguageSettingsProvider provider = fExtensionProviders.get(id);
|
||||
if (provider!=null) {
|
||||
if (!(provider instanceof ILanguageSettingsEditableProvider))
|
||||
throw new CloneNotSupportedException("Not able to clone provider " + provider.getClass());
|
||||
|
||||
provider = ((ILanguageSettingsEditableProvider) provider).clone();
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static ILanguageSettingsProvider getExtensionProviderShallow(String id) {
|
||||
ILanguageSettingsProvider provider = fExtensionProviders.get(id);
|
||||
if (provider instanceof ILanguageSettingsEditableProvider) {
|
||||
try {
|
||||
return ((ILanguageSettingsEditableProvider) provider).cloneShallow();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Not able to clone provider " + provider.getClass());
|
||||
CCorePlugin.log(new CoreException(status));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of providers contributed by all extensions. Preferable copy but if not possible
|
||||
* will return raw provider.
|
||||
*/
|
||||
/*package*/ static List<ILanguageSettingsProvider> getExtensionProvidersInternal() {
|
||||
ArrayList<ILanguageSettingsProvider> list = new ArrayList<ILanguageSettingsProvider>(fExtensionProviders.size());
|
||||
for (String id : fExtensionProviders.keySet()) {
|
||||
ILanguageSettingsProvider extensionProvider = null;
|
||||
try {
|
||||
extensionProvider = getExtensionProviderClone(id);
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// from here falls to get raw extension provider
|
||||
}
|
||||
if (extensionProvider==null)
|
||||
extensionProvider = fExtensionProviders.get(id);
|
||||
|
||||
if (extensionProvider!=null)
|
||||
list.add(extensionProvider);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<ICLanguageSettingEntry> safeGetSettingEntries(ILanguageSettingsProvider provider,
|
||||
ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
|
||||
try {
|
||||
return provider.getSettingEntries(cfgDescription, rc, languageId);
|
||||
} catch (Throwable e) {
|
||||
String cfgId = cfgDescription!=null ? cfgDescription.getId() : null;
|
||||
String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")";
|
||||
CCorePlugin.log(msg, e);
|
||||
// return empty array to prevent climbing up the resource tree
|
||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of setting entries of the given provider
|
||||
* for the given configuration description, resource and language.
|
||||
* This method reaches to the parent folder of the resource recursively
|
||||
* in case the resource does not define the entries for the given provider.
|
||||
*
|
||||
* @param provider - language settings provider.
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
*
|
||||
* @return the list of setting entries. Never returns {@code null}
|
||||
* although individual providers mandated to return {@code null} if no settings defined.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
Assert.isTrue( !(rc instanceof IWorkspaceRoot) );
|
||||
if (provider!=null) {
|
||||
List<ICLanguageSettingEntry> entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId);
|
||||
if (entries!=null) {
|
||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
}
|
||||
if (rc!=null) {
|
||||
IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent();
|
||||
if (parentFolder!=null) {
|
||||
return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId);
|
||||
}
|
||||
// if out of parent resources - get default entries for the applicable language scope
|
||||
entries = safeGetSettingEntries(provider, null, null, languageId);
|
||||
if (entries!=null) {
|
||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
||||
* Note that it is not advisable to "compact" the tree because of potential loss of information
|
||||
* which is especially important during partial or incremental builds.
|
||||
*
|
||||
* @param provider - language settings provider to build the tree for.
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param languageId - language ID.
|
||||
* @param folder - container where the tree roots.
|
||||
*/
|
||||
public static void buildResourceTree(LanguageSettingsSerializable provider, ICConfigurationDescription cfgDescription, String languageId, IContainer folder) {
|
||||
IResource[] members = null;
|
||||
try {
|
||||
members = folder.members();
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
if (members==null)
|
||||
return;
|
||||
|
||||
for (IResource rc : members) {
|
||||
if (rc instanceof IContainer) {
|
||||
buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc);
|
||||
}
|
||||
}
|
||||
|
||||
int rcNumber = members.length;
|
||||
|
||||
Map<List<ICLanguageSettingEntry>, Integer> listMap = new HashMap<List<ICLanguageSettingEntry>, Integer>();
|
||||
|
||||
// on the first pass find majority entries
|
||||
List<ICLanguageSettingEntry> majorityEntries = null;
|
||||
List<ICLanguageSettingEntry> candidate = null;
|
||||
int candidateCount = 0;
|
||||
for (IResource rc : members) {
|
||||
if (!isLanguageInScope(rc, cfgDescription, languageId)) {
|
||||
rcNumber--;
|
||||
} else {
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||
if (entries==null && rc instanceof IContainer) {
|
||||
rcNumber--;
|
||||
} else {
|
||||
Integer count = listMap.get(entries);
|
||||
if (count==null) {
|
||||
count = 0;
|
||||
}
|
||||
count++;
|
||||
|
||||
if (count>candidateCount) {
|
||||
candidateCount = count;
|
||||
candidate = entries;
|
||||
}
|
||||
|
||||
listMap.put(entries, count);
|
||||
}
|
||||
}
|
||||
|
||||
if (candidateCount > rcNumber/2) {
|
||||
majorityEntries = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (majorityEntries!=null) {
|
||||
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
||||
}
|
||||
|
||||
// second pass - assign the entries to the folders
|
||||
for (IResource rc : members) {
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||
if (entries!=null && entries==majorityEntries) {
|
||||
if (!(rc instanceof IFile)) { // preserve information which files were collected
|
||||
provider.setSettingEntries(cfgDescription, rc, languageId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLanguageInScope(IResource rc, ICConfigurationDescription cfgDescription, String languageId) {
|
||||
if (rc instanceof IFile) {
|
||||
ILanguage lang = null;
|
||||
try {
|
||||
lang = LanguageManager.getInstance().getLanguageForFile((IFile) rc, cfgDescription);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$
|
||||
}
|
||||
if (lang==null || (languageId!=null && languageId.equals(lang.getId()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkBit(int flags, int bit) {
|
||||
return (flags & bit) == bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of setting entries of a certain kind (such as include paths)
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
* @param kind - kind of language settings entries, such as
|
||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
* @param checkLocality - specifies if parameter {@code isLocal} should be considered.
|
||||
* @param isLocal - {@code true} if "local" entries should be provided and
|
||||
* {@code false} for "system" entries. This makes sense for include paths where
|
||||
* [#include "..."] is "local" and [#include <...>] is system.
|
||||
*
|
||||
* @return the list of setting entries found.
|
||||
*/
|
||||
private static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription,
|
||||
IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) {
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
List<String> alreadyAdded = new ArrayList<String>();
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
for (ILanguageSettingsProvider provider: providers) {
|
||||
List<ICLanguageSettingEntry> providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
||||
for (ICLanguageSettingEntry entry : providerEntries) {
|
||||
if (entry!=null) {
|
||||
String entryName = entry.getName();
|
||||
boolean isRightKind = (entry.getKind() & kind) != 0;
|
||||
// Only first entry is considered
|
||||
// Entry flagged as "UNDEFINED" prevents adding entry with the same name down the line
|
||||
if (isRightKind && !alreadyAdded.contains(entryName)) {
|
||||
int flags = entry.getFlags();
|
||||
boolean isRightLocal = !checkLocality || (checkBit(flags, ICSettingEntry.LOCAL) == isLocal);
|
||||
if (isRightLocal) {
|
||||
if (!checkBit(flags, ICSettingEntry.UNDEFINED)) {
|
||||
entries.add(entry);
|
||||
}
|
||||
alreadyAdded.add(entryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of setting entries of a certain kind (such as include paths)
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined. For include paths both
|
||||
* local (#include "...") and system (#include <...>) entries are returned.
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
* @param kind - kind of language settings entries, such as
|
||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ false, /* isLocal */ false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
* @param kind - kind of language settings entries, such as
|
||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind
|
||||
* for the given configuration description, resource and language. This is a
|
||||
* combined list for all providers taking into account settings of parent folder
|
||||
* if settings for the given resource are not defined.
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id.
|
||||
* @param kind - kind of language settings entries, such as
|
||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||
* and it is possible to specify composite kind.
|
||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||
*
|
||||
* @return the list of setting entries.
|
||||
*/
|
||||
public static List<ICLanguageSettingEntry> getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||
return getSettingEntriesByKind(cfgDescription, rc, languageId, kind, /* checkLocality */ true, /* isLocal */ true);
|
||||
}
|
||||
|
||||
public static boolean equalsExtensionProviderShallow(ILanguageSettingsEditableProvider provider) throws CloneNotSupportedException {
|
||||
String id = provider.getId();
|
||||
ILanguageSettingsProvider extensionProviderShallow = getExtensionProviderShallow(id);
|
||||
return provider.cloneShallow().equals(extensionProviderShallow);
|
||||
}
|
||||
|
||||
public static boolean equalsExtensionProvider(ILanguageSettingsProvider provider) {
|
||||
String id = provider.getId();
|
||||
ILanguageSettingsProvider extensionProvider = fExtensionProviders.get(id);
|
||||
return provider.equals(extensionProvider);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
@Deprecated
|
||||
public class LanguageSettingsLogger {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final boolean ENABLED = false;
|
||||
|
||||
// AG FIXME
|
||||
/**
|
||||
* @param msg
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void logInfo(String msg) {
|
||||
if (ENABLED) {
|
||||
Exception e = new Exception(msg);
|
||||
IStatus status = new Status(IStatus.INFO, CCorePlugin.PLUGIN_ID, msg, e);
|
||||
CCorePlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
// AG FIXME
|
||||
/**
|
||||
* @param msg
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void logWarning(String msg) {
|
||||
if (ENABLED) {
|
||||
Exception e = new Exception(msg);
|
||||
IStatus status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, e);
|
||||
CCorePlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
// AG FIXME
|
||||
/**
|
||||
* @param msg
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void logError(String msg) {
|
||||
if (ENABLED) {
|
||||
Exception e = new Exception(msg);
|
||||
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg, e);
|
||||
CCorePlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
// AG FIXME
|
||||
/**
|
||||
* @param rc
|
||||
* @param who - pass "this" (calling class instance) here
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void logScannerInfoProvider(IResource rc, Object who) {
|
||||
if (ENABLED) {
|
||||
String msg = "rc="+rc+" <-- "+who.getClass().getSimpleName();
|
||||
if (rc instanceof IFile) {
|
||||
LanguageSettingsLogger.logInfo(msg);
|
||||
} else if (rc instanceof IProject) {
|
||||
LanguageSettingsLogger.logWarning(msg);
|
||||
} else {
|
||||
LanguageSettingsLogger.logError(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,456 @@
|
|||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializable;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ILanguageSettingsEditableProvider;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class LanguageSettingsProvidersSerializer {
|
||||
|
||||
private static final String STORAGE_WORKSPACE_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$
|
||||
private static final String SETTINGS_FOLDER_NAME = ".settings/"; //$NON-NLS-1$
|
||||
private static final String STORAGE_PROJECT_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$
|
||||
public static final char PROVIDER_DELIMITER = ';';
|
||||
private static final String MBS_LANGUAGE_SETTINGS_PROVIDER = "org.eclipse.cdt.managedbuilder.core.LanguageSettingsProvider";
|
||||
private static final String ELEM_PLUGIN = "plugin"; //$NON-NLS-1$
|
||||
private static final String ELEM_EXTENSION = "extension"; //$NON-NLS-1$
|
||||
private static final String ATTR_POINT = "point"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROJECT = "project"; //$NON-NLS-1$
|
||||
private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$
|
||||
/** Cache of globally available providers to be consumed by calling clients */
|
||||
private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||
private static Object serializingLock = new Object();
|
||||
|
||||
private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider {
|
||||
private String providerId;
|
||||
|
||||
public LanguageSettingsWorkspaceProvider(String id) {
|
||||
Assert.isNotNull(id);
|
||||
Assert.isTrue(id.length()>0);
|
||||
providerId = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
ILanguageSettingsProvider rawProvider = getRawProvider();
|
||||
String name = rawProvider!=null ? rawProvider.getName() : null;
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
ILanguageSettingsProvider rawProvider = getRawProvider();
|
||||
List<ICLanguageSettingEntry> entries = rawProvider!=null ? rawProvider.getSettingEntries(cfgDescription, rc, languageId) : null;
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not cache the "raw" provider as workspace provider can be changed at any time.
|
||||
*/
|
||||
private ILanguageSettingsProvider getRawProvider() {
|
||||
return LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(providerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof LanguageSettingsWorkspaceProvider) {
|
||||
LanguageSettingsWorkspaceProvider that = (LanguageSettingsWorkspaceProvider) obj;
|
||||
return providerId.equals(that.providerId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Method toString() for debugging purposes.
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String toString() {
|
||||
return "id="+getId()+", name="+getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** static initializer */
|
||||
static {
|
||||
try {
|
||||
loadLanguageSettingsWorkspace();
|
||||
} catch (Throwable e) {
|
||||
CCorePlugin.log("Error loading workspace language settings providers", e); //$NON-NLS-1$
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and store in workspace area user defined providers.
|
||||
*
|
||||
* @param providers - array of user defined providers
|
||||
* @throws CoreException in case of problems
|
||||
*/
|
||||
public static void setWorkspaceProviders(List<ILanguageSettingsProvider> providers) throws CoreException {
|
||||
setWorkspaceProvidersInternal(providers);
|
||||
serializeLanguageSettingsWorkspace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to set user defined providers in memory.
|
||||
*
|
||||
* @param providers - list of user defined providers. If {@code null}
|
||||
* is passed user defined providers are cleared.
|
||||
*/
|
||||
private static void setWorkspaceProvidersInternal(List<ILanguageSettingsProvider> providers) {
|
||||
Map<String, ILanguageSettingsProvider> rawWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||
List<ILanguageSettingsProvider> extensionProviders = new ArrayList<ILanguageSettingsProvider>(LanguageSettingsExtensionManager.getExtensionProvidersInternal());
|
||||
for (ILanguageSettingsProvider rawExtensionProvider : extensionProviders) {
|
||||
if (rawExtensionProvider!=null) {
|
||||
rawWorkspaceProviders.put(rawExtensionProvider.getId(), rawExtensionProvider);
|
||||
}
|
||||
}
|
||||
|
||||
if (providers!=null) {
|
||||
List<ILanguageSettingsProvider> rawProviders = new ArrayList<ILanguageSettingsProvider>();
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
if (isWorkspaceProvider(provider)) {
|
||||
provider = rawGlobalWorkspaceProviders.get(provider.getId());
|
||||
}
|
||||
if (provider!=null) {
|
||||
rawProviders.add(provider);
|
||||
}
|
||||
}
|
||||
for (ILanguageSettingsProvider provider : rawProviders) {
|
||||
rawWorkspaceProviders.put(provider.getId(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
rawGlobalWorkspaceProviders = rawWorkspaceProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor with ErrorParserManager
|
||||
*
|
||||
* @param store - name of the store
|
||||
* @return location of the store in the plug-in state area
|
||||
*/
|
||||
private static URI getStoreLocation(String store) {
|
||||
IPath location = CCorePlugin.getDefault().getStateLocation().append(store);
|
||||
URI uri = URIUtil.toURI(location);
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettingsWorkspace() throws CoreException {
|
||||
URI uriLocation = getStoreLocation(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
List<LanguageSettingsSerializable> serializableExtensionProviders = new ArrayList<LanguageSettingsSerializable>();
|
||||
for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) {
|
||||
if (provider instanceof LanguageSettingsSerializable) {
|
||||
// serialize all editable providers which are different from corresponding extension
|
||||
// and serialize all serializable ones that are not editable (those are singletons and we don't know whether they changed)
|
||||
if (!(provider instanceof ILanguageSettingsEditableProvider) || !LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) {
|
||||
serializableExtensionProviders.add((LanguageSettingsSerializable)provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (serializableExtensionProviders.isEmpty()) {
|
||||
java.io.File file = new java.io.File(uriLocation);
|
||||
synchronized (serializingLock) {
|
||||
file.delete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN);
|
||||
Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||
|
||||
for (LanguageSettingsSerializable provider : serializableExtensionProviders) {
|
||||
provider.serialize(elementExtension);
|
||||
}
|
||||
|
||||
synchronized (serializingLock) {
|
||||
XmlUtil.serializeXml(doc, uriLocation);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$
|
||||
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e);
|
||||
throw new CoreException(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadLanguageSettingsWorkspace() throws CoreException {
|
||||
List <ILanguageSettingsProvider> providers = null;
|
||||
|
||||
URI uriLocation = getStoreLocation(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
|
||||
Document doc = null;
|
||||
try {
|
||||
synchronized (serializingLock) {
|
||||
doc = XmlUtil.loadXml(uriLocation);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Can't load preferences from file "+uriLocation, e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (doc!=null) {
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializable.ELEM_PROVIDER);
|
||||
|
||||
List<String> userDefinedProvidersIds = new ArrayList<String>();
|
||||
for (int i=0;i<providerNodes.getLength();i++) {
|
||||
Node providerNode = providerNodes.item(i);
|
||||
String providerId = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
if (userDefinedProvidersIds.contains(providerId)) {
|
||||
String msg = "Ignored repeatedly persisted duplicate language settings provider id=" + providerId;
|
||||
CCorePlugin.log(new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, msg, new Exception()));
|
||||
continue;
|
||||
}
|
||||
userDefinedProvidersIds.add(providerId);
|
||||
|
||||
ILanguageSettingsProvider provider = loadProvider(providerNode);
|
||||
if (provider!=null) {
|
||||
if (providers==null)
|
||||
providers= new ArrayList<ILanguageSettingsProvider>();
|
||||
|
||||
if (!LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) {
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setWorkspaceProvidersInternal(providers);
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettings(Element parentElement, ICProjectDescription prjDescription) throws CoreException {
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
|
||||
for (ICConfigurationDescription cfgDescription : cfgDescriptions) {
|
||||
Element elementConfiguration = XmlUtil.appendElement(parentElement, ELEM_CONFIGURATION, new String[] {
|
||||
LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(),
|
||||
LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(),
|
||||
});
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
if (providers.size()>0) {
|
||||
Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
|
||||
ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
if (isWorkspaceProvider(provider)) {
|
||||
// Element elementProviderReference =
|
||||
XmlUtil.appendElement(elementExtension, ELEM_PROVIDER_REFERENCE, new String[] {
|
||||
LanguageSettingsExtensionManager.ATTR_ID, provider.getId()});
|
||||
continue;
|
||||
}
|
||||
if (provider instanceof LanguageSettingsSerializable) {
|
||||
((LanguageSettingsSerializable) provider).serialize(elementExtension);
|
||||
} else {
|
||||
// Element elementProvider =
|
||||
XmlUtil.appendElement(elementExtension, LanguageSettingsExtensionManager.ELEM_PROVIDER, new String[] {
|
||||
LanguageSettingsExtensionManager.ATTR_ID, provider.getId(),
|
||||
LanguageSettingsExtensionManager.ATTR_NAME, provider.getName(),
|
||||
LanguageSettingsExtensionManager.ATTR_CLASS, provider.getClass().getCanonicalName(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IFile getStorage(IProject project) throws CoreException {
|
||||
IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME);
|
||||
if (!folder.exists()) {
|
||||
folder.create(true, true, null);
|
||||
}
|
||||
IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS);
|
||||
return storage;
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException {
|
||||
IProject project = prjDescription.getProject();
|
||||
try {
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_PROJECT);
|
||||
serializeLanguageSettings(rootElement, prjDescription);
|
||||
|
||||
IFile file = getStorage(project);
|
||||
synchronized (serializingLock){
|
||||
XmlUtil.serializeXml(doc, file);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e);
|
||||
CCorePlugin.log(s);
|
||||
throw new CoreException(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadLanguageSettings(Element parentElement, ICProjectDescription prjDescription) {
|
||||
/*
|
||||
<project>
|
||||
<configuration id="cfg.id">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider .../>
|
||||
<provider-reference id="..."/>
|
||||
</extension>
|
||||
</configuration>
|
||||
</project>
|
||||
*/
|
||||
NodeList configurationNodes = parentElement.getChildNodes();
|
||||
for (int ic=0;ic<configurationNodes.getLength();ic++) {
|
||||
Node cfgNode = configurationNodes.item(ic);
|
||||
if (!(cfgNode instanceof Element && cfgNode.getNodeName().equals(ELEM_CONFIGURATION)) )
|
||||
continue;
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
String cfgId = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
@SuppressWarnings("unused")
|
||||
String cfgName = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_NAME);
|
||||
|
||||
NodeList extensionAndReferenceNodes = cfgNode.getChildNodes();
|
||||
for (int ie=0;ie<extensionAndReferenceNodes.getLength();ie++) {
|
||||
Node extNode = extensionAndReferenceNodes.item(ie);
|
||||
if (!(extNode instanceof Element))
|
||||
continue;
|
||||
|
||||
if (extNode.getNodeName().equals(ELEM_EXTENSION)) {
|
||||
NodeList providerNodes = extNode.getChildNodes();
|
||||
|
||||
for (int i=0;i<providerNodes.getLength();i++) {
|
||||
Node providerNode = providerNodes.item(i);
|
||||
if (!(providerNode instanceof Element))
|
||||
continue;
|
||||
|
||||
ILanguageSettingsProvider provider=null;
|
||||
if (providerNode.getNodeName().equals(ELEM_PROVIDER_REFERENCE)) {
|
||||
String providerId = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
provider = getWorkspaceProvider(providerId);
|
||||
} else if (providerNode.getNodeName().equals(LanguageSettingsExtensionManager.ELEM_PROVIDER)) {
|
||||
provider = loadProvider(providerNode);
|
||||
}
|
||||
if (provider!=null) {
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getConfigurationById(cfgId);
|
||||
if (cfgDescription!=null)
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
}
|
||||
|
||||
private static ILanguageSettingsProvider loadProvider(Node providerNode) {
|
||||
String attrClass = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_CLASS);
|
||||
ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getProviderInstance(attrClass);
|
||||
|
||||
if (provider instanceof LanguageSettingsSerializable)
|
||||
((LanguageSettingsSerializable)provider).load((Element) providerNode);
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static void loadLanguageSettings(ICProjectDescription prjDescription) {
|
||||
IProject project = prjDescription.getProject();
|
||||
IFile file = project.getFile(SETTINGS_FOLDER_NAME+STORAGE_PROJECT_LANGUAGE_SETTINGS);
|
||||
// AG: FIXME not sure about that one
|
||||
// Causes java.lang.IllegalArgumentException: Attempted to beginRule: P/cdt312, does not match outer scope rule: org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover$SingletonRule@6f34fb
|
||||
try {
|
||||
file.refreshLocal(IResource.DEPTH_ZERO, null);
|
||||
} catch (CoreException e) {
|
||||
// ignore failure
|
||||
}
|
||||
if (file.exists() && file.isAccessible()) {
|
||||
Document doc = null;
|
||||
try {
|
||||
synchronized (serializingLock) {
|
||||
doc = XmlUtil.loadXml(file);
|
||||
}
|
||||
Element rootElement = doc.getDocumentElement(); // <project/>
|
||||
loadLanguageSettings(rootElement, prjDescription);
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Can't load preferences from file "+file.getLocation(), e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (doc!=null) {
|
||||
}
|
||||
|
||||
} else {
|
||||
// Already existing legacy projects
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
|
||||
for (ICConfigurationDescription cfgDescription : cfgDescriptions) {
|
||||
if (cfgDescription!=null) {
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(2);
|
||||
ILanguageSettingsProvider userProvider = getWorkspaceProvider(MBS_LANGUAGE_SETTINGS_PROVIDER);
|
||||
providers.add(userProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME Get Language Settings Provider defined in the workspace. That includes user-defined
|
||||
* providers and after that providers defined as extensions via
|
||||
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
|
||||
* That returns actual object, any modifications will affect any configuration
|
||||
* referring to the provider.
|
||||
*
|
||||
* @param id - ID of provider to find.
|
||||
* @return the provider or {@code null} if provider is not defined.
|
||||
*/
|
||||
public static ILanguageSettingsProvider getWorkspaceProvider(String id) {
|
||||
return new LanguageSettingsWorkspaceProvider(id);
|
||||
}
|
||||
|
||||
public static ILanguageSettingsProvider getRawWorkspaceProvider(String id) {
|
||||
return rawGlobalWorkspaceProviders.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return ordered set of providers defined in the workspace which include contributed through extension + user defined ones
|
||||
*
|
||||
*/
|
||||
public static List<ILanguageSettingsProvider> getWorkspaceProviders() {
|
||||
ArrayList<ILanguageSettingsProvider> workspaceProviders = new ArrayList<ILanguageSettingsProvider>();
|
||||
for (ILanguageSettingsProvider rawProvider : rawGlobalWorkspaceProviders.values()) {
|
||||
workspaceProviders.add(new LanguageSettingsWorkspaceProvider(rawProvider.getId()));
|
||||
}
|
||||
return workspaceProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provider is defined on the workspace level.
|
||||
*
|
||||
* @param provider - provider to check.
|
||||
* @return {@code true} if the given provider is workspace provider, {@code false} otherwise.
|
||||
*
|
||||
*/
|
||||
public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) {
|
||||
return provider instanceof LanguageSettingsWorkspaceProvider;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,325 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ACPathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingPathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IScannerInfoProvider} backed by the list of
|
||||
* language settings providers of "default settings configuration"
|
||||
* (see {@link ICProjectDescription#getDefaultSettingConfiguration()}).
|
||||
*
|
||||
*/
|
||||
public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider {
|
||||
private static final ExtendedScannerInfo DUMMY_SCANNER_INFO = new ExtendedScannerInfo();
|
||||
|
||||
public ExtendedScannerInfo getScannerInformation(IResource rc) {
|
||||
// AG FIXME
|
||||
LanguageSettingsLogger.logScannerInfoProvider(rc, this);
|
||||
|
||||
IProject project = rc.getProject();
|
||||
if (project==null)
|
||||
return DUMMY_SCANNER_INFO;
|
||||
|
||||
ICProjectDescription prjDescription = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
if (prjDescription==null)
|
||||
return DUMMY_SCANNER_INFO;
|
||||
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
|
||||
if (cfgDescription==null)
|
||||
return DUMMY_SCANNER_INFO;
|
||||
|
||||
List<String> languageIds = getLanguageIds(cfgDescription, rc);
|
||||
if (languageIds==null || languageIds.size()==0) {
|
||||
return DUMMY_SCANNER_INFO;
|
||||
}
|
||||
|
||||
LinkedHashSet<ICLanguageSettingEntry> includePathEntries = new LinkedHashSet<ICLanguageSettingEntry>();
|
||||
LinkedHashSet<ICLanguageSettingEntry> includePathLocalEntries = new LinkedHashSet<ICLanguageSettingEntry>();
|
||||
LinkedHashSet<ICLanguageSettingEntry> includeFileEntries = new LinkedHashSet<ICLanguageSettingEntry>();
|
||||
LinkedHashSet<ICLanguageSettingEntry> macroFileEntries = new LinkedHashSet<ICLanguageSettingEntry>();
|
||||
LinkedHashSet<ICLanguageSettingEntry> macroEntries = new LinkedHashSet<ICLanguageSettingEntry>();
|
||||
|
||||
for (String langId : languageIds) {
|
||||
List<ICLanguageSettingEntry> incSys = LanguageSettingsExtensionManager.getSystemSettingEntriesByKind(cfgDescription, rc, langId,
|
||||
ICSettingEntry.INCLUDE_PATH);
|
||||
includePathEntries.addAll(incSys);
|
||||
|
||||
List<ICLanguageSettingEntry> incLocal = LanguageSettingsExtensionManager.getLocalSettingEntriesByKind(cfgDescription, rc, langId,
|
||||
ICSettingEntry.INCLUDE_PATH);
|
||||
includePathLocalEntries.addAll(incLocal);
|
||||
|
||||
List<ICLanguageSettingEntry> incFiles = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId,
|
||||
ICSettingEntry.INCLUDE_FILE);
|
||||
includeFileEntries.addAll(incFiles);
|
||||
|
||||
List<ICLanguageSettingEntry> macroFiles = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId,
|
||||
ICSettingEntry.MACRO_FILE);
|
||||
macroFileEntries.addAll(macroFiles);
|
||||
|
||||
List<ICLanguageSettingEntry> macros = LanguageSettingsExtensionManager.getSettingEntriesByKind(cfgDescription, rc, langId,
|
||||
ICSettingEntry.MACRO);
|
||||
macroEntries.addAll(macros);
|
||||
}
|
||||
|
||||
String[] includePaths = convertToLocations(includePathEntries, cfgDescription);
|
||||
String[] includePathsLocal = convertToLocations(includePathLocalEntries, cfgDescription);
|
||||
String[] includeFiles = convertToLocations(includeFileEntries, cfgDescription);
|
||||
String[] macroFiles = convertToLocations(macroFileEntries, cfgDescription);
|
||||
|
||||
Map<String, String> definedMacros = new HashMap<String, String>();
|
||||
for (ICLanguageSettingEntry entry : macroEntries) {
|
||||
ICMacroEntry macroEntry = (ICMacroEntry)entry;
|
||||
String name = macroEntry.getName();
|
||||
String value = macroEntry.getValue();
|
||||
definedMacros.put(name, value);
|
||||
}
|
||||
|
||||
return new ExtendedScannerInfo(definedMacros, includePaths, macroFiles, includeFiles, includePathsLocal);
|
||||
}
|
||||
|
||||
private List<String> getLanguageIds(ICConfigurationDescription cfgDescription, IResource resource) {
|
||||
List<String> languageIds = null;
|
||||
if (resource instanceof IFile) {
|
||||
String langId = getLanguageIdForFile(cfgDescription, resource);
|
||||
if (langId!=null) {
|
||||
languageIds = new ArrayList<String>(1);
|
||||
languageIds.add(langId);
|
||||
}
|
||||
} else if (resource instanceof IContainer) { // IResource can be either IFile or IContainer
|
||||
languageIds = getLanguageIdsForFolder(cfgDescription, (IContainer) resource);
|
||||
}
|
||||
if (languageIds==null || languageIds.size()==0) {
|
||||
String msg = NLS.bind(SettingsModelMessages.getString("LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage"), resource.toString()); //$NON-NLS-1$
|
||||
CCorePlugin.log(new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, msg)));
|
||||
}
|
||||
return languageIds;
|
||||
}
|
||||
|
||||
private String getLanguageIdForFile(ICConfigurationDescription cfgDescription, IResource resource) {
|
||||
// For files using LanguageManager
|
||||
try {
|
||||
ILanguage language = LanguageManager.getInstance().getLanguageForFile((IFile) resource, cfgDescription);
|
||||
if (language!=null) {
|
||||
return language.getId();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> getLanguageIdsForFolder(ICConfigurationDescription cfgDescription, IContainer resource) {
|
||||
// Using MBS for folders. That will take language ID from input type of applicable tools in the toolchain.
|
||||
List<String> languageIds = new ArrayList<String>();
|
||||
|
||||
ICFolderDescription rcDes = null;
|
||||
ICLanguageSetting[] langSettings = null;
|
||||
if (resource.getType() == IResource.FOLDER) { // but not IResource.PROJECT
|
||||
IPath rcPath = resource.getProjectRelativePath();
|
||||
rcDes = (ICFolderDescription) cfgDescription.getResourceDescription(rcPath, false);
|
||||
langSettings = rcDes.getLanguageSettings();
|
||||
}
|
||||
if (langSettings==null || langSettings.length==0) {
|
||||
// not found or IResource.PROJECT
|
||||
ICFolderDescription rootDes = cfgDescription.getRootFolderDescription();
|
||||
langSettings = rootDes.getLanguageSettings();
|
||||
}
|
||||
|
||||
if (langSettings!=null) {
|
||||
for (ICLanguageSetting ls : langSettings) {
|
||||
String langId = ls.getLanguageId();
|
||||
if (langId!=null && !languageIds.contains(langId)) {
|
||||
languageIds.add(langId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return languageIds;
|
||||
}
|
||||
|
||||
private IPath expandVariables(IPath path, ICConfigurationDescription cfgDescription) {
|
||||
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
|
||||
String pathStr = path.toString();
|
||||
try {
|
||||
pathStr = varManager.resolveValue(pathStr, "", null, cfgDescription); //$NON-NLS-1$
|
||||
} catch (CdtVariableException e) {
|
||||
// Swallow exceptions but also log them
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
IPath resolvedLoc = new Path(pathStr);
|
||||
return resolvedLoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get build working directory for the provided configuration. Returns
|
||||
* project location if none defined.
|
||||
*/
|
||||
private static IPath getBuildCWD(ICConfigurationDescription cfgDescription) {
|
||||
IPath buildCWD = cfgDescription.getBuildSetting().getBuilderCWD();
|
||||
if (buildCWD==null) {
|
||||
IProject project = cfgDescription.getProjectDescription().getProject();
|
||||
buildCWD = project.getLocation();
|
||||
} else {
|
||||
ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager();
|
||||
try {
|
||||
// FIXME IPath buildCWD can hold variables i.e. ${workspace_loc:/path}
|
||||
String buildPathString = buildCWD.toString();
|
||||
buildPathString = mngr.resolveValue(buildPathString, "", null, cfgDescription);
|
||||
buildCWD = new Path(buildPathString);
|
||||
} catch (CdtVariableException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
|
||||
}
|
||||
buildCWD = buildCWD.addTrailingSeparator();
|
||||
return buildCWD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve location to file system location in a configuration context.
|
||||
* Resolving includes replacing build/environment variables with values, making relative path absolute etc.
|
||||
*
|
||||
* @param location - location to resolve. If relative, it is taken to be rooted in build working directory.
|
||||
* @param cfgDescription - the configuration context.
|
||||
* @return resolved file system location.
|
||||
*/
|
||||
private static String resolveEntry(String location, ICConfigurationDescription cfgDescription) {
|
||||
// Substitute build/environment variables
|
||||
ICdtVariableManager varManager = CCorePlugin.getDefault().getCdtVariableManager();
|
||||
try {
|
||||
location = varManager.resolveValue(location, "", null, cfgDescription); //$NON-NLS-1$
|
||||
} catch (CdtVariableException e) {
|
||||
// Swallow exceptions but also log them
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
// use OS file separators (i.e. '\' on Windows)
|
||||
if (java.io.File.separatorChar != '/') {
|
||||
location = location.replace('/', java.io.File.separatorChar);
|
||||
}
|
||||
|
||||
// note that we avoid using org.eclipse.core.runtime.Path for manipulations being careful
|
||||
// to preserve "../" segments and not let collapsing them which is not correct for symbolic links.
|
||||
Path locPath = new Path(location);
|
||||
if (locPath.isAbsolute() && locPath.getDevice()==null) {
|
||||
// prepend device (C:) for Windows
|
||||
IPath buildCWD = getBuildCWD(cfgDescription);
|
||||
String device = buildCWD.getDevice();
|
||||
if (device!=null)
|
||||
location = device + location;
|
||||
}
|
||||
if (!locPath.isAbsolute()) {
|
||||
// consider relative path to be from build working directory
|
||||
IPath buildCWD = getBuildCWD(cfgDescription);
|
||||
location = buildCWD.toOSString() + locPath;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the path entries to absolute file system locations represented as String array.
|
||||
* Resolve the entries which are not resolved.
|
||||
*
|
||||
* @param entriesPath - language settings path entries.
|
||||
* @param cfgDescription - configuration description for resolving entries.
|
||||
* @return array of the locations.
|
||||
*/
|
||||
private String[] convertToLocations(LinkedHashSet<ICLanguageSettingEntry> entriesPath, ICConfigurationDescription cfgDescription){
|
||||
List<String> locations = new ArrayList<String>(entriesPath.size());
|
||||
for (ICLanguageSettingEntry entry : entriesPath) {
|
||||
ACPathEntry entryPath = (ACPathEntry)entry;
|
||||
if (entryPath.isValueWorkspacePath()) {
|
||||
IPath loc = entryPath.getLocation();
|
||||
if (loc!=null) {
|
||||
if (checkBit(entryPath.getFlags(), ICSettingEntry.FRAMEWORKS_MAC)) {
|
||||
locations.add(loc.append("/__framework__.framework/Headers/__header__").toOSString());
|
||||
locations.add(loc.append("/__framework__.framework/PrivateHeaders/__header__").toOSString());
|
||||
} else {
|
||||
locations.add(loc.toOSString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String locStr = entryPath.getName();
|
||||
if (entryPath.isResolved()) {
|
||||
locations.add(locStr);
|
||||
} else {
|
||||
locStr = resolveEntry(locStr, cfgDescription);
|
||||
if (locStr!=null) {
|
||||
if (checkBit(entryPath.getFlags(), ICSettingEntry.FRAMEWORKS_MAC)) {
|
||||
locations.add(locStr+"/__framework__.framework/Headers/__header__");
|
||||
locations.add(locStr+"/__framework__.framework/PrivateHeaders/__header__");
|
||||
} else {
|
||||
locations.add(locStr);
|
||||
// add relative paths again for indexer to resolve from source file location
|
||||
IPath unresolvedPath = entryPath.getLocation();
|
||||
if (!unresolvedPath.isAbsolute()) {
|
||||
IPath expandedPath = expandVariables(unresolvedPath, cfgDescription);
|
||||
if (!expandedPath.isAbsolute()) {
|
||||
locations.add(expandedPath.toOSString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return locations.toArray(new String[locations.size()]);
|
||||
}
|
||||
|
||||
private static boolean checkBit(int flags, int bit) {
|
||||
return (flags & bit) == bit;
|
||||
}
|
||||
|
||||
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
// Handled by ScannerInfoProviderProxy for the moment
|
||||
}
|
||||
|
||||
public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
// Handled by ScannerInfoProviderProxy for the moment
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.CConfigurationStatus;
|
||||
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
||||
|
@ -765,4 +766,22 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC
|
|||
CConfigurationStatus status = data.getStatus();
|
||||
return status != null ? status : CConfigurationStatus.CFG_STATUS_OK;
|
||||
}
|
||||
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
try {
|
||||
CConfigurationSpecSettings specSettings = getSpecSettings();
|
||||
specSettings.setLanguageSettingProviders(providers);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
try {
|
||||
return getSpecSettings().getLanguageSettingProviders();
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.CConfigurationStatus;
|
||||
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
||||
|
@ -53,6 +54,28 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
|
||||
/**
|
||||
* CConfigurationDescriptionCache is a proxy class for serialization of configuration description data.
|
||||
*
|
||||
* An inspection of the scenario where user changes project properties and saves it yields
|
||||
* following sequence of events:
|
||||
* - Initialization:
|
||||
* - After eclipse started a project is being opened. A new CConfigurationDescriptionCache is created
|
||||
* with CConfigurationDescriptionCache(ICStorageElement storage, CProjectDescription parent) constructor.
|
||||
* - Any clients needed ICConfigurationDescription get CConfigurationDescription using constructor
|
||||
* CConfigurationDescription(CConfigurationData data, String buildSystemId, ICDataProxyContainer cr)
|
||||
* where the CConfigurationDescriptionCache is passed as data. The reference to cache is kept in field fCfgCache.
|
||||
* - fCfgCache is used to getSpecSettings() CConfigurationSpecSettings, after that fCfgCache is set to null.
|
||||
* - User enters project properties/settings:
|
||||
* - another CConfigurationDescription (settings configuration) created using the same constructor setting fCfgCache
|
||||
* to the CConfigurationDescriptionCache.
|
||||
* - User changes settings (in the settings configuration CConfigurationDescription) and saves it:
|
||||
* - new CConfigurationDescriptionCache is created from the CConfigurationDescription via constructor
|
||||
* CConfigurationDescriptionCache(ICConfigurationDescription baseDescription, ...) where
|
||||
* baseDescription is saved as fBaseDescription.
|
||||
* - CConfigurationDescriptionCache.applyData(...) is used to persist the data. at that point
|
||||
* reference fBaseDescription gets set to null.
|
||||
*/
|
||||
public class CConfigurationDescriptionCache extends CDefaultConfigurationData
|
||||
implements ICConfigurationDescription, IInternalCCfgInfo, ICachedData {
|
||||
private CProjectDescription fParent;
|
||||
|
@ -535,4 +558,15 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
|
|||
return status != null ? status : CConfigurationStatus.CFG_STATUS_OK;
|
||||
}
|
||||
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
// FIXME? - not sure
|
||||
// if(!fInitializing)
|
||||
// throw ExceptionFactory.createIsReadOnlyException();
|
||||
|
||||
fSpecSettings.setLanguageSettingProviders(providers);
|
||||
}
|
||||
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
return fSpecSettings.getLanguageSettingProviders();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,15 +11,19 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.settings.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
||||
|
@ -37,9 +41,11 @@ import org.eclipse.cdt.internal.core.COwner;
|
|||
import org.eclipse.cdt.internal.core.COwnerConfiguration;
|
||||
import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables;
|
||||
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.utils.envvar.StorableEnvironment;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* CConfigurationSpecSettings impelements ICSettingsStorage
|
||||
|
@ -87,6 +93,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
// private CConfigBasedDescriptor fDescriptor;
|
||||
// private Map fExternalSettingsProviderMap;
|
||||
|
||||
private List<ILanguageSettingsProvider> fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(0);
|
||||
|
||||
private class DeltaSet {
|
||||
public Set<ICConfigExtensionReference> extSet;
|
||||
public Set<String> idSet;
|
||||
|
@ -179,6 +187,8 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
fOwner = base.fOwner;
|
||||
|
||||
copyExtensionInfo(base);
|
||||
|
||||
fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(base.getLanguageSettingProviders());
|
||||
}
|
||||
|
||||
// private void copyRefInfos(Map infosMap){
|
||||
|
@ -971,4 +981,34 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
public void updateExternalSettingsProviders(String[] ids){
|
||||
ExtensionContainerFactory.updateReferencedProviderIds(fCfg, ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds list of {@link ILanguageSettingsProvider} to the specs.
|
||||
* Note that only unique IDs are accepted.
|
||||
*
|
||||
* @param providers - list of providers to keep in the specs.
|
||||
*/
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
fLanguageSettingsProviders.clear();
|
||||
Set<String> ids = new HashSet<String>();
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
String id = provider.getId();
|
||||
if (provider==LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(id)) {
|
||||
String msg = "Error: Attempt to add to the configuration raw global provider " + id;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
if (!ids.contains(id)) {
|
||||
fLanguageSettingsProviders.add(provider);
|
||||
ids.add(id);
|
||||
} else {
|
||||
String msg = NLS.bind(SettingsModelMessages.getString("CConfigurationSpecSettings.MustHaveUniqueID"), id); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
fIsModified = true;
|
||||
}
|
||||
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
return Collections.unmodifiableList(fLanguageSettingsProviders);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
|
|||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
|
@ -74,6 +75,9 @@ public class DescriptionScannerInfoProvider implements IScannerInfoProvider, ICP
|
|||
}
|
||||
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
// AG FIXME
|
||||
LanguageSettingsLogger.logScannerInfoProvider(resource, this);
|
||||
|
||||
if(!fInited)
|
||||
updateProjCfgInfo(CProjectDescriptionManager.getInstance().getProjectDescription(fProject, false));
|
||||
|
||||
|
|
|
@ -14,9 +14,11 @@ package org.eclipse.cdt.internal.core.settings.model;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
|
||||
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
|
||||
import org.eclipse.cdt.core.settings.model.CConfigurationStatus;
|
||||
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
|
||||
|
@ -581,4 +583,15 @@ public class MultiConfigDescription extends MultiItemsHolder implements
|
|||
fCfgs[i].removeStorage(id);
|
||||
}
|
||||
|
||||
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
|
||||
if (DEBUG)
|
||||
System.out.println("Bad multi access: MultiConfigDescription.setLanguageSettingProviders()"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public List<ILanguageSettingsProvider> getLanguageSettingProviders() {
|
||||
if (DEBUG)
|
||||
System.out.println("Bad multi access: MultiConfigDescription.getLanguageSettingProviders()"); //$NON-NLS-1$
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,13 +16,19 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
||||
/**
|
||||
* TODO fProvider is going to be deprecated in favor of {@link LanguageSettingsScannerInfoProvider}.
|
||||
*
|
||||
*/
|
||||
public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements IScannerInfoProvider, IScannerInfoChangeListener{
|
||||
private Map<IProject, List<IScannerInfoChangeListener>> listeners;
|
||||
private IScannerInfoProvider fProvider;
|
||||
|
@ -33,6 +39,11 @@ public class ScannerInfoProviderProxy extends AbstractCExtensionProxy implements
|
|||
}
|
||||
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
if (LanguageSettingsManager.isLanguageSettingsProvidersEnabled(getProject())) {
|
||||
LanguageSettingsScannerInfoProvider lsProvider = new LanguageSettingsScannerInfoProvider();
|
||||
return lsProvider.getScannerInformation(resource);
|
||||
}
|
||||
// Legacy logic
|
||||
providerRequested();
|
||||
return fProvider.getScannerInformation(resource);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,9 @@ CConfigurationDescription.0=data was not created
|
|||
CConfigurationDescription.1=expected proxy of type ICFileDescription, but was
|
||||
CConfigurationDescription.2=data was not created
|
||||
CConfigurationDescription.3=expected proxy of type ICFolderDescription, but was
|
||||
CConfigurationStatus.1=configurations settings invalid
|
||||
CConfigurationDescriptionCache.0=description is read only
|
||||
CConfigurationSpecSettings.MustHaveUniqueID=Language Settings Providers must have unique ID. Duplicate ID={0}
|
||||
CConfigurationStatus.1=configurations settings invalid
|
||||
CProjectConverterDesciptor.0=illegal provider implementation
|
||||
CProjectConverterDesciptor.1=no provider defined
|
||||
CProjectDescriptionManager.1=required build system is not installed
|
||||
|
@ -49,5 +50,8 @@ CExternalSettingsManager.3=writable ref info is requested for the read only conf
|
|||
CfgExportSettingContainerFactory.2=invalid id: project name not specified
|
||||
ExtensionContainerFactory.4=invalid setting provider class specified
|
||||
ExtensionContainerFactory.5=provider element not specified
|
||||
LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce=LanguageSettingsBaseProvider can be configured only once
|
||||
LanguageSettingsScannerInfoProvider.UnableToDetermineLanguage=Error getting ScannerInfo: Unable to determine language for resource {0}
|
||||
SettingsContext.0=no project associated with the context
|
||||
SettingsContext.1=can not accept the not-context project description
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import javax.xml.transform.dom.DOMSource;
|
|||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager_TBD;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingsStorage;
|
||||
|
@ -42,6 +43,7 @@ import org.eclipse.cdt.core.settings.model.extension.ICProjectConverter;
|
|||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.internal.core.envvar.ContributedEnvironment;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.settings.model.AbstractCProjectDescriptionStorage;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescription;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
|
@ -170,6 +172,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
|||
serializingLock.acquire();
|
||||
projectModificaitonStamp = serialize(fDes.getProject(), ICProjectDescriptionStorageType.STORAGE_FILE_NAME, fElement);
|
||||
((ContributedEnvironment) CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment()).serialize(fDes);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(fDes);
|
||||
} finally {
|
||||
serializingLock.release();
|
||||
Job.getJobManager().removeJobChangeListener(notifyJobCanceller);
|
||||
|
@ -481,6 +484,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
|||
// Update the modification stamp
|
||||
projectModificaitonStamp = getModificationStamp(project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME));
|
||||
CProjectDescription des = new CProjectDescription(project, new XmlStorage(storage), storage, true, false);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(des);
|
||||
try {
|
||||
setThreadLocalProjectDesc(des);
|
||||
des.loadDatas();
|
||||
|
|
|
@ -26,6 +26,7 @@ ErrorParser.name=Error Parser
|
|||
BinaryParser.name=Binary Parser
|
||||
PathEntryStore.name=Path Entry Store
|
||||
ScannerInfoProvider.name=Scanner Information Provider
|
||||
LanguageSettingsProvider.name=Language Settings Provider
|
||||
CIndexer.name= C/C++ Indexer
|
||||
language.name= CDT Language
|
||||
|
||||
|
|
|
@ -638,8 +638,9 @@
|
|||
<extension-point id="templateProcessTypes" name="%templateProcessTypes.name" schema="schema/templateProcessTypes.exsd"/>
|
||||
<extension-point id="templateAssociations" name="%templateAssociations.name" schema="schema/templateAssociations.exsd"/>
|
||||
<extension-point id="ScannerInfoProvider2" name="%scannerInfoProvider2.name" schema="schema/ScannerInfoProvider2.exsd"/>
|
||||
<extension-point id="EFSExtensionProvider" name="%efsExtensionProvider.name" schema="schema/EFSExtensionProvider.exsd"/>
|
||||
<extension-point id="RefreshExclusionFactory" name="%refreshExclusionFactory.name" schema="schema/RefreshExclusionFactory.exsd"/>
|
||||
<extension-point id="EFSExtensionProvider" name="EFSExtensionProvider" schema="schema/EFSExtensionProvider.exsd"/>
|
||||
<extension-point id="LanguageSettingsProvider" name="%LanguageSettingsProvider.name" schema="schema/LanguageSettingsProvider.exsd"/>
|
||||
<extension-point id="RefreshExclusionFactory" name="Refresh Exclusion Factory" schema="schema/RefreshExclusionFactory.exsd"/>
|
||||
<extension-point id="UNCPathConverter" name="%uncPathConverter.name" schema="schema/UNCPathConverter.exsd"/>
|
||||
|
||||
<extension
|
||||
|
@ -750,5 +751,12 @@
|
|||
factoryClass="org.eclipse.cdt.internal.core.resources.ResourceExclusionFactory">
|
||||
</exclusionFactory>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.core.EFSExtensionProvider">
|
||||
<EFSExtensionProvider
|
||||
class="org.eclipse.cdt.internal.core.resources.CygwinEFSExtensionProvider"
|
||||
scheme="cygwin">
|
||||
</EFSExtensionProvider>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
264
core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd
Normal file
264
core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd
Normal file
|
@ -0,0 +1,264 @@
|
|||
<?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="LanguageSettingsProvider" name="LanguageSettingsProvider"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
This extension point is used to contribute a new Language Settings Provider. A Language Settings Provider is used to get additions to compiler options such as include paths (-I) or preprocessor defines (-D) and others into the project model.
|
||||
</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>
|
||||
ID of the extension point, not used
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Name of the extension point, not used
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="provider">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The definition of a language settings provider.
|
||||
</documentation>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element ref="language-scope" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</sequence>
|
||||
<attribute name="class" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
A fully qualified name of the Java class that implements <samp>org.eclipse.cdt.core.settings.model.ILanguageSettingsProvider</samp> interface. If empty, <samp>org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider</samp> is used by default which provides basic functionality defined by this extension point.
|
||||
If there is a need to configure a provider, attribute parameter could be used in a class extending <samp>LanguageSettingsBaseProvider</samp>.
|
||||
</documentation>
|
||||
<appInfo>
|
||||
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider:org.eclipse.cdt.core.settings.model.ILanguageSettingsProvider"/>
|
||||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="id" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Unique ID of the provider
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Name of the provider. This name will be presented to a user in UI.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="parameter" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
A custom parameter to initialize provider. Used to deliver command for GCCBuiltinSpecsDetector as an example.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="language-scope">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The definition of language scope. Includes the list of language ID this provider is applicable to. If a language scope is not present, the provider will provide for any language.
|
||||
</documentation>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<attribute name="id" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
ID of the language for which this provider provides the entries. As an example, those are languages contributed by CDT (see extension org.eclipse.cdt.core.language):
|
||||
<p>- "<samp>org.eclipse.cdt.core.gcc</samp>" for C,</p>
|
||||
<p>- "<samp>org.eclipse.cdt.core.g++</samp>" for C++.</p>
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="entry">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The Language Settings Entries used to provide additions to compiler options such as include paths (-I) or preprocessor defines (-D) and others into the project model.
|
||||
</documentation>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element ref="flag" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</sequence>
|
||||
<attribute name="kind" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Kind of language settings entry which maps to compiler options. For example, following mapping is used for gcc options:
|
||||
|
||||
<br><samp>"-I"</samp> : includePath
|
||||
<br>"<samp>-D</samp>" : macro
|
||||
<br>"<samp>-include</samp>" : includeFile
|
||||
<br>"<samp>-L</samp>" : libraryPath
|
||||
<br>"<samp>-l</samp>" : libraryFile
|
||||
<br>"<samp>-imacros</samp>" : macroFile
|
||||
</documentation>
|
||||
</annotation>
|
||||
<simpleType>
|
||||
<restriction base="string">
|
||||
<enumeration value="includePath">
|
||||
</enumeration>
|
||||
<enumeration value="macro">
|
||||
</enumeration>
|
||||
<enumeration value="includeFile">
|
||||
</enumeration>
|
||||
<enumeration value="libraryPath">
|
||||
</enumeration>
|
||||
<enumeration value="libraryFile">
|
||||
</enumeration>
|
||||
<enumeration value="macroFile">
|
||||
</enumeration>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
</attribute>
|
||||
<attribute name="name" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
"name" attribute maps to path for the entries representing a path to a folder or file and to name for <samp>macro</samp> kind representing name-value pair. For example:
|
||||
<br>"<samp>/usr/include/</samp>"
|
||||
<br>"<samp>MACRO</samp>" (for <samp>#define MACRO value</samp>)
|
||||
<br>Note that relative paths are treated as rooted in build working directory (when applicable).
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="value" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
"value" attribute is used for <samp>macro</samp> kind representing name-value pair only. It is not used for the entries representing a path. For example:
|
||||
<br>"<samp>value</samp>" (for <samp>#define MACRO value</samp>)
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="flag">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Combination of flags for the entry.
|
||||
</documentation>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<attribute name="value" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
A value of the flag. Corresponds to <samp>ICSettingEntry</samp> flags, see JavaDoc there for more details. Here is an excerpt from the Javadoc for the flags intended to be used with this extension point (the others might be not supported):
|
||||
<br>- <samp>BUILTIN</samp> : Indicates settings built in a tool (compiler) itself. That kind of settings are not passed as options to a compiler but indexer or other clients might need them.
|
||||
<br>- <samp>LOCAL</samp> : Applicable for <samp>includePath</samp> only which could be local (#include "...") or system (#include <...>). If an <samp>includePath</samp> is not marked as <samp>LOCAL</samp> it is treated as system.
|
||||
<br>- <samp>RESOLVED</samp> : Indicates that the entries do not need to be resolved such as expansion of environment variables, normalizing the path against build working directory etc.
|
||||
<br>- <samp>VALUE_WORKSPACE_PATH</samp> : is used to indicate that the entry is a resource managed by eclipse in the workspace. The path is rooted in the workspace root.
|
||||
<br>- <samp>UNDEFINED</samp> : indicates that the entry should not be defined, corresponds to <samp>-U</samp> option of gcc compiler. If this flag is defined it will negate entries with the same name (and kind) for all providers down the list.
|
||||
</documentation>
|
||||
</annotation>
|
||||
<simpleType>
|
||||
<restriction base="string">
|
||||
<enumeration value="BUILTIN">
|
||||
</enumeration>
|
||||
<enumeration value="LOCAL">
|
||||
</enumeration>
|
||||
<enumeration value="RESOLVED">
|
||||
</enumeration>
|
||||
<enumeration value="VALUE_WORKSPACE_PATH">
|
||||
</enumeration>
|
||||
<enumeration value="UNDEFINED">
|
||||
</enumeration>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="since"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
CDT 9.0
|
||||
</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>
|
||||
Plug-ins that want to extend this extension point must implement <samp>org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider</samp> interface.
|
||||
<br/>
|
||||
For those cases where contributed settings entries (representing the compiler options) are not changed dynamically it is sufficient to configure existing class LanguageSettingsBaseProvider which is provided by default.
|
||||
<br/>
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="implementation"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
[Enter information about supplied implementation of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appInfo>
|
||||
<meta.section type="copyright"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) 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
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
</schema>
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue