Author: rob.stryker(a)jboss.com
Date: 2009-10-23 17:10:47 -0400 (Fri, 23 Oct 2009)
New Revision: 18272
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java
Log:
Some progress monitor cleanup
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2009-10-23
20:27:20 UTC (rev 18271)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2009-10-23
21:10:47 UTC (rev 18272)
@@ -65,7 +65,7 @@
* @param mf
* @param path
* @param monitor
- * @return
+ * @return a list of error status objects.
* @throws CoreException
*/
public IStatus[] copyFile(IModuleFile mf, IPath path, IProgressMonitor monitor) throws
CoreException;
@@ -78,9 +78,9 @@
*
* @param dir
* @param monitor
- * @return
+ * @return a list of error status objects.
*/
- public IStatus[] deleteResource(IPath path, IProgressMonitor monitor);
+ public IStatus[] deleteResource(IPath path, IProgressMonitor monitor) throws
CoreException ;
/**
* Make a directory for this path relative to where the module belongs.
@@ -89,9 +89,9 @@
*
* @param dir
* @param monitor
- * @return
+ * @return a list of error status objects.
*/
- public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor);
+ public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor) throws
CoreException;
}
public static class LocalCopyCallback implements IPublishCopyCallbackHandler {
@@ -111,19 +111,20 @@
}
public IStatus[] copyFile(IModuleFile mf, IPath relativePath, IProgressMonitor monitor)
throws CoreException {
- //Trace.trace(Trace.PUBLISHING, "Copying: " + mf.getName() + " to
" + path.toString());
File file = PublishUtil.getFile(mf);
if( file != null ) {
InputStream in = null;
try {
in = new FileInputStream(file);
} catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0,
- NLS.bind(Messages.errorReading, file.getAbsolutePath()), e));
+ return new IStatus[] {new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0,
+ NLS.bind(Messages.errorReading, file.getAbsolutePath()), e)};
}
- copyFile(in, deployRootFolder.append(relativePath), file.lastModified(), mf);
+ IStatus ret = copyFile(in, deployRootFolder.append(relativePath),
file.lastModified(), mf);
+ if( ret != null && ret.isOK())
+ return new IStatus[] { ret };
} // else silently ignore I guess
- return new IStatus[]{Status.OK_STATUS};
+ return new IStatus[]{};
}
/**
@@ -133,7 +134,7 @@
* @param to java.lang.String
* @return a status
*/
- private IStatus copyFile(InputStream in, String to) {
+ private IStatus copyFile(InputStream in, String to) {
OutputStream out = null;
try {
@@ -172,7 +173,7 @@
* @param ts timestamp
* @throws CoreException if anything goes wrong
*/
- private void copyFile(InputStream in, IPath to, long ts, IModuleFile mf) throws
CoreException {
+ private IStatus copyFile(InputStream in, IPath to, long ts, IModuleFile mf) throws
CoreException {
OutputStream out = null;
File tempFile = null;
@@ -198,11 +199,10 @@
if (ts != IResource.NULL_STAMP && ts != 0)
file.setLastModified(ts);
} catch (CoreException e) {
- throw e;
+ return e.getStatus();
} catch (Exception e) {
IPath path = mf.getModuleRelativePath().append(mf.getName());
- //Trace.trace(Trace.SEVERE, "Error copying file: " + to.toOSString() +
" to " + path.toOSString(), e);
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0,
NLS.bind(Messages.errorCopyingFile, path.toOSString(), e.getLocalizedMessage()), null));
+ return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0,
NLS.bind(Messages.errorCopyingFile, path.toOSString(), e.getLocalizedMessage()), null);
} finally {
if (tempFile != null && tempFile.exists())
tempFile.deleteOnExit();
@@ -219,6 +219,7 @@
// ignore
}
}
+ return null;
}
/**
@@ -229,7 +230,7 @@
* @param file
* @throws CoreException
*/
- private void moveTempFile(File tempFile, File file) throws CoreException {
+ private void moveTempFile(File tempFile, File file) throws CoreException {
if (file.exists()) {
if (!safeDelete(file, 2)) {
// attempt to rewrite an existing file with the tempFile contents if
@@ -312,7 +313,7 @@
IStatus s = new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0,
NLS.bind(Messages.errorDeleting, resource.toFile().getAbsolutePath()), null);
return new IStatus[]{s};
}
- return new IStatus[] { Status.OK_STATUS};
+ return new IStatus[] {};
}
/**
@@ -404,13 +405,6 @@
}
-
-
-
-
-
-
-
private static final IStatus[] EMPTY_STATUS = new IStatus[0];
private IPublishCopyCallbackHandler handler;
public PublishCopyUtil(IPublishCopyCallbackHandler handler) {
@@ -427,7 +421,7 @@
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
*/
- public IStatus[] publishDelta(IModuleResourceDelta[] delta, IProgressMonitor monitor) {
+ public IStatus[] publishDelta(IModuleResourceDelta[] delta, IProgressMonitor monitor)
throws CoreException {
if (delta == null)
return EMPTY_STATUS;
@@ -454,7 +448,7 @@
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
*/
- public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor
monitor) {
+ public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor
monitor) throws CoreException {
List status = new ArrayList(2);
IModuleResource resource = delta.getModuleResource();
@@ -518,11 +512,11 @@
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
*/
- public IStatus[] publishFull(IModuleResource[] resources, IProgressMonitor monitor) {
+ public IStatus[] publishFull(IModuleResource[] resources, IProgressMonitor monitor)
throws CoreException {
return publishFull(resources, new Path("/"), monitor); //$NON-NLS-1$
}
- public IStatus[] publishFull(IModuleResource[] resources, IPath relative,
IProgressMonitor monitor) {
+ public IStatus[] publishFull(IModuleResource[] resources, IPath relative,
IProgressMonitor monitor) throws CoreException {
if (resources == null)
return EMPTY_STATUS;
@@ -540,7 +534,7 @@
return stat;
}
- private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor)
{
+ private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor)
throws CoreException {
String name = resource.getName();
//Trace.trace(Trace.PUBLISHING, "Copying: " + name + " to " +
path.toString());
List status = new ArrayList(2);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java 2009-10-23
20:27:20 UTC (rev 18271)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java 2009-10-23
21:10:47 UTC (rev 18272)
@@ -11,6 +11,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
@@ -59,7 +60,7 @@
}
public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
+ return publishState;
}
public IStatus publishModule(IJBossServerPublishMethod method,
@@ -100,7 +101,7 @@
// First delete it
// if the module we're publishing is a project, not a binary, clean it's
folder
if( !(new Path(module.getName()).segmentCount() > 1 ))
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
remoteDeployPath.toString());
+ SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
remoteDeployPath.toString(), monitor);
ArrayList<IStatus> list = new ArrayList<IStatus>();
@@ -110,7 +111,7 @@
list.addAll(Arrays.asList(util.publishFull(members, monitor)));
}
else if( PublishUtil.isBinaryObject(moduleTree))
- list.addAll(Arrays.asList(copyBinaryModule(moduleTree)));
+ list.addAll(Arrays.asList(copyBinaryModule(moduleTree, monitor)));
else {
IPath deployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
append(IJBossServerConstants.DEPLOY).makeAbsolute();
@@ -137,7 +138,7 @@
results = new PublishCopyUtil(handler).publishDelta(delta, monitor);
} else if( delta.length > 0 ) {
if( PublishUtil.isBinaryObject(moduleTree))
- results = copyBinaryModule(moduleTree);
+ results = copyBinaryModule(moduleTree, monitor);
else {
IPath localDeployRoot =
JBossServerCorePlugin.getServerStateLocation(server.getServer()).
append(IJBossServerConstants.DEPLOY).makeAbsolute();
@@ -174,13 +175,13 @@
return ms;
}
- protected IStatus[] copyBinaryModule(IModule[] moduleTree) {
+ protected IStatus[] copyBinaryModule(IModule[] moduleTree, IProgressMonitor monitor) {
try {
IPath remoteDeployPath = getDeployPath(moduleTree, server);
IModuleResource[] members = PublishUtil.getResources(moduleTree);
File source = PublishUtil.getFile(members[0]);
if( source != null ) {
- SSHZippedJSTPublisher.launchCopyCommand(publishMethod.getSession(),
source.toString(), remoteDeployPath.toString());
+ SSHZippedJSTPublisher.launchCopyCommand(publishMethod.getSession(),
source.toString(), remoteDeployPath.toString(), monitor);
} else {
// IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.JST_PUB_COPY_BINARY_FAIL,
// NLS.bind(Messages.CouldNotPublishModule,
@@ -189,11 +190,7 @@
// TODO
}
} catch( CoreException ce ) {
-// IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.JST_PUB_COPY_BINARY_FAIL,
-// NLS.bind(Messages.CouldNotPublishModule,
-// moduleTree[moduleTree.length-1]), null);
-// return new IStatus[] {s};
- // TODO
+ return new IStatus[] {ce.getStatus()};
}
return new IStatus[]{Status.OK_STATUS};
}
@@ -201,7 +198,7 @@
protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
IProgressMonitor monitor) throws CoreException {
IPath remotePath = getDeployPath(module, server);
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
remotePath.toString());
+ SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
remotePath.toString(), monitor);
return Status.OK_STATUS;
}
@@ -215,8 +212,8 @@
public static void mkdirAndCopy(Session session, String localFile, String remoteFile)
throws CoreException {
String parentFolder = new Path(remoteFile).removeLastSegments(1).toString();
- SSHZippedJSTPublisher.launchCommand(session, "mkdir -p " + parentFolder);
- SSHZippedJSTPublisher.launchCopyCommand(session, localFile, remoteFile);
+ SSHZippedJSTPublisher.launchCommand(session, "mkdir -p " + parentFolder, new
NullProgressMonitor());
+ SSHZippedJSTPublisher.launchCopyCommand(session, localFile, remoteFile, new
NullProgressMonitor());
}
public class SSHCopyCallback implements IPublishCopyCallbackHandler {
@@ -230,35 +227,28 @@
IProgressMonitor monitor) throws CoreException {
File sourceFile = PublishUtil.getFile(mf);
IPath destination = deployRoot.append(path);
- try {
- mkdirAndCopy(publishMethod.getSession(), sourceFile.getCanonicalPath(),
destination.toString());
- } catch( IOException ioe) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, 0,
- "Error sending file: " + sourceFile.toString(), ioe));
- }
- return null;
+ mkdirAndCopy(publishMethod.getSession(), sourceFile.getAbsolutePath(),
destination.toString());
+ return new IStatus[]{};
}
public IStatus[] deleteResource(IPath path, IProgressMonitor monitor) {
IPath remotePath = deployRoot.append(path);
- IStatus ret = Status.OK_STATUS;
try {
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
remotePath.toString());
+ SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
remotePath.toString(), monitor);
} catch( CoreException ce ) {
- ret = ce.getStatus();
+ return new IStatus[]{ce.getStatus()};
}
- return new IStatus[] { ret };
+ return new IStatus[] {};
}
public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor) {
IPath remotePath = deployRoot.append(dir);
- IStatus ret = Status.OK_STATUS;
try {
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "mkdir -p "
+ remotePath.toString());
+ SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "mkdir -p "
+ remotePath.toString(), monitor);
} catch( CoreException ce ) {
- ret = ce.getStatus();
+ return new IStatus[]{ce.getStatus()};
}
- return new IStatus[] { ret };
+ return new IStatus[] {};
}
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java 2009-10-23
20:27:20 UTC (rev 18271)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java 2009-10-23
21:10:47 UTC (rev 18272)
@@ -1,7 +1,5 @@
package org.jboss.ide.eclipse.as.ssh.server;
-import java.io.File;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -18,11 +16,9 @@
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
import
org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory.SingleDeployableModuleDelegate;
-import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
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.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
@@ -80,7 +76,7 @@
return ce.getStatus();
}
} else {
- // error can't do nuffin
+ // error can't do nuffin, should never happen
publishState = IServer.PUBLISH_STATE_UNKNOWN;
}
return Status.OK_STATUS;
@@ -92,7 +88,7 @@
IPath sourcePath = delegate.getGlobalSourcePath();
String destFolder = SSHPublisher.getRemoteDeployFolder(server.getServer());
IPath destFile = new Path(destFolder).append(sourcePath.lastSegment());
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
destFile.toString());
+ SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " +
destFile.toString(), monitor);
} else {
// deleted module. o noes. Ignore it.
publishState = IServer.PUBLISH_STATE_UNKNOWN;
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java 2009-10-23
20:27:20 UTC (rev 18271)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java 2009-10-23
21:10:47 UTC (rev 18272)
@@ -74,10 +74,10 @@
// Am I a removal? If yes, remove me, and return
if( publishType == IJBossServerPublisher.REMOVE_PUBLISH) {
- launchRemoveCommand(method2.getSession(), deployFile);
+ launchRemoveCommand(method2.getSession(), deployFile, monitor);
} else {
launchCopyCommand(method2.getSession(),
- outputFilepath.toString(), deployFile);
+ outputFilepath.toString(), deployFile, monitor);
}
return null;
}
@@ -86,12 +86,12 @@
return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY,
(String)null);
}
- public static void launchRemoveCommand(Session session, String remoteLocation) throws
CoreException {
+ public static void launchRemoveCommand(Session session, String remoteLocation,
IProgressMonitor monitor) throws CoreException {
String command = "rm " + remoteLocation;
- launchCommand(session, command);
+ launchCommand(session, command, monitor);
}
- public static void launchCommand(Session session, String command) throws CoreException
{
+ public static void launchCommand(Session session, String command, IProgressMonitor
monitor) throws CoreException {
Channel channel = null;
try {
channel = session.openChannel("exec");
@@ -109,7 +109,11 @@
}
- public static void launchCopyCommand(Session session, String localFile, String
remoteFile) throws CoreException {
+ public static void launchCopyCommand(Session session, String localFile, String
remoteFile, IProgressMonitor monitor) throws CoreException {
+ launchCopyCommandImpl(session, localFile, remoteFile, monitor);
+ }
+
+ protected static void launchCopyCommandImpl(Session session, String localFile, String
remoteFile, IProgressMonitor monitor) throws CoreException {
Channel channel = null;
OutputStream out = null;
try {