01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.tools.build;
28:
29: import java.io.BufferedReader;
30: import java.io.DataInputStream;
31: import java.io.File;
32: import java.io.FileInputStream;
33: import java.io.FileNotFoundException;
34: import java.io.InputStream;
35: import java.io.InputStreamReader;
36: import java.util.ArrayList;
37: import java.util.List;
38:
39: /** A tool for cleaning up generated code files as listed in
40: * .gen files. This supports the ANT build method.
41: **/
42: public class DefCleaner {
43:
44: private static void parse(String filename) {
45: File genFile = new File(filename);
46: InputStream in;
47: List<File> filesToDelete = new ArrayList<File>();
48: try {
49: if (filename.equals("-")) {
50: in = new DataInputStream(System.in);
51: } else {
52: try {
53: in = new FileInputStream(filename);
54: } catch (FileNotFoundException fe) {
55: in = DefCleaner.class.getClassLoader()
56: .getResourceAsStream(filename);
57: }
58: }
59: if (in == null) {
60: System.err.println("File " + filename
61: + " could not be opened.");
62: }
63: InputStreamReader isr = new InputStreamReader(in);
64: BufferedReader br = new BufferedReader(isr);
65:
66: String line;
67: while ((line = br.readLine()) != null) {
68: filesToDelete.add(new File(genFile.getParentFile(),
69: line));
70: }
71: br.close();
72: } catch (Exception e) {
73: e.printStackTrace();
74: }
75: for (File fileToDelete : filesToDelete) {
76: try {
77: fileToDelete.delete();
78: System.out.println("deleted " + fileToDelete);
79: } catch (Exception e) {
80: System.err.println(e + ": " + fileToDelete);
81: }
82: }
83: }
84:
85: public static void main(String args[]) {
86: for (String defname : args) {
87: parse(defname);
88: }
89: }
90: }
|