diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/RSECorePlugin.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/RSECorePlugin.java index 4906a6ccfa8..db497805377 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/RSECorePlugin.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/RSECorePlugin.java @@ -23,6 +23,7 @@ * David Dykstal (IBM) - [197167] adding notification and waiting for RSE model * Martin Oberhuber (Wind River) - [cleanup] Add API "since" Javadoc tags * Martin Oberhuber (Wind River) - [190231] Prepare API for UI/Non-UI Splitting + * David Dykstal (IBM) = [226958] add status values to waitForInitCompletion(phase) ********************************************************************************/ package org.eclipse.rse.core; @@ -143,6 +144,7 @@ public class RSECorePlugin extends Plugin { * Waits until the RSE has completed a specific phase of its initialization. * * @param phase the phase to wait for completion. + * @return an IStatus indicating how the initialization for that phase ended. * @throws InterruptedException if this wait was interrupted for some * reason. * @throws IllegalArgumentException if the phase is undefined. @@ -151,8 +153,8 @@ public class RSECorePlugin extends Plugin { * @see #INIT_MODEL * @since org.eclipse.rse.core 3.0 */ - public static void waitForInitCompletion(int phase) throws InterruptedException { - RSEInitJob.getInstance().waitForCompletion(phase); + public static IStatus waitForInitCompletion(int phase) throws InterruptedException { + return RSEInitJob.getInstance().waitForCompletion(phase); } /** diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/RSEInitJob.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/RSEInitJob.java index 8eba5939275..90de2840e95 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/RSEInitJob.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/RSEInitJob.java @@ -8,6 +8,7 @@ * David Dykstal (IBM) - [197167] adding notification and waiting for RSE model * David Dykstal (IBM) - [226728] NPE during init with clean workspace * David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding + * David Dykstal (IBM) = [226958] add status values to waitForInitCompletion(phase) ********************************************************************************/ package org.eclipse.rse.internal.core; @@ -59,27 +60,31 @@ public final class RSEInitJob extends Job { private class Phase { private volatile boolean isCancelled = false; private volatile boolean isComplete = false; + private IStatus completionStatus = Status.OK_STATUS; private int phaseNumber = 0; public Phase(int phaseNumber) { this.phaseNumber = phaseNumber; } - public synchronized void waitForCompletion() throws InterruptedException { + public synchronized IStatus waitForCompletion() throws InterruptedException { while (!isComplete && !isCancelled) { wait(); } if (isCancelled) { throw new InterruptedException(); } + return completionStatus; } - public void done() { + public void done(IStatus status) { synchronized (this) { isComplete = true; + completionStatus = status; notifyAll(); } notifyListeners(phaseNumber); } public synchronized void cancel() { isCancelled = true; + completionStatus = Status.CANCEL_STATUS; notifyAll(); } public boolean isComplete() { @@ -95,11 +100,15 @@ public final class RSEInitJob extends Job { public void done(IJobChangeEvent event) { IStatus status = event.getJob().getResult(); if (status.getSeverity() == IStatus.CANCEL) { - modelPhase.cancel(); - initializerPhase.cancel(); + if (!modelPhase.isComplete()) { + modelPhase.cancel(); + } + if (!initializerPhase.isComplete()) { + initializerPhase.cancel(); + } finalPhase.cancel(); } else { - finalPhase.done(); + finalPhase.done(status); } } public void running(IJobChangeEvent event) { @@ -184,7 +193,7 @@ public final class RSEInitJob extends Job { ISystemProfile defaultProfile = SystemProfileManager.getDefault().getDefaultPrivateSystemProfile(); ISystemModelChangeEvent event = new SystemModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ALL_RELOADED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_PROFILE, defaultProfile); RSECorePlugin.getTheSystemRegistry().fireEvent(event); - modelPhase.done(); + modelPhase.done(result); // instantiate and run initializers IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.rse.core.modelInitializers"); //$NON-NLS-1$ monitor.beginTask(RSECoreMessages.InitRSEJob_initializing_rse, elements.length); @@ -216,7 +225,7 @@ public final class RSEInitJob extends Job { } }); - initializerPhase.done(); + initializerPhase.done(result); // finish up - propogate cancel if necessary if (monitor.isCanceled()) { result = Status.CANCEL_STATUS; @@ -308,24 +317,27 @@ public final class RSEInitJob extends Job { /** * Wait for the completion of a particular phase * @param phase the phase to wait for + * @return the completion status for that phase. * @see RSECorePlugin#INIT_ALL * @see RSECorePlugin#INIT_MODEL * @see RSECorePlugin#INIT_INITIALIZER */ - public void waitForCompletion(int phase) throws InterruptedException { + public IStatus waitForCompletion(int phase) throws InterruptedException { + IStatus result = Status.OK_STATUS; switch (phase) { case RSECorePlugin.INIT_MODEL: - modelPhase.waitForCompletion(); + result = modelPhase.waitForCompletion(); break; case RSECorePlugin.INIT_INITIALIZER: - initializerPhase.waitForCompletion(); + result = initializerPhase.waitForCompletion(); break; case RSECorePlugin.INIT_ALL: - finalPhase.waitForCompletion(); + result = finalPhase.waitForCompletion(); break; default: throw new IllegalArgumentException("undefined phase"); //$NON-NLS-1$ } + return result; } /** diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/initialization/InitializationTest.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/initialization/InitializationTest.java index 7ea568f331a..4f453e6c18d 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/initialization/InitializationTest.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/initialization/InitializationTest.java @@ -7,12 +7,15 @@ * * Contributors: * David Dykstal (IBM) - [197167] initial contribution. + * David Dykstal (IBM) = [226958] add status values to waitForInitCompletion(phase) *******************************************************************************/ package org.eclipse.rse.tests.initialization; import junit.framework.TestCase; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.rse.core.IRSEInitListener; import org.eclipse.rse.core.RSECorePlugin; @@ -47,7 +50,15 @@ public class InitializationTest extends TestCase { public void testInitialization() { //-test-author-:DavidDykstal try { - RSECorePlugin.waitForInitCompletion(); + IStatus status = null; + status = RSECorePlugin.waitForInitCompletion(RSECorePlugin.INIT_MODEL); + assertEquals(Status.OK_STATUS, status); + status = RSECorePlugin.waitForInitCompletion(RSECorePlugin.INIT_INITIALIZER); + assertEquals(IStatus.WARNING, status.getSeverity()); // because of BadInitializer + status = RSECorePlugin.waitForInitCompletion(RSECorePlugin.INIT_ALL); + assertEquals(IStatus.WARNING, status.getSeverity()); // because of BadInitializer + status = RSECorePlugin.waitForInitCompletion(); + assertEquals(IStatus.WARNING, status.getSeverity()); // because of BadInitializer } catch (InterruptedException e) { fail("interrupted"); } catch (RuntimeException e) {