diff --git a/docs/releasenotes.html b/docs/releasenotes.html index f40efa642..93e3da825 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -124,6 +124,9 @@
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java index 1d2de0439..82c5fc11c 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java @@ -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 */ diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java new file mode 100644 index 000000000..9b70cc965 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -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()); + } +}