Skip to content

Commit c7e182b

Browse files
author
rcartwright
committed
Made the creation of temp files more uniform by applying getCanonicalFile which converts the short name generated on Windows to a long name.
git-svn-id: file:///tmp/test-svn/trunk@3721 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent ce99ad7 commit c7e182b

20 files changed

+75
-127
lines changed

drjava/src/edu/rice/cs/drjava/CommandLineTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,76 +108,76 @@ public CommandLineTest(String name) {
108108
DrJava._initConfig();
109109
_mf = new MainFrame();
110110
try {
111-
f1 = File.createTempFile("DrJava-test", ".java");
111+
f1 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
112112
f1.deleteOnExit();
113113
f1_name = f1.getAbsolutePath();
114114
f1_contents = "abcde";
115115
FileWriter fw1 = new FileWriter(f1);
116116
fw1.write(f1_contents,0,f1_contents.length());
117117
fw1.close();
118-
f2 = File.createTempFile("DrJava-test", ".java");
118+
f2 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
119119
f2.deleteOnExit();
120120
f2_name = f2.getAbsolutePath();
121121
f2_contents = "fghijklm";
122122
FileWriter fw2 = new FileWriter(f2);
123123
fw2.write(f2_contents,0,f2_contents.length());
124124
fw2.close();
125-
f3 = File.createTempFile("DrJava-test", ".java");
125+
f3 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
126126
f3.deleteOnExit();
127127
f3_name = f3.getAbsolutePath();
128128
f3_contents = "nopqrstuvwxyz";
129129
FileWriter fw3 = new FileWriter(f3);
130130
fw3.write(f3_contents,0,f3_contents.length());
131131
fw3.close();
132-
f4 = File.createTempFile("DrJava-test", ".java");
132+
f4 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
133133
f4.deleteOnExit();
134134
f4_name = f4.getAbsolutePath();
135135
f4_contents = "abcde";
136136
FileWriter fw4 = new FileWriter(f4);
137137
fw4.write(f4_contents,0,f4_contents.length());
138138
fw4.close();
139-
f5 = File.createTempFile("DrJava-test", ".java");
139+
f5 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
140140
f5.deleteOnExit();
141141
f5_name = f5.getAbsolutePath();
142142
f5_contents = "fghijklm";
143143
FileWriter fw5 = new FileWriter(f5);
144144
fw5.write(f5_contents,0,f5_contents.length());
145145
fw5.close();
146-
f6 = File.createTempFile("DrJava-test", ".java");
146+
f6 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
147147
f6.deleteOnExit();
148148
f6_name = f6.getAbsolutePath();
149149
f6_contents = "nopqrstuvwxyz";
150150
FileWriter fw6 = new FileWriter(f6);
151151
fw6.write(f6_contents,0,f6_contents.length());
152152
fw6.close();
153-
f7 = File.createTempFile("DrJava-test", ".java");
153+
f7 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
154154
f7.deleteOnExit();
155155
f7_name = f7.getAbsolutePath();
156156
f7_contents = "abcde";
157157
FileWriter fw7 = new FileWriter(f7);
158158
fw7.write(f7_contents,0,f7_contents.length());
159159
fw7.close();
160-
f8 = File.createTempFile("DrJava-test", ".java");
160+
f8 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
161161
f8.deleteOnExit();
162162
f8_name = f8.getAbsolutePath();
163163
f8_contents = "fghijklm";
164164
FileWriter fw8 = new FileWriter(f8);
165165
fw8.write(f8_contents,0,f8_contents.length());
166166
fw8.close();
167167

168-
nof1 = File.createTempFile("DrJava-test", ".java");
168+
nof1 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
169169
nof1_name = nof1.getAbsolutePath();
170170
nof1.delete();
171-
nof2 = File.createTempFile("DrJava-test", ".java");
171+
nof2 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
172172
nof2_name = nof2.getAbsolutePath();
173173
nof2.delete();
174-
nof3 = File.createTempFile("DrJava-test", ".java");
174+
nof3 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
175175
nof3_name = nof3.getAbsolutePath();
176176
nof3.delete();
177-
nof4 = File.createTempFile("DrJava-test", ".java");
177+
nof4 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
178178
nof4_name = nof4.getAbsolutePath();
179179
nof4.delete();
180-
nof5 = File.createTempFile("DrJava-test", ".java");
180+
nof5 = File.createTempFile("DrJava-test", ".java").getCanonicalFile();
181181
nof5_name = nof5.getAbsolutePath();
182182
nof5.delete();
183183
}

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public static void main(final String[] args) {
119119
// Utilities.showDebug("Calling configureAndLoadDrJavaRoot with args = " + args);
120120
configureAndLoadDrJavaRoot(args);
121121

122+
// This obviously only runs in the main thread, not the UI thread, so use SwingUtilities rather than Utilities.
122123
SwingUtilities.invokeLater(new Runnable() {
123124
public void run() {
124125
try { Thread.currentThread().sleep(PAUSE_TIME); }

drjava/src/edu/rice/cs/drjava/DrJavaRoot.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ public static void main(String[] _filesToOpen) {
128128

129129
_openCommandLineFiles(mf, _filesToOpen, len);
130130

131-
/* setVibible is moved to the end of the eventqueue to be sure all files have finished loading and added to the
132-
* fileview before the MainFrame is set visible. When this was not done, occassionally a NullPointerException
133-
* was encountered on startup when specifying a file (ex: java -jar drjava.jar somefile.java)
131+
/* This call on invokeLater only runs in the main thread, so we use SwingUtilities rather than Utilities.
132+
* We use invokeLater here ensure all files have finished loading and added to the fileview before the MainFrame
133+
* is set visible. When this was not done, we occasionally encountered a NullPointerExceptio on startup when
134+
* specifying a file (ex: java -jar drjava.jar somefile.java)
134135
*/
135136
SwingUtilities.invokeLater(new Runnable(){ public void run(){mf.setVisible(true);}});
136137

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

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ public void fileClosed(OpenDefinitionsDocument doc) {
174174
listener.assertCloseCount(0);
175175
}
176176

177-
/**
178-
* Opens a file.
179-
*/
177+
/** Opens a file. */
180178
public void testOpenRealFile() throws BadLocationException, IOException {
181179
final File tempFile = writeToNewTempFile(BAR_TEXT);
182180

@@ -379,12 +377,8 @@ public void fileClosed(OpenDefinitionsDocument doc) {
379377

380378
}
381379

382-
/**
383-
* Opens multiple files.
384-
*/
385-
public void testOpenMultipleFiles()
386-
throws BadLocationException, IOException
387-
{
380+
/** Opens multiple files. */
381+
public void testOpenMultipleFiles() throws BadLocationException, IOException {
388382
final File tempFile1 = writeToNewTempFile(FOO_TEXT);
389383
final File tempFile2 = writeToNewTempFile(BAR_TEXT);
390384

@@ -494,22 +488,16 @@ public void fileClosed(OpenDefinitionsDocument doc) {
494488
}
495489
}
496490

497-
498-
/**
499-
* Attempts to open a non-existent file.
500-
*/
501-
public void testOpenMultipleNonexistentFiles() throws IOException
502-
{
491+
/** Attempts to open a non-existent file. */
492+
public void testOpenMultipleNonexistentFiles() throws IOException {
503493

504494
OpenDefinitionsDocument doc = null;
505495
final File tempFile1 = writeToNewTempFile(FOO_TEXT);
506496

507497
//TestListener listener = new TestListener();
508498
TestListener listener = new TestListener() {
509499

510-
public void fileNotFound(File f) {
511-
fileNotFoundCount++;
512-
}
500+
public void fileNotFound(File f) { fileNotFoundCount++; }
513501

514502
public void fileOpened(OpenDefinitionsDocument doc) {
515503
File file = null;
@@ -522,9 +510,7 @@ public void fileOpened(OpenDefinitionsDocument doc) {
522510
assertEquals("file to open", tempFile1.getCanonicalFile(), file.getCanonicalFile());
523511
openCount++;
524512
}
525-
catch (IOException ioe) {
526-
fail("could not get canonical file");
527-
}
513+
catch (IOException ioe) { fail("could not get canonical file"); }
528514
}
529515

530516
public void fileClosed(OpenDefinitionsDocument doc) {
@@ -646,11 +632,8 @@ public void fileClosed(OpenDefinitionsDocument doc) {
646632
assertContents(BAR_TEXT, doc2);
647633
}
648634

649-
/**
650-
* Attempts to make the first save of a document, but cancels instead.
651-
*/
652-
public void testCancelFirstSave() throws BadLocationException, IOException
653-
{
635+
/** Attempts to make the first save of a document, but cancels instead. */
636+
public void testCancelFirstSave() throws BadLocationException, IOException {
654637
OpenDefinitionsDocument doc = setupDocument(FOO_TEXT);
655638

656639
// No need to override methods since no events should be fired
@@ -662,9 +645,7 @@ public void testCancelFirstSave() throws BadLocationException, IOException
662645
assertContents(FOO_TEXT, doc);
663646
}
664647

665-
/**
666-
* Makes a first save of the current document.
667-
*/
648+
/** Makes a first save of the current document. */
668649
public void testRealSaveFirstSave() throws BadLocationException, IOException {
669650
OpenDefinitionsDocument doc = setupDocument(FOO_TEXT);
670651
final File file = tempFile();
@@ -699,11 +680,8 @@ public void fileSaved(OpenDefinitionsDocument doc) {
699680
FileOps.readFileAsString(file));
700681
}
701682

702-
/**
703-
* Saves a file already saved and overwrites its contents.
704-
*/
705-
public void testSaveAlreadySaved() throws BadLocationException, IOException
706-
{
683+
/** Saves a file already saved and overwrites its contents. */
684+
public void testSaveAlreadySaved() throws BadLocationException, IOException {
707685
//disable file backups, remember original setting
708686
Boolean backupStatus = DrJava.getConfig().getSetting(BACKUP_FILES);
709687
DrJava.getConfig().setSetting(BACKUP_FILES, Boolean.FALSE);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void testNoJUnitErrors() throws Exception {
184184
listener.checkCompileOccurred();
185185

186186
_runJUnit(doc);
187-
187+
188188
Utilities.clearEventQueue();
189189

190190
listener.assertJUnitStartCount(1);

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,24 @@ protected void changeDocumentText(String s, OpenDefinitionsDocument doc) throws
161161

162162
/** Create a new temporary file in _tempDir. */
163163
protected File tempFile() throws IOException {
164-
return File.createTempFile("DrJava-test", ".java", _tempDir);
164+
File f = File.createTempFile("DrJava-test", ".java", _tempDir).getCanonicalFile();
165+
// System.err.println("temp file created with name " + f);
166+
return f;
165167
}
166168

167-
/**
168-
* Create a new temporary file in _tempDir. Calls with the same
169-
* int will return the same filename, while calls with different
170-
* ints will return different filenames.
169+
/** Create a new temporary file in _tempDir. Calls with the same int will return the same filename, while calls
170+
* with different ints will return different filenames.
171171
*/
172172
protected File tempFile(int i) throws IOException {
173-
return File.createTempFile("DrJava-test" + i, ".java", _tempDir);
173+
return File.createTempFile("DrJava-test" + i, ".java", _tempDir).getCanonicalFile();
174174
}
175175

176176
/** Create a new temporary directory in _tempDir. */
177177
protected File tempDirectory() throws IOException {
178178
return FileOps.createTempDirectory("DrJava-test", _tempDir);
179179
}
180180

181-
protected File createFile(String name) {
182-
return new File(_tempDir, name);
183-
}
181+
protected File createFile(String name) { return new File(_tempDir, name); }
184182

185183
/** Given a .java file and a class file name, returns the corresponding .class file. */
186184
protected File classForJava(File sourceFile, String className) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public void testDisplayFilename() throws IOException, OperationCanceledException
314314
assertEquals("untitled display filename", "(Untitled)", _sdModel.getDisplayFilename(doc));
315315

316316
// Ends in ".java"
317-
File file = File.createTempFile("DrJava-filename-test", ".java", _tempDir);
317+
File file = File.createTempFile("DrJava-filename-test", ".java", _tempDir).getCanonicalFile();
318318
file.deleteOnExit();
319319
String name = file.getName();
320320
doc = _sdModel.openFile(new FileSelector(file));
@@ -323,14 +323,14 @@ public void testDisplayFilename() throws IOException, OperationCanceledException
323323
_sdModel.getDisplayFilename(doc));
324324

325325
// Doesn't contain ".java"
326-
file = File.createTempFile("DrJava-filename-test", ".txt", _tempDir);
326+
file = File.createTempFile("DrJava-filename-test", ".txt", _tempDir).getCanonicalFile();
327327
file.deleteOnExit();
328328
name = file.getName();
329329
doc = _sdModel.openFile(new FileSelector(file));
330330
assertEquals(".txt display filename", name, _sdModel.getDisplayFilename(doc));
331331

332332
// Doesn't end in ".java"
333-
file = File.createTempFile("DrJava-filename-test", ".java.txt", _tempDir);
333+
file = File.createTempFile("DrJava-filename-test", ".java.txt", _tempDir).getCanonicalFile();
334334
file.deleteOnExit();
335335
name = file.getName();
336336
doc = _sdModel.openFile(new FileSelector(file));

drjava/src/edu/rice/cs/drjava/model/cache/DocumentCacheTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ protected void createModel() {
9898

9999
/** Create a new temporary file in _tempDir. */
100100
protected File tempFile() throws IOException {
101-
return File.createTempFile("DrJava-test", ".java", _tempDir);
101+
return File.createTempFile("DrJava-test", ".java", _tempDir).getCanonicalFile();
102102
}
103103

104104
/** Create a new temporary file in _tempDir. Calls with the same
105105
* int will return the same filename, while calls with different
106106
* ints will return different filenames.
107107
*/
108108
protected File tempFile(int i) throws IOException {
109-
return File.createTempFile("DrJava-test" + i, ".java", _tempDir);
109+
return File.createTempFile("DrJava-test" + i, ".java", _tempDir).getCanonicalFile();
110110
}
111111

112112
protected OpenDefinitionsDocument openFile(final File f) throws IOException {

drjava/src/edu/rice/cs/drjava/model/debug/JPDADebugger.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,10 @@ protected ObjectReference _getInterpreterJVMRef()
315315
*/
316316
public synchronized void shutdown() {
317317
if (isReady()) {
318-
Runnable command = new Runnable() {
319-
public void run() {
320-
_model.removeListener(_watchListener);
321-
}
322-
};
323-
// use SwingUtilities.invokeLater rather than our own invokeLater
324-
// because this might be run from the event thread already, and we
325-
// don't want it to execute right now, just as soon as possible
318+
Runnable command = new Runnable() { public void run() { _model.removeListener(_watchListener); } };
319+
320+
/* Use SwingUtilities.invokeLater rather than Utilities.invokeLater because we want to defer executing this
321+
* code after pending events (that may involve the _watchListener) */
326322
SwingUtilities.invokeLater(command);
327323

328324
try {
@@ -335,9 +331,7 @@ public void run() {
335331
_log("Could not remove breakpoints/watches: " + de);
336332
}
337333

338-
try {
339-
_vm.dispose();
340-
}
334+
try { _vm.dispose(); }
341335
catch (VMDisconnectedException vmde) {
342336
//VM was shutdown prematurely
343337
}

drjava/src/edu/rice/cs/drjava/model/repl/HistoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void tearDown() throws Exception {
7878
*/
7979
public void testSaveAsExistsForOverwrite() throws IOException {
8080
_history.add("some text");
81-
final File file1 = File.createTempFile("DrJava-test", ".hist", _tempDir);
81+
final File file1 = File.createTempFile("DrJava-test", ".hist", _tempDir).getCanonicalFile();
8282
file1.deleteOnExit();
8383
try {
8484
_history.writeToFile(new WarningFileSelector(file1));

0 commit comments

Comments
 (0)