Skip to content

Commit

Permalink
[FIX][I] Stop session when current project is closed
Browse files Browse the repository at this point in the history
Stops the current session when the current project is closed. This is
done as the session state is dropped at that point, meaning we can no
longer work with the old session.

Furthermore, dropping the old session should guarantee that we don't
have any references to resources of the closed project. This is
necessary as trying to access these resources would lead to an assertion
error.
  • Loading branch information
tobous committed Feb 11, 2019
1 parent bd861a6 commit d5a696a
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import com.intellij.openapi.keymap.Keymap;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.project.Project;
import de.fu_berlin.inf.dpp.session.ISarosSession;
import de.fu_berlin.inf.dpp.session.ISarosSessionManager;
import de.fu_berlin.inf.dpp.session.SessionEndReason;
import de.fu_berlin.inf.dpp.util.ThreadUtils;
import java.awt.event.KeyEvent;
import java.io.InputStream;
import javax.swing.KeyStroke;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.LogLog;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,9 +22,13 @@
*/
public class SarosComponent implements com.intellij.openapi.components.ProjectComponent {

private static final Logger log = Logger.getLogger(SarosComponent.class);

/** This is the plugin ID that identifies the saros plugin in the IDEA ecosystem. */
public static final String PLUGIN_ID = "de.fu_berlin.inf.dpp.intellij";

private IntellijProjectLifecycle intellijProjectLifecycle;

public SarosComponent(final Project project) {
loadLoggers();

Expand Down Expand Up @@ -47,7 +56,9 @@ public SarosComponent(final Project project) {
LogLog.error("could not load saros property file 'saros.properties'", e);
}

IntellijProjectLifecycle.getInstance(project).start();
intellijProjectLifecycle = IntellijProjectLifecycle.getInstance(project);

intellijProjectLifecycle.start();
}

public static boolean isSwtBrowserEnabled() {
Expand Down Expand Up @@ -94,6 +105,16 @@ public void projectOpened() {

@Override
public void projectClosed() {
// TODO: Update project
ISarosSessionManager sarosSessionManager =
intellijProjectLifecycle.getSarosContext().getComponent(ISarosSessionManager.class);

ISarosSession currentSession = sarosSessionManager.getSession();

if (currentSession != null) {
ThreadUtils.runSafeAsync(
"StopSession",
log,
() -> sarosSessionManager.stopSession(SessionEndReason.LOCAL_USER_LEFT));
}
}
}

0 comments on commit d5a696a

Please sign in to comment.