ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs PreSetDefTest.java
Date Fri, 24 Sep 2004 08:45:50 GMT
peterreilly    2004/09/24 01:45:50

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant IntrospectionHelper.java
                        RuntimeConfigurable.java UnknownElement.java
               src/etc/testcases/taskdefs presetdef.xml
               src/testcases/org/apache/tools/ant/taskdefs
                        PreSetDefTest.java
  Added:       src/main/org/apache/tools/ant
                        UnsupportedAttributeException.java
                        UnsupportedElementException.java
  Log:
  Try to get the correct task/type name for an unsupported attribute/element
  exception thrown by IntrospectionHelper
  PR: 31389 and 29499
  Reported by: Tamas Szeredi and Jesse Glick
  
  Revision  Changes    Path
  1.663     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.662
  retrieving revision 1.663
  diff -u -r1.662 -r1.663
  --- WHATSNEW	24 Sep 2004 08:13:25 -0000	1.662
  +++ WHATSNEW	24 Sep 2004 08:45:49 -0000	1.663
  @@ -23,6 +23,9 @@
     <exec>, <apply>, or <java> tasks was always logged to System.out
     instead of to the managing Task.
   
  +* Incorrect task name with invalid "javac" task after a "presetdef.
  +  Bugzilla reports 31389 and 29499.
  +
   Other changes:
   --------------
   
  
  
  
  1.90      +6 -6      ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.89
  retrieving revision 1.90
  diff -u -r1.89 -r1.90
  --- IntrospectionHelper.java	13 Sep 2004 09:11:47 -0000	1.89
  +++ IntrospectionHelper.java	24 Sep 2004 08:45:49 -0000	1.90
  @@ -490,7 +490,7 @@
                   String msg = getElementName(p, element)
                       + " doesn't support the \"" + attributeName
                       + "\" attribute.";
  -                throw new BuildException(msg);
  +                throw new UnsupportedAttributeException(msg, attributeName);
               }
           }
           try {
  @@ -564,7 +564,7 @@
           String elementName) {
           String msg = project.getElementName(parent)
               + " doesn't support the nested \"" + elementName + "\" element.";
  -        throw new BuildException(msg);
  +        throw new UnsupportedElementException(msg, elementName);
       }
   
       private NestedCreator getNestedCreator(
  @@ -825,7 +825,7 @@
               String msg = "Class " + bean.getName()
                   + " doesn't support the nested \"" + elementName
                   + "\" element.";
  -            throw new BuildException(msg);
  +            throw new UnsupportedElementException(msg, elementName);
           }
           return nt;
       }
  @@ -848,7 +848,7 @@
           if (at == null) {
               String msg = "Class " + bean.getName()
                   + " doesn't support the \"" + attributeName + "\" attribute.";
  -            throw new BuildException(msg);
  +            throw new UnsupportedAttributeException(msg, attributeName);
           }
           return at;
       }
  @@ -892,7 +892,7 @@
               String msg = "Class " + bean.getName()
                   + " doesn't support the nested \"" + elementName
                   + "\" element.";
  -            throw new BuildException(msg);
  +            throw new UnsupportedElementException(msg, elementName);
           }
           return ((NestedCreator) creator).method;
       }
  @@ -914,7 +914,7 @@
           if (setter == null) {
               String msg = "Class " + bean.getName()
                   + " doesn't support the \"" + attributeName + "\" attribute.";
  -            throw new BuildException(msg);
  +            throw new UnsupportedAttributeException(msg, attributeName);
           }
           return ((AttributeSetter) setter).method;
       }
  
  
  
  1.53      +19 -2     ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
  
  Index: RuntimeConfigurable.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- RuntimeConfigurable.java	17 Jul 2004 16:31:40 -0000	1.52
  +++ RuntimeConfigurable.java	24 Sep 2004 08:45:50 -0000	1.53
  @@ -364,9 +364,26 @@
                   value = p.replaceProperties(value);
                   try {
                       ih.setAttribute(p, target, name, value);
  -                } catch (BuildException be) {
  +                } catch (UnsupportedAttributeException be) {
                       // id attribute must be set externally
  -                    if (!name.equals("id")) {
  +                    if (name.equals("id")) {
  +                        // Do nothing
  +                    } else  if (getElementTag() == null) {
  +                        throw be;
  +                    } else {
  +                        be.setMessage(
  +                            getElementTag()
  +                            +  " doesn't support the \""
  +                            + be.getAttribute()
  +                            + "\" attribute");
  +                        throw be;
  +                    }
  +                } catch (BuildException be) {
  +                    if (name.equals("id")) {
  +                        // Assume that this is an not supported attribute type
  +                        // thrown for example by a dymanic attribute task
  +                        // Do nothing
  +                    } else {
                           throw be;
                       }
                   }
  
  
  
  1.82      +19 -11    ant/src/main/org/apache/tools/ant/UnknownElement.java
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.81
  retrieving revision 1.82
  diff -u -r1.81 -r1.82
  --- UnknownElement.java	10 Jun 2004 18:01:47 -0000	1.81
  +++ UnknownElement.java	24 Sep 2004 08:45:50 -0000	1.82
  @@ -328,17 +328,25 @@
               for (int i = 0; it.hasNext(); i++) {
                   RuntimeConfigurable childWrapper = parentWrapper.getChild(i);
                   UnknownElement child = (UnknownElement) it.next();
  -                if (!handleChild(
  -                        parentUri, ih, parent, child, childWrapper)) {
  -                    if (!(parent instanceof TaskContainer)) {
  -                        ih.throwNotSupported(getProject(), parent,
  -                                             child.getTag());
  -                    } else {
  -                        // a task container - anything could happen - just add the
  -                        // child to the container
  -                        TaskContainer container = (TaskContainer) parent;
  -                        container.addTask(child);
  +                try {
  +                    if (!handleChild(
  +                            parentUri, ih, parent, child, childWrapper)) {
  +                        if (!(parent instanceof TaskContainer)) {
  +                            ih.throwNotSupported(getProject(), parent,
  +                                                 child.getTag());
  +                        } else {
  +                            // a task container - anything could happen - just add the
  +                            // child to the container
  +                            TaskContainer container = (TaskContainer) parent;
  +                            container.addTask(child);
  +                        }
                       }
  +                } catch (UnsupportedElementException ex) {
  +                    ex.setMessage(
  +                        parentWrapper.getElementTag()
  +                        + " doesn't support the nested \"" + ex.getElement()
  +                        + "\" element.");
  +                    throw ex;
                   }
               }
           }
  @@ -530,7 +538,7 @@
   
       /**
        * Set the configured object
  -     *
  +     * @param realThing the configured object
        * @since ant 1.7
        */
       public void setRealThing(Object realThing) {
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/UnsupportedAttributeException.java
  
  Index: UnsupportedAttributeException.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant;
  
  /**
   * Used to report attempts to set an unsupported attribute
   *
   * @since Ant 1.7
   */
  public class UnsupportedAttributeException extends BuildException {
  
      private String myMessage;
      private String attribute;
  
      /**
       * Constructs an unsupport attribute exception
       * @param msg       The string containing the message
       * @param attribute The unsupported attribute
       */
      public UnsupportedAttributeException(String msg, String attribute) {
          super(msg);
          this.attribute = attribute;
          this.myMessage = msg;
      }
  
      /**
       * The attribute that is wrong
       *
       * @return the attribute name
       */
      public String getAttribute() {
          return attribute;
      }
  
      /**
       * Override throwable#getMessage
       * @return the message
       */
      public String getMessage() {
          return myMessage;
      }
  
      /**
       * Set the message
       * @param message a new message
       */
      public void setMessage(String message) {
          this.myMessage = message;
      }
  }
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/UnsupportedElementException.java
  
  Index: UnsupportedElementException.java
  ===================================================================
  /*
   * Copyright  2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant;
  
  /**
   * Used to report attempts to set an unsupported element
   * When the attempt to set the element is made,
   * the code does not not know the name of the task/type
   * based on a mapping from the classname to the task/type.
   * However one class may be used by a lot of task/types.
   * This exception may be caught by code that does know
   * the task/type and it will reset the message to the
   * correct message.
   * This will be done once (in the case of a recursive
   * call to handlechildren).
   *
   * @since Ant 1.6.3 or Ant 1.7 ?
   */
  public class UnsupportedElementException extends BuildException {
  
      private String  myMessage = null;
      private String  element;
  
      /**
       * Constructs an unsupport element exception
       * @param msg The string containing the message
       * @param element The name of the incorrect element
       */
      public UnsupportedElementException(String msg, String element) {
          super(msg);
          this.element = element;
      }
  
      /**
       * The element that is wrong
       *
       * @return the element name
       */
      public String getElement() {
          return element;
      }
  
      /**
       * Override throwable#getMessage
       * @return the message
       */
      public String getMessage() {
          if (myMessage == null) {
              return super.getMessage();
          } else {
              return myMessage;
          }
      }
  
      /**
       * Set the message (If not set already)
       * @param message a new message
       */
      public void setMessage(String message) {
          if (this.myMessage == null) {
              this.myMessage = message;
          }
      }
  }
  
  
  
  1.4       +18 -0     ant/src/etc/testcases/taskdefs/presetdef.xml
  
  Index: presetdef.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/presetdef.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- presetdef.xml	13 Jan 2004 10:39:54 -0000	1.3
  +++ presetdef.xml	24 Sep 2004 08:45:50 -0000	1.4
  @@ -100,4 +100,22 @@
       </el.order2>
     </target>
   
  +  <target name="correct_taskname_badattr">
  +    <presetdef name="mytask">
  +       <javac srcdir="whatever"/>
  +    </presetdef>
  +
  +    <javac srcdir="whatever" badattr="whatever"/>
  +  </target>
  +
  +  <target name="correct_taskname_badel">
  +    <presetdef name="mytask">
  +       <javac srcdir="whatever"/>
  +    </presetdef>
  +
  +    <javac srcdir="whatever">
  +      <badel/>
  +    </javac>
  +  </target>
  +
   </project>
  
  
  
  1.8       +11 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/PreSetDefTest.java
  
  Index: PreSetDefTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/PreSetDefTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PreSetDefTest.java	9 Mar 2004 16:48:57 -0000	1.7
  +++ PreSetDefTest.java	24 Sep 2004 08:45:50 -0000	1.8
  @@ -70,6 +70,17 @@
           expectLog("antTypeTest", "");
       }
   
  +    public void testCorrectTaskNameBadAttr() {
  +        expectBuildExceptionContaining(
  +            "correct_taskname_badattr", "attribute message", "javac doesn't support the");
  +    }
  +
  +    public void testCorrectTaskNameBadEl() {
  +        expectBuildExceptionContaining(
  +            "correct_taskname_badel", "element message", "javac doesn't support the");
  +    }
  +    
  +    
       /**
        * A test class to check default properties
        */
  
  
  

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


Mime
View raw message