ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant Main.java Project.java
Date Tue, 19 Sep 2000 09:09:25 GMT
bodewig     00/09/19 02:09:24

  Modified:    .        WHATSNEW
               docs     index.html
               src/main/org/apache/tools/ant Main.java Project.java
  Log:
  Ant will now scan for build.xml in the parent directory (directories)
  as well.
  
  Added -debug and Project.MSG_DEBUG to make -verbose less verbose. Many
  messages really rather belong into a DEBUG category.
  
  Submitted by:	Jason Dillon <jason@planet57.com>
  
  Revision  Changes    Path
  1.29      +6 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- WHATSNEW	2000/09/15 11:41:58	1.28
  +++ WHATSNEW	2000/09/19 09:09:20	1.29
  @@ -79,6 +79,12 @@
   
   * project specific help can now be obtained with the -projecthelp option.
   
  +* Added a -debug option to make -verbose less verbose (and more useful)
  +
  +* Ant will now search for a file named build.xml in the parent directory
  +and above (towards the root of the filesystem) if you didn't specify
  +-buildfile and there is no build.xml in the current directory.
  +
   Fixed bugs:
   -----------
   
  
  
  
  1.105     +9 -5      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- index.html	2000/09/18 14:04:48	1.104
  +++ index.html	2000/09/19 09:09:22	1.105
  @@ -25,7 +25,7 @@
     <li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li>
   </ul>
   
  -<p>Version 1.2 - 2000/09/15</p>
  +<p>Version 1.2 - 2000/09/19</p>
   
   <hr>
   <h2>Table of Contents</h2>
  @@ -166,10 +166,13 @@
   <h2><a name="running">Running Ant</a></h2>
   <p>Running Ant is simple, when you installed it as described in the previous
   section. Just type <code>ant</code>.</p>
  -<p>When nothing is specified, Ant looks for a <code>build.xml</code>
file in the
  -current directory. When found, it uses that file as a buildfile. To make Ant use
  -another buildfile, use the commandline option <i>-buildfile &lt;file&gt;</i>,
  -where <i>&lt;file&gt;</i> is the buildfile you want to use.</p>
  +<p>When nothing is specified, Ant looks for a <code>build.xml</code>
  +file in the current directory. When found, it uses that file as a
  +buildfile, otherwise it searches in the parent directory and so on
  +until the root of the filesystem has been reached. To make Ant use
  +another buildfile, use the commandline option <i>-buildfile
  +&lt;file&gt;</i>, where <i>&lt;file&gt;</i> is the buildfile
you want
  +to use.</p>
   <p>You can also set properties which override properties specified in the
   buildfile (see the <a href="#property">property task</a>). 
   This can be done with the <i>-D&lt;property&gt;=&lt;value&gt;</i>
  @@ -192,6 +195,7 @@
   -version               print the version information and exit
   -quiet                 be extra quiet
   -verbose               be extra verbose
  +-debug                 print debugging information
   -emacs                 produce logging information without adornments
   -logfile &lt;file&gt;        use given file for log
   -logger &lt;classname&gt;    the class which is to perform logging
  
  
  
  1.20      +86 -2     jakarta-ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Main.java	2000/09/11 13:08:36	1.19
  +++ Main.java	2000/09/19 09:09:23	1.20
  @@ -72,11 +72,14 @@
   
   public class Main {
   
  +    /** The default build file name */
  +    public static final String DEFAULT_BUILD_FILENAME = "build.xml";
  +
       /** Our current message output status. Follows Project.MSG_XXX */
       private int msgOutputLevel = Project.MSG_INFO;
   
       /** File that we are using for configuration */
  -    private File buildFile = new File("build.xml");
  +    private File buildFile; /** null */
   
       /** Stream that we are using for logging */
       private PrintStream out = System.out;
  @@ -128,6 +131,7 @@
               System.exit(0);
           }
           catch(Throwable exc) {
  +            System.err.println(exc.getMessage());
               System.exit(1);
           }
       }
  @@ -150,6 +154,9 @@
               } else if (arg.equals("-verbose") || arg.equals("-v")) {
                   printVersion();
                   msgOutputLevel = Project.MSG_VERBOSE;
  +            } else if (arg.equals("-debug")) {
  +                printVersion();
  +                msgOutputLevel = Project.MSG_DEBUG;
               } else if (arg.equals("-logfile") || arg.equals("-l")) {
                   try {
                       File logFile = new File(args[i+1]);
  @@ -236,8 +243,13 @@
   
           }
   
  -        // make sure buildfile exists
  +        // if buildFile was not specified on the command line,
  +        // then search for it
  +        if (buildFile == null) {
  +            buildFile = findBuildFile(DEFAULT_BUILD_FILENAME);
  +        }
   
  +        // make sure buildfile exists
           if (!buildFile.exists()) {
               System.out.println("Buildfile: " + buildFile + " does not exist!");
               throw new BuildException("Build failed");
  @@ -255,6 +267,77 @@
       }
   
       /**
  +     * Helper to get the parent file for a given filename.
  +     *
  +     * <P>Added to simulate File.getParentFile() from JDK 1.2.
  +     *
  +     * @param filename  File name
  +     * @return          Parent file or null if none
  +     */
  +    private File getParentFile(String filename) {
  +        return getParentFile(new File(filename));
  +    }
  +
  +    /**
  +     * Helper to get the parent file for a given file.
  +     *
  +     * <P>Added to simulate File.getParentFile() from JDK 1.2.
  +     *
  +     * @param file   File
  +     * @return       Parent file or null if none
  +     */
  +    private File getParentFile(File file) {
  +        String filename = file.getAbsolutePath();
  +        file = new File(filename);
  +        filename = file.getParent();
  +
  +        if (filename != null && msgOutputLevel >= Project.MSG_VERBOSE) {
  +            System.out.println("Searching in "+filename);
  +        }
  +
  +        return (filename == null) ? null : new File(filename);
  +    }
  +
  +    /**
  +     * Search parent directories for the build file.
  +     *
  +     * <P>Takes the given target as a suffix to append to each
  +     *    parent directory in seach of a build file.  Once the
  +     *    root of the file-system has been reached an exception
  +     *    is thrown.
  +     *
  +     * @param suffix    Suffix filename to look for in parents.
  +     * @return          A handle to the build file
  +     *
  +     * @exception BuildException    Failed to locate a build file
  +     */
  +    private File findBuildFile(String suffix) throws BuildException {
  +        if (msgOutputLevel >= Project.MSG_INFO) {
  +            System.out.println("Searching for " + suffix + " ...");
  +        }
  +
  +        File parent = getParentFile(suffix);
  +        File file = new File(parent, suffix);
  +        
  +        // check if the target file exists in the current directory
  +        while (!file.exists()) {
  +            // change to parent directory
  +            parent = getParentFile(parent);
  +            
  +            // if parent is null, then we are at the root of the fs,
  +            // complain that we can't find the build file.
  +            if (parent == null) {
  +                throw new BuildException("Could not locate a build file!");
  +            }
  +            
  +            // refresh our file handle
  +            file = new File(parent, suffix);
  +        }
  +        
  +        return file;
  +    }
  +
  +    /**
        * Executes the build.
        */
       private void runBuild() throws BuildException {
  @@ -390,6 +473,7 @@
           msg.append("  -version               print the version information and exit" +
lSep);
           msg.append("  -quiet                 be extra quiet" + lSep);
           msg.append("  -verbose               be extra verbose" + lSep);
  +        msg.append("  -debug                 print debugging information" + lSep);
           msg.append("  -emacs                 produce logging information without adornments"
+ lSep);
           msg.append("  -logfile <file>        use given file for log" + lSep);
           msg.append("  -logger <classname>    the class which is to perform logging"
+ lSep);
  
  
  
  1.41      +9 -8      jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- Project.java	2000/09/18 14:04:50	1.40
  +++ Project.java	2000/09/19 09:09:23	1.41
  @@ -76,6 +76,7 @@
       public static final int MSG_WARN = 1;
       public static final int MSG_INFO = 2;
       public static final int MSG_VERBOSE = 3;
  +    public static final int MSG_DEBUG = 4;
   
       // private set of constants to represent the state
       // of a DFS of the Target dependencies
  @@ -238,13 +239,13 @@
           if (null != userProperties.get(name))
               return;
           log("Setting project property: " + name + " -> " +
  -            value, MSG_VERBOSE);
  +            value, MSG_DEBUG);
           properties.put(name, value);
       }
   
       public void setUserProperty(String name, String value) {
           log("Setting ro project property: " + name + " -> " +
  -            value, MSG_VERBOSE);
  +            value, MSG_DEBUG);
           userProperties.put(name, value);
           properties.put(name, value);
       }
  @@ -294,7 +295,7 @@
       public void addFilter(String token, String value) {
           if (token == null) return;
           log("Setting token to filter: " + token + " -> "
  -            + value, MSG_VERBOSE);
  +            + value, MSG_DEBUG);
           this.filters.put(token, value);
       }
   
  @@ -350,7 +351,7 @@
   
       public void addTaskDefinition(String taskName, Class taskClass) {
           String msg = " +User task: " + taskName + "     " + taskClass.getName();
  -        log(msg, MSG_VERBOSE);
  +        log(msg, MSG_DEBUG);
           taskClassDefinitions.put(taskName, taskClass);
       }
   
  @@ -360,7 +361,7 @@
   
       public void addDataTypeDefinition(String typeName, Class typeClass) {
           String msg = " +User datatype: " + typeName + "     " + typeClass.getName();
  -        log(msg, MSG_VERBOSE);
  +        log(msg, MSG_DEBUG);
           dataClassDefinitions.put(typeName, typeClass);
       }
   
  @@ -416,7 +417,7 @@
        */
       public void addOrReplaceTarget(String targetName, Target target) {
           String msg = " +Target: " + targetName;
  -        log(msg, MSG_VERBOSE);
  +        log(msg, MSG_DEBUG);
           target.setProject(this);
           targets.put(targetName, target);
       }
  @@ -449,7 +450,7 @@
               task.setTaskName(taskType);
   
               String msg = "   +Task: " + taskType;
  -            log (msg, MSG_VERBOSE);
  +            log (msg, MSG_DEBUG);
               return task;
           } catch (Exception e) {
               String msg = "Could not create task of type: "
  @@ -484,7 +485,7 @@
                    o = ctor.newInstance(new Object[] {this});
               }
               String msg = "   +DataType: " + typeName;
  -            log (msg, MSG_VERBOSE);
  +            log (msg, MSG_DEBUG);
               return o;
           } catch (java.lang.reflect.InvocationTargetException ite) {
               Throwable t = ite.getTargetException();
  
  
  

Mime
View raw message