Subversion Repositories XServices

Rev

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

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