Author: scabanovich
Date: 2011-05-26 19:07:05 -0400 (Thu, 26 May 2011)
New Revision: 31528
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/Libs.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
Log:
JBIDE-9005
https://issues.jboss.org/browse/JBIDE-9005
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/Libs.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/Libs.java 2011-05-26
19:43:02 UTC (rev 31527)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/Libs.java 2011-05-26
23:07:05 UTC (rev 31528)
@@ -45,6 +45,8 @@
protected List<String> paths = null;
Map<IPath, String> paths2 = new HashMap<IPath, String>();
+ LibraryNames libraryNames = new LibraryNames();
+
List<LibsListener> listeners = new ArrayList<LibsListener>();
public Libs(FileSystemsImpl object) {
@@ -64,6 +66,24 @@
return EclipseResourceUtil.getProject(object);
}
+ public XModelObject getLibrary(String path) {
+ String libName = libraryNames.getName(path);
+ if(libName == null) {
+ //compatibility to old code.
+ libName = LIB_PREFIX + new File(path).getName();
+ }
+ return object.getChildByPath(libName);
+ }
+
+ public XModelObject getLibrary(File f) {
+ XModelObject result = null;
+ if(f.exists()) {
+ String path = f.getAbsolutePath().replace('\\', '/');
+ result = getLibrary(path);
+ }
+ return result;
+ }
+
public boolean update() {
boolean result = updatePaths();
if(result) fire();
@@ -103,12 +123,25 @@
return true;
}
- static String LIB_PREFIX = "lib-"; //$NON-NLS-1$
+ public static String LIB_PREFIX = "lib-"; //$NON-NLS-1$
void updateFileSystems(List<String> paths) {
if(fsVersion >= pathsVersion) {
return;
}
+
+ Set<String> oldPaths = libraryNames.getPaths();
+ for (String p: oldPaths) {
+ if(!paths.contains(p)) {
+ String n = libraryNames.getName(p);
+ XModelObject o = object.getChildByPath(n);
+ if(o != null) {
+ o.removeFromParent();
+ }
+ libraryNames.removePath(p);
+ }
+ }
+
XModelObject[] fs = object.getChildren();
Set<XModelObject> fss = new HashSet<XModelObject>();
for (int i = 0; i < fs.length; i++) {
@@ -123,7 +156,14 @@
String libEntity = isJar ? "FileSystemJar" : "FileSystemFolder";
//$NON-NLS-1$ //$NON-NLS-2$
String fileName = new File(path).getName();
if(isJar && EclipseResourceUtil.SYSTEM_JAR_SET.contains(fileName)) continue;
- String jsname = LIB_PREFIX + fileName;
+ String jsname = libraryNames.getName(path);
+ if(jsname == null) {
+ jsname = LIB_PREFIX + fileName;
+ int q = 0;
+ while(libraryNames.hasName(jsname)) {
+ jsname = LIB_PREFIX + fileName + "-" + (++q); //$NON-NLS-1$
+ }
+ }
XModelObject o = object.getChildByPath(jsname);
if(o != null) {
fss.remove(o);
@@ -134,7 +174,8 @@
o.set(FileSystemsLoader.IS_ADDED_TO_CLASSPATH, XModelObjectConstants.TRUE);
object.addChild(o);
// object.setModified(true);
- }
+ }
+ libraryNames.put(path, jsname);
}
for (XModelObject o: fss) {
@@ -220,3 +261,36 @@
}
}
+
+class LibraryNames {
+ private Map<String, String> pathToName = new HashMap<String, String>();
+ private Map<String, String> nameToPath = new HashMap<String, String>();
+
+ public void put(String path, String name) {
+ pathToName.put(path, name);
+ nameToPath.put(name, path);
+ }
+
+ public void removePath(String path) {
+ String name = pathToName.remove(path);
+ if(name != null) {
+ nameToPath.remove(name);
+ }
+ }
+
+ public String getName(String path) {
+ return pathToName.get(path);
+ }
+
+ public String getPath(String name) {
+ return nameToPath.get(name);
+ }
+
+ public boolean hasName(String name) {
+ return nameToPath.containsKey(name);
+ }
+
+ public Set<String> getPaths() {
+ return new HashSet<String>(pathToName.keySet());
+ }
+}
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 2011-05-26
19:43:02 UTC (rev 31527)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2011-05-26
23:07:05 UTC (rev 31528)
@@ -63,6 +63,7 @@
import org.jboss.tools.common.model.filesystems.impl.FileSystemImpl;
import org.jboss.tools.common.model.filesystems.impl.FileSystemsImpl;
import org.jboss.tools.common.model.filesystems.impl.JarSystemImpl;
+import org.jboss.tools.common.model.filesystems.impl.Libs;
import org.jboss.tools.common.model.icons.impl.XModelObjectIcon;
import org.jboss.tools.common.model.impl.XModelObjectImpl;
import org.jboss.tools.common.model.plugin.ModelPlugin;
@@ -459,7 +460,7 @@
private static void validateJarSystem(XModelObject fs, IResource resource) {
if(fs == null || !isJar(resource)) return;
- String jsname = "lib-" + resource.getName().toLowerCase(); //$NON-NLS-1$
+ String jsname = Libs.LIB_PREFIX + resource.getName().toLowerCase(); //$NON-NLS-1$
String location = resource.getLocation().toString().replace('\\',
'/');
if(fs.getChildByPath(jsname) == null) {
XModelObject q = fs.getModel().createModelObject("FileSystemJar", null);
//$NON-NLS-1$