Author: rob.stryker(a)jboss.com
Date: 2009-11-04 21:27:35 -0500 (Wed, 04 Nov 2009)
New Revision: 18412
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
Log:
JBIDE-5121 - finally just hacked and cleaved it
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java 2009-11-05
01:03:49 UTC (rev 18411)
+++
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java 2009-11-05
02:27:35 UTC (rev 18412)
@@ -10,9 +10,12 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.webtools.modules;
+import java.io.File;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -31,15 +34,13 @@
import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.model.ModuleFactoryDelegate;
import org.eclipse.wst.server.core.util.ModuleFile;
+import org.eclipse.wst.server.core.util.ModuleFolder;
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;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor;
import
org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension.FileWrapper;
import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
-import org.jboss.ide.eclipse.archives.core.util.PathUtils;
-import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
/**
*
@@ -172,212 +173,118 @@
return moduleContributor.getModuleDelegate(module);
}
- public static interface IExtendedModuleResource extends IModuleResource {
- public IPath getSourcePath();
- public IArchiveNode getNode();
- // deep destination is the full path this resource represents, even if it's inside
a jar
- public IPath getDeepDestination();
- // the concrete file this resource is part of... so the top most zipped jar or, if all
is exploded, the file itself
- public IPath getConcreteDestFile();
- }
-
public static class DelegateInitVisitor implements IArchiveNodeVisitor {
private IArchive pack;
- private HashMap<IArchiveNode, ArchiveContainerResource> members; // node ->
imoduleresource
+ private HashMap<IArchiveNode, IModuleResource> members; // node ->
imoduleresource
private HashMap<IPath, IArchiveNode> pathToNode; // path -> node
public DelegateInitVisitor(IArchive pack) {
this.pack = pack;
reset();
}
public void reset() {
- members = new HashMap<IArchiveNode, ArchiveContainerResource>();
+ members = new HashMap<IArchiveNode, IModuleResource>();
pathToNode = new HashMap<IPath, IArchiveNode>();
}
- public boolean visit(IArchiveNode node) {
- int type = node.getNodeType();
- // not sure why this is giving wrong values but it seems to go deep into IArchive
code
- IPath rootRelative = node.getRootArchiveRelativePath().removeFirstSegments(1);
- if( type == IArchiveNode.TYPE_ARCHIVE && ((IArchive)node).isTopLevel()) {
- members.put(node, new ArchiveContainerResource(((IArchive)node).getName(), node,
rootRelative));
- pathToNode.put(rootRelative, node);
- } else if( type == IArchiveNode.TYPE_ARCHIVE || type ==
IArchiveNode.TYPE_ARCHIVE_FOLDER) {
- String name = type == IArchiveNode.TYPE_ARCHIVE ? ((IArchive)node).getName() :
((IArchiveFolder)node).getName();
- // if we're any other archive or a folder, create us and add to parent
- IArchiveNode parent = node.getParent();
- ArchiveContainerResource parentAsResource = members.get(parent);
- members.put(node, new ArchiveContainerResource(name, node, rootRelative));
- pathToNode.put(rootRelative, node);
- parentAsResource.addChild(members.get(node));
- } else if( type == IArchiveNode.TYPE_ARCHIVE_FILESET ) {
- ArchiveContainerResource parentAsResource = members.get(node.getParent());
- parentAsResource.addFilesetAsChild((IArchiveFileSet)node);
- }
-
- return true;
- }
-
- public IModuleResource getRootResource() {
- return members.get(pack);
- }
-
- public IModuleResource getResourceForNode(IArchiveNode node) {
- return members.get(node);
- }
- }
-
- public static class ArchiveContainerResource implements IModuleFolder,
IExtendedModuleResource {
-
- protected IPath moduleRelativePath;
- protected IPath fsRelative;
- protected IArchiveNode node;
- protected String name;
- private HashMap<IPath, IModuleResource> members;
-
- // represents source folder on disk. only used if node is fileset
-// private IPath folderGlobalPath = null;
- public ArchiveContainerResource(String name,IArchiveNode node,IPath moduleRelativePath
) {
- this.name = name;
- this.node = node;
- this.moduleRelativePath = moduleRelativePath;
- members = new HashMap<IPath, IModuleResource>();
- if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET ) {
- fsRelative =
moduleRelativePath.removeFirstSegments(node.getParent().getRootArchiveRelativePath().removeFirstSegments(1).segmentCount());
- }
- }
-
- public int hashCode() {
- return name.hashCode() * 37 + moduleRelativePath.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other instanceof IModuleFolder) {
- IModuleFolder resource = (IModuleFolder) other;
- return resource.getModuleRelativePath().equals(getModuleRelativePath());
- }
+
+ protected boolean addZippedPackage(IArchiveNode node) {
+ IPath pathWithName = node.getRootArchiveRelativePath().removeFirstSegments(1);
+ IPath path = pathWithName;
+ if( path.segmentCount() > 0 )
+ path = path.removeLastSegments(1);
+ File root = ModelUtil.getBaseDestinationFile(node).toFile();
+ IModuleFile mf = new ModuleFile(root, root.getName(), path);
+ members.put(node, mf);
+ pathToNode.put(pathWithName, node);
+ if( node.getRootArchive() != node )
+ ((PackagesModuleFolder)members.get(node.getParent())).addChild(mf);
return false;
}
-
- public void addChild(IModuleResource resource) {
- members.put(resource.getModuleRelativePath(), resource);
+
+ protected boolean addFolder(IArchiveNode node) {
+ IPath pathWithName = node.getRootArchiveRelativePath().removeFirstSegments(1);
+ IPath path = pathWithName;
+ if( path.segmentCount() > 0 )
+ path = path.removeLastSegments(1);
+ File root = ModelUtil.getBaseDestinationFile(node).toFile();
+ PackagesModuleFolder mf = new PackagesModuleFolder(root, root.getName(), path);
+ members.put(node, mf);
+ pathToNode.put(pathWithName, node);
+ if( node.getRootArchive() != node )
+ ((PackagesModuleFolder)members.get(node.getParent())).addChild(mf);
+ return true;
}
-
- public void removeChild(IPath moduleRelativePath) {
- members.remove(moduleRelativePath);
- }
- public IModuleResource getChild(IPath path) {
- return members.get(path);
- }
-
- public void addFilesetAsChild(IArchiveFileSet fs) {
+
+ public boolean addFilesetAsChild(IArchiveFileSet fs) {
FileWrapper[] files = fs.findMatchingPaths(); // file-system based source paths
if( files != null ) {
for( int i = 0; i < files.length; i++ ) {
addFilesetPathAsChild(fs, files[i]);
}
}
+ return true;
}
public void addFilesetPathAsChild(IArchiveFileSet fs, FileWrapper file) {
IPath fsRelative = new Path(file.getFilesetRelative());
- ArchiveContainerResource parent = find(fs, fsRelative.removeLastSegments(1), true);
- ExtendedModuleFile emf = new ExtendedModuleFile(file, fs);
- parent.addChild(emf);
+ IPath path =
fs.getRootArchiveRelativePath().removeFirstSegments(1).append(fsRelative);
+ PackagesModuleFolder parent = find(fs, fsRelative.removeLastSegments(1), true);
+ IModuleFile mf = new ModuleFile(file, file.getName(), path.removeLastSegments(1));
+ parent.addChild(mf);
}
- protected ArchiveContainerResource find(IArchiveFileSet fs, IPath fsRelative, boolean
create) {
- ArchiveContainerResource resource = this;
- ArchiveContainerResource tmpResource;
+ protected PackagesModuleFolder find(IArchiveFileSet fs, IPath fsRelative, boolean
create) {
+ PackagesModuleFolder folder = (PackagesModuleFolder)members.get(fs.getParent());
+ IPath folderPathWithName = folder.getModuleRelativePath().append(folder.getName());
+
+ PackagesModuleFolder tmpFolder;
IPath tmpPath = fs.getRootArchiveRelativePath().removeFirstSegments(1);
int count = fsRelative.segmentCount();
for( int i = 0; i < count; i++ ) {
tmpPath = tmpPath.append(fsRelative.segment(i));
- tmpResource = (ArchiveContainerResource)resource.getChild(tmpPath);
- if( tmpResource == null ) {
+ tmpFolder = (PackagesModuleFolder)folder.getChild(fsRelative.segment(i));
+ if( tmpFolder == null ) {
if( !create )
return null;
- tmpResource = new ArchiveContainerResource(tmpPath.lastSegment(), fs, tmpPath);
- resource.addChild(tmpResource);
+ tmpFolder = new PackagesModuleFolder(null, tmpPath.lastSegment(),
tmpPath.removeLastSegments(1));
+ folder.addChild(tmpFolder);
}
- resource = tmpResource;
+ folder = tmpFolder;
}
- return resource;
+ return folder;
}
-
- public IModuleResource[] members() {
- Collection<IModuleResource> c = members.values();
- return c.toArray(new IModuleResource[c.size()]);
+
+ public boolean visit(IArchiveNode node) {
+ try {
+ if( node == pack ) // we're at the root
+ if( !pack.isExploded())
+ return addZippedPackage(pack);
+
+ int type = node.getNodeType();
+ if( type == IArchiveNode.TYPE_ARCHIVE && !((IArchive)node).isExploded())
+ return addZippedPackage(node);
+
+ if( type == IArchiveNode.TYPE_ARCHIVE || type == IArchiveNode.TYPE_ARCHIVE_FOLDER)
+ return addFolder(node);
+
+ if( type == IArchiveNode.TYPE_ARCHIVE_FILESET )
+ return addFilesetAsChild((IArchiveFileSet)node);
+ } catch( Exception e) {
+ e.printStackTrace();
+ }
+ return true;
}
- public IPath getModuleRelativePath() {
- return moduleRelativePath;
+ public IModuleResource getRootResource() {
+ return members.get(pack);
}
- public String getName() {
- return name;
+ public IModuleResource getResourceForNode(IArchiveNode node) {
+ return members.get(node);
}
-
- public Object getAdapter(Class adapter) {
- return null;
- }
-
- public IPath getDeepDestination() {
- IPath tmp = node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET
- ? moduleRelativePath : node.getRootArchiveRelativePath();
- return PathUtils.getGlobalLocation(node.getRootArchive()).append(tmp);
- }
-
- public IPath getConcreteDestFile() {
- if( node.getNodeType() == IArchiveNode.TYPE_ARCHIVE_FILESET )
- return ModelUtil.getBaseDestinationFile((IArchiveFileSet)node,fsRelative);
- else
- return ModelUtil.getBaseDestinationFile((IArchiveFileSet)node);
- }
- public IArchiveNode getNode() {
- return node;
- }
-
- public IPath getSourcePath() {
- return null;
- }
-
}
- public static class ExtendedModuleFile extends ModuleFile implements
IExtendedModuleResource {
- private FileWrapper wrapper;
- private IArchiveFileSet node;
- public ExtendedModuleFile(FileWrapper wrapper, IArchiveFileSet fs) {
- super(wrapper.getOutputName(), wrapper.getRootArchiveRelative(),
wrapper.lastModified());
- this.node = fs;
- this.wrapper = wrapper;
- }
- public int hashCode() {
- return getName().hashCode() * 37 + getPath().hashCode();
- }
- public IPath getPath() { return new Path(wrapper.getAbsolutePath()); }
- public IArchiveNode getNode() { return node; }
- public IPath getDeepDestination() {
- return
PathUtils.getGlobalLocation(node.getRootArchive()).append(wrapper.getRootArchiveRelative());
- }
- public IPath getSourcePath() {
- return new Path(this.wrapper.getAbsolutePath());
- }
-
- public IPath getConcreteDestFile() {
- return ModelUtil.getBaseDestinationFile(node, new
Path(this.wrapper.getFilesetRelative()));
- }
-
- public boolean equals(Object other) {
- if (other instanceof IModuleFile) {
- IModuleFile resource = (IModuleFile) other;
- return resource.getModuleRelativePath().equals(getModuleRelativePath());
- }
- return false;
- }
-
- }
-
public static class PackagedModuleDelegate extends ModuleDelegate {
private IArchive pack;
private IModuleResource rootResource;
@@ -402,6 +309,8 @@
public IModuleResource[] members() throws CoreException {
init();
+ if( !pack.isExploded() )
+ return new IModuleResource[] { rootResource };
return ((IModuleFolder)rootResource).members();
}
@@ -409,5 +318,31 @@
return Status.OK_STATUS;
}
}
-
+
+ public static class PackagesModuleFolder extends ModuleFolder {
+ private File file;
+ private HashMap<String, IModuleResource> children = new HashMap<String,
IModuleResource>();
+ public PackagesModuleFolder(File f, String name, IPath path) {
+ super(null, name, path);
+ this.file = f;
+ }
+ public Object getAdapter(Class cl) {
+ if( File.class.equals(cl))
+ return file;
+ return null;
+ }
+
+ public void addChild(IModuleResource resource) {
+ children.put(resource.getName(), resource);
+ Collection<IModuleResource> l = children.values();
+ setMembers((IModuleResource[]) l.toArray(new IModuleResource[l.size()]));
+ }
+
+ public PackagesModuleFolder getChild(String name) {
+ Object o = children.get(name);
+ if( o != null && o instanceof PackagesModuleFolder)
+ return (PackagesModuleFolder)o;
+ return null;
+ }
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2009-11-05
01:03:49 UTC (rev 18411)
+++
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2009-11-05
02:27:35 UTC (rev 18412)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.webtools.modules;
+import java.io.File;
import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
@@ -22,16 +23,12 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.model.IModuleFile;
-import org.eclipse.wst.server.core.model.IModuleFolder;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.util.PathUtils;
import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
import org.jboss.ide.eclipse.archives.webtools.Messages;
-import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.ExtendedModuleFile;
-import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.IExtendedModuleResource;
import
org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
@@ -131,11 +128,13 @@
return;
}
- if( incremental ) {
- publishFromDelta(module, destPathRoot, sourcePath.removeLastSegments(1), delta);
- } else {
+ if( !incremental || !pack.isExploded() ) { // full publish, or zipped
// full publish, copy whole folder or file
FileUtil.fileSafeCopy(sourcePath.toFile(), destPathRoot.toFile(), listener);
+ } else if( destPathRoot.toFile().exists() && destPathRoot.toFile().isFile()) {
+ FileUtil.fileSafeCopy(sourcePath.toFile(), destPathRoot.toFile(), listener);
+ } else {
+ publishFromDelta(module, destPathRoot, sourcePath.removeLastSegments(1), delta);
}
}
@@ -149,63 +148,22 @@
protected void publishFromDeltaHandle(IModuleResourceDelta delta, IPath destRoot,
IPath sourcePrefix, ArrayList<IPath> changedFiles) {
- switch( delta.getKind()) {
- case IModuleResourceDelta.REMOVED:
- // removed might not be IExtendedModuleResource
- IModuleResource imr = delta.getModuleResource();
- if( imr instanceof IExtendedModuleResource) {
- IExtendedModuleResource emr = ((IExtendedModuleResource)imr);
- IPath concrete = emr.getConcreteDestFile();
- if( !changedFiles.contains(concrete)) {
- IPath destPath =
destRoot.append(concrete.removeFirstSegments(sourcePrefix.segmentCount()));
-
- // file hasnt been updated yet.
- // But we don't know whether to delete or copy this file.
- // depends where it is in the tree and what's exploded.
- changedFiles.add(concrete);
- IPath concreteRelative =
concrete.removeFirstSegments(sourcePrefix.segmentCount()).setDevice(null);
- IPath emrModRelative = emr.getModuleRelativePath();
- boolean delete = concreteRelative.equals(emrModRelative);
-
- if( delete ) {
- FileUtil.safeDelete(destPath.toFile(), listener);
- } else {
- // copy
- FileUtil.fileSafeCopy(concrete.toFile(), destPath.toFile(), listener);
- }
- }
+ IModuleResource imr = delta.getModuleResource();
+ File f = (File)imr.getAdapter(File.class);
+ if( f != null ) {
+ IPath destPath = destRoot.append(imr.getModuleRelativePath()).append(imr.getName());
+ switch( delta.getKind()) {
+ case IModuleResourceDelta.REMOVED:
+ FileUtil.safeDelete(destPath.toFile(), listener);
return;
- } else {
- // TODO
+ case IModuleResourceDelta.ADDED:
+ FileUtil.fileSafeCopy(f, destPath.toFile(), listener);
return;
+ case IModuleResourceDelta.CHANGED:
+ FileUtil.fileSafeCopy(f, destPath.toFile(), listener);
+ break;
}
- case IModuleResourceDelta.ADDED:
- imr = delta.getModuleResource();
- if( imr instanceof IExtendedModuleResource) {
- IPath concrete = ((IExtendedModuleResource)imr).getConcreteDestFile();
- if( !changedFiles.contains(concrete)) {
- changedFiles.add(concrete);
- IPath destPath =
destRoot.append(concrete.removeFirstSegments(sourcePrefix.segmentCount()));
- FileUtil.fileSafeCopy(concrete.toFile(), destPath.toFile(), listener);
- }
- return;
- } else {
- // TODO
- return;
- }
- case IModuleResourceDelta.CHANGED:
- imr = delta.getModuleResource();
- if( imr instanceof ExtendedModuleFile ) {
- IPath concrete = ((ExtendedModuleFile)imr).getConcreteDestFile();
- if( !changedFiles.contains(concrete)) {
- IPath destPath =
destRoot.append(concrete.removeFirstSegments(sourcePrefix.segmentCount()+1));
- FileUtil.fileSafeCopy(concrete.toFile(), destPath.toFile(), listener);
- changedFiles.add(concrete);
- }
- }
- break;
}
-
IModuleResourceDelta[] children = delta.getAffectedChildren();
if( children != null ) {
for( int i = 0; i < children.length; i++ ) {