1 28 29 package org.jibx.match; 30 31 import java.io.File ; 32 import java.lang.reflect.InvocationTargetException ; 33 import java.lang.reflect.Method ; 34 35 import org.jibx.binding.Loader; 36 37 49 50 public class TestLoaderDiff 51 { 52 private static final Class [] RUNNER_PARAM_TYPES = 53 { 54 String .class, String .class, String .class 55 }; 56 57 private TestLoaderDiff() {} 58 59 public static void main(String [] args) 60 throws ClassNotFoundException , NoSuchMethodException { 61 if (args.length >= 4 && args.length % 4 == 0) { 62 63 File temp = new File ("temp.xml"); 65 if (temp.exists()) { 66 temp.delete(); 67 } 68 69 boolean err = false; 71 int offset = 0; 72 String [] pargs = new String [3]; 73 ClassLoader base = Thread.currentThread().getContextClassLoader(); 74 for (; offset < args.length; offset += 4) { 75 try { 76 77 Thread.currentThread().setContextClassLoader(base); 79 Loader loader = new Loader(); 80 loader.loadResourceBinding(args[offset]); 81 82 Thread.currentThread().setContextClassLoader(loader); 84 Class clas = loader.loadClass("org.jibx.match.TestRunner"); 85 Method test = clas.getDeclaredMethod("runTest", 86 RUNNER_PARAM_TYPES); 87 pargs[0] = args[offset+1]; 88 pargs[1] = args[offset+2]; 89 pargs[2] = args[offset+3]; 90 Boolean result = (Boolean )test.invoke(null, pargs); 91 if (!result.booleanValue()) { 92 err = true; 93 break; 94 } 95 } catch (InvocationTargetException ex) { 96 ex.getTargetException().printStackTrace(); 97 err = true; 98 break; 99 } catch (Exception ex) { 100 ex.printStackTrace(); 101 err = true; 102 break; 103 } 104 } 105 106 if (err) { 108 System.err.println("Error on argument set: " + 109 args[offset] + ", " + args[offset+1] + ", " + args[offset+2] + 110 ", " + args[offset+3]); 111 System.err.println("File path " + temp.getAbsolutePath()); 112 System.exit(1); 113 } 114 115 } else { 116 System.err.println("Requires arguments in sets of four:\n" + 117 " binding-resource mapped-class in-file comp-file\n" + 118 "Leaves output as temp.xml in case of error"); 119 System.exit(1); 120 } 121 } 122 } | Popular Tags |