dion        2003/07/30 23:46:07

  Modified:    src/java/org/apache/maven/jelly/tags/maven
                        MavenTagLibrary.java
  Added:       src/java/org/apache/maven/jelly/tags/maven
                        CopyResources.java
  Removed:     src/java/org/apache/maven/jelly/tags/resources Copy.java
                        ResourcesTagLibrary.java
  Log:
  Move and rename tag
  
  Revision  Changes    Path
  1.9       +2 -1      
maven/src/java/org/apache/maven/jelly/tags/maven/MavenTagLibrary.java
  
  Index: MavenTagLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/java/org/apache/maven/jelly/tags/maven/MavenTagLibrary.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MavenTagLibrary.java      31 Jul 2003 05:14:31 -0000      1.8
  +++ MavenTagLibrary.java      31 Jul 2003 06:46:07 -0000      1.9
  @@ -85,5 +85,6 @@
           registerTag( "set-plugin-property", PluginPropertyTag.class );
           registerTag( "user-check", UserCheck.class);
           registerTag( "param-check", ParamCheck.class);
  +        registerTag( "copy-resources", CopyResources.class);
       }
   }
  
  
  
  1.1                  
maven/src/java/org/apache/maven/jelly/tags/maven/CopyResources.java
  
  Index: CopyResources.java
  ===================================================================
  package org.apache.maven.jelly.tags.maven;
  
  /* ====================================================================
   * 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.io.File;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.jelly.JellyTagException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.maven.jelly.tags.BaseTagSupport;
  import org.apache.maven.project.Resource;
  import org.apache.tools.ant.types.FileSet;
  import org.apache.tools.ant.types.PatternSet;
  
  /**
   * A tag to copy resources to a given directory 
   * 
   * @author dion
   * @version $Revision: 1.1 $
   */
  public class CopyResources extends BaseTagSupport
  {
      /** log for debug output */
      private static final Log log = LogFactory.getLog(BaseTagSupport.class);
      
      /** the resources to copy */
      private List resources;
      
      /** the directory to copy to */
      private String todir;
  
      /* (non-Javadoc)
       * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
       */
      public void doTag(XMLOutput output) throws MissingAttributeException, 
JellyTagException
      {
          if (resources == null || todir == null)
          {
              log.warn("resources or todir was null");
              return;
          }
  //      <j:forEach var="resource" items="${resources}">
  //        <j:set var="resourceDirectoryPresent" value="false"/>
  //          
  //        <util:available file="${resource.directory}">
  //          <j:set var="resourceDirectoryPresent" value="true"/>
  //        </util:available>
  //
  //        <j:if test="${resourceDirectoryPresent == 'true'}">
  //          <j:choose>
  //            <j:when test="${resource.targetPath ==''}">
  //              <j:set var="targetDirectory" value="${todir}"/>
  //            </j:when>
  //            <j:otherwise>
  //              <j:set var="targetDirectory" 
value="${todir}/${resource.targetPath}"/>
  //            </j:otherwise>
  //          </j:choose>
  //          <copy todir="${targetDirectory}" filtering="${resource.filtering}"
  //              overwrite="${resource.filtering}">
  //            <fileset dir="${resource.directory}">
  //              <j:if test="${resources.includes.isEmpty()}">
  //                <include name="**/**"/>
  //              </j:if>
  //              <j:forEach var="include" items="${resource.includes}">
  //                <include name="${include}"/>
  //              </j:forEach>
  //              <j:forEach var="exclude" items="${resource.excludes}">
  //                <exclude name="${exclude}"/>
  //              </j:forEach>
  //            </fileset>
  //          </copy>
  //        </j:if>
  //      </j:forEach>
          
          for (Iterator iter = resources.iterator(); iter.hasNext();)
          {
              Resource resource = (Resource) iter.next();
              String directoryName = resource.getDirectory();
              File directory = new File(directoryName);
              if ( directory.exists() && directory.isDirectory() && 
directory.canRead() )
              {
                  StringBuffer targetDirectoryBuffer = new StringBuffer(todir);
                  String targetPath = resource.getTargetPath();
                  if (targetPath != null && !targetPath.trim().equals(""))
                  {
                      targetDirectoryBuffer.append('/').append(targetPath); 
                  }
                  File targetDirectory = new File(targetDirectoryBuffer.toString());
                  // copy to targetDirectory....
                  org.apache.tools.ant.taskdefs.Copy copyTask = new 
org.apache.tools.ant.taskdefs.Copy();
                  copyTask.setProject( getMavenContext().getAntProject() );
                  copyTask.setTodir( targetDirectory );
                  copyTask.setFiltering(resource.getFiltering());
                  copyTask.setOverwrite(resource.getFiltering());
                  FileSet fileSet = new FileSet();
                  fileSet.setDir( directory );
                  if (resource.getIncludes().isEmpty())
                  {
                      PatternSet.NameEntry entry = fileSet.createInclude();
                      entry.setName("**/**");
                  }
                  // add includes
                  for (Iterator incIter = resource.getIncludes().iterator();
                      incIter.hasNext(); )
                  {
                      String include = (String) incIter.next();
                      PatternSet.NameEntry entry = fileSet.createInclude();
                      entry.setName(include);
                  }
                  // add excludes
                  for (Iterator incIter = resource.getExcludes().iterator();
                      incIter.hasNext(); )
                  {
                      String exclude = (String) incIter.next();
                      PatternSet.NameEntry entry = fileSet.createExclude();
                      entry.setName(exclude);
                  }
                  copyTask.addFileset(fileSet);
                  copyTask.execute();
              }
              else
              {
                  log.debug("todir is either not a directory, not writable or not 
there");
              }
          }
  
      }
  
      /**
       * @param list the resources to copy
       */
      public void setResources(List list)
      {
          resources = list;
      }
  
      /**
       * @param string the directory to copy them to
       */
      public void setTodir(String string)
      {
          todir = string;
      }
  
  }
  
  
  

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

Reply via email to