Subversion Repositories XServices

Rev

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

Rev 6 Rev 10
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
 
16
 
17
package net.brutex.xservices.types;
17
package net.brutex.xservices.types;
18
 
18
 
19
import java.io.File;
19
import java.io.File;
20
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlEnum;
21
import javax.xml.bind.annotation.XmlEnum;
22
import javax.xml.bind.annotation.XmlType;
22
import javax.xml.bind.annotation.XmlType;
-
 
23
import net.brutex.xservices.util.BrutexNamespaces;
23
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.types.Resource;
25
import org.apache.tools.ant.types.Resource;
25
import org.apache.tools.ant.types.resources.TarResource;
26
import org.apache.tools.ant.types.resources.TarResource;
26
import org.apache.tools.ant.types.resources.ZipResource;
27
import org.apache.tools.ant.types.resources.ZipResource;
27
import org.apache.tools.tar.TarEntry;
28
import org.apache.tools.tar.TarEntry;
28
import org.apache.tools.zip.ZipEntry;
29
import org.apache.tools.zip.ZipEntry;
29
 
30
 
30
/**
31
/**
-
 
32
 * Resource from archive declaration.
31
 * 
33
 *
-
 
34
 * Defines a resource within an archive.
32
 * @author Brian Rosenberger, bru@brutex.de
35
 * @author Brian Rosenberger, bru@brutex.de
33
 */
36
 */
34
@XmlType(namespace = "http://ws.xservices.brutex.net")
37
@XmlType(namespace = BrutexNamespaces.WS_XSERVICES, name="ArchiveResourceType")
35
public class ArchiveResource
38
public class ArchiveResource
36
        implements ResourceInterface {
39
        implements ResourceInterface {
-
 
40
 
-
 
41
    /**
-
 
42
     * Archive Type.
37
 
43
     */
38
    @XmlElement(defaultValue = "ZIP", nillable = false, required = true)
44
    @XmlElement(defaultValue = "ZIP", nillable = false, required = true)
-
 
45
    public ArchiveType type = ArchiveType.ZIP;
-
 
46
 
-
 
47
    /**
-
 
48
     * Archive file.
-
 
49
     *
-
 
50
     * Path and filename of the archive to use.
39
    public ArchiveType type = ArchiveType.ZIP;
51
     */
40
    @XmlElement(nillable = false, required = true)
52
    @XmlElement(nillable = false, required = true)
-
 
53
    public String archive;
-
 
54
 
-
 
55
    /**
-
 
56
     * URI within the archive.
-
 
57
     *
-
 
58
     * This is usually a filename or a path/filename combination. Relative paths
-
 
59
     * are based from the archive root. It depends on how the archive has been
-
 
60
     * created wether or not it is possible to use relative paths, absolute
-
 
61
     * paths are required otherwise. Uses "/" as separator.
41
    public String archive;
62
     */
42
    @XmlElement(nillable = false, required = true)
63
    @XmlElement(nillable = false, required = true)
43
    public String uri;
64
    public String uri;
-
 
65
 
-
 
66
    /**
-
 
67
     * Supported archive types.
44
 
68
     */
45
    @XmlEnum(String.class)
69
    @XmlEnum(value=String.class)
-
 
70
    public enum ArchiveType {
-
 
71
 
-
 
72
        /**
-
 
73
         * Zip archive type.
-
 
74
         */
-
 
75
        ZIP,
-
 
76
 
-
 
77
        /**
-
 
78
         * Tar archive type, without compression
-
 
79
         */
-
 
80
        TAR,
-
 
81
        
-
 
82
        /**
46
    public enum ArchiveType {
83
         * Tar archive type, with GZIP compression
47
 
84
         */
-
 
85
        GZTAR
-
 
86
    }
-
 
87
 
-
 
88
    /**
-
 
89
     * Get Apache Ant Resource Type.
-
 
90
     *
48
        ZIP, TAR, GZTAR
91
     * @param p     Ant project
49
    }
92
     * @return      this ArchiveResource as Ant Resource
50
 
93
     */
51
    public Resource getAntResource(Project p) {
94
    public Resource getAntResource(Project p) {
52
        Resource res = null;
95
        Resource res = null;
53
        switch (type) {
96
        switch (type) {
54
            case TAR:
97
            case TAR:
55
                TarEntry tarentry = new TarEntry(uri);
98
                TarEntry tarentry = new TarEntry(uri);
56
                TarResource tres = new TarResource(new File(archive), tarentry);
99
                TarResource tres = new TarResource(new File(archive), tarentry);
57
                res = tres;
100
                res = tres;
58
                break;
101
                break;
59
 
102
 
60
            case GZTAR:
103
            case GZTAR:
61
                TarResource gres = new TarResource(new org.apache.tools.ant.types.resources.GZipResource(
104
                TarResource gres = new TarResource(new org.apache.tools.ant.types.resources.GZipResource(
62
                        new org.apache.tools.ant.types.resources.FileResource(
105
                        new org.apache.tools.ant.types.resources.FileResource(
63
                        new File(archive))), new TarEntry(uri));
106
                        new File(archive))), new TarEntry(uri));
64
                res = gres;
107
                res = gres;
65
                break;
108
                break;
66
 
109
 
67
            default: //This is type ZIP also
110
            default: //This is type ZIP also
68
                ZipEntry zipentry = new ZipEntry(uri);
111
                ZipEntry zipentry = new ZipEntry(uri);
69
                if (zipentry.getTime() == -1) {
112
                if (zipentry.getTime() == -1) {
70
                    zipentry.setTime(System.currentTimeMillis());
113
                    zipentry.setTime(System.currentTimeMillis());
71
                }
114
                }
72
                res = new ZipResource(new File(archive), null, zipentry);
115
                res = new ZipResource(new File(archive), null, zipentry);
73
                break;
116
                break;
74
        }
117
        }
75
 
118
 
76
        res.setProject(p);
119
        res.setProject(p);
77
        return res;
120
        return res;
78
    }
121
    }
79
}
122
}