Author: scabanovich
Date: 2010-05-27 11:31:26 -0400 (Thu, 27 May 2010)
New Revision: 22375
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java
Log:
https://jira.jboss.org/browse/JBIDE-6372
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java 2010-05-27
15:30:35 UTC (rev 22374)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java 2010-05-27
15:31:26 UTC (rev 22375)
@@ -18,13 +18,16 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.eclipse.core.resources.IProject;
import org.jboss.tools.common.model.XModelObjectConstants;
import org.jboss.tools.common.model.plugin.ModelPlugin;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.util.FileUtil;
public class JarAccess {
@@ -274,6 +277,56 @@
return templocation;
}
+ JarSystemImpl main = null;
+ Set<JarSystemImpl> slaves = new HashSet<JarSystemImpl>();
+
+ public JarSystemImpl getMain() {
+ IProject p = EclipseResourceUtil.getProject(main);
+ if(p == null || !p.isAccessible() || main.getParent() == null) {
+ main = null;
+ synchronized(slaves) {
+ Iterator<JarSystemImpl> it = slaves.iterator();
+ while(it.hasNext()) {
+ JarSystemImpl s = it.next();
+ p = EclipseResourceUtil.getProject(s);
+ if(p == null || !p.isAccessible() || s.getParent() == null) {
+ it.remove();
+ } else if(main == null) {
+ main = s;
+ it.remove();
+ }
+ }
+ }
+ if(main != null) main.jarUpdated();
+ JarSystemImpl[] ss = getSlaves();
+ for (JarSystemImpl s: ss) s.jarUpdated();
+ }
+ return main;
+ }
+
+ public void setMain(JarSystemImpl main) {
+ this.main = main;
+ }
+
+ public JarSystemImpl[] getSlaves() {
+ synchronized(slaves) {
+ return slaves.toArray(new JarSystemImpl[slaves.size()]);
+ }
+ }
+
+ public void addSlave(JarSystemImpl s) {
+ if(main == null) {
+ main = s;
+ } else {
+ synchronized(slaves) {
+ slaves.add(s);
+ }
+ }
+ }
+
+ public boolean isSlave(JarSystemImpl s) {
+ return slaves.contains(s);
+ }
}
class LFileObjectJarImpl implements LFileObject {
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java 2010-05-27
15:31:26 UTC (rev 22375)
@@ -0,0 +1,24 @@
+package org.jboss.tools.common.model.filesystems.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class JarAccessFactory {
+
+ static Map<String, JarAccess> jars = new HashMap<String, JarAccess>();
+
+ public static JarAccess getJarAccess(String location, JarSystemImpl context) {
+ JarAccess jar = jars.get(location);
+ if(jar == null) {
+ jar = new JarAccess();
+ jar.setMain(context);
+ jar.setLocation(location);
+ jars.put(location, jar);
+ }
+ if(context != jar.getMain()) {
+ jar.addSlave(context);
+ }
+ return jar;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java 2010-05-27
15:30:35 UTC (rev 22374)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java 2010-05-27
15:31:26 UTC (rev 22375)
@@ -10,12 +10,14 @@
******************************************************************************/
package org.jboss.tools.common.model.filesystems.impl;
+import java.util.Set;
+
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.model.util.*;
public class JarSystemImpl extends JarFolderImpl implements
org.jboss.tools.common.model.filesystems.FileSystem {
private static final long serialVersionUID = 7958999759019059243L;
- protected JarAccess jar = new JarAccess();
+ protected JarAccess jar = null;
public JarSystemImpl() {}
@@ -28,6 +30,9 @@
}
protected JarAccess getJarAccess() {
+ if(jar == null) {
+ jar = JarAccessFactory.getJarAccess(getLocation(), this);
+ }
return jar;
}
@@ -38,15 +43,32 @@
protected String getAbsolutePath() {
return ""; //$NON-NLS-1$
}
+
+ boolean loaded2 = false;
protected void loadChildren() {
- if(jar.isLoaded()) return;
+// if(jar.isLoaded()) return;
+
+ if(this != getJarAccess().getMain()) return;
+ if(loaded2) return;
+ loaded2 = true;
+
synchronized (this) {
jar.setLocation(getLocation());
super.loadChildren();
}
}
+ public XModelObject[] getChildren() {
+ JarSystemImpl main = getJarAccess().getMain();
+ return (main == this || main == null) ? super.getChildren() : main.getChildren();
+ }
+
+ public XModelObject getChildByPathPart(String pathpart) {
+ JarSystemImpl main = getJarAccess().getMain();
+ return (main == this || main == null) ? super.getChildByPathPart(pathpart) :
main.getChildByPathPart(pathpart);
+ }
+
public String getPathPart() {
return name();
}
@@ -56,29 +78,44 @@
}
public String getTempLocation() {
- if(!jar.isLoaded()) loadChildren();
+ JarSystemImpl main = getJarAccess().getMain();
+ if(main != this && main != null) {
+ main.getChildren();
+ } else if(!jar.isLoaded()) {
+ loadChildren();
+ }
String s = jar.getTempLocation();
return (s == null) ? get(XModelObjectConstants.ATTR_NAME_LOCATION) : s;
}
public LFileObject getFileObject(String relpath) {
- return jar.getFileObject(name(), relpath);
+ return getJarAccess().getFileObject(name(), relpath);
}
public boolean update() {
+ if(getJarAccess().getMain() != this) return true;
+
if(jar.isModified()) {
if(jar.isLoaded()) {
XModelObject[] cs = getChildren();
for (int i = 0; i < cs.length; i++) removeChild_0(cs[i]);
jar.invalidate();
}
- loaded = false;
- fire = true;
- fireStructureChanged(3, null);
+ jarUpdated();
+
+ JarSystemImpl[] ss = getJarAccess().getSlaves();
+ for (JarSystemImpl s: ss) s.jarUpdated();
}
return true;
}
+ public void jarUpdated() {
+ loaded = false;
+ loaded2 = false;
+ fire = true;
+ fireStructureChanged(3, null);
+ }
+
public String getPresentationString() {
String location = getLocation();
if(location != null) {