Developer's Diary
Software development, with Terry Ebdon
A mixed bag

Thursday 29th June, 2017

Excludes in ant filesets

The excludes section in my backup script is getting quite large:

zip( destfile: zipFile ) {
fileset( dir: '.' ) {
exclude( name: 'html*/**/*' )
exclude( name: 'latex*/**/*' )
exclude( name: 'output/**/*' )
exclude( name: 'backup/**/*' )
exclude( name: '**/*.log' )
exclude( name: '**/*.class' )
exclude( name: 'plantuml.jar' )
}
}

A list like this should really be in configuration, not code. I can move the excludes into an excludes file. This is more manageable and would make it easy to switch between different exclude lists, if needed. This would be useful for backing up different folder trees with the same code.

zip( destfile: zipFile ) {
fileset(
dir: '.',
excludesfile: 'backupExcludes.txt' )
// Hard-coded file name ^^^ Ouch!
}

The backupExcludes.txt file has one pattern per line:

html*/**/*
latex*/**/*
output/**/*
backup/**/*
**/*.log
**/*.class
plantuml.jar

The hard-coded file name is a bit smelly, let's get rid of it. Currently all configuration for Backup.groovy is in the code, but all other classes use Groovy's ConfigSlurper to load it from config.groovy at run-time.

I've added the excludes file name to config.groovy:

backup {
excludesFile = "backupExcludes.txt"
}

The Backup class needs to load the configuration:

def buildConfig
Backup() {
buildConfig = new ConfigSlurper().
parse( new File( 'config.groovy' ).
toURI().toURL() )
}

Then use it in the FileSet's excludesfile attribute:

zip( destfile: zipFile ) {
fileset(
dir: '.',
excludesfile: config.backup.excludesFile
)
}

Errors with setx

The Windows set command allows environment variables to be created with spaces in the value string. There's no need to escape the spaces or quote the string:

C:>set greeting=Hello world.
C:>set greeting
greeting=Hello world.

Spaces are a problem for the setx command though. Unfortunately setx gives a confusing error message; it's not obvious that the space is the problem:

C:>setx JAVA_HOME c:\Program Files\Java\jdk1.8.0_92 /M
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

Surrounding the value with quotation marks solves the problem:

C:>setx JAVA_HOME "c:\Program Files\Java\jdk1.8.0_92" /M
SUCCESS: Specified value was saved.
C:>

Fixing Eclipse for Groovy

Yesterday Eclipse had problems running Groovy projects that use AntBuilder. This was easily fixed. Eclipse is using the embeddable Groovy jar, which doesn't include all the standard libraries. Adding the following three external dependencies to the build path resolves this: - ant-1.9.4.jar - ant-launcher-1.9.4.jar - commons-cli-1.2.jar

The commons-cli-1.2 jar is required to use Groovy's useful CliBuilder class.

BitBucket and Mercurial

The WebDoxy project has become non-trivial, so really should be in a cloud-based source control. Time to dust-off my BitBucket account. One advantage of Atlassian BitBucket is support for both Git and Mercurial. I've always used Mercurial as, at least in the past, it was said to have better integration on Microsoft Windows. The machine I'm currently using doesn't have Hg installed, so the combined Mercurial and TortoiseHg package seems the way to go.

Doxygen hates URLs that end with .md

I've been trying various versions of [hello world](https://example.com/hello.md). They all display as https://example.com/hello.md "hello world", where the URL is not rendered as a link. It's very odd. So far I've only seen the link work when it's a straight URL, with no markdown sugar, or the ".md" is removed.

The work-around is to use a HTML anchor.

Interesting web pages

Ant

Syntax Highlighting

Groovy

Mercurial

Microsoft Windows

Retro Computing


28th June 👈 Top of page 👉 30th June © 2017 Terry Ebdon.

Find me coding on GitHub, networking on LinkedIn, answering questions on Stack Exchange and hanging out on twitter.