Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2012-05-08 21:54:00 +0000
committerSteffen Pingel2012-05-18 16:12:42 +0000
commitf93c8eafc2f175a5e558225d1493f80dab413ca2 (patch)
tree34950d70d9953a3cc122e17d423baee7901316c5 /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional
parent918cbdbcf5d6acd49dca0106a7641cbb48c38bc7 (diff)
downloadorg.eclipse.mylyn.tasks-f93c8eafc2f175a5e558225d1493f80dab413ca2.tar.gz
org.eclipse.mylyn.tasks-f93c8eafc2f175a5e558225d1493f80dab413ca2.tar.xz
org.eclipse.mylyn.tasks-f93c8eafc2f175a5e558225d1493f80dab413ca2.zip
NEW - bug 378855: fix classloading issues with RepositoryClientManager
https://bugs.eclipse.org/bugs/show_bug.cgi?id=378855 Change-Id: I18ba7a241393eb33322b87d97fea41aba1c78d1b
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/provisional/tasks/core/RepositoryClientManager.java53
1 files changed, 44 insertions, 9 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 e2f6579f7..23a23f497 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 Tasktop Technologies and others.
+ * Copyright (c) 2004, 2012 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
@@ -14,9 +14,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
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;
@@ -30,11 +34,40 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.TaskRepositoryLocationFactory;
/**
- * TODO: fix class loading problems caused by serialization and make API
- *
* @author Steffen Pingel
*/
-abstract class RepositoryClientManager<T, C extends Serializable> implements IRepositoryListener {
+public abstract class RepositoryClientManager<T, C extends Serializable> implements IRepositoryListener {
+
+ private class OSGiAwareObjectInputStream extends ObjectInputStream {
+
+ 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());
+ } 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>();
@@ -103,7 +136,7 @@ abstract class RepositoryClientManager<T, C extends Serializable> implements IRe
ObjectInputStream in = null;
try {
- in = new ObjectInputStream(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();
@@ -113,8 +146,7 @@ abstract class RepositoryClientManager<T, C extends Serializable> implements IRe
}
}
} catch (Throwable e) {
- StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN,
- "The respository configuration cache could not be read", e)); //$NON-NLS-1$
+ handleError("The respository configuration cache could not be read", e); //$NON-NLS-1$
} finally {
if (in != null) {
try {
@@ -127,6 +159,10 @@ abstract class RepositoryClientManager<T, C extends Serializable> implements IRe
}
+ protected void handleError(String message, Throwable e) {
+ StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, message, e));
+ }
+
public void writeCache() {
if (cacheFile == null) {
return;
@@ -141,8 +177,7 @@ abstract class RepositoryClientManager<T, C extends Serializable> implements IRe
out.writeObject(clientDataByUrl.get(url));
}
} catch (IOException e) {
- StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN,
- "The respository configuration cache could not be written", e)); //$NON-NLS-1$
+ handleError("The respository configuration cache could not be written", e); //$NON-NLS-1$
} finally {
if (out != null) {
try {

Back to the top