ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Available.java defaults.properties Property.java Tstamp.java
Date Fri, 11 Feb 2000 01:31:25 GMT
stefano     00/02/10 17:31:25

  Modified:    src/main/org/apache/tools/ant/taskdefs defaults.properties
                        Property.java Tstamp.java
  Added:       src/main/org/apache/tools/ant/taskdefs Available.java
  Log:
  Added "available" task that sets a property in case a file|class|resource is present in
the system
  
  Also, added an init() method to Tasks and cleaned up Property task
  
  Revision  Changes    Path
  1.5       +4 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- defaults.properties	2000/02/10 18:04:29	1.4
  +++ defaults.properties	2000/02/11 01:31:24	1.5
  @@ -1,3 +1,4 @@
  +# standard ant tasks
   mkdir=org.apache.tools.ant.taskdefs.Mkdir
   javac=org.apache.tools.ant.taskdefs.Javac
   chmod=org.apache.tools.ant.taskdefs.Chmod
  @@ -23,5 +24,7 @@
   ant=org.apache.tools.ant.taskdefs.Ant
   exec=org.apache.tools.ant.taskdefs.Exec
   tar=org.apache.tools.ant.taskdefs.Tar
  -# remove the task below once everyone has migrated
  +available=org.apache.tools.ant.taskdefs.Available
  +
  +# deprecated ant tasks (kept for back compatibility)
   javadoc2=org.apache.tools.ant.taskdefs.Javadoc
  
  
  
  1.3       +74 -89    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Property.java	2000/01/14 02:13:19	1.2
  +++ Property.java	2000/02/11 01:31:24	1.3
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -9,7 +9,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -17,15 +17,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowlegement may appear in the software itself,
    *    if and wherever such third-party acknowlegements normally appear.
    *
    * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    from this software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache"
  @@ -57,100 +57,85 @@
   import org.apache.tools.ant.*;
   import java.io.*;
   import java.util.*;
  +
   /**
    * Will set a Project property. Used to be a hack in ProjectHelper
    *
    * @author costin@dnt.ro
    */
   public class Property extends Task {
  +
       private String name;
       private String value;
       private String file;
       private String resource;
  +
  +    public void setName(String name) {
  +        this.name = name;
  +    }
  +
  +    public void setValue(String value) {
  +        this.value = value;
  +    }
  +
  +    public void setFile(String file) {
  +        this.file = file;
  +    }
  +
  +    public void setResource(String resource) {
  +        this.resource = resource;
  +    }
  +
  +    public void init() throws BuildException {
  +        try {
  +            if ((name != null) && (value != null)) {
  +                String v = ProjectHelper.replaceProperties(value, project.getProperties());
  +                project.setProperty(name, v);
  +            }
  +
  +            if (file != null) loadFile(file);
  +
  +            if (resource != null) loadResource(resource);
  +
  +        } catch (Exception e) {
  +            throw new BuildException(e);
  +        }
  +    }
  +
  +    private void loadFile (String name) {
  +        Properties props = new Properties();
  +        project.log("Loading " + name, project.MSG_VERBOSE);
  +        try {
  +            if (new File(name).exists()) {
  +                props.load(new FileInputStream(name));
  +                addProperties(props);
  +            }
  +        } catch(Exception ex) {
  +            ex.printStackTrace();
  +        }
  +    }
  +
  +    private void loadResource( String name ) {
  +        Properties props = new Properties();
  +        project.log("Resource Loading " + name, project.MSG_VERBOSE);
  +        try {
  +            InputStream is = this.getClass().getResourceAsStream(name);
  +            if (is != null) {
  +                props.load(is);
  +                addProperties(props);
  +            }
  +        } catch (Exception ex) {
  +            ex.printStackTrace();
  +        }
  +    }
   
  -    /**
  -     * Needs to be set at XML-reading time,
  -     * no runtime action.
  -     *
  -     * @exception BuildException Thrown in unrecoverable error.
  -     */
  -    public void execute() throws BuildException {
  -    }
  -
  -    // XXX ugly - needs to be fixed
  -    /**
  -     * Called after each setter, will set the property at read-time
  -     */
  -    private void initTimeSetProperty()  {
  -	try {
  -	    if((name!=null) && (value!=null) ) {
  -		String value1= ProjectHelper.replaceProperties(value, project.getProperties());
  -		project.setProperty( name,value1);
  -	    }
  -				
  -	    if( file!=null)
  -		loadFile( file );
  -	    
  -	    if( resource!=null)
  -		loadResource( resource );
  -	} catch (Exception ex) {
  -	    ex.printStackTrace();
  -	}
  -    }
  -
  -    public void setName( String name) {
  -	this.name=name;
  -	initTimeSetProperty();
  -    }
  -
  -    public void setValue(String v) {
  -	value=v;
  -	initTimeSetProperty();
  -    }
  -
  -    public void setFile(String v) {
  -	file=v;
  -	initTimeSetProperty();
  -    }
  -
  -    public void setResource(String v) {
  -	resource=v;
  -	initTimeSetProperty();
  -    }
  -    
  -    private void loadFile( String name ) {
  -	Properties props = new Properties();
  -	project.log("Loading " + name, project.MSG_VERBOSE);
  -	try {
  -	    if( new File(name).exists() )
  -		props.load(new FileInputStream( name ));
  -	} catch(Exception ex) {
  -	    ex.printStackTrace();
  -	}
  -	addProperties( props );
  -    }    
  -	
  -    private  void loadResource( String name ) {
  -	Properties props = new Properties();
  -	project.log("Resource Loading " + name,
  -		    project.MSG_VERBOSE);
  -	try {
  -	    InputStream is=this.getClass().getResourceAsStream(name);
  -	    if(is!=null)
  -		props.load(is);
  -	} catch (Exception ex) {
  -	    ex.printStackTrace();
  -	}
  -	addProperties( props );
  -    }    
  -
  -    private void addProperties( Properties props) {
  -	Enumeration e=props.keys();
  -	while( e.hasMoreElements() ) {
  -	    String name=(String)e.nextElement();
  -	    String value=(String)props.getProperty(name);
  -	    String value1= ProjectHelper.replaceProperties(value, project.getProperties());
  -	    project.setProperty( name, value1);
  -	}
  +    private void addProperties(Properties props) {
  +        Enumeration e = props.keys();
  +        while (e.hasMoreElements()) {
  +            String name = (String) e.nextElement();
  +            String value = (String) props.getProperty(name);
  +            String v = ProjectHelper.replaceProperties(value, project.getProperties());
  +            project.setProperty(name, v);
  +        }
       }
   }
  
  
  
  1.3       +6 -7      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
  
  Index: Tstamp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Tstamp.java	2000/01/27 03:51:55	1.2
  +++ Tstamp.java	2000/02/11 01:31:24	1.3
  @@ -67,21 +67,20 @@
    */
   public class Tstamp extends Task {
   
  -    public void execute() throws BuildException {
  -
  +    public void init() throws BuildException {
           try {
               Date d = new Date();
  -            
  +
               SimpleDateFormat dstamp = new SimpleDateFormat ("yyyymmdd");
               project.setProperty("DSTAMP", dstamp.format(d));
  -    
  +
               SimpleDateFormat tstamp = new SimpleDateFormat ("hhmm");
               project.setProperty("TSTAMP", tstamp.format(d));
  -    
  +
               SimpleDateFormat today  = new SimpleDateFormat ("MMMM d yyyy", Locale.US);
               project.setProperty("TODAY", today.format(d));
  -        } catch (Exception ex) {
  -            ex.printStackTrace();
  +        } catch (Exception e) {
  +            throw new BuildException(e);
           }
       }
   }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java
  
  Index: Available.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.*;
  import java.io.*;
  import java.util.*;
  
  /**
   * Will set the given property if the requested resource is available at runtime.
   *
   * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
   */
  
  public class Available extends Task {
  
      private String property;
      private String classname;
      private String file;
      private String resource;
  
      public void setProperty(String property) {
          this.property = property;
      }
  
      public void setClass(String classname) {
          this.classname = classname;
      }
  
      public void setFile(String filename) {
          this.file = file;
      }
  
      public void setResource(String resource) {
          this.resource = resource;
      }
  
      public void init() throws BuildException {
          if ((classname != null) && !checkClass(classname)) return;
          if ((file != null) && !checkFile(file)) return;
          if ((resource != null) && !checkResource(resource)) return;
  
          this.project.setProperty(property, "true");
      }
  
      private boolean checkFile(String file) {
          try {
              File f = new File(file);
              return f.exists();
          } catch (Exception e) {
              return false;
          }
      }
  
      private boolean checkResource(String resource) {
          try {
              return (ClassLoader.getSystemResource(resource) != null);
          } catch (Exception e) {
              return false;
          }
      }
  
      private boolean checkClass(String classname) {
          try {
              Class.forName(classname);
              return true;
          } catch (Throwable t) {
              return false;
          }
      }
  }
  
  
  

Mime
View raw message