diff options
Diffstat (limited to 'target_explorer')
4 files changed, 93 insertions, 74 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java index a10717701..fa2a64556 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/ChannelManager.java @@ -847,10 +847,10 @@ public final class ChannelManager extends PlatformObject implements IChannelMana // Reset the error error = null; - } else { - available.add(valueAdd); } + if (error == null) available.add(valueAdd); + // If the value-add failed to launch, no other value-add's are launched if (error != null) { done.doneLaunchValueAdd(error, available); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/AbstractExternalValueAdd.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/AbstractExternalValueAdd.java index 3a565a078..07d50d6b9 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/AbstractExternalValueAdd.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/AbstractExternalValueAdd.java @@ -202,12 +202,8 @@ public abstract class AbstractExternalValueAdd extends AbstractValueAdd { try { // Check if the process exited right after the launch int exitCode = process.exitValue(); - // Died -> Read the error output if there is any - String output = launcher.getOutputReader() != null ? launcher.getOutputReader().getOutput() : null; - String cause = output != null && !"".equals(output) ? NLS.bind(Messages.AbstractExternalValueAdd_error_cause, output) : null; //$NON-NLS-1$ - // Create the exception - String message = NLS.bind(Messages.AbstractExternalValueAdd_error_processDied, Integer.valueOf(exitCode)); - error = new IOException(cause != null ? message + cause : message); + // Died -> Construct the error + error = onProcessDied(launcher, exitCode); } catch (IllegalThreadStateException e) { // Still running -> Associate the process with the entry entry.process = process; @@ -223,6 +219,15 @@ public abstract class AbstractExternalValueAdd extends AbstractValueAdd { // The agent is started with "-S" to write out the peer attributes in JSON format. int counter = 10; while (counter > 0 && output == null) { + try { + // Check if the process is still alive or died in the meanwhile + int exitCode = entry.process.exitValue(); + // Died -> Construct the error + error = onProcessDied(launcher, exitCode); + } catch (IllegalThreadStateException e) { /* ignored on purpose */ } + + if (error != null) break; + // Try to read in the output output = launcher.getOutputReader().getOutput(); if ("".equals(output) || output.indexOf("Server-Properties:") == -1) { //$NON-NLS-1$ //$NON-NLS-2$ @@ -235,7 +240,7 @@ public abstract class AbstractExternalValueAdd extends AbstractValueAdd { } counter--; } - if (output == null) { + if (output == null && error == null) { error = new IOException(Messages.AbstractExternalValueAdd_error_failedToReadOutput); } } @@ -305,14 +310,20 @@ public abstract class AbstractExternalValueAdd extends AbstractValueAdd { if (launcher.getOutputReader() != null) { launcher.getOutputReader().setBuffering(false); } + // Stop the buffering of the error reader + if (launcher.getErrorReader() != null) { + launcher.getErrorReader().setBuffering(false); + } + + // On error, dispose the entry + if (error != null) entry.dispose(); } else { error = new FileNotFoundException(NLS.bind(Messages.AbstractExternalValueAdd_error_invalidLocation, this.getId())); } IStatus status = Status.OK_STATUS; if (error != null) { - status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), - error.getLocalizedMessage(), error); + status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), error.getLocalizedMessage(), error); } done.done(AbstractExternalValueAdd.this, status); @@ -326,6 +337,25 @@ public abstract class AbstractExternalValueAdd extends AbstractValueAdd { protected abstract IPath getLocation(); /** + * Called if the value add process dies while launching. + * + * @param launcher The value add launcher. Must not be <code>null</code>. + * @param exitCode The process exit code. + * + * @return The error to report. + */ + protected Throwable onProcessDied(ValueAddLauncher launcher, int exitCode) { + Assert.isNotNull(launcher); + + // Read the error output if there is any + String output = launcher.getErrorReader() != null ? launcher.getErrorReader().getOutput() : null; + String cause = output != null && !"".equals(output) ? NLS.bind(Messages.AbstractExternalValueAdd_error_cause, output) : null; //$NON-NLS-1$ + // Create the exception + String message = NLS.bind(Messages.AbstractExternalValueAdd_error_processDied, Integer.valueOf(exitCode)); + return new IOException(cause != null ? message + cause : message); + } + + /** * Create a new value-add launcher instance. * * @param id The target peer id. Must not be <code>null</code>. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/ValueAddLauncher.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/ValueAddLauncher.java index 2a43bbca8..b7a4949ee 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/ValueAddLauncher.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/va/ValueAddLauncher.java @@ -154,9 +154,8 @@ public class ValueAddLauncher extends ProcessLauncher { outputReader = new ProcessOutputReaderThread(path.lastSegment(), new InputStream[] { process.getInputStream() }); outputReader.start(); - // Launch the process error reader (not buffering) + // Launch the process error reader errorReader = new ProcessOutputReaderThread(path.lastSegment(), new InputStream[] { process.getErrorStream() }); - errorReader.setBuffering(false); errorReader.start(); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java index 8cdee75c7..73f2d150a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java @@ -19,21 +19,18 @@ import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; -import org.eclipse.tcf.te.runtime.stepper.StepperAttributeUtil; import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.runtime.utils.ProgressHelper; import org.eclipse.tcf.te.runtime.utils.StatusHelper; import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.interfaces.steps.ITcfStepAttributes; +import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; -import org.eclipse.tcf.te.tcf.locator.model.Model; import org.eclipse.tcf.te.tcf.locator.nls.Messages; /** @@ -59,9 +56,9 @@ public class WaitForReadyStep extends AbstractPeerModelStep { */ @Override public void execute(final IStepContext context, final IPropertiesContainer data, final IFullQualifiedId fullQualifiedId, final IProgressMonitor monitor, final ICallback callback) { - // Trigger a refresh of the model to read in the newly created static peer - final ILocatorModelRefreshService service = Model.getModel().getService(ILocatorModelRefreshService.class); - if (service != null && !Boolean.getBoolean("WaitForReadyStep.skip")) { //$NON-NLS-1$ + final IPeerModel peerModel = getActivePeerModelContext(context, data, fullQualifiedId); + + if (peerModel != null && !Boolean.getBoolean("WaitForReadyStep.skip")) { //$NON-NLS-1$ Protocol.invokeLater(new Runnable() { final Runnable thisRunnable = this; int refreshCount = 0; @@ -75,48 +72,58 @@ public class WaitForReadyStep extends AbstractPeerModelStep { String message = NLS.bind(Messages.WaitForReadyStep_error_timeout, getActivePeerContext(context, data, fullQualifiedId).getName()); callback(data, fullQualifiedId, callback, StatusHelper.getStatus(new TimeoutException(message)), null); } - else if (getActivePeerModelContext(context, data, fullQualifiedId).isProperty(IPeerModelProperties.PROP_STATE, IPeerModelProperties.STATE_WAITING_FOR_READY)) { - // Refresh the model now (must be executed within the TCF dispatch thread) - service.refresh(new Callback() { - @Override - protected void internalDone(Object caller, org.eclipse.core.runtime.IStatus status) { - refreshCount++; - ProgressHelper.worked(monitor, 1); - Protocol.invokeLater(refreshCount < 20 ? 500 : 1000, thisRunnable); - } - }); - } else { - int state = getActivePeerModelContext(context, data, fullQualifiedId).getIntProperty(IPeerModelProperties.PROP_STATE); - if (state == IPeerModelProperties.STATE_CONNECTED || state == IPeerModelProperties.STATE_REACHABLE) { - Object wait = getParameters().get("wait"); //$NON-NLS-1$ - if (wait != null) { - try { - int waitValue = Integer.parseInt(wait.toString()); - ExecutorsUtil.waitAndExecute(waitValue, null); + // Try to open a channel to the target and check for errors + Tcf.getChannelManager().openChannel(peerModel.getPeer(), null, new IChannelManager.DoneOpenChannel() { + @Override + public void doneOpenChannel(final Throwable error, final IChannel channel) { + IStatus status = null; + + // If the channel open succeeded, we are done + if (error == null && channel != null && channel.getState() == IChannel.STATE_OPEN) { + status = Status.OK_STATUS; } - catch (Exception e) { + + // Close the channel right away + if (channel != null) Tcf.getChannelManager().closeChannel(channel); + + // If we have an OK status, we are done + if (status != null && status.isOK()) { + Object wait = getParameters().get("wait"); //$NON-NLS-1$ + if (wait != null) { + try { + int waitValue = Integer.parseInt(wait.toString()); + ExecutorsUtil.waitAndExecute(waitValue, null); + } + catch (Exception e) { + } + } + callback(data, fullQualifiedId, callback, status, null); } - } - callback(data, fullQualifiedId, callback, Status.OK_STATUS, null); - } - else { - @SuppressWarnings("synthetic-access") - String message = NLS.bind(Messages.WaitForReadyStep_error_state, getActivePeerContext(context, data, fullQualifiedId).getName()); - String cause = null; - if (state == IPeerModelProperties.STATE_ERROR) { - cause = getActivePeerModelContext(context, data, fullQualifiedId).getStringProperty(IPeerModelProperties.PROP_LAST_SCANNER_ERROR); - } + // License errors are reported to the user and breaks the wait immediately + if (error != null && error.getLocalizedMessage().contains("LMAPI error occured:")) { //$NON-NLS-1$ + callback(data, fullQualifiedId, callback, StatusHelper.getStatus(error), null); + } else if (peerModel.getIntProperty(IPeerModelProperties.PROP_STATE) == IPeerModelProperties.STATE_ERROR) { + @SuppressWarnings("synthetic-access") + String message = NLS.bind(Messages.WaitForReadyStep_error_state, getActivePeerContext(context, data, fullQualifiedId).getName()); - if (cause != null && !"".equals(cause.trim())) { //$NON-NLS-1$ - message += NLS.bind(Messages.WaitForReadyStep_error_reason_cause, cause); - } else { - message += Messages.WaitForReadyStep_error_reason_unknown; - } + String cause = peerModel.getStringProperty(IPeerModelProperties.PROP_LAST_SCANNER_ERROR); + if (cause != null && !"".equals(cause.trim())) { //$NON-NLS-1$ + message += NLS.bind(Messages.WaitForReadyStep_error_reason_cause, cause); + } else { + message += Messages.WaitForReadyStep_error_reason_unknown; + } - callback(data, fullQualifiedId, callback, StatusHelper.getStatus(new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), message))), null); - } + callback(data, fullQualifiedId, callback, StatusHelper.getStatus(new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), message))), null); + } else { + // Try again until timed out + refreshCount++; + ProgressHelper.worked(monitor, 1); + Protocol.invokeLater(refreshCount < 20 ? 500 : 1000, thisRunnable); + } + } + }); } } }); @@ -133,21 +140,4 @@ public class WaitForReadyStep extends AbstractPeerModelStep { public int getTotalWork(IStepContext context, IPropertiesContainer data) { return 100; } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.stepper.steps.AbstractStep#rollback(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.core.runtime.IStatus, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) - */ - @Override - public void rollback(IStepContext context, IPropertiesContainer data, IStatus status, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor, ICallback callback) { - final IChannel channel = (IChannel)StepperAttributeUtil.getProperty(ITcfStepAttributes.ATTR_CHANNEL, fullQualifiedId, data); - if (channel != null) { - Protocol.invokeAndWait(new Runnable() { - @Override - public void run() { - Tcf.getChannelManager().closeChannel(channel); - } - }); - } - super.rollback(context, data, status, fullQualifiedId, monitor, callback); - } } |