You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Bootstrap.java 3.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // -------------------------------------------------------------------------------
  2. // Copyright (c)2000 Apache Software Foundation
  3. // -------------------------------------------------------------------------------
  4. import java.io.*;
  5. import java.util.*;
  6. import java.util.zip.*;
  7. /**
  8. * Quick and dirty single class bootstrap utility for getting Ant off
  9. * the ground when in need. To use, compile this file in the directory
  10. * where the source code is in the repository, then execute it. That's
  11. * it.<p>
  12. *
  13. * No pretense is made that this is an elegant peice of code. This code
  14. * only exists to do a ground zero build of Ant. Any other building of
  15. * Ant should be done with itself whenever possible.
  16. *
  17. * @author James Duncan Davidson (duncan@apache.org)
  18. * @author Conor MacNeill (conor@m64.com)
  19. */
  20. public class Bootstrap {
  21. /**
  22. * Command line entry point. This is the first part of the bootstrap
  23. * where we go and set up the environment and generally do what is
  24. * necessary to set up for Bootstrapping.
  25. */
  26. public static void main(String[] args) throws Exception {
  27. String[] command;
  28. String classpath = null;
  29. // check to see if we have a compiler on the classpath. Right now
  30. // we're just checking for the old compiler, but will want to check
  31. // for the new compiler and use it if it exists. Later.
  32. try {
  33. Class clazz = Class.forName("sun.tools.javac.Main");
  34. } catch (ClassNotFoundException cnfe) {
  35. String javaHome = System.getProperty("java.home");
  36. if (javaHome.endsWith("jre")) {
  37. javaHome = javaHome.substring(0, javaHome.length() - 4);
  38. }
  39. // XXX should check if this exists and bail out if it doesn't
  40. classpath = javaHome + "/lib/tools.jar" + File.pathSeparator + ".";
  41. }
  42. // XXX really should check to see if compiling the bootstrap is necessary. :)
  43. System.out.println("Compiling Bootstrap2");
  44. if (classpath == null) {
  45. command = new String[] {"javac", "./Bootstrap2.java"};
  46. } else {
  47. command = new String[] {"javac", "-classpath", classpath, "./Bootstrap2.java"};
  48. }
  49. runCommand(command);
  50. System.out.println("Running Bootstrap2");
  51. if (classpath == null) {
  52. command = new String[] {"java", "Bootstrap2"};
  53. } else {
  54. command = new String[] {"java", "-cp", classpath, "Bootstrap2"};
  55. }
  56. runCommand(command);
  57. }
  58. /**
  59. * Utility method for execing processes
  60. */
  61. static void runCommand(String[] command) throws IOException {
  62. Runtime runtime = Runtime.getRuntime();
  63. Process process = runtime.exec(command);
  64. // echo output from process
  65. InputStream in = process.getInputStream();
  66. byte[] buf = new byte[80];
  67. int count = 0;
  68. count = in.read(buf, 0, buf.length);
  69. while (count != -1) {
  70. System.out.write(buf, 0, count);
  71. count = in.read(buf, 0, buf.length);
  72. }
  73. in = process.getErrorStream();
  74. count = in.read(buf, 0, buf.length);
  75. if (count > 0) {
  76. System.out.println();
  77. System.out.println("Error Stream Output:");
  78. while (count != -1) {
  79. System.out.write(buf, 0, count);
  80. count = in.read(buf, 0, buf.length);
  81. }
  82. }
  83. }
  84. }