Skip to content

Commit bd64409

Browse files
author
dlsmith
committed
Modified code dealing with class paths to consistently use Iterable<File> instead URL-based objects like ClassPathVector and ClassPathEntry. Since class paths never consist of arbitrary URLs, the difficulty of maintaining such a representation is not necessary, and leads to a lot of ugly code. (Also updated plt.jar to the latest version.)
git-svn-id: file:///tmp/test-svn/trunk@4181 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent add4ca7 commit bd64409

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+378
-1044
lines changed

drjava/lib/plt.jar

61.9 KB
Binary file not shown.

drjava/lib/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dynamicjava.jar: Updated 2005-10-11
1111
javalanglevels.jar: javalanglevels-20070213-2052
1212
junit.jar: JUnit 3.8.1
1313
platform.jar: platform-20070213-2003
14-
plt.jar: plt-20070213-2138
14+
plt.jar: plt-20070223-2125
1515
retroweaver-rt-1.2.3.jar: Retroweaver 1.2.3
1616
winlaf-0.5.1.jar: WinLAF 0.5.1
1717

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import edu.rice.cs.util.ArgumentTokenizer;
6161
import edu.rice.cs.util.FileOps;
6262
import edu.rice.cs.util.Log;
63-
import edu.rice.cs.util.classloader.ToolsJarClassLoader;
6463
import edu.rice.cs.util.newjvm.ExecJVM;
6564
import edu.rice.cs.plt.debug.DebugUtil;
6665

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import edu.rice.cs.util.UnexpectedException;
4848
import edu.rice.cs.util.OutputStreamRedirector;
4949
import edu.rice.cs.util.newjvm.ExecJVM;
50-
import edu.rice.cs.util.classloader.ToolsJarClassLoader;
5150
import edu.rice.cs.util.swing.Utilities;
5251

5352
import edu.rice.cs.drjava.ui.MainFrame;

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

Lines changed: 54 additions & 81 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 64 deletions
This file was deleted.

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

Lines changed: 31 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
import java.io.IOException;
4242
import java.io.OutputStream;
4343

44-
import java.net.MalformedURLException;
45-
import java.net.URL;
46-
4744
import java.rmi.RemoteException;
4845

4946
import java.util.ArrayList;
@@ -57,18 +54,17 @@
5754
import javax.swing.text.BadLocationException;
5855
import javax.swing.SwingUtilities;
5956

60-
import edu.rice.cs.util.ClassPathVector;
6157
import edu.rice.cs.util.FileOpenSelector;
6258
import edu.rice.cs.drjava.model.FileSaveSelector;
63-
import edu.rice.cs.util.FileOps;
6459
import edu.rice.cs.util.NullFile;
6560
import edu.rice.cs.util.OperationCanceledException;
6661
import edu.rice.cs.util.UnexpectedException;
6762
import edu.rice.cs.util.newjvm.AbstractMasterJVM;
6863
import edu.rice.cs.util.text.EditDocumentException;
6964
import edu.rice.cs.util.swing.Utilities;
7065
import edu.rice.cs.plt.reflect.JavaVersion;
71-
import edu.rice.cs.plt.iter.ReverseIterable;
66+
import edu.rice.cs.plt.iter.IterUtil;
67+
import edu.rice.cs.plt.io.IOUtil;
7268

7369
import edu.rice.cs.drjava.DrJava;
7470
import edu.rice.cs.drjava.config.OptionConstants;
@@ -140,12 +136,7 @@ public void interpreterReady(File wd) {
140136
File buildDir = _state.getBuildDirectory();
141137
if (buildDir != null) {
142138
// System.out.println("adding for reset: " + _state.getBuildDirectory().getAbsolutePath());
143-
try {
144-
_jvm.addBuildDirectoryClassPath(FileOps.toURL(new File(buildDir.getAbsolutePath())));
145-
} catch(MalformedURLException murle) {
146-
// edit this later! this is bad! we should handle this exception better!
147-
throw new RuntimeException(murle);
148-
}
139+
_jvm.addBuildDirectoryClassPath(IOUtil.attemptAbsoluteFile(buildDir));
149140
}
150141
}
151142

@@ -281,7 +272,7 @@ private Iterable<JDKToolsLibrary> findLibraries() {
281272
if (!results.containsKey(tVersion)) { results.put(tVersion, t); }
282273
}
283274

284-
return ReverseIterable.make(results.values());
275+
return IterUtil.reverse(results.values());
285276
}
286277

287278

@@ -299,14 +290,7 @@ public void setBuildDirectory(File f) {
299290
_state.setBuildDirectory(f);
300291
if (f != null) {
301292
// System.out.println("adding: " + f.getAbsolutePath());
302-
try {
303-
_jvm.addBuildDirectoryClassPath(FileOps.toURL(new File(f.getAbsolutePath())));
304-
}
305-
catch(MalformedURLException murle) {
306-
// TODO! change this! we should handle this exception better!
307-
// show a popup like "invalide build directory" or something
308-
throw new RuntimeException(murle);
309-
}
293+
_jvm.addBuildDirectoryClassPath(IOUtil.attemptAbsoluteFile(f));
310294
}
311295

312296
_notifier.projectBuildDirChanged();
@@ -360,22 +344,16 @@ public void disposeExternalResources() {
360344
* if a valid directory cannot be determined. In that case, the former working directory is used.
361345
*/
362346
public void resetInteractions(File wd, boolean forceReset) {
363-
// _log.log("DefaultGlobalModel.resetInteractions called");
364347
File workDir = _interactionsModel.getWorkingDirectory();
365348
if (wd == null) { wd = workDir; }
366-
// _log.log("New working directory = " + wd +"; current working directory = " + workDir + ";");
367349

368350
if (! forceReset && ! _jvm.slaveJVMUsed() && ! isClassPathChanged() && wd.equals(workDir)) {
369351
// Eliminate resetting interpreter (slaveJVM) since it has already been reset appropriately.
370-
// _log.log("Suppressing resetting of interactions pane");
371352
_interactionsModel._notifyInterpreterReady(wd);
372353
return;
373354
}
374-
// _log.log("Resetting interactions with working directory = " + wd);
375-
if (DrJava.getConfig().getSetting(STICKY_INTERACTIONS_DIRECTORY)) {
376-
// update the setting
377-
DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, wd);
378-
}
355+
// update the setting
356+
DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, wd);
379357
_interactionsModel.resetInterpreter(wd);
380358
}
381359

@@ -433,7 +411,7 @@ public void printDebugMessage(String s) {
433411

434412

435413
/** Returns the current classpath in use by the Interpreter JVM. */
436-
public ClassPathVector getInteractionsClassPath() { return _jvm.getClassPath(); }
414+
public Iterable<File> getInteractionsClassPath() { return _jvm.getClassPath(); }
437415

438416
/** Sets whether or not the Interactions JVM will be reset after a compilation succeeds. This should ONLY be used
439417
* in tests! This method is not supported by AbstractGlobalModel.
@@ -537,7 +515,7 @@ public void run() {
537515
*/
538516
public void generateJavadoc(FileSaveSelector saver) throws IOException {
539517
// Use the model's classpath, and use the EventNotifier as the listener
540-
_javadocModel.javadocDocument(this, saver, getClassPath().toString());
518+
_javadocModel.javadocDocument(this, saver, IOUtil.pathToString(getClassPath()));
541519
}
542520

543521
/** Called to indicate the document is being closed, so to remove all related state from the debug manager. */
@@ -567,15 +545,10 @@ protected ConcreteOpenDefDoc _createOpenDefinitionsDocument(File f) throws IOExc
567545
*/
568546
protected void addDocToClassPath(OpenDefinitionsDocument doc) {
569547
try {
570-
File classPath = doc.getSourceRoot();
571-
try {
572-
URL pathURL = FileOps.toURL(classPath);
573-
if (doc.isAuxiliaryFile())
574-
_interactionsModel.addProjectFilesClassPath(pathURL);
575-
else _interactionsModel.addExternalFilesClassPath(pathURL);
576-
setClassPathChanged(true);
577-
}
578-
catch(MalformedURLException murle) { /* fail silently */ }
548+
File sourceRoot = doc.getSourceRoot();
549+
if (doc.isAuxiliaryFile()) { _interactionsModel.addProjectFilesClassPath(sourceRoot); }
550+
else { _interactionsModel.addExternalFilesClassPath(sourceRoot); }
551+
setClassPathChanged(true);
579552
}
580553
catch (InvalidPackageException e) {
581554
// Invalid package-- don't add it to classpath
@@ -626,12 +599,12 @@ public void currThreadSet(DebugThreadData thread) { }
626599
/** Get the class path to be used in all class-related operations.
627600
* TODO: Insure that this is used wherever appropriate.
628601
*/
629-
public ClassPathVector getClassPath() {
630-
ClassPathVector result = new ClassPathVector();
602+
public Iterable<File> getClassPath() {
603+
Iterable<File> result = IterUtil.empty();
631604

632605
if (isProjectActive()) {
633606
File buildDir = getBuildDirectory();
634-
if (buildDir != null) { _addFileToClassPath(buildDir, result); }
607+
if (buildDir != null) { result = IterUtil.compose(result, buildDir); }
635608

636609
/* We prefer to assume the project root is the project's source root, rather than
637610
* checking *every* file in the project for its source root. This is a bit problematic,
@@ -641,86 +614,60 @@ public ClassPathVector getClassPath() {
641614
* Interactions.
642615
*/
643616
File projRoot = getProjectRoot();
644-
if (projRoot != null) { _addFileToClassPath(projRoot, result); }
617+
if (projRoot != null) { result = IterUtil.compose(result, projRoot); }
645618

646-
ClassPathVector projectExtras = getExtraClassPath();
647-
if (projectExtras != null) { result.addAll(projectExtras); }
619+
Iterable<File> projectExtras = getExtraClassPath();
620+
if (projectExtras != null) { result = IterUtil.compose(result, projectExtras); }
648621
}
649-
else {
650-
for (File f : getSourceRootSet()) { _addFileToClassPath(f, result); }
651-
}
652-
622+
else { result = IterUtil.compose(result, getSourceRootSet()); }
623+
653624
Vector<File> globalExtras = DrJava.getConfig().getSetting(EXTRA_CLASSPATH);
654-
if (globalExtras != null) {
655-
for (File f : globalExtras) { _addFileToClassPath(f, result); }
656-
}
625+
if (globalExtras != null) { result = IterUtil.compose(result, globalExtras); }
657626

658627
/* We must add JUnit to the class path. We do so by including the current JVM's class path.
659628
* This is not ideal, because all other classes on the current class path (including all of DrJava's
660629
* internal classes) are also included. But we're probably stuck doing something like this if we
661630
* want to continue bundling JUnit with DrJava.
662631
*/
663-
String currentClassPath = System.getProperty("java.class.path");
664-
if (currentClassPath != null) {
665-
// TODO: Parsing this string needs to only happen once, not every time this method is invoked.
666-
StringTokenizer tokens = new StringTokenizer(currentClassPath, File.pathSeparator);
667-
while (tokens.hasMoreTokens()) {
668-
_addFileToClassPath(new File(tokens.nextToken()), result);
669-
}
670-
}
632+
// TODO: Parsing this string needs to only happen once, not every time this method is invoked.
633+
String systemPath = System.getProperty("java.class.path", "");
634+
result = IterUtil.compose(result, IOUtil.attemptAbsoluteFiles(IOUtil.parsePath(systemPath)));
671635

672636
return result;
673637
}
674638

675-
/** Helper for getClassPath: add a File, rather than a URL, to the given path */
676-
private void _addFileToClassPath(File f, ClassPathVector cp) {
677-
/* TODO: This conversion should be done somewhere where errors can be reported to the user --
678-
for example, when a file is selected in the preferences dialog. */
679-
try { cp.add(FileOps.toURL(f)); }
680-
catch (MalformedURLException e) { /* ignore */ }
681-
}
682-
683639
/** Adds the project root (if a project is open), the source roots for other open documents, the paths in the
684640
* "extra classpath" config option, as well as any project-specific classpaths to the interpreter's classpath.
685641
* This method is called in DefaultInteractionsModel when the interpreter becomes ready.
686642
*/
687643
public void resetInteractionsClassPath() {
688-
ClassPathVector projectExtras = getExtraClassPath();
644+
Iterable<File> projectExtras = getExtraClassPath();
689645
//System.out.println("Adding project classpath vector to interactions classpath: " + projectExtras);
690-
if (projectExtras != null) for (URL cpE : projectExtras) { _interactionsModel.addProjectClassPath(cpE); }
646+
if (projectExtras != null) for (File cpE : projectExtras) { _interactionsModel.addProjectClassPath(cpE); }
691647

692648
Vector<File> cp = DrJava.getConfig().getSetting(EXTRA_CLASSPATH);
693649
if (cp != null) {
694-
for (File f : cp) {
695-
try { _interactionsModel.addExtraClassPath(FileOps.toURL(f)); }
696-
catch(MalformedURLException murle) {
697-
System.out.println("File " + f + " in your extra classpath could not be parsed to a URL; " +
698-
"it may contain un-URL-encodable characters.");
699-
}
700-
}
650+
for (File f : cp) { _interactionsModel.addExtraClassPath(f); }
701651
}
702652

703653
for (OpenDefinitionsDocument odd: getAuxiliaryDocuments()) {
704654
// this forwards directly to InterpreterJVM.addClassPath(String)
705-
try { _interactionsModel.addProjectFilesClassPath(FileOps.toURL(odd.getSourceRoot())); }
706-
catch(MalformedURLException murle) { /* fail silently */ }
655+
try { _interactionsModel.addProjectFilesClassPath(odd.getSourceRoot()); }
707656
catch(InvalidPackageException e) { /* ignore it */ }
708657
}
709658

710659
for (OpenDefinitionsDocument odd: getNonProjectDocuments()) {
711660
// this forwards directly to InterpreterJVM.addClassPath(String)
712661
try {
713662
File sourceRoot = odd.getSourceRoot();
714-
if (sourceRoot != null) _interactionsModel.addExternalFilesClassPath(FileOps.toURL(sourceRoot));
663+
if (sourceRoot != null) _interactionsModel.addExternalFilesClassPath(sourceRoot);
715664
}
716-
catch(MalformedURLException murle) { /* ignore it */ }
717665
catch(InvalidPackageException e) { /* ignore it */ }
718666
}
719667

720668
// add project source root to projectFilesClassPath. All files in project tree have this root.
721669

722-
try { _interactionsModel.addProjectFilesClassPath(FileOps.toURL(getProjectRoot())); }
723-
catch(MalformedURLException murle) { /* fail silently */ }
670+
_interactionsModel.addProjectFilesClassPath(getProjectRoot());
724671
setClassPathChanged(false); // reset classPathChanged state
725672
}
726673

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import java.util.Vector;
7272

7373
import edu.rice.cs.plt.tuple.Pair;
74-
import edu.rice.cs.util.ClassPathVector;
7574
import edu.rice.cs.util.FileOps;
7675
import edu.rice.cs.util.FileOpenSelector;
7776
import edu.rice.cs.util.OperationCanceledException;
@@ -290,11 +289,11 @@ public File getSourceFile(String fileName) {
290289
throw new UnsupportedOperationException("Tried to call getSourceFile on a Dummy");
291290
}
292291

293-
public File findFileInPaths(String fileName, List<File> paths) {
292+
public File findFileInPaths(String fileName, Iterable<File> paths) {
294293
throw new UnsupportedOperationException("Tried to call getSourceFileFromPaths on a Dummy");
295294
}
296295

297-
public File[] getSourceRootSet() {
296+
public Iterable<File> getSourceRootSet() {
298297
throw new UnsupportedOperationException("Tried to call getSourceRootSet on a Dummy");
299298
}
300299

@@ -362,7 +361,7 @@ public void interpretCurrentInteraction() {
362361
throw new UnsupportedOperationException("Tried to call interpretCurrentInteraction on a Dummy");
363362
}
364363

365-
public ClassPathVector getInteractionsClassPath() {
364+
public Iterable<File> getInteractionsClassPath() {
366365
throw new UnsupportedOperationException("Tried to call getInteractionsClasspath on a Dummy");
367366
}
368367

@@ -403,7 +402,7 @@ public int getDebugPort() throws IOException {
403402
throw new UnsupportedOperationException("Tried to call getDebugPort on a Dummy");
404403
}
405404

406-
public ClassPathVector getClassPath() {
405+
public Iterable<File> getClassPath() {
407406
throw new UnsupportedOperationException("Tried to call getClassPath on a Dummy");
408407
}
409408

@@ -503,11 +502,11 @@ public File getMainClass() {
503502
throw new UnsupportedOperationException("Tried to call getMainClass on a Dummy");
504503
}
505504

506-
public ClassPathVector getExtraClassPath() {
505+
public Iterable<File> getExtraClassPath() {
507506
throw new UnsupportedOperationException("Tried to call getExtraClasspath on a Dummy");
508507
}
509508

510-
public void setExtraClassPath(ClassPathVector cp) {
509+
public void setExtraClassPath(Iterable<File> cp) {
511510
throw new UnsupportedOperationException("Tried to call setExtraClasspath on a Dummy");
512511
}
513512

0 commit comments

Comments
 (0)