Author: rob.stryker(a)jboss.com
Date: 2007-06-21 15:59:55 -0400 (Thu, 21 Jun 2007)
New Revision: 2155
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesModelModuleContributor.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesBuildListener.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/PackageModuleFactory.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
Log:
committing to test compatibility with eclipse 3.3. no guarantee any of these changes work
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesBuildListener.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesBuildListener.java 2007-06-21
16:10:17 UTC (rev 2154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesBuildListener.java 2007-06-21
19:59:55 UTC (rev 2155)
@@ -192,7 +192,7 @@
else
p = delta.getPreNode().getProjectPath();
- PackageModuleFactory.getFactory().refreshProject(p);
+ ArchivesModelModuleContributor.getInstance().refreshProject(p);
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesModelModuleContributor.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesModelModuleContributor.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ArchivesModelModuleContributor.java 2007-06-21
19:59:55 UTC (rev 2155)
@@ -0,0 +1,129 @@
+package org.jboss.ide.eclipse.as.core.packages;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModelCore;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.as.core.packages.PackageModuleFactory.IModuleContributor;
+import
org.jboss.ide.eclipse.as.core.packages.PackageModuleFactory.PackagedModuleDelegate;
+
+public class ArchivesModelModuleContributor implements IModuleContributor {
+
+ private static ArchivesModelModuleContributor instance;
+ public static ArchivesModelModuleContributor getInstance() {
+ if( instance == null ) {
+ instance = new ArchivesModelModuleContributor(PackageModuleFactory.getFactory());
+ }
+ return instance;
+ }
+
+ private PackageModuleFactory factory;
+ protected ArrayList modules = null;
+ protected HashMap projectToModules = new HashMap(5); //IPath to IModule
+ protected HashMap moduleDelegates = new HashMap(5);
+ protected HashMap packageToModule = new HashMap(5);
+
+ private ArchivesModelModuleContributor(PackageModuleFactory factory) {
+ this.factory = factory;
+ }
+
+ public IModule[] getModules() {
+ if( modules == null ) {
+ modules = new ArrayList();
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int size = projects2.length;
+ for (int i = 0; i < size; i++) {
+ if (projects2[i].isAccessible()) {
+ createModules(projects2[i]);
+ }
+ }
+ }
+ return (IModule[]) modules.toArray(new IModule[modules.size()]);
+ }
+
+ protected void createModules(IProject project) {
+ try {
+ if( ArchivesModelCore.getProjectPackages(project.getLocation(), null, true).length
> 0 ) {
+ IModule module;
+ IArchive[] packages = ArchivesModelCore.getProjectPackages(project.getLocation(), new
NullProgressMonitor(), true);
+ boolean requiresSave = ensureArchivesHaveIDs(project, packages);
+ ArrayList mods = new ArrayList();
+ for( int i = 0; i < packages.length; i++ ) {
+ module = factory.createModule2(packages[i], project);
+ modules.add(module);
+ Object moduleDelegate = new PackagedModuleDelegate(packages[i]);
+ packageToModule.put(packages[i], module);
+ moduleDelegates.put(module, moduleDelegate);
+ mods.add(module);
+ }
+ projectToModules.put(project.getLocation(), mods);
+ }
+ } catch( Throwable t ) {
+ t.printStackTrace();
+ }
+ }
+
+ public boolean containsModule(IModule module) {
+ return moduleDelegates.containsKey(module);
+ }
+
+ public PackagedModuleDelegate getModuleDelegate(IModule module) {
+ return (PackagedModuleDelegate)moduleDelegates.get(module);
+ }
+
+ public void refreshProject(IPath projectLoc) {
+ // remove old mods
+ ArrayList mods = (ArrayList)projectToModules.get(projectLoc);
+ IModule mod;
+ IArchive arc;
+ for( Iterator i = mods.iterator(); i.hasNext();) {
+ mod = (IModule)i.next();
+ arc = ((PackagedModuleDelegate)moduleDelegates.get(mod)).getPackage();
+ packageToModule.remove(arc);
+ moduleDelegates.remove(mod);
+ }
+ createModules(findProject(projectLoc));
+ factory.clearModuleCache();
+ }
+
+ protected IProject findProject(IPath projectLoc) {
+ IProject proj = null;
+ IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ int size = projects2.length;
+ for (int i = 0; i < size; i++) {
+ if( projects2[i].getLocation().equals(projectLoc))
+ proj = projects2[i];
+ }
+ return proj;
+ }
+
+ /**
+ * Set a property so that each module that's here in the factory
+ * has a unique ID other than it's name (which is not unique)
+ * @param archives
+ * @return returns whether a save has occurred
+ */
+ protected boolean ensureArchivesHaveIDs(IProject project, IArchive[] archives) {
+ boolean requiresSave = false;
+ for( int i = 0; i < archives.length; i++ ) {
+ if( PackageModuleFactory.getID(archives[i]) == null ) {
+ requiresSave = true;
+ archives[i].setProperty(PackageModuleFactory.MODULE_ID_PROPERTY_KEY,
+ PackageModuleFactory.getID(archives[i], true));
+ }
+ }
+ if( requiresSave ) {
+ // save
+ ArchivesModel.instance().saveModel(project.getLocation(), new NullProgressMonitor());
+ }
+ return requiresSave;
+ }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/PackageModuleFactory.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/PackageModuleFactory.java 2007-06-21
16:10:17 UTC (rev 2154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/PackageModuleFactory.java 2007-06-21
19:59:55 UTC (rev 2155)
@@ -22,6 +22,7 @@
package org.jboss.ide.eclipse.as.core.packages;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -43,8 +44,6 @@
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.model.ModuleFactoryDelegate;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
-import org.jboss.ide.eclipse.archives.core.model.ArchivesModelCore;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFileSet;
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
@@ -73,19 +72,21 @@
private static PackageModuleFactory factDelegate;
private static ModuleFactory factory;
+ /**
+ * Find the module factory wrapper WTP provides for us
+ * @return
+ */
public static PackageModuleFactory getFactory() {
if( factDelegate == null ) {
- // find them
ModuleFactory[] factories = ServerPlugin.getModuleFactories();
- search:
for( int i = 0; i < factories.length; i++ ) {
if( factories[i].getId().equals(PackageModuleFactory.FACTORY_TYPE_ID)) {
Object o = factories[i].getDelegate(new NullProgressMonitor());
if( o instanceof PackageModuleFactory ) {
factory = factories[i];
factDelegate = (PackageModuleFactory)o;
- break search;
+ return factDelegate;
}
}
}
@@ -93,9 +94,23 @@
return factDelegate;
}
+ /**
+ * Get the module ID of this IArchive if it exists.
+ * Do not create a new one otherwise
+ * @param pack
+ * @return
+ */
public static String getID(IArchive pack) {
return getID(pack, false);
}
+
+ /**
+ * Get the module ID of this IArchive if it exists.
+ * If create is true, and the ID is not set, set a default ID.
+ * @param pack
+ * @param create
+ * @return
+ */
protected static String getID(IArchive pack, boolean create) {
String propVal = pack.getProperty(MODULE_ID_PROPERTY_KEY);
if( propVal == null && create ) {
@@ -116,6 +131,12 @@
}
return propVal;
}
+
+ /**
+ * Return the name of the project in the workspace
+ * @param node
+ * @return
+ */
public static String getProjectName(IArchiveNode node) {
IPath projPath = node.getProjectPath();
if( projPath == null ) return null;
@@ -125,130 +146,50 @@
return list[i].getName();
return null;
}
+
+ /**
+ * Get the visible name of this module
+ * @param pack
+ * @return
+ */
public static String getName(IArchive pack) {
- String projName = getProjectName(pack);
- return projName + "/" + pack.getName();
+ return getProjectName(pack) + "/" + pack.getName();
}
- /*
- * The beginning of the class. Finally!
- */
-
-
-
-
-
- protected HashMap moduleDelegates = new HashMap(5);
- protected HashMap packageToModule = new HashMap(5);
- protected HashMap projectToPackages = new HashMap(5);
+ protected IModuleContributor[] moduleContributors;
public PackageModuleFactory() {
super();
+ moduleContributors = new IModuleContributor[] {
ArchivesModelModuleContributor.getInstance() };
+
}
- /**
- * Set a property so that each module that's here in the factory
- * has a unique ID other than it's name (which is not unique)
- * @param archives
- * @return returns whether a save has occurred
- */
- protected boolean ensureArchivesHaveIDs(IProject project, IArchive[] archives) {
- boolean requiresSave = false;
- for( int i = 0; i < archives.length; i++ ) {
- if( getID(archives[i]) == null ) {
- requiresSave = true;
- archives[i].setProperty(MODULE_ID_PROPERTY_KEY, getID(archives[i], true));
- }
- }
- if( requiresSave ) {
- // save
- ArchivesModel.instance().saveModel(project.getLocation(), new NullProgressMonitor());
- }
- return requiresSave;
+ protected IModule createModule2(IArchive pack, IProject project) {
+ return createModule(getID(pack), getName(pack), MODULE_TYPE, VERSION, project);
}
-
- /**
- * Create and return the modules for a given IProject
- * @param project The project which has the modules
- * @return The modules that the project has
- */
- protected IModule[] createModules(IProject project) {
- try {
- if( ArchivesModelCore.getProjectPackages(project.getLocation(), null, true).length
> 0 ) {
- ArrayList list = new ArrayList();
- IModule module;
- IArchive[] packages = ArchivesModelCore.getProjectPackages(project.getLocation(), new
NullProgressMonitor(), true);
- boolean saved = ensureArchivesHaveIDs(project, packages);
- for( int i = 0; i < packages.length; i++ ) {
- module = createModule(getID(packages[i]), getName(packages[i]),
- MODULE_TYPE, VERSION, project);
- list.add(module);
- Object moduleDelegate = new PackagedModuleDelegate(packages[i]);
- moduleDelegates.put(module, moduleDelegate);
- packageToModule.put(packages[i], module);
- }
- projectToPackages.put(project, packages);
- return (IModule[]) list.toArray(new IModule[list.size()]);
- }
- } catch( Throwable t ) {
- t.printStackTrace();
+ public IModule[] getModules() {
+ ArrayList list = new ArrayList();
+ for( int i = 0; i < moduleContributors.length; i++ ) {
+ list.addAll(Arrays.asList(moduleContributors[i].getModules()));
}
- return new IModule[]{};
+ return (IModule[]) list.toArray(new IModule[list.size()]);
}
-
- public ModuleDelegate getModuleDelegate(IModule module) {
- return (ModuleDelegate) moduleDelegates.get(module);
- }
-
- public IModule getModuleFromPackage(IArchive pack) {
- return (IModule)packageToModule.get(pack);
- }
-
- private static boolean initiated = false;
- public IModule[] getModules() {
- if( !initiated )
- init();
- Collection c = packageToModule.values();
- return (IModule[]) c.toArray(new IModule[c.size()]);
- }
- protected void init() {
- IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- int size = projects2.length;
- for (int i = 0; i < size; i++) {
- if (projects2[i].isAccessible()) {
- createModules(projects2[i]);
- }
+ public ModuleDelegate getModuleDelegate(IModule module) {
+ for( int i = 0; i < moduleContributors.length; i++ ) {
+ if( moduleContributors[i].containsModule(module))
+ return moduleContributors[i].getModuleDelegate(module);
}
+ return null;
}
-
- public void refreshProject(IPath projectLoc) {
- IProject proj = null;
- IProject[] projects2 = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- int size = projects2.length;
- for (int i = 0; i < size; i++) {
- if( projects2[i].getLocation().equals(projectLoc))
- proj = projects2[i];
- }
- if( proj != null ) {
- IArchive[] archives = (IArchive[])projectToPackages.get(proj);
- IModule mod;
- projectToPackages.remove(proj);
- if( archives != null ) {
- for( int i = 0; i < archives.length; i++ ) {
- mod = (IModule)packageToModule.get(archives[i]);
- packageToModule.remove(archives[i]);
- moduleDelegates.remove(mod);
- }
- }
- createModules(proj);
- System.out.println("clearing cache");
- clearModuleCache();
- }
+ public static interface IModuleContributor {
+ public IModule[] getModules();
+ public boolean containsModule(IModule module);
+ public PackagedModuleDelegate getModuleDelegate(IModule module);
}
public static interface IExtendedModuleResource extends IModuleResource {
@@ -258,7 +199,7 @@
public IPath getConcreteDestFile();
}
- public class DelegateInitVisitor implements IArchiveNodeVisitor {
+ public static class DelegateInitVisitor implements IArchiveNodeVisitor {
private IArchive pack;
private HashMap members; // node -> imoduleresource
@@ -303,7 +244,7 @@
}
}
- public class ArchiveContainerResource implements IModuleFolder, IExtendedModuleResource
{
+ public static class ArchiveContainerResource implements IModuleFolder,
IExtendedModuleResource {
protected IPath moduleRelativePath;
protected IArchiveNode node;
@@ -363,7 +304,6 @@
}
public void removeFilesetPathAsChild(IArchiveFileSet fs, IPath path) {
- IPath archiveRelative = fs.getRootArchiveRelativePath(path);
IPath globalSource = fs.getGlobalSourcePath();
IPath fsRelative = path.removeFirstSegments(globalSource.segmentCount());
ArchiveContainerResource parent = find(fs, globalSource,
fsRelative.removeLastSegments(1), false);
@@ -425,7 +365,7 @@
}
- public class ExtendedModuleFile extends ModuleFile implements IExtendedModuleResource {
+ public static class ExtendedModuleFile extends ModuleFile implements
IExtendedModuleResource {
private IPath srcPath;
private IArchiveFileSet node;
public ExtendedModuleFile(String name, IPath relativePath, long stamp,
@@ -461,8 +401,7 @@
}
-
- public class PackagedModuleDelegate extends ModuleDelegate {
+ public static class PackagedModuleDelegate extends ModuleDelegate {
private IArchive pack;
private IModuleResource rootResource;
private DelegateInitVisitor initVisitor;
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/packages/ProjectArchiveStorer.java 2007-06-21
19:59:55 UTC (rev 2155)
@@ -0,0 +1,55 @@
+package org.jboss.ide.eclipse.as.core.packages;
+
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+
+
+public class ProjectArchiveStorer {
+ public static final String JST_ARCHIVE_CONFIGURATION =
"jst.archive.configuration";
+ private static HashMap cache = new HashMap();
+
+ public static IArchive getArchiveFor(IProject project) {
+ if( cache.containsKey(project))
+ return (IArchive)cache.get(project);
+ return loadArchiveFrom(project);
+ }
+
+ public static IArchive loadArchiveFrom(IProject project) {
+ try {
+ String s = project.getPersistentProperty(new
QualifiedName(JBossServerCorePlugin.PLUGIN_ID, JST_ARCHIVE_CONFIGURATION));
+ if( s != null ) {
+ XbPackages packs = XMLBinding.unmarshal(s, new NullProgressMonitor());
+ if( packs != null && packs.getAllChildren().size() == 1 ) {
+ XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
+ IArchive node = (IArchive)ArchivesModel.createPackageNodeImpl(project.getLocation(),
pack, null);
+ if( node != null ) {
+ cache.put(project, node);
+ }
+ }
+ }
+ } catch( CoreException ce ) {
+ ce.printStackTrace();
+ }
+ return (IArchive)cache.get(project);
+ }
+
+ public static void storeArchive(IProject project, IArchive archive) {
+ try {
+ String s = XMLBinding.marshall(archive, new NullProgressMonitor());
+ if( s != null )
+ project.setPersistentProperty(new QualifiedName(JBossServerCorePlugin.PLUGIN_ID,
JST_ARCHIVE_CONFIGURATION), s);
+ } catch( CoreException ce) {
+ ce.printStackTrace();
+ }
+ }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2007-06-21
16:10:17 UTC (rev 2154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2007-06-21
19:59:55 UTC (rev 2155)
@@ -27,6 +27,7 @@
import java.util.TreeSet;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -46,6 +47,7 @@
import org.jboss.ide.eclipse.as.core.model.EventLogModel;
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
import org.jboss.ide.eclipse.as.core.packages.ModulePackageTypeConverter;
+import org.jboss.ide.eclipse.as.core.packages.ProjectArchiveStorer;
import org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.PublishEvent;
import
org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.PublisherFileUtilListener;
import org.jboss.ide.eclipse.as.core.server.attributes.IDeployableServer;
@@ -96,7 +98,7 @@
EventLogModel.markChanged(eventRoot);
boolean incremental = shouldPublishIncremental(module, kind, deltaKind,
modulePublishState);
- IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), incremental,
monitor);
+ IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), monitor);
if( topLevel != null ) {
@@ -122,7 +124,7 @@
int kind, int deltaKind, int modulePublishKind, IProgressMonitor monitor) throws
CoreException {
PublishEvent event = PublisherEventLogger.createSingleModuleTopEvent(eventRoot, module,
kind, deltaKind);
- IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), false,
monitor);
+ IArchive topLevel = getTopPackage(module, jbServer.getDeployDirectory(), monitor);
if( topLevel != null ) {
IPath path = topLevel.getArchiveFilePath();
FileUtil.safeDelete(path.toFile(), new PublisherFileUtilListener(event));
@@ -135,14 +137,21 @@
}
- protected IArchive getTopPackage(IModule module, String deployDir,
- boolean incremental, IProgressMonitor monitor) {
- if( !moduleToArchiveMap.containsKey(module.getId()) || !incremental) {
- IArchive top = createTopPackage(module, deployDir, monitor);
- if( top != null )
+ protected IArchive getTopPackage(IModule module, String deployDir, IProgressMonitor
monitor) {
+ if( moduleToArchiveMap.containsKey(module.getId())) {
+ return (IArchive)moduleToArchiveMap.get(module.getId());
+ }
+
+ IProject project = module.getProject();
+ IArchive top = ProjectArchiveStorer.getArchiveFor(project);
+ if( top == null ) {
+ top = createTopPackage(module, deployDir, monitor);
+ if( top != null ) {
+ ProjectArchiveStorer.storeArchive(project, top);
moduleToArchiveMap.put(module.getId(), top);
+ }
}
- return (IArchive)moduleToArchiveMap.get(module.getId());
+ return top;
}
protected IArchive createTopPackage(IModule module, String deployDir, IProgressMonitor
monitor) {