[jbosstools-commits] JBoss Tools SVN: r22818 - branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Jun 15 09:57:45 EDT 2010


Author: scabanovich
Date: 2010-06-15 09:57:44 -0400 (Tue, 15 Jun 2010)
New Revision: 22818

Added:
   branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
Modified:
   branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
   branches/jbosstools-3.1.x/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: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
===================================================================
--- branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java	2010-06-15 13:46:49 UTC (rev 22817)
+++ branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java	2010-06-15 13:57:44 UTC (rev 22818)
@@ -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 {
@@ -197,7 +200,17 @@
 		String encoding = null;
 		boolean first = true;
 		try {
-			InputStream is = jar.getInputStream(jar.getEntry(path));
+			ZipEntry entry = jar.getEntry(path);
+			if(entry == null && path != null && path.length() > 0 && !path.startsWith("/")) {
+				 entry = jar.getEntry("/" + path);
+			}
+			if(entry == null) {
+				String error = "JarAccess: cannot obtain entry for path '" + path + "' from jar '" + location + "'.";  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+				ModelPlugin.getDefault().logError(error);
+				return ""; //$NON-NLS-1$
+			}
+			
+			InputStream is = jar.getInputStream(entry);
 			bs = new BufferedInputStream(is);
 			while ((length = bs.available()) > 0) {
 				if (length > size)
@@ -274,6 +287,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 {
@@ -341,4 +404,4 @@
 		return false;
 	}
 
-}
+}
\ No newline at end of file

Added: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
===================================================================
--- branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java	                        (rev 0)
+++ branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java	2010-06-15 13:57:44 UTC (rev 22818)
@@ -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: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccessFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java
===================================================================
--- branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java	2010-06-15 13:46:49 UTC (rev 22817)
+++ branches/jbosstools-3.1.x/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarSystemImpl.java	2010-06-15 13:57:44 UTC (rev 22818)
@@ -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) {
@@ -90,4 +127,3 @@
     	return super.getPresentationString();
     }
 }
-



More information about the jbosstools-commits mailing list