Permalink
Browse files

- version bump to jenkins, groovy and spock

- general cleanup to remove need for existing builds during testing
- move the HUDSON_HOME to the build directory instead of local install
- remove JSONPrettyPrinter(which only worked if the ruby file required was locally installed anyway) since groovy now
 how much better support for JSON natively
  • Loading branch information...
1 parent 1ed10e0 commit 027a102e7f40b3ca2ed6ec33177525400f1be280 @kellyrob99 committed Feb 19, 2012
View
@@ -18,16 +18,18 @@ apply plugin: 'org.linkedin.userConfig'
apply plugin: 'org.linkedin.spec'
repositories {
+ mavenRepo urls: ["http://download.java.net/maven/2/", 'http://maven.glassfish.org/content/groups/public/',
+ 'http://m2repo.spockframework.org/']
mavenLocal()
mavenCentral()
- mavenRepo urls: ["http://download.java.net/maven/2/", 'http://maven.glassfish.org/content/groups/public/']
}
configurations {
jenkins
}
dependencies {
+ compile gradleApi()
compile spec.libraries.ivy
compile spec.libraries.httpBuilder
compile spec.libraries.jenkinsCli
@@ -64,6 +66,7 @@ test {
boolean keepGoing = true
int tries = 0
final int maxTries = 30
+ final long sleep = 5000
while (keepGoing && tries < maxTries)
{
try
@@ -74,8 +77,8 @@ test {
{
//logger.warn("Exception thrown: $e")
}
- logger.warn("Waiting for Jenkins ${++tries}")
- Thread.sleep(5000)
+ logger.warn("Waiting for Jenkins ${++tries} ($sleep ms)")
+ Thread.sleep(sleep)
}
}
}
@@ -84,32 +87,39 @@ jar.enabled = true
[jettyRun, jettyRunWar]*.daemon = true
/**
- * Use the jetty plugin to run the build server.
- */
+* Use the jetty plugin to run the build server.
+*/
jettyRunWar {
+ dependsOn configurations.jenkins
webApp = configurations.jenkins.resolve().find {it.name.endsWith('war')}
contextPath = ''
}
task wrapper(type: Wrapper) {
- gradleVersion = '0.9.2'
+ gradleVersion = '1.0-milestone-8'
}
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])
+idea{
+ project {
+ jdkName = '1.6'
+ languageLevel = '1.6'
+ ipr {
+ 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'
+ module {
+ downloadJavadoc = true
+ downloadSources = true
}
}
View
@@ -0,0 +1 @@
+systemProp.HUDSON_HOME=build/jenkins
Binary file not shown.
@@ -1,6 +1,6 @@
-#Mon Mar 14 22:25:27 PDT 2011
+#Sat Feb 18 18:44:58 PST 2012
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
+distributionUrl=http\://gradle.artifactoryonline.com/gradle/distributions/gradle-1.0-milestone-8-bin.zip
View
0 gradlew 100644 → 100755
No changes.
View
@@ -8,8 +8,8 @@ spec = [
version: '0.1',
versions: [
- groovy: '1.7.6',
- jenkins: '1.401'
+ groovy: '1.8.6',
+ jenkins: '1.451'
],
]
@@ -18,13 +18,14 @@ spec = [
*/
spec.libraries = [
groovy: "org.codehaus.groovy:groovy-all:${spec.versions.groovy}",
- spock : ['org.spockframework:spock-core:0.5-groovy-1.7',
+ spock : [
+ 'org.spockframework:spock-core:0.5-groovy-1.8',
'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',
- jenkinsCli: 'org.jvnet.hudson.main:cli:1.395',
+ jenkinsCli: ["org.jenkins-ci.main:cli:${spec.versions.jenkins}","org.jenkins-ci.main:remoting:2.12"],
jenkins: "org.jenkins-ci.main:jenkins-war:${spec.versions.jenkins}@war"
]
@@ -70,7 +70,8 @@ class HudsonCliApi
* @param err
* @return
*/
- def runCliCommand(String rootUrl, List<String> args, InputStream input = System.in, OutputStream output = System.out, OutputStream err = System.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)
@@ -1,18 +0,0 @@
-package org.kar.hudson.api.utility
-
-/**
- * More of a local convenience than anything, utilizes an installed Ruby utility program to
- * pretty-print JSON.
- *
- * @author Kelly Robinson
- */
-class JSONPrettyPrinter
-{
-
- String prettyPrint(String content)
- {
- final process = ['echo', content].execute().pipeTo('prettify_json.rb'.execute())
- process.waitFor()
- process.text
- }
-}
@@ -12,67 +12,46 @@ import static java.net.HttpURLConnection.*
@SuppressWarnings('MethodName')
class JSONApiTest extends Specification
{
+ public static final String TEST_JOB_NAME = 'test'
+ public static final String NEW_JOB_NAME = 'myNewJob'
def rootUrl = 'http://localhost:8080/'
def api = new JSONApi()
def jobApi = new JobJSONApi()
def configApi = new JobConfigXmlAPI()
- def "test loading the api"()
+ def "test creating, copying and deleting jobs"()
{
+ //create a new job based from a config.xml file
when:
+ final createJobResult = jobApi.createJob(rootUrl, XmlUtil.serialize(new File(this.getClass().classLoader
+ .getResource('config.xml').toURI()).text), TEST_JOB_NAME)
def hudsonInfo = api.inspectApi(rootUrl)
- hudsonInfo.jobs.each { job ->
- jobApi.triggerBuild(job.url)
- jobApi.inspectSuccessfulJob(job.url).each { jobInfo ->
- jobInfo.each {
- println it
- }
- }
- println ''.center(40, '*')
- final jobDetails = jobApi.inspectJob(job.url)
- jobDetails.each { jobInfo ->
- jobInfo.each {
- println it
- }
- }
- jobDetails.builds.each { build ->
- println jobApi.inspectBuildTests(build.url)
- }
- println ''.center(40, '*')
-
- final config = configApi.loadJobConfig(job.url)
- println XmlUtil.serialize(config)
-
- println ''.center(40, '*')
-
- }
+ final testJob = hudsonInfo.jobs.find {it.name == TEST_JOB_NAME}
then:
+ HTTP_OK == createJobResult
hudsonInfo.jobs.size() > 0
- println hudsonInfo.toString()
- hudsonInfo.each {println it}
- println 'main hudson api finished'.center(40, '*')
-
- final testJob = hudsonInfo.jobs.find {it.name.contains('test')}
+ testJob.name == TEST_JOB_NAME
//copy an existing job
when:
- def copyJobResult = jobApi.copyJob(rootUrl, [name: 'myNewJob', mode: 'copy', from: testJob.name])
- def deleteJobResult = jobApi.deleteJob(rootUrl + 'job/myNewJob/')
+ def copyJobResult = jobApi.copyJob(rootUrl, [name: NEW_JOB_NAME, mode: 'copy', from: testJob.name])
+ hudsonInfo = api.inspectApi(rootUrl)
+ final newTestJob = hudsonInfo.jobs.find {it.name == NEW_JOB_NAME}
then:
HTTP_MOVED_TEMP == copyJobResult
- HTTP_MOVED_TEMP == deleteJobResult
+ newTestJob != null
+ newTestJob.name == NEW_JOB_NAME
- //create a new job based on a downloaded config.xml file
+ //delete copied job
when:
- final config = new JobConfigXmlAPI().loadJobConfig(testJob.url)
- final createJobResult = jobApi.createJob(rootUrl, XmlUtil.serialize(config), 'blah')
- final deleteCreatedJobResult = jobApi.deleteJob(rootUrl + 'job/blah/')
-
+ def deleteJobResult = jobApi.deleteJob(newTestJob.url)
+ hudsonInfo = api.inspectApi(rootUrl)
+ def deletedJob = hudsonInfo.jobs.find {it.name == NEW_JOB_NAME}
then:
- HTTP_OK == createJobResult
- HTTP_MOVED_TEMP == deleteCreatedJobResult
+ HTTP_MOVED_TEMP == deleteJobResult
+ deletedJob == null
}
def "test a POST failure"()
@@ -90,9 +69,6 @@ class JSONApiTest extends Specification
def computer = api.inspectComputer(rootUrl)
then:
- computer.each {
- println it
- }
- println "computer.computer.displayName is ${computer.computer.displayName}"
+ computer.computer.displayName == 'master'
}
}
@@ -11,9 +11,9 @@ import spock.lang.Unroll
@SuppressWarnings('MethodName')
class UDPApiTest extends Specification
{
- final static UDP_RESPONSE_PATTERN = '<hudson><version>.*</version><slave-port>.*</slave-port></hudson>'
+ final static UDP_RESPONSE_PATTERN = '''<hudson><version>.*</version><server-id>.*</server-id><slave-port>.*</slave-port></hudson>'''
- @Unroll("querying of #rootUrl should match #xmlResponse")
+ @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()
@@ -60,12 +60,25 @@ class HudsonCliApiTest extends Specification
{
final ByteArrayOutputStream output = new ByteArrayOutputStream()
when:
- api.runCliCommand(rootUrl, ['groovysh', 'for(item in hudson.model.Hudson.instance.items) { println("job $item.name")}'],
+ api.runCliCommand(rootUrl, ['groovysh', '''
+hudson.model.Hudson.instance.administrativeMonitors.inject([:]){ result, it ->
+ result[it.id] = [enabled: it.enabled, activated: it.activated]
+ result
+}.inspect()
+'''],
System.in, output, System.err)
+
then:
- println output.toString()
- output.toString().split('\n')[0].startsWith('job')
+ def s = output.toString()[11..-1] // the output string is wrapped in some boilerplate, remove it
+ println s
+ //some keys in the map contain $ signs, so we opt to just replace them with themselves
+ def map = new GroovyShell(new Binding('CoreUpdateMonitor':'$CoreUpdateMonitor',
+ 'AdministrativeMonitorImpl':'$AdministrativeMonitorImpl')).evaluate(s)
+ println map
+ println map.getClass()
+
+// output.toString().split('\n')[0].startsWith('job')
}
def "should be able to install the git plugin"()
@@ -1,37 +0,0 @@
-package org.kar.hudson.api.utility
-
-import spock.lang.Specification
-
-/**
- * @author Kelly Robinson
- */
-@SuppressWarnings('MethodName')
-class JSONPrettyPrinterTest extends Specification
-{
- def jsonPrinter = new JSONPrettyPrinter()
-
- static final String COMPUTER_INFO = '{"busyExecutors":0,"computer":[{"actions":[],"displayName":"master","executors":[{},{}],"icon":"computer.png","idle":true,"jnlpAgent":false,"launchSupported":true,"loadStatistics":{},"manualLaunchAllowed":true,"monitorData":{"hudson.node_monitors.SwapSpaceMonitor":null,"hudson.node_monitors.ArchitectureMonitor":"Mac OS X (x86_64)","hudson.node_monitors.TemporarySpaceMonitor":{"size":58392846336},"hudson.node_monitors.ResponseTimeMonitor":{"average":111},"hudson.node_monitors.DiskSpaceMonitor":{"size":58392846336},"hudson.node_monitors.ClockMonitor":{"diff":0}},"numExecutors":2,"offline":false,"offlineCause":null,"oneOffExecutors":[],"temporarilyOffline":false}],"displayName":"nodes","totalExecutors":2}'
- static final String ROOT_API = '{"assignedLabels":[{}],"mode":"NORMAL","nodeDescription":"the master Hudson node","nodeName":"","numExecutors":2,"description":"Welcome to my Test Hudson System","jobs":[{"name":"gradle","url":"http://localhost:8080/job/gradle/","color":"disabled"},{"name":"gradle-no-sonar","url":"http://localhost:8080/job/gradle-no-sonar/","color":"disabled"},{"name":"hudson-api","url":"http://localhost:8080/job/hudson-api/","color":"aborted"},{"name":"test","url":"http://localhost:8080/job/test/","color":"disabled"}],"overallLoad":{},"primaryView":{"name":"All","url":"http://localhost:8080/"},"slaveAgentPort":0,"useCrumbs":false,"useSecurity":false,"views":[{"name":"All","url":"http://localhost:8080/"}]}'
-
- def "should pretty print JSON if ruby program is installed"()
- {
- when:
- def prettyPrinted = jsonPrinter.prettyPrint('{ "foo": "bar" }')
-
- then:
- prettyPrinted == '''{
- "foo": "bar"
-}
-'''
- }
-
- def "format a bunch of canned json"()
- {
- when:
- println jsonPrinter.prettyPrint(COMPUTER_INFO)
- println jsonPrinter.prettyPrint(ROOT_API)
-
- then:
- true
- }
-}

0 comments on commit 027a102

Please sign in to comment.