KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > PDECore


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.internal.core;
12
13 import java.io.IOException JavaDoc;
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.resources.IWorkspace;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.FileLocator;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.NullProgressMonitor;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.core.runtime.Plugin;
26 import org.eclipse.core.runtime.QualifiedName;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.pde.core.plugin.IPluginModelBase;
29 import org.eclipse.pde.internal.core.builders.CompilerFlags;
30 import org.eclipse.pde.internal.core.builders.FeatureRebuilder;
31 import org.eclipse.pde.internal.core.builders.PluginRebuilder;
32 import org.eclipse.pde.internal.core.schema.SchemaRegistry;
33 import org.eclipse.update.configurator.ConfiguratorUtils;
34 import org.osgi.framework.BundleContext;
35
36 public class PDECore extends Plugin {
37     public static final String JavaDoc PLUGIN_ID = "org.eclipse.pde.core"; //$NON-NLS-1$
38

39     public static final IPath REQUIRED_PLUGINS_CONTAINER_PATH = new Path(PLUGIN_ID + ".requiredPlugins"); //$NON-NLS-1$
40
public static final IPath JAVA_SEARCH_CONTAINER_PATH = new Path(PLUGIN_ID + ".externalJavaSearch"); //$NON-NLS-1$
41

42     public static final String JavaDoc BINARY_PROJECT_VALUE = "binary"; //$NON-NLS-1$
43
public static final String JavaDoc BINARY_REPOSITORY_PROVIDER = PLUGIN_ID + "." + "BinaryRepositoryProvider"; //$NON-NLS-1$ //$NON-NLS-2$
44

45     public static final QualifiedName EXTERNAL_PROJECT_PROPERTY = new QualifiedName(PLUGIN_ID, "imported"); //$NON-NLS-1$
46
public static final QualifiedName TOUCH_PROJECT = new QualifiedName(PLUGIN_ID, "TOUCH_PROJECT"); //$NON-NLS-1$
47

48     public static final QualifiedName SCHEMA_PREVIEW_FILE =
49         new QualifiedName(PLUGIN_ID, "SCHEMA_PREVIEW_FILE"); //$NON-NLS-1$
50

51     // Shared instance
52
private static PDECore inst;
53     
54     private static IPluginModelBase[] registryPlugins;
55
56     public static PDECore getDefault() {
57         return inst;
58     }
59     
60     public static IWorkspace getWorkspace() {
61         return ResourcesPlugin.getWorkspace();
62     }
63
64     public static void log(IStatus status) {
65         if (status != null)
66             ResourcesPlugin.getPlugin().getLog().log(status);
67     }
68
69     public static void log(Throwable JavaDoc e) {
70         if (e instanceof InvocationTargetException JavaDoc)
71             e = ((InvocationTargetException JavaDoc) e).getTargetException();
72         IStatus status = null;
73         if (e instanceof CoreException) {
74             status = ((CoreException) e).getStatus();
75         } else if (e.getMessage() != null) {
76             status = new Status(
77                     IStatus.ERROR,
78                     PLUGIN_ID,
79                     IStatus.OK,
80                     e.getMessage(),
81                     e);
82         }
83         log(status);
84     }
85
86     public static void logErrorMessage(String JavaDoc message) {
87         log(new Status(
88                 IStatus.ERROR,
89                 PLUGIN_ID,
90                 IStatus.ERROR,
91                 message,
92                 null));
93     }
94
95     public static void logException(Throwable JavaDoc e) {
96         logException(e, null);
97     }
98
99     public static void logException(Throwable JavaDoc e, String JavaDoc message) {
100         if (e instanceof InvocationTargetException JavaDoc) {
101             e = ((InvocationTargetException JavaDoc) e).getTargetException();
102         }
103         IStatus status = null;
104         if (e instanceof CoreException)
105             status = ((CoreException) e).getStatus();
106         else {
107             if (message == null)
108                 message = e.getMessage();
109             if (message == null)
110                 message = e.toString();
111             status =
112                 new Status(
113                     IStatus.ERROR,
114                     PLUGIN_ID,
115                     IStatus.OK,
116                     message,
117                     e);
118         }
119         log(status);
120     }
121     
122     private PluginModelManager fModelManager;
123     private FeatureModelManager fFeatureModelManager;
124     
125     private TargetDefinitionManager fTargetProfileManager;
126
127     // Schema registry
128
private SchemaRegistry fSchemaRegistry;
129
130     private SourceLocationManager fSourceLocationManager;
131     private JavadocLocationManager fJavadocLocationManager;
132     private SearchablePluginsManager fSearchablePluginsManager;
133
134     // Tracing options manager
135
private TracingOptionsManager fTracingOptionsManager;
136     private BundleContext fBundleContext;
137     private JavaElementChangeListener fJavaElementChangeListener;
138
139     private FeatureRebuilder fFeatureRebuilder;
140
141     private PluginRebuilder fPluginRebuilder;
142
143     public PDECore() {
144         inst = this;
145     }
146
147     public URL JavaDoc getInstallURL() {
148         try {
149             return FileLocator.resolve(getDefault().getBundle().getEntry("/")); //$NON-NLS-1$
150
} catch (IOException JavaDoc e) {
151             return null;
152         }
153     }
154     
155     public IPluginModelBase findPluginInHost(String JavaDoc id) {
156         if (registryPlugins == null) {
157             URL JavaDoc[] pluginPaths = ConfiguratorUtils.getCurrentPlatformConfiguration().getPluginPath();
158             PDEState state = new PDEState(pluginPaths, false, new NullProgressMonitor());
159             registryPlugins = state.getTargetModels();
160         }
161
162         for (int i = 0; i < registryPlugins.length; i++) {
163             if (registryPlugins[i].getPluginBase().getId().equals(id))
164                 return registryPlugins[i];
165         }
166         return null;
167     }
168
169     public PluginModelManager getModelManager() {
170         if (fModelManager == null)
171             fModelManager = new PluginModelManager();
172         return fModelManager;
173     }
174     
175     public TargetDefinitionManager getTargetProfileManager() {
176         if (fTargetProfileManager == null)
177             fTargetProfileManager = new TargetDefinitionManager();
178         return fTargetProfileManager;
179     }
180     
181     public FeatureModelManager getFeatureModelManager() {
182         if (fFeatureModelManager == null)
183             fFeatureModelManager = new FeatureModelManager();
184         return fFeatureModelManager;
185     }
186     
187     public JavaElementChangeListener getJavaElementChangeListener() {
188         return fJavaElementChangeListener;
189     }
190     
191     public SchemaRegistry getSchemaRegistry() {
192         if (fSchemaRegistry == null)
193             fSchemaRegistry = new SchemaRegistry();
194         return fSchemaRegistry;
195     }
196
197     public SourceLocationManager getSourceLocationManager() {
198         if (fSourceLocationManager == null)
199             fSourceLocationManager = new SourceLocationManager();
200         return fSourceLocationManager;
201     }
202     
203     public JavadocLocationManager getJavadocLocationManager() {
204         if (fJavadocLocationManager == null)
205             fJavadocLocationManager = new JavadocLocationManager();
206         return fJavadocLocationManager;
207     }
208
209     public TracingOptionsManager getTracingOptionsManager() {
210         if (fTracingOptionsManager == null)
211             fTracingOptionsManager = new TracingOptionsManager();
212         return fTracingOptionsManager;
213     }
214     
215     public SearchablePluginsManager getSearchablePluginsManager() {
216         if (fSearchablePluginsManager == null) {
217             fSearchablePluginsManager = new SearchablePluginsManager();
218             try {
219                 getWorkspace().addSaveParticipant(inst, fSearchablePluginsManager);
220             } catch (CoreException e) {
221                 log(e);
222             }
223         }
224         return fSearchablePluginsManager;
225     }
226     
227     public boolean areModelsInitialized() {
228         return fModelManager != null && fModelManager.isInitialized();
229     }
230
231     public void start(BundleContext context) throws Exception JavaDoc {
232         super.start(context);
233         fBundleContext = context;
234         CompilerFlags.initializeDefaults();
235         fJavaElementChangeListener = new JavaElementChangeListener();
236         fJavaElementChangeListener.start();
237         fPluginRebuilder = new PluginRebuilder();
238         fPluginRebuilder.start();
239         fFeatureRebuilder = new FeatureRebuilder();
240         fFeatureRebuilder.start();
241     }
242
243     public BundleContext getBundleContext() {
244         return fBundleContext;
245     }
246
247     public void stop(BundleContext context) throws CoreException {
248         PDECore.getDefault().savePluginPreferences();
249         
250         fJavaElementChangeListener.shutdown();
251         fPluginRebuilder.stop();
252         fFeatureRebuilder.stop();
253         
254         if (fSchemaRegistry != null) {
255             fSchemaRegistry.shutdown();
256             fSchemaRegistry = null;
257         }
258         if (fTargetProfileManager != null) {
259             fTargetProfileManager.shutdown();
260             fTargetProfileManager = null;
261         }
262         if (fSearchablePluginsManager != null) {
263             getWorkspace().removeSaveParticipant(inst);
264             fSearchablePluginsManager.shutdown();
265             fSearchablePluginsManager = null;
266         }
267         if (fFeatureModelManager != null) {
268             fFeatureModelManager.shutdown();
269             fFeatureModelManager = null;
270         }
271         if (fModelManager != null) {
272             fModelManager.shutdown();
273             fModelManager = null;
274         }
275     }
276 }
277
Popular Tags