KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > PDE


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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;
12
13 import java.io.*;
14 import java.lang.reflect.*;
15 import java.net.*;
16
17 import org.eclipse.core.resources.*;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.pde.internal.builders.*;
20 import org.osgi.framework.*;
21
22
23 public class PDE extends Plugin {
24     public static final String JavaDoc PLUGIN_ID = "org.eclipse.pde"; //$NON-NLS-1$
25

26     public static final String JavaDoc MANIFEST_BUILDER_ID =
27         PLUGIN_ID + "." + "ManifestBuilder"; //$NON-NLS-1$ //$NON-NLS-2$
28
public static final String JavaDoc SCHEMA_BUILDER_ID =
29         PLUGIN_ID + "." + "SchemaBuilder"; //$NON-NLS-1$ //$NON-NLS-2$
30
public static final String JavaDoc PLUGIN_NATURE = PLUGIN_ID + "." + "PluginNature"; //$NON-NLS-1$ //$NON-NLS-2$
31
public static final String JavaDoc FEATURE_NATURE = PLUGIN_ID + "." + "FeatureNature"; //$NON-NLS-1$ //$NON-NLS-2$
32
public static final String JavaDoc SITE_NATURE = PLUGIN_ID + "." + "UpdateSiteNature"; //$NON-NLS-1$ //$NON-NLS-2$
33
public static final String JavaDoc FEATURE_BUILDER_ID =
34         PLUGIN_ID + "." + "FeatureBuilder"; //$NON-NLS-1$ //$NON-NLS-2$
35
public static final String JavaDoc SITE_BUILDER_ID =
36         PLUGIN_ID + "." + "UpdateSiteBuilder"; //$NON-NLS-1$ //$NON-NLS-2$
37

38     // Shared instance
39
private static PDE fInstance;
40     
41     private BundleContext fBundleContext;
42     
43     private FeatureRebuilder fFeatureRebuilder;
44     
45     public PDE() {
46         fInstance = this;
47     }
48     public BundleContext getBundleContext(){
49         return fBundleContext;
50     }
51     /* (non-Javadoc)
52      * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
53      */

54     public void start(BundleContext context) throws Exception JavaDoc {
55         fBundleContext = context;
56         super.start(context);
57         CompilerFlags.initializeDefaults();
58         fFeatureRebuilder = new FeatureRebuilder();
59         fFeatureRebuilder.start();
60     }
61     
62     /* (non-Javadoc)
63      * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
64      */

65     public void stop(BundleContext context) throws Exception JavaDoc {
66         fFeatureRebuilder.stop();
67         fFeatureRebuilder = null;
68         super.stop(context);
69         fInstance = null;
70         fBundleContext = null;
71     }
72
73     public URL getInstallURL() {
74         try {
75             return Platform.resolve(getDefault().getBundle().getEntry("/")); //$NON-NLS-1$
76
} catch (IOException e) {
77             return null;
78         }
79     }
80     
81     public static boolean hasPluginNature(IProject project) {
82         try {
83             return project.hasNature(PLUGIN_NATURE);
84         } catch (CoreException e) {
85             log(e);
86             return false;
87         }
88     }
89     
90     public static boolean hasFeatureNature(IProject project) {
91         try {
92             return project.hasNature(FEATURE_NATURE);
93         } catch (CoreException e) {
94             log(e);
95             return false;
96         }
97     }
98
99     public static boolean hasUpdateSiteNature(IProject project) {
100         try {
101             return project.hasNature(SITE_NATURE);
102         } catch (CoreException e) {
103             log(e);
104             return false;
105         }
106     }
107     
108     public static PDE getDefault() {
109         return fInstance;
110     }
111
112     public static String JavaDoc getPluginId() {
113         return getDefault().getBundle().getSymbolicName();
114     }
115     
116     public static IWorkspace getWorkspace() {
117         return ResourcesPlugin.getWorkspace();
118     }
119     
120     public static void log(IStatus status) {
121         ResourcesPlugin.getPlugin().getLog().log(status);
122     }
123
124     public static void logErrorMessage(String JavaDoc message) {
125         log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null));
126     }
127
128     public static void logException(
129         Throwable JavaDoc e,
130         final String JavaDoc title,
131         String JavaDoc message) {
132         if (e instanceof InvocationTargetException) {
133             e = ((InvocationTargetException) e).getTargetException();
134         }
135         IStatus status = null;
136         if (e instanceof CoreException)
137             status = ((CoreException) e).getStatus();
138         else {
139             if (message == null)
140                 message = e.getMessage();
141             if (message == null)
142                 message = e.toString();
143             status = new Status(IStatus.ERROR, getPluginId(), IStatus.OK, message, e);
144         }
145         ResourcesPlugin.getPlugin().getLog().log(status);
146     }
147
148     public static void logException(Throwable JavaDoc e) {
149         logException(e, null, null);
150     }
151
152     public static void log(Throwable JavaDoc e) {
153         if (e instanceof InvocationTargetException)
154             e = ((InvocationTargetException) e).getTargetException();
155         IStatus status = null;
156         if (e instanceof CoreException)
157             status = ((CoreException) e).getStatus();
158         else
159             status =
160                 new Status(IStatus.ERROR, getPluginId(), IStatus.OK, e.getMessage(), e);
161         log(status);
162     }
163 }
164
Popular Tags