[jbosstools-commits] JBoss Tools SVN: r42408 - branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jul 5 08:20:58 EDT 2012


Author: rob.stryker at jboss.com
Date: 2012-07-05 08:20:58 -0400 (Thu, 05 Jul 2012)
New Revision: 42408

Modified:
   branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java
   branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java
   branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java
   branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java
Log:
JBIDE-12201 JBIDE-12046 to maintenance 3.3.x

Modified: branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java
===================================================================
--- branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java	2012-07-05 12:19:27 UTC (rev 42407)
+++ branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/AbstractRSELaunchDelegate.java	2012-07-05 12:20:58 UTC (rev 42408)
@@ -44,11 +44,13 @@
 			behavior.setServerStopped(); 
 			throw new CoreException(new Status(IStatus.ERROR,
 					org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID,
-					MessageFormat.format("Could not execute command on remote server {0}", behavior.getServer().getName()), sme));
+					MessageFormat.format("Could not execute command on remote server {0}. Please ensure the server is reachable.", behavior.getServer().getName()), sme));
 		}
 	}
 	// Only for debugging
 	private void addShellOutputListener(IHostShell shell) {
+		if( shell == null ) 
+			return; // No listener needed for a null shell. 
 		IHostShellOutputListener listener = null;
 		listener = new IHostShellOutputListener() {
 			public void shellOutputChanged(IHostShellChangeEvent event) {

Modified: branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java
===================================================================
--- branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java	2012-07-05 12:19:27 UTC (rev 42407)
+++ branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEHostShellModel.java	2012-07-05 12:20:58 UTC (rev 42408)
@@ -109,6 +109,8 @@
 				startupShell = hs;
 				startupShell.addOutputListener(listener);
 				return hs;
+			} catch(SystemMessageException sme) {
+				throw sme; 
 			} catch(RuntimeException re) {
 				throw new CoreException(new Status(IStatus.ERROR, org.jboss.ide.eclipse.as.rse.core.RSECorePlugin.PLUGIN_ID, 
 						re.getMessage(), re));

Modified: branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java
===================================================================
--- branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java	2012-07-05 12:19:27 UTC (rev 42407)
+++ branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java	2012-07-05 12:20:58 UTC (rev 42408)
@@ -23,12 +23,16 @@
 import org.eclipse.rse.core.RSECorePlugin;
 import org.eclipse.rse.core.model.IHost;
 import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 import org.eclipse.rse.services.files.IFileService;
+import org.eclipse.rse.services.files.IHostFile;
 import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
 import org.eclipse.wst.server.core.IServer;
 import org.jboss.ide.eclipse.as.core.Trace;
+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.as.core.publishers.AbstractPublishMethod;
+import org.jboss.ide.eclipse.as.core.publishers.AbstractServerToolsPublisher;
 import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
 import org.jboss.ide.eclipse.as.core.server.IJBoss6Server;
 import org.jboss.ide.eclipse.as.core.server.IPublishCopyCallbackHandler;
@@ -39,6 +43,7 @@
 import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
 import org.jboss.ide.eclipse.as.core.util.ServerConverter;
 import org.jboss.ide.eclipse.as.rse.core.RSEHostShellModel.ServerShellModel;
+import org.jboss.ide.eclipse.as.rse.core.RSERemotePublishHandler.RunnableWithProgress2;
 
 public class RSEPublishMethod extends AbstractPublishMethod {
 
@@ -64,11 +69,15 @@
 	
 	public void publishStart(DeployableServerBehavior behaviour,
 			IProgressMonitor monitor) throws CoreException {
-		super.publishStart(behaviour, monitor);
+		monitor.beginTask("Beginning Publish for server " + behaviour.getServer().getName(), 300);
+		super.publishStart(behaviour, AbstractServerToolsPublisher.getSubMon(monitor, 100));
 		this.behaviour = behaviour;
 		loadRemoteDeploymentDetails();
-		ensureConnection(monitor);
-
+		IStatus connected = ensureConnection(AbstractServerToolsPublisher.getSubMon(monitor, 100));
+		if( !connected.isOK() ) {
+			throw new CoreException(connected);
+		}
+		
 		DelegatingServerBehavior b = (DelegatingServerBehavior) behaviour.getServer().loadAdapter(DelegatingServerBehavior.class, new NullProgressMonitor());
 		if( b != null && getServer().getServerState() == IServer.STATE_STARTED ) {
 			stopDeploymentScanner();
@@ -135,18 +144,38 @@
 		return behaviour.getServer();
 	}
 	
-	public boolean ensureConnection(IProgressMonitor monitor) {
+	public IStatus ensureConnection(IProgressMonitor monitor) {
+		monitor.beginTask("Verifying connectivity to remote server", 200);
+		Exception caught = null;
 		Trace.trace(Trace.STRING_FINER, "Ensuring connection to remote server for server " + getServer().getName());
 		if (fileSubSystem != null && !fileSubSystem.isConnected()) {
 		    try {
-		    	fileSubSystem.connect(monitor, false);
+		    	fileSubSystem.connect(AbstractServerToolsPublisher.getSubMon(monitor, 100), false);
 		    } catch (Exception e) {
 				Trace.trace(Trace.STRING_FINER, "Exception connecting to remote server: " + e.getMessage());
-		    	// I'd rather not catch Exception, but that's all they throw
-		    	return false;
+		    	// I'd rather not catch raw Exception, but that's all they throw
+				caught = e;
 		    }
 		}
-		return fileSubSystem != null && fileSubSystem.isConnected();
+		boolean isConnected = fileSubSystem != null && fileSubSystem.isConnected();
+		String connectionName = RSEUtils.getRSEConnectionName(behaviour.getServer());
+		if( isConnected ) {
+			// The RSE tools might be mistaken here. The user may in fact have lost internet connectivity
+			RunnableWithProgress2 run = new RunnableWithProgress2("Accessing Remote System Root") {
+				public void run(IProgressMonitor monitor) throws CoreException,
+						SystemMessageException, RuntimeException {
+					getFileService().getRoots(monitor);
+				}
+			};
+			IProgressMonitor childMonitor = AbstractServerToolsPublisher.getSubMon(monitor, 100);
+			Exception e = RSERemotePublishHandler.wrapRemoteCallStatusTimeLimit(run, "null", "null", null, 15000, childMonitor);
+			if( e == null )
+				return Status.OK_STATUS;
+			return new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FAIL,
+					"The remote server " + connectionName + " is currently not responding to file system requests.", e);
+		}
+		return new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FAIL,
+				"Unable to communicate with remote connection: " + connectionName, caught);
 	}
 	
 	public IPath getRemoteRootFolder() {

Modified: branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java
===================================================================
--- branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java	2012-07-05 12:19:27 UTC (rev 42407)
+++ branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.rse.core/src/org/jboss/ide/eclipse/as/rse/core/RSERemotePublishHandler.java	2012-07-05 12:20:58 UTC (rev 42408)
@@ -45,13 +45,20 @@
 		return shouldRestartModule;
 	}
 	
-	private interface RunnableWithProgress2 {
-		public void run(IProgressMonitor monitor) throws CoreException, SystemMessageException, RuntimeException;
+	abstract static class RunnableWithProgress2 {
+		private String name;
+		public RunnableWithProgress2(String name){
+			this.name = name;
+		}
+		public abstract void run(IProgressMonitor monitor) throws CoreException, SystemMessageException, RuntimeException;
+		public String getName() {
+			return name;
+		}
 	}
 	
-	protected IStatus generateFailStatus(String message, String resource, Exception sme) {
-		String connectionName = RSEUtils.getRSEConnectionName(method.getBehaviour().getServer());
-		IHost host = RSEUtils.findHost(connectionName);
+	protected static IStatus generateFailStatus(String message, String resource, RSEPublishMethod method, Exception sme) {
+		String connectionName = method == null ? null : RSEUtils.getRSEConnectionName(method.getBehaviour().getServer());
+		IHost host = connectionName == null ? null : RSEUtils.findHost(connectionName);
 		IStatus s = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FAIL,
 				NLS.bind(message, resource, host == null ? null : host.getName()), sme);
 		return s;
@@ -60,12 +67,52 @@
 	private IStatus[] wrapRemoteCall(final RunnableWithProgress2 runnable, 
 			final String remoteResource, final String failErrorMessage, 
 			final IProgressMonitor monitor) throws CoreException, RuntimeException  {
-		return wrapRemoteCall(runnable, remoteResource, failErrorMessage, true, monitor);
+		return wrapRemoteCall(runnable, remoteResource, failErrorMessage, true, 
+				method, monitor);
 	}
+
+	static IStatus[] wrapRemoteCall(final RunnableWithProgress2 runnable, 
+			final String remoteResource, final String failErrorMessage, 
+			final boolean alwaysThrow, RSEPublishMethod method, final IProgressMonitor monitor) throws CoreException, RuntimeException  {
+		IStatus s = wrapRemoteCall2(runnable, remoteResource, failErrorMessage, 
+				alwaysThrow, method, monitor);
+		return s == null ? new IStatus[]{} : new IStatus[]{s};
+	}
 	
-	private IStatus[] wrapRemoteCall(final RunnableWithProgress2 runnable, 
+	static Exception wrapRemoteCallStatusTimeLimit(final RunnableWithProgress2 runnable, 
 			final String remoteResource, final String failErrorMessage, 
-			final boolean alwaysThrow, final IProgressMonitor monitor) throws CoreException, RuntimeException  {
+			RSEPublishMethod method, final int maxDelay, final IProgressMonitor monitor) {
+		Thread t = new Thread("Remote call timer") {
+			public void run() {
+				try {
+					Thread.sleep(maxDelay);
+					monitor.setCanceled(true);
+				} catch( InterruptedException ie) {
+					// Do Nothing
+				}
+			}
+		};
+		t.start();
+		try {
+			wrapRemoteCall2(runnable, remoteResource, failErrorMessage,
+					true, method, monitor);
+		} catch (CoreException e) {
+			if( e.getStatus().getSeverity() == IStatus.CANCEL ) {
+				return new CoreException(new Status(IStatus.CANCEL,RSECorePlugin.PLUGIN_ID, 
+						"The remote operation has been canceled because it did not finish in the alloted time (" + maxDelay + "ms)"));
+			}
+			return e;
+		} catch (RuntimeException e) {
+			return e;
+		} finally {
+			t.interrupt();
+		}
+		return null;
+	}
+	
+	static IStatus wrapRemoteCall2(final RunnableWithProgress2 runnable, 
+			final String remoteResource, final String failErrorMessage, 
+			final boolean alwaysThrow, final RSEPublishMethod method, final IProgressMonitor monitor) throws CoreException, RuntimeException  {
 		
 		final CoreException[] coreEx = new CoreException[1];
 		final RuntimeException[] runtEx = new RuntimeException[1];
@@ -80,7 +127,8 @@
 				} catch( CoreException ce ) { 
 					coreEx[0] = ce;
 				} catch( SystemMessageException sme ) {
-					IStatus stat = generateFailStatus(failErrorMessage, remoteResource, sme);
+					IStatus stat = generateFailStatus(failErrorMessage, 
+							remoteResource, method, sme);
 					if( alwaysThrow )
 						coreEx[0] = new CoreException(stat);
 					else
@@ -99,14 +147,19 @@
 			}
 		}
 		
-		if( monitor.isCanceled()) {
-			throw new CoreException(Status.CANCEL_STATUS);
+		if( monitor.isCanceled()) { 
+			if( t.isAlive()) {
+				t.interrupt();
+			}
+			IStatus s = new Status(IStatus.CANCEL, RSECorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FAIL,
+					"Remote operation was canceled: " + runnable.getName(), null);
+			throw new CoreException(s);
 		}
-		if( runtEx[0] != null ) throw runtEx[0];
-		if( coreEx[0] != null ) throw coreEx[0];
-		if( failStat[0] != null ) return failStat;
-		return new IStatus[]{};
-
+		// To ensure a full stack-trace, throw all new exceptions. 
+		if( runtEx[0] != null ) throw new RuntimeException(runtEx[0]);
+		if( coreEx[0] != null ) throw new CoreException(coreEx[0].getStatus()); 
+		if( failStat[0] != null ) return failStat[0];
+		return null;
 	}
 	
 	public IStatus[] copyFile(final IModuleFile mf, final IPath path,
@@ -116,7 +169,7 @@
 		final IPath remotePath = root.append(path);
 		
 		
-		RunnableWithProgress2 run = new RunnableWithProgress2() {
+		RunnableWithProgress2 run = new RunnableWithProgress2("Copy file to remote location: " + remotePath.toString()) {
 			public void run(IProgressMonitor monitor) throws CoreException,
 					SystemMessageException, RuntimeException {
 				method.getFileService().upload(file, remotePath.removeLastSegments(1).toString(), 
@@ -130,14 +183,14 @@
 	public IStatus[] deleteResource(final IPath path, final IProgressMonitor monitor)
 			throws CoreException {
 		final IPath remotePath = root.append(path);
-		RunnableWithProgress2 run = new RunnableWithProgress2() {
+		RunnableWithProgress2 run = new RunnableWithProgress2("Delete remote file: " + remotePath.toString()) {
 			public void run(IProgressMonitor monitor) throws CoreException,
 					SystemMessageException, RuntimeException {
 				method.getFileService().delete(remotePath.removeLastSegments(1).toString(), remotePath.lastSegment(), monitor);
 			}
 		};
 		
-		return wrapRemoteCall(run, remotePath.toString(), "failed to delete {0} on host {1}", false, monitor);
+		return wrapRemoteCall(run, remotePath.toString(), "failed to delete {0} on host {1}", false, method, monitor);
 	}
 
 	public IStatus[] makeDirectoryIfRequired(final IPath dir,
@@ -149,22 +202,23 @@
 		if( createdFolders.contains(toMake)) 
 			return new IStatus[]{Status.OK_STATUS};
 
-		RunnableWithProgress2 run = new RunnableWithProgress2() {
+		RunnableWithProgress2 run = new RunnableWithProgress2("Create Remote Directory: " + toMake.toString()) {
 			public void run(IProgressMonitor monitor) throws CoreException,
 					SystemMessageException, RuntimeException {
 				if( toMake.segmentCount() > 0 ) {
 					method.getFileService().createFolder(toMake.removeLastSegments(1).toString(), 
 							toMake.lastSegment(), monitor);
+					createdFolders.add(toMake);
 				}
 			}
 		};
-		return wrapRemoteCall(run, toMake.toString(), "failed to create folder {0} on host {1}", false, monitor);
+		return wrapRemoteCall(run, toMake.toString(), "failed to create folder {0} on host {1}", false, method, monitor);
 	}
 
 	public IStatus[] touchResource(final IPath path, IProgressMonitor monitor) {
 		final IPath file = root.append(path);
 		
-		RunnableWithProgress2 run = new RunnableWithProgress2() {
+		RunnableWithProgress2 run = new RunnableWithProgress2("Touch remote resource" + file.toString()) {
 			public void run(IProgressMonitor monitor) throws CoreException,
 					SystemMessageException, RuntimeException {
 				IRemoteFile rf = method.getFileServiceSubSystem().getRemoteFileObject(file.toString(), new NullProgressMonitor());
@@ -175,7 +229,7 @@
 			}
 		};
 		try {
-			return wrapRemoteCall(run, file.toString(), "failed to touch resource {0} on host {1}", false, monitor);
+			return wrapRemoteCall(run, file.toString(), "failed to touch resource {0} on host {1}", false, method, monitor);
 		} catch(CoreException ce) {
 			return new IStatus[]{ce.getStatus()};
 		}
@@ -188,7 +242,7 @@
 		final Boolean[] boolRet = new Boolean[1];
 		boolRet[0] = null;
 		
-		RunnableWithProgress2 run = new RunnableWithProgress2() {
+		RunnableWithProgress2 run = new RunnableWithProgress2("Verify remote file exists: " + file.toString()) {
 			public void run(IProgressMonitor monitor) throws CoreException,
 					SystemMessageException, RuntimeException {
 				IRemoteFile rf = method.getFileServiceSubSystem().getRemoteFileObject(file.toString(), new NullProgressMonitor());



More information about the jbosstools-commits mailing list