Author: scabanovich
Date: 2009-09-23 07:22:25 -0400 (Wed, 23 Sep 2009)
New Revision: 17700
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4912
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2009-09-23
10:39:42 UTC (rev 17699)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2009-09-23
11:22:25 UTC (rev 17700)
@@ -62,8 +62,9 @@
protected boolean loaded = false;
protected IContainer resource = null;
protected String pathForResource = null;
- protected Map<String, File> linked = new HashMap<String, File>();
- protected Map<String, IResource> linkedResources = new HashMap<String,
IResource>();
+ LinkedResources linked = new LinkedResources();
+// protected Map<String, File> linked = new HashMap<String, File>();
+// protected Map<String, IResource> linkedResources = new HashMap<String,
IResource>();
public FolderImpl() {}
@@ -111,8 +112,8 @@
protected String getAbsolutePath() {
FolderImpl parent = (FolderImpl)getParent();
String p = (parent == null) ? null : parent.getAbsolutePath();
- if(parent.linked.containsKey(getPathPart())) {
- return parent.linked.get(getPathPart()).getAbsolutePath();
+ if(parent.linked.containsFile(getPathPart())) {
+ return parent.linked.getFileByFileName(getPathPart()).getAbsolutePath();
}
return (p == null) ? null : p + XModelObjectConstants.SEPARATOR + name();
}
@@ -157,10 +158,12 @@
for (int i = 0; i < rs.length; i++) {
if(!rs[i].isAccessible()) continue;
if(!rs[i].isLinked()) continue;
+ if(rs[i].getLocation() == null) {
+// System.out.println("no location at link " + rs[i]);
+ continue;
+ }
File f = rs[i].getLocation().toFile();
- String pp = FilePathHelper.toPathPath(f.getName());
- linked.put(pp, f);
- linkedResources.put(pp, rs[i]);
+ linked.registerResource(rs[i]);
_loadChild(peer, f);
}
@@ -187,8 +190,8 @@
p.setProperty(XModelObjectConstants.ATTR_NAME, f.getName());
XModelObject c = getModel().createModelObject("FileFolder", p);
//$NON-NLS-1$
String pp = FilePathHelper.toPathPath(f.getName());
- if(linked.containsKey(pp)) {
- c.setObject("file", linked.get(pp)); //$NON-NLS-1$
+ if(linked.containsFile(pp)) {
+ c.setObject("file", linked.getFileByFileName(pp)); //$NON-NLS-1$
}
addChild(c);
} else {
@@ -246,7 +249,7 @@
c.set(XModelObjectConstants.ATTR_NAME__FILE, f.getAbsolutePath());
}
}
- if(linked.containsValue(f)) {
+ if(linked.filesByFileName.containsValue(f)) {
c.setObject("file", f); //$NON-NLS-1$
}
addChild(c);
@@ -259,7 +262,7 @@
if(updateLock > 0) return true;
updateLock++;
Map<String,File> mf = new HashMap<String,File>();
- linked.clear();
+ linked.clearFiles();
XModelObject fileSystem = getFileSystem();
if(fileSystem == null) return false;
FileSystemsImpl fsi = (FileSystemsImpl)fileSystem.getParent();
@@ -302,8 +305,7 @@
File f = rs[i].getLocation().toFile();
String p = FilePathHelper.toPathPath(f.getName());
mf.put(p, f);
- linked.put(p, f);
- linkedResources.put(p, rs[i]);
+ linked.registerResource(rs[i]);
}
}
}
@@ -371,8 +373,8 @@
protected File getChildIOFile(XModelObject o) {
String s = FileAnyImpl.toFileName(o);
File f = (File)o.getObject("file"); //for links //$NON-NLS-1$
- if(f == null && linked.containsKey(o.getPathPart())) {
- f = linked.get(o.getPathPart());
+ if(f == null && linked.containsFile(o.getPathPart())) {
+ f = linked.getFileByFileName(o.getPathPart());
}
if(f == null) {
f = new File(getFile(), s);
@@ -383,8 +385,8 @@
protected File getChildIOFile(String filename) {
File f = null;
String p = FilePathHelper.toPathPath(filename);
- if(linked.containsKey(p)) {
- f = linked.get(p);
+ if(linked.containsFile(p)) {
+ f = linked.getFileByFileName(p);
}
if(f == null) {
f = new File(getFile(), filename);
@@ -615,8 +617,8 @@
p.setProperty(XModelObjectConstants.ATTR_NAME, f.getName());
c = getModel().createModelObject("FileFolder", p); //$NON-NLS-1$
String pp = FilePathHelper.toPathPath(f.getName());
- if(linked.containsKey(pp)) {
- c.setObject("file", linked.get(pp)); //$NON-NLS-1$
+ if(linked.containsFile(pp)) {
+ c.setObject("file", linked.getFileByFileName(pp)); //$NON-NLS-1$
}
} else {
Properties ep = getEntityProperties(f);
@@ -724,7 +726,7 @@
if (q || loaded) return q;
if(getParent() instanceof FolderImpl) {
FolderImpl p = (FolderImpl)getParent();
- if(p.linked.containsKey(getPathPart())) return true;
+ if(p.linked.containsFile(getPathPart())) return true;
}
File[] fs = getFiles();
q = (fs != null && fs.length > 0);
@@ -764,7 +766,7 @@
if(cs[i] instanceof FolderLoader) {
b &= ((FolderLoader)cs[i]).save();
} else {
- File d = linked.get(cs[i].getPathPart());
+ File d = linked.getFileByFileName(cs[i].getPathPart());
if(d == null) {
d = new File(f, FileAnyImpl.toFileName(cs[i]));
}
@@ -809,7 +811,7 @@
updateLock++;
boolean b = false;
try {
- File d = linked.get(c.getPathPart());
+ File d = linked.getFileByFileName(c.getPathPart());
if(d == null) {
d = new File(folder, FileAnyImpl.toFileName(c));
}
@@ -923,6 +925,10 @@
}
public XModelObject getChildByPathPart(String pathpart) {
+ if(linked.filesByLinkName.containsKey(pathpart)) {
+ File f = linked.getFileByResourceName(pathpart);
+ pathpart = f.getName();
+ }
pathpart = FilePathHelper.toPathPath(pathpart);
return super.getChildByPathPart(pathpart);
}
@@ -972,8 +978,8 @@
}
public IContainer getChildContainer(String name) {
- if(linked.containsKey(name)) {
- IResource r = linkedResources.get(name);
+ if(linked.containsFile(name)) {
+ IResource r = linked.getResourceByFileName(name);
return r instanceof IContainer ? (IContainer)r : null;
}
IContainer c = getResource();
@@ -981,8 +987,8 @@
}
public IFile getChildFile(String name) {
- if(linked.containsKey(name)) {
- IResource r = linkedResources.get(name);
+ if(linked.containsFile(name)) {
+ IResource r = linked.getResourceByFileName(name);
return r instanceof IFile ? (IFile)r : null;
}
IContainer c = getResource();
@@ -1061,6 +1067,48 @@
}
+class LinkedResources {
+ protected Map<String, File> filesByLinkName = new HashMap<String, File>();
+ protected Map<String, File> filesByFileName = new HashMap<String, File>();
+ protected Map<String, IResource> resourcesByLinkName = new HashMap<String,
IResource>();
+ protected Map<String, IResource> resourcesByFileName = new HashMap<String,
IResource>();
+
+ public boolean containsFile(String name) {
+ if(filesByFileName.containsKey(name)) return true;
+ return false;
+ }
+
+ public File getFileByResourceName(String name) {
+ return filesByLinkName.get(name);
+ }
+
+ public File getFileByFileName(String name) {
+ return filesByFileName.get(name);
+ }
+
+ public IResource getResourceByResourceName(String name) {
+ return resourcesByLinkName.get(name);
+ }
+
+ public IResource getResourceByFileName(String name) {
+ return resourcesByFileName.get(name);
+ }
+
+ public void registerResource(IResource r) {
+ File f = r.getLocation().toFile();
+ String pp = FilePathHelper.toPathPath(f.getName());
+ filesByFileName.put(pp, f);
+ filesByLinkName.put(r.getName(), f);
+ resourcesByFileName.put(pp, r);
+ resourcesByLinkName.put(r.getName(), r);
+ }
+
+ public void clearFiles() {
+ filesByFileName.clear();
+ filesByLinkName.clear();
+ }
+}
+
class EclipseFileBodySource implements BodySource {
IFile ef = null;
File f;
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2009-09-23
10:39:42 UTC (rev 17699)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2009-09-23
11:22:25 UTC (rev 17700)
@@ -374,6 +374,14 @@
}
if(cs != null) for (int i = 0; i < cs.length; i++) {
if(!cs[i].isLinked()) continue;
+ if(!cs[i].isAccessible()) continue;
+ if(cs[i].getLocation() == null) {
+// System.out.println("no location at link " + cs[i]);
+ continue;
+ }
+ if(cs[i].getLocation().toFile() == null ||
!cs[i].getLocation().toFile().isDirectory()) {
+ continue;
+ }
properties = new Properties();
fsLoc = cs[i].getLocation().toString();
properties.setProperty(XModelObjectConstants.ATTR_NAME_LOCATION, fsLoc);
@@ -418,9 +426,9 @@
}
IResource sr = s.getResource();
if(sr == null) return null;
- if(!sr.getLocation().isPrefixOf(resource.getLocation())) return null;
- String path = resource.getLocation().toString();
- String rootpath = sr.getLocation().toString();
+ if(!sr.getFullPath().isPrefixOf(resource.getFullPath())) return null;
+ String path = resource.getFullPath().toString();
+ String rootpath = sr.getFullPath().toString();
String relpath = path.substring(rootpath.length()).replace('\\', '/');
if(relpath.length() == 0) return s;
@@ -434,7 +442,7 @@
while(p != null &&
!XModelObjectConstants.TRUE.equals(p.get("overlapped"))) p = p.getParent();
//$NON-NLS-1$
if(p == null) {
IResource r = (IResource)o.getAdapter(IResource.class);
- if(r == null || !resource.getLocation().equals(r.getLocation())) {
+ if(r == null || !resource.getFullPath().equals(r.getFullPath())) {
//failure, more detailed file system is needed.
return null;
}