Esempio n. 1
0
  public void launch() {
    System.out.println(
        "## trampoline <" + this.getClass() + ":" + this.getClass().getClassLoader() + ">");
    trampoline = this;

    String exceptions = SystemProperties.getProperty("trampolineExceptions", null);
    ignored =
        new String[] {
          "apple.",
          "java.",
          "javax.",
          "sun.",
          "com.apple",
          "apple.",
          "field.namespace",
          "field.math",
          "field.launch.",
          "org.objectweb",
          "com.sun",
          "org.xml",
          "org.w3c",
          "$Prox",
          "org.eclipse",
          "main",
          "field.util.BetterWeak",
          "field.misc.ANSIColorUtils",
          "ch.rand",
          "org.python",
          "org.apache.batik",
          "org.antlr",
          "field.util.TaskQueue",
          "com.lowagie",
          "net.sf.cglib.proxy",
          "com.seaglasslookandfeel",
          "org.pushingpixels",
          "net.sourceforge.napkinlaf.",
          "com.kenai.jaffl"
        };
    allowed =
        new String[] {
          "phobos",
          "com.sun.script.",
          "com.sun.scenario",
          "com.sun.stylesheet",
          "com.sun.opengl",
          "com.sun.gluegen",
          "javax.media.opengl",
          "javax.media.nativewindow",
          "javax.jmdns"
        };

    if (exceptions != null) {

      ArrayList a = new ArrayList(Arrays.asList(ignored));
      a.addAll(Arrays.asList(exceptions.split(":")));
      ignored = (String[]) a.toArray(ignored);
    }

    loader =
        new MyClassLoader(
            ((URLClassLoader) this.getClass().getClassLoader()).getURLs(),
            (this.getClass().getClassLoader()));
    System.setSecurityManager(new PermissiveSecurityManager());

    String extendedJars = SystemProperties.getProperty("extendedJars", null);
    if (extendedJars != null) {
      String[] ex = extendedJars.split(":");
      for (String e : ex) {; // System.out.println(" adding jar <" + e +
        // ">");
        addJar(e);
      }
    }

    Vector v =
        (Vector) ReflectionTools.illegalGetObject(this.getClass().getClassLoader(), "classes");
    if (debug) ; // System.out.println(" already loaded all of <" + v +
    // ">");

    if (!System.getProperty("asserts", "none").equals("none"))
      loader.setDefaultAssertionStatus(true);

    Thread.currentThread().setContextClassLoader(loader);

    String extensionsDir = SystemProperties.getProperty("extensions.dir", "../../extensions/");
    Trampoline2.trampoline.addExtensionsDirectory(new File(extensionsDir));
    String extensionsDir2 =
        System.getProperty("user.home") + "/Library/Application Support/Field/extensions";

    if (!new File(extensionsDir2).exists()) new File(extensionsDir2).mkdirs();

    if (new File(extensionsDir2).exists())
      Trampoline2.trampoline.addExtensionsDirectory(new File(extensionsDir2));

    try {; // System.out.println(Arrays.asList(loader.getURLs()));
      final Class c = (loader.loadClass(classToLaunch));
      ; // System.out.println(" c = " + c + " " +
      // c.getClassLoader() + " " + loader);
      try {
        Method main = c.getDeclaredMethod("main", new Class[] {new String[0].getClass()});
        try {
          main.invoke(null, new Object[] {null});
          return;
        } catch (IllegalArgumentException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
        }
        return;
      } catch (SecurityException e) {
        e.printStackTrace();
        return;
      } catch (NoSuchMethodException e) {
      }

      Launcher.getLauncher().mainThread = Thread.currentThread();
      printInfo();
      Launcher.mainInstance = (iLaunchable) c.newInstance();
      printInfo();
      Launcher.mainInstance.launch();
      printInfo();
      printInfo();

    } catch (Throwable e) {
      e.printStackTrace();
      if (SystemProperties.getIntProperty("exitOnException", 0) == 1
          || e instanceof Error
          || e.getCause() instanceof Error) System.exit(1);
    }

    if (SystemProperties.getIntProperty("nosave", 0) == 1)
      System.setSecurityManager(new NoWriteSecurityManager());
    else if (SystemProperties.getIntProperty("collectResources", 0) == 1)
      System.setSecurityManager(new CollectResourcesSecurityManager());
    else System.setSecurityManager(new NoopSecurityManager());
  }
	public static List<JarClassModel> getJarMethod(String jarFile,String dependfile) throws Exception {
		
        String NORMAL_METHOD= "waitequalsnotifynotifyAlltoStringhashCodegetClass"; 
        List<JarClassModel> jarClassModels = new ArrayList<>();
 //       List<String[]> a = new ArrayList<String[]>();


/*        MyClassLoader myclassLoader = new MyClassLoader(urls,null);
*/        
        try {
            //通过jarFile 和JarEntry得到所有的类
            JarFile jar = new JarFile(jarFile);//
            Enumeration<JarEntry> e = jar.entries();
            while (e.hasMoreElements()) {
                JarEntry entry = (JarEntry) e.nextElement();
                //entry.getMethod()
                if (entry.getName().indexOf("META-INF") < 0) {
                    String sName = entry.getName();
                    String substr[] = sName.split("/");
                    String pName = "";
                    for (int i = 0; i < substr.length - 1; i++) {
                        if (i > 0)
                            pName = pName + "." + substr[i];
                        else
                            pName = substr[i];
                    }
                    //System.out.println(pName);
                    if (sName.indexOf(".class") < 0)
                    {
                        sName = sName.substring(0, sName.length() - 1);
                    }
                    else
                    {
                         //通过URLClassLoader.loadClass方法得到具体某个类 
                    	URL[] urls=new URL[]{};
                    	MyClassLoader myClassLoader=new MyClassLoader(urls,null);
                        if (dependfile != null) {
							List<String> dependjarlist = getDependJarFiles(dependfile);
	                    	for (String string : dependjarlist) {
								URL url=new URL("file:"+string);
								myClassLoader.addJar(url);
							}
						}
                    	                   	
                       
                        URL url1=new URL("file:"+jarFile);
                        myClassLoader.addJar(url1);
                        
                        String ppName = sName.replace("/", ".").replace(".class", "");
                        Class<?> myClass = null;
                        try {
                        	myClass = myClassLoader.loadClass(ppName);
                        	
						} catch (ClassNotFoundException e2) {
							// TODO: handle exception
							System.out.println("class not found exception");
				        	e2.printStackTrace();
						}
                       
                       /* //通过getMethods得到类中包含的方法
                        
	                     System.out.println("------------------------------------------------");
	                     System.out.println("sName:"+sName);
	                     System.out.println("pName:"+pName);
	                     System.out.println("ppName:"+ppName);
						*/
						Method m[] = myClass.getMethods();
	                     
	                   
	                     if (m.length>0) {
	                    	 
	                    	JarClassModel jarClassModel = new JarClassModel(pName,ppName);
	                    	 
	                        for(int i=0; i<m.length; i++){
	                            String sm = m[i].getName();
	                            
	                            if (NORMAL_METHOD.indexOf(sm) <0)
	                            {
	                            	JarMethodModel jarMethodModel = new JarMethodModel(sm);
//	                            	System.out.println("sm:"+sm);
	                            	Type[] parameter = m[i].getGenericParameterTypes();
	                            	List<String> paraList = new ArrayList<String>();
	                            	for (int j = 0; j < parameter.length; j++) {
	                            		if (parameter[j].toString().contains(" ")) {
//	                            			System.out.println(parameter[j].toString().split(" ")[0]);
//											System.out.println(parameter[j].toString().split(" ")[1]);
											paraList.add(parameter[j].toString().split(" ")[1]);
										}else {
//											System.out.println("para:"+parameter[j].toString());
											paraList.add(parameter[j].toString());
										}                       		
										
									}
	                            	jarMethodModel.setParameters(paraList);
	                            	jarClassModel.addmethod(jarMethodModel);
	                            }
	                            
	                        }
	                        jarClassModels.add(jarClassModel);
	                     }
	                     
//	                      System.out.println("------------------------------------------------");
                    }

                }
            }
            return jarClassModels;
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            //e1.printStackTrace();
        } catch (NullPointerException e2){
        	//e2.printStackTrace();
        } catch (Exception e) {
			// TODO: handle exception
        	//e.printStackTrace();
		}
        return jarClassModels;
    }