Made basedir property of Checker OS agnostic (663149)

This commit is contained in:
Oleg Sukhodolsky 2003-07-20 08:17:36 +00:00
parent dd477210ae
commit 57ea0b6a11
3 changed files with 50 additions and 1 deletions

View File

@ -124,6 +124,9 @@
<li class="body">Added filters for audit events (partially fulfills request 559103).
A SuppressionFilter denies events according to a suppressions file (request 756416).</li>
<li class="body">Made basedir property of Checker OS agnostic
(request 663149).</li>
</ul>
<p class="body">

View File

@ -36,6 +36,8 @@ import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
import org.apache.tools.ant.util.FileUtils;
/**
* This class provides the functionality to check a set of files.
* @author Oliver Burn
@ -291,7 +293,17 @@ public class Checker extends AutomaticBean
/** @param aBasedir the base directory to strip off in filenames */
public void setBasedir(String aBasedir)
{
mBasedir = aBasedir;
// we use getAbsolutePath() instead of getCanonicalPath()
// because normalize() removes all . and .. so path
// will be canonical by default.
mBasedir =
FileUtils.newFileUtils().normalize(aBasedir).getAbsolutePath();
}
/** @return the base directory property used in unit-test. */
String getBasedir()
{
return mBasedir;
}
/** notify all listeners about the audit start */

View File

@ -0,0 +1,34 @@
package com.puppycrawl.tools.checkstyle;
import java.io.File;
import junit.framework.TestCase;
public class CheckerTest extends TestCase
{
public void testDosBasedir() throws Exception
{
Checker c = new Checker();
c.setBasedir("c:/a\\b/./c\\..\\d");
assertEquals("C:\\a\\b\\d", c.getBasedir());
}
public void testOsBasedir() throws Exception
{
Checker c = new Checker();
// we need something to create absolute path
// let's take testinputs.dir
String testinputs_dir = System.getProperty("testinputs.dir");
if (!testinputs_dir.endsWith(File.separator)) {
testinputs_dir += File.separator;
}
c.setBasedir(testinputs_dir + "indentation/./..\\coding\\");
assertEquals(testinputs_dir + "coding", c.getBasedir());
}
}