Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Chen2012-02-23 02:03:15 -0500
committerWilliam Chen2012-02-23 02:03:15 -0500
commitc7af49022bcef0631acbb14c5435fa07873abe86 (patch)
tree22e23db73b3c072e0d65d07abbb3f49208bcc82b
parent1639b28c8d1b2af26e51ebb3f451c52f18d7ef6d (diff)
downloadorg.eclipse.tcf-c7af49022bcef0631acbb14c5435fa07873abe86.tar.gz
org.eclipse.tcf-c7af49022bcef0631acbb14c5435fa07873abe86.tar.xz
org.eclipse.tcf-c7af49022bcef0631acbb14c5435fa07873abe86.zip
Target Explorer: Use the URIs of remote files instead URL to persist
states.
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/compare/RemoteTypedElement.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSRename.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/PersistenceManager.java100
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/StateManager.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/model/FSTreeNode.java24
7 files changed, 80 insertions, 62 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/compare/RemoteTypedElement.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/compare/RemoteTypedElement.java
index 5348124f1..96f7e48fc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/compare/RemoteTypedElement.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/compare/RemoteTypedElement.java
@@ -99,6 +99,6 @@ public class RemoteTypedElement extends MergeTypedElement {
*/
@Override
public String toString() {
- return node.getLocationURL().toString();
+ return node.getLocationURI().toString();
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java
index e9c770972..880dcef37 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSOperation.java
@@ -176,7 +176,7 @@ public class FSOperation implements IRunnableWithProgress{
});
file.delete();
}
- PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURL());
+ PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURI());
FSTreeNode parent = node.parent;
if (parent != null) {
parent.removeChild(node);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSRename.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSRename.java
index edef1e1e4..43083dac6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSRename.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/operations/FSRename.java
@@ -130,7 +130,7 @@ public class FSRename extends FSJobOperation {
closeEditor(file);
}
});
- PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURL());
+ PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURI());
}
file.delete();
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java
index 4b40647f6..f314fd964 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/CacheManager.java
@@ -230,7 +230,7 @@ public class CacheManager {
if (file.exists()) {
// If downloading is successful, update the attributes of the file and
// set the last modified time to that of its corresponding file.
- PersistenceManager.getInstance().setBaseTimestamp(node.getLocationURL(), node.attr.mtime);
+ PersistenceManager.getInstance().setBaseTimestamp(node.getLocationURI(), node.attr.mtime);
file.setLastModified(node.attr.mtime);
if (!node.isWritable()) file.setReadOnly();
StateManager.getInstance().refreshState(node);
@@ -254,12 +254,12 @@ public class CacheManager {
// Something's gone wrong. Roll back the downloading and display the
// error.
file.delete();
- PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURL());
+ PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURI());
displayError(parent, e);
} catch (InterruptedException e) {
// It is canceled. Just roll back the downloading result.
file.delete();
- PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURL());
+ PersistenceManager.getInstance().removeBaseTimestamp(node.getLocationURI());
}
return false;
}
@@ -360,7 +360,7 @@ public class CacheManager {
@Override
public void run() throws Exception {
- PersistenceManager.getInstance().setBaseTimestamp(node.getLocationURL(), node.attr.mtime);
+ PersistenceManager.getInstance().setBaseTimestamp(node.getLocationURI(), node.attr.mtime);
if (sync) {
File file = getCacheFile(node);
file.setLastModified(node.attr.mtime);
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/PersistenceManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/PersistenceManager.java
index 4a4fc0185..99f6fe738 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/PersistenceManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/PersistenceManager.java
@@ -21,8 +21,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -75,8 +75,8 @@ public class PersistenceManager {
// The attribute "qualifier" of a qualified name.
private static final String ATTR_QUALIFIER = "qualifier"; //$NON-NLS-1$
- // The attribute of a node's URL
- private static final String ATTR_URL = "URL"; //$NON-NLS-1$
+ // The attribute of a node's URI
+ private static final String ATTR_URI = "URI"; //$NON-NLS-1$
// The element "property" to record a file's property
private static final String ELEMENT_PROPERTY = "property"; //$NON-NLS-1$
@@ -97,16 +97,16 @@ public class PersistenceManager {
private static PersistenceManager instance;
// The time stamp for each file.
- private Map<URL, Long> timestamps;
+ private Map<URI, Long> timestamps;
// The persistent properties of the files.
- private Map<URL, Map<QualifiedName, String>> properties;
+ private Map<URI, Map<QualifiedName, String>> properties;
- // Already known resolved content type of file nodes specified by their URLs.
- private Map<URL, IContentType> resolved;
+ // Already known resolved content type of file nodes specified by their URIs.
+ private Map<URI, IContentType> resolved;
- // Already known unresolvable file nodes specified by their URLs.
- private Map<URL, URL> unresolved;
+ // Already known unresolvable file nodes specified by their URIs.
+ private Map<URI, URI> unresolved;
/**
* Get the singleton cache manager.
@@ -136,7 +136,7 @@ public class PersistenceManager {
* @return true if it is not resolvable or else false.
*/
public boolean isUnresovled(FSTreeNode node) {
- return unresolved.get(node.getLocationURL()) != null;
+ return unresolved.get(node.getLocationURI()) != null;
}
/**
@@ -146,7 +146,7 @@ public class PersistenceManager {
* @return the content type of the node if it is resolvable or null.
*/
public IContentType getResolved(FSTreeNode node) {
- return resolved.get(node.getLocationURL());
+ return resolved.get(node.getLocationURI());
}
/**
@@ -156,7 +156,7 @@ public class PersistenceManager {
* @param contentType Its content type.
*/
public void addResovled(FSTreeNode node, IContentType contentType) {
- resolved.put(node.getLocationURL(), contentType);
+ resolved.put(node.getLocationURI(), contentType);
}
/**
@@ -165,7 +165,7 @@ public class PersistenceManager {
* @param node The file node.
*/
public void addUnresolved(FSTreeNode node) {
- unresolved.put(node.getLocationURL(), node.getLocationURL());
+ unresolved.put(node.getLocationURI(), node.getLocationURI());
}
/**
@@ -221,17 +221,17 @@ public class PersistenceManager {
*/
private void loadPersistentProperties() {
IMemento memento = readMemento(PERSISTENT_FILE, PERSISTENT_ROOT);
- properties = Collections.synchronizedMap(new HashMap<URL, Map<QualifiedName, String>>());
+ properties = Collections.synchronizedMap(new HashMap<URI, Map<QualifiedName, String>>());
IMemento[] children = memento.getChildren(ELEMENT_FILE);
if (children != null && children.length > 0) {
for (IMemento child : children) {
try {
- String str = child.getString(ATTR_URL);
- URL url = new URL(str);
+ String str = child.getString(ATTR_URI);
+ URI uri = new URI(str);
Map<QualifiedName, String> nodeProperties = loadFileProperties(child);
- properties.put(url, nodeProperties);
+ properties.put(uri, nodeProperties);
}
- catch (MalformedURLException e) {
+ catch (URISyntaxException e) {
}
}
}
@@ -242,24 +242,24 @@ public class PersistenceManager {
*/
private void loadContentTypes() {
IMemento memento = readMemento(CONTENT_TYPE_FILE, CONTENT_TYPE_ROOT);
- resolved = Collections.synchronizedMap(new HashMap<URL, IContentType>());
- unresolved = Collections.synchronizedMap(new HashMap<URL, URL>());
+ resolved = Collections.synchronizedMap(new HashMap<URI, IContentType>());
+ unresolved = Collections.synchronizedMap(new HashMap<URI, URI>());
IMemento mResolved = memento.getChild(ELEMENT_RESOLVED);
if (mResolved != null) {
IMemento[] children = mResolved.getChildren(ELEMENT_RESOLVABLE);
if (children != null && children.length > 0) {
for (IMemento child : children) {
try {
- String str = child.getString(ATTR_URL);
- URL url = new URL(str);
+ String str = child.getString(ATTR_URI);
+ URI uri = new URI(str);
String id = child.getString(ATTR_CONTENT_TYPE);
IContentType contentType = Platform.getContentTypeManager()
.getContentType(id);
if (contentType != null) {
- resolved.put(url, contentType);
+ resolved.put(uri, contentType);
}
}
- catch (MalformedURLException e) {
+ catch (URISyntaxException e) {
}
}
}
@@ -270,11 +270,11 @@ public class PersistenceManager {
if (children != null && children.length > 0) {
for (IMemento child : children) {
try {
- String str = child.getString(ATTR_URL);
- URL url = new URL(str);
- unresolved.put(url, url);
+ String str = child.getString(ATTR_URI);
+ URI uri = new URI(str);
+ unresolved.put(uri, uri);
}
- catch (MalformedURLException e) {
+ catch (URISyntaxException e) {
}
}
}
@@ -287,16 +287,16 @@ public class PersistenceManager {
private void saveContentTypes() {
XMLMemento memento = XMLMemento.createWriteRoot(CONTENT_TYPE_ROOT);
IMemento mResolved = memento.createChild(ELEMENT_RESOLVED);
- for (URL key : resolved.keySet()) {
+ for (URI key : resolved.keySet()) {
IContentType iContentType = resolved.get(key);
IMemento mResolvable = mResolved.createChild(ELEMENT_RESOLVABLE);
- mResolvable.putString(ATTR_URL, key.toString());
+ mResolvable.putString(ATTR_URI, key.toString());
mResolvable.putString(ATTR_CONTENT_TYPE, iContentType.getId());
}
IMemento mUnresolved = memento.createChild(ELEMENT_UNRESOLVED);
- for (URL key : unresolved.keySet()) {
+ for (URI key : unresolved.keySet()) {
IMemento mUnresolvable = mUnresolved.createChild(ELEMENT_UNRESOLVABLE);
- mUnresolvable.putString(ATTR_URL, key.toString());
+ mUnresolvable.putString(ATTR_URI, key.toString());
}
writeMemento(memento, CONTENT_TYPE_FILE);
}
@@ -363,11 +363,11 @@ public class PersistenceManager {
*/
private void savePersistentProperties() {
XMLMemento memento = XMLMemento.createWriteRoot(PERSISTENT_ROOT);
- for (URL key : properties.keySet()) {
+ for (URI key : properties.keySet()) {
Map<QualifiedName, String> nodeProperties = properties.get(key);
if (!nodeProperties.keySet().isEmpty()) {
IMemento mFile = memento.createChild(ELEMENT_FILE);
- mFile.putString(ATTR_URL, key.toString());
+ mFile.putString(ATTR_URI, key.toString());
saveFileProperties(mFile, nodeProperties);
}
}
@@ -425,10 +425,10 @@ public class PersistenceManager {
* @return The file properties object or empty properties object if it does not exist.
*/
public Map<QualifiedName, String> getPersistentProperties(FSTreeNode node) {
- Map<QualifiedName, String> nodeProperties = properties.get(node.getLocationURL());
+ Map<QualifiedName, String> nodeProperties = properties.get(node.getLocationURI());
if (nodeProperties == null) {
nodeProperties = Collections.synchronizedMap(new HashMap<QualifiedName, String>());
- properties.put(node.getLocationURL(), nodeProperties);
+ properties.put(node.getLocationURI(), nodeProperties);
}
return nodeProperties;
}
@@ -437,7 +437,7 @@ public class PersistenceManager {
* Load the time stamps from the time stamps file in the cache's root directory.
*/
private void loadTimestamps() {
- timestamps = Collections.synchronizedMap(new HashMap<URL, Long>());
+ timestamps = Collections.synchronizedMap(new HashMap<URI, Long>());
File location = CacheManager.getInstance().getCacheRoot();
File tsFile = new File(location, TIMESTAMP_FILE);
if (tsFile.exists()) {
@@ -466,7 +466,7 @@ public class PersistenceManager {
long timestamp = 0L;
try {
timestamp = Long.parseLong(value);
- timestamps.put(new URL(key), Long.valueOf(timestamp));
+ timestamps.put(new URI(key), Long.valueOf(timestamp));
}
catch (Exception nfe) {
}
@@ -479,7 +479,7 @@ public class PersistenceManager {
*/
private void saveTimestamps() {
Properties properties = new Properties();
- for (URL key : timestamps.keySet()) {
+ for (URI key : timestamps.keySet()) {
Long timestamp = timestamps.get(key);
properties.setProperty(key.toString(), timestamp.toString());
}
@@ -507,30 +507,30 @@ public class PersistenceManager {
/**
* Set the time stamp of the FSTreeNode with the specified location.
*
- * @param url The FSTreeNode's location URL.
+ * @param uri The FSTreeNode's location URI.
* @param timestamp The new base time stamp to be set.
*/
- public void setBaseTimestamp(URL url, long timestamp) {
- timestamps.put(url, Long.valueOf(timestamp));
+ public void setBaseTimestamp(URI uri, long timestamp) {
+ timestamps.put(uri, Long.valueOf(timestamp));
}
/**
- * Remove the time stamp entry with the specified URL.
+ * Remove the time stamp entry with the specified URI.
*
- * @param url The URL key.
+ * @param uri The URI key.
*/
- public void removeBaseTimestamp(URL url) {
- timestamps.remove(url);
+ public void removeBaseTimestamp(URI uri) {
+ timestamps.remove(uri);
}
/**
* Get the time stamp of the FSTreeNode with the specified location.
*
- * @param url The FSTreeNode's location URL.
+ * @param uri The FSTreeNode's location URI.
* @return The FSTreeNode's base time stamp.
*/
- public long getBaseTimestamp(URL url) {
- Long timestamp = timestamps.get(url);
+ public long getBaseTimestamp(URI uri) {
+ Long timestamp = timestamps.get(uri);
return timestamp == null ? 0L : timestamp.longValue();
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/StateManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/StateManager.java
index 3607e31a3..509d5e8ff 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/StateManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/internal/utils/StateManager.java
@@ -143,7 +143,7 @@ public class StateManager {
*/
void commitNodeAttr(FSTreeNode node, FileAttrs attr){
node.setAttributes(attr);
- PersistenceManager.getInstance().setBaseTimestamp(node.getLocationURL(), attr.mtime);
+ PersistenceManager.getInstance().setBaseTimestamp(node.getLocationURI(), attr.mtime);
}
/**
@@ -158,7 +158,7 @@ public class StateManager {
if(!file.exists())
return CacheState.consistent;
long ltime = file.lastModified();
- long btime = PersistenceManager.getInstance().getBaseTimestamp(node.getLocationURL());
+ long btime = PersistenceManager.getInstance().getBaseTimestamp(node.getLocationURI());
long mtime = 0;
if(node.attr!=null)
mtime = node.attr.mtime;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/model/FSTreeNode.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/model/FSTreeNode.java
index a01e801ff..39abe9701 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/model/FSTreeNode.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem/src/org/eclipse/tcf/te/tcf/filesystem/model/FSTreeNode.java
@@ -13,6 +13,8 @@
package org.eclipse.tcf.te.tcf.filesystem.model;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
@@ -405,16 +407,32 @@ public final class FSTreeNode extends PlatformObject implements Cloneable, IPeer
* {@link TcfURLConnection#TcfURLConnection(URL)}
*
* @see TcfURLStreamHandlerService#parseURL(URL, String, int, int)
+ * @see #getLocationURI()
* @return The URL of the file/folder.
- * @throws MalformedURLException
*/
public URL getLocationURL() {
try {
+ return getLocationURI().toURL();
+ } catch (MalformedURLException e) {
+ assert false;
+ return null;
+ }
+ }
+
+ /**
+ * Get the URI of the file or folder. The URI's format is created in the
+ * following way: tcf:/<TCF_AGENT_ID>/remote/path/to/the/resource...
+ *
+ * @return The URI of the file/folder.
+ */
+ public URI getLocationURI() {
+ try {
String id = peerNode.getPeerId();
String path = getLocation(true);
String location = TcfURLConnection.PROTOCOL_SCHEMA + ":/" + id + (path.startsWith("/") ? path : "/" + path); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return new URL(location);
- } catch (MalformedURLException e) {
+ return new URI(location);
+ }
+ catch (URISyntaxException e) {
assert false;
return null;
}

Back to the top