summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-05-14 06:54:31 (EDT)
committer Steffen Pingel2012-05-18 12:43:57 (EDT)
commit25071811501217bfbb896054763c83cc1fdb0326 (patch)
treea089cccf8afadbef0a0074bc415e181251c45ab8
parentf93c8eafc2f175a5e558225d1493f80dab413ca2 (diff)
downloadorg.eclipse.mylyn.tasks-25071811501217bfbb896054763c83cc1fdb0326.zip
org.eclipse.mylyn.tasks-25071811501217bfbb896054763c83cc1fdb0326.tar.gz
org.eclipse.mylyn.tasks-25071811501217bfbb896054763c83cc1fdb0326.tar.bz2
NEW - bug 378855: fix class loading issues with RepositoryClientManager refs/changes/71/5971/2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=378855 Change-Id: I51ba65053003a44099fb9406f4dc0aac4f8f9053
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional/tasks/core/RepositoryClientManager.java84
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryClientManagerTest.java9
2 files changed, 41 insertions, 52 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional/tasks/core/RepositoryClientManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional/tasks/core/RepositoryClientManager.java
index 23a23f4..5f645ce 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional/tasks/core/RepositoryClientManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional/tasks/core/RepositoryClientManager.java
@@ -19,8 +19,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
@@ -35,74 +33,70 @@ import org.eclipse.mylyn.tasks.core.TaskRepositoryLocationFactory;
/**
* @author Steffen Pingel
+ * @author Benjamin Muskalla
*/
public abstract class RepositoryClientManager<T, C extends Serializable> implements IRepositoryListener {
- private class OSGiAwareObjectInputStream extends ObjectInputStream {
+ /**
+ * Delegates to <code>repositoryConfigurationClass</code>'s class loader for accessing classes.
+ */
+ private class OsgiAwareObjectInputStream extends ObjectInputStream {
- public OSGiAwareObjectInputStream(InputStream in) throws IOException {
+ public OsgiAwareObjectInputStream(InputStream in) throws IOException {
super(in);
}
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
try {
- ClassLoader connectorClassloader = getConfigClassloader();
- return connectorClassloader.loadClass(desc.getName());
+ return repositoryConfigurationClass.getClassLoader().loadClass(desc.getName());
} catch (Exception e) {
return super.resolveClass(desc);
}
}
- private ClassLoader getConfigClassloader() {
- Class<?> configClazz = getConfigClass();
- ClassLoader connectorClassloader = configClazz.getClassLoader();
- return connectorClassloader;
- }
-
- private Class<?> getConfigClass() {
- Class<?> managerClazz = RepositoryClientManager.this.getClass();
- ParameterizedType type = (ParameterizedType) managerClazz.getGenericSuperclass();
- Type[] fieldArgTypes = type.getActualTypeArguments();
- Class<?> configClazz = (Class<?>) fieldArgTypes[1];
- return configClazz;
- }
}
private final Map<String, T> clientByUrl = new HashMap<String, T>();
- private final Map<String, C> clientDataByUrl = new HashMap<String, C>();
+ private final Map<String, C> respoitoryConfigurationByUrl = new HashMap<String, C>();
private final File cacheFile;
- private TaskRepositoryLocationFactory taskRepositoryLocationFactory;
+ private TaskRepositoryLocationFactory locationFactory;
+
+ private final Class<C> repositoryConfigurationClass;
- public RepositoryClientManager(File cacheFile) {
+ public RepositoryClientManager(File cacheFile, Class<C> repositoryConfigurationClass) {
Assert.isNotNull(cacheFile);
this.cacheFile = cacheFile;
+ this.repositoryConfigurationClass = repositoryConfigurationClass;
readCache();
}
- public synchronized T getClient(TaskRepository taskRepository) {
- Assert.isNotNull(taskRepository);
- T client = clientByUrl.get(taskRepository.getRepositoryUrl());
+ public synchronized T getClient(TaskRepository repository) {
+ Assert.isNotNull(repository);
+ T client = clientByUrl.get(repository.getRepositoryUrl());
if (client == null) {
- C data = clientDataByUrl.get(taskRepository.getRepositoryUrl());
+ C data = respoitoryConfigurationByUrl.get(repository.getRepositoryUrl());
if (data == null) {
- data = createRepositoryConfiguration();
- clientDataByUrl.put(taskRepository.getRepositoryUrl(), data);
+ data = createRepositoryConfiguration(repository);
+ respoitoryConfigurationByUrl.put(repository.getRepositoryUrl(), data);
}
- client = createClient(taskRepository, data);
- clientByUrl.put(taskRepository.getRepositoryUrl(), client);
+ client = createClient(repository, data);
+ clientByUrl.put(repository.getRepositoryUrl(), client);
}
return client;
}
- /**
- * FIXME: Add TaskRepository as parameter
- */
- protected abstract C createRepositoryConfiguration();
+ protected C createRepositoryConfiguration(TaskRepository repository) {
+ try {
+ return repositoryConfigurationClass.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
protected abstract T createClient(TaskRepository taskRepository, C data);
@@ -112,7 +106,7 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
public synchronized void repositoryAdded(TaskRepository repository) {
removeClient(repository);
- clientDataByUrl.remove(repository.getRepositoryUrl());
+ respoitoryConfigurationByUrl.remove(repository.getRepositoryUrl());
}
private void removeClient(TaskRepository repository) {
@@ -121,7 +115,7 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
public synchronized void repositoryRemoved(TaskRepository repository) {
removeClient(repository);
- clientDataByUrl.remove(repository.getRepositoryUrl());
+ respoitoryConfigurationByUrl.remove(repository.getRepositoryUrl());
}
public synchronized void repositorySettingsChanged(TaskRepository repository) {
@@ -136,13 +130,13 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
ObjectInputStream in = null;
try {
- in = new OSGiAwareObjectInputStream(new FileInputStream(cacheFile));
+ in = new OsgiAwareObjectInputStream(new FileInputStream(cacheFile));
int size = in.readInt();
for (int i = 0; i < size; i++) {
String url = (String) in.readObject();
C data = (C) in.readObject();
if (url != null && data != null) {
- clientDataByUrl.put(url, data);
+ respoitoryConfigurationByUrl.put(url, data);
}
}
} catch (Throwable e) {
@@ -171,10 +165,10 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(new FileOutputStream(cacheFile));
- out.writeInt(clientDataByUrl.size());
- for (String url : clientDataByUrl.keySet()) {
+ out.writeInt(respoitoryConfigurationByUrl.size());
+ for (String url : respoitoryConfigurationByUrl.keySet()) {
out.writeObject(url);
- out.writeObject(clientDataByUrl.get(url));
+ out.writeObject(respoitoryConfigurationByUrl.get(url));
}
} catch (IOException e) {
handleError("The respository configuration cache could not be written", e); //$NON-NLS-1$
@@ -189,12 +183,12 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
}
}
- public TaskRepositoryLocationFactory getTaskRepositoryLocationFactory() {
- return taskRepositoryLocationFactory;
+ public TaskRepositoryLocationFactory getLocationFactory() {
+ return locationFactory;
}
- public void setTaskRepositoryLocationFactory(TaskRepositoryLocationFactory taskRepositoryLocationFactory) {
- this.taskRepositoryLocationFactory = taskRepositoryLocationFactory;
+ public void setLocationFactory(TaskRepositoryLocationFactory locationFactory) {
+ this.locationFactory = locationFactory;
}
public void repositoryUrlChanged(TaskRepository repository, String oldUrl) {
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryClientManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryClientManagerTest.java
index 8e55500..fa31b3b 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryClientManagerTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryClientManagerTest.java
@@ -24,7 +24,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
*/
public class RepositoryClientManagerTest extends TestCase {
- private static class MyConfig implements Serializable {
+ public static class MyConfig implements Serializable {
private static final long serialVersionUID = 5105526708474366441L;
@@ -39,12 +39,7 @@ public class RepositoryClientManagerTest extends TestCase {
private Throwable throwable;
public MockRepositoryClientManager(File cacheFile) {
- super(cacheFile);
- }
-
- @Override
- protected MyConfig createRepositoryConfiguration() {
- return new MyConfig();
+ super(cacheFile, MyConfig.class);
}
@Override