Skip to content

Commit 0f1ebde

Browse files
author
mgricken
committed
Made fixes to the XML project file reader for Windows systems,
changed several tests so they do not leave as many temp files behind on Windows. git-svn-id: file:///tmp/test-svn/trunk@4434 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent c3fb656 commit 0f1ebde

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,6 @@ else if (doc.isAuxiliaryFile()) {
13821382
*/
13831383
public void saveProject(File file, Hashtable<OpenDefinitionsDocument, DocumentInfoGetter> info) throws IOException {
13841384
ProjectProfile builder = _makeProjectProfile(file, info);
1385-
System.out.println("builder.getAuxiliaryFiles().length = "+builder.getAuxiliaryFiles().length);
13861385
// write to disk
13871386
builder.write();
13881387

@@ -1818,7 +1817,10 @@ public void run() {
18181817

18191818
/** Prepares this model to be thrown away. Never called outside of tests. This version ignores the slave JVM. */
18201819
public void dispose() {
1821-
synchronized(_documentsRepos) { _documentsRepos.clear(); }
1820+
synchronized(_documentsRepos) {
1821+
closeAllFiles();
1822+
_documentsRepos.clear();
1823+
}
18221824
Utilities.invokeLater(new SRunnable() {
18231825
public void run() { _documentNavigator.clear(); } // this operation must run in event thread
18241826
});

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ public void setUp() throws Exception {
122122
/** Teardown for each test case, which recursively deletes the temporary directory created in setUp. */
123123
public void tearDown() throws Exception {
124124
_log.log("Tearing down " + this);
125-
boolean ret = IOUtil.deleteRecursively(_tempDir);
126-
assertTrue("delete temp directory " + _tempDir, ret);
127-
128125
_model.dispose();
126+
127+
/*boolean ret =*/ IOUtil.deleteOnExitRecursively(_tempDir);
128+
//assertTrue("delete temp directory " + _tempDir, ret);
129+
129130
_tempDir = null;
130131
_model = null;
131132

drjava/src/edu/rice/cs/drjava/project/ProjectTest.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,16 @@ public void testWriteFile() throws IOException, MalformedProjectFileException {
234234
fb.setBuildDirectory(new File(parent, "built"));
235235
fb.setWorkingDirectory(new File(parent, "src"));
236236
fb.setMainClass(new File(pf.getParentFile(), "dir1/testfile1.java"));
237-
238-
String expected = "";
239-
String received = "";
240237
fb.write();
241238

239+
StringBuilder received = new StringBuilder();
242240
FileReader fr = new FileReader(pf);
243241
int c = fr.read();
244242
while (c >= 0) {
245-
received += (char) c;
243+
received.append((char)c);
246244
c = fr.read();
247245
}
246+
fr.close();
248247
// assertEquals("Make relative", "dir1/test.java",
249248
// fb.makeRelative(new File(pf.getParentFile(),"dir1/test.java")));
250249
// assertEquals("The file written by the builder", expected, received);
@@ -266,13 +265,15 @@ public void testWriteFile() throws IOException, MalformedProjectFileException {
266265
// pfir.getSourceFiles()[0].getPath());
267266
// assertEquals("last source filename", new File(parent,"/dir3/testfile5.java").getPath(),
268267
// pfir.getSourceFiles()[4].getPath());
269-
assertEquals("first aux filename", new File(parent,"test/testfile6.java").getPath(),
270-
pfir.getAuxiliaryFiles()[0].getPath());
268+
assertEquals("first aux filename", new File(parent,"test/testfile6.java").getCanonicalPath(),
269+
pfir.getAuxiliaryFiles()[0].getCanonicalPath());
271270
assertEquals("last collapsed path", "./[ Source Files ]/dir1/", pfir.getCollapsedPaths()[0]);
272-
assertEquals("build-dir name", buildDir, pfir.getBuildDirectory());
273-
assertEquals("work-dir name", srcDir, pfir.getWorkingDirectory());
274-
assertEquals("classpath name", new File(parent,"lib"), IterUtil.first(pfir.getClassPaths()));
275-
assertEquals("main-class name", new File(parent,"/dir1/testfile1.java"), pfir.getMainClass());
271+
assertEquals("build-dir name", buildDir.getCanonicalPath(), pfir.getBuildDirectory().getCanonicalPath());
272+
assertEquals("work-dir name", srcDir.getCanonicalPath(), pfir.getWorkingDirectory().getCanonicalPath());
273+
assertEquals("classpath name", new File(parent,"lib").getCanonicalPath(),
274+
IterUtil.first(pfir.getClassPaths()).getCanonicalPath());
275+
assertEquals("main-class name", new File(parent,"dir1/testfile1.java").getCanonicalPath(),
276+
pfir.getMainClass().getCanonicalPath());
276277
pf.delete();
277278
}
278279

@@ -422,17 +423,16 @@ public void testWriteFilePJT() throws IOException, MalformedProjectFileException
422423
fb.setBuildDirectory(new File(parent, "built"));
423424
fb.setWorkingDirectory(new File(parent, "src"));
424425
fb.setMainClass(new File(pf.getParentFile(), "dir1/testfile1.java"));
425-
426-
String expected = "";
427-
String received = "";
428426
fb.writeOld();
429427

428+
StringBuilder received = new StringBuilder();
430429
FileReader fr = new FileReader(pf);
431430
int c = fr.read();
432431
while (c >= 0) {
433-
received += (char) c;
432+
received.append((char)c);
434433
c = fr.read();
435434
}
435+
fr.close();
436436
// assertEquals("Make relative", "dir1/test.java",
437437
// fb.makeRelative(new File(pf.getParentFile(),"dir1/test.java")));
438438
// assertEquals("The file written by the builder", expected, received);
@@ -484,17 +484,16 @@ public void testWriteFileXML() throws IOException, MalformedProjectFileException
484484
fb.setBuildDirectory(new File(parent, "built"));
485485
fb.setWorkingDirectory(new File(parent, "src"));
486486
fb.setMainClass(new File(pf.getParentFile(), "dir1/testfile1.java"));
487-
488-
String expected = "";
489-
String received = "";
490487
fb.write();
491488

489+
StringBuilder received = new StringBuilder();
492490
FileReader fr = new FileReader(pf);
493491
int c = fr.read();
494492
while (c >= 0) {
495-
received += (char) c;
493+
received.append((char)c);
496494
c = fr.read();
497495
}
496+
fr.close();
498497
// assertEquals("Make relative", "dir1/test.java",
499498
// fb.makeRelative(new File(pf.getParentFile(),"dir1/test.java")));
500499
// assertEquals("The file written by the builder", expected, received);
@@ -516,13 +515,15 @@ public void testWriteFileXML() throws IOException, MalformedProjectFileException
516515
// pfir.getSourceFiles()[0].getPath());
517516
// assertEquals("last source filename", new File(parent,"/dir3/testfile5.java").getPath(),
518517
// pfir.getSourceFiles()[4].getPath());
519-
assertEquals("first aux filename", new File(parent,"test/testfile6.java").getPath(),
520-
pfir.getAuxiliaryFiles()[0].getPath());
518+
assertEquals("first aux filename", new File(parent,"test/testfile6.java").getCanonicalPath(),
519+
pfir.getAuxiliaryFiles()[0].getCanonicalPath());
521520
assertEquals("last collapsed path", "./[ Source Files ]/dir1/", pfir.getCollapsedPaths()[0]);
522-
assertEquals("build-dir name", buildDir, pfir.getBuildDirectory());
523-
assertEquals("work-dir name", srcDir, pfir.getWorkingDirectory());
524-
assertEquals("classpath name", new File(parent,"lib"), IterUtil.first(pfir.getClassPaths()));
525-
assertEquals("main-class name", new File(parent,"/dir1/testfile1.java"), pfir.getMainClass());
521+
assertEquals("build-dir name", buildDir.getCanonicalPath(), pfir.getBuildDirectory().getCanonicalPath());
522+
assertEquals("work-dir name", srcDir.getCanonicalPath(), pfir.getWorkingDirectory().getCanonicalPath());
523+
assertEquals("classpath name", new File(parent,"lib").getCanonicalPath(),
524+
IterUtil.first(pfir.getClassPaths()).getCanonicalPath());
525+
assertEquals("main-class name", new File(parent,"dir1/testfile1.java").getCanonicalPath(),
526+
pfir.getMainClass().getCanonicalPath());
526527
pf.delete();
527528
}
528529

drjava/src/edu/rice/cs/drjava/project/XMLProjectFileParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ protected List<DocFile> readSourceFiles(String path, String rootPath) throws Mal
244244
}
245245
catch(XMLConfigException e) { active = false; /* it's ok if it doesn't exist */ }
246246

247-
DocFile docF = new DocFile(rootPath,
248-
name,
247+
DocFile docF = new DocFile(((rootPath.length()>0)?new File(rootPath,name):new File(name)).getAbsoluteFile(),
249248
new Pair<Integer,Integer>(selectFrom,selectTo),
250249
new Pair<Integer,Integer>(scrollCol,scrollCol),
251250
active,

drjava/src/edu/rice/cs/drjava/project/XMLProjectFileParserTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,24 @@ public void testXMLParse() throws IOException, MalformedProjectFileException, ja
143143
assertEquals("number of aux files", 1, pfir.getAuxiliaryFiles().length);
144144
assertEquals("number of collapsed", 2, pfir.getCollapsedPaths().length);
145145
assertEquals("number of classpaths", 2, IterUtil.sizeOf(pfir.getClassPaths()));
146-
File base = new File(System.getProperty("user.dir"));
146+
File base = new File(f.getParent());
147147
File root = new File(base, "src");
148-
assertEquals("first source filename", new File(root,"edu/rice/cs/drjava/DrJava.java").getAbsolutePath(),
149-
pfir.getSourceFiles()[0].getPath());
148+
assertEquals("first source filename", new File(root,"edu/rice/cs/drjava/DrJava.java").getCanonicalPath(),
149+
pfir.getSourceFiles()[0].getCanonicalPath());
150150
assertEquals("timestamp value",
151151
ProjectProfile.MOD_DATE_FORMAT.parse("27-Mar-2008 15:05:07").getTime(),
152152
pfir.getSourceFiles()[0].getSavedModDate());
153-
assertEquals("last source filename", new File(root,"edu/rice/cs/drjava/ui/BackgroundColorListener.java").getAbsolutePath(),
154-
pfir.getSourceFiles()[5].getPath());
155-
assertEquals("first aux filename", System.getProperty("user.dir")+"/testFiles/sample-project-file.xml",
156-
pfir.getAuxiliaryFiles()[0].getPath());
153+
assertEquals("last source filename", new File(root,"edu/rice/cs/drjava/ui/BackgroundColorListener.java").getCanonicalPath(),
154+
pfir.getSourceFiles()[5].getCanonicalPath());
155+
assertEquals("first aux filename", new File(System.getProperty("user.dir"),"/testFiles/sample-project-file.xml").getCanonicalPath(),
156+
pfir.getAuxiliaryFiles()[0].getCanonicalPath());
157157
assertEquals("last collapsed path", "./[ Source Files ]/grammar/util/", pfir.getCollapsedPaths()[1]);
158158
assertEquals("build-dir name", new File(base, "classes").getCanonicalPath(),
159159
pfir.getBuildDirectory().getCanonicalPath());
160160
assertEquals("work-dir name", new File(base, ".").getCanonicalPath(),
161161
pfir.getWorkingDirectory().getCanonicalPath());
162-
assertEquals("classpath name", System.getProperty("user.dir")+"/lib",
163-
IterUtil.first(pfir.getClassPaths()).getPath());
162+
assertEquals("classpath name", new File(System.getProperty("user.dir"),"lib").getCanonicalPath(),
163+
IterUtil.first(pfir.getClassPaths()).getCanonicalPath());
164164
assertEquals("main-class name", new File(base, "src/edu/rice/cs/drjava/DrJava.java").getCanonicalPath(),
165165
pfir.getMainClass().getCanonicalPath());
166166
}

drjava/src/edu/rice/cs/util/Log.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,10 @@ public synchronized void log(String s, Throwable t) {
148148
log(s + "\n" + sw.toString());
149149
}
150150
}
151-
}
151+
152+
/** Closes a log file. */
153+
public void close() {
154+
_writer.close();
155+
_writer = null;
156+
}
157+
}

drjava/src/edu/rice/cs/util/LogTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public void testConcurrentWrites() throws IOException, InterruptedException {
243243
for (int i = 0; i < NUM_THREADS; i++) threads[i] = new LogTestThread(log3, r.nextInt(DELAY));
244244
for (int i = 0; i < NUM_THREADS; i++) threads[i].start();
245245
for (int i = 0; i < NUM_THREADS; i++) threads[i].join();
246+
log3.close();
246247

247248
BufferedReader fin = new BufferedReader(new FileReader(file3));
248249
Date now = new Date();

0 commit comments

Comments
 (0)