From 1ad3cb149328c257e60a1910905615b48443a1fb Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Sun, 22 Mar 2009 16:27:33 +0000 Subject: [PATCH] Bug 247838 EPM annotates compile errors on wrong resource. EPM simplified to use ResourceLookup; tests added. --- .../tests/ErrorParserEfsFileMatchingTest.java | 1 + .../tests/ErrorParserFileMatchingTest.java | 98 +++++++++++++++++-- .../errorparsers/tests/ErrorParserTests.java | 1 + .../errorparsers/tests/ResourceHelper.java | 92 ++++++++++++++++- 4 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserEfsFileMatchingTest.java diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserEfsFileMatchingTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserEfsFileMatchingTest.java new file mode 100644 index 00000000000..0f548f86e4f --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserEfsFileMatchingTest.java @@ -0,0 +1 @@ +/******************************************************************************* * 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.internal.errorparsers.tests; import java.io.ByteArrayInputStream; import java.util.ArrayList; import junit.framework.Assert; import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.IErrorParser; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.ProblemMarkerInfo; import org.eclipse.cdt.core.errorparsers.AbstractErrorParser; 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.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.ContributorFactoryOSGi; import org.eclipse.core.runtime.IContributor; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; /** * The test case includes a few tests checking that {@link AbstractErrorParser}/{@link ErrorPattern} * properly locate and resolve filenames found in build output in case of EFS files/folders. */ public class ErrorParserEfsFileMatchingTest extends TestCase { private final static String testName = "FindMatchingFilesEfsTest"; // Default project gets created once then used by all test cases. private IProject fProject = null; private String mockErrorParserId = null; private ArrayList errorList; private final IMarkerGenerator markerGenerator = new IMarkerGenerator() { // deprecated public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {} public void addMarker(ProblemMarkerInfo problemMarkerInfo) { errorList.add(problemMarkerInfo); } }; /** * Simple error parser parsing line like "file:line:description" */ public static class MockErrorParser extends AbstractErrorParser { /** * Constructor to set the error pattern. */ public MockErrorParser() { super(new ErrorPattern[] { new ErrorPattern("(.*):(.*):(.*)", 1, 2, 3, 0, IMarkerGenerator.SEVERITY_ERROR_RESOURCE) }); } } /** * Constructor. * @param name - name of the test. */ public ErrorParserEfsFileMatchingTest(String name) { super(name); } @Override protected void setUp() throws Exception { if (fProject==null) { fProject = ResourceHelper.createCDTProject(testName); Assert.assertNotNull(fProject); mockErrorParserId = addErrorParserExtension("MockErrorParser", MockErrorParser.class); } errorList = new ArrayList(); } @Override protected void tearDown() { } /** * @return - new TestSuite. */ public static TestSuite suite() { return new TestSuite(ErrorParserEfsFileMatchingTest.class); } /** * main function of the class. * * @param args - arguments */ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } /** * Adds Error Parser extension to the global repository. * Note that this function will "pollute" the working environment and * the error parser will be seen by other test cases as well. * * @param shortId - last portion of ID with which error parser will be added. * @param cl - Error Parser class * @return - full ID of the error parser (generated by the method). */ private static String addErrorParserExtension(String shortId, Class cl) { String ext = "" + "" + ""; IContributor contributor = ContributorFactoryOSGi.createContributor(CTestPlugin.getDefault().getBundle()); boolean added = Platform.getExtensionRegistry().addContribution(new ByteArrayInputStream(ext.getBytes()), contributor, false, shortId, null, ((ExtensionRegistry) Platform.getExtensionRegistry()).getTemporaryUserToken()); assertTrue("failed to add extension", added); String fullId = "org.eclipse.cdt.core.tests." + shortId; IErrorParser[] errorParser = CCorePlugin.getDefault().getErrorParser(fullId); assertTrue(errorParser.length > 0); return fullId; } /** * Convenience method to let {@link ErrorParserManager} parse one line of output. * This method goes through the whole working cycle every time creating * new {@link ErrorParserManager}. * * @param project - for which project to parse output. * @param buildDir - location of build for {@link ErrorParserManager}. * @param line - one line of output. * @throws Exception */ private void parseOutput(IProject project, IPath buildDir, String line) throws Exception { ErrorParserManager epManager = new ErrorParserManager(project, buildDir, markerGenerator, new String[] { mockErrorParserId }); line = line + '\n'; epManager.write(line.getBytes(), 0, line.length()); epManager.close(); epManager.reportProblems(); } /** * Convenience method to parse one line of output. */ private void parseOutput(IProject project, String buildDir, String line) throws Exception { parseOutput(project, new Path(buildDir), line); } /** * Convenience method to parse one line of output. * Search is done in project location. */ private void parseOutput(IProject project, String line) throws Exception { parseOutput(project, project.getLocation(), line); } /** * Convenience method to parse one line of output. * Search is done for current project in default location. */ private void parseOutput(String line) throws Exception { parseOutput(fProject, fProject.getLocation(), line); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testSingle() throws Exception { ResourceHelper.createEfsFile(fProject, "testSingle.c", "null:/efsTestSingle.c"); parseOutput("efsTestSingle.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/testSingle.c",problemMarkerInfo.file.toString()); assertEquals("error",problemMarkerInfo.description); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testEfsVsRegular() throws Exception { ResourceHelper.createFile(fProject, "testEfsVsRegular.c"); ResourceHelper.createEfsFile(fProject, "efsTestEfsVsRegular.c", "null:/testEfsVsRegular.c"); parseOutput("testEfsVsRegular.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/testEfsVsRegular.c",problemMarkerInfo.file.toString()); assertEquals("error",problemMarkerInfo.description); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testFullPath() throws Exception { ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testFullPath.c", "null:/EfsFolder/efsTestFullPath.c"); parseOutput("EfsFolder/efsTestFullPath.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/Folder/testFullPath.c",problemMarkerInfo.file.toString()); assertEquals("error",problemMarkerInfo.description); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testInNonEfsFolder() throws Exception { ResourceHelper.createFolder(fProject, "NonEfsFolder"); ResourceHelper.createEfsFile(fProject, "NonEfsFolder/testInNonEfsFolder.c", "null:/EfsFolder/efsTestInNonEfsFolder.c"); parseOutput("efsTestInNonEfsFolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/NonEfsFolder/testInNonEfsFolder.c",problemMarkerInfo.file.toString()); assertEquals("error",problemMarkerInfo.description); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testInFolder() throws Exception { ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testInFolder.c", "null:/EfsFolder/efsTestInFolder.c"); parseOutput("efsTestInFolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/Folder/testInFolder.c",problemMarkerInfo.file.toString()); assertEquals("error",problemMarkerInfo.description); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testDuplicateInRoot() throws Exception { ResourceHelper.createEfsFile(fProject, "testDuplicateInRoot.c", "null:/testDuplicateInRoot.c"); ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testDuplicateInRoot.c", "null:/Folder/testDuplicateInRoot.c"); // Resolved to the file in root folder parseOutput("testDuplicateInRoot.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals(1,problemMarkerInfo.lineNumber); assertEquals("L/FindMatchingFilesEfsTest/testDuplicateInRoot.c",problemMarkerInfo.file.toString()); assertEquals("error",problemMarkerInfo.description); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testRelativePathFromProjectRoot() throws Exception { ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testRelativePathFromProjectRoot.c", "null:/EfsFolder/testRelativePathFromProjectRoot.c"); parseOutput("EfsFolder/testRelativePathFromProjectRoot.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/Folder/testRelativePathFromProjectRoot.c",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 testRelativePathFromSubfolder() throws Exception { ResourceHelper.createEfsFolder(fProject, "Subfolder", "null:/Subfolder"); ResourceHelper.createEfsFolder(fProject, "Subfolder/Folder", "null:/Subfolder/Folder"); ResourceHelper.createEfsFile(fProject, "Subfolder/Folder/testRelativePathFromSubfolder.c", "null:/Subfolder/Folder/testRelativePathFromSubfolder.c"); parseOutput("Folder/testRelativePathFromSubfolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/Subfolder/Folder/testRelativePathFromSubfolder.c",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 testRelativePathNotMatchingFolder() throws Exception { ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testRelativePathNotMatchingFolder.c", "null:/Folder/testRelativePathNotMatchingFolder.c"); parseOutput("NotMatchingFolder/testRelativePathNotMatchingFolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); // No match assertEquals("P/FindMatchingFilesEfsTest",problemMarkerInfo.file.toString()); assertEquals(1,problemMarkerInfo.lineNumber); assertEquals("error",problemMarkerInfo.description); assertEquals(new Path("NotMatchingFolder/testRelativePathNotMatchingFolder.c"),problemMarkerInfo.externalPath); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testRelativePathDuplicate() throws Exception { ResourceHelper.createEfsFolder(fProject, "SubfolderA", "null:/SubfolderA"); ResourceHelper.createEfsFolder(fProject, "SubfolderA/Folder", "null:/SubfolderA/Folder"); ResourceHelper.createEfsFile(fProject, "SubfolderA/Folder/testRelativePathDuplicate.c", "null:/SubfolderA/Folder/testRelativePathDuplicate.c"); ResourceHelper.createEfsFolder(fProject, "SubfolderB", "null:/SubfolderB"); ResourceHelper.createEfsFolder(fProject, "SubfolderB/Folder", "null:/SubfolderB/Folder"); ResourceHelper.createEfsFile(fProject, "SubfolderB/Folder/testRelativePathDuplicate.c", "null:/SubfolderBS/Folder/testRelativePathDuplicate.c"); parseOutput("Folder/testRelativePathDuplicate.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); // No match found assertEquals("P/FindMatchingFilesEfsTest",problemMarkerInfo.file.toString()); assertEquals(1,problemMarkerInfo.lineNumber); assertEquals("error",problemMarkerInfo.description); assertEquals(new Path("Folder/testRelativePathDuplicate.c"),problemMarkerInfo.externalPath); } /** * Checks if a file from error output can be found. * @throws Exception... */ public void testRelativePathUpSubfolder() throws Exception { ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testRelativePathUpSubfolder.c", "null:/Folder/testRelativePathUpSubfolder.c"); parseOutput("../Folder/testRelativePathUpSubfolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/Folder/testRelativePathUpSubfolder.c",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 testRelativePathDotFromSubfolder() throws Exception { ResourceHelper.createEfsFolder(fProject, "Subfolder", "null:/Subfolder"); ResourceHelper.createEfsFolder(fProject, "Subfolder/Folder", "null:/Subfolder/Folder"); ResourceHelper.createEfsFile(fProject, "Subfolder/Folder/testRelativePathDotFromSubfolder.c", "null:/Subfolder/Folder/testRelativePathDotFromSubfolder.c"); parseOutput("./Folder/testRelativePathDotFromSubfolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/Subfolder/Folder/testRelativePathDotFromSubfolder.c",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 testBuildDir() throws Exception { ResourceHelper.createEfsFolder(fProject, "Folder", "null:/Folder"); ResourceHelper.createEfsFile(fProject, "Folder/testBuildDir.c", "null:/Folder/testBuildDir.c"); ResourceHelper.createEfsFolder(fProject, "BuildDir", "null:/BuildDir"); ResourceHelper.createEfsFile(fProject, "BuildDir/testBuildDir.c", "null:/BuildDir/testBuildDir.c"); String buildDir = fProject.getLocation().append("BuildDir").toOSString(); parseOutput(fProject, buildDir, "testBuildDir.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); assertEquals("L/FindMatchingFilesEfsTest/BuildDir/testBuildDir.c",problemMarkerInfo.file.toString()); assertEquals(1,problemMarkerInfo.lineNumber); assertEquals("error",problemMarkerInfo.description); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java index df1ef0fde53..c4b1e0737cd 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserFileMatchingTest.java @@ -27,8 +27,10 @@ import org.eclipse.cdt.core.errorparsers.AbstractErrorParser; 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.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.ContributorFactoryOSGi; import org.eclipse.core.runtime.IContributor; import org.eclipse.core.runtime.IPath; @@ -285,6 +287,24 @@ public class ErrorParserFileMatchingTest extends TestCase { assertEquals("error",problemMarkerInfo.description); } + /** + * Checks if a file from error output can be found. + * @throws Exception... + */ + public void testLinkedFileWithDifferentName() throws Exception { + ResourceHelper.createWorkspaceFolder("OutsideFolder"); + IPath realFile = ResourceHelper.createWorkspaceFile("OutsideFolder/RealFileWithDifferentName.c"); + ResourceHelper.createFolder(fProject, "Folder"); + ResourceHelper.createLinkedFile(fProject, "Folder/testLinkedFileWithDifferentName.c", realFile); + + parseOutput("RealFileWithDifferentName.c:1:error"); + assertEquals(1, errorList.size()); + + ProblemMarkerInfo problemMarkerInfo = errorList.get(0); + assertEquals("L/FindMatchingFilesTest/Folder/testLinkedFileWithDifferentName.c",problemMarkerInfo.file.toString()); + assertEquals("error",problemMarkerInfo.description); + } + /** * Checks if a file from error output can be found. * @throws Exception... @@ -310,6 +330,30 @@ public class ErrorParserFileMatchingTest extends TestCase { assertEquals(new Path("testDuplicateLinkedFile.c"),problemMarkerInfo.externalPath); } + /** + * Checks if a file from error output can be found. + * @throws Exception... + */ + public void testDuplicateLinkedFileDifferentName() throws Exception { + ResourceHelper.createWorkspaceFolder("OutsideFolderA"); + ResourceHelper.createWorkspaceFolder("OutsideFolderB"); + IPath fileA = ResourceHelper.createWorkspaceFile("OutsideFolderA/testDuplicateLinkedFileDifferentName.c"); + IPath fileB = ResourceHelper.createWorkspaceFile("OutsideFolderB/testDuplicateLinkedFileDifferentName.c"); + ResourceHelper.createFolder(fProject, "FolderA"); + ResourceHelper.createLinkedFile(fProject, "FolderA/DuplicateLinkedFileA.c", fileA); + ResourceHelper.createFolder(fProject, "FolderB"); + ResourceHelper.createLinkedFile(fProject, "FolderB/DuplicateLinkedFileB.c", fileB); + + parseOutput("testDuplicateLinkedFileDifferentName.c:1:error"); + assertEquals(1, errorList.size()); + + ProblemMarkerInfo problemMarkerInfo = errorList.get(0); + // No match found + assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString()); + assertEquals("error",problemMarkerInfo.description); + assertEquals(new Path("testDuplicateLinkedFileDifferentName.c"),problemMarkerInfo.externalPath); + } + /** * Checks if a file from error output can be found. * @throws Exception... @@ -517,6 +561,28 @@ public class ErrorParserFileMatchingTest extends TestCase { assertEquals("error",problemMarkerInfo.description); } + /** + * Checks if a file from error output can be found. + * @throws Exception... + */ + public void testAbsolutePathOutsideWorkspace() throws Exception { + + ResourceHelper.createWorkspaceFolder("OutsideFolder"); + IPath outsideFile = ResourceHelper.createWorkspaceFile("OutsideFolder/testAbsolutePathOutsideWorkspace.c"); + + String fullName = ResourcesPlugin.getWorkspace().getRoot().getLocation() + .append("OutsideFolder/testAbsolutePathOutsideWorkspace.c").toOSString(); + + parseOutput(fullName+":1:error"); + assertEquals(1, errorList.size()); + + ProblemMarkerInfo problemMarkerInfo = errorList.get(0); + // Can't assign marker to non-IResource + assertEquals(1,problemMarkerInfo.lineNumber); + assertEquals("error",problemMarkerInfo.description); + assertEquals(outsideFile, problemMarkerInfo.externalPath); + } + /** * Checks if a file from error output can be found. * @throws Exception... @@ -539,15 +605,15 @@ public class ErrorParserFileMatchingTest extends TestCase { * @throws Exception... */ public void testRelativePathFromSubfolder() throws Exception { - ResourceHelper.createFolder(fProject, "Subfolder"); - ResourceHelper.createFolder(fProject, "Subfolder/Folder"); - ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathFromSubfolder.c"); + ResourceHelper.createFolder(fProject, "Folder"); + ResourceHelper.createFolder(fProject, "Folder/SubFolder"); + ResourceHelper.createFile(fProject, "Folder/SubFolder/testRelativePathFromSubfolder.c"); - parseOutput("Folder/testRelativePathFromSubfolder.c:1:error"); + parseOutput("SubFolder/testRelativePathFromSubfolder.c:1:error"); assertEquals(1, errorList.size()); ProblemMarkerInfo problemMarkerInfo = errorList.get(0); - assertEquals("L/FindMatchingFilesTest/Subfolder/Folder/testRelativePathFromSubfolder.c",problemMarkerInfo.file.toString()); + assertEquals("L/FindMatchingFilesTest/Folder/SubFolder/testRelativePathFromSubfolder.c",problemMarkerInfo.file.toString()); assertEquals(1,problemMarkerInfo.lineNumber); assertEquals("error",problemMarkerInfo.description); } @@ -558,7 +624,7 @@ public class ErrorParserFileMatchingTest extends TestCase { */ public void testRelativePathNotMatchingFolder() throws Exception { ResourceHelper.createFolder(fProject, "Folder"); - ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathNotMatchingFolder.c"); + ResourceHelper.createFile(fProject, "Folder/testRelativePathNotMatchingFolder.c"); parseOutput("NotMatchingFolder/testRelativePathNotMatchingFolder.c:1:error"); assertEquals(1, errorList.size()); @@ -967,4 +1033,24 @@ public class ErrorParserFileMatchingTest extends TestCase { assertEquals("error",problemMarkerInfo.description); } + /** + * Checks if a file from error output can be found. + * + * @throws Exception... + */ + public void testAbsoluteFileVsLink() throws Exception { + ResourceHelper.createFolder(fProject, "Folder"); + IFile file = ResourceHelper.createFile(fProject, "Folder/testAbsoluteFileVsLink.c"); + String fullName = file.getLocation().toOSString(); + ResourceHelper.createLinkedFile(fProject, "testAbsoluteFileVsLink.c", file.getLocation()); + + parseOutput(fullName+":1:error"); + assertEquals(1, errorList.size()); + + ProblemMarkerInfo problemMarkerInfo = errorList.get(0); + assertEquals("L/FindMatchingFilesTest/Folder/testAbsoluteFileVsLink.c",problemMarkerInfo.file.toString()); + assertEquals(1,problemMarkerInfo.lineNumber); + assertEquals("error",problemMarkerInfo.description); + } + } diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserTests.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserTests.java index 7da4b07d477..50cc51a9a25 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserTests.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ErrorParserTests.java @@ -25,6 +25,7 @@ public class ErrorParserTests { suite.addTest(FileBasedErrorParserTests.suite()); suite.addTest(ErrorParserManagerTest.suite()); suite.addTest(ErrorParserFileMatchingTest.suite()); + suite.addTest(ErrorParserEfsFileMatchingTest.suite()); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ResourceHelper.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ResourceHelper.java index b6cc95d0bfa..922f7969486 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ResourceHelper.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/ResourceHelper.java @@ -16,6 +16,8 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; import junit.framework.Assert; @@ -78,6 +80,30 @@ public class ResourceHelper { return project; } + /** + * Creates CDT project in a specific location and opens it. + * + * @param projectName - project name. + * @param locationURI - location. + * @return - new {@link IProject}. + * @throws CoreException - if the project can't be created. + * @throws OperationCanceledException... + */ + public static IProject createCDTProject(String projectName, URI locationURI) throws OperationCanceledException, CoreException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + IProject project = root.getProject(projectName); + IProjectDescription description = workspace.newProjectDescription(projectName); + description.setLocationURI(locationURI); + project = CCorePlugin.getDefault().createCDTProject(description, project, NULL_MONITOR); + Assert.assertNotNull(project); + + project.open(null); + Assert.assertTrue(project.isOpen()); + + return project; + } + /** * Creates a project in the workspace and opens it. * @@ -87,7 +113,7 @@ public class ResourceHelper { * @throws OperationCanceledException... */ public static IProject createCDTProject(String projectName) throws OperationCanceledException, CoreException { - return createCDTProject(projectName, null); + return createCDTProject(projectName, (String)null); } /** @@ -219,6 +245,35 @@ public class ResourceHelper { return createLinkedFile(project, fileLink, new Path(realFile)); } + /** + * Creates new eclipse file-link from project root to EFS file. + * + * @param project - project where to create the file. + * @param fileLink - filename of the link being created. + * @param realFile - file on the EFS file system, the target of the link. + * @return file handle. + * @throws CoreException if something goes wrong. + */ + public static IFile createEfsFile(IProject project, String fileLink, URI realFile) throws CoreException { + IFile file= project.getFile(fileLink); + file.createLink(realFile, IResource.ALLOW_MISSING_LOCAL, new NullProgressMonitor()); + return file; + } + + /** + * Creates new eclipse file-link from project root to EFS file. + * + * @param project - project where to create the file. + * @param fileLink - filename of the link being created. + * @param realFile - file on the EFS file system, the target of the link. + * @return file handle. + * @throws CoreException if something goes wrong. + * @throws URISyntaxException if wrong URI syntax + */ + public static IFile createEfsFile(IProject project, String fileLink, String realFile) throws CoreException, URISyntaxException { + return createEfsFile(project,fileLink,new URI(realFile)); + } + /** * Creates new eclipse folder-link from project root to file system folder. The folder name * can include relative path as a part of the name but the the path @@ -253,6 +308,41 @@ public class ResourceHelper { return createLinkedFolder(project, folderLink, new Path(realFolder)); } + /** + * Creates new eclipse folder-link from project root to EFS folder. + * + * @param project - project where to create the folder. + * @param folderLink - folder name of the link being created. + * @param realFolder - folder on the EFS file system, the target of the link. + * @return folder handle. + * @throws CoreException if something goes wrong. + */ + public static IFolder createEfsFolder(IProject project, String folderLink, URI realFolder) throws CoreException { + IFolder folder= project.getFolder(folderLink); + if (folder.exists()) { + Assert.assertEquals("Folder with the same name but different location already exists", + realFolder, folder.getLocationURI()); + return folder; + } + + folder.createLink(realFolder, IResource.ALLOW_MISSING_LOCAL, new NullProgressMonitor()); + return folder; + } + + /** + * Creates new eclipse folder-link from project root to EFS folder. + * + * @param project - project where to create the folder. + * @param folderLink - folder name of the link being created. + * @param realFolder - folder on the EFS file system, the target of the link. + * @return folder handle. + * @throws CoreException if something goes wrong. + * @throws URISyntaxException if wrong URI syntax + */ + public static IFolder createEfsFolder(IProject project, String folderLink, String realFolder) throws CoreException, URISyntaxException { + return createEfsFolder(project,folderLink,new URI(realFolder)); + } + /** * Creates new symbolic file system link from file or folder on project root * to another file system file. The filename can include relative path