mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-14 12:35:22 +02:00
[226958] [api] Inconsistent RSECorePlugin.waitForInitCompletion() return value
https://bugs.eclipse.org/bugs/show_bug.cgi?id=226958
This commit is contained in:
parent
ad938e2a5d
commit
40913e3cea
3 changed files with 39 additions and 14 deletions
|
@ -23,6 +23,7 @@
|
||||||
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
|
* 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) - [cleanup] Add API "since" Javadoc tags
|
||||||
* Martin Oberhuber (Wind River) - [190231] Prepare API for UI/Non-UI Splitting
|
* 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;
|
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.
|
* Waits until the RSE has completed a specific phase of its initialization.
|
||||||
*
|
*
|
||||||
* @param phase the phase to wait for completion.
|
* @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
|
* @throws InterruptedException if this wait was interrupted for some
|
||||||
* reason.
|
* reason.
|
||||||
* @throws IllegalArgumentException if the phase is undefined.
|
* @throws IllegalArgumentException if the phase is undefined.
|
||||||
|
@ -151,8 +153,8 @@ public class RSECorePlugin extends Plugin {
|
||||||
* @see #INIT_MODEL
|
* @see #INIT_MODEL
|
||||||
* @since org.eclipse.rse.core 3.0
|
* @since org.eclipse.rse.core 3.0
|
||||||
*/
|
*/
|
||||||
public static void waitForInitCompletion(int phase) throws InterruptedException {
|
public static IStatus waitForInitCompletion(int phase) throws InterruptedException {
|
||||||
RSEInitJob.getInstance().waitForCompletion(phase);
|
return RSEInitJob.getInstance().waitForCompletion(phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
|
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
|
||||||
* David Dykstal (IBM) - [226728] NPE during init with clean workspace
|
* David Dykstal (IBM) - [226728] NPE during init with clean workspace
|
||||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
* 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;
|
package org.eclipse.rse.internal.core;
|
||||||
|
|
||||||
|
@ -59,27 +60,31 @@ public final class RSEInitJob extends Job {
|
||||||
private class Phase {
|
private class Phase {
|
||||||
private volatile boolean isCancelled = false;
|
private volatile boolean isCancelled = false;
|
||||||
private volatile boolean isComplete = false;
|
private volatile boolean isComplete = false;
|
||||||
|
private IStatus completionStatus = Status.OK_STATUS;
|
||||||
private int phaseNumber = 0;
|
private int phaseNumber = 0;
|
||||||
public Phase(int phaseNumber) {
|
public Phase(int phaseNumber) {
|
||||||
this.phaseNumber = phaseNumber;
|
this.phaseNumber = phaseNumber;
|
||||||
}
|
}
|
||||||
public synchronized void waitForCompletion() throws InterruptedException {
|
public synchronized IStatus waitForCompletion() throws InterruptedException {
|
||||||
while (!isComplete && !isCancelled) {
|
while (!isComplete && !isCancelled) {
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
if (isCancelled) {
|
if (isCancelled) {
|
||||||
throw new InterruptedException();
|
throw new InterruptedException();
|
||||||
}
|
}
|
||||||
|
return completionStatus;
|
||||||
}
|
}
|
||||||
public void done() {
|
public void done(IStatus status) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
isComplete = true;
|
isComplete = true;
|
||||||
|
completionStatus = status;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
notifyListeners(phaseNumber);
|
notifyListeners(phaseNumber);
|
||||||
}
|
}
|
||||||
public synchronized void cancel() {
|
public synchronized void cancel() {
|
||||||
isCancelled = true;
|
isCancelled = true;
|
||||||
|
completionStatus = Status.CANCEL_STATUS;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
public boolean isComplete() {
|
public boolean isComplete() {
|
||||||
|
@ -95,11 +100,15 @@ public final class RSEInitJob extends Job {
|
||||||
public void done(IJobChangeEvent event) {
|
public void done(IJobChangeEvent event) {
|
||||||
IStatus status = event.getJob().getResult();
|
IStatus status = event.getJob().getResult();
|
||||||
if (status.getSeverity() == IStatus.CANCEL) {
|
if (status.getSeverity() == IStatus.CANCEL) {
|
||||||
|
if (!modelPhase.isComplete()) {
|
||||||
modelPhase.cancel();
|
modelPhase.cancel();
|
||||||
|
}
|
||||||
|
if (!initializerPhase.isComplete()) {
|
||||||
initializerPhase.cancel();
|
initializerPhase.cancel();
|
||||||
|
}
|
||||||
finalPhase.cancel();
|
finalPhase.cancel();
|
||||||
} else {
|
} else {
|
||||||
finalPhase.done();
|
finalPhase.done(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void running(IJobChangeEvent event) {
|
public void running(IJobChangeEvent event) {
|
||||||
|
@ -184,7 +193,7 @@ public final class RSEInitJob extends Job {
|
||||||
ISystemProfile defaultProfile = SystemProfileManager.getDefault().getDefaultPrivateSystemProfile();
|
ISystemProfile defaultProfile = SystemProfileManager.getDefault().getDefaultPrivateSystemProfile();
|
||||||
ISystemModelChangeEvent event = new SystemModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ALL_RELOADED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_PROFILE, defaultProfile);
|
ISystemModelChangeEvent event = new SystemModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ALL_RELOADED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_PROFILE, defaultProfile);
|
||||||
RSECorePlugin.getTheSystemRegistry().fireEvent(event);
|
RSECorePlugin.getTheSystemRegistry().fireEvent(event);
|
||||||
modelPhase.done();
|
modelPhase.done(result);
|
||||||
// instantiate and run initializers
|
// instantiate and run initializers
|
||||||
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.rse.core.modelInitializers"); //$NON-NLS-1$
|
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.rse.core.modelInitializers"); //$NON-NLS-1$
|
||||||
monitor.beginTask(RSECoreMessages.InitRSEJob_initializing_rse, elements.length);
|
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
|
// finish up - propogate cancel if necessary
|
||||||
if (monitor.isCanceled()) {
|
if (monitor.isCanceled()) {
|
||||||
result = Status.CANCEL_STATUS;
|
result = Status.CANCEL_STATUS;
|
||||||
|
@ -308,24 +317,27 @@ public final class RSEInitJob extends Job {
|
||||||
/**
|
/**
|
||||||
* Wait for the completion of a particular phase
|
* Wait for the completion of a particular phase
|
||||||
* @param phase the phase to wait for
|
* @param phase the phase to wait for
|
||||||
|
* @return the completion status for that phase.
|
||||||
* @see RSECorePlugin#INIT_ALL
|
* @see RSECorePlugin#INIT_ALL
|
||||||
* @see RSECorePlugin#INIT_MODEL
|
* @see RSECorePlugin#INIT_MODEL
|
||||||
* @see RSECorePlugin#INIT_INITIALIZER
|
* @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) {
|
switch (phase) {
|
||||||
case RSECorePlugin.INIT_MODEL:
|
case RSECorePlugin.INIT_MODEL:
|
||||||
modelPhase.waitForCompletion();
|
result = modelPhase.waitForCompletion();
|
||||||
break;
|
break;
|
||||||
case RSECorePlugin.INIT_INITIALIZER:
|
case RSECorePlugin.INIT_INITIALIZER:
|
||||||
initializerPhase.waitForCompletion();
|
result = initializerPhase.waitForCompletion();
|
||||||
break;
|
break;
|
||||||
case RSECorePlugin.INIT_ALL:
|
case RSECorePlugin.INIT_ALL:
|
||||||
finalPhase.waitForCompletion();
|
result = finalPhase.waitForCompletion();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("undefined phase"); //$NON-NLS-1$
|
throw new IllegalArgumentException("undefined phase"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,12 +7,15 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* David Dykstal (IBM) - [197167] initial contribution.
|
* David Dykstal (IBM) - [197167] initial contribution.
|
||||||
|
* David Dykstal (IBM) = [226958] add status values to waitForInitCompletion(phase)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.tests.initialization;
|
package org.eclipse.rse.tests.initialization;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
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.IRSEInitListener;
|
||||||
import org.eclipse.rse.core.RSECorePlugin;
|
import org.eclipse.rse.core.RSECorePlugin;
|
||||||
|
|
||||||
|
@ -47,7 +50,15 @@ public class InitializationTest extends TestCase {
|
||||||
public void testInitialization() {
|
public void testInitialization() {
|
||||||
//-test-author-:DavidDykstal
|
//-test-author-:DavidDykstal
|
||||||
try {
|
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) {
|
} catch (InterruptedException e) {
|
||||||
fail("interrupted");
|
fail("interrupted");
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue