Subversion Repositories XServices

Rev

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

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