001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.generator.iwrpgen;
021:
022: import java.io.BufferedReader;
023: import java.io.File;
024: import java.io.FileInputStream;
025: import java.io.IOException;
026: import java.io.InputStreamReader;
027: import java.util.ArrayList;
028: import java.util.List;
029:
030: /**
031: *
032: * @author mleidig@schlund.de
033: *
034: */
035: public class IWrapperFileScanner {
036:
037: private long fileReadCount;
038: private long fileReadTime;
039:
040: public IWrapperFileScanner() {
041: }
042:
043: public void reset() {
044: fileReadCount = 0;
045: fileReadTime = 0;
046: }
047:
048: public List<File> getChangedFiles(File srcDir, File destDir,
049: long lastScanTime) {
050: List<File> changedFiles = new ArrayList<File>();
051: getChangedFiles(srcDir, destDir, changedFiles, lastScanTime);
052: return changedFiles;
053: }
054:
055: private void getChangedFiles(File srcDir, File destDir,
056: List<File> changedFiles, long lastScanTime) {
057: File[] srcFiles = srcDir.listFiles();
058: for (File srcFile : srcFiles) {
059: if (srcFile.isDirectory()) {
060: if (!(srcFile.getName().equals(".svn") || srcFile
061: .getName().equals("CVS"))) {
062: File destFile = new File(destDir, srcFile.getName());
063: getChangedFiles(srcFile, destFile, changedFiles,
064: lastScanTime);
065: }
066: } else {
067: if (srcFile.getName().endsWith(".java")) {
068: String name = srcFile.getName().substring(0,
069: srcFile.getName().length() - 5)
070: + ".class";
071: File destFile = new File(destDir, name);
072: if (!destFile.exists()
073: || srcFile.lastModified() > destFile
074: .lastModified()
075: || srcFile.lastModified() > lastScanTime) {
076: boolean found = false;
077: long t1 = System.currentTimeMillis();
078: try {
079: // do fuzzy search for IWrapper annotation in source file
080: FileInputStream fis = new FileInputStream(
081: srcFile);
082: BufferedReader reader = new BufferedReader(
083: new InputStreamReader(fis));
084: String line = null;
085: int cnt = 0;
086: while ((line = reader.readLine()) != null) {
087: if (line.contains("IWrapper")) {
088: if (line.contains("@IWrapper")
089: || line
090: .contains("@de.schlund.pfixcore.generator.annotation.IWrapper")) {
091: found = true;
092: break;
093: }
094: }
095: cnt++;
096: if (cnt > 70)
097: break;
098: if (line.contains("public class"))
099: break;
100: }
101: fis.close();
102: } catch (IOException x) {
103: x.printStackTrace();
104: }
105: long t2 = System.currentTimeMillis();
106: fileReadCount++;
107: fileReadTime += (t2 - t1);
108: if (found)
109: changedFiles.add(srcFile);
110: }
111: }
112: }
113: }
114: }
115:
116: public long getScanCount() {
117: return fileReadCount;
118: }
119:
120: public String printStatistics() {
121: return "Scanned " + fileReadCount + " file(s) in "
122: + fileReadTime + "ms";
123: }
124:
125: }
|