1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-08 02:53:12 +02:00

[264715] - added more error parser (applied patch)

This commit is contained in:
Alena Laskavaia 2009-02-17 18:54:36 +00:00
parent 976b300b70
commit fbb7101ddc
3 changed files with 1319 additions and 0 deletions

View file

@ -0,0 +1,953 @@
/*******************************************************************************
* 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.
*/
public class ErrorParserFileMatchingTest extends TestCase {
private final static String testName = "FindMatchingFilesTest";
// Default project gets created once then used by all test cases.
private final IProject fProject;
private final String mockErrorParserId;
private ArrayList<ProblemMarkerInfo> 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 ErrorParserFileMatchingTest(String name) {
super(name);
IProject project = null;
try {
project = ResourceHelper.createCDTProject(testName);
} catch (Exception e) {
Assert.fail(e.toString());
}
fProject = project;
Assert.assertNotNull(project);
mockErrorParserId = addErrorParserExtension("MockErrorParser", MockErrorParser.class);
}
@Override
protected void setUp() throws Exception {
errorList = new ArrayList<ProblemMarkerInfo>();
}
@Override
protected void tearDown() {
}
/**
* @return - new TestSuite.
*/
public static TestSuite suite() {
return new TestSuite(ErrorParserFileMatchingTest.class);
}
/**
* main function of the class.
*
* @param args - arguments
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
private static String addErrorParserExtension(String shortId, Class cl) {
String ext = "<plugin><extension id=\"" + shortId + "\" name=\"" + shortId
+ "\" point=\"org.eclipse.cdt.core.ErrorParser\">" + "<errorparser class=\"" + cl.getName() + "\"/>"
+ "</extension></plugin>";
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.createFile(fProject, "testSingle.c");
parseOutput("testSingle.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/testSingle.c",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("error",problemMarkerInfo.description);
}
/**
* Checks that no false positive for missing file generated.
* @throws Exception...
*/
public void testMissing() throws Exception {
parseOutput("testMissing.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("testMissing.c error",problemMarkerInfo.description);
}
/**
* Checks if duplicate files give ambiguous match.
* @throws Exception...
*/
public void testDuplicate() throws Exception {
ResourceHelper.createFolder(fProject, "FolderA");
ResourceHelper.createFile(fProject, "FolderA/testDuplicate.c");
ResourceHelper.createFolder(fProject, "FolderB");
ResourceHelper.createFile(fProject, "FolderB/testDuplicate.c");
parseOutput("testDuplicate.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// Ambiguous match
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals("testDuplicate.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testInFolder() throws Exception {
ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Folder/testInFolder.c");
parseOutput("testInFolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/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.createFile(fProject, "testDuplicateInRoot.c");
ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "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/FindMatchingFilesTest/testDuplicateInRoot.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testLinkedFile() throws Exception {
ResourceHelper.createWorkspaceFolder("OutsideFolder");
IPath realFile = ResourceHelper.createWorkspaceFile("OutsideFolder/testLinkedFile.c");
ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createLinkedFile(fProject, "Folder/testLinkedFile.c", realFile);
parseOutput("testLinkedFile.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/Folder/testLinkedFile.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testDuplicateLinkedFile() throws Exception {
ResourceHelper.createWorkspaceFolder("OutsideFolderA");
ResourceHelper.createWorkspaceFolder("OutsideFolderB");
IPath fileA = ResourceHelper.createWorkspaceFile("OutsideFolderA/testDuplicateLinkedFile.c");
IPath fileB = ResourceHelper.createWorkspaceFile("OutsideFolderB/testDuplicateLinkedFile.c");
ResourceHelper.createFolder(fProject, "FolderA");
ResourceHelper.createLinkedFile(fProject, "FolderA/DuplicateLinkedFileA.c", fileA);
ResourceHelper.createFolder(fProject, "FolderB");
ResourceHelper.createLinkedFile(fProject, "FolderB/DuplicateLinkedFileB.c", fileB);
parseOutput("testDuplicateLinkedFile.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// Ambiguous match
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals("testDuplicateLinkedFile.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testInLinkedFolder() throws Exception {
IPath outsideFolder = ResourceHelper.createWorkspaceFolder("OutsideFolder");
ResourceHelper.createWorkspaceFile("OutsideFolder/testInLinkedFolder.c");
ResourceHelper.createLinkedFolder(fProject, "LinkedFolder", outsideFolder);
parseOutput("testInLinkedFolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/LinkedFolder/testInLinkedFolder.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testDuplicateInLinkedFolder() throws Exception {
IPath folderA = ResourceHelper.createWorkspaceFolder("OutsideFolderA");
ResourceHelper.createWorkspaceFile("OutsideFolderA/testDuplicateInLinkedFolder.c");
IPath folderB = ResourceHelper.createWorkspaceFolder("OutsideFolderB");
ResourceHelper.createWorkspaceFile("OutsideFolderB/testDuplicateInLinkedFolder.c");
ResourceHelper.createLinkedFolder(fProject, "LinkedFolderA", folderA);
ResourceHelper.createLinkedFolder(fProject, "LinkedFolderB", folderB);
parseOutput("testDuplicateInLinkedFolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals("testDuplicateInLinkedFolder.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testLinkedFolderInAnotherProject() throws Exception {
ResourceHelper.createFolder(fProject,"Folder");
ResourceHelper.createFile(fProject,"Folder/testLinkedFolderInAnotherProject.c");
IProject anotherProject = ResourceHelper.createCDTProject("AnotherProjectWithLinkedFolder");
ResourceHelper.createLinkedFolder(anotherProject, "LinkedFolder", fProject.getLocation()+"/Folder");
{
parseOutput(fProject, "testLinkedFolderInAnotherProject.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/Folder/testLinkedFolderInAnotherProject.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
{
parseOutput(anotherProject, "testLinkedFolderInAnotherProject.c:1:error");
assertEquals(2, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(1);
assertEquals("L/AnotherProjectWithLinkedFolder/LinkedFolder/testLinkedFolderInAnotherProject.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testSymbolicLink() throws Exception {
ResourceHelper.createWorkspaceFolder("OutsideFolder");
IPath realFile = ResourceHelper.createWorkspaceFile("OutsideFolder/RealFile.c");
try {
ResourceHelper.createFolder(fProject,"Folder");
ResourceHelper.createSymbolicLink(fProject, "Folder/testSymbolicLink.c", realFile);
} catch (UnsupportedOperationException e) {
// Do not run the test on Windows system where links are not supported.
return;
}
parseOutput("testSymbolicLink.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/Folder/testSymbolicLink.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testDuplicateSymbolicLink() throws Exception {
ResourceHelper.createWorkspaceFolder("OutsideFolder");
IPath realFile = ResourceHelper.createWorkspaceFile("OutsideFolder/RealFile.c");
try {
ResourceHelper.createFolder(fProject,"FolderA");
ResourceHelper.createSymbolicLink(fProject, "FolderA/testDuplicateSymbolicLink.c", realFile);
ResourceHelper.createFolder(fProject,"FolderB");
ResourceHelper.createSymbolicLink(fProject, "FolderB/testDuplicateSymbolicLink.c", realFile);
} catch (UnsupportedOperationException e) {
// Do not run the test on Windows system where links are not supported.
return;
}
parseOutput("testDuplicateSymbolicLink.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals("testDuplicateSymbolicLink.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testFolderSymbolicLink() throws Exception {
IPath realFolder = ResourceHelper.createWorkspaceFolder("OutsideFolderForSymbolicLink");
ResourceHelper.createWorkspaceFile("OutsideFolderForSymbolicLink/testFolderSymbolicLink.c");
try {
ResourceHelper.createSymbolicLink(fProject, "FolderSymbolicLink", realFolder);
} catch (UnsupportedOperationException e) {
// Do not run the test on Windows system where links are not supported.
return;
}
parseOutput("testFolderSymbolicLink.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/FolderSymbolicLink/testFolderSymbolicLink.c",problemMarkerInfo.file.toString());
assertEquals("error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testDuplicateFolderSymbolicLink() throws Exception {
IPath realFolder = ResourceHelper.createWorkspaceFolder("OutsideFolder");
ResourceHelper.createWorkspaceFile("OutsideFolder/testDuplicateFolderSymbolicLink.c");
try {
ResourceHelper.createSymbolicLink(fProject, "FolderSymbolicLinkA", realFolder);
ResourceHelper.createSymbolicLink(fProject, "FolderSymbolicLinkB", realFolder);
} catch (UnsupportedOperationException e) {
// Do not run the test on Windows system where links are not supported.
return;
}
parseOutput("testDuplicateFolderSymbolicLink.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals("testDuplicateFolderSymbolicLink.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testAbsolutePathSingle() throws Exception {
ResourceHelper.createFile(fProject, "testAbsolutePathSingle.c");
String fullName = fProject.getLocation().append("testAbsolutePathSingle.c").toOSString();
parseOutput(fullName+":1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/testAbsolutePathSingle.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 testAbsolutePathInOtherProject() throws Exception {
IProject anotherProject = ResourceHelper.createCDTProject("ProjectAbsolutePathInOtherProject");
ResourceHelper.createFile(anotherProject, "testAbsolutePathInOtherProject.c");
String fullName = anotherProject.getLocation().append("testAbsolutePathInOtherProject.c").toOSString();
parseOutput(fullName+":1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/ProjectAbsolutePathInOtherProject/testAbsolutePathInOtherProject.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 testRelativePathFromProjectRoot() throws Exception {
ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Folder/testRelativePathFromProjectRoot.c");
parseOutput("Folder/testRelativePathFromProjectRoot.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/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.createFolder(fProject, "Subfolder");
ResourceHelper.createFolder(fProject, "Subfolder/Folder");
ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathFromSubfolder.c");
parseOutput("Folder/testRelativePathFromSubfolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/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.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathNotMatchingFolder.c");
parseOutput("NotMatchingFolder/testRelativePathNotMatchingFolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("NotMatchingFolder/testRelativePathNotMatchingFolder.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testRelativePathDuplicate() throws Exception {
ResourceHelper.createFolder(fProject, "SubfolderA");
ResourceHelper.createFolder(fProject, "SubfolderA/Folder");
ResourceHelper.createFile(fProject, "SubfolderA/Folder/testRelativePathDuplicate.c");
ResourceHelper.createFolder(fProject, "SubfolderB");
ResourceHelper.createFolder(fProject, "SubfolderB/Folder");
ResourceHelper.createFile(fProject, "SubfolderB/Folder/testRelativePathDuplicate.c");
parseOutput("Folder/testRelativePathDuplicate.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("Folder/testRelativePathDuplicate.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testRelativePathUp() throws Exception {
ResourceHelper.createFile(fProject, "testRelativePathUp.c");
parseOutput("../FindMatchingFilesTest/testRelativePathUp.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/testRelativePathUp.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 testRelativePathUpOtherProject() throws Exception {
IProject anotherProject = ResourceHelper.createCDTProject("AnotherProject");
ResourceHelper.createFile(anotherProject, "testRelativePathUpOtherProject.c");
parseOutput("../AnotherProject/testRelativePathUpOtherProject.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/AnotherProject/testRelativePathUpOtherProject.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 testRelativePathUpDuplicate() throws Exception {
ResourceHelper.createFolder(fProject, "FolderA/SubFolder");
ResourceHelper.createFolder(fProject, "FolderB/SubFolder");
ResourceHelper.createFile(fProject, "FolderA/SubFolder/testRelativePathUpDuplicate.c");
ResourceHelper.createFile(fProject, "FolderB/SubFolder/testRelativePathUpDuplicate.c");
parseOutput("../SubFolder/testRelativePathUpDuplicate.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("../SubFolder/testRelativePathUpDuplicate.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testRelativePathDotFromProjectRoot() throws Exception {
ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Folder/testRelativePathDotFromProjectRoot.c");
parseOutput("./Folder/testRelativePathDotFromProjectRoot.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/Folder/testRelativePathDotFromProjectRoot.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.createFolder(fProject, "Subfolder");
ResourceHelper.createFolder(fProject, "Subfolder/Folder");
ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathDotFromSubfolder.c");
parseOutput("./Folder/testRelativePathDotFromSubfolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/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 testRelativePathDotNotMatchingFolder() throws Exception {
ResourceHelper.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Subfolder/Folder/testRelativePathDotNotMatchingFolder.c");
parseOutput("./NotMatchingFolder/testRelativePathDotNotMatchingFolder.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("./NotMatchingFolder/testRelativePathDotNotMatchingFolder.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testRelativePathDotDuplicate() throws Exception {
ResourceHelper.createFolder(fProject, "SubfolderA");
ResourceHelper.createFolder(fProject, "SubfolderA/Folder");
ResourceHelper.createFile(fProject, "SubfolderA/Folder/testRelativePathDotDuplicate.c");
ResourceHelper.createFolder(fProject, "SubfolderB");
ResourceHelper.createFolder(fProject, "SubfolderB/Folder");
ResourceHelper.createFile(fProject, "SubfolderB/Folder/testRelativePathDotDuplicate.c");
parseOutput("./Folder/testRelativePathDotDuplicate.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("./Folder/testRelativePathDotDuplicate.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testUppercase1() throws Exception {
if (!Platform.getOS().equals(Platform.OS_WIN32)) {
// This test is valid on Windows platform only
return;
}
// Note that old MSDOS can handle only 8 characters in file name
ResourceHelper.createFile(fProject, "upcase1.c");
parseOutput("UPCASE1.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/upcase1.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 testUppercase3ResolveCase() throws Exception {
// Note that old MSDOS can handle only 8 characters in file name
ResourceHelper.createFolder(fProject, "FolderA");
ResourceHelper.createFolder(fProject, "FolderB");
ResourceHelper.createFile(fProject, "FolderA/UPCASE3.c");
ResourceHelper.createFile(fProject, "FolderB/UpCase3.c");
parseOutput("UpCase3.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/FolderB/UpCase3.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 testUppercase4Duplicate() throws Exception {
// Note that old MSDOS can handle only 8 characters in file name
ResourceHelper.createFolder(fProject, "FolderA");
ResourceHelper.createFolder(fProject, "FolderB");
ResourceHelper.createFile(fProject, "FolderA/UPCASE4.c");
ResourceHelper.createFile(fProject, "FolderB/upcase4.c");
parseOutput("UpCase4.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
// No match found
assertEquals("P/FindMatchingFilesTest",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("UpCase4.c error",problemMarkerInfo.description);
}
/**
* Checks if a file from error output can be found.
* @throws Exception...
*/
public void testCygwinCygdrive() throws Exception {
String fileName = "testCygwinCygdrive.c";
String windowsFileName = fProject.getLocation().append(fileName).toOSString();
String cygwinFileName;
try {
cygwinFileName = ResourceHelper.windowsToCygwinPath(windowsFileName);
} catch (UnsupportedOperationException e) {
// Skip the test if Cygwin is not available.
return;
}
assertTrue("cygwinFileName=["+cygwinFileName+"]", cygwinFileName.startsWith("/cygdrive/"));
ResourceHelper.createFile(fProject, fileName);
parseOutput(cygwinFileName+":1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/"+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 testCygwinUsrUnclude() throws Exception {
String cygwinFolder = "/usr/include/";
String fileName = "stdio.h";
String usrIncludeWindowsPath;
try {
usrIncludeWindowsPath = ResourceHelper.cygwinToWindowsPath(cygwinFolder);
} catch (UnsupportedOperationException e) {
// Skip the test if Cygwin is not available.
return;
}
assertTrue("usrIncludeWindowsPath=["+usrIncludeWindowsPath+"]",
usrIncludeWindowsPath.charAt(1)==IPath.DEVICE_SEPARATOR);
ResourceHelper.createLinkedFolder(fProject, "include", usrIncludeWindowsPath);
parseOutput(cygwinFolder+fileName+":1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/include/"+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 testCygwinAnotherProject() throws Exception {
String fileName = "testCygwinAnotherProject.c";
IProject anotherProject = ResourceHelper.createCDTProject("AnotherProject");
String windowsFileName = anotherProject.getLocation().append(fileName).toOSString();
String cygwinFileName;
try {
cygwinFileName = ResourceHelper.windowsToCygwinPath(windowsFileName);
} catch (UnsupportedOperationException e) {
// Skip the test if Cygwin is not available.
return;
}
assertTrue("cygwinFileName=["+cygwinFileName+"]", cygwinFileName.startsWith("/cygdrive/"));
ResourceHelper.createFile(anotherProject, fileName);
parseOutput(cygwinFileName+":1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/AnotherProject/"+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 testCustomProjectLocation() throws Exception {
ResourceHelper.createWorkspaceFolder("Custom");
ResourceHelper.createWorkspaceFolder("Custom/ProjectLocation");
IProject anotherProject = ResourceHelper.createCDTProject("AnotherProject", "Custom/ProjectLocation");
ResourceHelper.createFolder(anotherProject, "Folder");
ResourceHelper.createFile(anotherProject, "Folder/testCustomProjectLocation.c");
parseOutput(anotherProject, "testCustomProjectLocation.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/AnotherProject/Folder/testCustomProjectLocation.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 testInNestedProject() throws Exception {
ResourceHelper.createFolder(fProject, "NestedProjectFolder");
IProject nestedProject = ResourceHelper.createCDTProject("NestedProject", "FindMatchingFilesTest/NestedProject");
ResourceHelper.createFolder(nestedProject, "Folder");
ResourceHelper.createFile(nestedProject, "Folder/testInNestedProject.c");
{
parseOutput(fProject, "testInNestedProject.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/NestedProject/Folder/testInNestedProject.c",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("error",problemMarkerInfo.description);
}
{
parseOutput(nestedProject, "testInNestedProject.c:1:error");
assertEquals(2, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(1);
assertEquals("L/NestedProject/Folder/testInNestedProject.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.createFolder(fProject, "Folder");
ResourceHelper.createFile(fProject, "Folder/testBuildDir.c");
ResourceHelper.createFolder(fProject, "BuildDir");
ResourceHelper.createFile(fProject, "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/FindMatchingFilesTest/BuildDir/testBuildDir.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 testBuildDirVsProjectRoot() throws Exception {
ResourceHelper.createFile(fProject, "testBuildDirVsProjectRoot.c");
ResourceHelper.createFolder(fProject, "BuildDir");
ResourceHelper.createFile(fProject, "BuildDir/testBuildDirVsProjectRoot.c");
String buildDir = fProject.getLocation().append("BuildDir").toOSString();
parseOutput(fProject, buildDir, "testBuildDirVsProjectRoot.c:1:error");
assertEquals(1, errorList.size());
ProblemMarkerInfo problemMarkerInfo = errorList.get(0);
assertEquals("L/FindMatchingFilesTest/BuildDir/testBuildDirVsProjectRoot.c",problemMarkerInfo.file.toString());
assertEquals(1,problemMarkerInfo.lineNumber);
assertEquals("error",problemMarkerInfo.description);
}
}

View file

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

View file

@ -0,0 +1,365 @@
/*******************************************************************************
* 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.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import junit.framework.Assert;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
/**
* This class contains utility methods for creating resources
* such as projects, files, folders etc. which are being used
* in test fixture of unit tests.
*
* Some classes with similar idea worth to look at:
* org.eclipse.core.filebuffers.tests.ResourceHelper,
* org.eclipse.cdt.ui.tests.text.ResourceHelper.
*
* @since 6.0
*/
public class ResourceHelper {
private final static IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
/**
* Creates CDT project in a specific location and opens it.
*
* @param projectName - project name.
* @param locationInWorkspace - location relative to workspace root.
* @return - new {@link IProject}.
* @throws CoreException - if the project can't be created.
* @throws OperationCanceledException...
*/
public static IProject createCDTProject(String projectName, String locationInWorkspace) throws OperationCanceledException, CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject(projectName);
IProjectDescription description = workspace.newProjectDescription(projectName);
if(locationInWorkspace != null) {
IPath absoluteLocation = root.getLocation().append(locationInWorkspace);
description.setLocation(absoluteLocation);
}
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.
*
* @param projectName - project name.
* @return - new {@link IProject}.
* @throws CoreException - if the project can't be created.
* @throws OperationCanceledException...
*/
public static IProject createCDTProject(String projectName) throws OperationCanceledException, CoreException {
return createCDTProject(projectName, null);
}
/**
* Creates a file with specified content.
*
* @param file - file name.
* @param contents - contents of the file.
* @return file handle.
* @throws CoreException - if the file can't be created.
*/
public static IFile createFile(IFile file, String contents) throws CoreException {
if (contents == null) {
contents= "";
}
InputStream inputStream = new ByteArrayInputStream(contents.getBytes());
file.create(inputStream, true, NULL_MONITOR);
return file;
}
/**
* Creates new file from project root with empty content. The filename
* can include relative path as a part of the name but the the path
* has to be present on disk.
*
* @param project - project where to create the file.
* @param name - filename.
* @return file handle.
* @throws CoreException if something goes wrong.
*/
public static IFile createFile(IProject project, String name) throws CoreException {
return createFile(project.getFile(name), null);
}
/**
* Creates new file from workspace root with empty content. The filename
* can include relative path as a part of the name but the the path
* has to be present on disk.
* @param name - filename.
* @return full path of the created file.
*
* @throws CoreException...
* @throws IOException...
*/
public static IPath createWorkspaceFile(String name) throws CoreException, IOException {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath fullPath = workspaceRoot.getLocation().append(name);
java.io.File file = new java.io.File(fullPath.toOSString());
if (!file.exists()) {
boolean result = file.createNewFile();
Assert.assertTrue(result);
}
Assert.assertTrue(file.exists());
return fullPath;
}
/**
* Creates new folder from project root. The folder name
* can include relative path as a part of the name but the the path
* has to be present on disk.
*
* @param project - project where to create the folder.
* @param name - folder name.
* @return folder handle.
* @throws CoreException if something goes wrong.
*/
public static IFolder createFolder(IProject project, String name) throws CoreException {
IFolder folder= project.getFolder(name);
if (!folder.exists()) {
folder.create(true, true, NULL_MONITOR);
}
return folder;
}
/**
* Creates new folder from workspace root. The folder name
* can include relative path as a part of the name but the the path
* has to be present on disk.
*
* @param name - folder name.
* @return full folder path.
* @throws IOException if something goes wrong.
*/
public static IPath createWorkspaceFolder(String name) throws IOException {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath fullPath = workspaceRoot.getLocation().append(name);
java.io.File folder = new java.io.File(fullPath.toOSString());
if (!folder.exists()) {
boolean result = folder.mkdirs();
Assert.assertTrue(result);
}
Assert.assertTrue(folder.exists());
return fullPath;
}
/**
* Creates new eclipse file-link from project root to file system file. The filename
* can include relative path as a part of the name but the the path
* has to be present on disk.
*
* @param project - project where to create the file.
* @param fileLink - filename of the link being created.
* @param realFile - file on the file system, the target of the link.
* @return file handle.
* @throws CoreException if something goes wrong.
*/
public static IFile createLinkedFile(IProject project, String fileLink, IPath realFile) throws CoreException {
IFile file = project.getFile(fileLink);
file.createLink(realFile, IResource.REPLACE, null);
Assert.assertTrue(file.exists());
return file;
}
/**
* Creates new eclipse file-link from project root to file system file. The filename
* can include relative path as a part of the name but the the path
* has to be present on disk.
*
* @param project - project where to create the file.
* @param fileLink - filename of the link being created.
* @param realFile - file on the file system, the target of the link.
* @return file handle.
* @throws CoreException if something goes wrong.
*/
public static IFile createLinkedFile(IProject project, String fileLink, String realFile) throws CoreException {
return createLinkedFile(project, fileLink, new Path(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
* has to be present on disk.
*
* @param project - project where to create the file.
* @param folderLink - name of the link being created.
* @param realFolder - folder on the file system, the target of the link.
* @return file handle.
* @throws CoreException if something goes wrong.
*/
public static IFolder createLinkedFolder(IProject project, String folderLink, IPath realFolder) throws CoreException {
IFolder folder = project.getFolder(folderLink);
folder.createLink(realFolder, IResource.REPLACE, null);
Assert.assertTrue(folder.exists());
return folder;
}
/**
* 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
* has to be present on disk.
*
* @param project - project where to create the file.
* @param folderLink - name of the link being created.
* @param realFolder - folder on the file system, the target of the link.
* @return file handle.
* @throws CoreException if something goes wrong.
*/
public static IFolder createLinkedFolder(IProject project, String folderLink, String realFolder) throws CoreException {
return createLinkedFolder(project, folderLink, new Path(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
* as a part of the name but the the path has to be present on disk.
*
* @param project - project where to create the file.
* @param linkName - name of the link being created.
* @param realPath - file or folder on the file system, the target of the link.
* @return file handle.
*
* @throws UnsupportedOperationException on Windows where links are not supported.
* @throws IOException...
* @throws CoreException...
*/
public static IResource createSymbolicLink(IProject project, String linkName, IPath realPath)
throws IOException, CoreException, UnsupportedOperationException {
if (Platform.getOS().equals(Platform.OS_WIN32)) {
throw new UnsupportedOperationException("Windows links .lnk are not supported.");
}
IPath linkedPath = project.getLocation().append(linkName);
String command = "ln -s " + realPath.toOSString() + ' ' + linkedPath.toOSString();
Process process = Runtime.getRuntime().exec(command);
try {
process.waitFor();
} catch (InterruptedException e) {
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
IResource resource = project.getFile(linkName);
if (!resource.exists()) {
resource = project.getFolder(linkName);
}
Assert.assertTrue(resource.exists());
return resource;
}
/**
* Creates new symbolic file system link from file or folder on project root
* to another file system file. The filename can include relative path
* as a part of the name but the the path has to be present on disk.
*
* @param project - project where to create the file.
* @param linkName - name of the link being created.
* @param realPath - file or folder on the file system, the target of the link.
* @return file handle.
*
* @throws UnsupportedOperationException on Windows where links are not supported.
* @throws IOException...
* @throws CoreException...
*/
public static IResource createSymbolicLink(IProject project, String linkName, String realPath)
throws IOException, CoreException, UnsupportedOperationException {
return createSymbolicLink(project, linkName, new Path(realPath));
}
/**
* Conversion from Windows path to Cygwin path.
*
* @param windowsPath - Windows path.
* @return Cygwin style converted path.
* @throws UnsupportedOperationException if Cygwin is unavailable.
* @throws IOException on IO problem.
*/
public static String windowsToCygwinPath(String windowsPath) throws IOException, UnsupportedOperationException {
if (!Platform.getOS().equals(Platform.OS_WIN32)) {
// Don't run this on non-windows platforms
throw new UnsupportedOperationException("Not a Windows system, Cygwin is unavailable.");
}
String[] args = {"cygpath", "-u", windowsPath};
Process cygpath = Runtime.getRuntime().exec(args);
BufferedReader stdout = new BufferedReader(new InputStreamReader(cygpath.getInputStream()));
String cygwinPath = stdout.readLine();
if (cygwinPath == null) {
throw new UnsupportedOperationException("Cygwin utility cygpath is not available.");
}
return cygwinPath.trim();
}
/**
* Conversion from Cygwin path to Windows path.
*
* @param cygwinPath - Cygwin path.
* @return Windows style converted path.
* @throws UnsupportedOperationException if Cygwin is unavailable.
* @throws IOException on IO problem.
*/
public static String cygwinToWindowsPath(String cygwinPath) throws IOException, UnsupportedOperationException {
if (!Platform.getOS().equals(Platform.OS_WIN32)) {
// Don't run this on non-windows platforms
throw new UnsupportedOperationException("Not a Windows system, Cygwin is unavailable.");
}
String[] args = {"cygpath", "-w", cygwinPath};
Process cygpath = Runtime.getRuntime().exec(args);
BufferedReader stdout = new BufferedReader(new InputStreamReader(cygpath.getInputStream()));
String windowsPath = stdout.readLine();
if (windowsPath == null) {
throw new UnsupportedOperationException("Cygwin utility cygpath is not available.");
}
return windowsPath.trim();
}
}