Source Code Cross Referenced for ExtensionUtil.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.io.IOException;
022:        import java.util.ArrayList;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.jar.JarFile;
026:        import java.util.jar.Manifest;
027:
028:        import org.apache.tools.ant.BuildException;
029:        import org.apache.tools.ant.DirectoryScanner;
030:        import org.apache.tools.ant.Project;
031:        import org.apache.tools.ant.types.FileSet;
032:
033:        /**
034:         * A set of useful methods relating to extensions.
035:         *
036:         */
037:        public class ExtensionUtil {
038:            /**
039:             * Class is not meant to be instantiated.
040:             */
041:            private ExtensionUtil() {
042:                //all methods static
043:            }
044:
045:            /**
046:             * Convert a list of extensionAdapter objects to extensions.
047:             *
048:             * @param adapters the list of ExtensionAdapterss to add to convert
049:             * @throws BuildException if an error occurs
050:             */
051:            static ArrayList toExtensions(final List adapters)
052:                    throws BuildException {
053:                final ArrayList results = new ArrayList();
054:
055:                final int size = adapters.size();
056:                for (int i = 0; i < size; i++) {
057:                    final ExtensionAdapter adapter = (ExtensionAdapter) adapters
058:                            .get(i);
059:                    final Extension extension = adapter.toExtension();
060:                    results.add(extension);
061:                }
062:
063:                return results;
064:            }
065:
066:            /**
067:             * Generate a list of extensions from a specified fileset.
068:             *
069:             * @param libraries the list to add extensions to
070:             * @param fileset the filesets containing librarys
071:             * @throws BuildException if an error occurs
072:             */
073:            static void extractExtensions(final Project project,
074:                    final List libraries, final List fileset)
075:                    throws BuildException {
076:                if (!fileset.isEmpty()) {
077:                    final Extension[] extensions = getExtensions(project,
078:                            fileset);
079:                    for (int i = 0; i < extensions.length; i++) {
080:                        libraries.add(extensions[i]);
081:                    }
082:                }
083:            }
084:
085:            /**
086:             * Retrieve extensions from the specified libraries.
087:             *
088:             * @param libraries the filesets for libraries
089:             * @return the extensions contained in libraries
090:             * @throws BuildException if failing to scan libraries
091:             */
092:            private static Extension[] getExtensions(final Project project,
093:                    final List libraries) throws BuildException {
094:                final ArrayList extensions = new ArrayList();
095:                final Iterator iterator = libraries.iterator();
096:                while (iterator.hasNext()) {
097:                    final FileSet fileSet = (FileSet) iterator.next();
098:
099:                    boolean includeImpl = true;
100:                    boolean includeURL = true;
101:
102:                    if (fileSet instanceof  LibFileSet) {
103:                        LibFileSet libFileSet = (LibFileSet) fileSet;
104:                        includeImpl = libFileSet.isIncludeImpl();
105:                        includeURL = libFileSet.isIncludeURL();
106:                    }
107:
108:                    final DirectoryScanner scanner = fileSet
109:                            .getDirectoryScanner(project);
110:                    final File basedir = scanner.getBasedir();
111:                    final String[] files = scanner.getIncludedFiles();
112:                    for (int i = 0; i < files.length; i++) {
113:                        final File file = new File(basedir, files[i]);
114:                        loadExtensions(file, extensions, includeImpl,
115:                                includeURL);
116:                    }
117:                }
118:                return (Extension[]) extensions
119:                        .toArray(new Extension[extensions.size()]);
120:            }
121:
122:            /**
123:             * Load list of available extensions from specified file.
124:             *
125:             * @param file the file
126:             * @param extensionList the list to add available extensions to
127:             * @throws BuildException if there is an error
128:             */
129:            private static void loadExtensions(final File file,
130:                    final List extensionList, final boolean includeImpl,
131:                    final boolean includeURL) throws BuildException {
132:                try {
133:                    final JarFile jarFile = new JarFile(file);
134:                    final Extension[] extensions = Extension
135:                            .getAvailable(jarFile.getManifest());
136:                    for (int i = 0; i < extensions.length; i++) {
137:                        final Extension extension = extensions[i];
138:                        addExtension(extensionList, extension, includeImpl,
139:                                includeURL);
140:                    }
141:                } catch (final Exception e) {
142:                    throw new BuildException(e.getMessage(), e);
143:                }
144:            }
145:
146:            /**
147:             * Add extension to list.
148:             * If extension should not have implementation details but
149:             * does strip them. If extension should not have url but does
150:             * then strip it.
151:             *
152:             * @param extensionList the list of extensions to add to
153:             * @param originalExtension the extension
154:             * @param includeImpl false to exclude implementation details
155:             * @param includeURL false to exclude implementation URL
156:             */
157:            private static void addExtension(final List extensionList,
158:                    final Extension originalExtension,
159:                    final boolean includeImpl, final boolean includeURL) {
160:                Extension extension = originalExtension;
161:                if (!includeURL && null != extension.getImplementationURL()) {
162:                    extension = new Extension(extension.getExtensionName(),
163:                            extension.getSpecificationVersion().toString(),
164:                            extension.getSpecificationVendor(), extension
165:                                    .getImplementationVersion().toString(),
166:                            extension.getImplementationVendor(), extension
167:                                    .getImplementationVendorID(), null);
168:                }
169:
170:                final boolean hasImplAttributes = null != extension
171:                        .getImplementationURL()
172:                        || null != extension.getImplementationVersion()
173:                        || null != extension.getImplementationVendorID()
174:                        || null != extension.getImplementationVendor();
175:
176:                if (!includeImpl && hasImplAttributes) {
177:                    extension = new Extension(extension.getExtensionName(),
178:                            extension.getSpecificationVersion().toString(),
179:                            extension.getSpecificationVendor(), null, null,
180:                            null, extension.getImplementationURL());
181:                }
182:
183:                extensionList.add(extension);
184:            }
185:
186:            /**
187:             * Retrieve manifest for specified file.
188:             *
189:             * @param file the file
190:             * @return the manifest
191:             * @throws BuildException if errror occurs (file doesn't exist,
192:             *         file not a jar, manifest doesn't exist in file)
193:             */
194:            static Manifest getManifest(final File file) throws BuildException {
195:                try {
196:                    final JarFile jarFile = new JarFile(file);
197:                    Manifest m = jarFile.getManifest();
198:                    if (m == null) {
199:                        throw new BuildException(file
200:                                + " doesn't have a MANIFEST");
201:                    }
202:                    return m;
203:                } catch (final IOException ioe) {
204:                    throw new BuildException(ioe.getMessage(), ioe);
205:                }
206:            }
207:        }
w_w_w__.__j__a_v___a___2__s___.___co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.