dion 2003/07/30 23:28:00
Added: src/java/org/apache/maven/jelly/tags/resources Copy.java
ResourcesTagLibrary.java
Log:
Add resources tag lib
Revision Changes Path
1.1 maven/src/java/org/apache/maven/jelly/tags/resources/Copy.java
Index: Copy.java
===================================================================
package org.apache.maven.jelly.tags.resources;
/* ====================================================================
* 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.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 Copy extends BaseTagSupport
{
/** 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)
{
return;
}
checkAttribute(todir, "todir");
// <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);
}
// copy to targetDirectory....
org.apache.tools.ant.taskdefs.Copy copyTask = new
org.apache.tools.ant.taskdefs.Copy();
copyTask.setProject(getMavenContext().getAntProject());
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
{
throw new JellyTagException("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;
}
}
1.1
maven/src/java/org/apache/maven/jelly/tags/resources/ResourcesTagLibrary.java
Index: ResourcesTagLibrary.java
===================================================================
package org.apache.maven.jelly.tags.resources;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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.commons.jelly.TagLibrary;
/**
* @author dion
* @version $Revision: 1.1 $
*/
public class ResourcesTagLibrary
extends TagLibrary
{
/**
* Create the taglib and register the tags
*/
public ResourcesTagLibrary()
{
registerTag("copy", Copy.class);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]