sysperfana/memspyext/com.nokia.s60tools.heapanalyser/src/com/nokia/s60tools/heapanalyser/HeapAnalyserPlugin.java
changeset 7 8e12a575a9b5
equal deleted inserted replaced
6:f65f740e69f9 7:8e12a575a9b5
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 package com.nokia.s60tools.heapanalyser;
       
    21 
       
    22 import java.io.File;
       
    23 import java.net.URL;
       
    24 
       
    25 import org.eclipse.core.runtime.FileLocator;
       
    26 import org.eclipse.core.runtime.Plugin;
       
    27 import org.osgi.framework.BundleContext;
       
    28 
       
    29 /**
       
    30  * The activator class controls the plug-in life cycle
       
    31  */
       
    32 public class HeapAnalyserPlugin extends Plugin {
       
    33 
       
    34 	/**
       
    35 	 * The plug-in ID for Heap Analyser.
       
    36 	 */
       
    37 	public static final String PLUGIN_ID = "com.nokia.s60tools.heapanalyser";
       
    38 
       
    39 	private String pluginInstallPath = "";
       
    40 
       
    41 	// The shared instance
       
    42 	private static HeapAnalyserPlugin plugin;
       
    43 	
       
    44 	/**
       
    45 	 * The constructor
       
    46 	 */
       
    47 	public HeapAnalyserPlugin() {
       
    48 	}
       
    49 
       
    50 	/*
       
    51 	 * (non-Javadoc)
       
    52 	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
       
    53 	 */
       
    54 	public void start(BundleContext context) throws Exception {
       
    55 		super.start(context);
       
    56 		plugin = this;
       
    57 	}
       
    58 
       
    59 	/*
       
    60 	 * (non-Javadoc)
       
    61 	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
       
    62 	 */
       
    63 	public void stop(BundleContext context) throws Exception {
       
    64 		plugin = null;
       
    65 		super.stop(context);
       
    66 	}
       
    67 
       
    68 	/**
       
    69 	 * Returns the shared instance
       
    70 	 *
       
    71 	 * @return the shared instance
       
    72 	 */
       
    73 	public static HeapAnalyserPlugin getDefault() {
       
    74 		return plugin;
       
    75 	}
       
    76 
       
    77 	/**
       
    78 	 * Returns the path where this plugin is installed
       
    79 	 * @return the path where this plugin is installed
       
    80 	 */
       
    81 	public static String getPluginInstallPath() {
       
    82 		try {
       
    83 			if ("".equals(plugin.pluginInstallPath)) {
       
    84 				 // URL to the plugin's root ("/")
       
    85 				URL relativeURL = plugin.getBundle().getEntry("/"); 
       
    86 				//	Converting into local path
       
    87 				URL localURL = FileLocator.toFileURL(relativeURL);
       
    88 				//	Getting install location in correct form
       
    89 				File f = new File(localURL.getPath());
       
    90 				plugin.pluginInstallPath = f.getAbsolutePath();
       
    91 			}
       
    92 			return plugin.pluginInstallPath;
       
    93 		} catch (Exception e) {
       
    94 			return "";
       
    95 		}
       
    96 	}	
       
    97 	
       
    98 }