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


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