Source Code Cross Referenced for Unpack.java in  » Build » ANT » org » apache » tools » ant » taskdefs » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » ANT » org.apache.tools.ant.taskdefs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.taskdefs;
020:
021:        import java.io.File;
022:        import org.apache.tools.ant.BuildException;
023:        import org.apache.tools.ant.Task;
024:        import org.apache.tools.ant.types.Resource;
025:        import org.apache.tools.ant.types.ResourceCollection;
026:        import org.apache.tools.ant.types.resources.FileResource;
027:
028:        /**
029:         * Abstract Base class for unpack tasks.
030:         *
031:         * @since Ant 1.5
032:         */
033:
034:        public abstract class Unpack extends Task {
035:            // CheckStyle:VisibilityModifier OFF - bc
036:            protected File source;
037:            protected File dest;
038:            protected Resource srcResource;
039:
040:            // CheckStyle:VisibilityModifier ON
041:
042:            /**
043:             * @deprecated since 1.5.x.
044:             *             setSrc(String) is deprecated and is replaced with
045:             *             setSrc(File) to make Ant's Introspection
046:             *             mechanism do the work and also to encapsulate operations on
047:             *             the type in its own class.
048:             * @ant.attribute ignore="true"
049:             * @param src a <code>String</code> value
050:             */
051:            public void setSrc(String src) {
052:                log("DEPRECATED - The setSrc(String) method has been deprecated."
053:                        + " Use setSrc(File) instead.");
054:                setSrc(getProject().resolveFile(src));
055:            }
056:
057:            /**
058:             * @deprecated since 1.5.x.
059:             *             setDest(String) is deprecated and is replaced with
060:             *             setDest(File) to make Ant's Introspection
061:             *             mechanism do the work and also to encapsulate operations on
062:             *             the type in its own class.
063:             * @ant.attribute ignore="true"
064:             * @param dest a <code>String</code> value
065:             */
066:            public void setDest(String dest) {
067:                log("DEPRECATED - The setDest(String) method has been deprecated."
068:                        + " Use setDest(File) instead.");
069:                setDest(getProject().resolveFile(dest));
070:            }
071:
072:            /**
073:             * The file to expand; required.
074:             * @param src file to expand
075:             */
076:            public void setSrc(File src) {
077:                setSrcResource(new FileResource(src));
078:            }
079:
080:            /**
081:             * The resource to expand; required.
082:             * @param src resource to expand
083:             */
084:            public void setSrcResource(Resource src) {
085:                if (!src.isExists()) {
086:                    throw new BuildException("the archive doesn't exist");
087:                }
088:                if (src.isDirectory()) {
089:                    throw new BuildException("the archive can't be a directory");
090:                }
091:                if (src instanceof  FileResource) {
092:                    source = ((FileResource) src).getFile();
093:                } else if (!supportsNonFileResources()) {
094:                    throw new BuildException("Only FileSystem resources are"
095:                            + " supported.");
096:                }
097:                srcResource = src;
098:            }
099:
100:            /**
101:             * Set the source Archive resource.
102:             * @param a the archive as a single element Resource collection.
103:             */
104:            public void addConfigured(ResourceCollection a) {
105:                if (a.size() != 1) {
106:                    throw new BuildException(
107:                            "only single argument resource collections"
108:                                    + " are supported as archives");
109:                }
110:                setSrcResource((Resource) a.iterator().next());
111:            }
112:
113:            /**
114:             * The destination file or directory; optional.
115:             * @param dest destination file or directory
116:             */
117:            public void setDest(File dest) {
118:                this .dest = dest;
119:            }
120:
121:            private void validate() throws BuildException {
122:                if (srcResource == null) {
123:                    throw new BuildException("No Src specified", getLocation());
124:                }
125:
126:                if (dest == null) {
127:                    dest = new File(source.getParent());
128:                }
129:
130:                if (dest.isDirectory()) {
131:                    String defaultExtension = getDefaultExtension();
132:                    createDestFile(defaultExtension);
133:                }
134:            }
135:
136:            private void createDestFile(String defaultExtension) {
137:                String sourceName = source.getName();
138:                int len = sourceName.length();
139:                if (defaultExtension != null
140:                        && len > defaultExtension.length()
141:                        && defaultExtension.equalsIgnoreCase(sourceName
142:                                .substring(len - defaultExtension.length()))) {
143:                    dest = new File(dest, sourceName.substring(0, len
144:                            - defaultExtension.length()));
145:                } else {
146:                    dest = new File(dest, sourceName);
147:                }
148:            }
149:
150:            /**
151:             * Execute the task.
152:             * @throws BuildException on error
153:             */
154:            public void execute() throws BuildException {
155:                File savedDest = dest; // may be altered in validate
156:                try {
157:                    validate();
158:                    extract();
159:                } finally {
160:                    dest = savedDest;
161:                }
162:            }
163:
164:            /**
165:             * Get the extension.
166:             * This is to be overridden by subclasses.
167:             * @return the default extension.
168:             */
169:            protected abstract String getDefaultExtension();
170:
171:            /**
172:             * Do the uncompressing.
173:             * This is to be overridden by subclasses.
174:             */
175:            protected abstract void extract();
176:
177:            /**
178:             * Whether this task can deal with non-file resources.
179:             *
180:             * <p>This implementation returns false.</p>
181:             * @return false for this task.
182:             * @since Ant 1.7
183:             */
184:            protected boolean supportsNonFileResources() {
185:                return false;
186:            }
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.