mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
turns out getResourcePaths() are no good because "mvn jetty:run" won't put things there.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2140 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
4a66510c12
commit
bd59be00ab
2 files changed
+45
-3
No files matched your search
@@ -29,6 +29,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -311,6 +313,13 @@ public final class Slave implements Node, Serializable {
|
||||
new LargeText(getLogFile(),false).doProgressText(req,rsp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves jar files for JNLP slave agents.
|
||||
*/
|
||||
public JnlpJar getJnlpJars(String fileName) {
|
||||
return new JnlpJar(fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void kill() {
|
||||
super.kill();
|
||||
@@ -339,6 +348,38 @@ public final class Slave implements Node, Serializable {
|
||||
private static final Logger logger = Logger.getLogger(ComputerImpl.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Web-bound object used to serve jar files for JNLP.
|
||||
*/
|
||||
public static final class JnlpJar {
|
||||
private final String className;
|
||||
|
||||
public JnlpJar(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public void doIndex( StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
|
||||
// where is the jar file?
|
||||
// we can't use ServletContext.getResourcePaths() because
|
||||
// during debugging there's no WEB-INF/lib.
|
||||
URL classFile = getClass().getClassLoader().getResource(className.replace('.', '/') + ".class");
|
||||
if(classFile==null) {
|
||||
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
String loc = classFile.toExternalForm().substring(4);// cut off jar:
|
||||
loc = loc.substring(0,loc.lastIndexOf('!'));
|
||||
|
||||
|
||||
URLConnection con = new URL(loc).openConnection();
|
||||
InputStream in = con.getInputStream();
|
||||
rsp.serveFile(req, in, con.getLastModified(), con.getContentLength(), "*.jar" );
|
||||
in.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Launcher createLauncher(TaskListener listener) {
|
||||
return new Launcher(listener, getComputer().getChannel()) {
|
||||
public Proc launch(final String[] cmd, final String[] env, InputStream _in, OutputStream _out, FilePath _workDir) throws IOException {
|
||||
|
||||
Reference in new issue
Block a user