1 18 19 package org.apache.tools.ant; 20 21 import java.io.ByteArrayOutputStream ; 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.InputStreamReader ; 27 import java.io.Reader ; 28 import java.lang.reflect.Constructor ; 29 import java.net.MalformedURLException ; 30 import java.net.URL ; 31 import java.util.Collections ; 32 import java.util.Enumeration ; 33 import java.util.HashMap ; 34 import java.util.Hashtable ; 35 import java.util.Map ; 36 import java.util.StringTokenizer ; 37 import java.util.Vector ; 38 import java.util.jar.Attributes ; 39 import java.util.jar.Attributes.Name; 40 import java.util.jar.JarFile ; 41 import java.util.jar.Manifest ; 42 import java.util.zip.ZipEntry ; 43 import java.util.zip.ZipFile ; 44 import org.apache.tools.ant.types.Path; 45 import org.apache.tools.ant.util.CollectionUtils; 46 import org.apache.tools.ant.util.FileUtils; 47 import org.apache.tools.ant.util.JavaEnvUtils; 48 import org.apache.tools.ant.util.LoaderUtils; 49 import org.apache.tools.ant.launch.Locator; 50 51 68 public class AntClassLoader extends ClassLoader implements SubBuildListener { 69 70 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 71 72 81 private class ResourceEnumeration implements Enumeration { 82 85 private String resourceName; 86 87 90 private int pathElementsIndex; 91 92 97 private URL nextResource; 98 99 105 ResourceEnumeration(String name) { 106 this.resourceName = name; 107 this.pathElementsIndex = 0; 108 findNextResource(); 109 } 110 111 118 public boolean hasMoreElements() { 119 return (this.nextResource != null); 120 } 121 122 127 public Object nextElement() { 128 URL ret = this.nextResource; 129 findNextResource(); 130 return ret; 131 } 132 133 139 private void findNextResource() { 140 URL url = null; 141 while ((pathElementsIndex < pathComponents.size()) 142 && (url == null)) { 143 try { 144 File pathComponent 145 = (File ) pathComponents.elementAt(pathElementsIndex); 146 url = getResourceURL(pathComponent, this.resourceName); 147 pathElementsIndex++; 148 } catch (BuildException e) { 149 } 152 } 153 this.nextResource = url; 154 } 155 } 156 157 160 private static final int BUFFER_SIZE = 8192; 161 164 private static final int NUMBER_OF_STRINGS = 256; 165 166 170 private Vector pathComponents = new Vector (); 171 172 175 private Project project; 176 177 181 private boolean parentFirst = true; 182 183 188 private Vector systemPackages = new Vector (); 189 190 195 private Vector loaderPackages = new Vector (); 196 197 203 private boolean ignoreBase = false; 204 205 208 private ClassLoader parent = null; 209 210 213 private Hashtable zipFiles = new Hashtable (); 214 215 216 private static Map pathMap = Collections.synchronizedMap(new HashMap ()); 217 218 222 private ClassLoader savedContextLoader = null; 223 226 private boolean isContextLoaderSaved = false; 227 228 237 public AntClassLoader( 238 ClassLoader parent, Project project, Path classpath) { 239 setParent(parent); 240 setClassPath(classpath); 241 setProject(project); 242 } 243 244 247 public AntClassLoader() { 248 setParent(null); 249 } 250 251 262 public AntClassLoader(Project project, Path classpath) { 263 setParent(null); 264 setProject(project); 265 setClassPath(classpath); 266 } 267 268 284 public AntClassLoader(ClassLoader parent, Project project, Path classpath, 285 boolean parentFirst) { 286 this(project, classpath); 287 if (parent != null) { 288 setParent(parent); 289 } 290 setParentFirst(parentFirst); 291 addJavaLibraries(); 292 } 293 294 295 307 public AntClassLoader(Project project, Path classpath, 308 boolean parentFirst) { 309 this(null, project, classpath, parentFirst); 310 } 311 312 325 public AntClassLoader(ClassLoader parent, boolean parentFirst) { 326 setParent(parent); 327 project = null; 328 this.parentFirst = parentFirst; 329 } 330 331 336 public void setProject(Project project) { 337 this.project = project; 338 if (project != null) { 339 project.addBuildListener(this); 340 } 341 } 342 343 350 public void setClassPath(Path classpath) { 351 pathComponents.removeAllElements(); 352 if (classpath != null) { 353 Path actualClasspath = classpath.concatSystemClasspath("ignore"); 354 String [] pathElements = actualClasspath.list(); 355 for (int i = 0; i < pathElements.length; ++i) { 356 try { 357 addPathElement(pathElements[i]); 358 } catch (BuildException e) { 359 } 362 } 363 } 364 } 365 366 372 public void setParent(ClassLoader parent) { 373 if (parent == null) { 374 this.parent = AntClassLoader.class.getClassLoader(); 375 } else { 376 this.parent = parent; 377 } 378 } 379 380 388 public void setParentFirst(boolean parentFirst) { 389 this.parentFirst = parentFirst; 390 } 391 392 393 401 protected void log(String message, int priority) { 402 if (project != null) { 403 project.log(message, priority); 404 } 405 } 409 410 414 public void setThreadContextLoader() { 415 if (isContextLoaderSaved) { 416 throw new BuildException("Context loader has not been reset"); 417 } 418 if (LoaderUtils.isContextLoaderAvailable()) { 419 savedContextLoader = LoaderUtils.getContextClassLoader(); 420 ClassLoader loader = this; 421 if (project != null 422 && "only".equals(project.getProperty("build.sysclasspath"))) { 423 loader = this.getClass().getClassLoader(); 424 } 425 LoaderUtils.setContextClassLoader(loader); 426 isContextLoaderSaved = true; 427 } 428 } 429 430 433 public void resetThreadContextLoader() { 434 if (LoaderUtils.isContextLoaderAvailable() 435 && isContextLoaderSaved) { 436 LoaderUtils.setContextClassLoader(savedContextLoader); 437 savedContextLoader = null; 438 isContextLoaderSaved = false; 439 } 440 } 441 442 443 452 public void addPathElement(String pathElement) throws BuildException { 453 File pathComponent 454 = project != null ? project.resolveFile(pathElement) 455 : new File (pathElement); 456 try { 457 addPathFile(pathComponent); 458 } catch (IOException e) { 459 throw new BuildException(e); 460 } 461 } 462 463 473 protected void addPathFile(File pathComponent) throws IOException { 474 pathComponents.addElement(pathComponent); 475 if (pathComponent.isDirectory()) { 476 return; 477 } 478 479 String absPathPlusTimeAndLength = 480 pathComponent.getAbsolutePath() + pathComponent.lastModified() + "-" 481 + pathComponent.length(); 482 String classpath = (String ) pathMap.get(absPathPlusTimeAndLength); 483 if (classpath == null) { 484 ZipFile jarFile = null; 485 InputStream manifestStream = null; 486 try { 487 jarFile = new ZipFile (pathComponent); 488 manifestStream 489 = jarFile.getInputStream(new ZipEntry ("META-INF/MANIFEST.MF")); 490 491 if (manifestStream == null) { 492 return; 493 } 494 Reader manifestReader 495 = new InputStreamReader (manifestStream, "UTF-8"); 496 org.apache.tools.ant.taskdefs.Manifest manifest 497 = new org.apache.tools.ant.taskdefs.Manifest(manifestReader); 498 classpath 499 = manifest.getMainSection().getAttributeValue("Class-Path"); 500 501 } catch (org.apache.tools.ant.taskdefs.ManifestException e) { 502 } finally { 504 if (manifestStream != null) { 505 manifestStream.close(); 506 } 507 if (jarFile != null) { 508 jarFile.close(); 509 } 510 } 511 if (classpath == null) { 512 classpath = ""; 513 } 514 pathMap.put(absPathPlusTimeAndLength, classpath); 515 } 516 517 if (!"".equals(classpath)) { 518 URL baseURL = FILE_UTILS.getFileURL(pathComponent); 519 StringTokenizer st = new StringTokenizer (classpath); 520 while (st.hasMoreTokens()) { 521 String classpathElement = st.nextToken(); 522 URL libraryURL = new URL (baseURL, classpathElement); 523 if (!libraryURL.getProtocol().equals("file")) { 524 log("Skipping jar library " + classpathElement 525 + " since only relative URLs are supported by this" 526 + " loader", Project.MSG_VERBOSE); 527 continue; 528 } 529 String decodedPath = Locator.decodeUri(libraryURL.getFile()); 530 File libraryFile = new File (decodedPath); 531 if (libraryFile.exists() && !isInPath(libraryFile)) { 532 addPathFile(libraryFile); 533 } 534 } 535 } 536 } 537 538 544 public String getClasspath() { 545 StringBuffer sb = new StringBuffer (); 546 boolean firstPass = true; 547 Enumeration componentEnum = pathComponents.elements(); 548 while (componentEnum.hasMoreElements()) { 549 if (!firstPass) { 550 sb.append(System.getProperty("path.separator")); 551 } else { 552 firstPass = false; 553 } 554 sb.append(((File ) componentEnum.nextElement()).getAbsolutePath()); 555 } 556 return sb.toString(); 557 } 558 559 568 public synchronized void setIsolated(boolean isolated) { 569 ignoreBase = isolated; 570 } 571 572 582 public static void initializeClass(Class theClass) { 583 588 final Constructor [] cons = theClass.getDeclaredConstructors(); 589 if (cons != null) { 591 if (cons.length > 0 && cons[0] != null) { 592 final String [] strs = new String [NUMBER_OF_STRINGS]; 593 try { 594 cons[0].newInstance((Object []) strs); 595 } catch (Exception e) { 598 } 611 } 612 } 613 } 614 615 624 public void addSystemPackageRoot(String packageRoot) { 625 systemPackages.addElement(packageRoot 626 + (packageRoot.endsWith(".") ? "" : ".")); 627 } 628 629 638 public void addLoaderPackageRoot(String packageRoot) { 639 loaderPackages.addElement(packageRoot 640 + (packageRoot.endsWith(".") ? "" : ".")); 641 } 642 643 658 public Class forceLoadClass(String classname) 659 throws ClassNotFoundException { 660 log("force loading " + classname, Project.MSG_DEBUG); 661 662 Class theClass = findLoadedClass(classname); 663 664 if (theClass == null) { 665 theClass = findClass(classname); 666 } 667 668 return theClass; 669 } 670 671 687 public Class forceLoadSystemClass(String classname) 688 throws ClassNotFoundException { 689 log("force system loading " + classname, Project.MSG_DEBUG); 690 691 Class theClass = findLoadedClass(classname); 692 693 if (theClass == null) { 694 theClass = findBaseClass(classname); 695 } 696 697 return theClass; 698 } 699 700 709 public InputStream getResourceAsStream(String name) { 710 711 InputStream resourceStream = null; 712 if (isParentFirst(name)) { 713 resourceStream = loadBaseResource(name); 714 if (resourceStream != null) { 715 log("ResourceStream for " + name 716 + " loaded from parent loader", Project.MSG_DEBUG); 717 718 } else { 719 resourceStream = loadResource(name); 720 if (resourceStream != null) { 721 log("ResourceStream for " + name 722 + " loaded from ant loader", Project.MSG_DEBUG); 723 } 724 } 725 } else { 726 resourceStream = loadResource(name); 727 if (resourceStream != null) { 728 log("ResourceStream for " + name 729 + " loaded from ant loader", Project.MSG_DEBUG); 730 731 } else { 732 resourceStream = loadBaseResource(name); 733 if (resourceStream != null) { 734 log("ResourceStream for " + name 735 + " loaded from parent loader", Project.MSG_DEBUG); 736 } 737 } 738 } 739 740 if (resourceStream == null) { 741 log("Couldn't load ResourceStream for " + name, 742 Project.MSG_DEBUG); 743 } 744 745 return resourceStream; 746 } 747 748 757 private InputStream loadResource(String name) { 758 InputStream stream = null; 761 762 Enumeration e = pathComponents.elements(); 763 while (e.hasMoreElements() && stream == null) { 764 File pathComponent = (File ) e.nextElement(); 765 stream = getResourceStream(pathComponent, name); 766 } 767 return stream; 768 } 769 770 780 private InputStream loadBaseResource(String name) { 781 if (parent == null) { 782 return getSystemResourceAsStream(name); 783 } else { 784 return parent.getResourceAsStream(name); 785 } 786 } 787 788 800 private InputStream getResourceStream(File file, String resourceName) { 801 try { 802 if (!file.exists()) { 803 return null; 804 } 805 806 if (file.isDirectory()) { 807 File resource = new File (file, resourceName); 808 809 if (resource.exists()) { 810 return new FileInputStream (resource); 811 } 812 } else { 813 ZipFile zipFile = (ZipFile ) zipFiles.get(file); 815 if (zipFile == null) { 816 zipFile = new ZipFile (file); 817 zipFiles.put(file, zipFile); 818 } 819 ZipEntry entry = zipFile.getEntry(resourceName); 820 if (entry != null) { 821 return zipFile.getInputStream(entry); 822 } 823 } 824 } catch (Exception e) { 825 log("Ignoring Exception " + e.getClass().getName() 826 + ": " + e.getMessage() + " reading resource " + resourceName 827 + " from " + file, Project.MSG_VERBOSE); 828 } 829 830 return null; 831 } 832 833 845 private boolean isParentFirst(String resourceName) { 846 851 853 boolean useParentFirst = parentFirst; 854 855 for (Enumeration e = systemPackages.elements(); e.hasMoreElements();) { 856 String packageName = (String ) e.nextElement(); 857 if (resourceName.startsWith(packageName)) { 858 useParentFirst = true; 859 break; 860 } 861 } 862 863 for (Enumeration e = loaderPackages.elements(); e.hasMoreElements();) { 864 String packageName = (String ) e.nextElement(); 865 if (resourceName.startsWith(packageName)) { 866 useParentFirst = false; 867 break; 868 } 869 } 870 871 return useParentFirst; 872 } 873 874 878 private ClassLoader getRootLoader() { 879 ClassLoader ret = getClass().getClassLoader(); 880 while (ret != null && ret.getParent() != null) { 881 ret = ret.getParent(); 882 } 883 return ret; 884 } 885 886 898 public URL getResource(String name) { 899 URL url = null; 902 if (isParentFirst(name)) { 903 url = (parent == null) ? super.getResource(name) 904 : parent.getResource(name); 905 } 906 907 if (url != null) { 908 log("Resource " + name + " loaded from parent loader", 909 Project.MSG_DEBUG); 910 911 } else { 912 Enumeration e = pathComponents.elements(); 915 while (e.hasMoreElements() && url == null) { 916 File pathComponent = (File ) e.nextElement(); 917 url = getResourceURL(pathComponent, name); 918 if (url != null) { 919 log("Resource " + name 920 + " loaded from ant loader", 921 Project.MSG_DEBUG); 922 } 923 } 924 } 925 926 if (url == null && !isParentFirst(name)) { 927 if (ignoreBase) { 929 url = (getRootLoader() == null) ? null 930 : getRootLoader().getResource(name); 931 } else { 932 url = (parent == null) ? super.getResource(name) 933 : parent.getResource(name); 934 } 935 if (url != null) { 936 log("Resource " + name + " loaded from parent loader", 937 Project.MSG_DEBUG); 938 } 939 } 940 941 if (url == null) { 942 log("Couldn't load Resource " + name, Project.MSG_DEBUG); 943 } 944 945 return url; 946 } 947 948 957 protected Enumeration findResources(String name) throws IOException { 958 Enumeration mine = new ResourceEnumeration(name); 959 Enumeration base; 960 if (parent != null && parent != getParent()) { 961 base = parent.getResources(name); 963 } else { 965 base = new CollectionUtils.EmptyEnumeration(); 968 } 969 if (isParentFirst(name)) { 970 return CollectionUtils.append(base, mine); 972 } else if (ignoreBase) { 973 return getRootLoader() == null 974 ? mine 975 : CollectionUtils.append( 976 mine, getRootLoader().getResources(name)); 977 } else { 978 return CollectionUtils.append(mine, base); 980 } 981 } 982 983 995 protected URL getResourceURL(File file, String resourceName) { 996 try { 997 if (!file.exists()) { 998 return null; 999 } 1000 1001 if (file.isDirectory()) { 1002 File resource = new File (file, resourceName); 1003 1004 if (resource.exists()) { 1005 try { 1006 return FILE_UTILS.getFileURL(resource); 1007 } catch (MalformedURLException ex) { 1008 return null; 1009 } 1010 } 1011 } else { 1012 ZipFile zipFile = (ZipFile ) zipFiles.get(file); 1013 if (zipFile == null) { 1014 zipFile = new ZipFile (file); 1015 zipFiles.put(file, zipFile); 1016 } 1017 1018 ZipEntry entry = zipFile.getEntry(resourceName); 1019 if (entry != null) { 1020 try { 1021 return new URL ("jar:" + FILE_UTILS.getFileURL(file) 1022 + "!/" + entry); 1023 } catch (MalformedURLException ex) { 1024 return null; 1025 } 1026 } 1027 } 1028 } catch (Exception e) { 1029 e.printStackTrace(); 1030 } 1031 1032 return null; 1033 } 1034 1035 1055 protected synchronized Class loadClass(String classname, boolean resolve) 1056 throws ClassNotFoundException { 1057 1061 Class theClass = findLoadedClass(classname); 1062 if (theClass != null) { 1063 return theClass; 1064 } 1065 1066 if (isParentFirst(classname)) { 1067 try { 1068 theClass = findBaseClass(classname); 1069 log("Class " + classname + " loaded from parent loader " 1070 + "(parentFirst)", Project.MSG_DEBUG); 1071 } catch (ClassNotFoundException cnfe) { 1072 theClass = findClass(classname); 1073 log("Class " + classname + " loaded from ant loader " 1074 + "(parentFirst)", Project.MSG_DEBUG); 1075 } 1076 } else { 1077 try { 1078 theClass = findClass(classname); 1079 log("Class " + classname + " loaded from ant loader", 1080 Project.MSG_DEBUG); 1081 } catch (ClassNotFoundException cnfe) { 1082 if (ignoreBase) { 1083 throw cnfe; 1084 } 1085 theClass = findBaseClass(classname); 1086 log("Class " + classname + " loaded from parent loader", 1087 Project.MSG_DEBUG); 1088 } 1089 } 1090 1091 if (resolve) { 1092 resolveClass(theClass); 1093 } 1094 1095 return theClass; 1096 } 1097 1098 1107 private String getClassFilename(String classname) { 1108 return classname.replace('.', '/') + ".class"; 1109 } 1110 1111 1124 protected Class defineClassFromData(File container, byte[] classData, 1125 String classname) throws IOException { 1126 definePackage(container, classname); 1127 return defineClass(classname, classData, 0, classData.length, 1131 Project.class.getProtectionDomain()); 1132 } 1133 1134 1144 protected void definePackage(File container, String className) 1145 throws IOException { 1146 int classIndex = className.lastIndexOf('.'); 1147 if (classIndex == -1) { 1148 return; 1149 } 1150 1151 String packageName = className.substring(0, classIndex); 1152 if (getPackage(packageName) != null) { 1153 return; 1155 } 1156 1157 Manifest manifest = getJarManifest(container); 1159 1160 if (manifest == null) { 1161 definePackage(packageName, null, null, null, null, null, 1162 null, null); 1163 } else { 1164 definePackage(container, packageName, manifest); 1165 } 1166 } 1167 1168 1179 private Manifest getJarManifest(File container) throws IOException { 1180 if (container.isDirectory()) { 1181 return null; 1182 } 1183 JarFile jarFile = null; 1184 try { 1185 jarFile = new JarFile (container); 1186 return jarFile.getManifest(); 1187 } finally { 1188 if (jarFile != null) { 1189 jarFile.close(); 1190 } 1191 } 1192 } 1193 1194 1202 protected void definePackage(File container, String packageName, 1203 Manifest manifest) { 1204 String sectionName = packageName.replace('.', '/') + "/"; 1205 1206 String specificationTitle = null; 1207 String specificationVendor = null; 1208 String specificationVersion = null; 1209 String implementationTitle = null; 1210 String implementationVendor = null; 1211 String implementationVersion = null; 1212 String sealedString = null; 1213 URL sealBase = null; 1214 1215 Attributes sectionAttributes = manifest.getAttributes(sectionName); 1216 if (sectionAttributes != null) { 1217 specificationTitle 1218 = sectionAttributes.getValue(Name.SPECIFICATION_TITLE); 1219 specificationVendor 1220 = sectionAttributes.getValue(Name.SPECIFICATION_VENDOR); 1221 specificationVersion 1222 = sectionAttributes.getValue(Name.SPECIFICATION_VERSION); 1223 implementationTitle 1224 = sectionAttributes.getValue(Name.IMPLEMENTATION_TITLE); 1225 implementationVendor 1226 = sectionAttributes.getValue(Name.IMPLEMENTATION_VENDOR); 1227 implementationVersion 1228 = sectionAttributes.getValue(Name.IMPLEMENTATION_VERSION); 1229 sealedString 1230 = sectionAttributes.getValue(Name.SEALED); 1231 } 1232 1233 Attributes mainAttributes = manifest.getMainAttributes(); 1234 if (mainAttributes != null) { 1235 if (specificationTitle == null) { 1236 specificationTitle 1237 = mainAttributes.getValue(Name.SPECIFICATION_TITLE); 1238 } 1239 if (specificationVendor == null) { 1240 specificationVendor 1241 = mainAttributes.getValue(Name.SPECIFICATION_VENDOR); 1242 } 1243 if (specificationVersion == null) { 1244 specificationVersion 1245 = mainAttributes.getValue(Name.SPECIFICATION_VERSION); 1246 } 1247 if (implementationTitle == null) { 1248 implementationTitle 1249 = mainAttributes.getValue(Name.IMPLEMENTATION_TITLE); 1250 } 1251 if (implementationVendor == null) { 1252 implementationVendor 1253 = mainAttributes.getValue(Name.IMPLEMENTATION_VENDOR); 1254 } 1255 if (implementationVersion == null) { 1256 implementationVersion 1257 = mainAttributes.getValue(Name.IMPLEMENTATION_VERSION); 1258 } 1259 if (sealedString == null) { 1260 sealedString 1261 = mainAttributes.getValue(Name.SEALED); 1262 } 1263 } 1264 1265 if (sealedString != null && sealedString.equalsIgnoreCase("true")) { 1266 try { 1267 sealBase = new URL (FileUtils.getFileUtils().toURI(container.getAbsolutePath())); 1268 } catch (MalformedURLException e) { 1269 } 1271 } 1272 1273 definePackage(packageName, specificationTitle, specificationVersion, 1274 specificationVendor, implementationTitle, 1275 implementationVersion, implementationVendor, sealBase); 1276 } 1277 1278 1279 1295 private Class getClassFromStream(InputStream stream, String classname, 1296 File container) 1297 throws IOException , SecurityException { 1298 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 1299 int bytesRead = -1; 1300 byte[] buffer = new byte[BUFFER_SIZE]; 1301 1302 while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) { 1303 baos.write(buffer, 0, bytesRead); 1304 } 1305 1306 byte[] classData = baos.toByteArray(); 1307 return defineClassFromData(container, classData, classname); 1308 } 1309 1310 1321 public Class findClass(String name) throws ClassNotFoundException { 1322 log("Finding class " + name, Project.MSG_DEBUG); 1323 1324 return findClassInComponents(name); 1325 } 1326 1327 1334 protected boolean isInPath(File component) { 1335 for (Enumeration e = pathComponents.elements(); e.hasMoreElements();) { 1336 File pathComponent = (File ) e.nextElement(); 1337 if (pathComponent.equals(component)) { 1338 return true; 1339 } 1340 } 1341 return false; 1342 } 1343 1344 1345 1356 private Class findClassInComponents(String name) 1357 throws ClassNotFoundException { 1358 InputStream stream = null; 1361 String classFilename = getClassFilename(name); 1362 try { 1363 Enumeration e = pathComponents.elements(); 1364 while (e.hasMoreElements()) { 1365 File pathComponent = (File ) e.nextElement(); 1366 try { 1367 stream = getResourceStream(pathComponent, classFilename); 1368 if (stream != null) { 1369 log("Loaded from " + pathComponent + " " 1370 + classFilename, Project.MSG_DEBUG); 1371 return getClassFromStream(stream, name, pathComponent); 1372 } 1373 } catch (SecurityException se) { 1374 throw se; 1375 } catch (IOException ioe) { 1376 log("Exception reading component " + pathComponent 1378 + " (reason: " + ioe.getMessage() + ")", 1379 Project.MSG_VERBOSE); 1380 } 1381 } 1382 1383 throw new ClassNotFoundException (name); 1384 } finally { 1385 try { 1386 if (stream != null) { 1387 stream.close(); 1388 } 1389 } catch (IOException e) { 1390 } 1392 } 1393 } 1394 1395 1410 private Class findBaseClass(String name) throws ClassNotFoundException { 1411 if (parent == null) { 1412 return findSystemClass(name); 1413 } else { 1414 return parent.loadClass(name); 1415 } 1416 } 1417 1418 1422 public synchronized void cleanup() { 1423 for (Enumeration e = zipFiles.elements(); e.hasMoreElements();) { 1424 ZipFile zipFile = (ZipFile ) e.nextElement(); 1425 try { 1426 zipFile.close(); 1427 } catch (IOException ioe) { 1428 } 1430 } 1431 zipFiles = new Hashtable (); 1432 if (project != null) { 1433 project.removeBuildListener(this); 1434 } 1435 project = null; 1436 } 1437 1438 1443 public void buildStarted(BuildEvent event) { 1444 } 1446 1447 1453 public void buildFinished(BuildEvent event) { 1454 cleanup(); 1455 } 1456 1457 1466 public void subBuildFinished(BuildEvent event) { 1467 if (event.getProject() == project) { 1468 cleanup(); 1469 } 1470 } 1471 1472 1479 public void subBuildStarted(BuildEvent event) { 1480 } 1482 1483 1488 public void targetStarted(BuildEvent event) { 1489 } 1491 1492 1497 public void targetFinished(BuildEvent event) { 1498 } 1500 1501 1506 public void taskStarted(BuildEvent event) { 1507 } 1509 1510 1515 public void taskFinished(BuildEvent event) { 1516 } 1518 1519 1524 public void messageLogged(BuildEvent event) { 1525 } 1527 1528 1532 public void addJavaLibraries() { 1533 Vector packages = JavaEnvUtils.getJrePackages(); 1534 Enumeration e = packages.elements(); 1535 while (e.hasMoreElements()) { 1536 String packageName = (String ) e.nextElement(); 1537 addSystemPackageRoot(packageName); 1538 } 1539 } 1540 1541 1545 public String toString() { 1546 return "AntClassLoader[" + getClasspath() + "]"; 1547 } 1548 1549} 1550 | Popular Tags |