Skip to content

Instantly share code, notes, and snippets.

Avatar

Schalk W. Cronjé ysb33r

  • Andorra
View GitHub Profile
@ysb33r
ysb33r / gradle-vfs-plugin2.groovy
Created Apr 9, 2014
VFS Gradle Plugin: SBE Copy Task
View gradle-vfs-plugin2.groovy
import org.ysb33r.gradle.vfs.*
// Assuming we have properties in gradle.properties
// userNameFrom
// passwordFrom
// userNameTo
// passwordTo
task simpleCopyTask ( type : VfsCopy ) {
from 'ftp://${userNameFrom}:${passwordFrom}@from.here/a.txt'
@ysb33r
ysb33r / vfs-plugins.groovy
Created Apr 1, 2014
How the plugin extension DSL will look like for Groovy VFS. No need to struggle with Apachae VFS vfs-provider.xml files
View vfs-plugins.groovy
import org.ysb33r.groovy.dsl.vfs.VFS
def vfs = new VFS()
// ---------------------------------
// Adding new providers with schemes
// ---------------------------------
vfs {
extend {
// Adding provider with no external dependencies
@ysb33r
ysb33r / bintray-examples.groovy
Created Mar 8, 2014
Maipulating Bintray API with Groovy
View bintray-examples.groovy
@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2' )
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseException
def repoOwner = 'ysb33r'
def repoName = 'grysb33r'
def packageName = 'bintray-gradle-plugin'
def bintrayUsername = '__YOUR_USERNAME__'
def bintrayApiKey = '__YOUR_APIKEY__'
def packageVersion = '0.1'
@ysb33r
ysb33r / JenkinsBuildFlowGetSVNTrackingInfo.groovy
Created Aug 13, 2013
Obtaining the SVN Tracking Plugin information from within a Jenkins Build Flow
View JenkinsBuildFlowGetSVNTrackingInfo.groovy
// Assumuing that the build flow tracks another job's SVN revision
// Get the SVN URLs and revisions
def svn=build.getAction(hudson.scm.RevisionParameterAction.class)
svn.revisions.each {
println it.SVNURL
println it.revision
}
// Get the Build number of the job being tracked
@ysb33r
ysb33r / JenkinsBuildFlowObjects.groovy
Last active Oct 1, 2016
If you are working with Jenkins BuildFlow plugin you can get some useful information of the returned build() call.
View JenkinsBuildFlowObjects.groovy
// 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
@ysb33r
ysb33r / JenkinsBuildFlow.groovy
Last active Dec 19, 2015
An example of a more complex build flow in Jenkins.
View JenkinsBuildFlow.groovy
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 / Example.groovy
Last active May 1, 2020
Running Groovy unittests from the command-line
View Example.groovy
class Example {
def hhg() { 42 }
}
@ysb33r
ysb33r / Download+Unpack.groovy
Created Jun 19, 2013
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).
View Download+Unpack.groovy
@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 / RelativePath.groovy
Last active Nov 29, 2020
The Groovy way to obtain a relative path given two paths.
View RelativePath.groovy
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 / XsltUnitToJUnitXml.xsl
Last active Dec 18, 2015
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.
View XsltUnitToJUnitXml.xsl
<?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"