Here you are
Jan

import java.io.File;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.FileUtils;

public class RelpathTask extends Task {
    private File basefile;
    private File checkfile;
    private String propertyname;
    
    public void setBase(File base) {
        basefile = base;
    }
    
    public void setFile(File file) {
        checkfile = file;
    }
    
    public void setProperty(String propName) {
        propertyname = propName;
    }
    
    public void execute() {
        checkSettings();
        try {
            String relPath = FileUtils.getRelativePath(basefile, checkfile);
            getProject().setNewProperty(propertyname, relPath);
        } catch (Exception e) {
            throw new BuildException(e);
        }
    }
    
    protected void checkSettings() {
        if (basefile == null) {
            throw new BuildException("'basefile' must be set.", getLocation());
        }
        if (checkfile == null) {
            throw new BuildException("'checkfile' must be set.", getLocation());
        }
        if (propertyname == null) {
            throw new BuildException("'propertyname' must be set.", 
getLocation());
        }
    }
} 


________________________________

        Von: Eric Dalquist [mailto:[EMAIL PROTECTED] 
        Gesendet: Montag, 17. September 2007 17:45
        An: Ant Users List
        Betreff: Re: AW: fileset exclude with full path
        
        
        Thanks for the solution, I may look at doing this in a custom task to 
avoid the BSF dependency but this should work one way or another.
        
        -Eric
        
        [EMAIL PROTECTED] wrote: 

                There is no task for that, but a core function in Ant's 
FileUtils which can be used
                
                <project>
                
                    <scriptdef name="relpath" language="javascript">
                        <attribute name="property"/>
                        <attribute name="base"/>
                        <attribute name="file"/>
                        <![CDATA[
                            
importClass(Packages.org.apache.tools.ant.util.FileUtils);
                            importClass(Packages.java.io.File);
                            propName = attributes.get("property");
                            baseFile = attributes.get("base");
                            file     = attributes.get("file");
                            relPath  = FileUtils.getRelativePath(new 
File(baseFile), new File(file) );
                            project.setNewProperty(propName, relPath);
                        ]]>
                    </scriptdef>
                    
                    <target name="clean">
                        <delete dir="x"/>
                    </target>
                    <target name="prepare">
                        <mkdir dir="x/a/b/c/d/e/f/g"/>
                        <echo file="x/a/b/c/d/e/f/g/file.txt" message="test"/>
                    </target>
                    <target name="test">
                        <relpath property="rel" base="x/a/b" 
file="x/a/b/c/d/e/f/g/file.txt"/>
                        <echo>
                            File: x/a/b/c/d/e/f/g/file.txt
                            Base: x/a/b
                            rel : ${rel}
                        </echo>
                    </target>
                </project>
                
                
                
                Jan 
                
                  

                        -----Ursprüngliche Nachricht-----
                        Von: Eric Dalquist [mailto:[EMAIL PROTECTED] 
                        Gesendet: Montag, 17. September 2007 17:10
                        An: user@ant.apache.org
                        Betreff: fileset exclude with full path
                        
                        I have a full path to a directory that I want to create 
a 
                        fileset of and 
                        a full path to a sub-directory that I want to exclude.
                        
                        I've tried the following and some variations on it:
                        <fileset id="projectFiles" dir="/a/b/c/" 
excludes="/a/b/c/d/**" />
                        
                        No matter what I try I can't seem to get the excludes 
path to 
                        be honored.
                        
                        I unfortunately do not have the ability to change the 
                        sub-directory path 
                        to a relative path instead of a full path, it is being 
populated from 
                        another task that I do not have control over.
                        
                        Thank you,
                        -Eric
                        
                            

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


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

Reply via email to