• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.ndk.internal;
18 
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.ui.plugin.AbstractUIPlugin;
24 import org.osgi.framework.Bundle;
25 import org.osgi.framework.BundleContext;
26 import org.osgi.framework.ServiceReference;
27 
28 import java.net.URL;
29 
30 /**
31  * The activator class controls the plug-in life cycle
32  */
33 public class Activator extends AbstractUIPlugin {
34 
35     // The plug-in ID
36     public static final String PLUGIN_ID = "com.android.ide.eclipse.ndk"; //$NON-NLS-1$
37 
38     // The shared instance
39     private static Activator mPlugin;
40 
41     @Override
start(BundleContext context)42     public void start(BundleContext context) throws Exception {
43         super.start(context);
44         mPlugin = this;
45     }
46 
47     @Override
stop(BundleContext context)48     public void stop(BundleContext context) throws Exception {
49         mPlugin = null;
50         super.stop(context);
51     }
52 
getDefault()53     public static Activator getDefault() {
54         return mPlugin;
55     }
56 
getService(Class<T> clazz)57     public static <T> T getService(Class<T> clazz) {
58         BundleContext context = mPlugin.getBundle().getBundleContext();
59         ServiceReference ref = context.getServiceReference(clazz.getName());
60         return (ref != null) ? (T) context.getService(ref) : null;
61     }
62 
getBundle(String id)63     public static Bundle getBundle(String id) {
64         for (Bundle bundle : mPlugin.getBundle().getBundleContext().getBundles()) {
65             if (bundle.getSymbolicName().equals(id)) {
66                 return bundle;
67             }
68         }
69         return null;
70     }
71 
newStatus(Exception e)72     public static IStatus newStatus(Exception e) {
73         return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e);
74     }
75 
log(Exception e)76     public static void log(Exception e) {
77         mPlugin.getLog().log(newStatus(e));
78     }
79 
findFile(IPath path)80     public static URL findFile(IPath path) {
81         return FileLocator.find(mPlugin.getBundle(), path, null);
82     }
83 
84 }
85