- /**\r
- The original file generated by MakeDeps.exe is for makefile uses. The target\r
- part (before :) is not useful for ANT. This method will do the removal.\r
-\r
- @returns true if cleaned files is saved successfully\r
- @returns false if error occurs in file I/O system\r
- **/\r
- private boolean cleanup() {\r
- File df = new File(depsFile);\r
-\r
- if (!df.exists()) {\r
- return false;\r
- }\r
-\r
- LineNumberReader lineReader = null;\r
- FileReader fileReader = null;\r
- Set<String> lineSet = new HashSet<String>(100); // used to remove duplicated lines\r
- try {\r
- fileReader = new FileReader(df);\r
- lineReader = new LineNumberReader(fileReader);\r
-\r
- ///\r
- /// clean-up each line in deps file\r
- //\r
- String line = null;\r
- while ((line = lineReader.readLine()) != null) {\r
- Pattern pattern = Pattern.compile(target + "[ ]*:[ ]*(.+)");\r
- Matcher matcher = pattern.matcher(line);\r
-\r
- while (matcher.find()) {\r
- ///\r
- /// keep the file name after ":"\r
- ///\r
- String filePath = line.substring(matcher.start(1), matcher.end(1));\r
- filePath = cleanupPathName(filePath);\r
- lineSet.add(filePath);\r
- }\r
- }\r
- lineReader.close();\r
- fileReader.close();\r
-\r
- ///\r
- /// we may have explicitly specified dependency files\r
- ///\r
- StringTokenizer fileTokens = new StringTokenizer(extraDeps, ";");\r
- while (fileTokens.hasMoreTokens()) {\r
- lineSet.add(cleanupPathName(fileTokens.nextToken()));\r
- }\r
-\r
- ///\r
- /// compose the final file content\r
- /// \r
- StringBuffer cleanedLines = new StringBuffer(40960);\r
- Iterator<String> it = lineSet.iterator();\r
- while (it.hasNext()) {\r
- String filePath = it.next();\r
- cleanedLines.append(filePath);\r
- cleanedLines.append("\n");\r
- }\r
- ///\r
- /// overwrite old dep file with new content\r
- ///\r
- FileWriter fileWriter = null;\r
- fileWriter = new FileWriter(df);\r
- fileWriter.write(cleanedLines.toString());\r
- fileWriter.close();\r
- } catch (IOException e) {\r
- log (e.getMessage());\r
- }\r
-\r
- return true;\r
- }\r
-\r