1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 247838 EPM annotates compile errors on wrong resource. EPM simplified to use ResourceLookup; tests added.

This commit is contained in:
James Blackburn 2009-03-22 16:27:33 +00:00
parent 1865f3344e
commit 1ad3cb1493
4 changed files with 185 additions and 7 deletions

View file

@ -27,8 +27,10 @@ import org.eclipse.cdt.core.errorparsers.AbstractErrorParser;
import org.eclipse.cdt.core.errorparsers.ErrorPattern; 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.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.runtime.ContributorFactoryOSGi; import org.eclipse.core.runtime.ContributorFactoryOSGi;
import org.eclipse.core.runtime.IContributor; import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -285,6 +287,24 @@ 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 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. * Checks if a file from error output can be found.
* @throws Exception... * @throws Exception...
@ -310,6 +330,30 @@ public class ErrorParserFileMatchingTest extends TestCase {
assertEquals(new Path("testDuplicateLinkedFile.c"),problemMarkerInfo.externalPath); 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. * Checks if a file from error output can be found.
* @throws Exception... * @throws Exception...
@ -517,6 +561,28 @@ 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 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. * Checks if a file from error output can be found.
* @throws Exception... * @throws Exception...
@ -539,15 +605,15 @@ public class ErrorParserFileMatchingTest extends TestCase {
* @throws Exception... * @throws Exception...
*/ */
public void testRelativePathFromSubfolder() throws Exception { public void testRelativePathFromSubfolder() throws Exception {
ResourceHelper.createFolder(fProject, "Subfolder"); ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFolder(fProject, "Subfolder/Folder"); ResourceHelper.createFolder(fProject, "Folder/SubFolder");
ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathFromSubfolder.c"); ResourceHelper.createFile(fProject, "Folder/SubFolder/testRelativePathFromSubfolder.c");
parseOutput("Folder/testRelativePathFromSubfolder.c:1:error"); parseOutput("SubFolder/testRelativePathFromSubfolder.c:1:error");
assertEquals(1, errorList.size()); assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0); 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(1,problemMarkerInfo.lineNumber);
assertEquals("error",problemMarkerInfo.description); assertEquals("error",problemMarkerInfo.description);
} }
@ -558,7 +624,7 @@ public class ErrorParserFileMatchingTest extends TestCase {
*/ */
public void testRelativePathNotMatchingFolder() throws Exception { public void testRelativePathNotMatchingFolder() throws Exception {
ResourceHelper.createFolder(fProject, "Folder"); ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathNotMatchingFolder.c"); ResourceHelper.createFile(fProject, "Folder/testRelativePathNotMatchingFolder.c");
parseOutput("NotMatchingFolder/testRelativePathNotMatchingFolder.c:1:error"); parseOutput("NotMatchingFolder/testRelativePathNotMatchingFolder.c:1:error");
assertEquals(1, errorList.size()); assertEquals(1, errorList.size());
@ -967,4 +1033,24 @@ 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 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);
}
} }

View file

@ -25,6 +25,7 @@ public class ErrorParserTests {
suite.addTest(FileBasedErrorParserTests.suite()); suite.addTest(FileBasedErrorParserTests.suite());
suite.addTest(ErrorParserManagerTest.suite()); suite.addTest(ErrorParserManagerTest.suite());
suite.addTest(ErrorParserFileMatchingTest.suite()); suite.addTest(ErrorParserFileMatchingTest.suite());
suite.addTest(ErrorParserEfsFileMatchingTest.suite());
return suite; return suite;
} }

View file

@ -16,6 +16,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import junit.framework.Assert; import junit.framework.Assert;
@ -78,6 +80,30 @@ public class ResourceHelper {
return project; 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. * Creates a project in the workspace and opens it.
* *
@ -87,7 +113,7 @@ public class ResourceHelper {
* @throws OperationCanceledException... * @throws OperationCanceledException...
*/ */
public static IProject createCDTProject(String projectName) throws OperationCanceledException, CoreException { 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)); 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 * 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 * 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)); 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 * Creates new symbolic file system link from file or folder on project root
* to another file system file. The filename can include relative path * to another file system file. The filename can include relative path