01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2008 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *
22: * $Id$
23: */
24: package com.bostechcorp.cbesb.build.ant.util;
25:
26: import java.io.BufferedReader;
27: import java.io.File;
28: import java.io.FileReader;
29: import java.io.FileWriter;
30: import java.io.IOException;
31: import java.util.Vector;
32:
33: public class UpToDateCache {
34:
35: private File cacheFile;
36: private Vector<String> upToDateList;
37:
38: public UpToDateCache(File cacheFile) {
39: this .cacheFile = cacheFile;
40: upToDateList = new Vector<String>();
41: }
42:
43: public boolean isProjectUpToDate(String project) throws IOException {
44: readFromFile();
45: return upToDateList.contains(project);
46: }
47:
48: public void setProjectUpToDate(String project) throws IOException {
49: readFromFile();
50: upToDateList.add(project);
51: writeToFile();
52: }
53:
54: public void debug() {
55: System.out.println("UpToDateCache intstance = "
56: + this .hashCode());
57: for (int i = 0; i < upToDateList.size(); i++) {
58: System.out.println("\t" + upToDateList.get(i));
59: }
60: }
61:
62: private void writeToFile() throws IOException {
63: FileWriter fw = new FileWriter(cacheFile);
64: for (int i = 0; i < upToDateList.size(); i++) {
65: fw.write(upToDateList.get(i) + "\n");
66: }
67: fw.close();
68: }
69:
70: private void readFromFile() throws IOException {
71: upToDateList.clear();
72: if (cacheFile.exists()) {
73: BufferedReader reader = new BufferedReader(new FileReader(
74: cacheFile));
75: String entry = reader.readLine();
76: while (entry != null) {
77: upToDateList.add(entry);
78: entry = reader.readLine();
79: }
80: reader.close();
81: }
82: }
83: }
|