[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory ...
Robert Stryker
rawblem at gmail.com
Fri Aug 18 11:16:49 EDT 2006
User: rawb
Date: 06/08/18 11:16:49
Modified: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory
JBossModuleFactory.java ArchiveModuleFactory.java
JBossModuleDelegate.java
Log:
Changed many IResource parameters to String path.
Re-configured JBossModuleFactory's initialization scheme to get a list of modules from all servers. If the Module's ID is from the factory executing, it will specifically try to add that resource.
This prevents a full workspace check and makes execution and startup much quicker.
Revision Changes Path
1.4 +88 -31 jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory/JBossModuleFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JBossModuleFactory.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory/JBossModuleFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- JBossModuleFactory.java 24 Jun 2006 01:20:52 -0000 1.3
+++ JBossModuleFactory.java 18 Aug 2006 15:16:49 -0000 1.4
@@ -21,16 +21,17 @@
*/
package org.jboss.ide.eclipse.as.core.module.factory;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceVisitor;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.internal.Server;
import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.model.ModuleFactoryDelegate;
import org.jboss.ide.eclipse.as.core.model.ModuleModel;
@@ -48,7 +49,11 @@
public abstract void initialize();
public abstract Object getLaunchable(JBossModuleDelegate delegate);
- public abstract boolean supports(IResource resource);
+ public abstract boolean supports(String path);
+
+ public boolean supports( IResource resource ) {
+ return supports(getPath(resource));
+ }
/**
* Get a delegate for this module.
@@ -77,44 +82,96 @@
* Store them when they're found.
*/
protected void cacheModules() {
+
ASDebug.p("Caching factory ", this);
this.pathToModule = new HashMap();
this.moduleToDelegate = new HashMap();
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- for( int i = 0; i < projects.length; i++ ) {
- try {
- projects[i].accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- acceptAddition(resource);
- return true;
+
+ String[] paths = getServerModulePaths();
+ for( int i = 0; i < paths.length; i++ ) {
+ acceptAddition(paths[i]);
+ }
+
+// IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+// for( int i = 0; i < projects.length; i++ ) {
+// try {
+// projects[i].accept(new IResourceVisitor() {
+// public boolean visit(IResource resource) throws CoreException {
+// acceptAddition(resource);
+// return true;
+// }
+// });
+// } catch( CoreException ce ) {
+// }
+// }
+ }
+
+ private String[] getServerModulePaths() {
+ // Stolen from Server.class, not public
+ final String MODULE_LIST = "modules";
+
+ ArrayList paths = new ArrayList();
+ IServer[] server = ServerCore.getServers();
+ for( int i = 0; i < server.length; i++ ) {
+ if( server[i].getClass().equals(Server.class)) {
+ // Get the module ID list:
+ Object[] o = ((Server)server[i]).getAttribute(MODULE_LIST, (List) null).toArray();
+ // Get the module ID list:
+ for( int j = 0; j < o.length; j++ ) {
+ ASDebug.p("(server,module) = (" + server[i].getName() + "," + o[j], this);
+ String moduleId = (String) o[j];
+ String name = "<unknown>";
+ int index = moduleId.indexOf("::");
+ if (index > 0) {
+ name = moduleId.substring(0, index);
+ moduleId = moduleId.substring(index+2);
+ }
+
+ String moduleTypeId = null;
+ String moduleTypeVersion = null;
+ index = moduleId.indexOf("::");
+ if (index > 0) {
+ int index2 = moduleId.indexOf("::", index+1);
+ moduleTypeId = moduleId.substring(index+2, index2);
+ moduleTypeVersion = moduleId.substring(index2+2);
+ moduleId = moduleId.substring(0, index);
+ }
+
+ if( moduleId.startsWith(getFactoryId() + ":")) {
+ String path = moduleId.substring((getFactoryId()+":").length());
+ paths.add(path);
+ }
+
}
- });
- } catch( CoreException ce ) {
}
}
+ return (String[]) paths.toArray(new String[paths.size()]);
}
-
/**
* Return an associated module for this resource,
* or null of none is found in this factory.
* @param resource
* @return
*/
- public IModule getModule(IResource resource) {
+ public IModule getModule(String path) {
//ASDebug.p("getModule: " + resource.getFullPath() + ", my ID is " + getId(), this);
if(pathToModule == null) {
cacheModules();
}
// return the module if it already exists
- String path = getPath(resource);
+ //String path = getPath(resource);
if( pathToModule.get(path) != null ) {
return (IModule)pathToModule.get(path);
}
return null;
}
+ public IModule getModule(IResource resource) {
+ return getModule(getPath(resource));
+ }
+
/**
* I dont think any class uses this yet, but I thought it should be public.
* @return
@@ -123,7 +180,7 @@
return getId();
}
- protected abstract IModule acceptAddition(IResource resource);
+ protected abstract IModule acceptAddition(String path);
/**
* Handle a deleted resource.
@@ -132,8 +189,8 @@
* the module will still be on the server.
* @param resource
*/
- protected void acceptDeletion(IResource resource) {
- IModule module = getModule(resource);
+ protected void acceptDeletion(String resourcePath) {
+ IModule module = getModule(resourcePath);
if( module == null ) return;
Object delegate = moduleToDelegate.get(module);
@@ -141,7 +198,7 @@
((JBossModuleDelegate)delegate).clearDocuments();
}
moduleToDelegate.remove(module);
- pathToModule.remove(getPath(resource));
+ pathToModule.remove(resourcePath);
ModuleModel.getDefault().markModuleChanged(module, IResourceDelta.REMOVED);
}
@@ -153,8 +210,8 @@
*
* @param resource
*/
- protected void acceptChange(IResource resource) {
- IModule module = getModule(resource);
+ protected void acceptChange(String resourcePath) {
+ IModule module = getModule(resourcePath);
if( module == null ) return;
Object delegate = moduleToDelegate.get(module);
@@ -177,15 +234,15 @@
public void resourceEvent(IResource resource, int kind) {
switch( kind ) {
case IResourceDelta.REMOVED:
- if( contains(resource))
- acceptDeletion(resource);
+ if( contains(getPath(resource)))
+ acceptDeletion(getPath(resource));
break;
case IResourceDelta.ADDED:
- acceptAddition(resource);
+ acceptAddition(getPath(resource));
break;
case IResourceDelta.CHANGED:
- if( contains(resource))
- acceptChange(resource);
+ if( contains(getPath(resource)))
+ acceptChange(getPath(resource));
break;
default:
break;
@@ -198,12 +255,12 @@
* @param resource
* @return
*/
- protected boolean contains(IResource resource) {
+ protected boolean contains(String resourcePath) {
if(pathToModule == null) {
cacheModules();
}
- Object o = pathToModule.get(getPath(resource));
+ Object o = pathToModule.get(resourcePath);
return o == null ? false : true;
}
1.3 +12 -11 jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory/ArchiveModuleFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ArchiveModuleFactory.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory/ArchiveModuleFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ArchiveModuleFactory.java 10 Jul 2006 17:42:57 -0000 1.2
+++ ArchiveModuleFactory.java 18 Aug 2006 15:16:49 -0000 1.3
@@ -4,17 +4,15 @@
import java.io.IOException;
import java.util.jar.JarFile;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.internal.ModuleFactory;
import org.eclipse.wst.server.core.internal.ServerPlugin;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.client.verifiers.ArchiveVerifier;
-import org.jboss.ide.eclipse.as.core.util.ASDebug;
public class ArchiveModuleFactory extends JBossModuleFactory {
@@ -29,19 +27,20 @@
public void initialize() {
}
- protected IModule acceptAddition(IResource resource) {
- if( !supports(resource))
+ protected IModule acceptAddition(String path) {
+ if( !supports(path))
return null;
// otherwise create the module
- String path = getPath(resource);
- IModule module = createModule(path, resource.getName(),
- GENERIC_JAR, VERSION, resource.getProject());
+ //String path = getPath(resource);
+ String name = new Path(path).lastSegment();
+ IModule module = createModule(path, name,
+ GENERIC_JAR, VERSION, null);
ArchiveModuleDelegate delegate = new ArchiveModuleDelegate();
delegate.initialize(module);
- delegate.setResource(resource);
+ delegate.setResourcePath(path);
delegate.setFactory(this);
// and insert it
@@ -59,9 +58,10 @@
return new ArchiveVerifier(delegate);
}
- public boolean supports(IResource resource) {
+ public boolean supports(String path) {
try {
- File f = resource.getLocation().toFile();
+ //File f = resource.getLocation().toFile();
+ File f = new File(path);
JarFile jf = new JarFile(f);
return true;
} catch( IOException e ) {
@@ -89,4 +89,5 @@
}
+
}
1.5 +3 -8 jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory/JBossModuleDelegate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JBossModuleDelegate.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/module/factory/JBossModuleDelegate.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- JBossModuleDelegate.java 19 Jun 2006 17:44:35 -0000 1.4
+++ JBossModuleDelegate.java 18 Aug 2006 15:16:49 -0000 1.5
@@ -112,15 +112,10 @@
return segments[segments.length - 1];
}
- public void setResource(IResource resource) {
+ public void setResourcePath(String path) {
try {
- if( factory == null ) {
- this.resourcePath = resource.getLocation().toOSString();
- } else {
- this.resourcePath = factory.getPath(resource);
- }
- this.resourceURL = resource.getLocation().toFile().toURL();
- //ASDebug.p("added resource URL is " + resourceURL, this);
+ this.resourcePath = path;
+ this.resourceURL = new File(path).toURL();
} catch( Exception e ) {
}
}
More information about the jboss-cvs-commits
mailing list