dion        2003/07/29 17:50:38

  Modified:    src/plugins-build/file-activity/src/plugin-resources
                        maven-file-activity-plugin.jsl
               src/plugins-build/junit-report/src/plugin-resources
                        junit.jsl
               src/plugins-build/xdoc plugin.jelly
               src/plugins-build/jdepend/src/plugin-resources jdepend.jsl
               src/plugins-build/checkstyle/src/plugin-resources
                        checkstyle.jsl
               src/plugins-build/pmd/src/plugin-resources pmd.jsl
               src/plugins-build/cactus/src/plugin-resources cactus.jsl
  Added:       src/java/org/apache/maven/util DVSLFormatter.java
                        StringTool.java MavenTool.java DVSLPathTool.java
               src/test/java/org/apache/maven/util MavenToolTest.java
                        DVSLPathToolTest.java DVSLFormatterTest.java
                        StringToolTest.java
  Removed:     src/test/java/org/apache/maven StringToolTest.java
                        DVSLFormatterTest.java MavenToolTest.java
                        DVSLPathToolTest.java
               src/java/org/apache/maven DVSLFormatter.java MavenTool.java
                        DVSLPathTool.java StringTool.java
  Log:
  Move utility classes to util package
  
  Revision  Changes    Path
  1.1                  maven/src/java/org/apache/maven/util/DVSLFormatter.java
  
  Index: DVSLFormatter.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 java.text.DecimalFormat;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Formatting tool for use with the DVSL toolbox.  This class contains
   * static methods to assist in formatting needs that can't be done or
   * shouldn't be done in a DVSL stylesheet.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pete Kazmier</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
   * @version $Id: DVSLFormatter.java,v 1.1 2003/07/30 00:50:37 dion Exp $
   * @todo move to org.apache.maven.util or make a jelly tag
   */
  public class DVSLFormatter
  {
      /**
       * Instance of a formatter.
       */
      private static DecimalFormat formatter = new DecimalFormat();
      
      /**
       * Log for debug output
       */
      private static Log log = LogFactory.getLog(DVSLFormatter.class);
  
      /**
       * Formats a string as a number using the specified pattern.
       * Patterns are specified using the same format as <code>
       * java.text.DecimalFormat</code>.
       * <p/>
       * This method is thread-hostile.
       *
       * @see java.text.DecimalFormat
       * @param value The number to format.
       * @param pattern The pattern used to format.
       * @return A string formatted using the specified pattern.
       * @throws IllegalArgumentException If an invalid pattern is
       * specified.
       */
      public static final String formatNumber( final String value, final String 
pattern )
      {
          log.debug("value = '" + value + "', pattern = '" + pattern + "'");
          if ( pattern == null || value == null )
          {
              return "<error formatting: '" + value + "' with '" + pattern + "'>";
          }
  
          String ret = null;
  
          try
          {
              formatter = new DecimalFormat(pattern);
              Number valueAsNumber = Double.valueOf(value.trim());
  
              if (pattern.indexOf(".") != -1 || pattern.indexOf("%") != -1)
              {
                  // parse as a decimal
                  ret = formatter.format( valueAsNumber.doubleValue() );
              }
              else
              {
                  // parse as an integer
                  formatter.setParseIntegerOnly(true);
                  ret = formatter.format(valueAsNumber.longValue());
              }
              log.debug("ret='" + ret + "'");
  
          }
          catch ( Exception e )
          {
              log.error("<error formatting: '" + value + "' with '" + pattern + "'>", 
e);
              return "<error formatting: '" + value + "' with '" + pattern + "'>";
          }
  
          return ret;
      }
  }
  
  
  
  1.1                  maven/src/java/org/apache/maven/util/StringTool.java
  
  Index: StringTool.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 java.util.Arrays;
  import java.util.List;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
   * @version $Id: StringTool.java,v 1.1 2003/07/30 00:50:37 dion Exp $
   * @todo move to org.apache.maven.util or make a jelly tag
   */
  public class StringTool
  {
  
      /**
       * Splits a string at the last delimiter. If no delimiter is found,
       * first element is the string, second element is empty string.
       * @param s the string to be split
       * @param delim the delimiter
       * @return String[] a two element array, element 0 = string up to last delim 
(exclusive), element 1 = string past
       * last delim (exclusive)
       */
      public List splitStringAtLastDelim(String s, String delim)
      {
          if (s == null)
          {
              String[] result = { null, null };
              return Arrays.asList(result);
          }
  
          int index = s.lastIndexOf(delim);
  
          if (index == -1)
          {
              String[] result = { s, "" };
              return Arrays.asList(result);
          }
          else
          {
              String[] result = { s.substring(0, index), s.substring(index + 1)};
              return Arrays.asList(result);
          }
      }
  }
  
  
  
  1.1                  maven/src/java/org/apache/maven/util/MavenTool.java
  
  Index: MavenTool.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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.maven.project.Project;
  import org.apache.tools.ant.types.Path;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeMap;
  import java.util.TreeSet;
  
  /**
   * Context/pull tool for use in MavenSession templates.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
   */
  public class MavenTool
  {
      /** The maven project the tool is processing */
      private Project project;
      /** list of items to be counted. Key is the object, value is a list
       of objects that have been added that are equal */
      private Map counted = new HashMap();
      /** the counted items in ascending order of number of times counted */
      private Map countedItems = null;
      /** the counted items in descending order of number of times counted */
      private Map countedItemsReversed = null;
  
      /**
       * Creates a new instance.
       */
      public MavenTool()
      {
          // FIXME: Need a path to the project descriptor.
          //project = MavenUtils.getProject("project.xml");
      }
  
      /**
       * Accessor for the project property.
       * @return the maven project being processed
       */
      public Project getProject()
      {
          return project;
      }
  
      /**
       * Resolves a path fragment for the first resource found in
       * <code>directories</code>.
       *
       * <blockquote><code><pre>
       * #set ($pathFragment =
       * $maven.resolvePathFragment($context.toolbox.string.basedir, "foo/bar",
       * ${src.set}))
       * </pre></code></blockquote>
       *
       * @param baseDir The directory to which <code>directories</code>
       * are relative.
       * @param resource The path to the resource to find in
       * <code>directories</code>.
       * @param directories The list of paths to search for
       * <code>resource</code> in..
       * @return The path fragment to <code>resource</code>.
       */
      public String resolvePathFragment( String baseDir, String resource,
                                         Path directories )
      {
          return resolvePathFragment( baseDir, resource, directories.list() );
      }
  
      /**
       * Called by [EMAIL PROTECTED] #resolvePathFragment(String, String, Path)}.
       *
       * @see #resolvePathFragment(String, String, Path)
       */
      protected final String resolvePathFragment( String baseDir, String resource,
                                                  String[] paths )
      {
          String path = null;
          for ( int i = 0; i < paths.length; i++ )
          {
              path = paths[i];
              File d = new File( baseDir, path );
              if ( d.isDirectory() && new File( d, resource ).exists() )
              {
                  break;
              }
              else
              {
                  // Avoid returning a bogus value on the last iteration.
                  path = null;
              }
          }
          if ( path == null )
          {
              System.err.println( "Unable to resolve " + resource
                                  + " using a base diretory of " + baseDir );
          }
          return path;
      }
  
      /**
       * Clear the counter so that there are zero items
       */
      public void resetCount()
      {
          getCounted().clear();
      }
  
      /**
       * Add an object to the list of counted items.
       * @param object the item to be added.
       */
      public void addToCount( Object object )
      {
          List list = null;
          if ( getCounted().get( object ) == null )
          {
              list = new ArrayList();
          }
          else
          {
              list = (List) getCounted().get( object );
          }
          list.add( object );
          getCounted().put( object, list );
          if ( getCountedItems() != null )
          {
              setCountedItems( null );
              setCountedItemsReversed( null );
          }
      }
  
      /** Fill the provided sorting map of items from the counted items
       * @param map a map that will sort the objects added to it
       */
      private void fillSortingMap( Map map )
      {
          List list = null;
          Object key = null;
          for ( Iterator index = counted.keySet().iterator(); index.hasNext(); )
          {
              key = index.next();
              list = (List) counted.get( key );
              Integer count = new Integer( list.size() );
              Set items = null;
              if ( !map.containsKey( count ) )
              {
                  items = new TreeSet();
              }
              else
              {
                  items = (Set) map.get( count );
              }
              items.add( key );
              map.put( count, items );
          }
      }
  
      /**
       * get a list of counted items with the key being the number of times
       * counted (in descending order) and the value any arbitrary item that was
       * counted
       * @return a sorted map of #times counted -> list of objects
       */
      public Map getCountDescending()
      {
          if ( getCountedItemsReversed() == null )
          {
              setCountedItemsReversed( new TreeMap( Collections.reverseOrder() ) );
              fillSortingMap( getCountedItemsReversed() );
          }
          return getCountedItemsReversed();
      }
  
      /**
       * get a list of counted items with the key being the number of times
       * counted and the value any arbitrary item that was counted
       * @return a sorted map of #times counted -> list of objects
       */
      public Map getCount()
      {
          if ( getCountedItems() == null )
          {
              setCountedItems( new TreeMap() );
              fillSortingMap( getCountedItems() );
          }
          return getCountedItems();
      }
  
      /** Getter for property counted.
       * @return Value of property counted.
       */
      private Map getCounted()
      {
          return counted;
      }
  
      /** Getter for property countedItems.
       * @return Value of property countedItems.
       */
      private Map getCountedItems()
      {
          return countedItems;
      }
  
      /** Setter for property countedItems.
       * @param countedItems New value of property countedItems.
       */
      private void setCountedItems( Map countedItems )
      {
          this.countedItems = countedItems;
      }
  
      /** Getter for property countedItemsReversed.
       * @return Value of property countedItemsReversed.
       */
      private Map getCountedItemsReversed()
      {
          return countedItemsReversed;
      }
  
      /** Setter for property countedItemsReverse.
       * @param countedItemsReversed New value of property countedItemsReverse.
       */
      private void setCountedItemsReversed( Map countedItemsReversed )
      {
          this.countedItemsReversed = countedItemsReversed;
      }
  
      public Integer toInteger( String s )
      {
          return Integer.valueOf( s );
      }
  }
  
  
  
  1.1                  maven/src/java/org/apache/maven/util/DVSLPathTool.java
  
  Index: DVSLPathTool.java
  ===================================================================
  package org.apache.maven.util;
  
  import org.apache.plexus.util.StringUtils;
  
  /* ====================================================================
   * 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/>.
   *
   * ====================================================================
   */
  
  /**
   * Path tool for use with the DVSL toolbox.  This class contains static
   * methods to assist in determining path-related information such as
   * relative paths.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pete Kazmier</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   * @version $Id: DVSLPathTool.java,v 1.1 2003/07/30 00:50:37 dion Exp $
   * @todo move to org.apache.maven.util or make a jelly tag
   */
  public class DVSLPathTool
  {
      /**
       * Determines the relative path of a filename from a base directory.
       * This method is useful in building relative links within pages of
       * a web site.  It provides similar functionality to Anakia's
       * <code>$relativePath</code> context variable.  The arguments to
       * this method may contain either forward or backward slashes as
       * file separators.  The relative path returned is formed using
       * forward slashes as it is expected this path is to be used as a
       * link in a web page (again mimicking Anakia's behavior).
       * <p/>
       * This method is thread-safe.
       *
       * @param basedir The base directory.
       * @param filename The filename that is relative to the base
       * directory.
       * @return The relative path of the filename from the base
       * directory.  This value is not terminated with a forward slash.
       * A zero-length string is returned if: the filename is not relative to
       * the base directory, <code>basedir</code> is null or zero-length,
       * or <code>filename</code> is null or zero-length.
       */
      public static final String getRelativePath( String basedir, String filename )
      {
          basedir = uppercaseDrive(basedir);
          filename = uppercaseDrive(filename);
                
          /*
           * Verify the arguments and make sure the filename is relative
           * to the base directory.
           */
          if ( basedir == null || basedir.length() == 0 || filename == null
              || filename.length() == 0 || !filename.startsWith( basedir ) )
          {
              return "";
          }
  
          /*
           * Normalize the arguments.  First, determine the file separator
           * that is being used, then strip that off the end of both the
           * base directory and filename.
           */
          String separator = determineSeparator( filename );
          basedir = StringUtils.chompLast( basedir, separator );
          filename = StringUtils.chompLast( filename, separator );
  
          /*
           * Remove the base directory from the filename to end up with a
           * relative filename (relative to the base directory).  This
           * filename is then used to determine the relative path.
           */
          String relativeFilename = filename.substring( basedir.length() );
  
          return determineRelativePath( relativeFilename, separator );
      }
  
      /**
       * Determines the relative path of a filename.  This method is
       * useful in building relative links within pages of a web site.  It
       * provides similar functionality to Anakia's
       * <code>$relativePath</code> context variable.  The argument to
       * this method may contain either forward or backward slashes as
       * file separators.  The relative path returned is formed using
       * forward slashes as it is expected this path is to be used as a
       * link in a web page (again mimicking Anakia's behavior).
       * <p/>
       * This method is thread-safe.
       *
       * @param filename The filename to be parsed.
       * @return The relative path of the filename. This value is not
       * terminated with a forward slash.  A zero-length string is
       * returned if: <code>filename</code> is null or zero-length.
       */
      public static final String getRelativePath( String filename )
      {
          filename = uppercaseDrive(filename);
          
          if ( filename == null || filename.length() == 0 )
          {
              return "";
          }
  
          
  
          
          /*
           * Normalize the argument.  First, determine the file separator
           * that is being used, then strip that off the end of the
           * filename.  Then, if the filename doesn't begin with a
           * separator, add one.
           */
          
          
          String separator = determineSeparator( filename );
          filename = StringUtils.chompLast( filename, separator );
          if ( !filename.startsWith( separator ) )
          {
              filename = separator + filename;
          }
  
          return determineRelativePath( filename, separator );
      }
  
      /**
       * Determines the directory component of a filename.  This is useful
       * within DVSL templates when used in conjunction with the DVSL's
       * <code>$context.getAppValue("infilename")</code> to get the
       * current directory that is currently being processed.
       * <p/>
       * This method is thread-safe.
       *
       * @param filename The filename to be parsed.
       * @return The directory portion of the <code>filename</code>.  If
       * the filename does not contain a directory component, "." is
       * returned.
       */
      public static final String getDirectoryComponent( String filename )
      {
          if ( filename == null || filename.length() == 0 )
          {
              return "";
          }
  
          String separator = determineSeparator( filename );
          String directory = StringUtils.chomp( filename, separator );
  
          if ( filename.equals( directory ) )
          {
              return ".";
          }
          else
          {
              return directory;
          }
      }
  
      /**
       * Determines the relative path of a filename.  For each separator
       * within the filename (except the leading if present), append the
       * "../" string to the return value.
       *
       * @param filename The filename to parse.
       * @param separator The separator used within the filename.
       * @return The relative path of the filename.  This value is not
       * terminated with a forward slash.  A zero-length string is
       * returned if: the filename is zero-length.
       */
      private static final String determineRelativePath( String filename,
                                                         String separator )
      {
          if ( filename.length() == 0 )
          {
              return "";
          }
  
          
          /*
           * Count the slashes in the relative filename, but exclude the
           * leading slash.  If the path has no slashes, then the filename
           * is relative to the current directory.
           */
          int slashCount = StringUtils.countMatches( filename, separator ) - 1;
          if ( slashCount <= 0 )
          {
              return ".";
          }
  
          /*
           * The relative filename contains one or more slashes indicating
           * that the file is within one or more directories.  Thus, each
           * slash represents a "../" in the relative path.
           */
          StringBuffer sb = new StringBuffer();
          for ( int i = 0; i < slashCount; i++ )
          {
              sb.append( "../" );
          }
  
          /*
           * Finally, return the relative path but strip the trailing
           * slash to mimic Anakia's behavior.
           */
          return StringUtils.chop( sb.toString() );
      }
  
      /**
       * Helper method to determine the file separator (forward or
       * backward slash) used in a filename.  The slash that occurs more
       * often is returned as the separator.
       *
       * @param filename The filename parsed to determine the file
       * separator.
       * @return The file separator used within <code>filename</code>.
       * This value is either a forward or backward slash.
       */
      private static final String determineSeparator( String filename )
      {
          int forwardCount = StringUtils.countMatches( filename, "/" );
          int backwardCount = StringUtils.countMatches( filename, "\\" );
  
          return forwardCount >= backwardCount ? "/" : "\\";
      }
      
      /**
       * Cygwin prefers lowercase drive letters, but other parts of maven use uppercase
       * @param path
       * @return String
       */
      static final String uppercaseDrive(String path) {
        if (path == null)
          return null;
          
        if (path.length() >=2 && path.charAt(1) == ':') {
            path = path.substring(0, 1).toUpperCase() + path.substring(1);    
        }
        return path;
      }
  
      /**
       * Calculates the appropriate link given the preferred link and the relativePath 
of the document
       * @param link
       * @param relativePath
       * @return String
       */
      public static final String calculateLink(String link, String relativePath)
      {
          //This must be some historical feature
          if (link.startsWith("/site/"))
          {
              return link.substring(5);
          }
  
          //Allows absolute links in nav-bars etc
          if (link.startsWith("/absolute/"))
          {
              return link.substring(10);
          }
  
          // This traps urls like http://
          if (link.indexOf(":") >= 0)
          {
              return link;
          }
  
          //If relativepath is current directory, just pass the link through
          if (relativePath.equals("."))
          {
              if (link.startsWith("/"))
              {
                  return link.substring(1);
              }
              else
              {
                  return link;
              }
          }
  
          //If we don't do this, you can end up with ..//bob.html rather than 
../bob.html
          if (relativePath.endsWith("/") && link.startsWith("/"))
          {
              return relativePath + "." + link.substring(1);
          }
  
          if (relativePath.endsWith("/") || link.startsWith("/"))
          {
              return relativePath + link;
          }
  
          return relativePath + "/" + link;
      }
  
  }
  
  
  
  1.1                  maven/src/test/java/org/apache/maven/util/MavenToolTest.java
  
  Index: MavenToolTest.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.io.File;
  
  /**
   * Unit test for <code>MavenTool</code>.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
   * @version $Id: MavenToolTest.java,v 1.1 2003/07/30 00:50:37 dion Exp $
   */
  public class MavenToolTest extends TestCase
  {
      /** fragment to be resolved */
      private static final String NEEDLE =
          "org/apache/maven/MavenTool.java";
      /** where to search for the fragment */
      private static final String[] HAYSTACK =
          {
              "docs",
              "src" + File.separator + "java",
              "xdocs"
          };
  
      /**
       * Create the test with the given name
       *
       * @param testName the name of the test
       */
      public MavenToolTest( String testName )
      {
          super( testName );
      }
  
      /**
       * @return the suite of tests being tested
       */
      public static Test suite()
      {
          return new TestSuite( MavenToolTest.class );
      }
  
      /**
       * Tests [EMAIL PROTECTED] MavenTool.resolvePathFragment(String, String, 
String[])}.
       */
      public void testResolvePathFragment()
      {
          MavenTool tool = new MavenTool();
  
          /*
           * The basedir for the project is passed into the system properties
           * by the junit task.
           */
          String basedir = System.getProperty( "basedir" );
          assertNotNull( "The system property basedir was not defined.", basedir );
  
          String path = tool.resolvePathFragment( basedir, NEEDLE, HAYSTACK );
          assertEquals( "Couldn't resolve fragment using a base directory of "
                        + basedir, HAYSTACK[1], path );
      }
  }
  
  
  
  1.1                  maven/src/test/java/org/apache/maven/util/DVSLPathToolTest.java
  
  Index: DVSLPathToolTest.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * Unit test for <code>DVSLPathTool</code>.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pete Kazmier</a>
   * @version $Id: DVSLPathToolTest.java,v 1.1 2003/07/30 00:50:37 dion Exp $
   */
  public class DVSLPathToolTest extends TestCase
  {
      /**
       * Create the test case
       *
       * @param testName name of the test case
       */
      public DVSLPathToolTest( String testName )
      {
          super( testName );
      }
  
      /**
       * @return the suite of tests being tested
       */
      public static Test suite()
      {
          return new TestSuite( DVSLPathToolTest.class );
      }
  
      /**
       * Tests <code>DVSLPathTool.getDirectoryComponent</code>.
       */
      public void testGetDirectoryComponent()
      {
          String[] test =
              {
                  "file1.xml",
                  "ref/file1",
                  "/home/test/file2.vm",
                  "d1\\d2\\d3\\file",
                  "/d1/d2/"
              };
  
          String[] expected =
              {
                  ".",
                  "ref",
                  "/home/test",
                  "d1\\d2\\d3",
                  "/d1/d2"
              };
  
          for ( int i = 0; i < test.length; i++ )
          {
              assertEquals( expected[i], DVSLPathTool.getDirectoryComponent( test[i] ) 
);
          }
      }
  
      /**
       * Tests <code>DVSLPathTool.getRelativePath</code>.
       */
      public void testGetRelativePath()
      {
          TestArgs[] tests =
              {
                  new TestArgs( "", "/home/www/html", "", "../.." ),
                  new TestArgs( "/", "/home/www/html", "../..", "../.." ),
                  new TestArgs( "", "/home/www/html/", "", "../.." ),
                  new TestArgs( "/", "/home/www/html/", "../..", "../.." ),
                  new TestArgs( "", "home/www/html", "", "../.." ),
                  new TestArgs( "/", "home/www/html", "", "../.." ),
                  new TestArgs( "", "home/www/html/", "", "../.." ),
                  new TestArgs( "/", "home/www/html/", "", "../.." ),
                  new TestArgs( "/", "/home", ".", "." ),
                  new TestArgs( "/usr/local", null, "", "" ),
                  new TestArgs( null, "/usr/local", "", ".." ),
                  new TestArgs( null, null, "", "" ),
                  new TestArgs( "/home/kaz", "/home/kaz", "", ".." ),
                  new TestArgs( "/home/kaz", "/home/kaz/", "", ".." ),
                  new TestArgs( "/home/kaz/", "/home/kaz", "", ".." ),
                  new TestArgs( "/home/kaz/", "/home/kaz/", "", ".." ),
                  new TestArgs( "/home/kaz", "/home/kaz/file.html", ".", "../.." ),
                  new TestArgs( "/home/kaz/", "/home/kaz/file.html", ".", "../.." ),
                  new TestArgs( "/home/kaz", "/home/kaz/howto/jeff.html", "..",
                                "../../.." ),
                  new TestArgs( "/home/", "/home/kaz/howto/images/", "../..",
                                "../../.." ),
                  new TestArgs( "/home/", "/home/kaz/howto/jeff.html", "../..",
                                "../../.." ),
                  new TestArgs( "/home/", "/home/kaz/howto/u/y/z/jeff.html",
                                "../../../../..", "../../../../../.." ),
                  new TestArgs( "/home/boston", "/usr/local/where/am/i", "",
                                "../../../.." ),
                  new TestArgs( "home/boston", "/usr/local/where/am/i", "",
                                "../../../.." ),
                  new TestArgs( "home/boston", "home/boston/where/am/i", "../..",
                                "../../../.." ),
                  new TestArgs( "", "\\home\\www\\html", "", "../.." ),
                  new TestArgs( "\\", "\\home\\www\\html", "../..", "../.." ),
                  new TestArgs( "", "\\home\\www\\html\\", "", "../.." ),
                  new TestArgs( "\\", "\\home\\www\\html\\", "../..", "../.." ),
                  new TestArgs( "", "home\\www\\html", "", "../.." ),
                  new TestArgs( "\\", "home\\www\\html", "", "../.." ),
                  new TestArgs( "", "home\\www\\html\\", "", "../.." ),
                  new TestArgs( "\\", "home\\www\\html\\", "", "../.." ),
                  new TestArgs( "\\", "\\home", ".", "." ),
                  new TestArgs( "\\usr\\local", null, "", "" ),
                  new TestArgs( null, "\\usr\\local", "", ".." ),
                  new TestArgs( null, null, "", "" ),
                  new TestArgs( "\\home\\kaz", "\\home\\kaz", "", ".." ),
                  new TestArgs( "\\home\\kaz", "\\home\\kaz\\", "", ".." ),
                  new TestArgs( "\\home\\kaz\\", "\\home\\kaz", "", ".." ),
                  new TestArgs( "\\home\\kaz\\", "\\home\\kaz\\", "", ".." ),
                  new TestArgs( "\\home\\kaz", "\\home\\kaz\\file.html", ".",
                                "../.." ),
                  new TestArgs( "\\home\\kaz\\", "\\home\\kaz\\file.html", ".",
                                "../.." ),
                  new TestArgs( "\\home\\kaz", "\\home\\kaz\\howto\\jeff.html", "..",
                                "../../.." ),
                  new TestArgs( "\\home\\", "\\home\\kaz\\howto\\images\\", "../..",
                                "../../.." ),
                  new TestArgs( "\\home\\", "\\home\\kaz\\howto\\jeff.html", "../..",
                                "../../.." ),
                  new TestArgs( "\\home\\", "\\home\\kaz\\howto\\u\\y\\z\\jeff.html",
                                "../../../../..", "../../../../../.." ),
                  new TestArgs( "\\home\\boston", "\\usr\\local\\where\\am\\i", "",
                                "../../../.." ),
                  new TestArgs( "home\\boston", "\\usr\\local\\where\\am\\i", "",
                                "../../../.." ),
                  new TestArgs( "home\\boston", "home\\boston\\where\\am\\i", "../..",
                                "../../../.." ),
                  new TestArgs( "/x/y/z/", "/x/y/z/a\\b\\c", ".", "../../.." ),
                  new TestArgs( "/x/y/z/", "\\x\\y\\z\\a\\b\\c", "", "../../../../.." 
),
                  new TestArgs( "\\x\\y\\z", "\\x\\y\\z\\a/b\\c", "..", "../../../.." 
),
                  new TestArgs( "\\x\\y\\z/", "\\x\\y\\z/\\a/b\\c", "..",
                                "../../../.." ),
                  new TestArgs( "D:/a/b", "D:/a/b/c", ".", "../../.." ),
                  new TestArgs( "d:/a/b", "D:/a/b/c.html", ".", "../../.." ),
              };
  
          for ( int i = 0; i < tests.length; i++ )
          {
              assertEquals( tests[i].toString(), tests[i].expected,
                            DVSLPathTool.getRelativePath( tests[i].basedir, 
tests[i].filename ) );
          }
  
          for ( int i = 0; i < tests.length; i++ )
          {
              assertEquals( tests[i].toString(), tests[i].expectedNoBase,
                            DVSLPathTool.getRelativePath( tests[i].filename ) );
          }
      }
  
      /**
       * Value object for a relative path test case.  This class is used
       * when testing the <code>getRelativePath(basedir, filename)</code>
       * and <code>getRelativePath(filename)</code> methods.  The expected
       * results for each method are different which is the reason that
       * both expected values are stored as part of the class.
       *
       * @author <a href="mailto:[EMAIL PROTECTED]">Pete Kazmier</a>
       * @version
       * $Id: DVSLPathToolTest.java,v 1.1 2003/07/30 00:50:37 dion Exp $
       */
      private static class TestArgs
      {
          /** base directory for tests */
          private String basedir;
          /** the file to test*/
          private String filename;
          /**
           * expected result when calling <code>getRelativePath(basedir,
           * filename)</code>.
           */
          private String expected;
          /**
           * expected result when calling <code>getRelativePath(filename)</code>.
           */
          private String expectedNoBase;
  
          /**
           * Constructor.
           *
           * @param b The base directory.
           * @param f The filename.
           * @param e The expected result when calling
           * <code>getRelativePath(basedir, filename)</code>.
           * @param enb The expected result when calling
           * <code>getRelativePath(filename)</code>.
           */
          TestArgs( String b, String f, String e, String enb )
          {
              basedir = b;
              filename = f;
              expected = e;
              expectedNoBase = enb;
          }
  
          /**
           * Provide detailed information regarding the test case which
           * can be used as part of the JUnit error message in the event
           * of a unit test failure.
           *
           * @return A string describing the test parameters.
           */
          public String toString()
          {
              StringBuffer sb = new StringBuffer();
              sb.append( "Basedir: " );
              sb.append( basedir );
              sb.append( " Filename: " );
              sb.append( filename );
              return sb.toString();
          }
      }
      
      public void testUppercaseDrive() {
        assertEquals("c:/b/", "C:/b/", DVSLPathTool.uppercaseDrive("c:/b/"));   
        assertEquals("c:", "C:", DVSLPathTool.uppercaseDrive("c:"));   
        assertEquals(".", ".", DVSLPathTool.uppercaseDrive("."));   
        assertEquals("null", null, DVSLPathTool.uppercaseDrive(null));   
      
      }
      
      public void testCalculateLink(String expected, String link, String relativePath)
      {
          String actual = DVSLPathTool.calculateLink(link, relativePath);
          String function = "DVSLPathTool.calculateLink(" + link + "," + relativePath 
+ ")";
          if (!expected.equals(actual)) {
              System.out.println("Function:" + function);
              System.out.println("Actual:" + actual);
              System.out.println("Expected:" + expected);            
          }
          assertEquals(function, expected, actual);
      }
  
      public void testCalculateLink()
      {
          testCalculateLink("/bob.html", "/absolute//bob.html", "..");
          testCalculateLink("http://crazyhorse.com";, 
"/absolute/http://crazyhorse.com";, "..");
          testCalculateLink("http://crazyhorse.com";, "http://crazyhorse.com";, "..");
          testCalculateLink("../index.html", "/index.html", "..");
          testCalculateLink("index.html", "/index.html", ".");
          testCalculateLink("../other-module/index.html", 
"../other-module/index.html", ".");
          testCalculateLink("../../other-module/index.html", 
"../other-module/index.html", "..");
      }
  }
  
  
  
  1.1                  maven/src/test/java/org/apache/maven/util/DVSLFormatterTest.java
  
  Index: DVSLFormatterTest.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 junit.framework.TestCase;
  
  /**
   * @author Ben Walding
   *
   */
  public class DVSLFormatterTest extends TestCase {
  
      public void testFormatNumberSimple() {
          testFormat("1", "1", "0");
  //        testFormat("1.0", "1", "0.0");
  //        testFormat("1.00", "1", "0.00");
  //        testFormat("1.000", "1", "0.000");
  //        testFormat("1.0000", "1", "0.0000");
  //
  //        testFormat("1.10", "1.10", "0.00");
  //        testFormat("1.100", "1.1000", "0.000");
  //        testFormat("1.123", "1.1234", "0.000");
  //        testFormat("1.1234", "1.1234", "0.0000");
      }
  
      public void testFormatNumberNegative() {
          testFormat("-1", "-1", "0");
  //        testFormat("-1.0", "-1", "0.0");
  //        testFormat("-1.00", "-1", "0.00");
  //        testFormat("-1.000", "-1", "0.000");
  //        testFormat("-1.0000", "-1", "0.0000");
  //
  //        testFormat("-1.10", "-1.10", "0.00");
  //        testFormat("-1.100", "-1.1000", "0.000");
  //        testFormat("-1.123", "-1.1234", "0.000");
  //        testFormat("-1.1234", "-1.1234", "0.0000");
      }
  
      public void testFormatNumberPercent() {
          testFormat("100%", "1", "0%");
  //        testFormat("100.0%", "1", "0.0%");
  //        testFormat("100.00%", "1", "0.00%");
  //        testFormat("100.000%", "1", "0.000%");
  //        testFormat("100.0000%", "1", "0.0000%");
  //
  //        testFormat("-110.00%", "-1.10", "0.00%");
  //        testFormat("-110.000%", "-1.1000", "0.000%");
  //        testFormat("-112.340%", "-1.1234", "0.000%");
  //        testFormat("-112.3400%", "-1.1234", "0.0000%");
  
          testFormat("-100%", "-1", "0%");
  //        testFormat("-100.0%", "-1", "0.0%");
  //        testFormat("-100.00%", "-1", "0.00%");
  //        testFormat("-100.000%", "-1", "0.000%");
  //        testFormat("-100.0000%", "-1", "0.0000%");
  //
  //        testFormat("-110.00%", "-1.10", "0.00%");
  //        testFormat("-110.000%", "-1.1000", "0.000%");
  //        testFormat("-112.340%", "-1.1234", "0.000%");
  //        testFormat("-112.3400%", "-1.1234", "0.0000%");
      }
  
      protected void testFormat(String expected, String value, String pattern) {
          String actual = DVSLFormatter.formatNumber(value, pattern);
          String function =
              "DVSLFormatter.formatNumber(" + value + "," + pattern + ")";
          if (!actual.equals(expected)) {
              System.out.println(
                  function + "  Actual: " + actual + ", Expected: " + expected);
          }
          assertEquals(function, expected, actual);
      }
  
  }
  
  
  
  1.1                  maven/src/test/java/org/apache/maven/util/StringToolTest.java
  
  Index: StringToolTest.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 java.util.List;
  
  import junit.framework.TestCase;
  
  /**
   * @author Ben Walding
   *
   */
  public class StringToolTest extends TestCase
  {
      private StringTool cst;
      public StringToolTest(String name)
      {
          super(name);
      }
  
      public void setUp()
      {
          cst = new StringTool();
      }
  
      public void tearDown()
      {
          cst = null;
      }
  
      public void testSplitStringAtLastDelim()
      {
          testSplitStringAtLastDelim("org.apache.maven.StringTool", ".", 
"org.apache.maven", "StringTool");
          testSplitStringAtLastDelim("org/apache/maven/StringTool.java", ".", 
"org/apache/maven/StringTool", "java");
          testSplitStringAtLastDelim("org.apache.maven.StringTool", "|", 
"org.apache.maven.StringTool", "");
          testSplitStringAtLastDelim(null, null, null, null);
  
      }
  
      public void testSplitStringAtLastDelim(String input, String delim, String s0, 
String s1)
      {
          List result = cst.splitStringAtLastDelim(input, delim);
          String f = "splitStringAtLastDelim(" + input + "," + delim + ")";
          assertEquals(f + "[0]", s0, result.get(0));
          assertEquals(f + "[1]", s1, result.get(1));
      }
  
  }
  
  
  
  1.2       +1 -1      
maven/src/plugins-build/file-activity/src/plugin-resources/maven-file-activity-plugin.jsl
  
  Index: maven-file-activity-plugin.jsl
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/file-activity/src/plugin-resources/maven-file-activity-plugin.jsl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- maven-file-activity-plugin.jsl    24 Jan 2003 03:46:27 -0000      1.1
  +++ maven-file-activity-plugin.jsl    30 Jul 2003 00:50:37 -0000      1.2
  @@ -7,7 +7,7 @@
     xmlns:x="jelly:xml"
     xmlns="dummy" trim="false">
     <!-- This needs to be instantiated here to be available in the template matches 
-->
  -  <j:useBean var="mavenTool" class="org.apache.maven.MavenTool"/>
  +  <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/>
     <jsl:template match="changelog">
       <document>
         <jsl:applyTemplates/>
  
  
  
  1.4       +3 -3      
maven/src/plugins-build/junit-report/src/plugin-resources/junit.jsl
  
  Index: junit.jsl
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/junit-report/src/plugin-resources/junit.jsl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- junit.jsl 19 Feb 2003 06:33:32 -0000      1.3
  +++ junit.jsl 30 Jul 2003 00:50:37 -0000      1.4
  @@ -12,12 +12,12 @@
     trim="false">
   
     <!-- This needs to be instantiated here to be available in the template matches 
-->
  -  <j:useBean var="mavenTool" class="org.apache.maven.MavenTool"/>
  +  <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/>
     <j:useBean var="numbers" class="java.text.DecimalFormat"/>
     <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/>
  -  <j:useBean var="formatter" class="org.apache.maven.DVSLFormatter"/>
  +  <j:useBean var="formatter" class="org.apache.maven.util.DVSLFormatter"/>
     <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/>
  -  <j:useBean var="pathtool" class="org.apache.maven.DVSLPathTool"/>
  +  <j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/>
   
     
     <define:taglib uri="junit">
  
  
  
  1.40      +2 -2      maven/src/plugins-build/xdoc/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/xdoc/plugin.jelly,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- plugin.jelly      29 Jul 2003 02:03:08 -0000      1.39
  +++ plugin.jelly      30 Jul 2003 00:50:37 -0000      1.40
  @@ -72,7 +72,7 @@
              more of a global tool box.
         -->
         
  -      <j:useBean var="formatter" class="org.apache.maven.DVSLFormatter"/>
  +      <j:useBean var="formatter" class="org.apache.maven.util.DVSLFormatter"/>
         ${formatter.formatNumber(string,pattern)}
       </define:tag>
   
  @@ -605,7 +605,7 @@
       
   
       <!-- path tool for relative processing -->
  -    <j:useBean var="pathTool" class="org.apache.maven.DVSLPathTool"/>
  +    <j:useBean var="pathTool" class="org.apache.maven.util.DVSLPathTool"/>
   
       <!-- tool for loading resources from the class loader -->
       <j:useBean class="org.apache.maven.util.ResourceBean" var="resourceTool"/>
  
  
  
  1.5       +3 -3      maven/src/plugins-build/jdepend/src/plugin-resources/jdepend.jsl
  
  Index: jdepend.jsl
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/jdepend/src/plugin-resources/jdepend.jsl,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jdepend.jsl       19 Feb 2003 06:01:38 -0000      1.4
  +++ jdepend.jsl       30 Jul 2003 00:50:37 -0000      1.5
  @@ -12,11 +12,11 @@
     trim="false">
   
     <!-- This needs to be instantiated here to be available in the template matches 
-->
  -  <j:useBean var="mavenTool" class="org.apache.maven.MavenTool"/>
  +  <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/>
     <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/>
     <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/>
  -  <j:useBean var="pathtool" class="org.apache.maven.DVSLPathTool"/>
  -  <j:useBean var="stringTool" class="org.apache.maven.StringTool"/>
  +  <j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/>
  +  <j:useBean var="stringTool" class="org.apache.maven.util.StringTool"/>
   
     <define:taglib uri="jdepend">
       <define:tag name="nav">
  
  
  
  1.10      +2 -2      
maven/src/plugins-build/checkstyle/src/plugin-resources/checkstyle.jsl
  
  Index: checkstyle.jsl
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/checkstyle/src/plugin-resources/checkstyle.jsl,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- checkstyle.jsl    25 Jul 2003 07:05:01 -0000      1.9
  +++ checkstyle.jsl    30 Jul 2003 00:50:37 -0000      1.10
  @@ -10,10 +10,10 @@
     xmlns="dummy" trim="false">
   
     <!-- This needs to be instantiated here to be available in the template matches 
-->
  -  <j:useBean var="mavenTool" class="org.apache.maven.MavenTool"/>
  +  <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/>
     <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/>
     <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/>
  -  <j:useBean var="pathtool" class="org.apache.maven.DVSLPathTool"/>
  +  <j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/>
   
     <jsl:template match="checkstyle">
       <document>
  
  
  
  1.3       +2 -2      maven/src/plugins-build/pmd/src/plugin-resources/pmd.jsl
  
  Index: pmd.jsl
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/pmd/src/plugin-resources/pmd.jsl,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- pmd.jsl   25 Jul 2003 07:05:38 -0000      1.2
  +++ pmd.jsl   30 Jul 2003 00:50:37 -0000      1.3
  @@ -10,10 +10,10 @@
     xmlns="dummy" trim="false">
   
     <!-- This needs to be instantiated here to be available in the template matches 
-->
  -  <j:useBean var="mavenTool" class="org.apache.maven.MavenTool"/>
  +  <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/>
     <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/>
     <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/>
  -  <j:useBean var="pathtool" class="org.apache.maven.DVSLPathTool"/>
  +  <j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/>
   
     <jsl:template match="pmd">
       <document>
  
  
  
  1.4       +3 -3      maven/src/plugins-build/cactus/src/plugin-resources/cactus.jsl
  
  Index: cactus.jsl
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/cactus/src/plugin-resources/cactus.jsl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- cactus.jsl        13 Apr 2003 11:12:38 -0000      1.3
  +++ cactus.jsl        30 Jul 2003 00:50:37 -0000      1.4
  @@ -12,12 +12,12 @@
     trim="false">
   
     <!-- This needs to be instantiated here to be available in the template matches 
-->
  -  <j:useBean var="mavenTool" class="org.apache.maven.MavenTool"/>
  +  <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/>
     <j:useBean var="numbers" class="java.text.DecimalFormat"/>
     <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/>
  -  <j:useBean var="formatter" class="org.apache.maven.DVSLFormatter"/>
  +  <j:useBean var="formatter" class="org.apache.maven.util.DVSLFormatter"/>
     <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/>
  -  <j:useBean var="pathtool" class="org.apache.maven.DVSLPathTool"/>
  +  <j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/>
   
     
     <define:taglib uri="junit">
  
  
  

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

Reply via email to