KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > core > plugin > TargetPlatform


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.core.plugin;
12
13 import java.io.File JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.Properties JavaDoc;
16 import java.util.Set JavaDoc;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.core.runtime.Path;
21 import org.eclipse.core.runtime.Platform;
22 import org.eclipse.core.runtime.Preferences;
23 import org.eclipse.pde.internal.core.ICoreConstants;
24 import org.eclipse.pde.internal.core.PDECore;
25 import org.eclipse.pde.internal.core.TargetPlatformHelper;
26 import org.eclipse.pde.internal.core.UpdateManagerHelper;
27
28 /**
29  * The central class for the plug-in development target platform. This class cannot
30  * be instantiated or subclassed by clients; all functionality is provided
31  * by static methods. Features include:
32  * <ul>
33  * <li>the target platform's OS/WS/ARCH</li>
34  * <li>the default application and product</li>
35  * <li>the available applications and products</li>
36  * </ul>
37  * <p>
38  * @since 3.3
39  * </p>
40  */

41 public class TargetPlatform {
42     
43     private static String JavaDoc PRODUCT_PROPERTY = "eclipse.product"; //$NON-NLS-1$
44
private static String JavaDoc APPLICATION_PROPERTY = "eclipse.application"; //$NON-NLS-1$
45

46     private static String JavaDoc SDK_PRODUCT = "org.eclipse.sdk.ide"; //$NON-NLS-1$
47
private static String JavaDoc PLATFORM_PRODUCT = "org.eclipse.platform.ide"; //$NON-NLS-1$
48

49     private static String JavaDoc IDE_APPLICATION = "org.eclipse.ui.ide.workbench"; //$NON-NLS-1$
50

51     /**
52      * Returns the target platform's main location as specified on the <b>Environment</b>
53      * tab of the <b>Plug-in Development > Target Platform</b> preference page.
54      *
55      * @return the target platform's main location
56      */

57     public static String JavaDoc getLocation() {
58         Preferences preferences = PDECore.getDefault().getPluginPreferences();
59         return preferences.getString(ICoreConstants.PLATFORM_PATH);
60     }
61     
62     /**
63      * Returns the location of the default target platform, namely the location
64      * of the host (running) instance of Eclipse.
65      *
66      * @return the location of the default target platform
67      */

68     public static String JavaDoc getDefaultLocation() {
69         URL JavaDoc installURL = Platform.getInstallLocation().getURL();
70         IPath path = new Path(installURL.getFile()).removeTrailingSeparator();
71         return path.toOSString();
72         
73     }
74
75     /**
76      * Returns the target operating system as specified on the <b>Environment</b>
77      * tab of the <b>Plug-in Development > Target Platform</b> preference page.
78      *
79      * @return the target operating system
80      */

81     public static String JavaDoc getOS() {
82         return getProperty(ICoreConstants.OS, Platform.getOS());
83     }
84
85     /**
86      * Returns the target windowing system as specified on the <b>Environment</b>
87      * tab of the <b>Plug-in Development > Target Platform</b> preference page.
88      *
89      * @return the target windowing system
90      */

91     public static String JavaDoc getWS() {
92         return getProperty(ICoreConstants.WS, Platform.getWS());
93     }
94
95     /**
96      * Returns the target locale as specified on the <b>Environment</b>
97      * tab of the <b>Plug-in Development > Target Platform</b> preference page.
98      *
99      * @return the target locale
100      */

101     public static String JavaDoc getNL() {
102         return getProperty(ICoreConstants.NL, Platform.getNL());
103     }
104
105     /**
106      * Returns the target system architecture as specified on the <b>Environment</b>
107      * tab of the <b>Plug-in Development > Target Platform</b> preference page.
108      *
109      * @return the target system architecture
110      */

111     public static String JavaDoc getOSArch() {
112         return getProperty(ICoreConstants.ARCH, Platform.getOSArch());
113     }
114
115     private static String JavaDoc getProperty(String JavaDoc key, String JavaDoc defaultValue) {
116         Preferences preferences = PDECore.getDefault().getPluginPreferences();
117         String JavaDoc value = preferences.getString(key);
118         return value.equals("") ? defaultValue : value; //$NON-NLS-1$
119
}
120     
121     /**
122      * Returns a list of identifiers for all available applications
123      * (i.e. <code>org.eclipse.core.runtime.applications</code> extensions) declared in the workspace
124      * and target platform plug-ins.
125      * <p>
126      * If a workspace plug-in has the same ID as a plug-in in the target platform, the extensions
127      * declared in the target counterpart are ignored.
128      * </p>
129      *
130      * @return a list of identifiers for all available applications
131      */

132     public static String JavaDoc[] getApplications() {
133         return TargetPlatformHelper.getApplicationNames();
134     }
135     
136     /**
137      * Returns a list of identifiers for all available products
138      * (i.e. <code>org.eclipse.core.runtime.products</code> extensions) declared in the workspace
139      * and target platform plug-ins.
140      * <p>
141      * If a workspace plug-in has the same ID as a plug-in in the target platform, the extensions
142      * declared in the target counterpart are ignored.
143      * </p>
144      *
145      * @return a list of identifiers for all available products
146      */

147     public static String JavaDoc[] getProducts() {
148         return TargetPlatformHelper.getProductNames();
149     }
150     
151     /**
152      * Returns the ID for the default product
153      * (<code>org.eclipse.core.runtime.products</code> extension) for the current target platform,
154      * or <code>null</code> if none can be determined.
155      *
156      * If any of the
157      *
158      * @return the ID for the default product or <code>null</code> if none could be determined
159      */

160     public static String JavaDoc getDefaultProduct() {
161         Properties JavaDoc config = TargetPlatformHelper.getConfigIniProperties();
162         Set JavaDoc set = TargetPlatformHelper.getProductNameSet();
163         if (config != null) {
164             String JavaDoc product = (String JavaDoc) config.get(PRODUCT_PROPERTY);
165             if (product != null && set.contains(product))
166                 return product;
167         }
168
169         if (set.contains(SDK_PRODUCT))
170             return SDK_PRODUCT;
171         
172         return set.contains(PLATFORM_PRODUCT) ? PLATFORM_PRODUCT : null;
173     }
174
175     /**
176      * Returns the ID for the default application
177      * (<code>org.eclipse.core.runtime.applications</code> extension) for the current target
178      * platform.
179      * <p>
180      * If none could be determined, then <code>org.eclipse.ui.ide.workbench</code>
181      * application is returned.
182      * </p>
183      * @return the default application to run when launching an Eclipse application
184      */

185     public static String JavaDoc getDefaultApplication() {
186         Properties JavaDoc config = TargetPlatformHelper.getConfigIniProperties();
187         Set JavaDoc set = TargetPlatformHelper.getApplicationNameSet();
188         if (config != null) {
189             String JavaDoc application = (String JavaDoc) config.get(APPLICATION_PROPERTY);
190             if (application != null && set.contains(application))
191                 return application;
192         }
193         return IDE_APPLICATION;
194     }
195     
196     /**
197      * Creates a platform configuration to be used when launching an Eclipse
198      * application that uses Update Manager as a configurator
199      *
200      * @param location the location where the configuration should be persisted
201      * @param plugins the list of plug-ins that make up the configuration
202      * @param brandingPlugin if specified, a entry for the feature containing the branding plug-in will
203      * be created in the platform configuration
204      *
205      * @throws CoreException an exception is thrown if there was a problem writing the platform
206      * configuration file
207      */

208     public static void createPlatformConfiguration(
209             File JavaDoc location, IPluginModelBase[] plugins, IPluginModelBase brandingPlugin)
210             throws CoreException {
211         UpdateManagerHelper.createPlatformConfiguration(location, plugins, brandingPlugin);
212     }
213     
214     /**
215     * The comma-separated list of bundles which are automatically installed
216     * and optionally started.
217     * <p>
218     * Each entry if of the form <bundleID>[@ [<startlevel>] [":start"]]
219     * If the startlevel is omitted then the framework will use the default start level for the bundle.
220     * If the "start" tag is added then the bundle will be marked as started after being installed.
221     * </p>
222     * <p>
223     * The list computed is based on the <b>osgi.bundles</b> key found in the config.ini
224     * file of the target platform. If no such key is found, then a suitable list is computed
225     * based on the target platform version.
226     * </p>
227     *
228     * @return a comma-separated list of bundles that are automatically installed
229     * and optionally started when a runtime Eclipse application is launched.
230     */

231     public static String JavaDoc getBundleList() {
232         return TargetPlatformHelper.getBundleList();
233     }
234         
235 }
236
Popular Tags