vmassol     2002/06/04 05:08:52

  Modified:    src/java/org/apache/maven/ant Ant.java
  Added:       src/java/org/apache/maven/ant UserProperty.java
  Log:
  added support for both Ant 1.4 and Ant 1.5 for user properties (it was breaking for 
Ant 1.5). Please give it a try and tell me if it works for you.
  
  Revision  Changes    Path
  1.6       +13 -12    jakarta-turbine-maven/src/java/org/apache/maven/ant/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/ant/Ant.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Ant.java  27 May 2002 12:25:44 -0000      1.5
  +++ Ant.java  4 Jun 2002 12:08:52 -0000       1.6
  @@ -70,6 +70,7 @@
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.lang.reflect.Method;
  +import java.lang.reflect.Constructor;
   import java.util.Vector;
   import java.util.Hashtable;
   import java.util.Enumeration;
  @@ -92,6 +93,7 @@
    *
    *
    * @author [EMAIL PROTECTED]
  + * @author <a href="[EMAIL PROTECTED]">Vincent Massol</a>
    *
    * @since Ant 1.1
    *
  @@ -143,7 +145,7 @@
        * If true, inherit all properties from parent Project
        * If false, inherit only userProperties and those defined
        * inside the ant call itself
  -     * @param value the new value of {@link inheritAll}
  +     * @param value the new value of {@link #inheritAll}
        */
       public void setInheritAll(boolean value) 
       {
  @@ -154,7 +156,7 @@
        * If true, inherit all references from parent Project
        * If false, inherit only those defined
        * inside the ant call itself
  -     * @param value the new value of {@link inheritRefs}
  +     * @param value the new value of {@link #inheritRefs}
        */
       public void setInheritRefs(boolean value)
       {
  @@ -730,7 +732,9 @@
           this.output = s;
       }
   
  -    /** create a property to pass to the new project as a 'user property' 
  +    /**
  +     * Create a property to pass to the new project as a 'user property'.
  +     *
        * @return the created {@link Property}
        */
       public Property createProperty()
  @@ -739,15 +743,12 @@
           {
               reinit();
           }
  -        //Property p = new Property(true);
  -        // Make 1.5 <ant> work with 1.4 base. jvz.
  -        Property p = new Property();
  -        p.setUserProperty(true);
  -        
  -        p.setProject(newProject);
  -        p.setTaskName("property");
  -        properties.addElement(p);
  -        return p;
  +
  +        UserProperty property = new UserProperty();
  +        property.setProject(newProject);
  +        property.setTaskName("property");
  +        properties.addElement(property);
  +        return property;
       }
   
       /**
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/ant/UserProperty.java
  
  Index: UserProperty.java
  ===================================================================
  package org.apache.maven.ant;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   *
   * ====================================================================
   */
  
  import org.apache.tools.ant.taskdefs.Property;
  
  import java.lang.reflect.Field;
  import java.lang.reflect.Method;
  
  /**
   * Extension to Ant Property object to provide support for user property for
   * both Ant 1.4 and Ant 1.5.
   *
   * @author <a href="[EMAIL PROTECTED]">Vincent Massol</a>
   * @version $Id: UserProperty.java,v 1.1 2002/06/04 12:08:52 vmassol Exp $
   */
  public class UserProperty extends Property
  {
      /**
       * Initialise the Ant property task so that the property is a user
       * property (works for Ant 1.4 and 1.5).
       */
      public UserProperty()
      {
          super();
  
          if (isAnt15())
          {
              try
              {
                  Field userProperty =
                      Property.class.getDeclaredField("userProperty");
                  userProperty.setBoolean(this, true);
              }
              catch (Exception e)
              {
                  e.printStackTrace();
                  throw new RuntimeException(
                      "Failed to set 'userProperty' field for Ant property");
              }
          }
          else
          {
              try
              {
                  Method method = Property.class.getMethod("setUserProperty",
                      new Class[] { boolean.class });
                  method.invoke(this, new Object[] { Boolean.TRUE });
              }
              catch (Exception e)
              {
                  e.printStackTrace();
                  throw new RuntimeException(
                      "Failed to call 'setUserProperty(boolean)'");
              }
          }
      }
  
      /**
       * @return true if Ant 1.5 or above is used
       */
      private boolean isAnt15()
      {
          boolean isAnt15;
          try
          {
              this.getClass().getMethod("setPrefix",
                  new Class[] { String.class });
              isAnt15 = true;
          }
          catch (Exception e)
          {
              isAnt15 = false;
          }
          return isAnt15;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to