1 2 12 package com.versant.core.jdo.tools.ant; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 import java.util.Iterator ; 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 29 public class PCAwareSet extends AbstractFileSet{ 30 private ArrayList packages = new ArrayList (); 31 32 public PCAwareSet() { 33 super(); 34 } 35 36 protected PCAwareSet(PCAwareSet fileset) { 37 super(fileset); 38 } 39 40 public Package createPackage(){ 41 Package pack = new Package (); 42 packages.add(pack); 43 return pack; 44 } 45 46 50 public Object clone() { 51 if (isReference()) { 52 return new PCAwareSet((PCAwareSet) getRef(getProject())); 53 } else { 54 return new PCAwareSet(this); 55 } 56 } 57 58 public List getAwareClasses(Project project){ 59 ArrayList classlist = new ArrayList (); 60 final String dotClass = ".class"; 61 StringBuffer buf = new StringBuffer (); 62 for (Iterator iterator = packages.iterator(); iterator.hasNext();) { 63 Package s = (Package ) iterator.next(); 64 String 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 [] incFiles = scanner.getIncludedFiles(); 77 for (int j = 0; j < incFiles.length; j++) { 78 String 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 e) { 88 classlist.add(temp); 89 } 90 } 91 92 } 93 return classlist; 94 } 95 96 99 public static class Package { 100 101 private String name; 102 103 108 public void setName(String name) { 109 this.name = name.trim(); 110 } 111 112 117 public String getName() { 118 return name; 119 } 120 121 124 public String toString() { 125 return getName(); 126 } 127 } 128 } 129 130 | Popular Tags |