Author: rob.stryker(a)jboss.com
Date: 2007-10-16 21:13:54 -0400 (Tue, 16 Oct 2007)
New Revision: 4277
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java
Log:
Improved event logs for SingleFilePublisher ONLY.
JBIDE-1047
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java 2007-10-17
00:49:40 UTC (rev 4276)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java 2007-10-17
01:13:54 UTC (rev 4277)
@@ -9,25 +9,35 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
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.IServer;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.extensions.events.EventLogModel;
+import org.jboss.ide.eclipse.as.core.extensions.events.EventLogModel.EventLogTreeItem;
import
org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory.SingleDeployableModuleDelegate;
+import org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.CoppiedEvent;
+import org.jboss.ide.eclipse.as.core.publishers.PublisherEventLogger.DeletedEvent;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.core.util.FileUtil.IFileUtilListener;
public class SingleFilePublisher implements IJBossServerPublisher {
private IDeployableServer server;
- public SingleFilePublisher(IServer server) {
+ private EventLogTreeItem root;
+ private int publishState = IServer.PUBLISH_STATE_NONE;
+ public SingleFilePublisher(IServer server, EventLogTreeItem root) {
this.server = ServerConverter.getDeployableServer(server);
+ this.root = root;
}
public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
+ return publishState;
}
public IStatus publishModule(int kind, int deltaKind,
@@ -50,32 +60,37 @@
}
protected IStatus publish(IDeployableServer server, IModule module, int kind, int
deltaKind,
- int modulePublishState, boolean updateTimestamp, IProgressMonitor monitor) {
+ int modulePublishState, boolean updateTimestamp, IProgressMonitor monitor) throws
CoreException {
SingleDeployableModuleDelegate delegate =
(SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class,
new NullProgressMonitor());
if( delegate != null ) {
IPath sourcePath = delegate.getGlobalSourcePath();
IPath destFolder = new Path(server.getDeployDirectory());
File destFile = destFolder.append(sourcePath.lastSegment()).toFile();
- FileUtil.fileSafeCopy(sourcePath.toFile(), destFile);
+ FileUtilListener l = new FileUtilListener(root);
+ FileUtil.fileSafeCopy(sourcePath.toFile(), destFile, l);
if( updateTimestamp )
destFile.setLastModified(new Date().getTime());
+ if( l.errorFound ) publishState = IServer.PUBLISH_STATE_FULL;
} else {
- // deleted module. o noes.
- IPath destFolder = new Path(server.getDeployDirectory());
- IPath destFile = destFolder.append(new Path(module.getName()).lastSegment());
- destFile.toFile().delete();
+ // deleted module. o noes. Ignore it. We can't re-publish it, so just ignore it.
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"The module cannot be published because it cannot be located"));
}
return null;
}
- protected IStatus unpublish(IDeployableServer server, IModule module, int kind, int
deltaKind, int modulePublishState, IProgressMonitor monitor) {
+ protected IStatus unpublish(IDeployableServer server, IModule module, int kind, int
deltaKind, int modulePublishState, IProgressMonitor monitor) throws CoreException {
// delete file
SingleDeployableModuleDelegate delegate =
(SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class,
new NullProgressMonitor());
if( delegate != null ) {
IPath sourcePath = delegate.getGlobalSourcePath();
IPath destFolder = new Path(server.getDeployDirectory());
- FileUtil.safeDelete(destFolder.append(sourcePath.lastSegment()).toFile());
+ FileUtilListener l = new FileUtilListener(root);
+ FileUtil.safeDelete(destFolder.append(sourcePath.lastSegment()).toFile(), l);
+ if( l.errorFound ) {
+ publishState = IServer.PUBLISH_STATE_FULL;
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
"Unable to delete module from server.", new Exception("Some files were not
removed from the server")));
+ }
}
return null;
@@ -84,4 +99,33 @@
// ignore delta
}
+ public static class FileUtilListener implements IFileUtilListener {
+ protected EventLogTreeItem root;
+ protected boolean errorFound = false;
+ public FileUtilListener(EventLogTreeItem root) {
+ this.root = root;
+ }
+ public void fileCoppied(File source, File dest, boolean result,Exception e) {
+ if( result == false || e != null ) {
+ errorFound = true;
+ new CoppiedEvent(root, source, dest, result, e);
+ EventLogModel.markChanged(root);
+ }
+ }
+ public void fileDeleted(File file, boolean result, Exception e) {
+ if( result == false || e != null ) {
+ errorFound = true;
+ new DeletedEvent(root, file, result, e);
+ EventLogModel.markChanged(root);
+ }
+ }
+ public void folderDeleted(File file, boolean result, Exception e) {
+ if( result == false || e != null ) {
+ errorFound = true;
+ new DeletedEvent(root, file, result, e);
+ EventLogModel.markChanged(root);
+ }
+ }
+ };
+
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2007-10-17
00:49:40 UTC (rev 4276)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2007-10-17
01:13:54 UTC (rev 4277)
@@ -113,7 +113,7 @@
} else if( isPackagesTypeModule(lastMod) ) {
publisher = new PackagesPublisher(getServer(), root);
} else if( lastMod.getModuleType().getId().equals("jboss.singlefile")){
- publisher = new SingleFilePublisher(getServer());
+ publisher = new SingleFilePublisher(getServer(), root);
} else {
publisher = new NullPublisher();
}