ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types EnumeratedAttribute.java Path.java
Date Mon, 24 Jul 2000 16:05:30 GMT
bodewig     00/07/24 09:05:29

  Modified:    docs     index.html
               src/main/org/apache/tools/ant EnumeratedAttribute.java
                        IntrospectionHelper.java
               src/main/org/apache/tools/ant/taskdefs AntStructure.java
                        FixCRLF.java
  Added:       src/main/org/apache/tools/ant/types EnumeratedAttribute.java
                        Path.java
  Log:
  Moved EnumeratedAttribute to types as well.
  
  Revision  Changes    Path
  1.54      +1 -1      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- index.html	2000/07/20 13:25:49	1.53
  +++ index.html	2000/07/24 16:05:27	1.54
  @@ -3229,7 +3229,7 @@
       or any other type that has a constructor with a single <code>String</code>
       argument</li>
     <li>If your task has enumerated attributes, you should consider using
  -    a subclass of org.apache.tools.ant.EnumeratedAttribute as argument
  +    a subclass of org.apache.tools.ant.types.EnumeratedAttribute as argument
       to your setter method. See org.apache.tools.ant.taskdefs.FixCRLF for
       an example.</li>
     <li>If the task should support character data, write a <code>public void

  
  
  
  1.2       +3 -53     jakarta-ant/src/main/org/apache/tools/ant/EnumeratedAttribute.java
  
  Index: EnumeratedAttribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/EnumeratedAttribute.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EnumeratedAttribute.java	2000/07/12 14:06:18	1.1
  +++ EnumeratedAttribute.java	2000/07/24 16:05:28	1.2
  @@ -55,58 +55,8 @@
   package org.apache.tools.ant;
   
   /**
  - * Helper class for attributes that can only take one of a fixed list
  - * of values.
  + * This class has been moved to org.apache.tools.ant.types.
    *
  - * <p>See {@link org.apache.tools.ant.taskdefs.FixCRLF FixCRLF} for an
  - * example.
  - *
  - * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>

  + * @deprecated This class has been moved to org.apache.tools.ant.types.
    */
  -public abstract class EnumeratedAttribute {
  -
  -    protected String value;
  -
  -    /**
  -     * This is the only method a subclass needs to implement.
  -     *
  -     * @return an array holding all possible values of the enumeration.
  -     */
  -    public abstract String[] getValues();
  -
  -    public EnumeratedAttribute() {}
  -
  -    /**
  -     * Invoked by {@link IntrospectionHelper IntrospectionHelper}.
  -     */
  -    public final void setValue(String value) throws BuildException {
  -        if (!containsValue(value)) {
  -            throw new BuildException(value+" is not a legal value for this attribute");
  -        }
  -        this.value = value;
  -    }
  -
  -    /**
  -     * Is this value included in the enumeration?
  -     */
  -    public final boolean containsValue(String value) {
  -        String[] values = getValues();
  -        if (values == null || value == null) {
  -            return false;
  -        }
  -        
  -        for (int i=0; i<values.length; i++) {
  -            if (value.equals(values[i])) {
  -                return true;
  -            }
  -        }
  -        return false;
  -    }
  -
  -    /**
  -     * Retrieves the value.
  -     */
  -    public final String getValue() {
  -        return value;
  -    }
  -}
  +public abstract class EnumeratedAttribute {}
  
  
  
  1.8       +3 -3      jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IntrospectionHelper.java	2000/07/24 15:52:53	1.7
  +++ IntrospectionHelper.java	2000/07/24 16:05:28	1.8
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant;
   
   import org.apache.tools.ant.types.Path;
  +import org.apache.tools.ant.types.EnumeratedAttribute;
   
   import java.lang.reflect.*;
   import java.io.File;
  @@ -460,13 +461,12 @@
                   };
   
           // EnumeratedAttributes have their own helper class
  -        } else if (org.apache.tools.ant.EnumeratedAttribute.class.isAssignableFrom(arg))
{
  +        } else if (org.apache.tools.ant.types.EnumeratedAttribute.class.isAssignableFrom(arg))
{
               return new AttributeSetter() {
                       public void set(Project p, Object parent, String value) 
                           throws InvocationTargetException, IllegalAccessException, BuildException
{
                           try {
  -                            EnumeratedAttribute ea = 
  -                                (EnumeratedAttribute)arg.newInstance();
  +                            org.apache.tools.ant.types.EnumeratedAttribute ea = (org.apache.tools.ant.types.EnumeratedAttribute)arg.newInstance();
                               ea.setValue(value);
                               m.invoke(parent, new EnumeratedAttribute[] {ea});
                           } catch (InstantiationException ie) {
  
  
  
  1.4       +6 -2      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  
  Index: AntStructure.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AntStructure.java	2000/07/21 12:42:54	1.3
  +++ AntStructure.java	2000/07/24 16:05:29	1.4
  @@ -54,7 +54,11 @@
   
   package org.apache.tools.ant.taskdefs;
   
  -import org.apache.tools.ant.*;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.IntrospectionHelper;
  +import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.types.EnumeratedAttribute;
   
   import java.util.Enumeration;
   import java.util.Hashtable;
  @@ -64,7 +68,7 @@
   /**
    * Creates a partial DTD for Ant from the currently known tasks.
    *
  - * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>
  + * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
    */
   
   public class AntStructure extends Task {
  
  
  
  1.12      +5 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FixCRLF.java	2000/07/12 14:05:12	1.11
  +++ FixCRLF.java	2000/07/24 16:05:29	1.12
  @@ -54,7 +54,11 @@
   
   package org.apache.tools.ant.taskdefs;
   
  -import org.apache.tools.ant.*;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.DirectoryScanner;
  +import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.types.EnumeratedAttribute;
  +
   import java.io.*;
   import java.util.*;
   import java.text.*;
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java
  
  Index: EnumeratedAttribute.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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.types;
  
  import org.apache.tools.ant.BuildException;
  
  /**
   * Helper class for attributes that can only take one of a fixed list
   * of values.
   *
   * <p>See {@link org.apache.tools.ant.taskdefs.FixCRLF FixCRLF} for an
   * example.
   *
   * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>

   */
  public abstract class EnumeratedAttribute {
  
      protected String value;
  
      /**
       * This is the only method a subclass needs to implement.
       *
       * @return an array holding all possible values of the enumeration.
       */
      public abstract String[] getValues();
  
      public EnumeratedAttribute() {}
  
      /**
       * Invoked by {@link IntrospectionHelper IntrospectionHelper}.
       */
      public final void setValue(String value) throws BuildException {
          if (!containsValue(value)) {
              throw new BuildException(value+" is not a legal value for this attribute");
          }
          this.value = value;
      }
  
      /**
       * Is this value included in the enumeration?
       */
      public final boolean containsValue(String value) {
          String[] values = getValues();
          if (values == null || value == null) {
              return false;
          }
          
          for (int i=0; i<values.length; i++) {
              if (value.equals(values[i])) {
                  return true;
              }
          }
          return false;
      }
  
      /**
       * Retrieves the value.
       */
      public final String getValue() {
          return value;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
  
  Index: Path.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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.types;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.PathTokenizer;
  
  import java.io.File;
  import java.util.Vector;
  import java.util.StringTokenizer;
  import java.text.CharacterIterator;
  import java.text.StringCharacterIterator;
  
  /**
   * This object represents a path as used by CLASSPATH or PATH
   * environment variable.
   *
   * <code>
   * &lt;sometask&gt;<br>
   * &nbsp;&nbsp;&lt;somepath&gt;
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="/path/to/file.jar"
/&gt;
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement path="/path/to/file2.jar:/path/to/class2;/path/to/class3"
/&gt;
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="/path/to/file3.jar"
/&gt;
   * &nbsp;&nbsp;&nbsp;&nbsp;&lt;pathelement location="/path/to/file4.jar"
/&gt;
   * &nbsp;&nbsp;&lt;/somepath&gt;
   * &lt;/sometask&gt;<br>
   * </code>
   *
   * The object implemention <code>sometask</code> must provide a method called
   * <code>createSomepath</code> which returns an instance of <code>Path</code>.
   * Nested path definitions are handled by the Path object and must be labeled
   * <code>pathelement</code>.<p>
   *
   * The path element takes a parameter <code>path</code> which will be parsed
   * and split into single elements. It will usually be used
   * to define a path from an environment variable.
   *
   * @author Thomas.Haas@softwired-inc.com
   * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> 
   */
  
  public class Path {
  
      private Vector definition;
      private Project project;
  
      public static Path systemClasspath = 
          new Path(null, System.getProperty("java.class.path"));
  
      public Path(Project p, String path) {
          this(p);
          setPath(path);
      }
  
      public Path(Project p) {
          this.project = project;
          definition = new Vector();
      }
  
      /**
       * Adds a element definition to the path.
       * @param location the location of the element to add (must not be
       * <code>null</code> nor empty.
       */
      public void setLocation(String location) {
          if (location != null && location.length() > 0) {
              String element = translateFile(resolveFile(project, location));
              if (definition.indexOf(element) == -1) {
                  definition.addElement(element);
              }
          }
      }
  
  
      /**
       * Append the contents of the other Path instance to this.
       */
      public void append(Path other) {
          String[] l = other.list();
          for (int i=0; i<l.length; i++) {
              if (definition.indexOf(l[i]) == -1) {
                  definition.addElement(l[i]);
              }
          }
      }
  
      /**
       * Parses a path definition and creates single PathElements.
       * @param path the path definition.
       */
      public void setPath(String path) {
          final Vector elements = translatePath(project, path);
          for (int i=0; i < elements.size(); i++) {
              String element = (String) elements.elementAt(i);
              if (definition.indexOf(element) == -1) {
                  definition.addElement(element);
              }
          }
      }
  
  
      public Path createPathElement() {
          return this;
      }
  
  
      /**
       * Returns all path elements defined by this and netsed path objects.
       * @return list of path elements.
       */
      public String[] list() {
          final String[] result = new String[definition.size()];
          definition.copyInto(result);
          return result;
      }
  
  
      /**
       * Returns a textual representation of the path, which can be used as
       * CLASSPATH or PATH environment variable definition.
       * @return a textual representation of the path.
       */
      public String toString() {
          final String[] list = list();
  
          // empty path return empty string
          if (list.length == 0) return "";
  
          // path containing one or more elements
          final StringBuffer result = new StringBuffer(list[0].toString());
          for (int i=1; i < list.length; i++) {
              result.append(File.pathSeparatorChar);
              result.append(list[i]);
          }
  
          return result.toString();
      }
  
  
  
      public static Vector translatePath(Project project, String source) {
          final Vector result = new Vector();
          if (source == null) return result;
  
          PathTokenizer tok = new PathTokenizer(source);
          StringBuffer element = new StringBuffer();
          while (tok.hasMoreTokens()) {
              element.setLength(0);
              element.append(resolveFile(project, tok.nextToken()));
              for (int i=0; i<element.length(); i++) {
                  translateFileSep(element, i);
              }
              result.addElement(element.toString());
          }
          return result;
      }
  
  
      public static String translateFile(String source) {
          if (source == null) return "";
  
          final StringBuffer result = new StringBuffer(source);
          for (int i=0; i < result.length(); i++) {
              translateFileSep(result, i);
          }
  
          return result.toString();
      }
  
  
      protected static boolean translateFileSep(StringBuffer buffer, int pos) {
          if (buffer.charAt(pos) == '/' || buffer.charAt(pos) == '\\') {
              buffer.setCharAt(pos, File.separatorChar);
              return true;
          }
          return false;
      }
  
      public int size() {
          return definition.size();
      }
  
      private static String resolveFile(Project project, String relativeName) {
          if (project != null) {
              return project.resolveFile(relativeName).getAbsolutePath();
          }
          return relativeName;
      }
  
  }
  
  
  

Mime
View raw message