KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > api > RubyInstallation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.ruby.rubyproject.api;
20
21 import java.awt.Dialog JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.lang.String JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.prefs.Preferences JavaDoc;
33 import java.util.regex.Matcher JavaDoc;
34 import java.util.regex.Pattern JavaDoc;
35 import javax.swing.JButton JavaDoc;
36 import org.netbeans.api.java.classpath.ClassPath;
37 import org.netbeans.api.options.OptionsDisplayer;
38 import org.netbeans.modules.retouche.source.usages.ClassIndexManager;
39 import org.netbeans.spi.java.classpath.ClassPathFactory;
40 import org.netbeans.spi.java.classpath.ClassPathImplementation;
41 import org.netbeans.spi.java.classpath.PathResourceImplementation;
42 import org.openide.DialogDescriptor;
43 import org.openide.DialogDisplayer;
44 import org.openide.NotifyDescriptor;
45 import org.openide.modules.InstalledFileLocator;
46 import org.openide.util.Exceptions;
47 import org.openide.util.HelpCtx;
48 import org.openide.util.NbBundle;
49 import org.openide.util.NbPreferences;
50 import org.openide.util.Utilities;
51
52
53 /**
54  * Information about a Ruby installation
55  *
56  * @author Tor Norbye
57  */

58 public class RubyInstallation {
59     /** NOTE: Keep this in sync with ruby/jruby/nbproject/project.properties */
60     private static final String JavaDoc JRUBY_RELEASE = "0.9.8"; // NOI18N
61
/** NOTE: Keep this in sync with ruby/jruby/nbproject/project.properties */
62     public static final String JavaDoc RUBY_RELEASE = "1.8"; // NOI18N
63

64     private static final String JavaDoc JRUBY_RELEASEDIR = "jruby-" + JRUBY_RELEASE; // NOI18N
65
/**
66      * MIME type for Ruby. Don't change this without also consulting the various XML files
67      * that cannot reference this value directly, as well as RUBY_MIME_TYPE in the editing plugin
68      */

69     public static final String JavaDoc RUBY_MIME_TYPE = "text/x-ruby"; // application/x-ruby is also used a fair bit.
70
private static final String JavaDoc KEY_RUBY = "ruby"; //NOI18N
71
private static final String JavaDoc KEY_RAKE = "rake"; //NOI18N
72
private static final String JavaDoc KEY_RDOC = "rdoc"; //NOI18N
73
private static final String JavaDoc KEY_RAILS = "rails"; //NOI18N
74
private static final String JavaDoc KEY_IRB = "irb"; //NOI18N
75
private static final String JavaDoc KEY_RAILS_PORT = "rails-port"; //NOI18N
76
private static final RubyInstallation INSTANCE = new RubyInstallation();
77     private String JavaDoc ruby;
78     private String JavaDoc gem;
79     private String JavaDoc rake;
80     private String JavaDoc rails;
81     private String JavaDoc rdoc;
82     private String JavaDoc irb;
83     private String JavaDoc jrubyHome;
84
85     private RubyInstallation() {
86     }
87
88     public static RubyInstallation getInstance() {
89         return INSTANCE;
90     }
91     
92     // Ensure that JRuby can find its libraries etc.
93
public void setJRubyLoadPaths() {
94         System.setProperty("jruby.home", getJRubyHome());
95     }
96
97     public String JavaDoc getRuby() {
98         if (ruby == null) {
99             String JavaDoc binary = org.openide.util.Utilities.isWindows() ? "jruby.bat" : "jruby";
100             String JavaDoc defaultRuby = getJRubyBin() + File.separator + binary;
101
102             // Normalize path
103
try {
104                 defaultRuby = new File JavaDoc(defaultRuby).getCanonicalFile().getAbsolutePath();
105             } catch (IOException JavaDoc ioe) {
106                 Exceptions.printStackTrace(ioe);
107             }
108
109             ruby = getPreferences().get(KEY_RUBY, defaultRuby);
110         }
111
112         return ruby;
113     }
114
115     public boolean isValidRuby(boolean warn) {
116         File JavaDoc file = new File JavaDoc(getRuby());
117         boolean valid = file.exists();
118
119         if (warn && !valid) {
120             String JavaDoc msg =
121                 NbBundle.getMessage(RubyInstallation.class, "NotInstalled", file.getPath());
122             javax.swing.JButton JavaDoc closeButton = new javax.swing.JButton JavaDoc(NbBundle.getMessage(RubyInstallation.class,"CTL_Close"));
123             closeButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(RubyInstallation.class,"AD_Close"));
124             final JButton JavaDoc optionsButton = new JButton JavaDoc (NbBundle.getMessage (RubyInstallation.class, "EditOptions"));
125             Object JavaDoc[] options = new Object JavaDoc[] {
126                 optionsButton,
127                 closeButton
128             };
129             DialogDescriptor descriptor = new DialogDescriptor (msg,
130                     NbBundle.getMessage (RubyInstallation.class, "MissingRuby"),
131                     true, options, optionsButton, // XXX TODO i18n
132
DialogDescriptor.DEFAULT_ALIGN, new HelpCtx (RubyInstallation.class),null);
133             descriptor.setMessageType(NotifyDescriptor.Message.ERROR_MESSAGE);
134             Dialog JavaDoc dlg = null;
135             descriptor.setModal(true);
136             try {
137                 dlg = DialogDisplayer.getDefault().createDialog (descriptor);
138                 dlg.setVisible(true);
139             } finally {
140                 if (dlg != null)
141                     dlg.dispose();
142             }
143
144             if (descriptor.getValue() == optionsButton) {
145                 OptionsDisplayer.getDefault().open("Advanced"); // NOI18N
146
}
147         }
148
149         return valid;
150     }
151
152     public String JavaDoc getGem() {
153         if (gem == null) {
154             File JavaDoc f = new File JavaDoc(getRuby());
155             // Actually, look for gem.exe, gem.rb etc.
156
gem = new File JavaDoc(f.getParentFile(), Utilities.isWindows() ? "gem.bat" : "gem").getAbsolutePath(); // NOI18N
157
}
158
159         return gem;
160     }
161     
162     public String JavaDoc getRake() {
163         if (rake == null) {
164             //String binary = org.openide.util.Utilities.isWindows() ? "rake.bat" : "rake";
165
String JavaDoc binary = "rake";
166             String JavaDoc defaultRake = getJRubyBin() + File.separator + binary;
167
168             // Normalize path
169
try {
170                 defaultRake = new File JavaDoc(defaultRake).getCanonicalFile().getAbsolutePath();
171             } catch (IOException JavaDoc ioe) {
172                 Exceptions.printStackTrace(ioe);
173             }
174
175             rake = getPreferences().get(KEY_RAKE, defaultRake);
176         }
177
178         return rake;
179     }
180
181     public boolean isValidRake(boolean warn) {
182         File JavaDoc file = new File JavaDoc(getRake());
183         boolean valid = file.exists();
184
185         if (warn && !valid) {
186             String JavaDoc msg =
187                 NbBundle.getMessage(RubyInstallation.class, "NotInstalled", file.getPath());
188             NotifyDescriptor nd =
189                 new NotifyDescriptor.Message(msg, NotifyDescriptor.Message.ERROR_MESSAGE);
190             DialogDisplayer.getDefault().notify(nd);
191         }
192
193         return valid;
194     }
195
196     public String JavaDoc getIrb() {
197         if (irb == null) {
198             String JavaDoc binary = "jirb";
199             String JavaDoc defaultIrb = getJRubyBin() + File.separator + binary;
200
201             // Normalize path
202
try {
203                 defaultIrb = new File JavaDoc(defaultIrb).getCanonicalFile().getAbsolutePath();
204             } catch (IOException JavaDoc ioe) {
205                 Exceptions.printStackTrace(ioe);
206             }
207
208             irb = getPreferences().get(KEY_IRB, defaultIrb);
209         }
210
211         return irb;
212     }
213
214     public boolean isValidIrb(boolean warn) {
215         File JavaDoc file = new File JavaDoc(getIrb());
216         boolean valid = file.exists();
217
218         if (warn && !valid) {
219             String JavaDoc msg =
220                 NbBundle.getMessage(RubyInstallation.class, "NotInstalled", file.getPath());
221             NotifyDescriptor nd =
222                 new NotifyDescriptor.Message(msg, NotifyDescriptor.Message.ERROR_MESSAGE);
223             DialogDisplayer.getDefault().notify(nd);
224         }
225
226         return valid;
227     }
228     
229     public String JavaDoc getJRubyHome() {
230         if (jrubyHome == null) {
231             File JavaDoc f =
232                 InstalledFileLocator.getDefault()
233                                     .locate("modules/org-netbeans-modules-ruby-project.jar", null, false); // NOI18N
234

235             if (f == null) {
236                 throw new RuntimeException JavaDoc("Can't find cluster");
237             }
238
239             f = new File JavaDoc(f.getParentFile().getAbsolutePath() + File.separator + ".." + File.separator + JRUBY_RELEASEDIR); // NOI18N
240
try {
241                 f = f.getCanonicalFile();
242             } catch (IOException JavaDoc ioe) {
243                 Exceptions.printStackTrace(ioe);
244             }
245             jrubyHome = f.getPath();
246         }
247         
248         return jrubyHome;
249     }
250
251     private String JavaDoc getJRubyBin() {
252         return getJRubyHome() + File.separator + "bin";
253     }
254
255     private String JavaDoc getJRubyLib() {
256         return getJRubyHome() + File.separator + "lib";
257     }
258
259     /** Return the lib directory for the currently chosen Ruby interpreter */
260     public String JavaDoc getRubyLib() {
261         File JavaDoc rubyLib = new File JavaDoc(new File JavaDoc(getRuby()).getParentFile().getParent(), "lib"); // NOI18N
262
if (rubyLib.exists() && new File JavaDoc(rubyLib, "ruby").exists()) { // NOI18N
263
try {
264                 return rubyLib.getCanonicalPath();
265             } catch (IOException JavaDoc ioe) {
266                 Exceptions.printStackTrace(ioe);
267             }
268         }
269         return getJRubyLib();
270     }
271     
272     public String JavaDoc getRDoc() {
273         if (rdoc == null) {
274             //String binary = org.openide.util.Utilities.isWindows() ? "rdoc.bat" : "rdoc";
275
String JavaDoc binary = "rdoc";
276             String JavaDoc defaultRDoc = getJRubyBin() + File.separator + binary;
277
278             // Normalize path
279
try {
280                 defaultRDoc = new File JavaDoc(defaultRDoc).getCanonicalFile().getAbsolutePath();
281             } catch (IOException JavaDoc ioe) {
282                 Exceptions.printStackTrace(ioe);
283             }
284
285             rdoc = getPreferences().get(KEY_RDOC, defaultRDoc);
286         }
287
288         return rdoc;
289     }
290
291     public boolean isValidRDoc(boolean warn) {
292         File JavaDoc file = new File JavaDoc(getRDoc());
293         boolean valid = file.exists();
294
295         if (warn && !valid) {
296             String JavaDoc msg =
297                 NbBundle.getMessage(RubyInstallation.class, "NotInstalled", file.getPath());
298             NotifyDescriptor nd =
299                 new NotifyDescriptor.Message(msg, NotifyDescriptor.Message.ERROR_MESSAGE);
300             DialogDisplayer.getDefault().notify(nd);
301         }
302
303         return valid;
304     }
305
306     public String JavaDoc getRails() {
307         if (rails == null) {
308             //String binary = org.openide.util.Utilities.isWindows() ? "rails.bat" : "rails";
309
String JavaDoc binary = "rails";
310             String JavaDoc defaultRails = getJRubyBin() + File.separator + binary;
311
312             // Normalize path
313
try {
314                 defaultRails = new File JavaDoc(defaultRails).getCanonicalFile().getAbsolutePath();
315             } catch (IOException JavaDoc ioe) {
316                 Exceptions.printStackTrace(ioe);
317             }
318
319             rails = getPreferences().get(KEY_RAILS, defaultRails);
320         }
321
322         return rails;
323     }
324
325     public boolean isValidRails(boolean warn) {
326         File JavaDoc file = new File JavaDoc(getRails());
327         boolean valid = file.exists();
328
329         if (warn && !valid) {
330             String JavaDoc msg =
331                 NbBundle.getMessage(RubyInstallation.class, "NotInstalled", file.getPath());
332             NotifyDescriptor nd =
333                 new NotifyDescriptor.Message(msg, NotifyDescriptor.Message.ERROR_MESSAGE);
334             DialogDisplayer.getDefault().notify(nd);
335         }
336
337         return valid;
338     }
339
340     public boolean isValid(File JavaDoc home) {
341         // TODO - Windows - check for .exe or .bat?
342
if (org.openide.util.Utilities.isWindows()) {
343             if (new File JavaDoc(home + File.separator + "bin" + File.separator + "jruby.bat").exists()) {
344                 return true;
345             }
346
347             if (new File JavaDoc(home + File.separator + "bin" + File.separator + "ruby.exe").exists()) {
348                 return true;
349             }
350         } else {
351             if (new File JavaDoc(home + File.separator + "bin" + File.separator + "jruby").exists()) {
352                 return true;
353             }
354
355             if (new File JavaDoc(home + File.separator + "bin" + File.separator + "ruby").exists()) {
356                 return true;
357             }
358         }
359
360         return false;
361     }
362
363     private static Preferences JavaDoc getPreferences() {
364         return NbPreferences.forModule(RubyInstallation.class);
365     }
366
367     public void setRuby(final String JavaDoc ruby) {
368         if (!ruby.equals(getRuby())) {
369             getPreferences().put(KEY_RUBY, ruby);
370             this.ruby = ruby;
371             recomputeRoots();
372         }
373     }
374
375     public void setRake(final String JavaDoc rake) {
376         if (!rake.equals(getRake())) {
377             getPreferences().put(KEY_RAKE, rake);
378             this.rake = rake;
379         }
380     }
381
382     public void setRDoc(final String JavaDoc rdoc) {
383         if (!rdoc.equals(getRDoc())) {
384             getPreferences().put(KEY_RDOC, rdoc);
385             this.rdoc = rdoc;
386         }
387     }
388
389     public void setIrb(final String JavaDoc irb) {
390         if (!irb.equals(getIrb())) {
391             getPreferences().put(KEY_IRB, irb);
392             this.irb = irb;
393         }
394     }
395
396     public void setRails(final String JavaDoc rails) {
397         if (!rails.equals(getRails())) {
398             getPreferences().put(KEY_RAILS, rails);
399             this.rails = rails;
400         }
401     }
402
403     public void setRailsPort(final int port) {
404         getPreferences().putInt(KEY_RAILS_PORT, port);
405     }
406     
407     public int getRailsPort() {
408         return getPreferences().getInt(KEY_RAILS_PORT, 3000);
409     }
410     
411
412     public void ensureExecutable() {
413         // No excute permissions on Windows. On Unix and Mac, try.
414
if (Utilities.isWindows()) {
415             return;
416         }
417
418         File JavaDoc binDir = new File JavaDoc(getJRubyBin());
419
420         // Ensure that the binaries are installed as expected
421
// The following logic is from CLIHandler in core/bootstrap:
422
File JavaDoc chmod = new File JavaDoc("/bin/chmod"); // NOI18N
423
if (!chmod.isFile()) {
424             // Linux uses /bin, Solaris /usr/bin, others hopefully one of those
425
chmod = new File JavaDoc("/usr/bin/chmod"); // NOI18N
426
}
427         if (chmod.isFile()) {
428             try {
429                 List JavaDoc<String JavaDoc> argv = new ArrayList JavaDoc<String JavaDoc>();
430                 argv.add(chmod.getAbsolutePath());
431                 argv.add("u+rx"); // NOI18N
432
String JavaDoc[] files = binDir.list();
433                 for (String JavaDoc file : files) {
434                     argv.add(file);
435                 }
436                 ProcessBuilder JavaDoc pb = new ProcessBuilder JavaDoc(argv);
437                 pb.directory(binDir);
438                 Process JavaDoc process = pb.start();
439
440                 int chmoded = process.waitFor();
441                 if (chmoded != 0) {
442                     throw new IOException JavaDoc("could not run " + argv); // NOI18N
443
}
444             } catch (InterruptedException JavaDoc e) {
445                 Exceptions.printStackTrace(e);
446             } catch (IOException JavaDoc e) {
447                 Exceptions.printStackTrace(e);
448             }
449         }
450     }
451     
452     /** The gems installed have changed, or the installed ruby has changed etc. --
453      * force a recomputation of the installed classpath roots */

454     public void recomputeRoots() {
455         this.cp = null;
456         // Force ClassIndex registration
457
getClassPathEntries();
458
459         // Force recomputation of libraries in the index
460
// TODO: Wipe out boot roots in ClassIndexManager as well
461
// Possibly clean up index as well?
462

463     }
464     
465     private Pattern JavaDoc pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)");
466     
467     /** Return > 0 if version1 is greater than version 2, 0 if equal and -1 otherwise */
468     private int compareGemVersions(String JavaDoc version1, String JavaDoc version2) {
469         if (version1.equals(version2)) {
470             return 0;
471         }
472
473         Matcher JavaDoc matcher1 = pattern.matcher(version1);
474         if (matcher1.matches()) {
475             int major1 = Integer.parseInt(matcher1.group(1));
476             int minor1 = Integer.parseInt(matcher1.group(2));
477             int micro1 = Integer.parseInt(matcher1.group(3));
478         
479             Matcher JavaDoc matcher2 = pattern.matcher(version2);
480             if (matcher2.matches()) {
481                 int major2 = Integer.parseInt(matcher2.group(1));
482                 int minor2 = Integer.parseInt(matcher2.group(2));
483                 int micro2 = Integer.parseInt(matcher2.group(3));
484                 
485                 if (major1 != major2) {
486                     return major1-major2;
487                 }
488                 if (minor1 != minor2) {
489                     return minor1-minor2;
490                 }
491                 if (micro1 != micro2) {
492                     return micro1-micro2;
493                 }
494             } else {
495                 // uh oh
496
//assert false : "no version match on " + version2;
497
}
498         } else {
499             //assert false : "no version match on " + version1;
500
}
501         
502         // Just do silly alphabetical comparison
503
return version1.compareTo(version2);
504     }
505     
506     public String JavaDoc getVersion(String JavaDoc gemName) {
507         if (gemFiles == null) {
508             return null;
509         }
510         
511         Map JavaDoc<String JavaDoc,File JavaDoc> highestVersion = gemFiles.get(gemName);
512         if (highestVersion == null || highestVersion.size() == 0) {
513             return null;
514         }
515         
516         return highestVersion.keySet().iterator().next();
517     }
518
519     Map JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,File JavaDoc>> gemFiles = new HashMap JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,File JavaDoc>>();
520         
521     
522     /** Given a list of files that may represent gems, choose the most recent version
523      * of each */

524     private File JavaDoc[] chooseGems(File JavaDoc[] gems) {
525         for (File JavaDoc f : gems) {
526             // See if it looks like a gem
527
String JavaDoc n = f.getName();
528             int dashIndex = n.indexOf('-');
529             if (dashIndex != -1) {
530                 String JavaDoc name = n.substring(0, dashIndex);
531                 String JavaDoc version = n.substring(dashIndex+1);
532                 
533                 Map JavaDoc<String JavaDoc,File JavaDoc> nameMap = gemFiles.get(name);
534                 if (nameMap == null) {
535                     nameMap = new HashMap JavaDoc<String JavaDoc,File JavaDoc>();
536                     gemFiles.put(name, nameMap);
537                     nameMap.put(version, f);
538                 } else {
539                     // Decide whether this version is more recent than the one already there
540
String JavaDoc oldVersion = nameMap.keySet().iterator().next();
541                     if (compareGemVersions(version, oldVersion) > 0) {
542                         // New version is higher
543
nameMap.clear();
544                         nameMap.put(version, f);
545                     }
546                 }
547             }
548         }
549         
550         List JavaDoc<File JavaDoc> result = new ArrayList JavaDoc<File JavaDoc>();
551         for (Map JavaDoc<String JavaDoc,File JavaDoc> map : gemFiles.values()) {
552             for (File JavaDoc f : map.values()) {
553                 result.add(f);
554             }
555         }
556         
557         return result.toArray(new File JavaDoc[result.size()]);
558     }
559     
560     private static boolean SKIP_INDEX_LIBS = System.getProperty("ruby.index.nolibs") != null;
561     private static boolean SKIP_INDEX_GEMS = System.getProperty("ruby.index.nogems") != null;
562
563     // TODO Allow callers to decide if they want rails+dependencies included or not
564
static ClassPath cp;
565     public List JavaDoc<ClassPath.Entry> getClassPathEntries() {
566         if (cp == null) {
567             cp = ClassPathFactory.createClassPath(new ClassPathImplementation() {
568             public List JavaDoc<? extends PathResourceImplementation> getResources() {
569                 try {
570                     List JavaDoc<PathResourceImplementation> list = new ArrayList JavaDoc<PathResourceImplementation>();
571                     List JavaDoc<URL JavaDoc> urls = new ArrayList JavaDoc<URL JavaDoc>();
572                     // Scan <ruby>/lib/ruby/
573
// TODO: Make this work for whatever interpreter is installed, not necessarily JRuby!
574

575                     // Core classes: Stubs generated for the "builtin" Ruby libraries.
576
File JavaDoc builtin = new File JavaDoc(getJRubyHome()+File.separator+"rubystubs");
577                     assert builtin.exists() && builtin.isDirectory();
578                     urls.add(builtin.toURI().toURL());
579                     
580                     String JavaDoc rubyLib = getRubyLib();
581                     
582                     // Install standard libraries
583
// lib/ruby/1.8/
584
if (!SKIP_INDEX_LIBS) {
585                         File JavaDoc libs = new File JavaDoc(rubyLib+File.separator+"ruby"+File.separator+RUBY_RELEASE);
586                         assert libs.exists() && libs.isDirectory();
587                         urls.add(libs.toURI().toURL());
588                     }
589                     
590                     // Install gems.
591
if (!SKIP_INDEX_GEMS) {
592                         File JavaDoc gemDir = new File JavaDoc(rubyLib+File.separator+"ruby"+File.separator+"gems"+File.separator+
593                                 RUBY_RELEASE+File.separator+"gems"+File.separator);
594                         if (gemDir.exists()) {
595                             // Add each of */lib/
596
File JavaDoc[] gems = gemDir.listFiles();
597                             gems = chooseGems(gems);
598                             for (File JavaDoc gem : gems) {
599                                // TODO: Consider skipping Rails related libraries when we're not in a Rails project
600
File JavaDoc lib = new File JavaDoc(gem, "lib");
601                                 if (lib.exists() && lib.isDirectory()) {
602                                     URL JavaDoc url = lib.toURI().toURL();
603                                     urls.add(url);
604                                 }
605                             }
606                         }
607                     }
608                     
609                     // Install site ruby - this is where rubygems lives for example
610
if (!SKIP_INDEX_LIBS) {
611                         File JavaDoc siteruby = new File JavaDoc(rubyLib+File.separator+"ruby"+File.separator+"site_ruby"+File.separator+RUBY_RELEASE);
612                         if (siteruby.exists() && siteruby.isDirectory()) {
613                             urls.add(siteruby.toURI().toURL());
614                         }
615                     }
616
617                     // Register boot roots. This is a bit of a hack.
618
// I need to find a better way to distinguish source directories
619
// from boot (library, gems, etc.) directories at the scanning and indexing end.
620
ClassIndexManager mgr = ClassIndexManager.getDefault();
621                     mgr.setBootRoots(urls);
622                     
623                     final URL JavaDoc[] roots = urls.toArray(new URL JavaDoc[urls.size()]);
624                     PathResourceImplementation pri = new PathResourceImplementation() {
625                         public URL JavaDoc[] getRoots() {
626                             return roots;
627                         }
628
629                         public ClassPathImplementation getContent() {
630                             return null;
631                         }
632                         public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
633                             // No changes will ever be fired
634
}
635                         public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
636                             // No changes will ever be fired
637
}
638                     };
639                     list.add(pri);
640                     return list;
641                 } catch (MalformedURLException JavaDoc mue) {
642                     Exceptions.printStackTrace(mue);
643                 }
644                 
645                 return null;
646             }
647
648             public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
649                 // There will be no changes fired
650
//throw new UnsupportedOperationException("Not supported yet.");
651
}
652
653             public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
654                 // There will be no changes fired
655
//throw new UnsupportedOperationException("Not supported yet.");
656
}
657         });
658         }
659         
660         return cp.entries();
661     }
662 }
663
Popular Tags