You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/11/10 18:07:20 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant Main.java

bodewig     00/11/10 09:07:20

  Modified:    .        WHATSNEW
               docs     index.html
               src/main/org/apache/tools/ant Main.java
  Log:
  Make the buildfile searching only start on demand, introduced a new
  command line argument -file.
  
  Suggested by:	Jose  Alberto Fernandez <JF...@viquity.com>
  
  Revision  Changes    Path
  1.48      +6 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- WHATSNEW	2000/11/09 16:18:45	1.47
  +++ WHATSNEW	2000/11/10 17:07:19	1.48
  @@ -1,6 +1,12 @@
   Changes from Ant 1.2 to the current sources
   ===========================================
   
  +Changes that could break older environments:
  +--------------------------------------------
  +
  +* Ant doesn't search for the buildfile anymore, unless you use the new
  +  -find argument.
  +
   Other changes:
   --------------
   
  
  
  
  1.149     +1 -0      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.148
  retrieving revision 1.149
  diff -u -r1.148 -r1.149
  --- index.html	2000/11/09 16:18:46	1.148
  +++ index.html	2000/11/10 17:07:20	1.149
  @@ -202,6 +202,7 @@
   -logger &lt;classname&gt;    the class which is to perform logging
   -listener &lt;classname&gt;  add an instance of class as a project listener
   -buildfile &lt;file&gt;      use given buildfile
  +-find &lt;file&gt;           search for buildfile towards the root of the filesystem and use it
   -D&lt;property&gt;=&lt;value&gt;   use value for given property</pre>
   <h3>Examples</h3>
   <blockquote>
  
  
  
  1.23      +20 -17    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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Main.java	2000/10/16 09:21:22	1.22
  +++ Main.java	2000/11/10 17:07:20	1.23
  @@ -161,6 +161,8 @@
   
       protected Main(String[] args) throws BuildException {
   
  +        String searchForThis = null;
  +
           // cycle through given args
   
           for (int i = 0; i < args.length; i++) {
  @@ -238,7 +240,7 @@
                   if (posEq > 0) {
                       value = name.substring(posEq+1);
                       name = name.substring(0, posEq);
  -                } else if (i < args.length)
  +                } else if (i < args.length-1)
                       value = args[++i];
   
                   definedProps.put(name, value);
  @@ -253,6 +255,13 @@
               } else if (arg.equals("-projecthelp")) {
                   // set the flag to display the targets and quit
                   projectHelp = true;
  +            } else if (arg.equals("-find")) {
  +                // eat up next arg if present, default to build.xml
  +                if (i < args.length-1) {
  +                    searchForThis = args[++i];
  +                } else {
  +                    searchForThis = DEFAULT_BUILD_FILENAME;
  +                }
               } else if (arg.startsWith("-")) {
                   // we don't have any more args to recognize!
                   String msg = "Unknown arg: " + arg;
  @@ -267,9 +276,13 @@
           }
   
           // if buildFile was not specified on the command line,
  -        // then search for it
           if (buildFile == null) {
  -            buildFile = findBuildFile(DEFAULT_BUILD_FILENAME);
  +            // but -find then search for it
  +            if (searchForThis != null) {
  +                buildFile = findBuildFile(".", searchForThis);
  +            } else {
  +                buildFile = new File(DEFAULT_BUILD_FILENAME);
  +            }
           }
   
           // make sure buildfile exists
  @@ -290,18 +303,6 @@
       }
   
       /**
  -     * 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.
  @@ -334,12 +335,12 @@
        *
        * @exception BuildException    Failed to locate a build file
        */
  -    private File findBuildFile(String suffix) throws BuildException {
  +    private File findBuildFile(String start, String suffix) throws BuildException {
           if (msgOutputLevel >= Project.MSG_INFO) {
               System.out.println("Searching for " + suffix + " ...");
           }
   
  -        File parent = getParentFile(suffix);
  +        File parent = new File(new File(start).getAbsolutePath());
           File file = new File(parent, suffix);
           
           // check if the target file exists in the current directory
  @@ -503,6 +504,8 @@
           msg.append("  -listener <classname>  add an instance of class as a project listener" + lSep);
           msg.append("  -buildfile <file>      use given buildfile" + lSep);
           msg.append("  -D<property>=<value>   use value for given property" + lSep);
  +        msg.append("  -find <file>           search for buildfile towards the root of the file" + lSep);
  +        msg.append("                         system and use it" + lSep);
           System.out.println(msg.toString());
       }