Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfbecker2009-10-02 20:24:59 +0000
committerfbecker2009-10-02 20:24:59 +0000
commit0680038bab07835148d9d8942962737a45add5dc (patch)
tree5e7f39766d95ec6d5478530986d0bc95050d151e /org.eclipse.mylyn.bugzilla.core/src
parent131696d6a498bebfe6a05e967f5b6c0e1ce5076d (diff)
downloadorg.eclipse.mylyn.tasks-0680038bab07835148d9d8942962737a45add5dc.tar.gz
org.eclipse.mylyn.tasks-0680038bab07835148d9d8942962737a45add5dc.tar.xz
org.eclipse.mylyn.tasks-0680038bab07835148d9d8942962737a45add5dc.zip
ASSIGNED - bug 289663: remove circular dependency between BugzillaCorePlugin and BugzillaTaskDataHandler
https://bugs.eclipse.org/bugs/show_bug.cgi?id=289663
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core/src')
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java11
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java30
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java13
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java9
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java384
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java8
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java376
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java44
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java7
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java9
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java6
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java10
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java10
13 files changed, 462 insertions, 455 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java
index bdc2be37e..a96078108 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java
@@ -42,8 +42,11 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper {
private final String dateFormat_3_TimeZone = "yyyy-MM-dd zzz"; //$NON-NLS-1$
- public BugzillaAttributeMapper(TaskRepository taskRepository) {
+ private final BugzillaRepositoryConnector connector;
+
+ public BugzillaAttributeMapper(TaskRepository taskRepository, BugzillaRepositoryConnector connector) {
super(taskRepository);
+ this.connector = connector;
}
@Override
@@ -93,7 +96,7 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper {
RepositoryConfiguration repositoryConfiguration;
BugzillaVersion bugzillaVersion = null;
- repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(getTaskRepository().getUrl());
+ repositoryConfiguration = connector.getRepositoryConfiguration(getTaskRepository().getUrl());
if (repositoryConfiguration != null) {
bugzillaVersion = repositoryConfiguration.getInstallVersion();
} else {
@@ -192,7 +195,7 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper {
RepositoryConfiguration repositoryConfiguration;
BugzillaVersion bugzillaVersion = null;
- repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(getTaskRepository().getUrl());
+ repositoryConfiguration = connector.getRepositoryConfiguration(getTaskRepository().getUrl());
if (repositoryConfiguration != null) {
bugzillaVersion = repositoryConfiguration.getInstallVersion();
} else {
@@ -353,7 +356,7 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper {
@Override
public Map<String, String> getOptions(TaskAttribute attribute) {
- RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(getTaskRepository().getRepositoryUrl());
+ RepositoryConfiguration configuration = connector.getRepositoryConfiguration(getTaskRepository().getRepositoryUrl());
if (configuration != null) {
TaskAttribute attributeProduct = attribute.getTaskData().getRoot().getMappedAttribute(
BugzillaAttribute.PRODUCT.getKey());
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
index 6a894081c..1074776d2 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
@@ -75,6 +75,7 @@ import org.eclipse.mylyn.internal.bugzilla.core.history.TaskHistory;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
@@ -171,6 +172,8 @@ public class BugzillaClient {
private final AbstractWebLocation location;
+ private BugzillaRepositoryConnector connector;
+
public BugzillaClient(AbstractWebLocation location, String characterEncoding, Map<String, String> configParameters,
BugzillaLanguageSettings languageSettings) throws MalformedURLException {
this.repositoryUrl = new URL(location.getUrl());
@@ -183,6 +186,24 @@ public class BugzillaClient {
}
+ public BugzillaClient(AbstractWebLocation location, TaskRepository taskRepository,
+ BugzillaRepositoryConnector connector) throws MalformedURLException {
+ String language = taskRepository.getProperty(IBugzillaConstants.BUGZILLA_LANGUAGE_SETTING);
+ if (language == null || language.equals("")) { //$NON-NLS-1$
+ language = IBugzillaConstants.DEFAULT_LANG;
+ }
+
+ this.connector = connector;
+ this.repositoryUrl = new URL(location.getUrl());
+ this.location = location;
+ this.characterEncoding = taskRepository.getCharacterEncoding();
+ this.configParameters = taskRepository.getProperties();
+ this.bugzillaLanguageSettings = connector.getLanguageSetting(language);
+ this.proxy = location.getProxyForHost(location.getUrl(), IProxyData.HTTP_PROXY_TYPE);
+ WebUtil.configureHttpClient(httpClient, USER_AGENT);
+
+ }
+
public void validate(IProgressMonitor monitor) throws IOException, CoreException {
monitor = Policy.monitorFor(monitor);
GzipGetMethod method = null;
@@ -565,7 +586,7 @@ public class BugzillaClient {
for (String type : VALID_CONFIG_CONTENT_TYPES) {
if (responseTypeHeader.getValue().toLowerCase(Locale.ENGLISH).contains(type)) {
RepositoryConfigurationFactory configFactory = new RepositoryConfigurationFactory(
- stream, getCharacterEncoding());
+ stream, getCharacterEncoding(), connector);
repositoryConfiguration = configFactory.getConfiguration();
@@ -950,7 +971,7 @@ public class BugzillaClient {
if (repositoryConfiguration == null) {
getRepositoryConfiguration(new SubProgressMonitor(monitor, 1));
- BugzillaCorePlugin.addRepositoryConfiguration(repositoryConfiguration);
+ connector.addRepositoryConfiguration(repositoryConfiguration);
}
if (taskData == null) {
@@ -1687,7 +1708,7 @@ public class BugzillaClient {
if (repositoryConfiguration == null) {
getRepositoryConfiguration(new SubProgressMonitor(monitor, 1));
- BugzillaCorePlugin.addRepositoryConfiguration(repositoryConfiguration);
+ connector.addRepositoryConfiguration(repositoryConfiguration);
}
GzipPostMethod method = null;
@@ -1734,7 +1755,8 @@ public class BugzillaClient {
if (responseTypeHeader.getValue().toLowerCase(Locale.ENGLISH).contains(type)) {
InputStream input = getResponseStream(method, monitor);
try {
- MultiBugReportFactory factory = new MultiBugReportFactory(input, getCharacterEncoding());
+ MultiBugReportFactory factory = new MultiBugReportFactory(input,
+ getCharacterEncoding(), connector);
List<BugzillaCustomField> customFields = new ArrayList<BugzillaCustomField>();
if (repositoryConfiguration != null) {
customFields = repositoryConfiguration.getCustomFields();
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java
index 09fd7f879..7d2fe125f 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java
@@ -25,15 +25,12 @@ public class BugzillaClientFactory {
protected static TaskRepositoryLocationFactory taskRepositoryLocationFactory = new TaskRepositoryLocationFactory();
- public static BugzillaClient createClient(TaskRepository taskRepository) throws MalformedURLException {
- String language = taskRepository.getProperty(IBugzillaConstants.BUGZILLA_LANGUAGE_SETTING);
- if (language == null || language.equals("")) { //$NON-NLS-1$
- language = IBugzillaConstants.DEFAULT_LANG;
- }
- BugzillaLanguageSettings languageSettings = BugzillaRepositoryConnector.getLanguageSetting(language);
+ public static BugzillaClient createClient(TaskRepository taskRepository, BugzillaRepositoryConnector connector)
+ throws MalformedURLException {
AbstractWebLocation location = taskRepositoryLocationFactory.createWebLocation(taskRepository);
- BugzillaClient client = new BugzillaClient(location, taskRepository.getCharacterEncoding(),
- taskRepository.getProperties(), languageSettings);
+
+ BugzillaClient client = new BugzillaClient(location, taskRepository, connector);
+
return client;
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java
index 6c13f3d89..7ef42677c 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java
@@ -30,7 +30,10 @@ public class BugzillaClientManager implements IRepositoryListener {
private final Map<String, BugzillaClient> clientByUrl = new HashMap<String, BugzillaClient>();
- public BugzillaClientManager() {
+ private final BugzillaRepositoryConnector connector;
+
+ public BugzillaClientManager(BugzillaRepositoryConnector connector) {
+ this.connector = connector;
}
public BugzillaClient getClient(TaskRepository taskRepository, IProgressMonitor monitor) throws CoreException {
@@ -50,14 +53,14 @@ public class BugzillaClientManager implements IRepositoryListener {
}
clientByUrl.put(taskRepository.getRepositoryUrl(), client);
}
- RepositoryConfiguration config = BugzillaCorePlugin.getRepositoryConfiguration(taskRepository.getUrl());
+ RepositoryConfiguration config = connector.getRepositoryConfiguration(taskRepository.getUrl());
client.setRepositoryConfiguration(config);
}
return client;
}
protected BugzillaClient createClient(TaskRepository taskRepository) throws MalformedURLException {
- return BugzillaClientFactory.createClient(taskRepository);
+ return BugzillaClientFactory.createClient(taskRepository, connector);
}
public void repositoryAdded(TaskRepository repository) {
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 23fbda154..cdd3db7f5 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
@@ -11,29 +11,9 @@
package org.eclipse.mylyn.internal.bugzilla.core;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-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.mylyn.commons.core.StatusHandler;
-import org.eclipse.mylyn.commons.net.Policy;
-import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
-import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.osgi.framework.BundleContext;
/**
@@ -42,39 +22,16 @@ import org.osgi.framework.BundleContext;
*/
public class BugzillaCorePlugin extends Plugin {
- private static final String ERROR_DELETING_CONFIGURATION = "Error removing corrupt repository configuration file."; //$NON-NLS-1$
-
- private static final String ERROR_INCOMPATIBLE_CONFIGURATION = "Reset Bugzilla repository configuration cache due to format change"; //$NON-NLS-1$
-
public static final String CONNECTOR_KIND = "bugzilla"; //$NON-NLS-1$
public static final String ID_PLUGIN = "org.eclipse.mylyn.bugzilla"; //$NON-NLS-1$
private static BugzillaCorePlugin INSTANCE;
- private static boolean cacheFileRead = false;
-
- private static File repositoryConfigurationFile = null;
-
- private static BugzillaRepositoryConnector connector;
-
- private static final String OPTION_ALL = "All"; //$NON-NLS-1$
-
- // A Map from Java's Platform to Buzilla's
- private final Map<String, String> java2buzillaPlatformMap = new HashMap<String, String>();
-
- /** Product configuration for the current server */
- private static Map<String, RepositoryConfiguration> repositoryConfigurations = new HashMap<String, RepositoryConfiguration>();
+ private BugzillaRepositoryConnector connector;
public BugzillaCorePlugin() {
super();
- java2buzillaPlatformMap.put("x86", "PC"); // can be PC or Macintosh! //$NON-NLS-1$ //$NON-NLS-2$
- java2buzillaPlatformMap.put("x86_64", "PC"); //$NON-NLS-1$ //$NON-NLS-2$
- java2buzillaPlatformMap.put("ia64", "PC"); //$NON-NLS-1$ //$NON-NLS-2$
- java2buzillaPlatformMap.put("ia64_32", "PC"); //$NON-NLS-1$ //$NON-NLS-2$
- java2buzillaPlatformMap.put("sparc", "Sun"); //$NON-NLS-1$ //$NON-NLS-2$
- java2buzillaPlatformMap.put("ppc", "Power PC"); // not Power! //$NON-NLS-1$ //$NON-NLS-2$
-
}
public static BugzillaCorePlugin getDefault() {
@@ -89,345 +46,26 @@ public class BugzillaCorePlugin extends Plugin {
@Override
public void stop(BundleContext context) throws Exception {
- writeRepositoryConfigFile();
+ if (connector != null) {
+ connector.stop();
+ connector = null;
+ }
INSTANCE = null;
super.stop(context);
}
- /**
- * public for testing
- */
- public static void setConnector(BugzillaRepositoryConnector theConnector) {
+ void setConnector(BugzillaRepositoryConnector theConnector) {
connector = theConnector;
}
- public static Map<String, RepositoryConfiguration> getConfigurations() {
- readRepositoryConfigurationFile();
- return repositoryConfigurations;
- }
-
- public static void setConfigurationCacheFile(File file) {
- repositoryConfigurationFile = file;
- }
-
- public static File getConfigurationCacheFile() {
- return repositoryConfigurationFile;
- }
-
/**
- * @since 2.1
- * @return cached repository configuration. If not already cached, null is returned.
+ * Returns the path to the file caching the product configuration.
*/
- public static RepositoryConfiguration getRepositoryConfiguration(String repositoryUrl) {
- readRepositoryConfigurationFile();
- return repositoryConfigurations.get(repositoryUrl);
+ IPath getConfigurationCachePath() {
+ IPath stateLocation = Platform.getStateLocation(getBundle());
+ IPath configFile = stateLocation.append("repositoryConfigurations"); //$NON-NLS-1$
+ return configFile;
}
- /**
- * Retrieves the latest repository configuration from the server
- */
- public static RepositoryConfiguration getRepositoryConfiguration(TaskRepository repository, boolean forceRefresh,
- IProgressMonitor monitor) throws CoreException {
- monitor = Policy.monitorFor(monitor);
- try {
- readRepositoryConfigurationFile();
- RepositoryConfiguration configuration;
- configuration = repositoryConfigurations.get(repository.getRepositoryUrl());
- if (configuration == null || forceRefresh) {
- synchronized (repositoryConfigurations) {
- // check if another thread already retrieved configuration
- configuration = repositoryConfigurations.get(repository.getRepositoryUrl());
- if (configuration == null || forceRefresh) {
- BugzillaClient client = connector.getClientManager().getClient(repository, monitor);
- configuration = client.getRepositoryConfiguration(monitor);
- if (configuration != null) {
- internalAddConfiguration(configuration);
- }
- }
- }
- }
- return configuration;//repositoryConfigurations.get(repository.getRepositoryUrl());
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, 1,
- "Error retrieving task attributes from repository.\n\n" + e.getMessage(), e)); //$NON-NLS-1$
- }
- }
-
- public static void addRepositoryConfiguration(RepositoryConfiguration config) {
- if (config != null) {
- readRepositoryConfigurationFile();
- synchronized (repositoryConfigurations) {
- internalAddConfiguration(config);
- }
- }
- }
-
- private static void internalAddConfiguration(RepositoryConfiguration config) {
- repositoryConfigurations.remove(config.getRepositoryUrl());
- repositoryConfigurations.put(config.getRepositoryUrl(), config);
- }
-
- // /**
- // * Returns the path to the file cacheing the product configuration.
- // */
- // private static IPath getProductConfigurationCachePath() {
- // IPath stateLocation =
- // Platform.getStateLocation(BugzillaPlugin.getDefault().getBundle());
- // IPath configFile = stateLocation.append("repositoryConfigurations");
- // return configFile;
- // }
-
- /** public for testing */
- public static void removeConfiguration(RepositoryConfiguration config) {
- synchronized (repositoryConfigurations) {
- repositoryConfigurations.remove(config.getRepositoryUrl());
- }
- }
-
- /** public for testing */
- public static synchronized void readRepositoryConfigurationFile() {
-
- // IPath configFile = getProductConfigurationCachePath();
- if (cacheFileRead || repositoryConfigurationFile == null || !repositoryConfigurationFile.exists()) {
- return;
- }
-
- synchronized (repositoryConfigurations) {
- ObjectInputStream in = null;
- try {
- in = new ObjectInputStream(new FileInputStream(repositoryConfigurationFile));
- int size = in.readInt();
- for (int nX = 0; nX < size; nX++) {
- RepositoryConfiguration item = (RepositoryConfiguration) in.readObject();
- if (item != null) {
- repositoryConfigurations.put(item.getRepositoryUrl(), item);
- }
- }
- } catch (Exception e) {
- StatusHandler.log(new Status(IStatus.INFO, BugzillaCorePlugin.ID_PLUGIN,
- ERROR_INCOMPATIBLE_CONFIGURATION));
- try {
- if (in != null) {
- in.close();
- }
- if (repositoryConfigurationFile != null && repositoryConfigurationFile.exists()) {
- if (repositoryConfigurationFile.delete()) {
- // successfully deleted
- } else {
- StatusHandler.log(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, 0,
- ERROR_DELETING_CONFIGURATION, e));
- }
- }
-
- } catch (Exception ex) {
- StatusHandler.log(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, 0,
- ERROR_DELETING_CONFIGURATION, e));
- }
- } finally {
- cacheFileRead = true;
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
- }
-
- /** public for testing */
- public static void writeRepositoryConfigFile() {
- if (repositoryConfigurationFile != null) {
- ObjectOutputStream out = null;
- try {
- Set<RepositoryConfiguration> tempConfigs;
- synchronized (repositoryConfigurations) {
- tempConfigs = new HashSet<RepositoryConfiguration>(repositoryConfigurations.values());
- }
- if (tempConfigs.size() > 0) {
- out = new ObjectOutputStream(new FileOutputStream(repositoryConfigurationFile));
- out.writeInt(tempConfigs.size());
- for (RepositoryConfiguration repositoryConfiguration : tempConfigs) {
- if (repositoryConfiguration != null) {
- out.writeObject(repositoryConfiguration);
- }
- }
- }
- } catch (IOException e) {
- StatusHandler.log(new Status(IStatus.WARNING, BugzillaCorePlugin.ID_PLUGIN, 0,
- "Failed to write repository configuration cache", e)); //$NON-NLS-1$
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
- }
-
- /**
- * Returns the path to the file caching bug reports created while offline.
- */
- protected IPath getCachedBugReportPath() {
- IPath stateLocation = Platform.getStateLocation(BugzillaCorePlugin.getDefault().getBundle());
- IPath bugFile = stateLocation.append("bugReports"); //$NON-NLS-1$
- return bugFile;
- }
-
- public void setPlatformDefaultsOrGuess(TaskRepository repository, TaskData newBugModel) {
-
- String platform = repository.getProperty(IBugzillaConstants.BUGZILLA_DEF_PLATFORM);
- String os = repository.getProperty(IBugzillaConstants.BUGZILLA_DEF_OS);
-
- // set both or none
- if (null != os && null != platform) {
- TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
- TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
- BugzillaAttribute.REP_PLATFORM.getKey());
-
- // TODO something can still go wrong when the allowed values on the repository change...
- opSysAttribute.setValue(os);
- platformAttribute.setValue(platform);
- return;
- }
- // fall through to old code
- setPlatformOptions(newBugModel);
- }
-
- public void setPlatformOptions(TaskData newBugModel) {
- try {
-
- // Get OS Lookup Map
- // Check that the result is in Values, if it is not, set it to other
- // Defaults to the first of each (sorted) list All, All
- TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
- TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
- BugzillaAttribute.REP_PLATFORM.getKey());
-
- String OS = Platform.getOS();
- String platform = Platform.getOSArch();
- String ws = Platform.getWS();
-
- String bugzillaOS = null; // Bugzilla String for OS
- String bugzillaPlatform = null; // Bugzilla String for Platform
- String[] wsExtentions = null;
-/*
- AIX -> AIX
- Linux -> Linux
- HP-UX -> HP-UX
- Solaris -> Solaris
- MacOS X -> Mac OS X
- */
-
- if (ws.length() > 1) {
- char first = ws.charAt(0);
- char firstLower = Character.toLowerCase(first);
- char firstUpper = Character.toUpperCase(first);
- String[] wsExtentionsTemp = { " - " + firstUpper + ws.substring(1, ws.length()), //$NON-NLS-1$
- " - " + firstLower + ws.substring(1, ws.length()), //$NON-NLS-1$
- " " + firstUpper + ws.substring(1, ws.length()), //$NON-NLS-1$
- " " + firstLower + ws.substring(1, ws.length()), "" }; //$NON-NLS-1$//$NON-NLS-2$
- wsExtentions = wsExtentionsTemp;
- } else if (ws.length() == 1) {
- char first = ws.charAt(0);
- char firstLower = Character.toLowerCase(first);
- char firstUpper = Character.toUpperCase(first);
- String[] wsExtentionsTemp = { " - " + firstUpper, " - " + firstLower, " " + firstUpper, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- " " + firstLower, "" }; //$NON-NLS-1$//$NON-NLS-2$
- wsExtentions = wsExtentionsTemp;
- } else {
- String[] wsExtentionsTemp = { "" }; //$NON-NLS-1$
- wsExtentions = wsExtentionsTemp;
- }
-
- bugzillaOS = System.getProperty("os.name") + " " + System.getProperty("os.version"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // We start with the most specific Value as the Search String.
- // If we didn't find it we remove the last part of the version String or the OS Name from
- // the Search String and continue with the test until we found it or the Search String is empty.
- //
- // The search in casesensitive.
- if (opSysAttribute != null) {
- for (String element : wsExtentions) {
- String bugzillaOSTemp = bugzillaOS;
- while (bugzillaOSTemp != null && opSysAttribute.getOption(bugzillaOSTemp + element) == null) {
- int dotindex = bugzillaOSTemp.lastIndexOf('.');
- if (dotindex > 0) {
- bugzillaOSTemp = bugzillaOSTemp.substring(0, dotindex);
- } else {
- int spaceindex = bugzillaOSTemp.lastIndexOf(' ');
- if (spaceindex > 0) {
- bugzillaOSTemp = bugzillaOSTemp.substring(0, spaceindex);
- } else {
- bugzillaOSTemp = null;
- }
- }
- }
- if (bugzillaOSTemp != null) {
- bugzillaOS = bugzillaOSTemp + element;
- break;
- }
- }
- } else {
- bugzillaOS = null;
- }
-
- if (platform != null && java2buzillaPlatformMap.containsKey(platform)) {
- bugzillaPlatform = java2buzillaPlatformMap.get(platform);
- // Bugzilla knows the following Platforms [All, Macintosh, Other, PC, Power PC, Sun]
- // Platform.getOSArch() returns "x86" on Intel Mac's and "ppc" on Power Mac's
- // so bugzillaPlatform is "Power" or "PC".
- //
- // If the OS is "macosx" we change the Platform to "Macintosh"
- //
- if (bugzillaPlatform != null
- && (bugzillaPlatform.compareTo("Power") == 0 || bugzillaPlatform.compareTo("PC") == 0) //$NON-NLS-1$ //$NON-NLS-2$
- && OS != null && OS.compareTo("macosx") == 0) { //$NON-NLS-1$
- // TODO: this may not even be a legal value in another repository!
- bugzillaPlatform = "Macintosh"; //$NON-NLS-1$
- } else if (platformAttribute != null && platformAttribute.getOption(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;
- }
- }
- // Set the OS and the Platform in the taskData
- if (bugzillaOS != null && opSysAttribute != null) {
- opSysAttribute.setValue(bugzillaOS);
- } else if (opSysAttribute != null && opSysAttribute.getOption(OPTION_ALL) != null) {
- opSysAttribute.setValue(OPTION_ALL);
- }
-
- if (bugzillaPlatform != null && platformAttribute != null) {
- platformAttribute.setValue(bugzillaPlatform);
- } else if (opSysAttribute != null && platformAttribute != null
- && platformAttribute.getOption(OPTION_ALL) != null) {
- opSysAttribute.setValue(OPTION_ALL);
- }
-
- } catch (Exception e) {
- StatusHandler.log(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, "could not set platform options", //$NON-NLS-1$
- e));
- }
- }
-
- public Set<BugzillaLanguageSettings> getLanguageSettings() {
- return BugzillaRepositoryConnector.getLanguageSettings();
- }
-
- public BugzillaLanguageSettings getLanguageSetting(String language) {
- return BugzillaRepositoryConnector.getLanguageSetting(language);
- }
-
- /**
- * this method is only for testing
- */
- public static void setCacheFileRead(boolean cacheFileRead) {
- BugzillaCorePlugin.cacheFileRead = cacheFileRead;
- }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java
index 995db308f..837f61858 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaFlagMapper.java
@@ -35,6 +35,12 @@ public class BugzillaFlagMapper {
private int number;
+ private final BugzillaRepositoryConnector connector;
+
+ public BugzillaFlagMapper(BugzillaRepositoryConnector connector) {
+ this.connector = connector;
+ }
+
public String getRequestee() {
return requestee;
}
@@ -95,7 +101,7 @@ public class BugzillaFlagMapper {
BugzillaVersion bugzillaVersion = null;
RepositoryConfiguration repositoryConfiguration;
try {
- repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(mapper.getTaskRepository(), false,
+ repositoryConfiguration = connector.getRepositoryConfiguration(mapper.getTaskRepository(), false,
new NullProgressMonitor());
bugzillaVersion = repositoryConfiguration.getInstallVersion();
} catch (CoreException e) {
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
index 9fff2fbc6..64b4d0e9d 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
@@ -11,7 +11,12 @@
package org.eclipse.mylyn.internal.bugzilla.core;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.MessageFormat;
@@ -25,11 +30,14 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
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.core.runtime.SubProgressMonitor;
import org.eclipse.mylyn.commons.core.StatusHandler;
@@ -82,6 +90,65 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
protected static final Set<BugzillaLanguageSettings> languages = new LinkedHashSet<BugzillaLanguageSettings>();
+ private static final String ERROR_DELETING_CONFIGURATION = "Error removing corrupt repository configuration file."; //$NON-NLS-1$
+
+ private static final String ERROR_INCOMPATIBLE_CONFIGURATION = "Reset Bugzilla repository configuration cache due to format change"; //$NON-NLS-1$
+
+ private boolean cacheFileRead;
+
+ private File repositoryConfigurationFile;
+
+ private final Map<String, RepositoryConfiguration> repositoryConfigurations = new HashMap<String, RepositoryConfiguration>();
+
+ // A Map from Java's Platform to Buzilla's
+ private static final Map<String, String> java2buzillaPlatformMap = new HashMap<String, String>();
+
+ private static final String OPTION_ALL = "All"; //$NON-NLS-1$
+
+ static {
+ enSetting = new BugzillaLanguageSettings(IBugzillaConstants.DEFAULT_LANG);
+ enSetting.addLanguageAttribute("error_login", "Login"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("error_login", "log in"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("error_login", "check e-mail"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("error_login", "Invalid Username Or Password"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("error_collision", "Mid-air collision!"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("error_comment_required", "Comment Required"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("error_logged_out", "logged out"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bad_login", "Login"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bad_login", "log in"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bad_login", "check e-mail"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bad_login", "Invalid Username Or Password"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bad_login", "error"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("processed", "processed"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("changes_submitted", "Changes submitted"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("changes_submitted", "added to Bug"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bug", "Bug"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("bug", "Issue"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("submitted", "Submitted"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("submitted", "posted"); //$NON-NLS-1$ //$NON-NLS-2$
+ enSetting.addLanguageAttribute("suspicious_action", "Suspicious action"); //$NON-NLS-1$ //$NON-NLS-2$
+ languages.add(enSetting);
+
+ java2buzillaPlatformMap.put("x86", "PC"); // can be PC or Macintosh! //$NON-NLS-1$ //$NON-NLS-2$
+ java2buzillaPlatformMap.put("x86_64", "PC"); //$NON-NLS-1$ //$NON-NLS-2$
+ java2buzillaPlatformMap.put("ia64", "PC"); //$NON-NLS-1$ //$NON-NLS-2$
+ java2buzillaPlatformMap.put("ia64_32", "PC"); //$NON-NLS-1$ //$NON-NLS-2$
+ java2buzillaPlatformMap.put("sparc", "Sun"); //$NON-NLS-1$ //$NON-NLS-2$
+ java2buzillaPlatformMap.put("ppc", "Power PC"); // not Power! //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public BugzillaRepositoryConnector() {
+ if (BugzillaCorePlugin.getDefault() != null) {
+ BugzillaCorePlugin.getDefault().setConnector(this);
+ IPath path = BugzillaCorePlugin.getDefault().getConfigurationCachePath();
+ this.repositoryConfigurationFile = path.toFile();
+ }
+ }
+
+ public BugzillaRepositoryConnector(File repositoryConfigurationFile) {
+ this.repositoryConfigurationFile = repositoryConfigurationFile;
+ }
+
@Override
public String getLabel() {
return CLIENT_LABEL;
@@ -381,32 +448,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
public BugzillaClientManager getClientManager() {
if (clientManager == null) {
- clientManager = new BugzillaClientManager();
- // TODO: Move this initialization elsewhere
- BugzillaCorePlugin.setConnector(this);
- enSetting = new BugzillaLanguageSettings(IBugzillaConstants.DEFAULT_LANG);
- enSetting.addLanguageAttribute("error_login", "Login"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("error_login", "log in"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("error_login", "check e-mail"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("error_login", "Invalid Username Or Password"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("error_collision", "Mid-air collision!"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("error_comment_required", "Comment Required"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("error_logged_out", "logged out"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bad_login", "Login"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bad_login", "log in"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bad_login", "check e-mail"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bad_login", "Invalid Username Or Password"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bad_login", "error"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("processed", "processed"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("changes_submitted", "Changes submitted"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("changes_submitted", "added to Bug"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bug", "Bug"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("bug", "Issue"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("submitted", "Submitted"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("submitted", "posted"); //$NON-NLS-1$ //$NON-NLS-2$
- enSetting.addLanguageAttribute("suspicious_action", "Suspicious action"); //$NON-NLS-1$ //$NON-NLS-2$
- languages.add(enSetting);
-
+ clientManager = new BugzillaClientManager(this);
}
return clientManager;
}
@@ -414,7 +456,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
@Override
public void updateRepositoryConfiguration(TaskRepository repository, IProgressMonitor monitor) throws CoreException {
if (repository != null) {
- BugzillaCorePlugin.getRepositoryConfiguration(repository, true, monitor);
+ getRepositoryConfiguration(repository, true, monitor);
}
}
@@ -608,4 +650,284 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
};
}
+ /** public for testing */
+ public synchronized void readRepositoryConfigurationFile() {
+ if (cacheFileRead || repositoryConfigurationFile == null || !repositoryConfigurationFile.exists()) {
+ return;
+ }
+
+ synchronized (repositoryConfigurations) {
+ ObjectInputStream in = null;
+ try {
+ in = new ObjectInputStream(new FileInputStream(repositoryConfigurationFile));
+ int size = in.readInt();
+ for (int nX = 0; nX < size; nX++) {
+ RepositoryConfiguration item = (RepositoryConfiguration) in.readObject();
+ if (item != null) {
+ repositoryConfigurations.put(item.getRepositoryUrl(), item);
+ }
+ }
+ } catch (Exception e) {
+ StatusHandler.log(new Status(IStatus.INFO, BugzillaCorePlugin.ID_PLUGIN,
+ ERROR_INCOMPATIBLE_CONFIGURATION));
+ try {
+ if (in != null) {
+ in.close();
+ }
+ if (repositoryConfigurationFile != null && repositoryConfigurationFile.exists()) {
+ if (repositoryConfigurationFile.delete()) {
+ // successfully deleted
+ } else {
+ StatusHandler.log(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, 0,
+ ERROR_DELETING_CONFIGURATION, e));
+ }
+ }
+
+ } catch (Exception ex) {
+ StatusHandler.log(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, 0,
+ ERROR_DELETING_CONFIGURATION, e));
+ }
+ } finally {
+ cacheFileRead = true;
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Retrieves the latest repository configuration from the server
+ */
+ public RepositoryConfiguration getRepositoryConfiguration(TaskRepository repository, boolean forceRefresh,
+ IProgressMonitor monitor) throws CoreException {
+ monitor = Policy.monitorFor(monitor);
+ try {
+ readRepositoryConfigurationFile();
+ RepositoryConfiguration configuration;
+ configuration = repositoryConfigurations.get(repository.getRepositoryUrl());
+ if (configuration == null || forceRefresh) {
+ synchronized (repositoryConfigurations) {
+ // check if another thread already retrieved configuration
+ configuration = repositoryConfigurations.get(repository.getRepositoryUrl());
+ if (configuration == null || forceRefresh) {
+ BugzillaClient client = clientManager.getClient(repository, monitor);
+ configuration = client.getRepositoryConfiguration(monitor);
+ if (configuration != null) {
+ internalAddConfiguration(configuration);
+ }
+ }
+ }
+ }
+ return configuration;//repositoryConfigurations.get(repository.getRepositoryUrl());
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, 1,
+ "Error retrieving task attributes from repository.\n\n" + e.getMessage(), e)); //$NON-NLS-1$
+ }
+ }
+
+ public void addRepositoryConfiguration(RepositoryConfiguration config) {
+ if (config != null) {
+ readRepositoryConfigurationFile();
+ synchronized (repositoryConfigurations) {
+ internalAddConfiguration(config);
+ }
+ }
+ }
+
+ private void internalAddConfiguration(RepositoryConfiguration config) {
+ repositoryConfigurations.remove(config.getRepositoryUrl());
+ repositoryConfigurations.put(config.getRepositoryUrl(), config);
+ }
+
+ public RepositoryConfiguration getRepositoryConfiguration(String repositoryUrl) {
+ readRepositoryConfigurationFile();
+ return repositoryConfigurations.get(repositoryUrl);
+ }
+
+ /** public for testing */
+ public void removeConfiguration(RepositoryConfiguration config) {
+ synchronized (repositoryConfigurations) {
+ repositoryConfigurations.remove(config.getRepositoryUrl());
+ }
+ }
+
+ /** public for testing */
+ public void writeRepositoryConfigFile() {
+ if (repositoryConfigurationFile != null) {
+ ObjectOutputStream out = null;
+ try {
+ Set<RepositoryConfiguration> tempConfigs;
+ synchronized (repositoryConfigurations) {
+ tempConfigs = new HashSet<RepositoryConfiguration>(repositoryConfigurations.values());
+ }
+ if (tempConfigs.size() > 0) {
+ out = new ObjectOutputStream(new FileOutputStream(repositoryConfigurationFile));
+ out.writeInt(tempConfigs.size());
+ for (RepositoryConfiguration repositoryConfiguration : tempConfigs) {
+ if (repositoryConfiguration != null) {
+ out.writeObject(repositoryConfiguration);
+ }
+ }
+ }
+ } catch (IOException e) {
+ StatusHandler.log(new Status(IStatus.WARNING, BugzillaCorePlugin.ID_PLUGIN, 0,
+ "Failed to write repository configuration cache", e)); //$NON-NLS-1$
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+
+ public void stop() {
+ writeRepositoryConfigFile();
+ }
+
+ public void setPlatformDefaultsOrGuess(TaskRepository repository, TaskData newBugModel) {
+
+ String platform = repository.getProperty(IBugzillaConstants.BUGZILLA_DEF_PLATFORM);
+ String os = repository.getProperty(IBugzillaConstants.BUGZILLA_DEF_OS);
+
+ // set both or none
+ if (null != os && null != platform) {
+ TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
+ TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
+ BugzillaAttribute.REP_PLATFORM.getKey());
+
+ // TODO something can still go wrong when the allowed values on the repository change...
+ opSysAttribute.setValue(os);
+ platformAttribute.setValue(platform);
+ return;
+ }
+ // fall through to old code
+ setPlatformOptions(newBugModel);
+ }
+
+ public void setPlatformOptions(TaskData newBugModel) {
+ try {
+
+ // Get OS Lookup Map
+ // Check that the result is in Values, if it is not, set it to other
+ // Defaults to the first of each (sorted) list All, All
+ TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
+ TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
+ BugzillaAttribute.REP_PLATFORM.getKey());
+
+ String OS = Platform.getOS();
+ String platform = Platform.getOSArch();
+ String ws = Platform.getWS();
+
+ String bugzillaOS = null; // Bugzilla String for OS
+ String bugzillaPlatform = null; // Bugzilla String for Platform
+ String[] wsExtentions = null;
+/*
+ AIX -> AIX
+ Linux -> Linux
+ HP-UX -> HP-UX
+ Solaris -> Solaris
+ MacOS X -> Mac OS X
+ */
+
+ if (ws.length() > 1) {
+ char first = ws.charAt(0);
+ char firstLower = Character.toLowerCase(first);
+ char firstUpper = Character.toUpperCase(first);
+ String[] wsExtentionsTemp = { " - " + firstUpper + ws.substring(1, ws.length()), //$NON-NLS-1$
+ " - " + firstLower + ws.substring(1, ws.length()), //$NON-NLS-1$
+ " " + firstUpper + ws.substring(1, ws.length()), //$NON-NLS-1$
+ " " + firstLower + ws.substring(1, ws.length()), "" }; //$NON-NLS-1$//$NON-NLS-2$
+ wsExtentions = wsExtentionsTemp;
+ } else if (ws.length() == 1) {
+ char first = ws.charAt(0);
+ char firstLower = Character.toLowerCase(first);
+ char firstUpper = Character.toUpperCase(first);
+ String[] wsExtentionsTemp = { " - " + firstUpper, " - " + firstLower, " " + firstUpper, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " " + firstLower, "" }; //$NON-NLS-1$//$NON-NLS-2$
+ wsExtentions = wsExtentionsTemp;
+ } else {
+ String[] wsExtentionsTemp = { "" }; //$NON-NLS-1$
+ wsExtentions = wsExtentionsTemp;
+ }
+
+ bugzillaOS = System.getProperty("os.name") + " " + System.getProperty("os.version"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ // We start with the most specific Value as the Search String.
+ // If we didn't find it we remove the last part of the version String or the OS Name from
+ // the Search String and continue with the test until we found it or the Search String is empty.
+ //
+ // The search in casesensitive.
+ if (opSysAttribute != null) {
+ for (String element : wsExtentions) {
+ String bugzillaOSTemp = bugzillaOS;
+ while (bugzillaOSTemp != null && opSysAttribute.getOption(bugzillaOSTemp + element) == null) {
+ int dotindex = bugzillaOSTemp.lastIndexOf('.');
+ if (dotindex > 0) {
+ bugzillaOSTemp = bugzillaOSTemp.substring(0, dotindex);
+ } else {
+ int spaceindex = bugzillaOSTemp.lastIndexOf(' ');
+ if (spaceindex > 0) {
+ bugzillaOSTemp = bugzillaOSTemp.substring(0, spaceindex);
+ } else {
+ bugzillaOSTemp = null;
+ }
+ }
+ }
+ if (bugzillaOSTemp != null) {
+ bugzillaOS = bugzillaOSTemp + element;
+ break;
+ }
+ }
+ } else {
+ bugzillaOS = null;
+ }
+
+ if (platform != null && java2buzillaPlatformMap.containsKey(platform)) {
+ bugzillaPlatform = java2buzillaPlatformMap.get(platform);
+ // Bugzilla knows the following Platforms [All, Macintosh, Other, PC, Power PC, Sun]
+ // Platform.getOSArch() returns "x86" on Intel Mac's and "ppc" on Power Mac's
+ // so bugzillaPlatform is "Power" or "PC".
+ //
+ // If the OS is "macosx" we change the Platform to "Macintosh"
+ //
+ if (bugzillaPlatform != null
+ && (bugzillaPlatform.compareTo("Power") == 0 || bugzillaPlatform.compareTo("PC") == 0) //$NON-NLS-1$ //$NON-NLS-2$
+ && OS != null && OS.compareTo("macosx") == 0) { //$NON-NLS-1$
+ // TODO: this may not even be a legal value in another repository!
+ bugzillaPlatform = "Macintosh"; //$NON-NLS-1$
+ } else if (platformAttribute != null && platformAttribute.getOption(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;
+ }
+ }
+ // Set the OS and the Platform in the taskData
+ if (bugzillaOS != null && opSysAttribute != null) {
+ opSysAttribute.setValue(bugzillaOS);
+ } else if (opSysAttribute != null && opSysAttribute.getOption(OPTION_ALL) != null) {
+ opSysAttribute.setValue(OPTION_ALL);
+ }
+
+ if (bugzillaPlatform != null && platformAttribute != null) {
+ platformAttribute.setValue(bugzillaPlatform);
+ } else if (opSysAttribute != null && platformAttribute != null
+ && platformAttribute.getOption(OPTION_ALL) != null) {
+ opSysAttribute.setValue(OPTION_ALL);
+ }
+
+ } catch (Exception e) {
+ StatusHandler.log(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, "could not set platform options", //$NON-NLS-1$
+ e));
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java
index f809568f8..7f8cb6c93 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java
@@ -48,14 +48,14 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
VERSION_0(0f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
// ignore
}
},
VERSION_1_0(1.0f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
// 1: the value was stored in the attribute rather than the key
for (TaskAttribute attribute : new ArrayList<TaskAttribute>(data.getRoot().getAttributes().values())) {
if (attribute.getId().equals(BugzillaAttribute.DESC.getKey())) {
@@ -74,7 +74,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
for (TaskAttribute taskAttribute : operationsToRemove) {
data.getRoot().removeAttribute(taskAttribute.getId());
}
- RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(repository.getRepositoryUrl());
+ RepositoryConfiguration configuration = connector.getRepositoryConfiguration(repository.getRepositoryUrl());
if (configuration != null) {
configuration.addValidOperations(data);
}
@@ -82,26 +82,26 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
},
VERSION_2_0(2.0f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
updateAttribute(data, BugzillaAttribute.LONG_DESC);
}
},
VERSION_3_0(3.0f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
updateAttribute(data, BugzillaAttribute.NEW_COMMENT);
}
},
VERSION_4_0(4.0f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
updateAttribute(data, BugzillaAttribute.DEADLINE);
updateAttribute(data, BugzillaAttribute.ACTUAL_TIME);
}
},
VERSION_4_1(4.1f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
updateAttribute(data, BugzillaAttribute.VOTES);
TaskAttribute attrDeadline = data.getRoot().getMappedAttribute(BugzillaAttribute.VOTES.getKey());
if (attrDeadline != null) {
@@ -111,7 +111,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
},
VERSION_4_2(4.2f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
updateAttribute(data, BugzillaAttribute.CC);
updateAttribute(data, BugzillaAttribute.DEPENDSON);
updateAttribute(data, BugzillaAttribute.BLOCKED);
@@ -124,7 +124,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
},
VERSION_4_3(4.3f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
// migrate custom attributes
for (TaskAttribute attribute : data.getRoot().getAttributes().values()) {
if (attribute.getId().startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
@@ -141,16 +141,16 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
},
VERSION_4_4(4.4f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
// summary didn't have spell checking, update to short rich text
updateAttribute(data, BugzillaAttribute.SHORT_DESC);
}
},
VERSION_4_5(4.5f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
// migrate custom attributes
- RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(repository.getRepositoryUrl());
+ RepositoryConfiguration configuration = connector.getRepositoryConfiguration(repository.getRepositoryUrl());
if (configuration == null) {
return;
@@ -205,7 +205,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
},
VERSION_CURRENT(4.6f) {
@Override
- void migrate(TaskRepository repository, TaskData data) {
+ void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector) {
data.setVersion(TaskDataVersion.VERSION_CURRENT.toString());
}
};
@@ -220,7 +220,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
return versionNumber;
}
- abstract void migrate(TaskRepository repository, TaskData data);
+ abstract void migrate(TaskRepository repository, TaskData data, BugzillaRepositoryConnector connector);
@Override
public String toString() {
@@ -237,7 +237,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
}
}
- private final BugzillaRepositoryConnector connector;
+ protected final BugzillaRepositoryConnector connector;
public BugzillaTaskDataHandler(BugzillaRepositoryConnector connector) {
this.connector = connector;
@@ -356,7 +356,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
for (TaskDataVersion version : TaskDataVersion.values()) {
if (bugzillaTaskDataVersion <= version.getVersionNum()) {
- version.migrate(taskRepository, taskData);
+ version.migrate(taskRepository, taskData, connector);
}
}
}
@@ -397,8 +397,8 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
// fresh from the repository (not locally stored data that may not have been migrated).
taskData.setVersion(TaskDataVersion.VERSION_CURRENT.toString());
- RepositoryConfiguration repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(repository,
- false, monitor);
+ RepositoryConfiguration repositoryConfiguration = connector.getRepositoryConfiguration(repository, false,
+ monitor);
if (repositoryConfiguration == null) {
return false;
@@ -429,14 +429,14 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
}
initializeNewTaskDataAttributes(repositoryConfiguration, taskData, product, component, monitor);
- if (BugzillaCorePlugin.getDefault() != null) {
- BugzillaCorePlugin.getDefault().setPlatformDefaultsOrGuess(repository, taskData);
+ if (connector != null) {
+ connector.setPlatformDefaultsOrGuess(repository, taskData);
}
return true;
} else {
boolean shortLogin = Boolean.parseBoolean(repository.getProperty(IBugzillaConstants.REPOSITORY_SETTING_SHORT_LOGIN));
- repositoryConfiguration.configureTaskData(taskData, shortLogin);
+ repositoryConfiguration.configureTaskData(taskData, shortLogin, connector);
}
return true;
}
@@ -662,7 +662,7 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler {
@Override
public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
- return new BugzillaAttributeMapper(taskRepository);
+ return new BugzillaAttributeMapper(taskRepository, connector);
}
public static TaskAttribute createAttribute(TaskData data, BugzillaAttribute key) {
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java
index d5e6a9d11..cbf4d5d33 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/MultiBugReportFactory.java
@@ -33,15 +33,18 @@ import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
*/
public class MultiBugReportFactory extends AbstractReportFactory {
- public MultiBugReportFactory(InputStream inStream, String encoding) {
+ private final BugzillaRepositoryConnector connector;
+
+ public MultiBugReportFactory(InputStream inStream, String encoding, BugzillaRepositoryConnector connector) {
super(inStream, encoding);
+ this.connector = connector;
}
public void populateReport(Map<String, TaskData> bugMap, TaskDataCollector collector, TaskAttributeMapper mapper,
List<BugzillaCustomField> customFields) throws IOException, CoreException {
SaxMultiBugReportContentHandler contentHandler = new SaxMultiBugReportContentHandler(mapper, collector, bugMap,
- customFields);
+ customFields, connector);
collectResults(contentHandler, false);
for (TaskData data : bugMap.values()) {
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java
index fb159df79..e71062c52 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java
@@ -71,7 +71,6 @@ public class RepositoryConfiguration implements Serializable {
private String encoding = null;
public RepositoryConfiguration() {
- super();
}
public void addStatus(String status) {
@@ -366,9 +365,9 @@ public class RepositoryConfiguration implements Serializable {
return customFields;
}
- public void configureTaskData(TaskData taskData, boolean localuser) {
+ public void configureTaskData(TaskData taskData, boolean localuser, BugzillaRepositoryConnector connector) {
if (taskData != null) {
- addMissingFlags(taskData);
+ addMissingFlags(taskData, connector);
updateAttributeOptions(taskData);
addValidOperations(taskData);
if (localuser) {
@@ -396,7 +395,7 @@ public class RepositoryConfiguration implements Serializable {
}
}
- private void addMissingFlags(TaskData taskData) {
+ private void addMissingFlags(TaskData taskData, BugzillaRepositoryConnector connector) {
List<String> existingFlags = new ArrayList<String>();
List<BugzillaFlag> flags = getFlags();
for (TaskAttribute attribute : new HashSet<TaskAttribute>(taskData.getRoot().getAttributes().values())) {
@@ -433,7 +432,7 @@ public class RepositoryConfiguration implements Serializable {
if (existingFlags.contains(bugzillaFlag.getName()) && !bugzillaFlag.isMultiplicable()) {
continue;
}
- BugzillaFlagMapper mapper = new BugzillaFlagMapper();
+ BugzillaFlagMapper mapper = new BugzillaFlagMapper(connector);
mapper.setRequestee(""); //$NON-NLS-1$
mapper.setSetter(""); //$NON-NLS-1$
mapper.setState(" "); //$NON-NLS-1$
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java
index ae8b26db3..f5da73228 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java
@@ -25,13 +25,15 @@ import org.xml.sax.SAXParseException;
* @author Rob Elves
*/
public class RepositoryConfigurationFactory extends AbstractReportFactory {
+ private final BugzillaRepositoryConnector connector;
- public RepositoryConfigurationFactory(InputStream inStream, String encoding) {
+ public RepositoryConfigurationFactory(InputStream inStream, String encoding, BugzillaRepositoryConnector connector) {
super(inStream, encoding);
+ this.connector = connector;
}
public RepositoryConfiguration getConfiguration() throws IOException, CoreException {
- SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler();
+ SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler(connector);
collectResults(contentHandler, true);
RepositoryConfiguration config = contentHandler.getConfiguration();
return config;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java
index d13d9646a..292e251ff 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java
@@ -175,7 +175,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler {
private String about;
- private final RepositoryConfiguration configuration = new RepositoryConfiguration();
+ private final RepositoryConfiguration configuration;
private final Map<String, List<String>> components = new HashMap<String, List<String>>();
@@ -199,6 +199,14 @@ public class SaxConfigurationContentHandler extends DefaultHandler {
private String currentCustomOptionName = ""; //$NON-NLS-1$
+ private final BugzillaRepositoryConnector connector;
+
+ public SaxConfigurationContentHandler(BugzillaRepositoryConnector connector) {
+ super();
+ this.connector = connector;
+ configuration = new RepositoryConfiguration();
+ }
+
public RepositoryConfiguration getConfiguration() {
return configuration;
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java
index 800860a61..3a3458ae4 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java
@@ -74,11 +74,15 @@ public class SaxMultiBugReportContentHandler extends DefaultHandler {
private boolean bugParseErrorOccurred;
+ private final BugzillaRepositoryConnector connector;
+
public SaxMultiBugReportContentHandler(TaskAttributeMapper mapper, TaskDataCollector collector,
- Map<String, TaskData> taskDataMap, List<BugzillaCustomField> customFields) {
+ Map<String, TaskData> taskDataMap, List<BugzillaCustomField> customFields,
+ BugzillaRepositoryConnector connector) {
this.taskDataMap = taskDataMap;
this.customFields = customFields;
this.collector = collector;
+ this.connector = connector;
}
public boolean errorOccurred() {
@@ -177,7 +181,7 @@ public class SaxMultiBugReportContentHandler extends DefaultHandler {
if (attributes != null && attributes.getLength() > 0) {
String name = attributes.getValue(ATTRIBUTE_NAME);
if (name != null) {
- BugzillaFlagMapper mapper = new BugzillaFlagMapper();
+ BugzillaFlagMapper mapper = new BugzillaFlagMapper(connector);
String requestee = attributes.getValue("requestee"); //$NON-NLS-1$
mapper.setRequestee(requestee);
String setter = attributes.getValue("setter"); //$NON-NLS-1$
@@ -468,7 +472,7 @@ public class SaxMultiBugReportContentHandler extends DefaultHandler {
}
private void updateCustomFields(TaskData taskData) {
- RepositoryConfiguration config = BugzillaCorePlugin.getRepositoryConfiguration(repositoryTaskData.getRepositoryUrl());
+ RepositoryConfiguration config = connector.getRepositoryConfiguration(repositoryTaskData.getRepositoryUrl());
if (config != null) {
for (BugzillaCustomField bugzillaCustomField : config.getCustomFields()) {

Back to the top