This post originated from an RSS feed registered with Java Buzz
by Simon Brown.
Original Post: Blogging via Ant with the Blogger API
Feed Title: Simon Brown's weblog
Feed URL: http://www.simongbrown.com/blog/feed.xml?flavor=rss20&category=java
Feed Description: My thoughts on Java, software development and technology.
I've often thought that it would be nice to be able to blog from Ant and, while discussing some stuff over at JavaRanch, Gregg has given me an opportunity to put some simple code together. Being able to blog from Ant opens up a few opportunities if you think about using a blog as a project diary.
Publishing Ant build/test reports
Publishing release information such as change logs
So, after a bit of hacking I came up with a simple Ant task that posts a blog entry via the Blogger API. I'm going to include it in the next Pebble release but if you want to give it a go now, you'll need pebble-ant.jar and xmlrpc-1.1.jar (you'll need to right click and "Save as..." because the MIME type isn't set correctly). Just drop these both onto your classpath before starting Ant and then use the following in your build.xml file, changing the attributes as necessary.
<taskdef name="postToBlog" classname="pebble.ant.BloggerAPITask"/>
<!-- content must use escaped HTML/XML tags -->
<property name="content" value="<p>Hello from Ant!</p>"/>
<!-- example of how to post to a blog -->
<target name="example">
<postToBlog
url="http://localhost:8080/blog/xmlrpc"
handler="blogger"
blogid="test"
username="simon"
password="password"
title="Hello"
content="${content}" />
</target>
There's also a category attribute but you'll need to be posting to Pebble 1.4.2 to be able to use this because I've extended the Blogger API to allow entries to be categorised. If your blogging system supports the Blogger API and expects blog entry titles to be wrapped up within <title> tags at the start of the blog entry text then it should work.