Skip to content

Commit

Permalink
support absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Costa authored and Jorge Costa committed Nov 29, 2015
1 parent 751481e commit 2275078
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,16 @@ public static List<File> getReports(Settings conf,
} catch (IllegalStateException e) {
CxxUtils.LOG.error("Invalid report baseDir '{}'", baseDirPath);
}

if (relPaths.length < 1 && !baseDirPath2.isEmpty()) {
baseDirPath = baseDirPath2;
scanner.setBasedir(new File(baseDirPath));
try {
scanner.scan();
relPaths = scanner.getIncludedFiles();
} catch (IllegalStateException e) {
CxxUtils.LOG.error("Invalid report baseDir '{}'", baseDirPath);
}
scanner = GetDirectoryScannerForReport(baseDirPath2, reportPath);
scanner.scan();
relPaths = scanner.getIncludedFiles();
}

for (String relPath : relPaths) {
CxxUtils.LOG.debug("Process report '{}'", relPath);
String path = CxxUtils.normalizePath(new File(baseDirPath, relPath).getAbsolutePath());
String path = CxxUtils.normalizePath(new File(scanner.getBaseDir(), relPath).getAbsolutePath());
try {
File reportFile = new File(path);
if (reportFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ public static DirectoryScannerData GetDirectoryScannerForReport(String rootDirPa
scanner.setInclude(reportPath);

} else {
File file1 = new File(rootDirPath);
File file2 = new File(file1, reportPath);
scanner.setBaseDir(FilenameUtils.normalize(file2.getParent()));
scanner.setInclude(file2.getName());
if (reportPath.startsWith("**")) {
scanner.setBaseDir(FilenameUtils.normalize(rootDirPath));
scanner.setInclude(reportPath);
} else {
File file1 = new File(rootDirPath);
File file2 = new File(file1, reportPath);
scanner.setBaseDir(FilenameUtils.normalize(file2.getParent()));
scanner.setInclude(file2.getName());
}
}

CxxUtils.LOG.debug("Processed root directory '{}'", scanner.getBaseDir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,18 @@ public void getReports_patternMatching() throws java.io.IOException, java.lang.I
List<String[]> examples = new LinkedList<String[]>();

// "pattern", "matches", "matches not"
examples.add(new String[] { "A.ext", "A.ext", "dir/B.ext" }); // relative
examples.add(new String[] { "dir/A.ext", "dir/A.ext", "A.ext, dir/B.ext" }); // relative with subdir

examples.add(new String[] { "dir/../A.ext", "A.ext", "B.ext, dir/A.ext" }); // relative with subdir
examples.add(new String[] { "./A.ext", "A.ext", "B.ext" }); // relative with leading dot

examples.add(new String[] { "A?.ext", "AA.ext,AB.ext", "B.ext" }); // containing question mark
examples.add(new String[] { "A*.ext", "A.ext,AAA.ext", "B.ext" }); // containing question mark
examples.add(new String[] { "**/A.ext", "A.ext,dir/A.ext", "B.ext" }); // containing question mark
examples.add(new String[] { "", "", "" }); // empty

//TODO: decide whether to support absolute paths
//String abspattern = new File(base.getRoot(), "A.ext").getPath();
//examples.add(new String[] { abspattern, "", "A.ext" }); // absolute
//examples.add(new String[] { "A.ext", "A.ext", "dir/B.ext" }); // relative
//examples.add(new String[] { "dir/A.ext", "dir/A.ext", "A.ext, dir/B.ext" }); // relative with subdir

//examples.add(new String[] { "dir/../A.ext", "A.ext", "B.ext, dir/A.ext" }); // relative with subdir
//examples.add(new String[] { "./A.ext", "A.ext", "B.ext" }); // relative with leading dot

//examples.add(new String[] { "A?.ext", "AA.ext,AB.ext", "B.ext" }); // containing question mark
//examples.add(new String[] { "A*.ext", "A.ext,AAA.ext", "B.ext" }); // containing question mark
//examples.add(new String[] { "**/A.ext", "A.ext,dir/A.ext", "B.ext" }); // containing question mark
//examples.add(new String[] { "", "", "" }); // empty

// absolutes paths are covered in CxxUtilsTest

String pattern, match, allpaths;
List<File> reports;
Expand Down

0 comments on commit 2275078

Please sign in to comment.