1 19 20 package org.netbeans.core.startup; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 import java.net.URLClassLoader ; 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import org.netbeans.CLIHandler; 31 import org.netbeans.Module; 32 import org.openide.filesystems.Repository; 33 import org.openide.util.Exceptions; 34 import org.openide.util.Lookup; 35 36 40 public class CLICoreBridge extends CLIHandler { 41 44 public CLICoreBridge() { 45 super(WHEN_INIT); 46 } 47 48 protected int cli(Args arguments) { 49 Lookup clis = Lookup.getDefault(); 50 Collection handlers = clis.lookupAll(CLIHandler.class); 51 int h = notifyHandlers(arguments, handlers, WHEN_EXTRA, true, true); 52 if (h == 0) { 53 h = CoreBridge.getDefault().cli( 54 arguments.getArguments(), 55 arguments.getInputStream(), 56 arguments.getOutputStream(), 57 arguments.getErrorStream(), 58 arguments.getCurrentDirectory() 59 ); 60 } 61 return h; 62 } 63 64 protected void usage(PrintWriter w) { 65 if (MainLookup.isStarted()) { 66 Lookup clis = Lookup.getDefault(); 67 Collection handlers = clis.lookupAll(CLIHandler.class); 68 showHelp(w, handlers, WHEN_EXTRA); 69 w.flush(); 70 return; 71 } 72 73 ModuleSystem moduleSystem; 74 try { 75 moduleSystem = new ModuleSystem(Repository.getDefault().getDefaultFileSystem()); 76 } catch (IOException ioe) { 77 throw (IllegalStateException ) new IllegalStateException ("Module system cannot be created").initCause(ioe); } 80 81 moduleSystem.readList(); 83 84 85 ArrayList <URL > urls = new ArrayList <URL >(); 86 for (Module m : moduleSystem.getManager().getModules()) { 87 for (File f : m.getAllJars()) { 88 try { 89 urls.add(f.toURI().toURL()); 90 } 91 catch (MalformedURLException ex) { 92 Exceptions.printStackTrace(ex); 93 } 94 } 95 } 96 97 URLClassLoader loader = new URLClassLoader (urls.toArray(new URL [0]), getClass().getClassLoader()); 98 MainLookup.systemClassLoaderChanged(loader); 99 Lookup clis = Lookup.getDefault(); 100 Collection handlers = clis.lookupAll(CLIHandler.class); 101 showHelp(w, handlers, WHEN_EXTRA); 102 w.flush(); 103 } 104 } 105 | Popular Tags |