Skip to content

Instantly share code, notes, and snippets.

View ysb33r's full-sized avatar

Schalk W. Cronjé ysb33r

  • Andorra
View GitHub Profile
@ysb33r
ysb33r / SumSquaresNumbersDiv7SmallerThan100.groovy
Created April 15, 2013 13:35
Russel Winder did a lightning talk at ACCU 2013 titled "Who needs C++ when you have D and Go": http://www.slideshare.net/Russel_Winder/who-needscwhenyouhaved-andgo I decided to address the same problem using a one-liner in Groovy
println ((0..<100).step(7).collect{it*it}.sum())
@ysb33r
ysb33r / gist:5554324
Last active December 17, 2015 04:59
I am trying to wrapper a Task class in Gradle to wrap some legacy build tools i.e. GNU Make, SCons etc. This is to help migrating legacy builds to Gradle. The idea is to still call parts of the old build systems and just to collect the artifacts from them. So instead of inheriting from DefaultTask I thought it would be easier to just to extend s…
class GnuMake extends DefaultTask {
@Input
@Optional
List<String> targets
@Input
@Optional
Map<String,Object> flags = [:]
@ysb33r
ysb33r / publishToBintrayDSLSuggestion.gradle
Last active December 17, 2015 11:49
Suggested DSL adaptation for publising to Bintray
// FOR THE IMPATIENT: Final solution at the end
// Classic Ivy style to publish to Bintray.
// This requires the package to be pre-created, possibly by manual process on website
// or via call such as https://github.com/ysb33r/Gradle/blob/master/buildSrc/src/main/groovy/BintrayPackage.groovy
uploadArchives {
repositories {
ivy {
url 'http://api.bintray.com/ysb33r/grysb33r/gnumake-gradle-plugin/0.0.3'
credentials {
// Create the task
// The declare the task and adds a body that will be executed everytime the tasks is executed
// Variables pushed in as configuration can be referenced here
//
// This simple tasks will write a text file containing a list of files
// in a source set. It will also only update the output file, if at least one
// source file has changed.
task myTask << {
outputs.file.singleFile.withWriter { out ->
inputs.sourceFiles.each {
@ysb33r
ysb33r / XsltUnitToJUnitXml.xsl
Last active December 18, 2015 02:39
I do not know if anyone still uses for XSLTUnit (http://xsltunit.org/) for new development, but I recently had the requirement to convert the XML created by this framework to a JUnit XML format so that it can be read by other tools such as JUnit that understands this format.
<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================================
(C) Copyright Schalk W. Cronjé 2013
This code snippet is licensed under the Apache License 2.0
See http://www.apache.org/licenses/LICENSE-2.0 for license details
============================================================================ -->
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"
@ysb33r
ysb33r / RelativePath.groovy
Last active November 4, 2022 14:18
The Groovy way to obtain a relative path given two paths.
def root= new File('/usr/share')
def full= new File('/usr/share/docs/rpm-4.4')
// Print the relative path of 'full' in relation to 'root'
// Notice that the full path is passed as a parameter to the root.
def relPath= new File( root.toURI().relativize( full.toURI() ).toString() )
@ysb33r
ysb33r / Download+Unpack.groovy
Created June 19, 2013 16:24
groovy-vfs makes downloading & unpacking very simple. The following works well for smaller archives. Once the archive contains thousands of files, it is better to download first and then unpack. (This is due to a performance issue inside VFS2, not groovy-vfs).
@Grapes([
@GrabResolver( name='grysb33r', root='http://dl.bintray.com/ysb33r/grysb33r' ),
@Grab( 'org.ysb33r.groovy:groovy-vfs:0.2' ),
@Grab( 'commons-httpclient:commons-httpclient:3.1')
])
import org.ysb33r.groovy.dsl.vfs.VFS
// This will download the compressed archive from Sourceforge and unpack it to a local directory
new VFS() {
@ysb33r
ysb33r / Example.groovy
Last active June 26, 2023 23:43
Running Groovy unittests from the command-line
class Example {
def hhg() { 42 }
}
@ysb33r
ysb33r / JenkinsBuildFlow.groovy
Last active December 19, 2015 01:19
An example of a more complex build flow in Jenkins.
def partitions=6
def testResults
def buildResult
def staticAnalysisResult
def smokeTestResult
def performanceResult
def buildFlow= { buildResult= build( 'BUILDER' ) }
def performanceFlow= { performanceResult = build('PERFORMANCE')}
@ysb33r
ysb33r / JenkinsBuildFlowObjects.groovy
Last active October 1, 2016 19:24
If you are working with Jenkins BuildFlow plugin you can get some useful information of the returned build() call.
// Given that you have kicked off a build according to the DSL syntax
def results = build('RUN_THIS_JOB')
// Get out the name of the job again
println results.name
// Get the build ID
println results.id
// Get the build URL