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
 
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.Resource;
25
import org.apache.tools.ant.types.resources.TarResource;
26
import org.apache.tools.ant.types.resources.ZipResource;
27
import org.apache.tools.tar.TarEntry;
28
import org.apache.tools.zip.ZipEntry;
29
 
30
/**
31
 *
32
 * @author Brian Rosenberger, bru@brutex.de
33
 */
34
@XmlType(namespace = "http://ws.xservices.brutex.net")
35
public class ArchiveResource
36
        implements ResourceInterface {
37
 
38
    @XmlElement(defaultValue = "ZIP", nillable = false, required = true)
39
    public ArchiveType type = ArchiveType.ZIP;
40
    @XmlElement(nillable = false, required = true)
41
    public String archive;
42
    @XmlElement(nillable = false, required = true)
43
    public String uri;
44
 
45
    @XmlEnum(String.class)
46
    public enum ArchiveType {
47
 
48
        ZIP, TAR, GZTAR
49
    }
50
 
51
    public Resource getAntResource(Project p) {
52
        Resource res = null;
53
        switch (type) {
54
            case TAR:
55
                TarEntry tarentry = new TarEntry(uri);
56
                TarResource tres = new TarResource(new File(archive), tarentry);
57
                res = tres;
58
                break;
59
 
60
            case GZTAR:
61
                TarResource gres = new TarResource(new org.apache.tools.ant.types.resources.GZipResource(
62
                        new org.apache.tools.ant.types.resources.FileResource(
63
                        new File(archive))), new TarEntry(uri));
64
                res = gres;
65
                break;
66
 
67
            default: //This is type ZIP also
68
                ZipEntry zipentry = new ZipEntry(uri);
69
                if (zipentry.getTime() == -1) {
70
                    zipentry.setTime(System.currentTimeMillis());
71
                }
72
                res = new ZipResource(new File(archive), null, zipentry);
73
                break;
74
        }
75
 
76
        res.setProject(p);
77
        return res;
78
    }
79
}