You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2004/10/12 14:26:45 UTC

DO NOT REPLY [Bug 31665] New: - set filename of default buildfile to allow for convienience and dynamic ant and subant calls

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31665>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31665

set filename of default buildfile to allow for convienience and dynamic ant and subant calls

           Summary: set filename of default buildfile to allow for
                    convienience and dynamic ant and subant calls
           Product: Ant
           Version: 1.7Alpha (nightly)
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: steve.morin@gmail.com


This patch allowes people to set the default filename that ant uses if
none is given and sets ant.file.default to default file name value.

M docs/manual/running.html
M docs/manual/using.html
M src/main/org/apache/tools/ant/Main.java
M src/main/org/apache/tools/ant/taskdefs/Ant.java
M src/main/org/apache/tools/ant/taskdefs/SubAnt.java

I would have provided unit tests with this and would appreciate some
one pointing me in the right direction so I can create them.

I have a couple of scenarios where this could be useful.

1st usage convenience..
A person that often uses a different build file could use a shell
script that calls ant using a different default for convenience.

       #!/bin/sh
       ant -df config.xml "$@"

or
       alias cfg="ant -df config.xml"
or
       ANT_ARGS="-df config.xml"

2nd usage dynamic change of ant task default target.

>>      Ant
>>      Description
>>
>>      Runs Ant on a supplied buildfile. This can be used to build
subprojects. This task must not be used outside of a target if it
invokes the same build file it is part of.
>>
>>      When the antfile attribute is omitted, the file "build.xml" in the
supplied directory (dir attribute) is used.

3rd usage dynamic change of subant task calls

>>      antfile          Build file name, to use in conjunction with
directories.               String         Optional
>>      Defaults to "build.xml".
>>      If genericantfile is set, this attribute is ignored.

Of the three usages I believe the 1st and 3rd usages have the most
merit.  I believe the 1st could be very beneficial to many people to
speed development.  It's a minor changes and requires little
maintenance but increases flexibility greatly.  Dynamic usage of
subant  would great to simplify ant usage for projects that multiple
preprocess.

--build.xml
<project name="subant" default="subant1">
       <property name="build.dir" value="subant.build"/>
       <target name="subant1">
           <subant target="" buildpath="${project.dir}>
             <property name="build.dir" value="subant1.build"/>
             <property name="not.overloaded" value="not.overloaded"/>

           </subant>
       </target>
</project>

--bashrc
alias doc="and -df docs.xml"
alias gen="ant -df generate.xml"
alias cfg="ant -df config.xml"

cmd: gen -f build.xml
cmd: cfg -f build.xml
cmd: ant

--patch.txt
Index: docs/manual/running.html
===================================================================
RCS file: /home/cvspublic/ant/docs/manual/running.html,v
retrieving revision 1.27
diff -u -r1.27 running.html
--- docs/manual/running.html	31 Aug 2004 22:32:53 -0000	1.27
+++ docs/manual/running.html	8 Oct 2004 18:13:10 -0000
@@ -77,35 +77,43 @@
 
 <h3><a name="options">Command-line Options Summary</a></h3>
 <pre>ant [options] [target [target2 [target3] ...]]
-Options:
-  -help, -h              print this message
-  -projecthelp, -p       print project help information
-  -version               print the version information and exit
-  -diagnostics           print information that might be helpful to
-                         diagnose or report problems.
-  -quiet, -q             be extra quiet
-  -verbose, -v           be extra verbose
-  -debug, -d             print debugging information
-  -emacs, -e             produce logging information without adornments
-  -lib &lt;path&gt;            specifies a path to search for jars and classes
-  -logfile &lt;file&gt;        use given file for log
-    -l     &lt;file&gt;                ''
-  -logger &lt;classname&gt;    the class which is to perform logging
-  -listener &lt;classname&gt;  add an instance of class as a project listener
-  -noinput               do not allow interactive input
-  -buildfile &lt;file&gt;      use given buildfile
-    -file    &lt;file&gt;              ''
-    -f       &lt;file&gt;              ''
-  -D&lt;property&gt;=&lt;value&gt;   use value for given property
-  -keep-going, -k        execute all targets that do not depend
-                         on failed target(s)
-  -propertyfile &lt;name&gt;   load all properties from file with -D
-                         properties taking precedence
-  -inputhandler &lt;class&gt;  the class which will handle input requests
-  -find &lt;file&gt;           (s)earch for buildfile towards the root of
-    -s  &lt;file&gt;           the filesystem and use it
-  -nice  number          A niceness value for the main thread:
-                         1 (lowest) to 10 (highest); 5 is the default
+Options: 
+  -help, -h                print this message
+  -projecthelp, -p         print project help information
+  -version                 print the version information and exit
+  -diagnostics             print information that might be helpful to
+                           diagnose or report problems.
+  -quiet, -q               be extra quiet
+  -verbose, -v             be extra verbose
+  -debug, -d               print debugging information
+  -emacs, -e               produce logging information without adornments
+  -lib <path>              specifies a path to search for jars and classes
+  -logfile <file>          use given file for log
+    -l     <file>                ''
+  -logger <classname>      the class which is to perform logging
+  -listener <classname>    add an instance of class as a project listener
+  -noinput                 do not allow interactive input
+  -buildfile <file>        use given buildfile
+    -file    <file>              ''
+    -f       <file>              ''
+  -defaultbuildfile <file> set given file name as default buildfile
+    -defaultfile    <file>              ''
+    -df             <file>              ''
+  -D<property>=<value>     use value for given property
+  -keep-going, -k          execute all targets that do not depend
+                           on failed target(s)
+  -propertyfile <name>     load all properties from file with -D
+                           properties taking precedence
+  -inputhandler <class>    the class which will handle input requests
+  -find <file>             (s)earch for buildfile towards the root of
+    -s  <file>             the filesystem and use it
+  -nice  number            A niceness value for the main thread:
+                           1 (lowest) to 10 (highest); 5 is the default
+  -nouserlib               Run ant without using the jar files from ${user.home}/
+                           .ant/lib
+  -noclasspath             Run ant without using CLASSPATH
+
+
 </pre>
 <p>For more information about <code>-logger</code> and
 <code>-listener</code> see
Index: docs/manual/using.html
===================================================================
RCS file: /home/cvspublic/ant/docs/manual/using.html,v
retrieving revision 1.35
diff -u -r1.35 using.html
--- docs/manual/using.html	2 Oct 2004 23:39:59 -0000	1.35
+++ docs/manual/using.html	8 Oct 2004 18:13:10 -0000
@@ -253,6 +253,7 @@
 basedir             the absolute path of the project's basedir (as set
                     with the basedir attribute of &lt;project&gt;).
 ant.file            the absolute path of the buildfile.
+ant.file.default    the file name of defaultbuildfile
 ant.version         the version of Ant
 ant.project.name    the name of the project that is currently executing;
                     it is set in the name attribute of &lt;project&gt;.
Index: src/main/org/apache/tools/ant/Main.java
===================================================================
RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.112
diff -u -r1.112 Main.java
--- src/main/org/apache/tools/ant/Main.java	5 Oct 2004 08:37:00 -0000	1.112
+++ src/main/org/apache/tools/ant/Main.java	8 Oct 2004 18:13:11 -0000
@@ -46,8 +46,11 @@
 public class Main implements AntMain {
 
     /** The default build file name. */
-    public static final String DEFAULT_BUILD_FILENAME = "build.xml";
+    private static final String DEFAULT_ANT_FILENAME = "build.xml";
 
+    /** The default ant file name */
+    private String antdefaultfile = null;
+    
     /** Our current message output status. Follows Project.MSG_XXX. */
     private int msgOutputLevel = Project.MSG_INFO;
 
@@ -263,6 +266,19 @@
         processArgs(args);
     }
 
+    public String getAntDefaultFilename(){
+    		if(this.antdefaultfile != null){
+    			return this.antdefaultfile;
+    		} else{
+    			return Main.DEFAULT_ANT_FILENAME;
+    		}
+    }
+    
+    private void setAntDefaultFilename(String antdefaultfile){
+    		this.antdefaultfile = antdefaultfile;
+    }
+    
+    
     /**
      * Process command line arguments.
      * When ant is started from Launcher, the -lib argument does not get
@@ -276,6 +292,20 @@
         String searchForThis = null;
         PrintStream logTo = null;
 
+        for (int i = 0; i < args.length; i++) {
+        		String arg = args[i];
+        		if(arg.equals("-defaultbuildfile") || arg.equals("-defaultfile")
+                        || arg.equals("-df")){
+        			try {
+                        this.setAntDefaultFilename(args[++i]);
+                        break;
+                    } catch (ArrayIndexOutOfBoundsException aioobe) {
+                        throw new BuildException("You must specify a default "+
+                        		"build file when using -defaultbuildfile argument.");
+                    }
+        		}
+        }
+        
         // cycle through given args
 
         for (int i = 0; i < args.length; i++) {
@@ -395,7 +425,8 @@
                 if (i < args.length - 1) {
                     searchForThis = args[++i];
                 } else {
-                    searchForThis = DEFAULT_BUILD_FILENAME;
+                    //searchForThis = DEFAULT_BUILD_FILENAME;
+                		searchForThis = this.getAntDefaultFilename();
                 }
             } else if (arg.startsWith("-propertyfile")) {
                 try {
@@ -425,7 +456,15 @@
                     throw new BuildException(
                             "Niceness value is out of the range 1-10");
                 }
-            } else if (arg.startsWith("-")) {
+            } else if(arg.equals("-defaultbuildfile") || arg.equals("-defaultfile")
+                    || arg.equals("-df")){
+    			try {
+    					++i;
+                } catch (ArrayIndexOutOfBoundsException aioobe) {
+                    throw new BuildException("You must specify a default "+
+                    		"build file when using -defaultbuildfile argument.");
+                }
+    			}else if (arg.startsWith("-")) {
                 // we don't have any more args to recognize!
                 String msg = "Unknown argument: " + arg;
                 System.out.println(msg);
@@ -444,7 +483,8 @@
                 buildFile = findBuildFile(System.getProperty("user.dir"),
                                           searchForThis);
             } else {
-                buildFile = new File(DEFAULT_BUILD_FILENAME);
+                //buildFile = new File(DEFAULT_BUILD_FILENAME);
+            		buildFile = new File(this.getAntDefaultFilename());
             }
         }
 
@@ -652,6 +692,8 @@
 
                 project.setUserProperty("ant.file",
                                         buildFile.getAbsolutePath());
+                
+               
project.setUserProperty("ant.file.default",this.getAntDefaultFilename());
 
                 project.setKeepGoingMode(keepGoingMode);
 
@@ -806,41 +848,44 @@
         StringBuffer msg = new StringBuffer();
         msg.append("ant [options] [target [target2 [target3] ...]]" + lSep);
         msg.append("Options: " + lSep);
-        msg.append("  -help, -h              print this message" + lSep);
-        msg.append("  -projecthelp, -p       print project help information" +
lSep);
-        msg.append("  -version               print the version information and
exit" + lSep);
-        msg.append("  -diagnostics           print information that might be
helpful to" + lSep);
-        msg.append("                         diagnose or report problems." + lSep);
-        msg.append("  -quiet, -q             be extra quiet" + lSep);
-        msg.append("  -verbose, -v           be extra verbose" + lSep);
-        msg.append("  -debug, -d             print debugging information" + lSep);
-        msg.append("  -emacs, -e             produce logging information
without adornments"
+        msg.append("  -help, -h                print this message" + lSep);
+        msg.append("  -projecthelp, -p         print project help information"
+ lSep);
+        msg.append("  -version                 print the version information
and exit" + lSep);
+        msg.append("  -diagnostics             print information that might be
helpful to" + lSep);
+        msg.append("                           diagnose or report problems." +
lSep);
+        msg.append("  -quiet, -q               be extra quiet" + lSep);
+        msg.append("  -verbose, -v             be extra verbose" + lSep);
+        msg.append("  -debug, -d               print debugging information" +
lSep);
+        msg.append("  -emacs, -e               produce logging information
without adornments"
                    + lSep);
-        msg.append("  -lib <path>            specifies a path to search for
jars and classes"
+        msg.append("  -lib <path>              specifies a path to search for
jars and classes"
                    + lSep);
-        msg.append("  -logfile <file>        use given file for log" + lSep);
+        msg.append("  -logfile <file>          use given file for log" + lSep);
         msg.append("    -l     <file>                ''" + lSep);
-        msg.append("  -logger <classname>    the class which is to perform
logging" + lSep);
-        msg.append("  -listener <classname>  add an instance of class as a
project listener"
+        msg.append("  -logger <classname>      the class which is to perform
logging" + lSep);
+        msg.append("  -listener <classname>    add an instance of class as a
project listener"
                    + lSep);
-        msg.append("  -noinput               do not allow interactive input" +
lSep);
-        msg.append("  -buildfile <file>      use given buildfile" + lSep);
+        msg.append("  -noinput                 do not allow interactive input"
+ lSep);
+        msg.append("  -buildfile <file>        use given buildfile" + lSep);
         msg.append("    -file    <file>              ''" + lSep);
         msg.append("    -f       <file>              ''" + lSep);
-        msg.append("  -D<property>=<value>   use value for given property" + lSep);
-        msg.append("  -keep-going, -k        execute all targets that do not
depend" + lSep);
-        msg.append("                         on failed target(s)" + lSep);
-        msg.append("  -propertyfile <name>   load all properties from file with
-D" + lSep);
-        msg.append("                         properties taking precedence" + lSep);
-        msg.append("  -inputhandler <class>  the class which will handle input
requests" + lSep);
-        msg.append("  -find <file>           (s)earch for buildfile towards the
root of" + lSep);
-        msg.append("    -s  <file>           the filesystem and use it" + lSep);
-        msg.append("  -nice  number          A niceness value for the main
thread:" + lSep
-                   + "                         1 (lowest) to 10 (highest); 5 is
the default"
+        msg.append("  -defaultbuildfile <file> set given file name as default
buildfile" + lSep);
+        msg.append("    -defaultfile    <file>              ''" + lSep);
+        msg.append("    -df             <file>              ''" + lSep);
+        msg.append("  -D<property>=<value>     use value for given property" +
lSep);
+        msg.append("  -keep-going, -k          execute all targets that do not
depend" + lSep);
+        msg.append("                           on failed target(s)" + lSep);
+        msg.append("  -propertyfile <name>     load all properties from file
with -D" + lSep);
+        msg.append("                           properties taking precedence" +
lSep);
+        msg.append("  -inputhandler <class>    the class which will handle
input requests" + lSep);
+        msg.append("  -find <file>             (s)earch for buildfile towards
the root of" + lSep);
+        msg.append("    -s  <file>             the filesystem and use it" + lSep);
+        msg.append("  -nice  number            A niceness value for the main
thread:" + lSep
+                   + "                           1 (lowest) to 10 (highest); 5
is the default"
                    + lSep);
-        msg.append("  -nouserlib             Run ant without using the jar
files from ${user.home}/"
-                   + ".ant/lib");
-        msg.append("  -noclasspath           Run ant without using CLASSPATH");
+        msg.append("  -nouserlib               Run ant without using the jar
files from ${user.home}/" + lSep
+                   + "                           .ant/lib" + lSep);
+        msg.append("  -noclasspath             Run ant without using CLASSPATH"
+ lSep);
         System.out.println(msg.toString());
     }
 
Index: src/main/org/apache/tools/ant/taskdefs/Ant.java
===================================================================
RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.106
diff -u -r1.106 Ant.java
--- src/main/org/apache/tools/ant/taskdefs/Ant.java	31 Aug 2004 22:32:53 -0000	1.106
+++ src/main/org/apache/tools/ant/taskdefs/Ant.java	8 Oct 2004 18:13:11 -0000
@@ -318,7 +318,8 @@
             overrideProperties();
 
             if (antFile == null) {
-                antFile = "build.xml";
+            		antFile = getProject().getProperty("ant.file.default");
+                //antFile = "build.xml";
             }
 
             File file = FileUtils.newFileUtils().resolveFile(dir, antFile);
@@ -328,6 +329,7 @@
                 + ((locals.size() == 0) ? locals.toString() : "[default]")
                 + " in build file " + antFile, Project.MSG_VERBOSE);
             newProject.setUserProperty("ant.file" , antFile);
+           
newProject.setUserProperty("ant.file.default",getProject().getProperty("ant.file.default"));
 
             String thisAntFile = getProject().getProperty("ant.file");
             // Are we trying to call the target in which we are defined (or
Index: src/main/org/apache/tools/ant/taskdefs/SubAnt.java
===================================================================
RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/SubAnt.java,v
retrieving revision 1.17
diff -u -r1.17 SubAnt.java
--- src/main/org/apache/tools/ant/taskdefs/SubAnt.java	2 Jul 2004 07:23:54
-0000	1.17
+++ src/main/org/apache/tools/ant/taskdefs/SubAnt.java	8 Oct 2004 18:13:11 -0000
@@ -63,7 +63,8 @@
 
     private Ant ant = null;
     private String target = null;
-    private String antfile = "build.xml";
+    //private String antfile = "build.xml";
+    private String antfile = null;
     private File genericantfile = null;
     private boolean inheritAll = false;
     private boolean inheritRefs = false;
@@ -177,6 +178,13 @@
             target = getOwningTarget().getName();
         }
 */
+        if(antfile == null){
+        		antfile = getProject().getProperty("ant.file.default");
+        		if(antfile == null){
+        			antfile = "build.xml";
+        		}
+        }
+        
         BuildException buildException = null;
         for (int i = 0; i < count; ++i) {
             File file = null;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org