| /******************************************************************************* |
| * Copyright (c) 2010 Eteration A.S. and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| * - This code is based on WTP SDK frameworks and Tomcat Server Adapters |
| * org.eclipse.jst.server.core |
| * org.eclipse.jst.server.ui |
| * |
| * Naci Dai and Murat Yener, Eteration A.S. |
| *******************************************************************************/ |
| package org.eclipse.libra.framework.core; |
| |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.Platform; |
| import org.eclipse.core.runtime.preferences.DefaultScope; |
| import org.eclipse.pde.core.project.IBundleProjectDescription; |
| import org.eclipse.pde.core.project.IBundleProjectService; |
| import org.eclipse.pde.internal.core.PDECore; |
| import org.eclipse.ui.plugin.AbstractUIPlugin; |
| import org.osgi.framework.BundleContext; |
| |
| |
| public class FrameworkCorePlugin extends AbstractUIPlugin { |
| |
| // The plug-in ID |
| public static final String PLUGIN_ID = "org.eclipse.libra.framework.core"; //$NON-NLS-1$ |
| |
| // The shared instance |
| private static FrameworkCorePlugin plugin; |
| |
| /** |
| * The constructor |
| */ |
| public FrameworkCorePlugin() { |
| super(); |
| plugin = this; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
| */ |
| public void start(BundleContext context) throws Exception { |
| super.start(context); |
| plugin = this; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
| */ |
| public void stop(BundleContext context) throws Exception { |
| plugin = null; |
| super.stop(context); |
| } |
| |
| /** |
| * Returns the shared instance |
| * |
| * @return the shared instance |
| */ |
| public static FrameworkCorePlugin getDefault() { |
| return plugin; |
| } |
| |
| |
| |
| public static String getPreference(String id) { |
| return Platform.getPreferencesService().getString(PLUGIN_ID, id, "", null); |
| } |
| |
| public static void setPreference(String id, String value) { |
| (new DefaultScope()).getNode(PLUGIN_ID).put(id, value); |
| } |
| |
| |
| public static IBundleProjectService getBundleProjectService() { |
| PDECore instance = PDECore.getDefault(); |
| if (instance == null) |
| return null; |
| return (IBundleProjectService) instance.acquireService(IBundleProjectService.class.getName()); |
| } |
| |
| public static IBundleProjectDescription getDescription(IProject project) throws CoreException { |
| try { |
| return getBundleProjectService().getDescription(project); |
| } |
| catch (IllegalArgumentException e) { |
| return null; |
| } |
| } |
| |
| |
| } |