Skip to content

Commit 666dbbb

Browse files
committed
This revison fixes a bug in the "open project" command. If a project was
already open, this operation would sometimes deadlock presumably because the command runs in the event thread and requires another event thread operation to complete. The revised version first closes the existing project before asking the use to select the new project file (using a file selector). The following files were modified: modified: build.xml modified: src/edu/rice/cs/drjava/model/AbstractGlobalModel.java modified: src/edu/rice/cs/drjava/model/GlobalModelJUnitTest.java modified: src/edu/rice/cs/drjava/model/GlobalModelTestCase.java modified: src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java modified: src/edu/rice/cs/drjava/model/junit/JUnitTestRunner.java modified: src/edu/rice/cs/drjava/ui/MainFrame.java
1 parent 600e7f2 commit 666dbbb

File tree

7 files changed

+42
-47
lines changed

7 files changed

+42
-47
lines changed

drjava/build.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,7 @@
880880
</replace>
881881
</target>
882882

883-
<!-- Standardize all newline character sequences. Subversion takes care of this
884-
automatically, but sometimes files crop up with the wrong sequence.-->
883+
<!-- Standardize all newline character sequences.-->
885884
<target name="fix-newlines" description="Standardize newline character sequences in all text files">
886885
<!-- If we're in Windows, use \r\n -->
887886
<condition property="newline-code" value="crlf">
@@ -1151,7 +1150,6 @@
11511150
value="${ant.project.name}${tag-append}-${DSTAMP}-${TSTAMP}"/>
11521151
</target>
11531152

1154-
11551153
<!-- Sets "already-generated" if "generate-file" is more recent than "generate-sourcefile";
11561154
otherwise, the out-of-date target file is deleted (if it exists). Note that, since
11571155
properties can only be set once, this should happen underneath an "antcall". -->

drjava/src/edu/rice/cs/drjava/model/AbstractGlobalModel.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,24 +1812,22 @@ public void reloadProject(File file, HashMap<OpenDefinitionsDocument, DocumentIn
18121812
setProjectChanged(projChanged);
18131813
}
18141814

1815-
/** Parses the given project file and loads it into the document navigator
1816-
* and resets interactions pane. Assumes preceding project, if any, has
1817-
* already been closed.
1818-
*
1819-
* @param projectFile The project file to parse
1820-
* @throws IOException if an IO operation fails
1821-
* @throws MalformedProjectFileException if one of the project files was malformed
1822-
*/
1815+
/** Parses the given project file and loads it into the document navigator and resets interactions pane. Assumes
1816+
* that any existing project has been closed.
1817+
* @param projectFile The project file to parse
1818+
* @throws IOException if an IO operation fails
1819+
* @throws MalformedProjectFileException if one of the project files was malformed
1820+
*/
18231821
public void openProject(File projectFile) throws IOException, MalformedProjectFileException {
1824-
_loadProject(ProjectFileParserFacade.ONLY.parse(projectFile));
1822+
_loadProject(ProjectFileParserFacade.ONLY.parse(projectFile)); // resets interactions if successful
18251823
}
18261824

18271825
/** Loads the specified project into the document navigator and opens all of
1828-
* the files (if not already open).
1829-
* Assumes that any prior project has been closed. Only runs in event thread.
1830-
* @param ir The project file to load
1831-
* @throws IOException if an IO operation fails
1832-
*/
1826+
* the files (if not already open).
1827+
* Assumes that any prior project has been closed. Only runs in event thread.
1828+
* @param ir The project file to load
1829+
* @throws IOException if an IO operation fails
1830+
*/
18331831
private void _loadProject(final ProjectFileIR ir) throws IOException {
18341832

18351833
assert EventQueue.isDispatchThread();
@@ -2011,16 +2009,16 @@ public boolean accept(OpenDefinitionsDocument d) {
20112009
public void autoRefreshProject() { openNewFilesInProject(); }
20122010

20132011
/** Performs any needed operations on the model after project files have been
2014-
* closed. This method is not responsible for closing any files; both the
2015-
* files in the project and the project file have already been closed (by
2016-
* MainFrame._closeProject()). Resets interations unless suppressReset is
2017-
* true, which only happens when DrJava is quitting.
2018-
*
2019-
* @param suppressReset false if we want to reset the interactions pane; true otherwise
2020-
*/
2012+
* closed. This method is not responsible for closing any files; both the
2013+
* files in the project and the project file have already been closed (by
2014+
* MainFrame._closeProject()). Resets interations unless suppressReset is
2015+
* true, which only happens when DrJava is quitting.
2016+
*
2017+
* @param suppressReset false if we want to reset the interactions pane; true otherwise
2018+
*/
20212019
public void closeProject(boolean suppressReset) {
2022-
setDocumentNavigator(new AWTContainerNavigatorFactory<OpenDefinitionsDocument>().
2023-
makeListNavigator(getDocumentNavigator()));
2020+
IDocumentNavigator<OpenDefinitionsDocument> nav = getDocumentNavigator();
2021+
setDocumentNavigator(new AWTContainerNavigatorFactory<OpenDefinitionsDocument>().makeListNavigator(nav));
20242022
setFileGroupingState(makeFlatFileGroupingState());
20252023

20262024
// remove previous listeners

drjava/src/edu/rice/cs/drjava/model/GlobalModelJUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
*/
5353
public final class GlobalModelJUnitTest extends GlobalModelTestCase {
5454

55-
private static Log _log = new Log("GlobalModelTest.txt", true);
55+
private static Log _log = new Log("GlobalModelTest.txt", false);
5656

5757
/** Whether or not to print debugging output. */
5858
static final boolean printMessages = true;

drjava/src/edu/rice/cs/drjava/model/GlobalModelTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
*/
7676
public abstract class GlobalModelTestCase extends MultiThreadedTestCase {
7777

78-
public static final Log _log = new Log("GlobalModelTest.txt", true);
78+
public static final Log _log = new Log("GlobalModelTest.txt", false);
7979

8080
protected volatile DefaultGlobalModel _model;
8181
protected volatile InteractionsController _interactionsController;

drjava/src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
*/
9191
public class JUnitTestManager {
9292

93-
protected static final Log _log = new Log("JUnitTestManager.txt", true);
93+
protected static final Log _log = new Log("JUnitTestManager.txt", false);
9494

9595
/** The interface to the master JVM via RMI. */
9696
private final JUnitModelCallback _jmc;

drjava/src/edu/rice/cs/drjava/model/junit/JUnitTestRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949
public class JUnitTestRunner extends BaseTestRunner {
5050

51-
protected static final Log _log = new Log("JUnitTestManager.txt", true);
51+
protected static final Log _log = new Log("JUnitTestManager.txt", false);
5252

5353
/** Receives updates on the test suite's progress. */
5454
private JUnitModelCallback _jmc;

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4854,29 +4854,28 @@ private void _resetNavigatorPane() {
48544854
_updateBackgroundColor();
48554855
}
48564856

4857-
/** Asks the user to select the project file to open and starts the process of opening the project. */
4858-
private void _openProject() { openProject(_openProjectSelector); }
4857+
/** Closes existing project if one exists, asks the user to select the project file to open, and opens it. */
4858+
private void _openProject() {
4859+
if (_model.isProjectActive()) closeProject(); // does not reset interactions
4860+
openProject(_openProjectSelector); // resets interactions if successful
4861+
}
48594862

4860-
public void openProject(FileOpenSelector projectSelector) {
4861-
4862-
try {
4863+
/** Assumes any existing project has already been closed. */
4864+
public void openProject(final FileOpenSelector projectSelector) {
4865+
try {
48634866
final File[] files = projectSelector.getFiles();
48644867
if (files.length < 1)
48654868
throw new IllegalStateException("Open project file selection not canceled but no project file was selected.");
48664869
final File file = files[0];
4867-
4868-
updateStatusField("Opening project " + file);
4869-
4870-
try {
4871-
hourglassOn();
4872-
// make sure there are no open projects
4873-
if (! _model.isProjectActive() || (_model.isProjectActive() && _closeProject())) _openProjectHelper(file);
4874-
}
4875-
catch(Exception e) { e.printStackTrace(System.out); }
4876-
finally { hourglassOff(); }
4870+
if (file != null && file != FileOps.NULL_FILE)
4871+
Utilities.invokeLater(new Runnable() {
4872+
public void run() {
4873+
updateStatusField("Opening project " + file);
4874+
_openProjectHelper(file);
4875+
}
4876+
});
48774877
}
4878-
catch(OperationCanceledException oce) { /* do nothing, we just won't open anything */ }
4879-
4878+
catch(OperationCanceledException oce) { return; /* do nothing if getFiles() fails; we just don't open anything */ }
48804879
}
48814880

48824881
/** Oversees the opening of the project by delegating to the model to parse and initialize the project

0 commit comments

Comments
 (0)