Browse files

- adding wrapper for CI usage

- adding in Hudson cli fetch and testing
  • Loading branch information...
1 parent e1e358e commit 674bc7140f7cc2dc3d52d99bdd1a5028451877d4 @kellyrob99 committed Feb 6, 2011
View
61 build.gradle
@@ -18,18 +18,16 @@ apply plugin: 'org.linkedin.spec'
repositories {
mavenLocal()
mavenCentral()
+ mavenRepo urls: "http://download.java.net/maven/2/"
}
-configurations {
- hudson
-}
dependencies {
compile spec.libraries.ivy
compile spec.libraries.httpBuilder
+ compile spec.libraries.hudsonCli
testCompile spec.libraries.spock
testCompile spec.libraries.junit
groovy spec.libraries.groovy
- hudson files('src/test/hudson/hudson.war')
}
group = spec.group
@@ -50,19 +48,62 @@ artifacts {
archives javadocJar
}
-def DUMMY_NAME = 'DUMMY_NAME'
-task runHudson << {
- ['java', '-jar', 'src/test/hudson/hudson.war', "-D$DUMMY_NAME"].execute()
+DUMMY_NAME = 'DUMMY_NAME'
+
+task killHudson {
+ description = "find and kill the Hudson process"
+ doLast {
+ internalKillHudson()
+ }
+}
+
+task runHudson {
+ description = 'start a Hudson server from the war at localhost:8080'
+ doLast {
+ ['java', '-jar', 'src/test/hudson/hudson.war', "-D$DUMMY_NAME"].execute()
+ Thread.sleep(10000)
+ }
}
-task killHudson << {
+test {
+ dependsOn runHudson
+ doLast {
+ internalKillHudson()
+ }
+}
+
+task wrapper(type: Wrapper) {
+ gradleVersion = '0.9.2'
+}
+
+ideaModule {
+ downloadJavadoc = true
+}
+
+ideaProject {
+ withXml { provider ->
+ def root = provider.asNode()
+ root.component.find { it.@name == 'VcsDirectoryMappings' }.mapping[0].@vcs = 'Git'
+ // Set gradle home
+ def gradleSettings = root.appendNode('component', [name: 'GradleSettings'])
+ gradleSettings.appendNode('option', [name: 'SDK_HOME', value: gradle.gradleHomeDir.absolutePath])
+ }
+ whenConfigured { project ->
+ project.jdk.languageLevel = 'JDK_1_6'
+ project.jdk.projectJdkName = '1.6'
+ }
+}
+
+private def internalKillHudson()
+{
final Process findProcess = ['ps', '-a'].execute()
findProcess.waitFor()
findProcess.text.eachLine {line ->
- if(line.contains(DUMMY_NAME))
+ if (line.contains(DUMMY_NAME))
{
['kill', '-9', line.split()[0]].execute()
return
}
}
-}
+}
+
View
BIN gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
View
6 gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Sun Feb 06 15:24:10 PST 2011
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://gradle.artifactoryonline.com/gradle/distributions/gradle-0.9.2-bin.zip
View
168 gradlew
@@ -0,0 +1,168 @@
+#!/bin/bash
+
+##############################################################################
+## ##
+## Gradle wrapper script for UN*X ##
+## ##
+##############################################################################
+
+# Uncomment those lines to set JVM options. GRADLE_OPTS and JAVA_OPTS can be used together.
+# GRADLE_OPTS="$GRADLE_OPTS -Xmx512m"
+# JAVA_OPTS="$JAVA_OPTS -Xmx512m"
+
+GRADLE_APP_NAME=Gradle
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set JAVA_HOME if it's not already set.
+if [ -z "$JAVA_HOME" ] ; then
+ if $darwin ; then
+ [ -z "$JAVA_HOME" -a -d "/Library/Java/Home" ] && export JAVA_HOME="/Library/Java/Home"
+ [ -z "$JAVA_HOME" -a -d "/System/Library/Frameworks/JavaVM.framework/Home" ] && export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
+ else
+ javaExecutable="`which javac`"
+ [ -z "$javaExecutable" -o "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ] && die "JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME."
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ [ `expr "$readLink" : '\([^ ]*\)'` = "no" ] && die "JAVA_HOME not set and readlink not available, please set JAVA_HOME."
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ export JAVA_HOME="$javaHome"
+ fi
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVACMD" ] && JAVACMD=`cygpath --unix "$JAVACMD"`
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+STARTER_MAIN_CLASS=org.gradle.wrapper.GradleWrapperMain
+CLASSPATH=`dirname "$0"`/gradle/wrapper/gradle-wrapper.jar
+WRAPPER_PROPERTIES=`dirname "$0"`/gradle/wrapper/gradle-wrapper.properties
+# Determine the Java command to use to start the JVM.
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="java"
+ fi
+fi
+if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+if [ -z "$JAVA_HOME" ] ; then
+ warn "JAVA_HOME environment variable is not set"
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add GRADLE_APP_NAME to the JAVA_OPTS as -Xdock:name
+if $darwin; then
+ JAVA_OPTS="$JAVA_OPTS -Xdock:name=$GRADLE_APP_NAME"
+# we may also want to set -Xdock:image
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ JAVA_HOME=`cygpath --path --mixed "$JAVA_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+GRADLE_APP_BASE_NAME=`basename "$0"`
+
+exec "$JAVACMD" $JAVA_OPTS $GRADLE_OPTS \
+ -classpath "$CLASSPATH" \
+ -Dorg.gradle.appname="$GRADLE_APP_BASE_NAME" \
+ -Dorg.gradle.wrapper.properties="$WRAPPER_PROPERTIES" \
+ $STARTER_MAIN_CLASS \
+ "$@"
View
82 gradlew.bat
@@ -0,0 +1,82 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem ##
+@rem Gradle startup script for Windows ##
+@rem ##
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Uncomment those lines to set JVM options. GRADLE_OPTS and JAVA_OPTS can be used together.
+@rem set GRADLE_OPTS=%GRADLE_OPTS% -Xmx512m
+@rem set JAVA_OPTS=%JAVA_OPTS% -Xmx512m
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.\
+
+@rem Find java.exe
+set JAVA_EXE=java.exe
+if not defined JAVA_HOME goto init
+
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+echo.
+goto end
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set STARTER_MAIN_CLASS=org.gradle.wrapper.GradleWrapperMain
+set CLASSPATH=%DIRNAME%\gradle\wrapper\gradle-wrapper.jar
+set WRAPPER_PROPERTIES=%DIRNAME%\gradle\wrapper\gradle-wrapper.properties
+
+set GRADLE_OPTS=%JAVA_OPTS% %GRADLE_OPTS% -Dorg.gradle.wrapper.properties="%WRAPPER_PROPERTIES%"
+
+@rem Execute Gradle
+"%JAVA_EXE%" %GRADLE_OPTS% -classpath "%CLASSPATH%" %STARTER_MAIN_CLASS% %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+if not "%OS%"=="Windows_NT" echo 1 > nul | choice /n /c:1
+
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit "%ERRORLEVEL%"
+exit /b "%ERRORLEVEL%"
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
View
7 project-spec.groovy
@@ -17,11 +17,12 @@ spec = [
*/
spec.libraries = [
groovy: "org.codehaus.groovy:groovy:${spec.versions.groovy}",
- spock : ['org.spockframework:spock-core:0.5-groovy-1.7@jar',
- 'org.hamcrest:hamcrest-core:1.1@jar',
+ spock : ['org.spockframework:spock-core:0.5-groovy-1.7',
+ 'org.hamcrest:hamcrest-core:1.1',
'cglib:cglib-nodep:2.2',
'org.objenesis:objenesis:1.2'],
ivy: "org.apache.ivy:ivy:2.0.0",
httpBuilder: 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.1',
- junit: 'junit:junit:4.8.2'
+ junit: 'junit:junit:4.8.2',
+ hudsonCli: 'org.jvnet.hudson.main:cli:1.395'
]
View
8 src/main/groovy/org/kar/hudson/api/JSONApi.groovy
@@ -14,18 +14,18 @@ class JSONApi
* @param rootUrl the url to query for the hosted json api
* @return contents of api in json format
*/
- def inspectApi(String rootUrl)
+ def inspectApi(String rootUrl, int depth = 0)
{
- requestSupport.get(rootUrl, API_JSON)
+ requestSupport.get(rootUrl, API_JSON, depth)
}
/**
* Display the json api for a particular Hudson computer.
* @param rootUrl the url of the Hudson server
* @return contents of computer api in json format
*/
- def inspectComputer(String rootUrl)
+ def inspectComputer(String rootUrl, int depth = 0)
{
- requestSupport.get(rootUrl, COMPUTER)
+ requestSupport.get(rootUrl, COMPUTER, depth)
}
}
View
12 src/main/groovy/org/kar/hudson/api/JobJSONApi.groovy
@@ -16,29 +16,29 @@ class JobJSONApi
* @param rootUrl the url for a particular build
* @return lastSuccessfulBuild in json format
*/
- def inspectSuccessfulJob(String rootUrl)
+ def inspectSuccessfulJob(String rootUrl, int depth = 0)
{
- requestSupport.get(rootUrl, LAST_SUCCESSFUL)
+ requestSupport.get(rootUrl, LAST_SUCCESSFUL, depth)
}
/**
* Display the job api for a particular Hudson job.
* @param rootUrl the url for a particular build
* @return job info in json format
*/
- def inspectJob(String rootUrl)
+ def inspectJob(String rootUrl, int depth = 0)
{
- requestSupport.get(rootUrl, API_JSON)
+ requestSupport.get(rootUrl, API_JSON, depth)
}
/**
* Display the test results for a particular Hudson job.
* @param rootUrl the url for a particular build
* @return test info in json format
*/
- def inspectBuildTests(String rootUrl)
+ def inspectBuildTests(String rootUrl, int depth = 0)
{
- requestSupport.get(rootUrl, TEST_REPORT)
+ requestSupport.get(rootUrl, TEST_REPORT, depth)
}
/**
View
54 src/main/groovy/org/kar/hudson/api/cli/HudsonCliApi.groovy
@@ -0,0 +1,54 @@
+package org.kar.hudson.api.cli
+
+import groovyx.net.http.HTTPBuilder
+import hudson.cli.CLI
+import static groovyx.net.http.ContentType.BINARY
+import static groovyx.net.http.Method.GET
+
+/**
+ * @author Kelly Robinson
+ */
+class HudsonCliApi
+{
+// http://localhost:8080/jnlpJars/hudson-cli.jar
+ static final String JAR_DIR = '/.hudsonApi/'
+ static final String JAR_NAME = 'hudson-cli.jar'
+ static final String FINAL_PATH = JAR_DIR + JAR_NAME
+
+ def downloadJar(String rootUrl)
+ {
+ def userHome = System.getProperty('user.home')
+ println "downloading $rootUrl to $userHome/$FINAL_PATH"
+ HTTPBuilder http = new HTTPBuilder(rootUrl)
+ http.request(GET, BINARY) { req ->
+ uri.path = '/jnlpJars/hudson-cli.jar'
+
+ response.success = { resp, reader ->
+ println "Got response: ${resp.statusLine}"
+ println "Content-Type: ${resp.headers.'Content-Type'}"
+ final File hudsonJarDir = new File("$userHome/$JAR_DIR")
+ hudsonJarDir.mkdirs()
+ final File hudsonJarFile = new File(hudsonJarDir, JAR_NAME)
+ if (hudsonJarFile.exists())
+ {
+ hudsonJarFile.delete()
+ }
+ hudsonJarFile.createNewFile()
+ hudsonJarFile << reader
+ }
+ }
+ }
+
+ def runCliCommand(String rootUrl, String arg, InputStream input = System.in, OutputStream output = System.out, OutputStream err = System.err)
+ {
+ runCliCommand(rootUrl, [arg], input, output, err)
+ }
+
+ def runCliCommand(String rootUrl, List<String> args, InputStream input = System.in, OutputStream output = System.out, OutputStream err = System.err)
+ {
+ def CLI cli = new CLI(rootUrl.toURI().toURL())
+ cli.execute(args, input, output, err)
+ }
+
+
+}
View
12 src/test/groovy/org/kar/hudson/api/JSONApiTest.groovy
@@ -2,7 +2,7 @@ package org.kar.hudson.api
import groovy.xml.XmlUtil
import spock.lang.Specification
-
+import static java.net.HttpURLConnection.*
/**
* Depends on having Hudson running on the local machine.
*
@@ -58,15 +58,15 @@ class JSONApiTest extends Specification
when:
final testJob = hudsonInfo.jobs.find {it.name.equals('test')}
- 302 == jobApi.copyJob(rootUrl, [name: 'myNewJob', mode: 'copy', from: testJob.name])
- 302 == jobApi.deleteJob(rootUrl + 'job/myNewJob/')
+ HTTP_MOVED_TEMP == jobApi.copyJob(rootUrl, [name: 'myNewJob', mode: 'copy', from: testJob.name])
+ HTTP_MOVED_TEMP == jobApi.deleteJob(rootUrl + 'job/myNewJob/')
then:
true
when:
final config = new JobConfigXmlAPI().loadJobConfig(testJob.url)
- 200 == jobApi.createJob(rootUrl, XmlUtil.serialize(config), 'blah')
- 302 == jobApi.deleteJob(rootUrl + 'job/blah/')
+ HTTP_OK == jobApi.createJob(rootUrl, XmlUtil.serialize(config), 'blah')
+ HTTP_MOVED_TEMP == jobApi.deleteJob(rootUrl + 'job/blah/')
then:
true
@@ -80,7 +80,7 @@ class JSONApiTest extends Specification
def status = jobApi.deleteJob("$rootUrl/job/randomJob")
then:
- status == HttpURLConnection.HTTP_NOT_FOUND
+ status == HTTP_NOT_FOUND
}
def "test loading the computer info"()
View
3 src/test/groovy/org/kar/hudson/api/UDPApiTest.groovy
@@ -12,7 +12,7 @@ class UDPApiTest extends Specification
{
final static UDP_RESPONSE_PATTERN = '<hudson><version>.*</version><url>http://localhost:8080/</url><slave-port>.*</slave-port></hudson>'
- @Unroll
+ @Unroll("querying of #rootUrl should match #xmlResponse")
def "should be able to test for presence of Hudson by sending a UDP packet"()
{
def udpInfo = new UDPApi()
@@ -22,6 +22,7 @@ class UDPApiTest extends Specification
then:
response ==~ xmlResponse
+ println response
where:
rootUrl | xmlResponse
View
67 src/test/groovy/org/kar/hudson/api/cli/HudsonCliApiTest.groovy
@@ -0,0 +1,67 @@
+package org.kar.hudson.api.cli
+
+import spock.lang.Specification
+
+/**
+ * @author Kelly Robinson
+ */
+class HudsonCliApiTest extends Specification
+{
+ def rootUrl = 'http://localhost:8080/'
+
+ final HudsonCliApi api = new HudsonCliApi()
+
+ def "should be able to download the hudson cli jar"()
+ {
+ when:
+ api.downloadJar(rootUrl)
+
+ then:
+ new File("${System.getProperty('user.home')}/${HudsonCliApi.FINAL_PATH}").exists()
+ }
+
+ def "should be able to load commands from hudson-cli"()
+ {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream()
+ when:
+ //output of help command is written to err stream
+ api.runCliCommand(rootUrl, 'help', System.in, System.out, output)
+
+ then:
+ final String[] lines = output.toString().split('\n')
+ def commands = [:]
+ for (int i = 0; i < (lines.size() - 1); i++)
+ {
+ if (i % 2 == 0)
+ {
+ commands[lines[i]] = lines[i + 1]
+ }
+ }
+ commands.size() > 0
+ }
+
+ def "should be able to run a groovy shell"()
+ {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream()
+ final message = 'hello from hudson-cli!'
+
+ when:
+ api.runCliCommand(rootUrl, ['groovysh', "println '$message'".toString()], System.in, output, System.err)
+
+ then:
+ output.toString().split('\n')[0] == message
+ }
+
+
+ def "should be able to query hudson object through a groovy script"()
+ {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream()
+ when:
+ output = new ByteArrayOutputStream()
+ api.runCliCommand(rootUrl, ['groovysh', 'for(item in hudson.model.Hudson.instance.items) { println("job $item.name")}'],
+ System.in, output, System.err)
+
+ then:
+ output.toString().split('\n')[0].startsWith('job')
+ }
+}
View
BIN src/test/hudson/hudson.war
Binary file not shown.

0 comments on commit 674bc71

Please sign in to comment.