mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 271327 ErrorParserManager Fixes & Tests for tracking working directory.
- Vector of working directories now contains absolute wd location
This commit is contained in:
parent
a461f247eb
commit
f806e4b989
2 changed files with 124 additions and 11 deletions
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.errorparsers.ErrorPattern;
|
|||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.internal.registry.ExtensionRegistry;
|
||||
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;
|
||||
|
@ -1121,4 +1122,119 @@ public class ErrorParserFileMatchingTest extends TestCase {
|
|||
assertEquals("error",problemMarkerInfo.description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file from error output can be found.
|
||||
*
|
||||
* @throws Exception...
|
||||
*/
|
||||
public void testPushDirectory() throws Exception {
|
||||
String fileName = "testPushDirectory.c";
|
||||
ResourceHelper.createFolder(fProject, "Folder");
|
||||
ResourceHelper.createFile(fProject, fileName);
|
||||
ResourceHelper.createFile(fProject, "Folder/"+fileName);
|
||||
|
||||
String lines = "make[0]: Entering directory `Folder'\n"
|
||||
+ fileName+":1:error\n";
|
||||
|
||||
String[] errorParsers = {MAKE_ERRORPARSER_ID, mockErrorParserId };
|
||||
parseOutput(fProject, fProject.getLocation(), errorParsers, lines);
|
||||
assertEquals(1, errorList.size());
|
||||
|
||||
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
|
||||
assertEquals("L/FindMatchingFilesTest/Folder/"+fileName,problemMarkerInfo.file.toString());
|
||||
assertEquals(1,problemMarkerInfo.lineNumber);
|
||||
assertEquals("error",problemMarkerInfo.description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file from error output can be found.
|
||||
*
|
||||
* @throws Exception...
|
||||
*/
|
||||
public void testPushAbsoluteDirectory() throws Exception {
|
||||
String fileName = "testPushAbsoluteDirectory.c";
|
||||
IFolder folder = ResourceHelper.createFolder(fProject, "Folder");
|
||||
ResourceHelper.createFile(fProject, fileName);
|
||||
ResourceHelper.createFile(fProject, "Folder/"+fileName);
|
||||
|
||||
IPath absoluteDir = folder.getLocation();
|
||||
Assert.assertTrue(absoluteDir.isAbsolute());
|
||||
|
||||
String lines = "make[0]: Entering directory `" + absoluteDir + "'\n"
|
||||
+ fileName+":1:error\n";
|
||||
|
||||
String[] errorParsers = {MAKE_ERRORPARSER_ID, mockErrorParserId };
|
||||
parseOutput(fProject, fProject.getLocation(), errorParsers, lines);
|
||||
assertEquals(1, errorList.size());
|
||||
|
||||
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
|
||||
assertEquals("L/FindMatchingFilesTest/Folder/"+fileName,problemMarkerInfo.file.toString());
|
||||
assertEquals(1,problemMarkerInfo.lineNumber);
|
||||
assertEquals("error",problemMarkerInfo.description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file from error output can be found.
|
||||
*
|
||||
* @throws Exception...
|
||||
*/
|
||||
public void testPopDirectory() throws Exception {
|
||||
String fileName = "testPopDirectory.c";
|
||||
|
||||
ResourceHelper.createFolder(fProject, "Folder");
|
||||
ResourceHelper.createFolder(fProject, "Folder/SubFolder");
|
||||
|
||||
ResourceHelper.createFile(fProject, fileName);
|
||||
ResourceHelper.createFile(fProject, "Folder/"+fileName);
|
||||
ResourceHelper.createFile(fProject, "Folder/SubFolder/"+fileName);
|
||||
|
||||
String lines = "make[1]: Entering directory `Folder'\n"
|
||||
+ "make[2]: Entering directory `SubFolder'\n"
|
||||
+ "make[2]: Leaving directory `SubFolder'\n"
|
||||
+ fileName+":1:error\n";
|
||||
|
||||
String[] errorParsers = {MAKE_ERRORPARSER_ID, mockErrorParserId };
|
||||
parseOutput(fProject, fProject.getLocation(), errorParsers, lines);
|
||||
assertEquals(1, errorList.size());
|
||||
|
||||
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
|
||||
assertEquals("L/FindMatchingFilesTest/Folder/"+fileName,problemMarkerInfo.file.toString());
|
||||
assertEquals(1,problemMarkerInfo.lineNumber);
|
||||
assertEquals("error",problemMarkerInfo.description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file from error output can be found.
|
||||
*
|
||||
* @throws Exception...
|
||||
*/
|
||||
public void testPushDirectoryAndCache() throws Exception {
|
||||
String fileName = "testPushDirectoryCacheProblem.c";
|
||||
ResourceHelper.createFolder(fProject, "Folder");
|
||||
ResourceHelper.createFile(fProject, fileName);
|
||||
ResourceHelper.createFile(fProject, "Folder/"+fileName);
|
||||
|
||||
String lines = fileName+":1:error\n"
|
||||
+ "make[0]: Entering directory `Folder'\n"
|
||||
+ fileName+":1:error\n";
|
||||
|
||||
String[] errorParsers = {MAKE_ERRORPARSER_ID, mockErrorParserId };
|
||||
parseOutput(fProject, fProject.getLocation(), errorParsers, lines);
|
||||
assertEquals(2, errorList.size());
|
||||
|
||||
{
|
||||
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
|
||||
assertEquals("L/FindMatchingFilesTest/"+fileName,problemMarkerInfo.file.toString());
|
||||
assertEquals(1,problemMarkerInfo.lineNumber);
|
||||
assertEquals("error",problemMarkerInfo.description);
|
||||
}
|
||||
|
||||
{
|
||||
ProblemMarkerInfo problemMarkerInfo = errorList.get(1);
|
||||
assertEquals("L/FindMatchingFilesTest/Folder/"+fileName,problemMarkerInfo.file.toString());
|
||||
assertEquals(1,problemMarkerInfo.lineNumber);
|
||||
assertEquals("error",problemMarkerInfo.description);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ErrorParserManager extends OutputStream {
|
|||
private ArrayList<ProblemMarkerInfo> fErrors;
|
||||
|
||||
private Vector<IPath> fDirectoryStack;
|
||||
private IPath fBaseDirectory;
|
||||
private final IPath fBaseDirectory;
|
||||
|
||||
private String previousLine;
|
||||
private OutputStream outputStream;
|
||||
|
@ -65,6 +65,7 @@ public class ErrorParserManager extends OutputStream {
|
|||
private boolean hasErrors = false;
|
||||
|
||||
private String cachedFileName = null;
|
||||
private IPath cachedWorkingDirectory = null;
|
||||
private IFile cachedFile = null;
|
||||
|
||||
private static boolean isCygwin = true;
|
||||
|
@ -155,14 +156,10 @@ public class ErrorParserManager extends OutputStream {
|
|||
*/
|
||||
public void pushDirectory(IPath dir) {
|
||||
if (dir != null) {
|
||||
IPath pwd = null;
|
||||
if (fBaseDirectory.isPrefixOf(dir)) {
|
||||
int segments = fBaseDirectory.matchingFirstSegments(dir);
|
||||
pwd = dir.removeFirstSegments(segments);
|
||||
} else {
|
||||
pwd = dir;
|
||||
}
|
||||
fDirectoryStack.addElement(pwd);
|
||||
if (dir.isAbsolute())
|
||||
fDirectoryStack.addElement(dir);
|
||||
else
|
||||
fDirectoryStack.addElement(getWorkingDirectory().append(dir));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,7 +263,7 @@ public class ErrorParserManager extends OutputStream {
|
|||
* @return - file in the workspace or {@code null}.
|
||||
*/
|
||||
public IFile findFileName(String fileName) {
|
||||
if (fileName.equals(cachedFileName))
|
||||
if (fileName.equals(cachedFileName) && getWorkingDirectory().equals(cachedWorkingDirectory))
|
||||
return cachedFile;
|
||||
|
||||
IPath path = new Path(fileName);
|
||||
|
@ -290,6 +287,7 @@ public class ErrorParserManager extends OutputStream {
|
|||
}
|
||||
|
||||
cachedFileName = fileName;
|
||||
cachedWorkingDirectory = getWorkingDirectory();
|
||||
cachedFile = file;
|
||||
return file;
|
||||
}
|
||||
|
@ -430,7 +428,6 @@ public class ErrorParserManager extends OutputStream {
|
|||
if (nOpens > 0 && --nOpens == 0) {
|
||||
checkLine(true);
|
||||
fDirectoryStack.removeAllElements();
|
||||
fBaseDirectory = null;
|
||||
if (outputStream != null)
|
||||
outputStream.close();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue