diff options
author | relves | 2007-05-18 20:11:26 +0000 |
---|---|---|
committer | relves | 2007-05-18 20:11:26 +0000 |
commit | 7f395c9c97f84e487812a1f14aa1e0371e304fe6 (patch) | |
tree | 6cd5ae22819b286c41cdba82c97568c80578748f | |
parent | 17f9302d122ee0404ecc97381b13966ac4c96dce (diff) | |
download | org.eclipse.mylyn.tasks-7f395c9c97f84e487812a1f14aa1e0371e304fe6.tar.gz org.eclipse.mylyn.tasks-7f395c9c97f84e487812a1f14aa1e0371e304fe6.tar.xz org.eclipse.mylyn.tasks-7f395c9c97f84e487812a1f14aa1e0371e304fe6.zip |
NEW - bug 174993: [api] Move duplicate initialization code to ITaskDataHandler.initializeTaskData()
https://bugs.eclipse.org/bugs/show_bug.cgi?id=174993
3 files changed, 122 insertions, 172 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java index 7dfd995d0..94140fd94 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java @@ -25,13 +25,15 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; +import org.eclipse.mylar.core.MylarStatusHandler; +import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; +import org.eclipse.mylar.tasks.core.RepositoryTaskData; import org.eclipse.mylar.tasks.core.TaskRepository; import org.osgi.framework.BundleContext; /** - * The main plug-in class to be used in the desktop. - * - * @author Mik Kersten (added support for multiple repositories) + * @author Mik Kersten + * @author Rob Elves */ public class BugzillaCorePlugin extends Plugin { @@ -46,14 +48,35 @@ public class BugzillaCorePlugin extends Plugin { private static boolean cacheFileRead = false; private static File repositoryConfigurationFile = null; - + private static BugzillaRepositoryConnector connector; + private static final String OPTION_ALL = "All"; + + // A Map from Java's OS and Platform to Buzilla's + private Map<String, String> java2buzillaOSMap = new HashMap<String, String>(); + + private Map<String, String> java2buzillaPlatformMap = new HashMap<String, String>(); + /** Product configuration for the current server */ private static Map<String, RepositoryConfiguration> repositoryConfigurations = new HashMap<String, RepositoryConfiguration>(); public BugzillaCorePlugin() { super(); + java2buzillaPlatformMap.put("x86", "PC"); + java2buzillaPlatformMap.put("x86_64", "PC"); + java2buzillaPlatformMap.put("ia64", "PC"); + java2buzillaPlatformMap.put("ia64_32", "PC"); + java2buzillaPlatformMap.put("sparc", "Sun"); + java2buzillaPlatformMap.put("ppc", "Power"); + + java2buzillaOSMap.put("aix", "AIX"); + java2buzillaOSMap.put("hpux", "HP-UX"); + java2buzillaOSMap.put("linux", "Linux"); + java2buzillaOSMap.put("macosx", "Mac OS"); + java2buzillaOSMap.put("qnx", "QNX-Photon"); + java2buzillaOSMap.put("solaris", "Solaris"); + java2buzillaOSMap.put("win32", "Windows XP"); } public static BugzillaCorePlugin getDefault() { @@ -74,11 +97,11 @@ public class BugzillaCorePlugin extends Plugin { INSTANCE = null; super.stop(context); } - + static void setConnector(BugzillaRepositoryConnector theConnector) { connector = theConnector; } - + public static Map<String, RepositoryConfiguration> getConfigurations() { if (!cacheFileRead) { readRepositoryConfigurationFile(); @@ -87,7 +110,6 @@ public class BugzillaCorePlugin extends Plugin { return repositoryConfigurations; } - public static void setConfigurationCacheFile(File file) { repositoryConfigurationFile = file; } @@ -98,27 +120,29 @@ public class BugzillaCorePlugin extends Plugin { public static RepositoryConfiguration getRepositoryConfiguration(String repositoryUrl) { return repositoryConfigurations.get(repositoryUrl); } - + /** * Retrieves the latest repository configuration from the server */ - public static RepositoryConfiguration getRepositoryConfiguration(TaskRepository repository, boolean forceRefresh) throws CoreException { + public static RepositoryConfiguration getRepositoryConfiguration(TaskRepository repository, boolean forceRefresh) + throws CoreException { try { - if (!cacheFileRead) { - readRepositoryConfigurationFile(); - cacheFileRead = true; - } - if (repositoryConfigurations.get(repository.getUrl()) == null || forceRefresh) { - BugzillaClient client = connector.getClientManager().getClient(repository); - RepositoryConfiguration config = client.getRepositoryConfiguration(); - if(config != null) { - addRepositoryConfiguration(config); + if (!cacheFileRead) { + readRepositoryConfigurationFile(); + cacheFileRead = true; } - - } - return repositoryConfigurations.get(repository.getUrl()); - } catch (Exception e){ - throw new CoreException(new Status(Status.ERROR, BugzillaCorePlugin.PLUGIN_ID, 1, "Error updating attributes.\n\n"+e.getMessage(), e)); + if (repositoryConfigurations.get(repository.getUrl()) == null || forceRefresh) { + BugzillaClient client = connector.getClientManager().getClient(repository); + RepositoryConfiguration config = client.getRepositoryConfiguration(); + if (config != null) { + addRepositoryConfiguration(config); + } + + } + return repositoryConfigurations.get(repository.getUrl()); + } catch (Exception e) { + throw new CoreException(new Status(Status.ERROR, BugzillaCorePlugin.PLUGIN_ID, 1, + "Error updating attributes.\n\n" + e.getMessage(), e)); } } @@ -246,4 +270,76 @@ public class BugzillaCorePlugin extends Plugin { IPath bugFile = stateLocation.append("bugReports"); return bugFile; } + + public void setPlatformOptions(RepositoryTaskData newBugModel) { + try { + + // Get OS Lookup Map + // Check that the result is in Values, if it is not, set it to other + RepositoryTaskAttribute opSysAttribute = newBugModel.getAttribute(BugzillaReportElement.OP_SYS + .getKeyString()); + RepositoryTaskAttribute platformAttribute = newBugModel.getAttribute(BugzillaReportElement.REP_PLATFORM + .getKeyString()); + + String OS = Platform.getOS(); + String platform = Platform.getOSArch(); + + String bugzillaOS = null; // Bugzilla String for OS + String bugzillaPlatform = null; // Bugzilla String for Platform + + if (java2buzillaOSMap != null && java2buzillaOSMap.containsKey(OS) && opSysAttribute != null + && opSysAttribute.getOptions() != null) { + bugzillaOS = java2buzillaOSMap.get(OS); + if (opSysAttribute != null && opSysAttribute.getOptionParameter(bugzillaOS) == null) { + // If the OS we found is not in the list of available + // options, set bugzillaOS + // to null, and just use "other" + bugzillaOS = null; + } + } else { + // If we have a strangeOS, then just set buzillaOS to null, and + // use "other" + bugzillaOS = null; + } + + if (platform != null && java2buzillaPlatformMap.containsKey(platform)) { + bugzillaPlatform = java2buzillaPlatformMap.get(platform); + if (platformAttribute != null && platformAttribute.getOptionParameter(bugzillaPlatform) == null) { + // If the platform we found is not int the list of available + // optinos, set the + // Bugzilla Platform to null, and juse use "other" + bugzillaPlatform = null; + } + } else { + // If we have a strange platform, then just set bugzillaPatforrm + // to null, and use "other" + bugzillaPlatform = null; + } + if (bugzillaPlatform != null && bugzillaPlatform.compareTo("PC") == 0 && bugzillaOS != null + && bugzillaOS.compareTo("Mac OS") == 0) + // Intel Mac's return PC as Platform because the OSArch == "x86" + // so we change the Plaform if the bugzilla OS tell us it is an + // Mac OS + // + // btw bugzilla 3.0rc1 set Platform to PC in enter_bug.cgi + // pickplatform + // move line 225 before 202 to fix this. + bugzillaPlatform = "Macintosh"; + // Set the OS and the Platform in the taskData + if (bugzillaOS != null && opSysAttribute != null) { + opSysAttribute.setValue(bugzillaOS); + } else if (opSysAttribute != null && opSysAttribute.getOptionParameter(OPTION_ALL) != null) { + opSysAttribute.setValue(OPTION_ALL); + } + + if (bugzillaPlatform != null && platformAttribute != null) { + platformAttribute.setValue(bugzillaPlatform); + } else if (platformAttribute != null && platformAttribute.getOptionParameter(OPTION_ALL) != null) { + opSysAttribute.setValue(OPTION_ALL); + } + + } catch (Exception e) { + MylarStatusHandler.fail(e, "could not set platform options", false); + } + } } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java index 21cfa6b53..f0a80e516 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java @@ -19,11 +19,9 @@ import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement; import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector; import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; -import org.eclipse.mylar.internal.bugzilla.ui.wizard.BugzillaProductPage; import org.eclipse.mylar.tasks.core.RepositoryTaskData; import org.eclipse.mylar.tasks.core.Task; import org.eclipse.mylar.tasks.core.TaskRepository; -import org.eclipse.ui.PlatformUI; /** * @author Mik Kersten @@ -39,8 +37,7 @@ public class NewBugWizardTest extends TestCase { TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_220_URL); BugzillaRepositoryConnector.setupNewBugAttributes(repository, newReport); - BugzillaProductPage page = new BugzillaProductPage(PlatformUI.getWorkbench(), null, repository); - page.setPlatformOptions(newReport); + BugzillaCorePlugin.getDefault().setPlatformOptions(newReport); String os = Platform.getOS(); if (os.equals("win32")) diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java index c468b0920..69d4aa22d 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java @@ -17,15 +17,12 @@ import java.net.URLDecoder; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; @@ -52,7 +49,6 @@ import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin; import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylar.tasks.core.ITask; -import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; import org.eclipse.mylar.tasks.core.RepositoryTaskData; import org.eclipse.mylar.tasks.core.TaskRepository; import org.eclipse.mylar.tasks.ui.TasksUiPlugin; @@ -82,13 +78,6 @@ import org.eclipse.ui.progress.UIJob; */ public class BugzillaProductPage extends WizardPage { - private static final String OPTION_ALL = "All"; - - // A Map from Java's OS and Platform to Buzilla's - private Map<String, String> java2buzillaOSMap = new HashMap<String, String>(); - - private Map<String, String> java2buzillaPlatformMap = new HashMap<String, String>(); - private static final String NEW_BUGZILLA_TASK_ERROR_TITLE = "New Bugzilla Task Error"; private static final String DESCRIPTION = "Pick a product to open the new bug editor.\n" @@ -138,20 +127,6 @@ public class BugzillaProductPage extends WizardPage { setImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin("org.eclipse.mylar.bugzilla.ui", "icons/wizban/bug-wizard.gif")); - java2buzillaPlatformMap.put("x86", "PC"); - java2buzillaPlatformMap.put("x86_64", "PC"); - java2buzillaPlatformMap.put("ia64", "PC"); - java2buzillaPlatformMap.put("ia64_32", "PC"); - java2buzillaPlatformMap.put("sparc", "Sun"); - java2buzillaPlatformMap.put("ppc", "Power"); - - java2buzillaOSMap.put("aix", "AIX"); - java2buzillaOSMap.put("hpux", "HP-UX"); - java2buzillaOSMap.put("linux", "Linux"); - java2buzillaOSMap.put("macosx", "Mac OS"); - java2buzillaOSMap.put("qnx", "QNX-Photon"); - java2buzillaOSMap.put("solaris", "Solaris"); - java2buzillaOSMap.put("win32", "Windows XP"); } public void createControl(Composite parent) { @@ -316,7 +291,7 @@ public class BugzillaProductPage extends WizardPage { Object element = selection.getFirstElement(); if (element instanceof BugzillaTask) { - BugzillaTask bugzillaTask = (BugzillaTask) element; + BugzillaTask bugzillaTask = (BugzillaTask) element; if (bugzillaTask.getProduct() != null) { products.add(bugzillaTask.getProduct()); } @@ -415,7 +390,7 @@ public class BugzillaProductPage extends WizardPage { model.setAttributeValue(BugzillaReportElement.PRODUCT.getKeyString(), (String) ((IStructuredSelection) productList.getViewer().getSelection()).getFirstElement()); BugzillaRepositoryConnector.setupNewBugAttributes(repository, model); - setPlatformOptions(model); + BugzillaCorePlugin.getDefault().setPlatformOptions(model); } @Override @@ -424,122 +399,4 @@ public class BugzillaProductPage extends WizardPage { return bugWizard.completed; } - public void setPlatformOptions(RepositoryTaskData newBugModel) { - try { - - // Get OS Lookup Map - // Check that the result is in Values, if it is not, set it to other - RepositoryTaskAttribute opSysAttribute = newBugModel.getAttribute(BugzillaReportElement.OP_SYS - .getKeyString()); - RepositoryTaskAttribute platformAttribute = newBugModel.getAttribute(BugzillaReportElement.REP_PLATFORM - .getKeyString()); - - String OS = Platform.getOS(); - String platform = Platform.getOSArch(); - - String bugzillaOS = null; // Bugzilla String for OS - String bugzillaPlatform = null; // Bugzilla String for Platform - - if (java2buzillaOSMap != null && java2buzillaOSMap.containsKey(OS) && opSysAttribute != null - && opSysAttribute.getOptions() != null) { - bugzillaOS = java2buzillaOSMap.get(OS); - if (opSysAttribute != null && opSysAttribute.getOptionParameter(bugzillaOS) == null) { - // If the OS we found is not in the list of available - // options, set bugzillaOS - // to null, and just use "other" - bugzillaOS = null; - } - } else { - // If we have a strangeOS, then just set buzillaOS to null, and - // use "other" - bugzillaOS = null; - } - - if (platform != null && java2buzillaPlatformMap.containsKey(platform)) { - bugzillaPlatform = java2buzillaPlatformMap.get(platform); - if (platformAttribute != null && platformAttribute.getOptionParameter(bugzillaPlatform) == null) { - // If the platform we found is not int the list of available - // optinos, set the - // Bugzilla Platform to null, and juse use "other" - bugzillaPlatform = null; - } - } else { - // If we have a strange platform, then just set bugzillaPatforrm - // to null, and use "other" - bugzillaPlatform = null; - } - if (bugzillaPlatform!= null && bugzillaPlatform.compareTo("PC")== 0 && - bugzillaOS!= null && bugzillaOS.compareTo("Mac OS")== 0) - // Intel Mac's return PC as Platform because the OSArch == "x86" - // so we change the Plaform if the bugzilla OS tell us it is an Mac OS - // - // btw bugzilla 3.0rc1 set Platform to PC in enter_bug.cgi pickplatform - // move line 225 before 202 to fix this. - bugzillaPlatform = "Macintosh"; - // Set the OS and the Platform in the taskData - if (bugzillaOS != null && opSysAttribute != null) { - opSysAttribute.setValue(bugzillaOS); - } else if (opSysAttribute != null && opSysAttribute.getOptionParameter(OPTION_ALL) != null) { - opSysAttribute.setValue(OPTION_ALL); - } - - if (bugzillaPlatform != null && platformAttribute != null) { - platformAttribute.setValue(bugzillaPlatform); - } else if (platformAttribute != null && platformAttribute.getOptionParameter(OPTION_ALL) != null) { - opSysAttribute.setValue(OPTION_ALL); - } - - } catch (Exception e) { - MylarStatusHandler.fail(e, "could not set platform options", false); - } - } - - // @Override - // public IWizardPage getNextPage() { - // // save the product information to the taskData - // saveDataToModel(); - // NewBugzillaTaskWizard wizard = (NewBugzillaTaskWizard) getWizard(); - // NewBugzillaTaskData taskData = wizard.model; - // - // // try to get the attributes from the bugzilla server - // try { - // if (!taskData.hasParsedAttributes() || - // !taskData.getProduct().equals(prevProduct)) { - // BugzillaRepositoryUtil.setupNewBugAttributes(repository.getUrl(), - // MylarTaskListPlugin.getDefault() - // .getProxySettings(), repository.getUserName(), repository.getPassword(), - // taskData, repository - // .getCharacterEncoding()); - // taskData.setParsedAttributesStatus(true); - // } - // - // // if (prevProduct == null) { - // // bugWizard.setAttributePage(new WizardAttributesPage(workbench)); - // // bugWizard.addPage(bugWizard.getAttributePage()); - // // } else { - // // // selected product has changed - // // // will createControl again with new attributes in taskData - // // bugWizard.getAttributePage().setControl(null); - // // } - // - // } catch (final Exception e) { - // e.printStackTrace(); - // PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - // public void run() { - // MessageDialog.openError(Display.getDefault().getActiveShell(), - // NEW_BUGZILLA_TASK_ERROR_TITLE, e - // .getLocalizedMessage() - // + " Ensure proper repository configuration in " + - // TaskRepositoriesView.NAME + "."); - // } - // }); - // // MylarStatusHandler.fail(e, e.getLocalizedMessage()+" Ensure - // // proper repository configuration in - // // "+TaskRepositoriesView.NAME+".", true); - // // BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e, - // // "occurred.", "Bugzilla Error"); - // } - // return super.getNextPage(); - // } - } |