1 package hudson.maven.agent; 2 3 import org.codehaus.classworlds.ClassRealm; 4 import org.codehaus.classworlds.Launcher; 5 import org.codehaus.classworlds.NoSuchRealmException; 6 7 import java.io.ByteArrayInputStream ; 8 import java.io.File ; 9 import java.io.InputStream ; 10 import java.io.OutputStream ; 11 import java.lang.reflect.InvocationTargetException ; 12 13 23 public class Main { 24 27 private static Launcher launcher; 28 29 public static void main(String [] args) throws Exception { 30 main(new File (args[0]),new File (args[1]),new File (args[2])); 31 } 32 33 public static void main(File m2Home, File remotingJar, File interceptorJar) throws Exception { 34 System.setProperty("maven.home",m2Home.getPath()); 35 System.setProperty("maven.interceptor",interceptorJar.getPath()); 36 37 launcher = new Launcher(); 39 launcher.setSystemClassLoader(Main.class.getClassLoader()); 40 launcher.configure(Main.class.getResourceAsStream("classworlds.conf")); 41 42 44 ClassRealm remoting = launcher.getWorld().getRealm("plexus.core.maven").createChildRealm("hudson-remoting"); 47 remoting.addConstituent(remotingJar.toURL()); 48 49 OutputStream os = System.out; 52 System.setOut(System.err); 53 InputStream is = System.in; 54 System.setIn(new ByteArrayInputStream (new byte[0])); 55 56 Class remotingLauncher = remoting.loadClass("hudson.remoting.Launcher"); 57 remotingLauncher.getMethod("main",InputStream .class,OutputStream .class).invoke(null,is,os); 58 System.exit(0); 59 } 60 61 64 public static int launch(String [] args) throws NoSuchMethodException , IllegalAccessException , NoSuchRealmException, InvocationTargetException , ClassNotFoundException { 65 launcher.launch(args); 66 return launcher.getExitCode(); 67 } 68 } | Popular Tags |