Subversion Repositories XServices

Rev

Rev 10 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/*
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package net.brutex.xservices.types;

import java.io.File;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.TarFileSet;
import org.apache.tools.ant.types.ZipFileSet;

/**
 *
 * @author Brian Rosenberger, bru@brutex.de
 */
@XmlType(name="FileSetType", namespace="http://ws.xservices.brutex.net",
    propOrder={"type", "source", "includes", "excludes", "casesensitive"})
public class FileSetResource {

    @XmlElement(name="FileSetType", required=true, nillable=false, defaultValue="FILES")
    public FileSetType type = FileSetType.FILES;

    @XmlElement(name="source", required=true, nillable=false)
    public String source = "";

    @XmlElement(name="includes", required=true, nillable=false, defaultValue="**/*")
    public String includes = "";

    @XmlElement(name="excludes", required=false, nillable=true, defaultValue="")
    public String excludes ="";

    @XmlElement(name="casesensitive", required=true, nillable=false, defaultValue="true")
    public boolean casesensitive = true;

    public FileSet getAntFileSet(Project p) {
        FileSet set = null;
        switch(type) {
            case ZIP:
                ZipFileSet zset = new ZipFileSet();
                zset.setSrc(new File(source));
                zset.setEncoding(System.getProperty("file.encoding"));
                set = zset;
                break;
            case TAR:
                TarFileSet tset = new TarFileSet();
                tset.setSrc(new File(source));
                set = tset;
                break;
            case GZTAR:
                Resource res = new FileResource(FileResource.Type.GZIP, source).getAntResource(p);
                TarFileSet gzset = new TarFileSet();
                gzset.setSrcResource(res);
                set = gzset;
                break;
            default: //FILES
                set = new FileSet();
                set.setDir(new File(source));
        }
        set.setProject(p);
        set.setIncludes(includes);
        set.setExcludes(excludes);
        set.setCaseSensitive(casesensitive);

        return set;
    }

    @XmlEnum
    public enum FileSetType{
        FILES, ZIP, TAR, GZTAR
    }

}