Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinston Prakash2012-02-03 18:57:19 -0500
committerWinston Prakash2012-02-03 18:57:19 -0500
commitf8941c880cdfb0bd00ceff9684576dfb6496b827 (patch)
tree210ff2990a02e70160396a15592d7c75a8b7bda2
parent4ac40d5139bb2d5763f700ac416c3873317fe6f2 (diff)
downloadorg.eclipse.hudson.core-f8941c880cdfb0bd00ceff9684576dfb6496b827.tar.gz
org.eclipse.hudson.core-f8941c880cdfb0bd00ceff9684576dfb6496b827.tar.xz
org.eclipse.hudson.core-f8941c880cdfb0bd00ceff9684576dfb6496b827.zip
Add the --logfile and --prefix options to the jetty launcher
-rw-r--r--hudson-jetty-war-executable/nbactions.xml40
-rw-r--r--hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/jetty/JettyLauncher.java21
-rwxr-xr-xhudson-jetty-war-executable/src/main/java/org/eclipse/hudson/war/Executable.java88
3 files changed, 117 insertions, 32 deletions
diff --git a/hudson-jetty-war-executable/nbactions.xml b/hudson-jetty-war-executable/nbactions.xml
new file mode 100644
index 00000000..2692b445
--- /dev/null
+++ b/hudson-jetty-war-executable/nbactions.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+ <action>
+ <actionName>run</actionName>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
+ </goals>
+ <properties>
+ <exec.args>-classpath %classpath org.eclipse.hudson.war.Executable --prefix=jetty</exec.args>
+ <exec.executable>java</exec.executable>
+ <exec.classpathScope>runtime</exec.classpathScope>
+ </properties>
+ </action>
+ <action>
+ <actionName>debug</actionName>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
+ </goals>
+ <properties>
+ <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.eclipse.hudson.war.Executable --prefix=jetty</exec.args>
+ <exec.executable>java</exec.executable>
+ <exec.classpathScope>runtime</exec.classpathScope>
+ <jpda.listen>true</jpda.listen>
+ </properties>
+ </action>
+ <action>
+ <actionName>profile</actionName>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
+ </goals>
+ <properties>
+ <exec.args>${profiler.args} -classpath %classpath org.eclipse.hudson.war.Executable --prefix=jetty</exec.args>
+ <exec.executable>${profiler.java}</exec.executable>
+ <profiler.action>profile</profiler.action>
+ </properties>
+ </action>
+ </actions>
diff --git a/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/jetty/JettyLauncher.java b/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/jetty/JettyLauncher.java
index 940b4cdc..abf93e10 100644
--- a/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/jetty/JettyLauncher.java
+++ b/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/jetty/JettyLauncher.java
@@ -12,8 +12,8 @@
*
* Winston Prakash
*
- *******************************************************************************/
-
+ ******************************************************************************
+ */
package org.eclipse.hudson.jetty;
import java.io.File;
@@ -24,10 +24,13 @@ import org.mortbay.jetty.webapp.WebAppContext;
/**
* Jetty Utility to launch the Jetty Server
+ *
* @author Winston Prakash
*/
public class JettyLauncher {
+ private static String contextPath = "/";
+
public static void start(String[] args, URL warUrl) throws Exception {
int port = 8080;
@@ -36,10 +39,12 @@ public class JettyLauncher {
if (args[i].startsWith("--httpPort=")) {
String portStr = args[i].substring("--httpPort=".length());
port = Integer.parseInt(portStr);
- }
+ } else if (args[i].startsWith("--prefix=")) {
+ contextPath = "/" + args[i].substring("--prefix=".length());
+ }
}
- Server server = new Server(port);
+ final Server server = new Server(port);
SocketConnector connector = new SocketConnector();
WebAppContext context = new WebAppContext();
@@ -47,8 +52,8 @@ public class JettyLauncher {
File tempDir = new File(getHomeDir(), "war");
tempDir.mkdirs();
context.setTempDirectory(tempDir);
-
- context.setContextPath("/");
+
+ context.setContextPath(contextPath);
context.setDescriptor(warUrl.toExternalForm() + "/WEB-INF/web.xml");
context.setServer(server);
context.setWar(warUrl.toExternalForm());
@@ -58,10 +63,12 @@ public class JettyLauncher {
System.setProperty("executable-war", warUrl.getPath());
server.addHandler(context);
+ server.setStopAtShutdown(true);
+
server.start();
server.join();
}
-
+
/**
* Get the home directory for Hudson.
*/
diff --git a/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/war/Executable.java b/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/war/Executable.java
index 158259ec..79d4aa84 100755
--- a/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/war/Executable.java
+++ b/hudson-jetty-war-executable/src/main/java/org/eclipse/hudson/war/Executable.java
@@ -21,9 +21,7 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
+import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -35,38 +33,82 @@ import java.util.jar.Manifest;
*/
public class Executable {
- private String[] jettyJars = {
+ private final String[] jettyJars = {
"libs/jetty.jar",
"libs/jetty-util.jar",
"libs/jetty-servlet-api.jar",
"libs/hudson-jetty-war-executable.jar"
};
+ private List<String> arguments;
public static void main(String[] args) throws Exception {
- for (int i = 0; i < args.length; i++) {
- if (args[i].startsWith("--version")) {
- System.out.println("Hudson Continuous Integration Server" + getVersion());
+ String javaVersion = System.getProperty("java.version");
+
+ StringTokenizer tokens = new StringTokenizer(javaVersion, ".-_");
+
+ int majorVersion = Integer.parseInt(tokens.nextToken());
+ int minorVersion = Integer.parseInt(tokens.nextToken());
+
+ // Make sure Java version is 1.6 or later
+ if (majorVersion < 2) {
+ if (minorVersion < 6) {
+ System.err.println("Hudson requires Java 6 or later.");
+ System.err.println("Your java version is " + javaVersion);
+ System.err.println("Java Home: " + System.getProperty("java.home"));
System.exit(0);
- } else if (args[i].startsWith("--usage")) {
- String usageStr = "Hudson Continuous Integration Server " + getVersion() + "\n"
- + "Usage: java -jar hudson.war [--option=value] [--option=value] ... \n"
- + "\n"
- + "Options:\n"
- + " --httpPort=<value> HTTP listening port. Default value is 8080\n"
- + " --version Show Hudson version and quit\n";
- System.out.println(usageStr);
+ }
+ }
+
+ Executable executable = new Executable();
+ executable.parseArguments(args);
+ executable.launchJetty();
+ }
+
+ private void parseArguments(String[] args) throws IOException {
+ arguments = Arrays.asList(args);
+
+ for (String arg : arguments) {
+ if (arg.startsWith("--version")) {
+ System.out.println("Hudson Continuous Integration Server" + getHudsonVersion());
System.exit(0);
+ } else if (arg.startsWith("--usage")) {
+ printUsage();
+ break;
+ } else if (arg.startsWith("--logfile=")) {
+ String logFile = arg.substring("--logfile=".length());
+ System.out.println("Logging information is send to file " + logFile);
+ FileOutputStream fos = new FileOutputStream(new File(logFile));
+ PrintStream ps = new PrintStream(fos);
+ System.setOut(ps);
+ System.setErr(ps);
+ break;
}
}
+ }
- Executable jettyLauncher = new Executable();
- jettyLauncher.launchJetty(args);
+ private void printUsage() throws IOException {
+ String usageStr = "Hudson Continuous Integration Server " + getHudsonVersion() + "\n"
+ + "Usage: java -jar hudson.war [--option=value] [--option=value] ... \n"
+ + "\n"
+ + "Options:\n"
+ + " --httpPort=<value> HTTP listening port. Default value is 8080\n"
+ + " --version Show Hudson version and quit\n"
+ + " --logfile=<filename> Send the output log to this file\n"
+ + " --prefix=<prefix> Add this prefix to all URLs (eg http://localhost:8080/prefix/resource). Default is none\n";;
+ System.out.println(usageStr);
+ System.exit(0);
}
- private void launchJetty(String[] args) throws Exception {
+ private void launchJetty() throws Exception {
ProtectionDomain protectionDomain = Executable.class.getProtectionDomain();
URL warUrl = protectionDomain.getCodeSource().getLocation();
+
+ // For Testing purpose
+// File file = new File("/Users/winstonp/hudson/hudson-eclipse/org.eclipse.hudson.core/hudson-war/target/hudson-war-3.0.0-SNAPSHOT.war");
+// URL warUrl = file.toURI().toURL();
+
+ System.out.println(warUrl.getPath());
List<URL> jarUrls = extractJettyJarsFromWar(warUrl.getPath());
@@ -75,7 +117,7 @@ public class Executable {
Class jettyUtil = urlClassLoader.loadClass("org.eclipse.hudson.jetty.JettyLauncher");
Method mainMethod = jettyUtil.getMethod("start", new Class[]{String[].class, URL.class});
- mainMethod.invoke(null, new Object[]{args, warUrl});
+ mainMethod.invoke(null, new Object[]{arguments.toArray(new String[arguments.size()]), warUrl});
}
/**
@@ -84,7 +126,7 @@ public class Executable {
* @return
* @throws IOException
*/
- private static String getVersion() throws IOException {
+ private static String getHudsonVersion() throws IOException {
Enumeration manifests = Executable.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (manifests.hasMoreElements()) {
URL manifestUrl = (URL) manifests.nextElement();
@@ -104,12 +146,8 @@ public class Executable {
*/
private List<URL> extractJettyJarsFromWar(String warPath) throws IOException {
- System.out.println(warPath);
-
JarFile jarFile = new JarFile(warPath);
-
-
List<URL> jarUrls = new ArrayList<URL>();
InputStream inStream = null;
@@ -142,7 +180,7 @@ public class Executable {
}
tmpFile.deleteOnExit();
- System.out.println("Extracted " + entryPath + " to " + tmpFile);
+ //System.out.println("Extracted " + entryPath + " to " + tmpFile);
jarUrls.add(tmpFile.toURI().toURL());
}

Back to the top