Subversion Repositories XServices

Rev

Rev 23 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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