Skip to content

Commit

Permalink
Enhance start management of messagingsystem.ui (#7)
Browse files Browse the repository at this point in the history
Ensures preferenceStore() is accessed in the start method.
Ensures getConsoleIO is fully initialize before trying to send message
to it from other plugins.
This avoid deadlock

contributes to #6
  • Loading branch information
dvojtise authored Sep 11, 2024
1 parent 28b5ee4 commit 0d67581
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bundle-SymbolicName: org.eclipse.gemoc.commons.eclipse.messagingsystem.api;singl
Bundle-Version: 3.3.0.qualifier
Bundle-Vendor: Eclipse GEMOC Project
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Export-Package: org.eclipse.gemoc.commons.eclipse.messagingsystem.api,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Require-Bundle: org.eclipse.core.resources,
org.eclipse.ui.editors,
org.eclipse.gemoc.commons.eclipse.messagingsystem.api;bundle-version="1.0.0",
org.eclipse.swt
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.gemoc.commons.eclipse.messagingsystem.ui
Automatic-Module-Name: org.eclipse.gemoc.commons.eclipse.messagingsystem.ui

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Activator extends AbstractUIPlugin {

// protected MessagingSystem messaggingSystem;
protected EclipseConsoleIO consoleIO = null;

protected static boolean isPluginFullyInitialized = false;

/**
* The constructor
Expand All @@ -57,48 +59,56 @@ public Activator() {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;

Job j = new Job("Waiting workbench to redirect system.out to console") {

@Override
protected IStatus run(IProgressMonitor monitor) {
final boolean[] workbenchAvailable = new boolean[] { false };
Display.getDefault().syncExec(new Runnable() {

@Override
public void run() {
if (PlatformUI.isWorkbenchRunning()
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
workbenchAvailable[0] = true;
}

}
});
if (workbenchAvailable[0]) {
System.out.println("Workbench is available");
Display.getDefault().asyncExec(new Runnable() {


this.getPreferenceStore(); // get preference store on start in order to avoid entering in the synchronized section later
Boolean mustCapture = getPreferenceStore()
.getBoolean(PreferenceConstants.P_CAPTURE_SYSTEM_ERROUT);
if(mustCapture) {
Job j = new Job("Waiting workbench to redirect system.out to console") {

@Override
protected IStatus run(IProgressMonitor monitor) {
final boolean[] workbenchAvailable = new boolean[] { false };
Display.getDefault().syncExec(new Runnable() {

@Override
public void run() {
Boolean mustCapture = getPreferenceStore()
.getBoolean(PreferenceConstants.P_CAPTURE_SYSTEM_ERROUT);
if (mustCapture) {
captureSystemOutAndErr();
if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null
&& PlatformUI.getWorkbench().getWorkbenchWindows().length > 0 && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
workbenchAvailable[0] = true;
}
}
});
} else {
System.out.println("Waiting for the Workbench ...");
schedule(1000);

if (workbenchAvailable[0]) {
Boolean mustCapture = getPreferenceStore()
.getBoolean(PreferenceConstants.P_CAPTURE_SYSTEM_ERROUT);
if(mustCapture) {
Display.getDefault().syncExec(new Runnable() {

@Override
public void run() {
captureSystemOutAndErr();
isPluginFullyInitialized = true;
}
});
} else {
isPluginFullyInitialized = true;
}
} else {
System.out.println("Waiting for the Workbench ...");
schedule(1000);
}
return Status.OK_STATUS;
}
return Status.OK_STATUS;
}
};

j.schedule();

};

j.schedule(200);
}
else {
isPluginFullyInitialized = true;
}
}

/*
* (non-Javadoc)
*
Expand All @@ -122,16 +132,26 @@ public static Activator getDefault() {
return plugin;
}

// public MessagingSystem getMessaggingSystem() {
// return messaggingSystem;
// }


public void clearConsole() {
getConsoleIO().clear();
}

public ConsoleIO getConsoleIO() {
synchronized public ConsoleIO getConsoleIO() {
// makes sure that external call to getConsoleIO() occurs only when the plugin is fully operational
// ie. workbench is started and system.out is possibly redirected
while (!isPluginFullyInitialized) {
try {
System.out.println("waiting messagingsystem.ui.Activator.isPluginFullyInitialized");
Thread.sleep(500);
} catch (InterruptedException e) {}
}
return getConsoleIOInternal();
}
private ConsoleIO getConsoleIOInternal() {
if (consoleIO == null) {

String bundleSymbolicName = getBundle().getHeaders().get("Bundle-SymbolicName").toString();
String consoleUId = bundleSymbolicName + this.hashCode();
consoleIO = EclipseConsoleIOFactory.getInstance().getConsoleIO(consoleUId,
Expand All @@ -148,19 +168,20 @@ public ConsoleIO getConsoleIO() {
* default console
*/
public void captureSystemOutAndErr() {
Activator.getDefault().getConsoleIO().print("Redirecting System.out and System.err to this console.\n");

if (originalSystemOut != System.out) {
originalSystemOut = System.out;
TeeOutputStream teeOutputStream = new TeeOutputStream(originalSystemOut,
new EclipseConsoleOutputStream(Activator.getDefault().getConsoleIO(), false));
new EclipseConsoleOutputStream(Activator.getDefault().getConsoleIOInternal(), false));
System.setOut(new PrintStream(teeOutputStream));
}
if (originalSystemErr != System.err) {
originalSystemErr = System.err;
TeeOutputStream teeOutputStream = new TeeOutputStream(originalSystemErr,
new EclipseConsoleOutputStream(Activator.getDefault().getConsoleIO(), true));
new EclipseConsoleOutputStream(Activator.getDefault().getConsoleIOInternal(), true));
System.setErr(new PrintStream(teeOutputStream));
}
System.out.println("System.out and System.err copied to Eclipse console");
}

/**
Expand Down

0 comments on commit 0d67581

Please sign in to comment.