Source Code Cross Referenced for PluginPathFinder.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » build » site » 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 » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.build.site 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2007 IBM Corporation and others. All rights reserved.
003:         * This program and the accompanying materials are made available under the
004:         * terms of the Eclipse Public License v1.0 which accompanies this distribution,
005:         * and is available at http://www.eclipse.org/legal/epl-v10.html
006:         * 
007:         * Contributors: IBM - Initial API and implementation
008:         ******************************************************************************/package org.eclipse.pde.internal.build.site;
009:
010:        import java.io.*;
011:        import java.net.MalformedURLException;
012:        import java.net.URL;
013:        import java.util.ArrayList;
014:        import java.util.Properties;
015:        import org.eclipse.core.runtime.IPath;
016:        import org.eclipse.core.runtime.Path;
017:        import org.eclipse.pde.internal.build.Utils;
018:        import org.eclipse.update.configurator.ConfiguratorUtils;
019:        import org.eclipse.update.configurator.IPlatformConfiguration;
020:
021:        public class PluginPathFinder {
022:            private static final String URL_PROPERTY = "org.eclipse.update.resolution_url"; //$NON-NLS-1$
023:            private static final String EMPTY_STRING = ""; //$NON-NLS-1$
024:
025:            /**
026:             * 
027:             * @param platformHome
028:             * @param linkFile
029:             * @param features false for plugins, true for features
030:             * @return path of plugins or features directory of an extension site
031:             */
032:            private static String getSitePath(String platformHome,
033:                    File linkFile, boolean features) {
034:                String prefix = new Path(platformHome).removeLastSegments(1)
035:                        .toString();
036:                Properties properties = new Properties();
037:                try {
038:                    FileInputStream fis = new FileInputStream(linkFile);
039:                    properties.load(fis);
040:                    fis.close();
041:                    String path = properties.getProperty("path"); //$NON-NLS-1$
042:                    if (path != null) {
043:                        if (!new Path(path).isAbsolute())
044:                            path = prefix + IPath.SEPARATOR + path;
045:                        path += IPath.SEPARATOR + "eclipse" + IPath.SEPARATOR; //$NON-NLS-1$
046:                        if (features)
047:                            path += "features"; //$NON-NLS-1$
048:                        else
049:                            path += "plugins"; //$NON-NLS-1$
050:                        if (new File(path).exists()) {
051:                            return path;
052:                        }
053:                    }
054:                } catch (IOException e) {
055:                }
056:                return null;
057:            }
058:
059:            /**
060:             * 
061:             * @param platformHome
062:             * @param features false for plugin sites, true for feature sites
063:             * @return array of ".../plugins" or ".../features" Files
064:             */
065:            private static File[] getSites(String platformHome, boolean features) {
066:                ArrayList sites = new ArrayList();
067:
068:                File file = new File(platformHome,
069:                        features ? "features" : "plugins"); //$NON-NLS-1$ //$NON-NLS-2$
070:                if (!features && !file.exists())
071:                    file = new File(platformHome);
072:                if (file.exists())
073:                    sites.add(file);
074:
075:                File[] linkFiles = new File(platformHome + IPath.SEPARATOR
076:                        + "links").listFiles(); //$NON-NLS-1$	
077:                if (linkFiles != null) {
078:                    for (int i = 0; i < linkFiles.length; i++) {
079:                        String path = getSitePath(platformHome, linkFiles[i],
080:                                features);
081:                        if (path != null) {
082:                            sites.add(new File(path));
083:                        }
084:                    }
085:                }
086:                return (File[]) sites.toArray(new File[sites.size()]);
087:            }
088:
089:            public static File[] getFeaturePaths(String platformHome) {
090:                return getPaths(platformHome, true);
091:            }
092:
093:            public static File[] getPluginPaths(String platformHome) {
094:                return getPaths(platformHome, false);
095:            }
096:
097:            public static File[] getPaths(String platformHome, boolean features) {
098:                File file = new File(platformHome,
099:                        "configuration/org.eclipse.update/platform.xml"); //$NON-NLS-1$
100:                if (file.exists()) {
101:                    try {
102:                        String value = new Path(platformHome).toFile().toURL()
103:                                .toExternalForm();
104:                        System.setProperty(URL_PROPERTY, value);
105:                        try {
106:                            IPlatformConfiguration config = ConfiguratorUtils
107:                                    .getPlatformConfiguration(file.toURL());
108:                            return Utils.asFile(getConfiguredSitesPaths(
109:                                    platformHome, config, features));
110:                        } finally {
111:                            System.setProperty(URL_PROPERTY, EMPTY_STRING);
112:                        }
113:                    } catch (MalformedURLException e) {
114:                    } catch (IOException e) {
115:                    }
116:                }
117:
118:                return Utils.asFile(scanLocations(getSites(platformHome,
119:                        features)));
120:            }
121:
122:            private static URL[] getConfiguredSitesPaths(String platformHome,
123:                    IPlatformConfiguration configuration, boolean features) {
124:                URL[] installPlugins = scanLocations(new File[] { new File(
125:                        platformHome, features ? "features" : "plugins") }); //$NON-NLS-1$ //$NON-NLS-2$
126:                URL[] extensionPlugins = getExtensionPluginURLs(configuration,
127:                        features);
128:
129:                URL[] all = new URL[installPlugins.length
130:                        + extensionPlugins.length];
131:                System.arraycopy(installPlugins, 0, all, 0,
132:                        installPlugins.length);
133:                System.arraycopy(extensionPlugins, 0, all,
134:                        installPlugins.length, extensionPlugins.length);
135:                return all;
136:            }
137:
138:            /**
139:             * 
140:             * @param config
141:             * @param features true for features false for plugins
142:             * @return URLs for features or plugins on the site
143:             */
144:            private static URL[] getExtensionPluginURLs(
145:                    IPlatformConfiguration config, boolean features) {
146:                ArrayList extensionPlugins = new ArrayList();
147:                IPlatformConfiguration.ISiteEntry[] sites = config
148:                        .getConfiguredSites();
149:                for (int i = 0; i < sites.length; i++) {
150:                    URL url = sites[i].getURL();
151:                    if ("file".equalsIgnoreCase(url.getProtocol())) { //$NON-NLS-1$
152:                        String[] entries;
153:                        if (features)
154:                            entries = sites[i].getFeatures();
155:                        else
156:                            entries = sites[i].getPlugins();
157:                        for (int j = 0; j < entries.length; j++) {
158:                            try {
159:                                extensionPlugins.add(new File(url.getFile(),
160:                                        entries[j]).toURL());
161:                            } catch (MalformedURLException e) {
162:                            }
163:                        }
164:                    }
165:                }
166:                return (URL[]) extensionPlugins
167:                        .toArray(new URL[extensionPlugins.size()]);
168:            }
169:
170:            /**
171:             * Scan given plugin/feature directories or jars for existence
172:             * @param sites
173:             * @return URLs to plugins/features
174:             */
175:            private static URL[] scanLocations(File[] sites) {
176:                ArrayList result = new ArrayList();
177:                for (int i = 0; i < sites.length; i++) {
178:                    if (!sites[i].exists())
179:                        continue;
180:                    File[] children = sites[i].listFiles();
181:                    if (children != null) {
182:                        for (int j = 0; j < children.length; j++) {
183:                            try {
184:                                result.add(children[j].toURL());
185:                            } catch (MalformedURLException e) {
186:                            }
187:                        }
188:                    }
189:                }
190:                return (URL[]) result.toArray(new URL[result.size()]);
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.