You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ho...@apache.org on 2001/05/03 09:41:12 UTC

cvs commit: jakarta-ant/src/etc/testcases/taskdefs available.xml

holtdl      01/05/03 00:41:12

  Modified:    docs/manual/CoreTasks available.html
               src/main/org/apache/tools/ant/taskdefs Available.java
               src/etc/testcases/taskdefs available.xml
  Log:
  Backed out previous change that added a "dir" attribute, as this caused
  backwards-compatibility issues. Added a "type" attribute instead, which
  works with the "file" attribute to specify either a file or a directory.
  
  Revision  Changes    Path
  1.4       +17 -11    jakarta-ant/docs/manual/CoreTasks/available.html
  
  Index: available.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/available.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- available.html	2001/04/30 23:25:32	1.3
  +++ available.html	2001/05/03 07:41:06	1.4
  @@ -12,8 +12,8 @@
   <p>Sets a property if a resource is available at runtime. This resource can be a
   file, a directory, a class in the classpath, or a JVM system resource.</p>
   <p>If the resource is present, the property value is set to true by
  -default, otherwise the property is not set. You can set the value to
  -something specific by specifying the <code>value</code> attribute.</p>
  +default; otherwise, the property is not set. You can set the value to
  +something other than the default by specifying the <code>value</code> attribute.</p>
   <p>Normally, this task is used to set properties that are useful to avoid target
   execution depending on system parameters.</p>
   <h3>Parameters</h3>
  @@ -36,13 +36,9 @@
     <tr>
       <td valign="top">classname</td>
       <td valign="top">The class to look for in the classpath.</td>
  -    <td valign="middle" align="center" rowspan="4">Yes</td>
  +    <td valign="middle" align="center" rowspan="3">Yes</td>
     </tr>
     <tr>
  -    <td valign="top">dir</td>
  -    <td valign="top">The directory to look for.</td>
  -  </tr>
  -  <tr>
       <td valign="top">file</td>
       <td valign="top">The file to look for.</td>
     </tr>
  @@ -51,13 +47,18 @@
       <td valign="top">The resource to look for in the JVM.</td>
     </tr>
     <tr>
  -    <td valign="top">classpath</td> <td valign="top">The classpath to
  -      use when looking up <code>classname</code> or <code>resource</code>.</td> <td
  -    align="center" valign="top">No</td>
  +    <td valign="top">classpath</td>
  +    <td valign="top">The classpath to use when looking up <code>classname</code> or <code>resource</code>.</td>
  +    <td align="center" valign="top">No</td>    
     </tr>
     <tr>
       <td valign="top">classpathref</td>
  -	<td valign="top">The classpath to use, given as a <a href="../using.html#references">reference</a> to a path defined elsewhere.</td>
  +    <td valign="top">The classpath to use, given as a <a href="../using.html#references">reference</a> to a path defined elsewhere.</td>
  +    <td align="center" valign="top">No</td>    
  +  </tr>
  +  <tr>
  +    <td valign="top">type</td>
  +    <td valign="top">The type of <code>file</code> to look for, either a directory (<code>type="dir"</code>) or a file (<code>type="file"</code>). If not set, the property will be set if the name specified in the <code>file</code> attribute exists as either a file or a directory.</td>
       <td align="center" valign="top">No</td>    
     </tr>
     
  @@ -77,6 +78,11 @@
   </pre>
   <p>sets the <code>jaxp.jar.present</code> property to the value &quot;true&quot;
   if the file <code>./lib/jaxp11/jaxp.jar</code> is found.</p>
  +<pre>
  +&lt;available file=&quot;/usr/local/lib&quot; type=&quot;dir&quot; property=&quot;local.lib.present&quot;/&gt;
  +</pre>
  +<p>sets the <code>local.lib.present</code> property to the value &quot;true&quot;
  +if the directory <code>/usr/local/lib</code> is found.</p>
   <pre>
   ...in project ...
   &lt;property name=&quot;jaxp.jar&quot; value=&quot;./lib/jaxp11/jaxp.jar&quot;/&gt;
  
  
  
  1.20      +22 -18    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java
  
  Index: Available.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Available.java	2001/04/30 23:25:36	1.19
  +++ Available.java	2001/05/03 07:41:08	1.20
  @@ -70,8 +70,8 @@
       private String property;
       private String classname;
       private File file;
  -    private File dir;
       private String resource;
  +    private String type;
       private Path classpath;
       private AntClassLoader loader;
       private String value = "true";
  @@ -113,21 +113,27 @@
           this.file = file;
       }
   
  -    public void setDir(File dir) {
  -        this.dir = dir;
  -    }
  -
       public void setResource(String resource) {
           this.resource = resource;
       }
   
  +    public void setType(String type) {
  +        this.type = type;
  +    }
  +
       public void execute() throws BuildException {
           if (property == null) {
               throw new BuildException("property attribute is required", location);
           }
           
  -        if (classname == null && file == null && dir == null && resource == null) {
  -            throw new BuildException("At least one of (classname|file|dir|resource) is required", location);
  +        if (classname == null && file == null && resource == null) {
  +            throw new BuildException("At least one of (classname|file|resource) is required", location);
  +        }
  +
  +        if (type != null){
  +            if (!type.equalsIgnoreCase("file") && !type.equalsIgnoreCase("dir")){
  +                throw new BuildException("Type must be one of either dir or file");
  +            }
           }
   
           if (classpath != null) {
  @@ -140,15 +146,10 @@
           }
           
           if ((file != null) && !checkFile(file)) {
  -            log("Unable to find file " + file + " to set property " + property, Project.MSG_VERBOSE);
  +            log("Unable to find " + file + " to set property " + property, Project.MSG_VERBOSE);
               return;
           }
           
  -        if ((dir != null) && !checkDir(dir)) {
  -            log("Unable to find dir " + dir + " to set property " + property, Project.MSG_VERBOSE);
  -            return;
  -        }
  -        
           if ((resource != null) && !checkResource(resource)) {
               log("Unable to load resource " + resource + " to set property " + property, Project.MSG_VERBOSE);
               return;
  @@ -158,11 +159,14 @@
       }
   
       private boolean checkFile(File file) {
  -        return file.isFile();
  -    }
  -
  -    private boolean checkDir(File dir) {
  -        return dir.isDirectory();
  +        if (type != null) {
  +            if (type.equalsIgnoreCase("dir")){
  +                return file.isDirectory();
  +            } else if (type.equalsIgnoreCase("file")){
  +                return file.isFile();
  +            }
  +        }
  +        return file.exists();
       }
   
       private boolean checkResource(String resource) {
  
  
  
  1.6       +3 -3      jakarta-ant/src/etc/testcases/taskdefs/available.xml
  
  Index: available.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/available.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- available.xml	2001/05/01 11:41:04	1.5
  +++ available.xml	2001/05/03 07:41:11	1.6
  @@ -80,17 +80,17 @@
   
     <target name="test16">
       <available property="test" 
  -               dir=""/>
  +               file="" type="dir"/>
     </target>
   
     <target name="test17">
       <available property="test" 
  -               dir="../taskdefs"/>
  +               file="../taskdefs" type="dir"/>
     </target>
   
     <target name="test18">
       <available property="test" 
  -               dir="../this_dir_should_never_exist"/>
  +               file="../this_dir_should_never_exist" type="dir"/>
     </target>
   
   </project>
  
  
  

Re: cvs commit: jakarta-ant/src/etc/testcases/taskdefs available.xml

Posted by Conor MacNeill <co...@cognet.com.au>.
From: "Stefan Bodewig" <bo...@apache.org>
To: <an...@jakarta.apache.org>
Sent: Thursday, May 03, 2001 6:18 PM
Subject: Re: cvs commit: jakarta-ant/src/etc/testcases/taskdefs
available.xml


> Diane Holt <ho...@yahoo.com> wrote:
>
> > --- Stefan Bodewig <bo...@apache.org> wrote:
> >> <ho...@apache.org> wrote:
> >>
> >> >   Added a "type" attribute instead, which works with the "file"
> >> >   attribute to specify either a file or a directory.
> >>
> >> I'd suggest to make this attribute accept file|dir|both and default
> >> to "both" - looks cleaner than making non-set a magic value.
> >
> > But then we're back to b-c issues,
>
> Not if we make "both" the default value - behavior would be the same
> as now, you don't specify type and everything is as it would have been
> in 1.3.

or should that be "either" - sorry :-)


Re: cvs commit: jakarta-ant/src/etc/testcases/taskdefs available.xml

Posted by Stefan Bodewig <bo...@apache.org>.
Diane Holt <ho...@yahoo.com> wrote:

> --- Stefan Bodewig <bo...@apache.org> wrote:
>> <ho...@apache.org> wrote:
>> 
>> >   Added a "type" attribute instead, which works with the "file"
>> >   attribute to specify either a file or a directory.
>> 
>> I'd suggest to make this attribute accept file|dir|both and default
>> to "both" - looks cleaner than making non-set a magic value.
> 
> But then we're back to b-c issues,

Not if we make "both" the default value - behavior would be the same
as now, you don't specify type and everything is as it would have been
in 1.3.  

The main advantage is that I could explicitly say type="both", if I
want to, instead of not setting this attribute at all.

Stefan

Re: cvs commit: jakarta-ant/src/etc/testcases/taskdefs available.xml

Posted by Diane Holt <ho...@yahoo.com>.
--- Stefan Bodewig <bo...@apache.org> wrote:
> <ho...@apache.org> wrote:
> 
> >   Added a "type" attribute instead, which works with the "file"
> >   attribute to specify either a file or a directory.
> 
> I'd suggest to make this attribute accept file|dir|both and default to
> "both" - looks cleaner than making non-set a magic value.

But then we're back to b-c issues, since 1.3 doesn't have the "type" attr,
and "file" already is "magical", since it currently works for either (and
which is what got me started on this in the first place -- I was looking
for a file, which it turned out didn't exist, but a directory by that name
did, but that wasn't what I was looking for).

Diane


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: cvs commit: jakarta-ant/src/etc/testcases/taskdefs available.xml

Posted by Stefan Bodewig <bo...@apache.org>.
<ho...@apache.org> wrote:

>   Added a "type" attribute instead, which works with the "file"
>   attribute to specify either a file or a directory.

I'd suggest to make this attribute accept file|dir|both and default to
"both" - looks cleaner than making non-set a magic value.

Stefan