}
private static void findFileRecursive(File rootPath, String regex, boolean recursive,
- List<String> result) throws FileNotFoundException, IOException {
+ boolean isFile, List<String> result) throws FileNotFoundException, IOException {
File[] filesAndDirs = rootPath.listFiles();
if (null == filesAndDirs) { // if rootPath is not a directory
return;
}
for (File file : filesAndDirs) {
- if (file.isFile() && file.getName().matches(regex)) {
- result.add(file.getCanonicalPath()); // add to result if it's
- // file
- } else if (recursive) {
- findFileRecursive(file, regex, recursive, result); // recursive
+ if (file.isFile()) { // file
+ if (isFile && file.getName().matches(regex)) {
+ result.add(file.getCanonicalPath()); // add to result if it's file
+ }
+ } else { // directory
+ if (!isFile && file.getName().matches(regex)) {
+ result.add(file.getCanonicalPath());
+ }
+ if (recursive) {
+ findFileRecursive(file, regex, recursive, isFile, result); // recursive
+ }
}
}
}
* glob pattern of file name
* @return canonical file path list
*/
- public static List<String> findFilesInDir(String dirPath, String fileToken) {
+ public static List<String> findFilesInDir(String dirPath, String fileToken, boolean isFile) {
List<String> resultFiles = new ArrayList<String>();
String regex = convertGlobToRegex(fileToken);
File startingDir = new File(dirPath);
if (startingDir.exists()) {
try {
- findFileRecursive(startingDir, regex, true, resultFiles);
+ findFileRecursive(startingDir, regex, true, isFile, resultFiles);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// check debuginfo file path
if (debugInfoRpmFile.getName().contains(RpmUtil.DEBUGINFO)) {
- List<String> files = FileUtil.findFilesInDir(rpmPath, getExecFileName() + ".debug");
+ List<String> files = FileUtil.findFilesInDir(rpmPath, getExecFileName() + ".debug", true);
if (files.size() == 0) {
return;
} else {
}
// future extension for applications with normal debug package
} else if (debugInfoRpmFile.getName().contains(RpmUtil.DEBUG)) {
- List<String> files = FileUtil.findFilesInDir(rpmPath, getExecFileName());
+ List<String> files = FileUtil.findFilesInDir(rpmPath, getExecFileName(), true);
if (files.size() == 0) {
return;
} else {
// check debugsource file path
List<String> files = FileUtil.findFilesInDir(rpmPath, projectName
- + CommonConstants.ASTERISK);
+ + CommonConstants.ASTERISK, false);
if (files.size() != 0) {
setSourcePath(rpmPath);
Logger.debug("SOURCE PATH : " + properties.get(PROPERTY.SRCPATH.index));
if (debugRpmPath.contains(RpmUtil.DEBUGINFO)) {
// find real debug file
String debugCandidate = "*" + binName + ".debug";
- List<String> debugfilelist = FileUtil.findFilesInDir(extractPath, debugCandidate);
+ List<String> debugfilelist = FileUtil.findFilesInDir(extractPath, debugCandidate, true);
if (debugfilelist.size() > 0) {
binData.setDebugFilePath(debugfilelist.get(0));
binData.setDebugFilePath(null);
}
} else if (debugRpmPath.contains(RpmUtil.DEBUG)) {
- List<String> debugfilelist = FileUtil.findFilesInDir(extractPath, binName);
+ List<String> debugfilelist = FileUtil.findFilesInDir(extractPath, binName, true);
if (debugfilelist.size() > 0) {
binData.setDebugFilePath(debugfilelist.get(0));
} else {
rootPath = rootPath + File.separator;
}
- List<String> rpmlist = FileUtil.findFilesInDir(rootPath, token);
+ List<String> rpmlist = FileUtil.findFilesInDir(rootPath, token, true);
if (binName != null) {
// get file list in rpm package and find target binary name