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 |
|
|
|
17 |
package net.brutex.xservices.types;
|
|
|
18 |
|
|
|
19 |
import java.io.File;
|
|
|
20 |
import javax.xml.bind.annotation.XmlElement;
|
|
|
21 |
import javax.xml.bind.annotation.XmlEnum;
|
|
|
22 |
import javax.xml.bind.annotation.XmlType;
|
|
|
23 |
import org.apache.tools.ant.Project;
|
|
|
24 |
import org.apache.tools.ant.types.FileSet;
|
|
|
25 |
import org.apache.tools.ant.types.Resource;
|
|
|
26 |
import org.apache.tools.ant.types.TarFileSet;
|
|
|
27 |
import org.apache.tools.ant.types.ZipFileSet;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* @author Brian Rosenberger, bru@brutex.de
|
|
|
32 |
*/
|
|
|
33 |
@XmlType(name="FileSetType", namespace="http://ws.xservices.brutex.net",
|
|
|
34 |
propOrder={"type", "source", "includes", "excludes", "casesensitive"})
|
|
|
35 |
public class FileSetResource {
|
|
|
36 |
|
|
|
37 |
@XmlElement(name="FileSetType", required=true, nillable=false, defaultValue="FILES")
|
|
|
38 |
public FileSetType type = FileSetType.FILES;
|
|
|
39 |
|
|
|
40 |
@XmlElement(name="source", required=true, nillable=false)
|
|
|
41 |
public String source = "";
|
|
|
42 |
|
|
|
43 |
@XmlElement(name="includes", required=true, nillable=false, defaultValue="**/*")
|
|
|
44 |
public String includes = "";
|
|
|
45 |
|
|
|
46 |
@XmlElement(name="excludes", required=false, nillable=true, defaultValue="")
|
|
|
47 |
public String excludes ="";
|
|
|
48 |
|
|
|
49 |
@XmlElement(name="casesensitive", required=true, nillable=false, defaultValue="true")
|
|
|
50 |
public boolean casesensitive = true;
|
|
|
51 |
|
|
|
52 |
public FileSet getAntFileSet(Project p) {
|
|
|
53 |
FileSet set = null;
|
|
|
54 |
switch(type) {
|
|
|
55 |
case ZIP:
|
|
|
56 |
ZipFileSet zset = new ZipFileSet();
|
|
|
57 |
zset.setSrc(new File(source));
|
|
|
58 |
zset.setEncoding(System.getProperty("file.encoding"));
|
|
|
59 |
set = zset;
|
|
|
60 |
break;
|
|
|
61 |
case TAR:
|
|
|
62 |
TarFileSet tset = new TarFileSet();
|
|
|
63 |
tset.setSrc(new File(source));
|
|
|
64 |
set = tset;
|
|
|
65 |
break;
|
|
|
66 |
case GZTAR:
|
|
|
67 |
Resource res = new FileResource(FileResource.Type.GZIP, source).getAntResource(p);
|
|
|
68 |
TarFileSet gzset = new TarFileSet();
|
|
|
69 |
gzset.setSrcResource(res);
|
|
|
70 |
set = gzset;
|
|
|
71 |
break;
|
|
|
72 |
default: //FILES
|
|
|
73 |
set = new FileSet();
|
|
|
74 |
set.setDir(new File(source));
|
|
|
75 |
}
|
|
|
76 |
set.setProject(p);
|
|
|
77 |
set.setIncludes(includes);
|
|
|
78 |
set.setExcludes(excludes);
|
|
|
79 |
set.setCaseSensitive(casesensitive);
|
|
|
80 |
|
|
|
81 |
return set;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
@XmlEnum
|
|
|
85 |
public enum FileSetType{
|
|
|
86 |
FILES, ZIP, TAR, GZTAR
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
}
|