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",
34
propOrder = {"type", "source", "includes", "excludes", "casesensitive"})
6 brianR 35
public class FileSetResource {
36
 
10 brianR 37
    /**
38
     * Type of FileSet
39
     */
40
    @XmlElement(name = "FileSetType", required = true, nillable = false, defaultValue = "FILES")
6 brianR 41
    public FileSetType type = FileSetType.FILES;
10 brianR 42
    /**
43
     * File set source.
44
     *
45
     * Depends on the file set type. This is either an archive file or a
46
     * directory.
47
     */
48
    @XmlElement(name = "source", required = true, nillable = false)
6 brianR 49
    public String source = "";
10 brianR 50
    /**
51
     * Pattern of files to include.
52
     *
53
     */
54
    @XmlElement(name = "includes", required = true, nillable = false, defaultValue = "**/*")
6 brianR 55
    public String includes = "";
10 brianR 56
    /**
57
     * Pattern of files to exclude.
58
     */
59
    @XmlElement(name = "excludes", required = false, nillable = true, defaultValue = "")
60
    public String excludes = "";
61
    /**
62
     * Case sensitivity for include/ exclude patterns.
63
     */
64
    @XmlElement(name = "casesensitive", required = true, nillable = false, defaultValue = "true")
6 brianR 65
    public boolean casesensitive = true;
66
 
10 brianR 67
    /**
68
     * Get Ant FileSet for this file set.
69
     *
70
     * @param p     Ant project
71
     * @return      Ant FileSet for this file set.
72
     */
6 brianR 73
    public FileSet getAntFileSet(Project p) {
74
        FileSet set = null;
10 brianR 75
        switch (type) {
6 brianR 76
            case ZIP:
77
                ZipFileSet zset = new ZipFileSet();
78
                zset.setSrc(new File(source));
79
                zset.setEncoding(System.getProperty("file.encoding"));
80
                set = zset;
81
                break;
82
            case TAR:
83
                TarFileSet tset = new TarFileSet();
84
                tset.setSrc(new File(source));
85
                set = tset;
86
                break;
87
            case GZTAR:
88
                Resource res = new FileResource(FileResource.Type.GZIP, source).getAntResource(p);
89
                TarFileSet gzset = new TarFileSet();
90
                gzset.setSrcResource(res);
91
                set = gzset;
92
                break;
93
            default: //FILES
94
                set = new FileSet();
95
                set.setDir(new File(source));
96
        }
97
        set.setProject(p);
98
        set.setIncludes(includes);
99
        set.setExcludes(excludes);
100
        set.setCaseSensitive(casesensitive);
101
 
102
        return set;
103
    }
104
 
10 brianR 105
    /**
106
     * File set types.
107
     */
6 brianR 108
    @XmlEnum
10 brianR 109
    public enum FileSetType {
110
 
111
        /**
112
         * Set of files (this is based on a directory, so provide a path only
113
         * as file set source).
114
         */
115
        FILES,
116
        /**
117
         * Set of files inside a ZIP archive.
118
         */
119
        ZIP,
120
        /**
121
         * Set of files inside a TAR archive (without compression).
122
         */
123
        TAR,
124
        /**
125
         * Set of files inside a gzip compressed TAR archive.
126
         */
127
        GZTAR
6 brianR 128
    }
129
}