blob: 26d74bff39f52dac669060d6299edf93c183a792 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*******************************************************************************
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.bugzilla.core;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.tasks.core.IRepositoryListener;
import org.eclipse.mylyn.tasks.core.TaskRepository;
/**
* @author Steffen Pingel
* @author Robert Elves (adaption for Bugzilla)
*/
public class BugzillaClientManager implements IRepositoryListener {
private final Map<String, BugzillaClient> clientByUrl = new HashMap<String, BugzillaClient>();
public BugzillaClientManager() {
}
public synchronized BugzillaClient getClient(TaskRepository taskRepository, IProgressMonitor monitor)
throws MalformedURLException, CoreException {
BugzillaClient client = clientByUrl.get(taskRepository.getRepositoryUrl());
if (client == null) {
String language = taskRepository.getProperty(IBugzillaConstants.BUGZILLA_LANGUAGE_SETTING);
if (language == null || language.equals("")) {
language = IBugzillaConstants.DEFAULT_LANG;
}
client = BugzillaClientFactory.createClient(taskRepository);
clientByUrl.put(taskRepository.getRepositoryUrl(), client);
client.setRepositoryConfiguration(BugzillaCorePlugin.getRepositoryConfiguration(taskRepository, false,
monitor));
}
return client;
}
public synchronized void repositoryAdded(TaskRepository repository) {
// make sure there is no stale client still in the cache, bug #149939
removeClient(repository);
}
public synchronized void repositoryRemoved(TaskRepository repository) {
removeClient(repository);
}
private void removeClient(TaskRepository repository) {
clientByUrl.remove(repository.getRepositoryUrl());
}
public synchronized void repositorySettingsChanged(TaskRepository repository) {
removeClient(repository);
}
public void repositoryUrlChanged(TaskRepository repository, String oldUrl) {
// ignore
}
}
|