Skip to content

Commit

Permalink
Merge pull request #8 from ndeloof/JENKINS-21746
Browse files Browse the repository at this point in the history
accept TCP communication socket parameter as `[ip:]port`
  • Loading branch information
ndeloof committed Aug 18, 2015
2 parents 5792f2a + a40fbf9 commit baebe81
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 54 deletions.
Expand Up @@ -61,8 +61,22 @@ public class Maven3Main {
private static Launcher launcher;

public static void main(String... args) throws Exception {
main(new File(args[0]), new File(args[1]),new File(args[2]),
new File(args[3]), Integer.parseInt(args[4]));
String slaveAgentSocket = args[4];
int i = slaveAgentSocket.indexOf(':');
if (i > 0) {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), slaveAgentSocket.substring(0, i), Integer.parseInt(slaveAgentSocket.substring(i+1)));
} else {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), null, Integer.parseInt(slaveAgentSocket));
}
}

@Deprecated
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {

main(m2Home, remotingJar, interceptorJar, interceptorCommonJar, null, tcpPort);
}

/**
Expand All @@ -76,12 +90,14 @@ public static void main(String... args) throws Exception {
* maven-listener.jar that we'll load.
* @param interceptorCommonJar
* maven3-interceptor-commons.jar we'll load
* @param agentIp
* IP address the TCP socket is bound to
* @param tcpPort
* TCP socket that the launching Hudson will be listening to.
* This is used for the remoting communication.
*/
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {
public static void main(File m2Home, File remotingJar, File interceptorJar,
File interceptorCommonJar, String agentIp, int tcpPort) throws Exception {
// Unix master with Windows slave ends up passing path in Unix format,
// so convert it to Windows format now so that no one chokes with the
// path format later.
Expand Down Expand Up @@ -117,20 +133,7 @@ public static void main(File m2Home, File remotingJar, File interceptorJar
remoting.setParentRealm(launcher.getWorld().getRealm("plexus.core"));
remoting.addURL(remotingJar.toURI().toURL());

final Socket s;

String mavenRemoteUseInetEnvVar = System.getenv( "MAVEN_REMOTE_USEINET" );

boolean mavenRemoteUseInet = Boolean.parseBoolean( mavenRemoteUseInetEnvVar );

if(mavenRemoteUseInet) {
InetAddress host = InetAddress.getLocalHost();
String hostname = host.getHostName();
System.out.println( "use inet address " + hostname );
s = new Socket(hostname,tcpPort);
}
else
s = new Socket((String)null,tcpPort);
final Socket s = new Socket(agentIp,tcpPort);

Class remotingLauncher = remoting.loadClass("hudson.remoting.Launcher");
remotingLauncher.getMethod("main",
Expand Down
40 changes: 22 additions & 18 deletions maven31-agent/src/main/java/jenkins/maven3/agent/Maven31Main.java
Expand Up @@ -64,10 +64,25 @@ public class Maven31Main
private static Launcher launcher;

public static void main(String... args) throws Exception {
main(new File(args[0]), new File(args[1]),new File(args[2]),
new File(args[3]), Integer.parseInt(args[4]));
String slaveAgentSocket = args[4];
int i = slaveAgentSocket.indexOf(':');
if (i > 0) {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), slaveAgentSocket.substring(0, i), Integer.parseInt(slaveAgentSocket.substring(i+1)));
} else {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), null, Integer.parseInt(slaveAgentSocket));
}
}

@Deprecated
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {

main(m2Home, remotingJar, interceptorJar, interceptorCommonJar, null, tcpPort);
}


/**
*
* @param m2Home
Expand All @@ -79,12 +94,14 @@ public static void main(String... args) throws Exception {
* maven-listener.jar that we'll load.
* @param interceptorCommonJar
* maven3-interceptor-commons.jar we'll load
* @param agentIp
* IP address the TCP socket is bound to
* @param tcpPort
* TCP socket that the launching Hudson will be listening to.
* This is used for the remoting communication.
*/
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {
public static void main(File m2Home, File remotingJar, File interceptorJar,
File interceptorCommonJar, String agentIp, int tcpPort) throws Exception {
// Unix master with Windows slave ends up passing path in Unix format,
// so convert it to Windows format now so that no one chokes with the
// path format later.
Expand Down Expand Up @@ -120,20 +137,7 @@ public static void main(File m2Home, File remotingJar, File interceptorJar
remoting.setParentRealm(launcher.getWorld().getRealm("plexus.core"));
remoting.addURL(remotingJar.toURI().toURL());

final Socket s;

String mavenRemoteUseInetEnvVar = System.getenv( "MAVEN_REMOTE_USEINET" );

boolean mavenRemoteUseInet = Boolean.parseBoolean( mavenRemoteUseInetEnvVar );

if(mavenRemoteUseInet) {
InetAddress host = InetAddress.getLocalHost();
String hostname = host.getHostName();
System.out.println( "use inet address " + hostname );
s = new Socket(hostname,tcpPort);
}
else
s = new Socket((String)null,tcpPort);
final Socket s = new Socket(agentIp,tcpPort);

Class remotingLauncher = remoting.loadClass("hudson.remoting.Launcher");
remotingLauncher.getMethod("main",
Expand Down
41 changes: 23 additions & 18 deletions maven32-agent/src/main/java/jenkins/maven3/agent/Maven32Main.java
Expand Up @@ -39,6 +39,7 @@
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;


/**
Expand All @@ -64,10 +65,25 @@ public class Maven32Main
private static Launcher launcher;

public static void main(String... args) throws Exception {
main(new File(args[0]), new File(args[1]),new File(args[2]),
new File(args[3]), Integer.parseInt(args[4]));
String slaveAgentSocket = args[4];
int i = slaveAgentSocket.indexOf(':');
if (i > 0) {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), slaveAgentSocket.substring(0, i), Integer.parseInt(slaveAgentSocket.substring(i+1)));
} else {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), null, Integer.parseInt(slaveAgentSocket));
}
}

@Deprecated
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {

main(m2Home, remotingJar, interceptorJar, interceptorCommonJar, null, tcpPort);
}


/**
*
* @param m2Home
Expand All @@ -79,12 +95,14 @@ public static void main(String... args) throws Exception {
* maven-listener.jar that we'll load.
* @param interceptorCommonJar
* maven3-interceptor-commons.jar we'll load
* @param agentIp
* IP address the TCP socket is bound to
* @param tcpPort
* TCP socket that the launching Hudson will be listening to.
* This is used for the remoting communication.
*/
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {
public static void main(File m2Home, File remotingJar, File interceptorJar,
File interceptorCommonJar, String agentIp, int tcpPort) throws Exception {
// Unix master with Windows slave ends up passing path in Unix format,
// so convert it to Windows format now so that no one chokes with the
// path format later.
Expand Down Expand Up @@ -120,20 +138,7 @@ public static void main(File m2Home, File remotingJar, File interceptorJar
remoting.setParentRealm(launcher.getWorld().getRealm("plexus.core"));
remoting.addURL(remotingJar.toURI().toURL());

final Socket s;

String mavenRemoteUseInetEnvVar = System.getenv( "MAVEN_REMOTE_USEINET" );

boolean mavenRemoteUseInet = Boolean.parseBoolean( mavenRemoteUseInetEnvVar );

if(mavenRemoteUseInet) {
InetAddress host = InetAddress.getLocalHost();
String hostname = host.getHostName();
System.out.println( "use inet address " + hostname );
s = new Socket(hostname,tcpPort);
}
else
s = new Socket((String)null,tcpPort);
final Socket s = new Socket(agentIp,tcpPort);

Class remotingLauncher = remoting.loadClass("hudson.remoting.Launcher");
remotingLauncher.getMethod("main",
Expand Down

0 comments on commit baebe81

Please sign in to comment.