Subversion Repositories XServices

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 brianR 1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
package net.brutex.xservices.types;
17
 
18
import java.io.File;
19
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlEnum;
21
import javax.xml.bind.annotation.XmlType;
22
import org.apache.tools.ant.Project;
23
import org.apache.tools.ant.types.FileSet;
24
import org.apache.tools.ant.types.Resource;
25
import org.apache.tools.ant.types.TarFileSet;
26
import org.apache.tools.ant.types.ZipFileSet;
27
 
28
/**
10 brianR 29
 * Set of files from various sources.
6 brianR 30
 *
31
 * @author Brian Rosenberger, bru@brutex.de
32
 */
10 brianR 33
@XmlType(name = "FileSetType", namespace = "http://ws.xservices.brutex.net",
23 brianR 34
propOrder = {"type", "source", "filter", "excludes", "casesensitive"})
54 brianR 35
public class FileSetResource implements ResourceSetInterface {
6 brianR 36
 
65 brianR 37
	public static final String XML_NAME = "fileset";
10 brianR 38
    /**
39
     * Type of FileSet
40
     */
41
    @XmlElement(name = "FileSetType", required = true, nillable = false, defaultValue = "FILES")
6 brianR 42
    public FileSetType type = FileSetType.FILES;
10 brianR 43
    /**
44
     * File set source.
45
     *
46
     * Depends on the file set type. This is either an archive file or a
47
     * directory.
48
     */
49
    @XmlElement(name = "source", required = true, nillable = false)
6 brianR 50
    public String source = "";
10 brianR 51
    /**
52
     * Pattern of files to include.
53
     *
54
     */
23 brianR 55
    @XmlElement(name = PatternSetType.XML_NAME, required = true, nillable = true)
56
    public PatternSetType filter;
57
 
10 brianR 58
    /**
59
     * Pattern of files to exclude.
60
     */
61
    @XmlElement(name = "excludes", required = false, nillable = true, defaultValue = "")
62
    public String excludes = "";
63
    /**
64
     * Case sensitivity for include/ exclude patterns.
65
     */
66
    @XmlElement(name = "casesensitive", required = true, nillable = false, defaultValue = "true")
6 brianR 67
    public boolean casesensitive = true;
68
 
10 brianR 69
    /**
70
     * Get Ant FileSet for this file set.
71
     *
72
     * @param p     Ant project
73
     * @return      Ant FileSet for this file set.
74
     */
54 brianR 75
    public FileSet getAntResource(Project p) {
6 brianR 76
        FileSet set = null;
10 brianR 77
        switch (type) {
6 brianR 78
            case ZIP:
79
                ZipFileSet zset = new ZipFileSet();
80
                zset.setSrc(new File(source));
81
                zset.setEncoding(System.getProperty("file.encoding"));
82
                set = zset;
83
                break;
84
            case TAR:
85
                TarFileSet tset = new TarFileSet();
86
                tset.setSrc(new File(source));
87
                set = tset;
88
                break;
89
            case GZTAR:
90
                Resource res = new FileResource(FileResource.Type.GZIP, source).getAntResource(p);
91
                TarFileSet gzset = new TarFileSet();
92
                gzset.setSrcResource(res);
93
                set = gzset;
94
                break;
95
            default: //FILES
96
                set = new FileSet();
97
                set.setDir(new File(source));
98
        }
99
        set.setProject(p);
23 brianR 100
        //set.setIncludes(includes);
6 brianR 101
        set.setExcludes(excludes);
102
        set.setCaseSensitive(casesensitive);
103
 
104
        return set;
105
    }
106
 
10 brianR 107
    /**
108
     * File set types.
109
     */
54 brianR 110
    @XmlEnum()
111
    @XmlType(name="resourcetype")
10 brianR 112
    public enum FileSetType {
113
 
114
        /**
115
         * Set of files (this is based on a directory, so provide a path only
116
         * as file set source).
117
         */
118
        FILES,
119
        /**
120
         * Set of files inside a ZIP archive.
121
         */
122
        ZIP,
123
        /**
124
         * Set of files inside a TAR archive (without compression).
125
         */
126
        TAR,
127
        /**
128
         * Set of files inside a gzip compressed TAR archive.
129
         */
130
        GZTAR
6 brianR 131
    }
132
}