1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +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:
James Blackburn 2009-04-13 10:39:01 +00:00
parent a461f247eb
commit f806e4b989
2 changed files with 124 additions and 11 deletions

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.errorparsers.ErrorPattern;
import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.core.internal.registry.ExtensionRegistry; import org.eclipse.core.internal.registry.ExtensionRegistry;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -1121,4 +1122,119 @@ public class ErrorParserFileMatchingTest extends TestCase {
assertEquals("error",problemMarkerInfo.description); 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);
}
}
} }

View file

@ -54,7 +54,7 @@ public class ErrorParserManager extends OutputStream {
private ArrayList<ProblemMarkerInfo> fErrors; private ArrayList<ProblemMarkerInfo> fErrors;
private Vector<IPath> fDirectoryStack; private Vector<IPath> fDirectoryStack;
private IPath fBaseDirectory; private final IPath fBaseDirectory;
private String previousLine; private String previousLine;
private OutputStream outputStream; private OutputStream outputStream;
@ -65,6 +65,7 @@ public class ErrorParserManager extends OutputStream {
private boolean hasErrors = false; private boolean hasErrors = false;
private String cachedFileName = null; private String cachedFileName = null;
private IPath cachedWorkingDirectory = null;
private IFile cachedFile = null; private IFile cachedFile = null;
private static boolean isCygwin = true; private static boolean isCygwin = true;
@ -155,14 +156,10 @@ public class ErrorParserManager extends OutputStream {
*/ */
public void pushDirectory(IPath dir) { public void pushDirectory(IPath dir) {
if (dir != null) { if (dir != null) {
IPath pwd = null; if (dir.isAbsolute())
if (fBaseDirectory.isPrefixOf(dir)) { fDirectoryStack.addElement(dir);
int segments = fBaseDirectory.matchingFirstSegments(dir); else
pwd = dir.removeFirstSegments(segments); fDirectoryStack.addElement(getWorkingDirectory().append(dir));
} else {
pwd = dir;
}
fDirectoryStack.addElement(pwd);
} }
} }
@ -266,7 +263,7 @@ public class ErrorParserManager extends OutputStream {
* @return - file in the workspace or {@code null}. * @return - file in the workspace or {@code null}.
*/ */
public IFile findFileName(String fileName) { public IFile findFileName(String fileName) {
if (fileName.equals(cachedFileName)) if (fileName.equals(cachedFileName) && getWorkingDirectory().equals(cachedWorkingDirectory))
return cachedFile; return cachedFile;
IPath path = new Path(fileName); IPath path = new Path(fileName);
@ -290,6 +287,7 @@ public class ErrorParserManager extends OutputStream {
} }
cachedFileName = fileName; cachedFileName = fileName;
cachedWorkingDirectory = getWorkingDirectory();
cachedFile = file; cachedFile = file;
return file; return file;
} }
@ -430,7 +428,6 @@ public class ErrorParserManager extends OutputStream {
if (nOpens > 0 && --nOpens == 0) { if (nOpens > 0 && --nOpens == 0) {
checkLine(true); checkLine(true);
fDirectoryStack.removeAllElements(); fDirectoryStack.removeAllElements();
fBaseDirectory = null;
if (outputStream != null) if (outputStream != null)
outputStream.close(); outputStream.close();
} }