From: <jsa...@us...> - 2008-11-05 16:15:15
|
Revision: 57 http://flexotask.svn.sourceforge.net/flexotask/?rev=57&view=rev Author: jsauerbach Date: 2008-11-05 16:15:07 +0000 (Wed, 05 Nov 2008) Log Message: ----------- Create AbstractRuntimeProvider to capture design pattern of provider zips in either a plugin or a plugin project. Make existing providers inherit from it. Modified Paths: -------------- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/OpenRuntimeProvider.java Added Paths: ----------- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/AbstractRuntimeProvider.java Added: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/AbstractRuntimeProvider.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/AbstractRuntimeProvider.java (rev 0) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/AbstractRuntimeProvider.java 2008-11-05 16:15:07 UTC (rev 57) @@ -0,0 +1,85 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * 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 + */ +package com.ibm.realtime.flexotask.editor.dialogs; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.eclipse.pde.core.plugin.PluginRegistry; +import org.osgi.framework.Bundle; + +/** + * An abstract implementation of RuntimeProvider supporting providers who keep a zip file in the + * root directory of a plugin. Supports the convenience that, if the plugin is in the workspace as + * a project, the project's copy of the zip file will be used in lieu of that installed formally + * as a plugin + */ +public abstract class AbstractRuntimeProvider implements RuntimeProvider +{ + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.dialogs.RuntimeProvider#contribute() + */ + public String contribute() + { + IPluginModelBase model = PluginRegistry.findModel(getPluginID()); + IPath root = null; + if (model != null && model.isEnabled()) { + /* We have the model. Check for a project in the current workspace representing the plugin. If it is there, use it */ + IResource resource = model.getUnderlyingResource(); + if (resource != null) { + IProject project = resource.getProject(); + root = project.getLocation(); + } + } + if (root == null) { + /* It wasn't a project so assume it's an OSGi bundle installed in the usual way */ + Bundle bundle = Platform.getBundle(getPluginID()); + URL entryURL = bundle.getEntry("/"); + try { + entryURL = FileLocator.toFileURL(entryURL); + File rootLoc = new File(entryURL.getPath()).getAbsoluteFile(); + if (rootLoc.exists()) { + root = Path.fromOSString(rootLoc.getAbsolutePath()); + } + } catch (IOException e) { + } + if (root == null) { + return null; + } + } + /* Have the root location. Append the file name to get a full path */ + return root.append(getZipFileName()).toString(); + } + + /** + * To be implemented by subclasses + * @return the name of the zipFile + */ + protected abstract String getZipFileName(); + + /** + * To be implemented by subclasses + * @return the plugin ID under which the zip file is to be found + */ + protected abstract String getPluginID(); +} \ No newline at end of file Property changes on: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/AbstractRuntimeProvider.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/OpenRuntimeProvider.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/OpenRuntimeProvider.java 2008-11-05 16:13:59 UTC (rev 56) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/dialogs/OpenRuntimeProvider.java 2008-11-05 16:15:07 UTC (rev 57) @@ -26,23 +26,21 @@ /** * RuntimeProvider providing just the things that are available in open source. */ -public class OpenRuntimeProvider implements RuntimeProvider +public class OpenRuntimeProvider extends AbstractRuntimeProvider { /* (non-Javadoc) - * @see com.ibm.realtime.flexotask.editor.dialogs.RuntimeProvider#contribute() + * @see com.ibm.realtime.flexotask.editor.dialogs.AbstractRuntimeProvider#getPluginID() */ - public String contribute() + protected String getPluginID() { - Bundle bundle = Platform.getBundle(EEditPlugin.ID); - URL entryURL = bundle.getEntry("/"); - try { - entryURL = FileLocator.toFileURL(entryURL); - File zipFile = new File(entryURL.getPath(), "openRuntimeProvider.zip").getAbsoluteFile(); - if (zipFile.exists()) { - return zipFile.getAbsolutePath(); - } - } catch (IOException e) { - } - return null; + return EEditPlugin.ID; } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.dialogs.AbstractRuntimeProvider#getZipFileName() + */ + protected String getZipFileName() + { + return "openRuntimeProvider.zip"; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |