[jbosstools-commits] JBoss Tools SVN: r23636 - in workspace/rstryker/rse/as/plugins: org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/rse and 6 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed Jul 21 08:30:35 EDT 2010
Author: rob.stryker at jboss.com
Date: 2010-07-21 08:30:33 -0400 (Wed, 21 Jul 2010)
New Revision: 23636
Added:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSESingleFilePublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java
Removed:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java
Modified:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/rse/RSEZippedJSTPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractServerToolsPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java
Log:
Moved two of three remaining publisher methods into the publisher method (local, rse, ssh, etc)
JBIDE-6580
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -10,16 +10,9 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.webtools.modules;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
-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.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.rse.core.AbstractServerToolsPublisher;
public class PackagesPublisher extends AbstractServerToolsPublisher {
@@ -29,18 +22,4 @@
return true;
return false;
}
-
- @Override
- protected IPublishCopyCallbackHandler getCallbackHandler(IPath path,
- IServer server, IJBossServerPublishMethod method) {
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- return new LocalCopyCallback(server, path,
- new Path(ds.getTempDeployFolder()));
- }
-
- @Override
- protected String getPublishDefaultRootFolder() {
- return server.getDeployFolder();
- }
-
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/rse/RSEZippedJSTPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/rse/RSEZippedJSTPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/rse/RSEZippedJSTPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -64,9 +64,9 @@
// set up needed vars
IDeployableServer server2 = ServerConverter.getDeployableServer(server);
- String depRoot = getDeployRoot(module, ServerConverter.getDeployableServer(server));
+ String remoteTempDeployRoot = getDeployRoot(module, ServerConverter.getDeployableServer(server));
RSEPublishMethod method2 = (RSEPublishMethod)method;
- IPath sourcePath = PublishUtil.getDeployPath(module, depRoot);
+ IPath sourcePath = PublishUtil.getDeployPath(module, remoteTempDeployRoot);
IModule lastMod = module[module.length-1];
IPath destFolder = RSEPublishMethod.findModuleFolderWithDefault(lastMod, server2, method2.getRemoteRootFolder());
IPath tempDestFolder = RSEPublishMethod.findModuleFolderWithDefault(lastMod, server2, method2.getRemoteTemporaryFolder());
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -10,33 +10,10 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.publishers;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.server.core.IServer;
-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.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.rse.core.AbstractJSTPublisher;
public class JstPublisher extends AbstractJSTPublisher {
protected String getTargetedPublishMethodId() {
return LocalPublishMethod.LOCAL_PUBLISH_METHOD;
}
-
- @Override
- protected IPublishCopyCallbackHandler getCallbackHandler(IPath path,
- IServer server, IJBossServerPublishMethod method) {
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- String tempDeployPath = ds.getTempDeployFolder();
- LocalCopyCallback handler = new LocalCopyCallback(server,
- path, new Path(tempDeployPath));
- return handler;
- }
-
- @Override
- protected String getPublishDefaultRootFolder() {
- return server.getDeployFolder();
- }
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -10,12 +10,32 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.publishers;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+
public class LocalPublishMethod extends AbstractPublishMethod {
public static final String LOCAL_PUBLISH_METHOD = "local"; //$NON-NLS-1$
- @Override
public String getPublishMethodId() {
return LOCAL_PUBLISH_METHOD;
}
+
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server) {
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ String tempDeployPath = ds.getTempDeployFolder();
+ LocalCopyCallback handler = new LocalCopyCallback(server,
+ path, new Path(tempDeployPath));
+ return handler;
+ }
+
+ public String getPublishDefaultRootFolder(IServer server) {
+ IDeployableServer s = ServerConverter.getDeployableServer(server);
+ return s.getDeployFolder();
+ }
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -10,16 +10,9 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.publishers;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
-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.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.rse.core.AbstractServerToolsPublisher;
public class SingleFilePublisher extends AbstractServerToolsPublisher {
@@ -31,19 +24,4 @@
return true;
return false;
}
-
- @Override
- protected IPublishCopyCallbackHandler getCallbackHandler(IPath path,
- IServer server, IJBossServerPublishMethod method) {
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- String tempDeployPath = ds.getTempDeployFolder();
- LocalCopyCallback handler = new LocalCopyCallback(server,
- path, new Path(tempDeployPath));
- return handler;
- }
-
- @Override
- protected String getPublishDefaultRootFolder() {
- return server.getDeployFolder();
- }
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -11,14 +11,20 @@
package org.jboss.ide.eclipse.as.core.server;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
public interface IJBossServerPublishMethod {
public IJBossServerPublishMethodType getPublishMethodType();
public void publishStart(DeployableServerBehavior behaviour, IProgressMonitor monitor) throws CoreException;
public int publishFinish(DeployableServerBehavior behaviour, IProgressMonitor monitor) throws CoreException;
public int publishModule(DeployableServerBehavior behaviour, int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException;
+
+ // Methods moved from publishers into the publish method
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server);
+ public String getPublishDefaultRootFolder(IServer server);
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractServerToolsPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractServerToolsPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractServerToolsPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -25,7 +25,6 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.model.IModuleResource;
@@ -38,7 +37,6 @@
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
@@ -97,21 +95,8 @@
}
return status;
}
-
+
/**
- * Get the callback handler to be used for building the module.
- * If the module is to be published locally, this may be a handler which only copies locally.
- * If the module is to be zipped & published locally, this may be
- * a handler which zips to a temporary directory, and allows the finish method to move the file
- *
- * @param path
- * @param server
- * @param method
- * @return
- */
- protected abstract IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server, IJBossServerPublishMethod method);
-
- /**
* Gets the actual deploy path for this module
*
* @param moduleTree
@@ -122,19 +107,12 @@
DeploymentPreferenceLoader.getCurrentDeploymentMethodType(server.getServer());
String folder = PublishUtil.getDeployRootFolder(
moduleTree, server,
- getPublishDefaultRootFolder(),
+ publishMethod.getPublishDefaultRootFolder(server.getServer()),
IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
return PublishUtil.getDeployPath(moduleTree, folder);
}
-
+
/**
- * In the event that no module-specific preferences are enabled,
- * get the default publish folder
- * @return
- */
- protected abstract String getPublishDefaultRootFolder();
-
- /**
* Finish up the publishing. This may be moving a final zipped entity into the proper
* folder or sending it over the wire to a remote machine.
*
@@ -148,7 +126,7 @@
protected void finishPublish(int publishType, IModule[] moduleTree, IDeployableServer server, IProgressMonitor monitor){}
private IPublishCopyCallbackHandler getCallbackHandler(IPath path) {
- return getCallbackHandler(path, server.getServer(), publishMethod);
+ return publishMethod.getCallbackHandler(path, server.getServer());
}
/**
@@ -283,7 +261,7 @@
protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
IProgressMonitor monitor) throws CoreException {
IPath remotePath = getDeployPath(module, server);
- IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
+ IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
handler.deleteResource(remotePath, monitor);
return Status.OK_STATUS;
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -12,89 +12,11 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.rse.core;
-import java.io.File;
-import java.util.ArrayList;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.model.IModuleFile;
-import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-
public class RSEJSTPublisher extends AbstractJSTPublisher {
@Override
protected String getTargetedPublishMethodId() {
return RSEPublishMethod.RSE_ID;
}
-
- private RSEPublishMethod getPublishMethod() {
- return (RSEPublishMethod)publishMethod;
- }
-
- @Override
- protected String getPublishDefaultRootFolder() {
- return getPublishMethod().getRemoteRootFolder().toString();
- }
-
- @Override
- protected IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server,
- IJBossServerPublishMethod method) {
- return new RSERemotePublishHandler(path, getPublishMethod());
- }
-
- public static class RSERemotePublishHandler implements IPublishCopyCallbackHandler {
- protected IPath root;
- protected RSEPublishMethod method;
- private ArrayList<IPath> createdFolders = new ArrayList<IPath>();
- public RSERemotePublishHandler(IPath path, RSEPublishMethod method) {
- this.root = path;
- this.method = method;
- }
- public IStatus[] copyFile(IModuleFile mf, IPath path,
- IProgressMonitor monitor) throws CoreException {
- File file = PublishUtil.getFile(mf);
- IPath remotePath = root.append(path);
- try {
- method.getFileService().upload(file, remotePath.removeLastSegments(1).toString(),
- remotePath.lastSegment(), true, null, null, monitor);
- } catch( SystemMessageException sme ) {
- System.err.println("failed to copy to " + remotePath.toString()); //$NON-NLS-1$
- }
- return null;
- }
-
- public IStatus[] deleteResource(IPath path, IProgressMonitor monitor)
- throws CoreException {
- IPath remotePath = root.append(path);
- try {
- method.getFileService().delete(remotePath.removeLastSegments(1).toString(), remotePath.lastSegment(), monitor);
- } catch( SystemMessageException sme ) {
- System.err.println("failed to delete " + remotePath.toString()); //$NON-NLS-1$
- }
- return null;
- }
-
- public IStatus[] makeDirectoryIfRequired(IPath dir,
- IProgressMonitor monitor) throws CoreException {
- if( dir.segmentCount() > 0 )
- makeDirectoryIfRequired(dir.removeLastSegments(1), monitor);
- IPath toMake = root.append(dir);
- if( createdFolders.contains(toMake))
- return new IStatus[]{Status.OK_STATUS};
- try {
- method.getFileService().createFolder(toMake.removeLastSegments(1).toString(), toMake.lastSegment(), monitor);
- } catch( SystemMessageException sme ) {
- System.err.println("failed to make folder " + toMake.toString()); //$NON-NLS-1$
- }
- createdFolders.add(toMake);
- return null;
- }
- }
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -23,10 +23,12 @@
import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.publishers.AbstractPublishMethod;
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.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
public class RSEPublishMethod extends AbstractPublishMethod {
@@ -116,4 +118,13 @@
return PublishUtil.getDeployPath(moduleTree, folder).removeLastSegments(1);
}
+
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server) {
+ return new RSERemotePublishHandler(path, this);
+ }
+
+ public String getPublishDefaultRootFolder(IServer server) {
+ return getRemoteRootFolder().toString();
+ }
+
}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ *
+ * TODO: Logging and Progress Monitors
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.rse.core;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+
+public class RSERemotePublishHandler implements IPublishCopyCallbackHandler {
+ protected IPath root;
+ protected RSEPublishMethod method;
+ private ArrayList<IPath> createdFolders = new ArrayList<IPath>();
+ public RSERemotePublishHandler(IPath path, RSEPublishMethod method) {
+ this.root = path;
+ this.method = method;
+ }
+ public IStatus[] copyFile(IModuleFile mf, IPath path,
+ IProgressMonitor monitor) throws CoreException {
+ File file = PublishUtil.getFile(mf);
+ IPath remotePath = root.append(path);
+ try {
+ method.getFileService().upload(file, remotePath.removeLastSegments(1).toString(),
+ remotePath.lastSegment(), true, null, null, monitor);
+ } catch( SystemMessageException sme ) {
+ System.err.println("failed to copy to " + remotePath.toString()); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public IStatus[] deleteResource(IPath path, IProgressMonitor monitor)
+ throws CoreException {
+ IPath remotePath = root.append(path);
+ try {
+ method.getFileService().delete(remotePath.removeLastSegments(1).toString(), remotePath.lastSegment(), monitor);
+ } catch( SystemMessageException sme ) {
+ System.err.println("failed to delete " + remotePath.toString()); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public IStatus[] makeDirectoryIfRequired(IPath dir,
+ IProgressMonitor monitor) throws CoreException {
+ if( dir.segmentCount() > 0 )
+ makeDirectoryIfRequired(dir.removeLastSegments(1), monitor);
+ IPath toMake = root.append(dir);
+ if( createdFolders.contains(toMake))
+ return new IStatus[]{Status.OK_STATUS};
+ try {
+ method.getFileService().createFolder(toMake.removeLastSegments(1).toString(), toMake.lastSegment(), monitor);
+ } catch( SystemMessageException sme ) {
+ System.err.println("failed to make folder " + toMake.toString()); //$NON-NLS-1$
+ }
+ createdFolders.add(toMake);
+ return null;
+ }
+}
+
Copied: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSESingleFilePublisher.java (from rev 23618, workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java)
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSESingleFilePublisher.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSESingleFilePublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.rse.core;
+
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
+
+public class RSESingleFilePublisher extends AbstractServerToolsPublisher {
+
+ public boolean accepts(String method, IServer server, IModule[] module) {
+ if( RSEPublishMethod.RSE_ID.equals(method)
+ && module != null && module.length > 0
+ && module[module.length-1] != null
+ && module[module.length-1].getModuleType().getId().equals(SingleDeployableFactory.MODULE_TYPE))
+ return true;
+ return false;
+ }
+}
Deleted: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.as.rse.core;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.ide.eclipse.as.rse.core.RSEJSTPublisher.RSERemotePublishHandler;
-
-public class SingleFileRSEPublisher extends AbstractServerToolsPublisher {
-
- public boolean accepts(String method, IServer server, IModule[] module) {
- if( RSEPublishMethod.RSE_ID.equals(method)
- && module != null && module.length > 0
- && module[module.length-1] != null
- && module[module.length-1].getModuleType().getId().equals(SingleDeployableFactory.MODULE_TYPE))
- return true;
- return false;
- }
-
- @Override
- protected IPublishCopyCallbackHandler getCallbackHandler(IPath path,
- IServer server, IJBossServerPublishMethod method) {
- return new RSERemotePublishHandler(path, (RSEPublishMethod)method);
- }
-
- @Override
- protected String getPublishDefaultRootFolder() {
- return ((RSEPublishMethod)publishMethod).getRemoteRootFolder().toString();
- }
-}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2010-07-21 12:30:33 UTC (rev 23636)
@@ -1062,7 +1062,7 @@
<extension
point="org.jboss.ide.eclipse.as.core.publishers">
<publisher
- class="org.jboss.ide.eclipse.as.rse.core.SingleFileRSEPublisher"
+ class="org.jboss.ide.eclipse.as.rse.core.RSESingleFilePublisher"
priority="7">
</publisher>
<publisher
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml 2010-07-21 12:30:33 UTC (rev 23636)
@@ -69,7 +69,7 @@
zipDelegate="true">
</publisher>
<publisher
- class="org.jboss.ide.eclipse.as.ssh.server.SSHPublisher"
+ class="org.jboss.ide.eclipse.as.ssh.server.SSHJstPublisher"
priority="3"
zipDelegate="false">
</publisher>
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -0,0 +1,213 @@
+package org.jboss.ide.eclipse.as.ssh.server;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
+import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
+
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+
+public class SSHCommandUtil {
+ public static void launchRemoveCommand(Session session, String remoteLocation, IProgressMonitor monitor) throws CoreException {
+ String command = "rm " + remoteLocation;
+ launchCommand(session, command, monitor);
+ }
+
+ public static void launchCommand(Session session, String command, IProgressMonitor monitor) throws CoreException {
+ launchThreadedCommand(session, command, monitor);
+ }
+
+ public static void launchThreadedCommand(final Session session, final String command, final IProgressMonitor monitor) throws CoreException {
+ // thread and watch the monitor for cancelations and interrupt the thread
+ LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
+ launchCommandNoThread(session, command, monitor);
+ } };
+ launchThreadedCommand(r, monitor);
+ }
+
+ public static void launchCommandNoThread(Session session, String command, IProgressMonitor monitor) throws CoreException {
+ Channel channel = null;
+ try {
+ channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(command);
+
+ channel.connect();
+ while(!channel.isClosed()) {
+ try {Thread.sleep(300);} catch(InterruptedException ie) {}
+ }
+ } catch( JSchException jsche ) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error executing command: " + command, null));
+ } finally {
+ channel.disconnect();
+ }
+ }
+
+ public static class LaunchRunnable {
+ public void run() throws CoreException {
+ }
+ }
+
+ public static void launchCopyCommand(final Session session, final String localFile,
+ final String remoteFile, final IProgressMonitor monitor) throws CoreException {
+ // thread and watch the monitor for cancelations and interrupt the thread
+ LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
+ launchCopyCommandImpl(session, localFile, remoteFile, monitor);
+ } };
+ launchThreadedCommand(r, monitor);
+ }
+
+ public static void launchThreadedCommand(final LaunchRunnable runnable, IProgressMonitor monitor) throws CoreException {
+ final Exception[] e = new Exception[1];
+ e[0] = null;
+ final Object waitObject = new Object();
+ final Boolean[] subtaskComplete = new Boolean[1];
+ subtaskComplete[0] = new Boolean(false);
+ Thread t = new Thread() {
+ public void run() {
+ Exception exception = null;
+ try {
+ runnable.run();
+ } catch( Exception ex ) {
+ exception = ex;
+ }
+ synchronized(waitObject) {
+ e[0] = exception;
+ subtaskComplete[0] = new Boolean(true);
+ waitObject.notifyAll();
+ }
+ }
+ };
+ t.start();
+ while(t.isAlive() && !monitor.isCanceled() ) {
+ synchronized(waitObject) {
+ if( subtaskComplete[0].booleanValue() )
+ break;
+ try {
+ waitObject.wait(500);
+ } catch(InterruptedException ie) {}
+ }
+ }
+ synchronized(waitObject) {
+ if( !subtaskComplete[0].booleanValue()) {
+ t.interrupt();
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "SSH command canceled", e[0]);
+ CoreException ce = new CoreException(status);
+ throw ce;
+ }
+ if( e[0] != null ) {
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "Error running remote command", e[0]);
+ CoreException ce = new CoreException(status);
+ throw ce;
+ }
+
+ }
+ }
+
+ public static void launchCopyCommandImpl(Session session, String localFile, String remoteFile, IProgressMonitor monitor) throws CoreException {
+ Channel channel = null;
+ OutputStream out = null;
+ try {
+ // exec 'scp -t rfile' remotely
+ String command = "scp -p -t " + remoteFile;
+ channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(command);
+
+ // get I/O streams for remote scp
+ out = channel.getOutputStream();
+ InputStream in = channel.getInputStream();
+ channel.connect();
+ if (checkAck(in) != 0) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
+ }
+
+ // send "C0644 filesize filename", where filename should not include
+ // '/'
+ long filesize = (new File(localFile)).length();
+ command = "C0644 " + filesize + " ";
+ if (localFile.lastIndexOf('/') > 0) {
+ command += localFile.substring(localFile.lastIndexOf('/') + 1);
+ } else {
+ command += localFile;
+ }
+ command += "\n";
+ out.write(command.getBytes());
+ out.flush();
+ if (checkAck(in) != 0) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
+ }
+
+ // send a content of lfile
+ FileInputStream fis = new FileInputStream(localFile);
+ byte[] buf = new byte[1024];
+ while (true) {
+ int len = fis.read(buf, 0, buf.length);
+ if (len <= 0)
+ break;
+ out.write(buf, 0, len); // out.flush();
+ }
+ fis.close();
+ fis = null;
+ // send '\0'
+ buf[0] = 0;
+ out.write(buf, 0, 1);
+ out.flush();
+ if (checkAck(in) != 0) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
+ }
+
+ } catch( JSchException jsche ) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, jsche));
+ } catch( IOException ioe) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, ioe));
+ } finally {
+ if( channel != null )
+ channel.disconnect();
+ if( out != null ) {
+ try {
+ out.close();
+ } catch(IOException ioe) {}
+ }
+ }
+ }
+
+ static int checkAck(InputStream in) throws IOException {
+ int b = in.read();
+ // b may be 0 for success,
+ // 1 for error,
+ // 2 for fatal error,
+ // -1
+ if (b == 0)
+ return b;
+ if (b == -1)
+ return b;
+
+ if (b == 1 || b == 2) {
+ StringBuffer sb = new StringBuffer();
+ int c;
+ do {
+ c = in.read();
+ sb.append((char) c);
+ } while (c != '\n');
+// if (b == 1) { // error
+// System.out.print(sb.toString());
+// }
+// if (b == 2) { // fatal error
+// System.out.print(sb.toString());
+// }
+ }
+ return b;
+ }
+
+}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+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;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
+
+import com.jcraft.jsch.Session;
+
+public class SSHCopyCallback implements IPublishCopyCallbackHandler {
+
+ private IPath root;
+ private SSHPublishMethod method;
+ public SSHCopyCallback(IPath deployRoot, SSHPublishMethod method) {
+ this.root = deployRoot;
+ this.method = method;
+ }
+
+ public IStatus[] copyFile(IModuleFile mf, IPath path,
+ IProgressMonitor monitor) throws CoreException {
+ File sourceFile = PublishUtil.getFile(mf);
+ IPath destination = root.append(path);
+ String parentFolder = destination.removeLastSegments(1).toString();
+ SSHCommandUtil.launchCommand(getSession(), "mkdir -p " + parentFolder, new NullProgressMonitor());
+ SSHCommandUtil.launchCopyCommand(getSession(), sourceFile.getAbsolutePath(), destination.toString(), new NullProgressMonitor());
+ return new IStatus[]{};
+ }
+
+ protected Session getSession() {
+ return method.getSession();
+ }
+
+ public IStatus[] deleteResource(IPath path, IProgressMonitor monitor) {
+ IPath remotePath = root.append(path);
+ try {
+ SSHCommandUtil.launchCommand(method.getSession(), "rm -rf " + remotePath.toString(), monitor);
+ } catch( CoreException ce ) {
+ return new IStatus[]{ce.getStatus()};
+ }
+ return new IStatus[] {};
+ }
+
+ public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor) {
+ IPath remotePath = root.append(dir);
+ try {
+ SSHCommandUtil.launchCommand(method.getSession(), "mkdir -p " + remotePath.toString(), monitor);
+ } catch( CoreException ce ) {
+ return new IStatus[]{ce.getStatus()};
+ }
+ return new IStatus[] {};
+ }
+}
\ No newline at end of file
Copied: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java (from rev 23581, workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java)
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ssh.server;
+
+
+import org.jboss.ide.eclipse.as.rse.core.AbstractJSTPublisher;
+import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
+
+
+public class SSHJstPublisher extends AbstractJSTPublisher {
+ public SSHJstPublisher() {}
+
+ @Override
+ protected String getTargetedPublishMethodId() {
+ return SSHPublishMethod.SSH_PUBLISH_METHOD;
+ }
+}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -1,149 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ssh.server;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-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;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.internal.Server;
-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.webtools.IntegrationPlugin;
-import org.jboss.ide.eclipse.archives.webtools.Messages;
import org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory;
-import org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
-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.server.xpl.PublishCopyUtil;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.ssh.server.SSHPublisher.SSHCopyCallback;
+import org.jboss.ide.eclipse.as.rse.core.AbstractServerToolsPublisher;
import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-public class SSHPackagesPublisher implements IJBossServerPublisher {
-
- protected IDeployableServer server;
- protected IModuleResourceDelta[] delta;
- protected ArrayList<IStatus> statuses = new ArrayList<IStatus>();
- protected SSHPublishMethod method;
- public SSHPackagesPublisher() {
- }
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
+public class SSHPackagesPublisher extends AbstractServerToolsPublisher {
public boolean accepts(String method, IServer server, IModule[] module) {
if( SSHPublishMethod.SSH_PUBLISH_METHOD.equals(method) && module != null && module.length > 0
&& PackageModuleFactory.MODULE_TYPE.equals(module[0].getModuleType().getId()))
return true;
return false;
}
- public IStatus publishModule(
- IJBossServerPublishMethod method,
- IServer server, IModule[] module,
- int publishType, IModuleResourceDelta[] delta,
- IProgressMonitor monitor)
- throws CoreException {
- this.method = (SSHPublishMethod)method;
- this.server = ServerConverter.getDeployableServer(server);
- this.delta = delta;
- IModule module2 = module[0];
-
- try {
- // if it's being removed
- if( publishType == REMOVE_PUBLISH ) {
- statuses.addAll(Arrays.asList(removeModule(module2, monitor)));
- } else if( publishType == FULL_PUBLISH ) {
- statuses.addAll(Arrays.asList(publishModule(module2, false, monitor)));
- } else if( publishType == INCREMENTAL_PUBLISH ) {
- statuses.addAll(Arrays.asList(publishModule(module2, true, monitor)));
- }
- }catch(Exception e) {
- e.printStackTrace();
- IStatus status = new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.ErrorDuringPublish, module2.getName()), e);
- return status;
- }
-
- if( statuses.size() > 0 ) {
- MultiStatus ms = new MultiStatus(IntegrationPlugin.PLUGIN_ID, IStatus.ERROR,
- NLS.bind(Messages.ErrorDuringPublish, module2.getName()), null);
- for( int i = 0; i < statuses.size(); i++ ) {
- ms.add(statuses.get(i));
- }
- return ms;
- }
-
- IStatus ret = new Status(IStatus.OK, IntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.PublishSuccessful, module2.getName()));
- return ret;
- }
-
- protected IStatus[] removeModule(IModule module, IProgressMonitor monitor) {
- IArchive pack = getPackage(module);
- // remove all of the deployed items
- if( pack != null ) {
- IPath sourcePath = pack.getArchiveFilePath();
- String deployFolder = getRemoteDeployFolder(server.getServer());
- String deployFile = new Path(deployFolder).append(sourcePath.lastSegment()).toString();
- try {
- SSHZippedJSTPublisher.launchRemoveCommand(method.getSession(), deployFile, monitor);
- } catch( CoreException ce ) {
- return new IStatus[] { ce.getStatus() };
- }
- }
- return new IStatus[] { }; // nothing to report
- }
-
-
-
- protected IStatus[] publishModule(IModule module, boolean incremental, IProgressMonitor monitor) {
- IArchive pack = getPackage(module);
- IPath sourcePath = pack.getArchiveFilePath();
- String remoteContainer = getRemoteDeployFolder(server.getServer());
- IPath remoteRoot = new Path(remoteContainer).append(sourcePath.lastSegment());
-
- try {
- if( !pack.isExploded() ) {
- // copy the output file
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "rm -rf " + remoteRoot.toString(), monitor);
- SSHZippedJSTPublisher.launchCopyCommand(method.getSession(), sourcePath.toOSString(), remoteRoot.toString(), monitor);
- } else {
- if( incremental ) {
- SSHCopyCallback callback = new SSHCopyCallback(remoteRoot, method);
- PublishCopyUtil util = new PublishCopyUtil(callback);
- return util.publishDelta(delta, monitor);
- } else {
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "rm -rf " + remoteRoot.toString(), monitor);
- IModuleResource[] members = PublishUtil.getResources(module);
- SSHCopyCallback callback = new SSHCopyCallback(remoteRoot, method);
- PublishCopyUtil util = new PublishCopyUtil(callback);
- return util.publishFull(members, monitor);
- }
- }
- } catch( CoreException ce ) {
- return new IStatus[] { ce.getStatus() };
- }
- return new IStatus[] { };
- }
-
- protected IArchive getPackage(IModule module) {
- PackagedModuleDelegate delegate = (PackagedModuleDelegate)module.loadAdapter(PackagedModuleDelegate.class, new NullProgressMonitor());
- return delegate == null ? null : delegate.getPackage();
- }
- protected String getRemoteDeployFolder(IServer server) {
- return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
- }
}
\ No newline at end of file
Deleted: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -1,267 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.as.ssh.server;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-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;
-import org.eclipse.wst.common.componentcore.ModuleCoreNature;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.internal.Server;
-import org.eclipse.wst.server.core.model.IModuleFile;
-import org.eclipse.wst.server.core.model.IModuleResource;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
-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.IJBossServerConstants;
-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.server.xpl.PublishCopyUtil;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
-import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-
-import com.jcraft.jsch.Session;
-
-public class SSHPublisher implements IJBossServerPublisher {
- protected IModuleResourceDelta[] delta;
- protected IDeployableServer server;
- protected int publishState = IServer.PUBLISH_STATE_NONE;
- protected SSHPublishMethod publishMethod;
-
- public SSHPublisher() {}
-
- public boolean accepts(String method, IServer server, IModule[] module) {
- if( !method.equals(SSHPublishMethod.SSH_PUBLISH_METHOD))
- return false;
- if( module == null )
- return true;
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- boolean shouldAccept = ds != null
- && ModuleCoreNature.isFlexibleProject(module[0].getProject())
- && !SSHPublishUtil.getZipsSSHDeployments(server);
- return shouldAccept;
- }
-
- public int getPublishState() {
- return publishState;
- }
-
- public IStatus publishModule(IJBossServerPublishMethod method,
- IServer server, IModule[] module, int publishType,
- IModuleResourceDelta[] delta, IProgressMonitor monitor)
- throws CoreException {
- IStatus status = null;
- this.server = ServerConverter.getDeployableServer(server);
- this.delta = delta;
- this.publishMethod = (SSHPublishMethod)method;
-
- boolean deleted = false;
- for( int i = 0; i < module.length; i++ ) {
- if( module[i].isExternal() )
- deleted = true;
- }
-
- if (publishType == REMOVE_PUBLISH ) {
- status = unpublish(this.server, module, monitor);
- } else {
- if( deleted ) {
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- } else {
- if (publishType == FULL_PUBLISH ) {
- status = fullPublish(module, module[module.length-1], monitor);
- } else if (publishType == INCREMENTAL_PUBLISH) {
- status = incrementalPublish(module, module[module.length-1], monitor);
- }
- }
- }
- return status;
- }
-
- protected IStatus fullPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IPath remoteDeployPath = getDeployPath(moduleTree, server);
- IModuleResource[] members = PublishUtil.getResources(module);
-
- // 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(), monitor);
-
- ArrayList<IStatus> list = new ArrayList<IStatus>();
-
- if( !PublishUtil.deployPackaged(moduleTree) && !PublishUtil.isBinaryObject(moduleTree)) {
- SSHCopyCallback callback = new SSHCopyCallback(remoteDeployPath, publishMethod);
- PublishCopyUtil util = new PublishCopyUtil(callback);
- list.addAll(Arrays.asList(util.publishFull(members, monitor)));
- }
- else if( PublishUtil.isBinaryObject(moduleTree))
- list.addAll(Arrays.asList(copyBinaryModule(moduleTree, monitor)));
- else {
- IPath deployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
- append(IJBossServerConstants.DEPLOY).makeAbsolute();
- try {
- File temp = deployRoot.toFile().createTempFile(module.getName(), ".tmp", deployRoot.toFile());
- IPath tempFile = new Path(temp.getAbsolutePath());
- list.addAll(Arrays.asList(PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1], tempFile)));
- mkdirAndCopy(publishMethod.getSession(), tempFile.toString(), remoteDeployPath.toString());
- } catch( IOException ioe) {
- list.add(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, ioe.getMessage(), ioe));
- }
- }
-
- if( list.size() > 0 )
- return createMultiStatus(list, module);
- return Status.OK_STATUS;
- }
-
- protected IStatus incrementalPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IStatus[] results = new IStatus[] {};
- IPath remoteDeployPath = getDeployPath(moduleTree, server);
- if( !PublishUtil.deployPackaged(moduleTree) && !PublishUtil.isBinaryObject(moduleTree)) {
- SSHCopyCallback handler = new SSHCopyCallback(remoteDeployPath, publishMethod);
- results = new PublishCopyUtil(handler).publishDelta(delta, monitor);
- } else if( delta.length > 0 ) {
- if( PublishUtil.isBinaryObject(moduleTree))
- results = copyBinaryModule(moduleTree, monitor);
- else {
- IPath localDeployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
- append(IJBossServerConstants.DEPLOY).makeAbsolute();
- try {
- File temp = localDeployRoot.toFile().createTempFile(module.getName(), ".tmp", localDeployRoot.toFile());
- IPath tempFile = new Path(temp.getAbsolutePath());
- PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1], tempFile);
- mkdirAndCopy(publishMethod.getSession(), tempFile.toString(), remoteDeployPath.toString());
- } catch( IOException ioe) {
- IStatus s = new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, ioe.getMessage(), ioe);
- results = new IStatus[] { s };
- }
- }
- }
-
- if( results != null && results.length > 0 ) {
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_INC_FAIL,
- NLS.bind(Messages.IncrementalPublishFail, module.getName()), null);
- for( int i = 0; i < results.length; i++ )
- ms.add(results[i]);
- return ms;
- }
-
- IStatus ret = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_SUCCESS,
- NLS.bind(Messages.CountModifiedMembers, PublishUtil.countChanges(delta), module.getName()), null);
- return ret;
- }
-
-
- protected IStatus createMultiStatus(List<IStatus> list, IModule module) {
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_FAIL,
- NLS.bind(Messages.FullPublishFail, module.getName()), null);
- for( int i = 0; i < list.size(); i++ )
- ms.add(list.get(i));
- return ms;
- }
-
- 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(), monitor);
- } else {
-// 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
- }
- } catch( CoreException ce ) {
- return new IStatus[] {ce.getStatus()};
- }
- return new IStatus[]{Status.OK_STATUS};
- }
-
- protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
- IProgressMonitor monitor) throws CoreException {
- IPath remotePath = getDeployPath(module, server);
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " + remotePath.toString(), monitor);
- return Status.OK_STATUS;
- }
-
- public static IPath getDeployPath(IModule[] moduleTree, IDeployableServer server) {
- return PublishUtil.getDeployPath(moduleTree, getRemoteDeployFolder(server.getServer()));
- }
-
- public static String getRemoteDeployFolder(IServer server) {
- return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
- }
-
- 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, new NullProgressMonitor());
- SSHZippedJSTPublisher.launchCopyCommand(session, localFile, remoteFile, new NullProgressMonitor());
- }
-
- public static class SSHCopyCallback implements IPublishCopyCallbackHandler {
-
- private IPath root;
- private SSHPublishMethod method;
- public SSHCopyCallback(IPath deployRoot, SSHPublishMethod method) {
- this.root = deployRoot;
- this.method = method;
- }
-
- public IStatus[] copyFile(IModuleFile mf, IPath path,
- IProgressMonitor monitor) throws CoreException {
- File sourceFile = PublishUtil.getFile(mf);
- IPath destination = root.append(path);
- mkdirAndCopy(method.getSession(), sourceFile.getAbsolutePath(), destination.toString());
- return new IStatus[]{};
- }
-
- public IStatus[] deleteResource(IPath path, IProgressMonitor monitor) {
- IPath remotePath = root.append(path);
- try {
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "rm -rf " + remotePath.toString(), monitor);
- } catch( CoreException ce ) {
- return new IStatus[]{ce.getStatus()};
- }
- return new IStatus[] {};
- }
-
- public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor) {
- IPath remotePath = root.append(dir);
- try {
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "mkdir -p " + remotePath.toString(), monitor);
- } catch( CoreException ce ) {
- return new IStatus[]{ce.getStatus()};
- }
- return new IStatus[] {};
- }
- }
-}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -11,16 +11,19 @@
package org.jboss.ide.eclipse.as.ssh.server;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.internal.Server;
import org.jboss.ide.eclipse.as.core.ExtensionManager;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
import com.jcraft.jsch.JSch;
@@ -79,6 +82,10 @@
session = null;
return ret;
}
+
+ public String getPublishDefaultRootFolder(IServer server) {
+ return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
+ }
}
@@ -127,4 +134,15 @@
}
}
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path,
+ IServer server, IJBossServerPublishMethod method) {
+ return new SSHCopyCallback(path, (SSHPublishMethod)method);
+ }
+
+ public String getPublishDefaultRootFolder(IServer server) {
+ return getPublishDefaultRootFolder(server);
+ }
+
+
+
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -10,33 +10,16 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.ssh.server;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-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.osgi.util.NLS;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-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.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.ServerConverter;
+import org.jboss.ide.eclipse.as.rse.core.AbstractServerToolsPublisher;
import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-public class SSHSingleFilePublisher implements IJBossServerPublisher {
+public class SSHSingleFilePublisher extends AbstractServerToolsPublisher {
- public SSHSingleFilePublisher() {
- }
-
public boolean accepts(String method, IServer server, IModule[] module) {
if( !method.equals(SSHPublishMethod.SSH_PUBLISH_METHOD))
return false;
@@ -48,68 +31,4 @@
&& module[0].getModuleType().getId().equals(SingleDeployableFactory.MODULE_TYPE);
return shouldAccept;
}
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
- private IDeployableServer server;
- private SSHPublishMethod publishMethod;
- private int publishState = IServer.PUBLISH_STATE_NONE;
- public IStatus publishModule(IJBossServerPublishMethod method,
- IServer server, IModule[] module, int publishType,
- IModuleResourceDelta[] delta, IProgressMonitor monitor)
- throws CoreException {
- this.server = ServerConverter.getDeployableServer(server);
- this.publishMethod = (SSHPublishMethod)method;
- IModule module2 = module[0];
-
- IStatus status = null;
- if(publishType == REMOVE_PUBLISH){
- status = unpublish(this.server, module2, monitor);
- } else if( publishType == FULL_PUBLISH || publishType == INCREMENTAL_PUBLISH){
- // if there's no change, do nothing. Otherwise, on change or add, re-publish
- status = publish(this.server, module2, monitor);
- }
- return status;
- }
-
- protected IStatus publish(IDeployableServer server, IModule module, IProgressMonitor monitor) {
- SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
- if( delegate != null ) {
- IPath sourcePath = delegate.getGlobalSourcePath();
- String destFolder = SSHPublisher.getRemoteDeployFolder(server.getServer());
- IPath destFile = new Path(destFolder).append(sourcePath.lastSegment());
- try {
- SSHPublisher.mkdirAndCopy(publishMethod.getSession(), sourcePath.toOSString(), destFile.toString());
- } catch( CoreException ce ) {
- return ce.getStatus();
- }
- } else {
- // error can't do nuffin, should never happen
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- }
- return Status.OK_STATUS;
- }
-
- protected IStatus unpublish(IDeployableServer server, IModule module, IProgressMonitor monitor) throws CoreException {
- SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
- if( delegate != null ) {
- 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(), monitor);
- } else {
- // deleted module. o noes. Ignore it.
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- Status status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_MNF,
- NLS.bind(Messages.DeleteModuleFail, module.getName()), null);
- return status;
- }
- Status status = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_SUCCESS,
- NLS.bind(Messages.ModuleDeleted, module.getName()), null);
- return status;
- }
-
-
}
Modified: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java 2010-07-21 12:08:00 UTC (rev 23635)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java 2010-07-21 12:30:33 UTC (rev 23636)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2010 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -10,282 +10,48 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.ssh.server;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.internal.Server;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.archives.webtools.modules.LocalZippedPublisherUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
-import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
+import org.jboss.ide.eclipse.archives.webtools.modules.WTPZippedPublisher;
+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.IJBossServerConstants;
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.ServerConverter;
-import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
-public class SSHZippedJSTPublisher implements IJBossServerPublisher {
-
- public SSHZippedJSTPublisher() {
+public class SSHZippedJSTPublisher extends WTPZippedPublisher {
+ protected String getPublishMethod() {
+ return SSHPublishMethod.SSH_PUBLISH_METHOD;
}
-
- public boolean accepts(String method, IServer server, IModule[] module) {
- if( !method.equals(SSHPublishMethod.SSH_PUBLISH_METHOD))
- return false;
- if( module == null )
- return true;
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- boolean shouldAccept = ds != null
- && ModuleCoreNature.isFlexibleProject(module[0].getProject())
- && SSHPublishUtil.getZipsSSHDeployments(server);
- return shouldAccept;
- }
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
+
public IStatus publishModule(
IJBossServerPublishMethod method,
IServer server, IModule[] module,
int publishType, IModuleResourceDelta[] delta,
IProgressMonitor monitor) throws CoreException {
- // Let the local zipped publisher do the work in a local / metadata folder
- IStatus returnStatus = null;
- SSHPublishMethod method2 = (SSHPublishMethod)method;
- IPath deployRoot = JBossServerCorePlugin.getServerStateLocation(server).
- append(IJBossServerConstants.DEPLOY).makeAbsolute();
+ IStatus s = super.publishModule(method, server, module, publishType, delta, monitor);
+ // set up needed vars
+ IDeployableServer server2 = ServerConverter.getDeployableServer(server);
+ String builtArchivesFolder = getDeployRoot(module, ServerConverter.getDeployableServer(server));
+ IPath builtArchive = PublishUtil.getDeployPath(module, builtArchivesFolder);
+ String defaultDeployRoot = ((SSHPublishMethod)method).getPublishDefaultRootFolder(server);
+ String folder = PublishUtil.getDeployRootFolder(
+ module, server2, defaultDeployRoot,
+ SSHPublishMethod.SSH_PUBLISH_METHOD);
+ IPath remoteFile = PublishUtil.getDeployPath(module, folder);
+ Session session = ((SSHPublishMethod)method).getSession();
- LocalZippedPublisherUtil localDelegate = new LocalZippedPublisherUtil();
- IStatus localCopyStatus = localDelegate.publishModule(server,
- deployRoot.toOSString(), module, publishType, delta, monitor);
- IPath outputFilepath = localDelegate.getOutputFilePath(module);
-
- String deployFolder = getRemoteDeployFolder(server);
- String deployFile = new Path(deployFolder).append(outputFilepath.lastSegment()).toString();
-
- // Am I a removal? If yes, remove me, and return
- if( publishType == IJBossServerPublisher.REMOVE_PUBLISH) {
- launchRemoveCommand(method2.getSession(), deployFile, monitor);
- } else {
- launchCopyCommand(method2.getSession(),
- outputFilepath.toString(), deployFile, monitor);
- }
- return null;
+ // Now transfer the file via ssh
+ SSHCommandUtil.launchCopyCommand(session, builtArchive.toString(), remoteFile.toString(), monitor);
+ return s;
}
-
- protected String getRemoteDeployFolder(IServer server) {
- return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
- }
- public static void launchRemoveCommand(Session session, String remoteLocation, IProgressMonitor monitor) throws CoreException {
- String command = "rm " + remoteLocation;
- launchCommand(session, command, monitor);
- }
- public static void launchCommand(Session session, String command, IProgressMonitor monitor) throws CoreException {
- launchThreadedCommand(session, command, monitor);
- }
-
- protected static void launchThreadedCommand(final Session session, final String command, final IProgressMonitor monitor) throws CoreException {
- // thread and watch the monitor for cancelations and interrupt the thread
- LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
- launchCommandNoThread(session, command, monitor);
- } };
- launchThreadedCommand(r, monitor);
- }
-
- protected static void launchCommandNoThread(Session session, String command, IProgressMonitor monitor) throws CoreException {
- Channel channel = null;
- try {
- channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- channel.connect();
- while(!channel.isClosed()) {
- try {Thread.sleep(300);} catch(InterruptedException ie) {}
- }
- } catch( JSchException jsche ) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error executing command: " + command, null));
- } finally {
- channel.disconnect();
- }
- }
-
- public static class LaunchRunnable {
- public void run() throws CoreException {
- }
- }
-
- public static void launchCopyCommand(final Session session, final String localFile,
- final String remoteFile, final IProgressMonitor monitor) throws CoreException {
- // thread and watch the monitor for cancelations and interrupt the thread
- LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
- launchCopyCommandImpl(session, localFile, remoteFile, monitor);
- } };
- launchThreadedCommand(r, monitor);
- }
-
- protected static void launchThreadedCommand(final LaunchRunnable runnable, IProgressMonitor monitor) throws CoreException {
- final Exception[] e = new Exception[1];
- e[0] = null;
- final Object waitObject = new Object();
- final Boolean[] subtaskComplete = new Boolean[1];
- subtaskComplete[0] = new Boolean(false);
- Thread t = new Thread() {
- public void run() {
- Exception exception = null;
- try {
- runnable.run();
- } catch( Exception ex ) {
- exception = ex;
- }
- synchronized(waitObject) {
- e[0] = exception;
- subtaskComplete[0] = new Boolean(true);
- waitObject.notifyAll();
- }
- }
- };
- t.start();
- while(t.isAlive() && !monitor.isCanceled() ) {
- synchronized(waitObject) {
- if( subtaskComplete[0].booleanValue() )
- break;
- try {
- waitObject.wait(500);
- } catch(InterruptedException ie) {}
- }
- }
- synchronized(waitObject) {
- if( !subtaskComplete[0].booleanValue()) {
- t.interrupt();
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "SSH command canceled", e[0]);
- CoreException ce = new CoreException(status);
- throw ce;
- }
- if( e[0] != null ) {
- IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "Error running remote command", e[0]);
- CoreException ce = new CoreException(status);
- throw ce;
- }
-
- }
- }
-
- protected static void launchCopyCommandImpl(Session session, String localFile, String remoteFile, IProgressMonitor monitor) throws CoreException {
- Channel channel = null;
- OutputStream out = null;
- try {
- // exec 'scp -t rfile' remotely
- String command = "scp -p -t " + remoteFile;
- channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- // get I/O streams for remote scp
- out = channel.getOutputStream();
- InputStream in = channel.getInputStream();
- channel.connect();
- if (checkAck(in) != 0) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
- }
-
- // send "C0644 filesize filename", where filename should not include
- // '/'
- long filesize = (new File(localFile)).length();
- command = "C0644 " + filesize + " ";
- if (localFile.lastIndexOf('/') > 0) {
- command += localFile.substring(localFile.lastIndexOf('/') + 1);
- } else {
- command += localFile;
- }
- command += "\n";
- out.write(command.getBytes());
- out.flush();
- if (checkAck(in) != 0) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
- }
-
- // send a content of lfile
- FileInputStream fis = new FileInputStream(localFile);
- byte[] buf = new byte[1024];
- while (true) {
- int len = fis.read(buf, 0, buf.length);
- if (len <= 0)
- break;
- out.write(buf, 0, len); // out.flush();
- }
- fis.close();
- fis = null;
- // send '\0'
- buf[0] = 0;
- out.write(buf, 0, 1);
- out.flush();
- if (checkAck(in) != 0) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
- }
-
- } catch( JSchException jsche ) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, jsche));
- } catch( IOException ioe) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, ioe));
- } finally {
- if( channel != null )
- channel.disconnect();
- if( out != null ) {
- try {
- out.close();
- } catch(IOException ioe) {}
- }
- }
- }
-
- static int checkAck(InputStream in) throws IOException {
- int b = in.read();
- // b may be 0 for success,
- // 1 for error,
- // 2 for fatal error,
- // -1
- if (b == 0)
- return b;
- if (b == -1)
- return b;
-
- if (b == 1 || b == 2) {
- StringBuffer sb = new StringBuffer();
- int c;
- do {
- c = in.read();
- sb.append((char) c);
- } while (c != '\n');
-// if (b == 1) { // error
-// System.out.print(sb.toString());
-// }
-// if (b == 2) { // fatal error
-// System.out.print(sb.toString());
-// }
- }
- return b;
- }
}
More information about the jbosstools-commits
mailing list