You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/07/30 22:14:49 UTC

cvs commit: jakarta-cactus/anttasks/src/java/org/apache/cactus/ant CheckPropertiesTask.java CheckPropertyItem.java PropertyName.java ArgListTask.java ArgListProperty.java

vmassol     2002/07/30 13:14:49

  Modified:    anttasks/src/java/org/apache/cactus/ant ArgListTask.java
  Added:       anttasks/src/java/org/apache/cactus/ant
                        CheckPropertiesTask.java CheckPropertyItem.java
                        PropertyName.java
  Removed:     anttasks/src/java/org/apache/cactus/ant ArgListProperty.java
  Log:
  added a new CheckProperties Ant task to check that proprties have been set
  
  Revision  Changes    Path
  1.2       +3 -3      jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/ArgListTask.java
  
  Index: ArgListTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/ArgListTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArgListTask.java	24 Feb 2002 23:49:05 -0000	1.1
  +++ ArgListTask.java	30 Jul 2002 20:14:49 -0000	1.2
  @@ -104,7 +104,7 @@
        *
        * @param theProperty the property to add to the list
        */
  -    public void addProperty(ArgListProperty theProperty)
  +    public void addProperty(PropertyName theProperty)
       {
           this.properties.addElement(theProperty);
       }
  @@ -135,7 +135,7 @@
           while (args.hasMoreElements()) {
   
               String propertyName =
  -                ((ArgListProperty) args.nextElement()).getName();
  +                ((PropertyName) args.nextElement()).getName();
   
               // Check if this property is defined
               String value = getProject().getProperty(propertyName);
  
  
  
  1.1                  jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/CheckPropertiesTask.java
  
  Index: CheckPropertiesTask.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 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", "Cactus" 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.cactus.ant;
  
  import java.util.Enumeration;
  import java.util.Vector;
  import java.io.File;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  
  /**
   * Check the existence of a list of properties, display their values and stop Ant if a property
   * does not exist.
   *
   * Example :<br>
   * <pre><code>
   * <property name="property1" value="value1"/>
   *
   * <checkProperties>
   *   <property name="property1" isfile="true|false"/>
   *   <property name="property2" isfile="true|false"/>
   * </checkProperties>
   * </code></pre>
   * <br>
   *
   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
   *
   * @version $Id: CheckPropertiesTask.java,v 1.1 2002/07/30 20:14:49 vmassol Exp $
   */
  public class CheckPropertiesTask extends Task
  {
      /**
       * List of Ant properties to check.
       */
      private Vector properties = new Vector();
  
      /**
       * Add a new property to the list of properties to check.
       *
       * @param theProperty the property to add to the list
       */
      public void addProperty(CheckPropertyItem theProperty)
      {
          this.properties.addElement(theProperty);
      }
  
      /**
       * Execute task.
       *
       * @see Task#execute()
       */
      public void execute() throws BuildException
      {
          Enumeration properties = this.properties.elements();
          while (properties.hasMoreElements()) {
  
              CheckPropertyItem property =
                      (CheckPropertyItem) properties.nextElement();
  
              String value = getProject().getProperty(property.getName());
              if (value == null) {
                  value = getProject().getUserProperty(property.getName());
                  if (value == null) {
                      // The property does not exist
                      throw new BuildException("The property ["
                              + property.getName() + "] is not defined");
                  }
              }
  
              // Print the property name/value
              log(property.getName() + " = [" + value + "]");
  
              // Check if the file/dir exist
              if (property.isFile()) {
                  File file = project.resolveFile(value);
                  if (!file.exists()) {
                      if (file.isDirectory()) {
                          throw new BuildException("The directory ["
                              + value + "] pointed by ["
                              + property.getName() + "] does not exist");
                      } else {
                          throw new BuildException("The file ["
                              + value + "] pointed by ["
                              + property.getName() + "] does not exist");
                      }
                  }
              }
          }
  
      }
  
  }
  
  
  
  1.1                  jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/CheckPropertyItem.java
  
  Index: CheckPropertyItem.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 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", "Cactus" 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.cactus.ant;
  
  /**
   * Data object for holding a Property for the <code>CheckProperties</code> task.
   *
   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
   *
   * @version $Id: CheckPropertyItem.java,v 1.1 2002/07/30 20:14:49 vmassol Exp $
   * @see ArgListTask
   */
  public class CheckPropertyItem extends PropertyName
  {
      /**
       * Is the property representing a file/directory ? If so we will check
       * whether the value it points to exsits on the file system.
       */
      private boolean isFile = false;
  
      /**
       * @param isFile true if the property represents a file or directory for
       *        which to check its existence.
       */
      public void setIsfile(boolean isFile)
      {
          this.isFile = isFile;
      }
  
      /**
       * @return true if the property represents a file or directory for which
       *         to check its existence.
       */
      public boolean isFile()
      {
          return this.isFile;
      }
  }
  
  
  1.1                  jakarta-cactus/anttasks/src/java/org/apache/cactus/ant/PropertyName.java
  
  Index: PropertyName.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 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", "Cactus" 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.cactus.ant;
  
  /**
   * Data object for holding a Property name.
   *
   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
   *
   * @version $Id: PropertyName.java,v 1.1 2002/07/30 20:14:49 vmassol Exp $
   * @see CheckPropertiesTask
   */
  public class PropertyName
  {
      /**
       * Name of the property
       */
      private String name;
  
      /**
       * @param theName the property's name
       */
      public void setName(String theName)
      {
          this.name = theName;
      }
  
      /**
       * @return the property's name
       */
      public String getName()
      {
          return this.name;
      }
  }
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>