Source Code Cross Referenced for JarLibAvailableTask.java in  » Build » ANT » org » apache » tools » ant » taskdefs » optional » extension » 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.optional.extension 
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:        package org.apache.tools.ant.taskdefs.optional.extension;
019:
020:        import java.io.File;
021:        import java.util.Iterator;
022:        import java.util.Vector;
023:        import java.util.jar.Manifest;
024:        import org.apache.tools.ant.BuildException;
025:        import org.apache.tools.ant.Task;
026:
027:        /**
028:         * Checks whether an extension is present in a fileset or an extensionSet.
029:         *
030:         * @ant.task name="jarlib-available"
031:         */
032:        public class JarLibAvailableTask extends Task {
033:            /**
034:             * The library to display information about.
035:             */
036:            private File libraryFile;
037:
038:            /**
039:             * Filesets specifying all the librarys
040:             * to display information about.
041:             */
042:            private final Vector extensionFileSets = new Vector();
043:
044:            /**
045:             * The name of the property to set if extension is available.
046:             */
047:            private String propertyName;
048:
049:            /**
050:             * The extension that is required.
051:             */
052:            private ExtensionAdapter requiredExtension;
053:
054:            /**
055:             * The name of property to set if extensions are available.
056:             *
057:             * @param property The name of property to set if extensions is available.
058:             */
059:            public void setProperty(final String property) {
060:                this .propertyName = property;
061:            }
062:
063:            /**
064:             * The JAR library to check.
065:             *
066:             * @param file The jar library to check.
067:             */
068:            public void setFile(final File file) {
069:                this .libraryFile = file;
070:            }
071:
072:            /**
073:             * Set the Extension looking for.
074:             *
075:             * @param extension Set the Extension looking for.
076:             */
077:            public void addConfiguredExtension(final ExtensionAdapter extension) {
078:                if (null != requiredExtension) {
079:                    final String message = "Can not specify extension to "
080:                            + "search for multiple times.";
081:                    throw new BuildException(message);
082:                }
083:                requiredExtension = extension;
084:            }
085:
086:            /**
087:             * Adds a set of extensions to search in.
088:             *
089:             * @param extensionSet a set of extensions to search in.
090:             */
091:            public void addConfiguredExtensionSet(
092:                    final ExtensionSet extensionSet) {
093:                extensionFileSets.addElement(extensionSet);
094:            }
095:
096:            /**
097:             * Execute the task.
098:             *
099:             * @throws BuildException if somethign goes wrong.
100:             */
101:            public void execute() throws BuildException {
102:                validate();
103:
104:                final Extension test = requiredExtension.toExtension();
105:
106:                // Check if list of files to check has been specified
107:                if (!extensionFileSets.isEmpty()) {
108:                    final Iterator iterator = extensionFileSets.iterator();
109:                    while (iterator.hasNext()) {
110:                        final ExtensionSet extensionSet = (ExtensionSet) iterator
111:                                .next();
112:                        final Extension[] extensions = extensionSet
113:                                .toExtensions(getProject());
114:                        for (int i = 0; i < extensions.length; i++) {
115:                            final Extension extension = extensions[i];
116:                            if (extension.isCompatibleWith(test)) {
117:                                getProject().setNewProperty(propertyName,
118:                                        "true");
119:                            }
120:                        }
121:                    }
122:                } else {
123:                    final Manifest manifest = ExtensionUtil
124:                            .getManifest(libraryFile);
125:                    final Extension[] extensions = Extension
126:                            .getAvailable(manifest);
127:                    for (int i = 0; i < extensions.length; i++) {
128:                        final Extension extension = extensions[i];
129:                        if (extension.isCompatibleWith(test)) {
130:                            getProject().setNewProperty(propertyName, "true");
131:                        }
132:                    }
133:                }
134:            }
135:
136:            /**
137:             * Validate the tasks parameters.
138:             *
139:             * @throws BuildException if invalid parameters found
140:             */
141:            private void validate() throws BuildException {
142:                if (null == requiredExtension) {
143:                    final String message = "Extension element must be specified.";
144:                    throw new BuildException(message);
145:                }
146:
147:                if (null == libraryFile && extensionFileSets.isEmpty()) {
148:                    final String message = "File attribute not specified.";
149:                    throw new BuildException(message);
150:                }
151:                if (null != libraryFile && !libraryFile.exists()) {
152:                    final String message = "File '" + libraryFile
153:                            + "' does not exist.";
154:                    throw new BuildException(message);
155:                }
156:                if (null != libraryFile && !libraryFile.isFile()) {
157:                    final String message = "\'" + libraryFile
158:                            + "\' is not a file.";
159:                    throw new BuildException(message);
160:                }
161:            }
162:        }
ww__w.___j___a___va___2s___._c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.