Skip to content

Commit

Permalink
turns out getResourcePaths() are no good because "mvn jetty:run" won'…
Browse files Browse the repository at this point in the history
…t put things there.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2140 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information
kohsuke committed Feb 10, 2007
1 parent 4a66510 commit bd59be0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
41 changes: 41 additions & 0 deletions core/src/main/java/hudson/model/Slave.java
Expand Up @@ -29,6 +29,8 @@
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;

Expand Down Expand Up @@ -311,6 +313,13 @@ public void doProgressiveLog( StaplerRequest req, StaplerResponse rsp) throws IO
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();
Expand Down Expand Up @@ -339,6 +348,38 @@ protected void setNode(Node node) {
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 {
Expand Down
Expand Up @@ -6,7 +6,7 @@
<l:isAdmin>
<!-- See http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html for the syntax -->
<jnlp spec="1.0+"
codebase="${rootURL}/computer/${it.node.nodName}/">
codebase="${rootURL}/computer/${it.node.nodeName}/">

<information>
<title>Slave Agent for ${it.displayName}</title>
Expand All @@ -15,12 +15,13 @@
</information>

<security>
<all-permissions/>
<all-permissions/>
</security>

<resources>
<j2se version="1.5"/>
<jar href="jnlp-agent.jar"/>
<jar href="jnlpJars/hudson.jnlp.Main"/><!-- JNLP agent jar -->
<jar href="jnlpJars/hudson.remoting.Channel"/><!-- remoting jar -->
</resources>

<application-desc main-class="hudson.jnlp.Main">
Expand Down

0 comments on commit bd59be0

Please sign in to comment.