Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-02-04 05:12:35 -0500
committerAnton Leherbauer2008-02-04 05:12:35 -0500
commit7ad140069cdc90718d9f9966f4e507a7d0407075 (patch)
tree2483cb73aa4f22aed36c445c97eea1fcd8ddc826
parent5a7960446ccc9980b3a749983c97e037a53e9009 (diff)
downloadorg.eclipse.cdt-7ad140069cdc90718d9f9966f4e507a7d0407075.tar.gz
org.eclipse.cdt-7ad140069cdc90718d9f9966f4e507a7d0407075.tar.xz
org.eclipse.cdt-7ad140069cdc90718d9f9966f4e507a7d0407075.zip
Fix for 216945: GCCPerFileBOPConsoleParser doesn't handle symbolic links correctly
-rw-r--r--build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCPerFileBOPConsoleParserTests.java29
-rw-r--r--build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/TestScannerInfoCollector.java23
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java50
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java40
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java35
5 files changed, 96 insertions, 81 deletions
diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCPerFileBOPConsoleParserTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCPerFileBOPConsoleParserTests.java
index 3e22eb4677..376ad9cf43 100644
--- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCPerFileBOPConsoleParserTests.java
+++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/GCCPerFileBOPConsoleParserTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 Wind River Systems, 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
@@ -7,9 +7,11 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.scannerdiscovery;
+import java.io.File;
import java.util.List;
import junit.framework.TestSuite;
@@ -21,8 +23,11 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCPerFileBOPConsoleParser;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
+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.Path;
public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
private final static IMarkerGenerator MARKER_GENERATOR= new IMarkerGenerator() {
@@ -68,4 +73,26 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
CCommandDSC command= (CCommandDSC) cmds.get(0);
assertEquals("gcc", command.getCompilerName());
}
+
+ public void testResolvingLinkedResourceArgument_Bug216945() throws Exception {
+ File tempRoot= new File(System.getProperty("java.io.tmpdir"));
+ File tempDir= new File(tempRoot, "cdttest_216945");
+ tempDir.mkdir();
+ File tempFile= null;
+ try {
+ tempFile= new File(tempDir, "test.c");
+ tempFile.createNewFile();
+ IFolder linkedFolder= fCProject.getProject().getFolder("cdttest");
+ linkedFolder.createLink(new Path(tempDir.toString()), IResource.ALLOW_MISSING_LOCAL, null);
+ fOutputParser.processLine("gcc -g -O0 -c \""+ tempFile.toString() + "\""); //$NON-NLS-1$
+ IFile file= linkedFolder.getFile("test.c");
+ List cmds = fCollector.getCollectedScannerInfo(file, ScannerInfoTypes.COMPILER_COMMAND);
+ assertEquals(1, cmds.size());
+ } finally {
+ if (tempFile != null) {
+ tempFile.delete();
+ }
+ tempDir.delete();
+ }
+ }
}
diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/TestScannerInfoCollector.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/TestScannerInfoCollector.java
index 8721db531b..b4350ac62d 100644
--- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/TestScannerInfoCollector.java
+++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/TestScannerInfoCollector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 Wind River Systems, 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.scannerdiscovery;
@@ -24,7 +25,8 @@ import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
final class TestScannerInfoCollector implements IScannerInfoCollector {
private HashMap fInfoMap = new HashMap();
-
+ private HashMap fResourceToInfoMap = new HashMap();
+
public void contributeToScannerConfig(Object resource, Map scannerInfo) {
for (Iterator iterator = scannerInfo.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
@@ -41,6 +43,9 @@ final class TestScannerInfoCollector implements IScannerInfoCollector {
}
}
}
+ if (resource != null) {
+ fResourceToInfoMap.put(resource, scannerInfo);
+ }
}
private void addTo(ScannerInfoTypes type, List col) {
@@ -53,7 +58,15 @@ final class TestScannerInfoCollector implements IScannerInfoCollector {
}
public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) {
- List result= (List) fInfoMap.get(type);
- return result == null ? Collections.EMPTY_LIST : result;
+ if (resource == null) {
+ List result= (List) fInfoMap.get(type);
+ return result == null ? Collections.EMPTY_LIST : result;
+ }
+ Map scannerInfo= (Map)fResourceToInfoMap.get(resource);
+ if (scannerInfo != null) {
+ List result= (List) scannerInfo.get(type);
+ return result == null ? Collections.EMPTY_LIST : result;
+ }
+ return Collections.EMPTY_LIST;
}
-} \ No newline at end of file
+}
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 d82ac0f1ab..66d1bb2513 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * 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
@@ -10,6 +10,7 @@
* Tianchao Li (tianchao.li@gmail.com) - arbitrary build directory (bug #136136)
* Gerhard Schaber (Wind River Systems) - bug 187910
* Markus Schorn (Wind River Systems)
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.gnu;
@@ -27,6 +28,7 @@ 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;
@@ -116,22 +118,9 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
}
}
- CCommandDSC cmd = fUtil.getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
- IPath baseDirectory = fUtil.getBaseDirectory();
- boolean isValidPath = baseDirectory.isPrefixOf(pFilePath);
- if (!isValidPath) {
- final IProject prj= fUtil.getProject();
- IFile[] foundOccurrences = ((IWorkspaceRoot) prj.getParent()).findFilesForLocation(pFilePath);
- for (int j=0; !isValidPath && j<foundOccurrences.length; j++) {
- isValidPath= prj.equals(foundOccurrences[j].getProject());
- }
- }
- if (isValidPath) {
- List cmdList = new ArrayList();
- cmdList.add(cmd);
- Map sc = new HashMap(1);
- sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
-
+ IFile file= null;
+ IPath baseDirectory= fUtil.getBaseDirectory();
+ if (baseDirectory.isPrefixOf(pFilePath)) {
IPath relPath = pFilePath.removeFirstSegments(baseDirectory.segmentCount());
//Note: We add the scanner-config even if the resource doesn't actually
//exist below this project (which may happen when reading existing
@@ -139,15 +128,28 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
//and may not exist at the time of analyzing the config but re-built
//later on.
//if (getProject().exists(relPath)) {
- IFile file = getProject().getFile(relPath);
- getCollector().contributeToScannerConfig(file, sc);
+ file = getProject().getFile(relPath);
} else {
- //TODO limiting to paths below this project means not being
- //able to work with linked resources. Linked resources could
- //be checked through IWorkspaceRoot.findFilesForLocation().
- TraceUtil.outputError("Build command for file outside project: "+pFilePath.toString(), tokens); //$NON-NLS-1$
+ // 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;
+ }
+ }
}
- // fUtil.addGenericCommandForFile2(longFileName, genericLine);
+ if (file != null) {
+ CCommandDSC cmd = fUtil.getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
+ List cmdList = new ArrayList();
+ cmdList.add(cmd);
+ Map sc = new HashMap(1);
+ sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
+ getCollector().contributeToScannerConfig(file, sc);
+ } else
+ TraceUtil.outputError("Build command for file outside project: "+pFilePath.toString(), tokens); //$NON-NLS-1$
}
return true;
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java
index fa405a8022..848131d172 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * 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
@@ -231,35 +231,33 @@ public class PerFileSICollector implements IScannerInfoCollector3, IScannerInfoC
addScannerInfo(((Integer)resource), scannerInfo);
return;
}
-// GSA allow per project settings
-// else if (!(resource instanceof IFile)) {
-// errorMessage = "resource is not an IFile";//$NON-NLS-1$
-// }
+ else if (!(resource instanceof IFile)) {
+ errorMessage = "resource is not an IFile";//$NON-NLS-1$
+ }
else if (((IFile) resource).getProject() == null) {
errorMessage = "project is null";//$NON-NLS-1$
}
- else if (((IFile) resource).getProject() != project) {
+ else if (!((IFile) resource).getProject().equals(project)) {
errorMessage = "wrong project";//$NON-NLS-1$
}
if (errorMessage != null) {
TraceUtil.outputError("PerFileSICollector.contributeToScannerConfig : ", errorMessage); //$NON-NLS-1$
return;
}
- if (resource instanceof IFile) {
- IFile file = (IFile) resource;
-
- for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext(); ) {
- ScannerInfoTypes type = (ScannerInfoTypes) i.next();
- if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
- List commands = (List) scannerInfo.get(type);
- for (Iterator j = commands.iterator(); j.hasNext(); ) {
- addCompilerCommand(file, (CCommandDSC) j.next());
- }
- }
- else {
- addScannerInfo(type, (List) scannerInfo.get(type));
- }
- }
+
+ IFile file = (IFile) resource;
+
+ for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext(); ) {
+ ScannerInfoTypes type = (ScannerInfoTypes) i.next();
+ if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
+ List commands = (List) scannerInfo.get(type);
+ for (Iterator j = commands.iterator(); j.hasNext(); ) {
+ addCompilerCommand(file, (CCommandDSC) j.next());
+ }
+ }
+ else {
+ addScannerInfo(type, (List) scannerInfo.get(type));
+ }
}
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java
index 9fe2e29601..2927e2dce2 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerProjectSICollector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig2;
@@ -50,7 +51,7 @@ import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
import org.w3c.dom.Element;
/**
@@ -107,7 +108,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
else if (((IResource) resource).getProject() == null) {
errorMessage = "project is null";//$NON-NLS-1$
}
- else if (((IResource) resource).getProject() != project) {
+ else if (!((IResource) resource).getProject().equals(project)) {
errorMessage = "wrong project";//$NON-NLS-1$
}
if (errorMessage != null) {
@@ -289,32 +290,6 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
return addedIncludes;
}
- /*
- * translated to raw map
- */
- private Map translateDiscoveredIncludes(List list){
- int baseSize = list.size();
- LinkedHashMap map = new LinkedHashMap(baseSize);
- List translated = CygpathTranslator.translateIncludePaths(project, list);
- if(baseSize == translated.size()){
- for(int i = 0; i < baseSize; i++){
- map.put(translated.get(i), list.get(i));
- }
- } else {
- List tmpList = new ArrayList(1);
- for(int i = 0; i < baseSize; i++){
- String basePath = (String)list.get(i);
- tmpList.add(0, basePath);
- List tr = CygpathTranslator.translateIncludePaths(project, tmpList);
- if(tr.size() != 0){
- String translatedPath = (String)tr.get(0);
- map.put(translatedPath, basePath);
- }
- }
- }
- return map;
- }
-
/**
* Compare symbol definitions with already discovered.
*
@@ -507,7 +482,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
}
}
};
- Platform.run(runnable);
+ SafeRunner.run(runnable);
}
private static void createDiscoveredPathContainer(IProject project, IProgressMonitor monitor) throws CModelException {

Back to the top