In progress: [ Issue 40 ] Add support for import resolution across multiple folders
https://code.google.com/p/protobuf-dt/issues/detail?id=40
Adding support for using both workspace and file system paths for resolution of imports.
diff --git a/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF
index ad89cad..87abba7 100644
--- a/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF
@@ -16,7 +16,8 @@
org.eclipse.core.runtime,
com.ibm.icu,
org.eclipse.emf.databinding,
- org.eclipse.core.resources
+ org.eclipse.core.resources,
+ org.eclipse.core.filesystem;bundle-version="1.3.100"
Import-Package: org.apache.log4j,
org.apache.commons.logging
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java
index 15c6e5d..7f46b50 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.scoping;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences;
@@ -18,7 +19,7 @@
interface FileResolverStrategy {
String PREFIX = "platform:/resource";
- String SEPARATOR = "/";
+ char SEPARATOR = IPath.SEPARATOR;
String resolveUri(String importUri, URI declaringResourceUri, PathsPreferences preferences);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
index abb6877..6379c7d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
@@ -8,6 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.scoping;
+import org.eclipse.core.filesystem.*;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import com.google.eclipse.protobuf.ui.preferences.paths.DirectoryPath;
@@ -27,16 +30,28 @@
/** {@inheritDoc} */
public String resolveUri(String importUri, URI declaringResourceUri, PathsPreferences preferences) {
for (DirectoryPath directoryPath : preferences.directoryPaths()) {
- if (!directoryPath.isWorkspacePath()) continue; // TODO file system is not supported yet.
- String resolved = resolveUriInWorkspace(importUri, directoryPath.value());
+ String resolved = resolveUri(importUri, directoryPath);
if (resolved != null) return resolved;
}
return null;
}
- private String resolveUriInWorkspace(String importUri, String directoryName) {
- String path = PREFIX + directoryName + SEPARATOR + importUri;
+ private String resolveUri(String importUri, DirectoryPath directoryPath) {
+ if (directoryPath.isWorkspacePath()) return resolveUriInWorkspace(importUri, directoryPath.value());
+ return resolveUriFileSystem(importUri, directoryPath.value());
+ }
+
+ private String resolveUriInWorkspace(String importUri, String directoryPath) {
+ String path = PREFIX + directoryPath + SEPARATOR + importUri;
boolean exists = resources.fileExists(URI.createURI(path));
return (exists) ? path : null;
}
+
+ private String resolveUriFileSystem(String importUri, String directoryPath) {
+ IFileSystem fileSystem = EFS.getLocalFileSystem();
+ IPath path = new Path(directoryPath + SEPARATOR + importUri);
+ IFileInfo fileInfo = fileSystem.getStore(path).fetchInfo();
+ if (!fileInfo.exists()) return null;
+ return URIUtil.toURI(path).toString();
+ }
}