public File resolvePath(String path) {
File file = new File(path);
if (!file.isAbsolute()) {
- file = new File(getBasedir(), path);
+ try {
+ file = new File(getBasedir(), path).getCanonicalFile();
+ } catch (IOException e) {
+ throw new SonarException("Unable to resolve path '" + path + "'", e);
+ }
}
return file;
}
*/
package org.sonar.api.resources;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
+import org.apache.maven.project.MavenProject;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import java.io.File;
import java.util.List;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-
public class DefaultProjectFileSystemTest {
private Project project = null;
assertThat(files.size(), is(2));
}
+ /**
+ * See http://jira.codehaus.org/browse/SONAR-2280
+ */
+ @Test
+ public void resolvePathShouldReturnCanonicalFile() {
+ MavenProject pom = mock(MavenProject.class);
+ when(pom.getBasedir()).thenReturn(new File("/project"));
+ Project project = new Project("").setPom(pom);
+ DefaultProjectFileSystem fs = new DefaultProjectFileSystem(project, null);
+
+ assertThat(fs.resolvePath(".").getAbsolutePath(), endsWith("project"));
+ assertThat(fs.resolvePath("../project").getAbsolutePath(), endsWith("project"));
+ }
+
/**
* Example of hidden files/directories : .DSStore, .svn, .git
*/