Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectable JDK for Fitnesse #3

Merged
merged 5 commits into from
Aug 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 146 additions & 153 deletions .classpath

Large diffs are not rendered by default.

Binary file added fitnesse.hpi
Binary file not shown.
145 changes: 87 additions & 58 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,98 @@

<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.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.401</version>
</parent>
<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.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.401</version>
</parent>
<profiles>
<profile>
<id>tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<artifactId>fitnesse</artifactId>
<version>1.8-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Hudson Fitnesse plugin</name>
<url>http://wiki.jenkins-ci.org/display/HUDSON/Fitnesse+Plugin</url>
<artifactId>fitnesse</artifactId>
<version>1.8-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Hudson Fitnesse plugin</name>
<url>http://wiki.jenkins-ci.org/display/HUDSON/Fitnesse+Plugin</url>

<developers>
<developer>
<id>prime8</id>
<name>timbacon</name>
<email>tim bacon @at@ gmail dotcom</email>
</developer>
</developers>
<developers>
<developer>
<id>prime8</id>
<name>timbacon</name>
<email>tim bacon @at@ gmail dotcom</email>
</developer>
</developers>

<licenses>
<license>
<name>MIT license</name>
<comments>All source code is under the MIT license.</comments>
</license>
</licenses>
<licenses>
<license>
<name>MIT license</name>
<comments>All source code is under the MIT license.</comments>
</license>
</licenses>

<scm>
<connection>scm:git:git://github.com/jenkinsci/fitnesse-plugin.git</connection>
<developerConnection>scm:git:git://github.com/jenkinsci/fitnesse-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/fitnesse-plugin</url>
</scm>
<scm>
<connection>scm:git:git://github.com/jenkinsci/fitnesse-plugin.git</connection>
<developerConnection>scm:git:git://github.com/jenkinsci/fitnesse-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/fitnesse-plugin</url>
</scm>

<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>

<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
</repository>
</distributionManagement>
<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
</repository>
</distributionManagement>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>

18 changes: 16 additions & 2 deletions src/main/java/hudson/plugins/fitnesse/FitnesseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class FitnesseBuilder extends Builder {
public static final String FITNESSE_PORT_LOCAL = "fitnessePortLocal";
public static final String FITNESSE_ADDITIONAL_OPTIONS = "additionalFitnesseOptions";
public static final String JAVA_OPTS = "fitnesseJavaOpts";
public static final String FITNESSE_JDK = "fitnesseJdk";
public static final String PATH_TO_JAR = "fitnessePathToJar";
public static final String PATH_TO_ROOT = "fitnessePathToRoot";
public static final String TARGET_PAGE = "fitnesseTargetPage";
Expand Down Expand Up @@ -91,6 +92,13 @@ public String getFitnesseHost(AbstractBuild<?,?> build) throws InterruptedExcept
} else return getOption(FITNESSE_HOST, "unknown_host");
}

/**
* referenced in config.jelly
*/
public String getFitnesseJdk() {
return getOption(FITNESSE_JDK, "");
}

/**
* referenced in config.jelly
*/
Expand Down Expand Up @@ -237,6 +245,12 @@ public FormValidation doCheckFitnessePort(@QueryParameter String value) throws I
return FormValidation.ok();
}

public FormValidation doCheckFitnesseJdk(@QueryParameter String value) throws IOException, ServletException {
if (value.length()==0)
return FormValidation.ok("Defaults to project's JDK");
return FormValidation.ok();
}

public FormValidation doCheckFitnesseJavaOpts(@QueryParameter String value) throws IOException, ServletException {
return FormValidation.ok();
}
Expand Down Expand Up @@ -323,7 +337,7 @@ public FitnesseBuilder newInstance(StaplerRequest req, JSONObject formData)
if (Boolean.parseBoolean(startFitnesseValue)) {
return newFitnesseBuilder(startFitnesseValue,
collectFormData(formData, new String[] {
JAVA_OPTS, JAVA_WORKING_DIRECTORY,
FITNESSE_JDK, JAVA_OPTS, JAVA_WORKING_DIRECTORY,
PATH_TO_JAR, PATH_TO_ROOT, FITNESSE_PORT_LOCAL,
TARGET_PAGE, TARGET_IS_SUITE, HTTP_TIMEOUT, PATH_TO_RESULTS,
FITNESSE_ADDITIONAL_OPTIONS
Expand Down Expand Up @@ -355,6 +369,6 @@ private Map<String, String> collectFormData(JSONObject formData, String[] keys)
}
return targetElements;
}
}
}
}

8 changes: 6 additions & 2 deletions src/main/java/hudson/plugins/fitnesse/FitnesseExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Proc;
import hudson.Launcher.ProcStarter;
import hudson.Proc;
import hudson.model.AbstractBuild;
import hudson.model.Hudson;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -14,7 +15,6 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand Down Expand Up @@ -85,6 +85,10 @@ public ArrayList<String> getJavaCmd(FilePath workingDirectory, EnvVars envVars)
String java = "java";
if (envVars.containsKey("JAVA_HOME"))
java = new File(new File(envVars.get("JAVA_HOME"), "bin"), java).getAbsolutePath();
if(!builder.getFitnesseJdk().isEmpty()){
File customJavaHome = Hudson.getInstance().getJDK(builder.getFitnesseJdk()).getBinDir();
java = new File(customJavaHome, java).getAbsolutePath();
}
String fitnesseJavaOpts = builder.getFitnesseJavaOpts();
String[] java_opts = ("".equals(fitnesseJavaOpts) ? new String[0] : fitnesseJavaOpts.split(" "));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
help="/descriptor/hudson.plugins.fitnesse.FitnesseBuilder/help/fitnesseStartTrue"
checked="${instance.fitnesseStart==true}">

<j:set var="jdks" value="${app.JDKs}" />
<j:if test="${jdks.size() gt 1}">
<!-- if there's only one JDK configured, always use that. -->
<f:entry title="Fitnesse JDK"
description="JDK to be used for Fitnesse">
<select class="setting-input validated" name="fitnesseJdk" checkUrl="'${rootURL}/defaultJDKCheck?value='+this.value">
<j:forEach var="inst" items="${jdks}">
<f:option selected="${inst.name==instance.fitnesseJdk}" value="${inst.name}">${inst.name}</f:option>
</j:forEach>
</select>
</f:entry>
</j:if>

<f:entry title="Java startup options"
help="/descriptor/hudson.plugins.fitnesse.FitnesseBuilder/help/javaOpts">
<f:textbox name="fitnesseJavaOpts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Java JDK home directory that Fitnesse should use, if different than project
</div>
18 changes: 18 additions & 0 deletions src/test/java/hudson/plugins/fitnesse/FitnesseBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
import org.junit.Test;

public class FitnesseBuilderTest {
@Test
public void getJdkShouldReturnSpecificJavaHomeIfSpecified() {
HashMap<String, String> options = new HashMap<String, String>();
String expectedJavaHome = "jdk1.6.0_18";
options.put(FitnesseBuilder.FITNESSE_JDK, expectedJavaHome);
FitnesseBuilder builder = new FitnesseBuilder(options);
Assert.assertEquals(expectedJavaHome, builder.getFitnesseJdk());
}

@Test
public void getJdkShouldReturnNothingIfNotSpecifiedSoThatTheDefaultJDKIsUsed() {
HashMap<String, String> options = new HashMap<String, String>();
String expectedJavaHome = "";
FitnesseBuilder builder = new FitnesseBuilder(options);

Assert.assertEquals(expectedJavaHome, builder.getFitnesseJdk());
}

@Test
public void getPortShouldReturnLocalPortIfSpecified() {
HashMap<String, String> options = new HashMap<String, String>();
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/hudson/plugins/fitnesse/FitnesseExecutorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ public void javaCmdShouldReferenceJAVAHOME() throws IOException {
Assert.assertEquals("-p", cmd.get(7));
Assert.assertEquals("9876", cmd.get(8));
}

@Test
public void javaCmdShouldReferenceFitnesseSpecificJavaHome() throws IOException {
File javaHome = File.createTempFile("JavaHome", "");
executor = getExecutorForBuilder(
new String[] {FitnesseBuilder.PATH_TO_ROOT, FitnesseBuilder.PATH_TO_JAR, FitnesseBuilder.FITNESSE_PORT, FitnesseBuilder.FITNESSE_JDK},
new String[] {getTestResourceFitNesseRoot(), getTestResourceFitnesseJar(), "9876", javaHome.getAbsolutePath()});

EnvVars envVars = new EnvVars();
FilePath workingDirectory = new FilePath(new File(TMP_DIR));
ArrayList<String> cmd = executor.getJavaCmd(workingDirectory, envVars);

Assert.assertEquals(new File(new File(javaHome, "bin"), "java").getAbsolutePath(),
cmd.get(0));
Assert.assertEquals("-jar", cmd.get(1));
Assert.assertEquals(getTestResourceFitnesseJar(), cmd.get(2));
Assert.assertEquals("-d", cmd.get(3));
Assert.assertEquals(new File(getTestResourceFitNesseRoot()).getParent(), cmd.get(4));
Assert.assertEquals("-r", cmd.get(5));
Assert.assertEquals("FitNesseRoot", cmd.get(6));
Assert.assertEquals("-p", cmd.get(7));
Assert.assertEquals("9876", cmd.get(8));
}

@Test
public void javaCmdShouldHandleRelativePaths() throws IOException {
Expand Down
Loading