提交 6e211c37 编写于 作者: K kohsuke

Merged jnlp-agent and remoting module, so that the JNLP like proactive...

Merged jnlp-agent and remoting module, so that the JNLP like proactive connection mode is available through slave.jar

This allows us to define another launch mode, especially suitable for running as a service on Windows.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@12181 71c3de6d-444a-0410-be80-ed276b4c234a
上级 46a30e21
jnlp-agent.iws
jnlp-agent.ipr
jnlp-agent.iml
target
.classpath
.project
.settings
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jvnet.hudson.main</groupId>
<artifactId>pom</artifactId>
<version>1.253-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>jnlp-agent</artifactId>
<packaging>jar</packaging>
<name>Hudson JNLP slave agent</name>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<!--
during the development, debug profile defined in ../pom.xml will cause
the jars to be signed by a self-certified dummy public key.
For release, you should define the real values in ~/.m2/settings.xml
-->
<alias>${hudson.sign.alias}</alias>
<storepass>${hudson.sign.storepass}</storepass>
<keystore>${hudson.sign.keystore}</keystore>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<executions>
<execution>
<!-- rejar args4j contents -->
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<resolveArtifact artifactId="args4j" property="args4j.jar" />
<unjar src="${args4j.jar}" dest="target/classes" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jvnet.hudson.main</groupId>
<artifactId>remoting</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -18,7 +18,6 @@
<modules>
<module>remoting</module>
<module>core</module>
<module>jnlp-agent</module>
<module>maven-agent</module>
<module>maven-interceptor</module>
<module>war</module>
......
......@@ -54,6 +54,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<executions>
<execution>
<!-- rejar args4j contents -->
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<resolveArtifact artifactId="args4j" property="args4j.jar" />
<unjar src="${args4j.jar}" dest="target/classes" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
......@@ -71,5 +90,11 @@
<version>2.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package hudson.remoting;
import hudson.remoting.Channel.Mode;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* Entry point for running a {@link Channel} that uses stdin/stdout.
* Entry point for running a {@link Channel}.
*
* <p>
* This can be used as the main class for launching a channel on
......@@ -23,8 +30,10 @@ public class Launcher {
public static void main(String[] args) throws Exception {
Mode m = Mode.BINARY;
boolean ping = false;
URL slaveJnlpURL = null;
for (String arg : args) {
for(int i=0; i<args.length; i++) {
String arg = args[i];
if(arg.equals("-text")) {
System.out.println("Running in text mode");
m = Mode.TEXT;
......@@ -34,10 +43,38 @@ public class Launcher {
ping = true;
continue;
}
if(arg.equals("-jnlpUrl")) {
if(i+1==args.length) {
System.err.println("The -jnlpUrl option is missing a URL parameter");
System.exit(1);
}
slaveJnlpURL = new URL(args[i+1]);
continue;
}
System.err.println("Invalid option: "+arg);
System.exit(-1);
}
if(slaveJnlpURL!=null) {
// exec into the JNLP launcher, to fetch the connection parameter through JNLP.
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document dom = db.parse(slaveJnlpURL.toExternalForm());
NodeList argElements = dom.getElementsByTagName("argument");
List<String> jnlpArgs = new ArrayList<String>();
for( int i=0; i<argElements.getLength(); i++ )
jnlpArgs.add(argElements.item(i).getTextContent());
// force a headless mode
jnlpArgs.add("-headless");
hudson.remoting.jnlp.Main.main(jnlpArgs.toArray(new String[jnlpArgs.size()]));
} else
runWithStdinStdout(m, ping);
System.exit(0);
}
private static void runWithStdinStdout(Mode m, boolean ping) throws IOException, InterruptedException {
// use stdin/stdout for channel communication
ttyCheck();
// this will prevent programs from accidentally writing to System.out
......@@ -45,7 +82,6 @@ public class Launcher {
OutputStream os = System.out;
System.setOut(System.err);
main(System.in,os,m,ping);
System.exit(0);
}
private static void ttyCheck() {
......
package hudson.jnlp;
package hudson.remoting.jnlp;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
......
package hudson.jnlp;
package hudson.remoting.jnlp;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.CmdLineParser;
......
package hudson.jnlp;
package hudson.remoting.jnlp;
import hudson.remoting.jnlp.GUI;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
......
/**
* Code for launching the remote agent through JNLP.
*
* <p>
* This involves in getting the connection parameters through command line,
* which is provided from <tt>slave-agent.jnlp.jelly</tt> file in the core.
*/
package hudson.remoting.jnlp;
......@@ -77,7 +77,6 @@
<!-- dependencies that goes to unusual locations -->
<resolveArtifact artifactId="remoting" tofile="${basedir}/target/generated-resources/WEB-INF/remoting.jar" />
<resolveArtifact artifactId="remoting" tofile="${basedir}/target/generated-resources/WEB-INF/slave.jar" />
<resolveArtifact artifactId="jnlp-agent" tofile="${basedir}/target/generated-resources/WEB-INF/jnlp-agent.jar" />
<resolveArtifact artifactId="winstone" tofile="${basedir}/target/generated-resources/winstone.jar" />
</tasks>
</configuration>
......@@ -132,16 +131,6 @@
</build>
<dependencies>
<dependency>
<groupId>org.jvnet.hudson.main</groupId>
<artifactId>jnlp-agent</artifactId>
<version>${project.version}</version>
<!--
not really a test scope, but we use dependency-maven-plugin to copy this jar,
so we don't want this to be bundled in war by maven-war-plugin.
-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.main</groupId>
<artifactId>hudson-core</artifactId>
......@@ -196,10 +185,6 @@
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
</exclusion>
<exclusion>
<groupId>jaxme</groupId>
<artifactId>jaxme-api</artifactId>
......@@ -305,7 +290,12 @@
</goals>
<configuration>
<tasks>
<!-- see ../jnlp-agent/pom.xml for details -->
<!--
during the development, debug profile defined in ../pom.xml will cause
the jars to be signed by a self-certified dummy public key.
For release, you should define the real values in ~/.m2/settings.xml
-->
<signjar jar="target/hudson.war" alias="${hudson.sign.alias}" keystore="${hudson.sign.keystore}" storepass="${hudson.sign.storepass}" />
</tasks>
</configuration>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册