4141import java .io .IOException ;
4242import java .io .OutputStream ;
4343
44- import java .net .MalformedURLException ;
45- import java .net .URL ;
46-
4744import java .rmi .RemoteException ;
4845
4946import java .util .ArrayList ;
5754import javax .swing .text .BadLocationException ;
5855import javax .swing .SwingUtilities ;
5956
60- import edu .rice .cs .util .ClassPathVector ;
6157import edu .rice .cs .util .FileOpenSelector ;
6258import edu .rice .cs .drjava .model .FileSaveSelector ;
63- import edu .rice .cs .util .FileOps ;
6459import edu .rice .cs .util .NullFile ;
6560import edu .rice .cs .util .OperationCanceledException ;
6661import edu .rice .cs .util .UnexpectedException ;
6762import edu .rice .cs .util .newjvm .AbstractMasterJVM ;
6863import edu .rice .cs .util .text .EditDocumentException ;
6964import edu .rice .cs .util .swing .Utilities ;
7065import 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
7369import edu .rice .cs .drjava .DrJava ;
7470import 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
0 commit comments