From: <jsa...@us...> - 2008-11-08 17:49:04
|
Revision: 73 http://flexotask.svn.sourceforge.net/flexotask/?rev=73&view=rev Author: jsauerbach Date: 2008-11-08 17:49:01 +0000 (Sat, 08 Nov 2008) Log Message: ----------- Automated generation of test project for those without repository access. Modified Paths: -------------- trunk/flexotask-development/plugin.xml Added Paths: ----------- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/MakeFunctionTestWizard.java Modified: trunk/flexotask-development/plugin.xml =================================================================== --- trunk/flexotask-development/plugin.xml 2008-11-08 17:48:32 UTC (rev 72) +++ trunk/flexotask-development/plugin.xml 2008-11-08 17:49:01 UTC (rev 73) @@ -16,6 +16,14 @@ name="Flexotask Project" project="true"> </wizard> + <wizard + category="com.ibm.realtime.flexotask" + class="com.ibm.realtime.flexotask.development.wizards.MakeFunctionTestWizard" + icon="icons/icon.gif" + id="com.ibm.realtime.flexotask.devplugin.wizards.MakeFunctionTestWizard" + name="Flexotask Function Test and Samples Project" + project="true"> + </wizard> </extension> <extension Added: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/MakeFunctionTestWizard.java =================================================================== --- trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/MakeFunctionTestWizard.java (rev 0) +++ trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/MakeFunctionTestWizard.java 2008-11-08 17:49:01 UTC (rev 73) @@ -0,0 +1,161 @@ +/* + * 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.development.wizards; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.util.zip.ZipFile; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.actions.WorkspaceModifyOperation; +import org.eclipse.ui.dialogs.IOverwriteQuery; +import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.wizards.datatransfer.ImportOperation; +import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; +import org.osgi.framework.Bundle; + +import com.ibm.realtime.flexotask.editor.EEditPlugin; + +/** + * A specialized newWizard (actually based most closely on the project import wizard) for generating + * the flexotask-functiontest project. + */ +public class MakeFunctionTestWizard extends Wizard implements INewWizard, IOverwriteQuery { + private static final String FUNCTIONTEST_PLUGIN_ID = "com.ibm.realtime.flexotask.functiontest"; + private static final String FUNCTIONTEST_ZIPFILE = "flexotaskFunctionTest.zip"; + private WizardNewProjectCreationPage mainPage; + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + public void addPages() { + mainPage = new WizardNewProjectCreationPage("project"); + mainPage.setTitle("Create a Flexotask Project"); + mainPage.setDescription("Create a Flexotask Project in the Workspace or external location"); + mainPage.setInitialProjectName("flexotask-functiontest"); + addPage(mainPage); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + // set icon + ImageDescriptor image = AbstractUIPlugin.imageDescriptorFromPlugin( + "FlexotaskBuilder", "icons/logo.gif"); + setDefaultPageImageDescriptor(image); + setNeedsProgressMonitor(true); + setWindowTitle("New Flexotask Function Test and Samples Project"); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + public boolean performFinish() { + WorkspaceModifyOperation op = new WorkspaceModifyOperation() { + protected void execute(IProgressMonitor monitor) throws CoreException, + InvocationTargetException, InterruptedException { + doFinish(monitor); + } + }; + try { + getContainer().run(false, true, op); + } catch (InvocationTargetException e) { + Throwable exception = e.getTargetException(); + IStatus status = null; + if (exception instanceof CoreException) { + status = ((CoreException) exception).getStatus(); + } + if (status == null) { + status = new Status(Status.ERROR, EEditPlugin.ID, exception.getMessage(), exception); + } + ResourcesPlugin.getPlugin().getLog().log(status); + ErrorDialog.openError(getShell(), "Error during project creation", status.getMessage(), status); + } catch (InterruptedException e) { + return false; + } + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.IOverwriteQuery#queryOverwrite(java.lang.String) + */ + public String queryOverwrite(String pathString) { + return YES; + } + + /** + * Subroutine containing the logic of performFinish, running under a WorkspaceModifyOperation + * @throws InvocationTargetException if a subsidiary operation throws one + * @throws InterruptedException if a subsidiary operation throws one (due to cancellation) + * @throws CoreException if a subsidiary operation throws one + */ + private void doFinish(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, CoreException + { + IProject project = mainPage.getProjectHandle(); + IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName()); + if (!mainPage.useDefaults()) { + desc.setLocation(mainPage.getLocationPath()); + } + project.create(desc, new SubProgressMonitor(monitor, 1)); + project.open(new SubProgressMonitor(monitor, 1)); + ZipFileStructureProvider provider = new ZipFileStructureProvider(getZipFile()); + Object root = provider.getRoot(); + ImportOperation op = new ImportOperation(project.getFullPath(), root, provider, this, provider.getChildren(root)); + op.setContext(getShell()); + op.run(monitor); + } + + /** + * Subroutine to find and return the ZipFile containing the flexotask-functiontest project image + * @return a ZipFile containing the flexotask-functiontest project image + * @throws CoreException if the ZipFile could not be located + */ + private ZipFile getZipFile() throws CoreException { + Bundle bundle = Platform.getBundle(FUNCTIONTEST_PLUGIN_ID); + URL entryURL = bundle.getEntry("/"); + File rootLoc; + try { + entryURL = FileLocator.toFileURL(entryURL); + rootLoc = new File(entryURL.getPath()).getAbsoluteFile(); + if (rootLoc.exists()) { + IPath root = Path.fromOSString(rootLoc.getAbsolutePath()); + return new ZipFile(root.append(FUNCTIONTEST_ZIPFILE).toString()); + } + } catch (IOException e) { + throw new CoreException(new Status(Status.ERROR, EEditPlugin.ID, e.getMessage(), e)); + } + throw new CoreException(new Status(Status.ERROR, EEditPlugin.ID, rootLoc + " does not exist")); + } +} Property changes on: trunk/flexotask-development/src/com/ibm/realtime/flexotask/development/wizards/MakeFunctionTestWizard.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |