KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > tools > ant > PCAwareSet


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.tools.ant;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.io.*;
18
19 import org.apache.tools.ant.types.*;
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.DirectoryScanner;
22 import com.versant.lib.bcel.classfile.JavaClass;
23 import com.versant.lib.bcel.classfile.ClassParser;
24
25
26 /**
27  * @keep-all
28  */

29 public class PCAwareSet extends AbstractFileSet{
30     private ArrayList JavaDoc packages = new ArrayList JavaDoc();
31
32     public PCAwareSet() {
33         super();
34     }
35
36     protected PCAwareSet(PCAwareSet fileset) {
37         super(fileset);
38     }
39
40     public Package JavaDoc createPackage(){
41         Package JavaDoc pack = new Package JavaDoc();
42         packages.add(pack);
43         return pack;
44     }
45
46     /**
47      * Return a FileSet that has the same basedir and same patternsets
48      * as this one.
49      */

50     public Object JavaDoc clone() {
51         if (isReference()) {
52             return new PCAwareSet((PCAwareSet) getRef(getProject()));
53         } else {
54             return new PCAwareSet(this);
55         }
56     }
57
58     public List JavaDoc getAwareClasses(Project project){
59         ArrayList JavaDoc classlist = new ArrayList JavaDoc();
60         final String JavaDoc dotClass = ".class";
61         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
62         for (Iterator JavaDoc iterator = packages.iterator(); iterator.hasNext();) {
63             Package JavaDoc s = (Package JavaDoc) iterator.next();
64             String JavaDoc pat = s.getName();
65             if (pat.endsWith("*")){
66                 pat = pat+"*";
67             } else {
68                 pat = pat+".*";
69             }
70             buf.append(pat.replace('.','/'));
71             buf.append(" ");
72
73         }
74         setIncludes(buf.toString().trim());
75         DirectoryScanner scanner = getDirectoryScanner(project);
76         String JavaDoc[] incFiles = scanner.getIncludedFiles();
77         for (int j = 0; j < incFiles.length; j++) {
78             String JavaDoc temp = incFiles[j];
79             if (temp.endsWith(dotClass)){
80                 try {
81                     File file = new File(scanner.getBasedir(), temp);
82                     FileInputStream inputStream = new FileInputStream(file);
83                     ClassParser parser = new ClassParser(inputStream, "");
84                     JavaClass javaClass = parser.parse();
85                     classlist.add(javaClass.getClassName().replace('.', '/') +
86                             ".class");
87                 } catch (Exception JavaDoc e) {
88                     classlist.add(temp);
89                 }
90             }
91
92         }
93         return classlist;
94     }
95
96     /**
97      * Used to track info about the packages to be
98      */

99     public static class Package {
100         /** The package name */
101         private String JavaDoc name;
102
103         /**
104          * Set the name of the package
105          *
106          * @param name the package name.
107          */

108         public void setName(String JavaDoc name) {
109             this.name = name.trim();
110         }
111
112         /**
113          * Get the package name.
114          *
115          * @return the package's name.
116          */

117         public String JavaDoc getName() {
118             return name;
119         }
120
121         /**
122          * @see java.lang.Object#toString
123          */

124         public String JavaDoc toString() {
125             return getName();
126         }
127     }
128 }
129
130
Popular Tags