1 11 package org.eclipse.pde.internal.junit.runtime; 12 13 import java.io.IOException ; 14 import java.net.URL ; 15 import java.util.Enumeration ; 16 import java.util.Locale ; 17 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.jdt.internal.junit.runner.RemoteTestRunner; 20 import org.osgi.framework.Bundle; 21 22 25 public class RemotePluginTestRunner extends RemoteTestRunner { 26 27 private String fTestPluginName; 28 private ClassLoader fLoaderClassLoader; 29 30 class BundleClassLoader extends ClassLoader { 31 private Bundle bundle; 32 public BundleClassLoader(Bundle target) { 33 this.bundle = target; 34 } 35 protected Class findClass(String name) throws ClassNotFoundException { 36 return bundle.loadClass(name); 37 } 38 protected URL findResource(String name) { 39 return bundle.getResource(name); 40 } 41 protected Enumeration findResources(String name) throws IOException { 42 return bundle.getResources(name); 43 } 44 } 45 46 54 55 public static void main(String [] args) { 56 RemotePluginTestRunner testRunner= new RemotePluginTestRunner(); 57 testRunner.init(args); 58 testRunner.run(); 59 } 60 61 65 protected ClassLoader getTestClassLoader() { 66 final String pluginId = fTestPluginName; 67 return getClassLoader(pluginId); 68 } 69 70 public ClassLoader getClassLoader(final String pluginId) { 71 Bundle bundle = Platform.getBundle(pluginId); 72 if (bundle == null) 73 throw new IllegalArgumentException ("No Classloader found for plug-in " + pluginId); return new BundleClassLoader(bundle); 75 } 76 77 public void init(String [] args) { 78 readPluginArgs(args); 79 defaultInit(args); 80 } 81 82 public void readPluginArgs(String [] args) { 83 for (int i = 0; i < args.length; i++) { 84 if (isFlag(args, i, "-testpluginname")) fTestPluginName = args[i + 1]; 86 87 if (isFlag(args, i, "-loaderpluginname")) fLoaderClassLoader = getClassLoader(args[i + 1]); 89 } 90 91 if (fTestPluginName == null) 92 throw new IllegalArgumentException ("Parameter -testpluginnname not specified."); 94 if (fLoaderClassLoader == null) 95 fLoaderClassLoader = getClass().getClassLoader(); 96 } 97 98 protected Class loadTestLoaderClass(String className) throws ClassNotFoundException { 99 return fLoaderClassLoader.loadClass(className); 100 } 101 102 private boolean isFlag(String [] args, int i, final String wantedFlag) { 103 String lowerCase = args[i].toLowerCase(Locale.ENGLISH); 104 return lowerCase.equals(wantedFlag) && i < args.length - 1; 105 } 106 } 107 | Popular Tags |