Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorMarkus Schorn2008-10-02 11:36:51 +0000
committerMarkus Schorn2008-10-02 11:36:51 +0000
commit3e28b31ae14ac9b0df055fbf4ec7ddbcc5e43ec6 (patch)
treeb8796a652fc787963e734ce1cf4ad715ae53921f /build
parent4796a78346722d14c7523729e67b1f3be820d615 (diff)
downloadorg.eclipse.cdt-3e28b31ae14ac9b0df055fbf4ec7ddbcc5e43ec6.tar.gz
org.eclipse.cdt-3e28b31ae14ac9b0df055fbf4ec7ddbcc5e43ec6.tar.xz
org.eclipse.cdt-3e28b31ae14ac9b0df055fbf4ec7ddbcc5e43ec6.zip
Implementation to select resource for a location, bug 248419.
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java24
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java42
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java120
3 files changed, 82 insertions, 104 deletions
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java
index 66d1bb2513c..e5d2d30974b 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java
@@ -21,14 +21,13 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.IMarkerGenerator;
+import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
@@ -41,7 +40,7 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
private final static String[] FILE_EXTENSIONS = {
".c", ".cc", ".cpp", ".cxx", ".C", ".CC", ".CPP", ".CXX" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
};
- private final static List FILE_EXTENSIONS_LIST = Arrays.asList(FILE_EXTENSIONS);
+ private final static List<String> FILE_EXTENSIONS_LIST = Arrays.asList(FILE_EXTENSIONS);
private GCCPerFileBOPConsoleParserUtility fUtil;
@@ -57,14 +56,16 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser#getUtility()
*/
- protected AbstractGCCBOPConsoleParserUtility getUtility() {
+ @Override
+ protected AbstractGCCBOPConsoleParserUtility getUtility() {
return fUtil;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser#processSingleLine(java.lang.String)
*/
- protected boolean processCommand(String[] tokens) {
+ @Override
+ protected boolean processCommand(String[] tokens) {
// GCC C/C++ compiler invocation
int compilerInvocationIndex= findCompilerInvocation(tokens);
if (compilerInvocationIndex < 0) {
@@ -132,20 +133,13 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
} else {
// search linked resources
final IProject prj= fUtil.getProject();
- final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
- IFile[] foundOccurrences= root.findFilesForLocation(pFilePath);
- for (int j=0; j<foundOccurrences.length; j++) {
- if (prj.equals(foundOccurrences[j].getProject())) {
- file= foundOccurrences[j];
- break;
- }
- }
+ file= ResourceLookup.selectFileForLocation(pFilePath, prj);
}
if (file != null) {
CCommandDSC cmd = fUtil.getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
- List cmdList = new ArrayList();
+ List<CCommandDSC> cmdList = new ArrayList<CCommandDSC>();
cmdList.add(cmd);
- Map sc = new HashMap(1);
+ Map<ScannerInfoTypes, List<CCommandDSC>> sc = new HashMap<ScannerInfoTypes, List<CCommandDSC>>(1);
sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
getCollector().contributeToScannerConfig(file, sc);
} else
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java
index d19258c552b..16fc36bab81 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/ScannerInfoConsoleParserUtility.java
@@ -1,13 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 IBM Corporation 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:
- * IBM - Initial API and implementation
- * Tianchao Li (tianchao.li@gmail.com) - arbitrary build directory (bug #136136)
+ * IBM - Initial API and implementation
+ * Tianchao Li (tianchao.li@gmail.com) - arbitrary build directory (bug #136136)
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.gnu;
@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.IMarkerGenerator;
+import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.internal.core.MakeMessages;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
@@ -42,16 +43,16 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser
/*
* For tracking the location of files being compiled
*/
- private Map fFilesInProject;
- private List fCollectedFiles;
- private List fNameConflicts;
+ private Map<String, IFile> fFilesInProject;
+ private List<IResource> fCollectedFiles;
+ private List<String> fNameConflicts;
public ScannerInfoConsoleParserUtility(IProject project, IPath workingDirectory, IMarkerGenerator markerGenerator) {
super(project, workingDirectory, markerGenerator);
- fFilesInProject = new HashMap();
- fCollectedFiles = new ArrayList();
- fNameConflicts = new ArrayList();
+ fFilesInProject = new HashMap<String, IFile>();
+ fCollectedFiles = new ArrayList<IResource>();
+ fNameConflicts = new ArrayList<String>();
collectFiles(getProject(), fCollectedFiles);
@@ -135,7 +136,7 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser
*/
protected IFile findFileName(String fileName) {
IPath path = new Path(fileName);
- return (IFile) fFilesInProject.get(path.lastSegment());
+ return fFilesInProject.get(path.lastSegment());
}
protected IFile findFileInWorkspace(IPath path) {
@@ -145,22 +146,15 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser
file = root.getFileForLocation(path);
// It may be a link resource so we must check it also.
if (file == null) {
- IFile[] files = root.findFilesForLocation(path);
- for (int i = 0; i < files.length; i++) {
- if (files[i].getProject().equals(getProject())) {
- file = files[i];
- break;
- }
- }
+ file= ResourceLookup.selectFileForLocation(path, getProject());
}
-
} else {
file = getProject().getFile(path);
}
return file;
}
- protected void collectFiles(IContainer parent, List result) {
+ protected void collectFiles(IContainer parent, List<IResource> result) {
try {
IResource[] resources = parent.members();
for (int i = 0; i < resources.length; i++) {
@@ -181,10 +175,10 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser
return fNameConflicts.contains(path.lastSegment());
}
- public List translateRelativePaths(IFile file, String fileName, List includes) {
- List translatedIncludes = new ArrayList(includes.size());
- for (Iterator i = includes.iterator(); i.hasNext(); ) {
- String include = (String) i.next();
+ public List<String> translateRelativePaths(IFile file, String fileName, List<String> includes) {
+ List<String> translatedIncludes = new ArrayList<String>(includes.size());
+ for (Iterator<String> i = includes.iterator(); i.hasNext(); ) {
+ String include = i.next();
IPath includePath = new Path(include);
if (!includePath.isAbsolute() && !includePath.isUNC()) { // do not translate UNC paths
// First try the current working directory
@@ -205,7 +199,7 @@ public class ScannerInfoConsoleParserUtility extends AbstractGCCBOPConsoleParser
if (fileName.startsWith("..")) { //$NON-NLS-1$
// probably multiple choices for cwd, hopeless
final String error = MakeMessages.getString("ConsoleParser.Working_Directory_Error_Message"); //$NON-NLS-1$
- TraceUtil.outputError(error, fileName); //$NON-NLS-1$
+ TraceUtil.outputError(error, fileName);
generateMarker(file, -1, error, IMarkerGenerator.SEVERITY_WARNING, fileName);
break;
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java
index c31536e7fe4..6f2779d8bb0 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java
@@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -44,14 +45,14 @@ public class CCommandDSC {
private final static String KIND_ATTR = "kind"; //$NON-NLS-1$
private int commandId;
- private List compilerCommand; // members are KVStringPair objects
+ private List<KVStringPair> compilerCommand; // members are KVStringPair objects
private boolean discovered;
private boolean cppFileType; // C or C++ file type
private IProject project;
- private List symbols;
- private List includes;
- private List quoteIncludes;
+ private List<String> symbols;
+ private List<String> includes;
+ private List<String> quoteIncludes;
/**
* @param cppFileType2
@@ -61,13 +62,13 @@ public class CCommandDSC {
}
public CCommandDSC(boolean cppFileType, IProject project) {
- compilerCommand = new ArrayList();
+ compilerCommand = new ArrayList<KVStringPair>();
discovered = false;
this.cppFileType = cppFileType;
- symbols = new ArrayList();
- includes = new ArrayList();
- quoteIncludes = new ArrayList();
+ symbols = new ArrayList<String>();
+ includes = new ArrayList<String>();
+ quoteIncludes = new ArrayList<String>();
this.project = project;
}
@@ -84,7 +85,7 @@ public class CCommandDSC {
option.getKey().equals(SCDOptionsEnum.IQUOTE.toString())))
{
String value = option.getValue();
- value = (String)CygpathTranslator.translateIncludePaths(project, Collections.singletonList(value)).get(0);
+ value = CygpathTranslator.translateIncludePaths(project, Collections.singletonList(value)).get(0);
value = makeRelative(project, new Path(value)).toOSString();
option = new KVStringPair(option.getKey(), value);
}
@@ -110,10 +111,11 @@ public class CCommandDSC {
this.commandId = commandId;
}
+ @Override
public String toString() {
String commandAsString = new String();
- for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
- KVStringPair optionPair = (KVStringPair)i.next();
+ for (Iterator<KVStringPair> i = compilerCommand.iterator(); i.hasNext(); ) {
+ KVStringPair optionPair = i.next();
String value = optionPair.getValue();
commandAsString += optionPair.getKey() + SINGLE_SPACE +
value + SINGLE_SPACE;
@@ -132,8 +134,8 @@ public class CCommandDSC {
*/
public String getSCDRunnableCommand(boolean quoteIncludePaths, boolean quoteDefines) {
String commandAsString = new String();
- for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
- KVStringPair optionPair = (KVStringPair)i.next();
+ for (Iterator<KVStringPair> i = compilerCommand.iterator(); i.hasNext(); ) {
+ KVStringPair optionPair = i.next();
if (optionPair.getKey().equals(SCDOptionsEnum.COMMAND.toString())) {
commandAsString += optionPair.getValue() + SINGLE_SPACE;
}
@@ -172,8 +174,8 @@ public class CCommandDSC {
*/
public String getCompilerName() {
String compiler = new String();
- for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
- KVStringPair optionPair = (KVStringPair)i.next();
+ for (Iterator<KVStringPair> i = compilerCommand.iterator(); i.hasNext(); ) {
+ KVStringPair optionPair = i.next();
if (optionPair.getKey().equals(SCDOptionsEnum.COMMAND.toString())) {
compiler = optionPair.getValue();
break;
@@ -185,10 +187,10 @@ public class CCommandDSC {
/**
* @return list of strings
*/
- public List getImacrosFile() {
- List imacrosFiles = new ArrayList();
- for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
- KVStringPair optionPair = (KVStringPair)i.next();
+ public List<String> getImacrosFile() {
+ List<String> imacrosFiles = new ArrayList<String>();
+ for (Iterator<KVStringPair> i = compilerCommand.iterator(); i.hasNext(); ) {
+ KVStringPair optionPair = i.next();
if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString())) {
imacrosFiles.add(makeAbsolute(project,optionPair.getValue()));
}
@@ -199,10 +201,10 @@ public class CCommandDSC {
/**
* @return list of strings
*/
- public List getIncludeFile() {
- List includeFiles = new ArrayList();
- for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
- KVStringPair optionPair = (KVStringPair)i.next();
+ public List<String> getIncludeFile() {
+ List<String> includeFiles = new ArrayList<String>();
+ for (Iterator<KVStringPair> i = compilerCommand.iterator(); i.hasNext(); ) {
+ KVStringPair optionPair = i.next();
if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString())) {
includeFiles.add(makeAbsolute(project,optionPair.getValue()));
}
@@ -217,6 +219,7 @@ public class CCommandDSC {
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
+ @Override
public boolean equals(Object arg0) {
if (arg0 != null && arg0.getClass().equals(this.getClass())) {
CCommandDSC other = (CCommandDSC)arg0;
@@ -228,6 +231,7 @@ public class CCommandDSC {
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
+ @Override
public int hashCode() {
return compilerCommand.hashCode();
}
@@ -235,37 +239,37 @@ public class CCommandDSC {
/**
* @return Returns the includes as strings.
*/
- public List getIncludes() {
+ public List<String> getIncludes() {
return makeAbsolute(project, includes);
}
/**
* @param includes The includes to set.
*/
- public void setIncludes(List includes) {
+ public void setIncludes(List<String> includes) {
this.includes = includes;
}
/**
* @return Returns the quote include paths as strings (for #include "...")
*/
- public List getQuoteIncludes() {
+ public List<String> getQuoteIncludes() {
return makeAbsolute(project, quoteIncludes);
}
/**
* @param includes. Quote include paths (for #include "...")
*/
- public void setQuoteIncludes(List includes) {
+ public void setQuoteIncludes(List<String> includes) {
quoteIncludes = includes;
}
/**
* @return Returns the symbols.
*/
- public List getSymbols() {
+ public List<String> getSymbols() {
return symbols;
}
/**
* @param symbols The symbols to set.
*/
- public void setSymbols(List symbols) {
+ public void setSymbols(List<String> symbols) {
this.symbols = symbols;
}
/**
@@ -288,9 +292,9 @@ public class CCommandDSC {
Document doc = cmdElem.getOwnerDocument();
// serialize the command
Element cmdDescElem = doc.createElement(CMD_DESCRIPTION_ELEM);
- for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
+ for (Iterator<KVStringPair> i = compilerCommand.iterator(); i.hasNext(); ) {
Element optionElem = doc.createElement(OPTION_ELEM);
- KVStringPair option = (KVStringPair) i.next();
+ KVStringPair option = i.next();
optionElem.setAttribute(KEY_ATTR, option.getKey());
optionElem.setAttribute(VALUE_ATTR, option.getValue());
cmdDescElem.appendChild(optionElem);
@@ -298,23 +302,23 @@ public class CCommandDSC {
cmdElem.appendChild(cmdDescElem);
// serialize includes and symbols
Element siElem = doc.createElement(CMD_SI_ELEM);
- for (Iterator j = quoteIncludes.iterator(); j.hasNext(); ) {
+ for (Iterator<String> j = quoteIncludes.iterator(); j.hasNext(); ) {
Element siItem = doc.createElement(SI_ITEM_ELEM);
siItem.setAttribute(KIND_ATTR, "INCLUDE_PATH"); //$NON-NLS-1$
- siItem.setAttribute(VALUE_ATTR, (String) j.next());
+ siItem.setAttribute(VALUE_ATTR, j.next());
siItem.setAttribute(QUOTE_INCLUDE_ATTR, "true"); //$NON-NLS-1$
siElem.appendChild(siItem);
}
- for (Iterator j = includes.iterator(); j.hasNext(); ) {
+ for (Iterator<String> j = includes.iterator(); j.hasNext(); ) {
Element siItem = doc.createElement(SI_ITEM_ELEM);
siItem.setAttribute(KIND_ATTR, "INCLUDE_PATH"); //$NON-NLS-1$
- siItem.setAttribute(VALUE_ATTR, (String) j.next());
+ siItem.setAttribute(VALUE_ATTR, j.next());
siElem.appendChild(siItem);
}
- for (Iterator j = symbols.iterator(); j.hasNext(); ) {
+ for (Iterator<String> j = symbols.iterator(); j.hasNext(); ) {
Element siItem = doc.createElement(SI_ITEM_ELEM);
siItem.setAttribute(KIND_ATTR, "SYMBOL_DEFINITION"); //$NON-NLS-1$
- siItem.setAttribute(VALUE_ATTR, (String) j.next());
+ siItem.setAttribute(VALUE_ATTR, j.next());
siElem.appendChild(siItem);
}
cmdElem.appendChild(siElem);
@@ -366,11 +370,11 @@ public class CCommandDSC {
public void resolveOptions(IProject project) {
if (!isDiscovered()) {
// that's wrong for sure, options cannot be resolved fron the optionPairs??
- ArrayList symbols = new ArrayList();
- ArrayList includes = new ArrayList();
- ArrayList quoteincludes = new ArrayList();
- for (Iterator options = compilerCommand.iterator(); options.hasNext(); ) {
- KVStringPair optionPair = (KVStringPair)options.next();
+ ArrayList<String> symbols = new ArrayList<String>();
+ ArrayList<String> includes = new ArrayList<String>();
+ ArrayList<String> quoteincludes = new ArrayList<String>();
+ for (Iterator<KVStringPair> options = compilerCommand.iterator(); options.hasNext(); ) {
+ KVStringPair optionPair = options.next();
String key = optionPair.getKey();
String value = optionPair.getValue();
if (key.equals(SCDOptionsEnum.INCLUDE.toString()) || key.equals(SCDOptionsEnum.ISYSTEM.toString())) {
@@ -409,30 +413,16 @@ public class CCommandDSC {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
resource = root.findMember(path, false);
if (resource == null) {
- IResource[] resources = root.findFilesForLocation(path);
- if (project != null) {
- for (int i = 0; i < resources.length; i++) {
- final IProject myProject = resources[i].getProject();
- // resource could be root, then myProject is null.
- if (myProject != null && myProject.equals(project)) {
- resource = resources[i];
- break;
- }
- }
- }
- // make a relative path to another project (better than an absolute path)
- if (resource == null && resources.length > 0) {
- resource = resources[0];
- }
+ resource= ResourceLookup.selectFileForLocation(path, project);
}
}
return resource;
}
- public static List makeRelative(IProject project, List paths) {
- List list = new ArrayList(paths.size());
- for (Iterator iter=paths.iterator(); iter.hasNext(); ) {
- String path = (String)iter.next();
+ public static List<String> makeRelative(IProject project, List<String> paths) {
+ List<String> list = new ArrayList<String>(paths.size());
+ for (Iterator<String> iter=paths.iterator(); iter.hasNext(); ) {
+ String path = iter.next();
path = makeRelative(project, new Path(path)).toOSString();
list.add(path);
}
@@ -455,10 +445,10 @@ public class CCommandDSC {
return path;
}
- public static List makeAbsolute(IProject project, List paths) {
- List list = new ArrayList(paths.size());
- for (Iterator iter=paths.iterator(); iter.hasNext(); ) {
- String path = (String)iter.next();
+ public static List<String> makeAbsolute(IProject project, List<String> paths) {
+ List<String> list = new ArrayList<String>(paths.size());
+ for (Iterator<String> iter=paths.iterator(); iter.hasNext(); ) {
+ String path = iter.next();
path = makeAbsolute(project, path);
list.add(path);
}

Back to the top