提交 65ae5f44 编写于 作者: K kohsuke

moved the code to remoting for better reuse.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2292 71c3de6d-444a-0410-be80-ed276b4c234a
上级 400bbdaf
...@@ -2,6 +2,7 @@ package hudson.maven.agent; ...@@ -2,6 +2,7 @@ package hudson.maven.agent;
import hudson.remoting.Channel; import hudson.remoting.Channel;
import hudson.remoting.Launcher; import hudson.remoting.Launcher;
import hudson.remoting.Which;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.codehaus.classworlds.ClassWorld; import org.codehaus.classworlds.ClassWorld;
...@@ -30,15 +31,15 @@ public class LaunchTest extends TestCase { ...@@ -30,15 +31,15 @@ public class LaunchTest extends TestCase {
//args.add("-Xrunjdwp:transport=dt_socket,server=y,address=8000"); //args.add("-Xrunjdwp:transport=dt_socket,server=y,address=8000");
args.add("-cp"); args.add("-cp");
args.add(toJarFile(Main.class)+File.pathSeparator+toJarFile(ClassWorld.class)); args.add(Which.jarFile(Main.class)+File.pathSeparator+Which.jarFile(ClassWorld.class));
args.add(Main.class.getName()); args.add(Main.class.getName());
// M2_HOME // M2_HOME
args.add("c:\\development\\Java\\maven2"); args.add("c:\\development\\Java\\maven2");
// remoting.jar // remoting.jar
args.add(toJarFile(Launcher.class).getPath()); args.add(Which.jarFile(Launcher.class).getPath());
// interceptor.jar // interceptor.jar
args.add(toJarFile(PluginManagerInterceptor.class).getPath()); args.add(Which.jarFile(PluginManagerInterceptor.class).getPath());
System.out.println("Launching "+args); System.out.println("Launching "+args);
...@@ -65,60 +66,6 @@ public class LaunchTest extends TestCase { ...@@ -65,60 +66,6 @@ public class LaunchTest extends TestCase {
System.out.println("done"); System.out.println("done");
} }
/**
* Finds the jar file that contains the class.
*/
private File toJarFile(Class clazz) throws IOException, URISyntaxException {
String res = clazz.getClassLoader().getResource(clazz.getName().replace('.', '/') + ".class").toExternalForm();
if(res.startsWith("jar:")) {
res = res.substring(4,res.lastIndexOf('!')); // cut off jar: and the file name portion
return new File(decode(new URL(res).getPath()));
}
if(res.startsWith("file:")) {
// unpackaged classes
int n = clazz.getName().split("\\.").length; // how many slashes do wo need to cut?
for( ; n>0; n-- ) {
int idx = Math.max(res.lastIndexOf('/'), res.lastIndexOf('\\'));
res = res.substring(0,idx);
}
// won't work if res URL contains ' '
// return new File(new URI(null,new URL(res).toExternalForm(),null));
// won't work if res URL contains '%20'
// return new File(new URL(res).toURI());
return new File(decode(new URL(res).getPath()));
}
throw new IllegalArgumentException(res);
}
/**
* Decode '%HH'.
*/
private static String decode(String s) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for( int i=0; i<s.length();i++ ) {
char ch = s.charAt(i);
if(ch=='%') {
baos.write(hexToInt(s.charAt(i+1))*16 + hexToInt(s.charAt(i+2)));
i+=2;
continue;
}
baos.write(ch);
}
try {
return new String(baos.toByteArray(),"UTF-8");
} catch (UnsupportedEncodingException e) {
throw new Error(e); // impossible
}
}
private static int hexToInt(int ch) {
return Character.getNumericValue(ch);
}
public static void copyStream(InputStream in, OutputStream out) throws IOException { public static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] buf = new byte[8192]; byte[] buf = new byte[8192];
int len; int len;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册