[94617] Updated publish task
diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java
index 974246f..8b332da 100644
--- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java
+++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/PublishOperation2.java
@@ -19,8 +19,8 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.wst.server.core.IModule;
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.eclipse.wst.server.core.model.PublishOperation;
import org.eclipse.wst.server.core.util.ProjectModule;
@@ -43,15 +43,65 @@
}
public void execute(IProgressMonitor monitor, IAdaptable info) throws CoreException {
- //IModuleResourceDelta[] delta = server.getPublishedResourceDelta(new IModule[] { module });
- ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, monitor);
+ IModuleResourceDelta[] delta = server.getPublishedResourceDelta(new IModule[] { module });
IPath path = server.getTempDirectory();
path = path.append(module.getName());
- copy(pm.members(), path);
+
+ int size = delta.length;
+ for (int i = 0; i < size; i++) {
+ handleDelta(path, delta[i]);
+ }
+
+ ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, monitor);
+ IModuleResource[] mr = pm.members();
+ System.out.println(mr);
+ //copy(pm.members(), path);
}
- protected void copy(IModuleResource[] resources, IPath path) throws CoreException {
+ protected void handleDelta(IPath path, IModuleResourceDelta delta) throws CoreException {
+ IModuleResource resource = delta.getModuleResource();
+ int kind = delta.getKind();
+
+ if (resource instanceof IModuleFile) {
+ IModuleFile file = (IModuleFile) resource;
+ if (kind == IModuleResourceDelta.REMOVED)
+ deleteFile(path, file);
+ else
+ copyFile(path, file);
+ return;
+ }
+
+ if (kind == IModuleResourceDelta.ADDED) {
+ IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
+ path2.toFile().mkdirs();
+ } else if (kind == IModuleResourceDelta.REMOVED) {
+ IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
+ path2.toFile().delete();
+ }
+ IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
+ int size = childDeltas.length;
+ for (int i = 0; i < size; i++) {
+ handleDelta(path, childDeltas[i]);
+ }
+ }
+
+ protected void deleteFile(IPath path, IModuleFile file) {
+ IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
+ path2.toFile().delete();
+ }
+
+ protected void copyFile(IPath path, IModuleFile file) throws CoreException {
+ IFile file2 = (IFile) file.getAdapter(IFile.class);
+ IPath path3 = path.append(file.getModuleRelativePath()).append(file.getName());
+ File f = path3.toFile().getParentFile();
+ if (!f.exists())
+ f.mkdirs();
+ FileUtil.copyFile(file2.getContents(), path3.toOSString());
+ }
+
+
+ /*protected void copy(IModuleResource[] resources, IPath path) throws CoreException {
if (resources == null)
return;
@@ -74,5 +124,5 @@
f.mkdirs();
FileUtil.copyFile(file.getContents(), path3.toOSString());
}
- }
+ }*/
}
\ No newline at end of file