Blogging via Ant with the Blogger API

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="&lt;p&gt;Hello from Ant!&lt;/p&gt;"/>

  <!-- 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.



Re: Blogging via Ant with the Blogger API

What utter nonsense. Why the hell would you want to be editing your build.xml file at every build just so you can post a blog entry?

Re: Blogging via Ant with the Blogger API

You probably wouldn't, but you could put some text into a property and use this as your blog content.

Re: Blogging via Ant with the Blogger API

...of course, I meant that you would populate the property during the build process automatically ... just to save any confusion. :-)

Re: Blogging via Ant with the Blogger API

I think it's great! It will save me just that much time where I would normally be logging onto my weblog just to make a build release announcement. This way, I run 1 task, and everything is done for me; from compiling all my code to ftp-ing to the site, to creating my weblog entry. Super cool Simon!!

Re: Blogging via Ant with the Blogger API

Ant -> Blogger!?!?! Simon, you are a nut! ;-)

Re: Blogging via Ant with the Blogger API

Definately getting there. I can really see this being useful.

If you want extra synergy, I remember seeing one project where the delivered documentation was compiled by doing an HTTP trawl of a local Wiki. Add these two ideas together and you get painless editing of release notes, change lists and other documentation, and one-button publishing. Sweet.

Now, has anyone got any ant tasks for driving the byzantine file release process at sourceforge ?

Re: Blogging via Ant with the Blogger API

This feature sounds like it was inspired by lots of caffeine. Not sure Ill use it, but I won't criticize it either! Really I think it comes down to the focus of your blog.

Re: Blogging via Ant with the Blogger API

This is an excellent product Simon. I was wondering if you had thought of adding a wiki engine to it?

Re: Blogging via Ant with the Blogger API

Cameron, so do you think a Blogger API log4j appender is a nutty idea too? ;-)

Re: Blogging via Ant with the Blogger API

You mention you have extended the API to allow entries to be categorised. What are you expecting?

If if post with a <category>Java</category> in the content, it adds it to the post. The log looks like...

[pebble.webservice.BloggerAPIHandler] BloggerAPI.newPost(77783D0E1EE8808BD4D3327D1EB2601C78DB3D65, blog, phil, ********, <title>Test</title><category>Java</category>Test Content, true)

Re: Blogging via Ant with the Blogger API

It's an additional XML-RPC method call as follows because the BloggerAPI doesn't support it...

Name : addCategory
Parameters : appkey, postid, username, password, category (the category ID)

Re: Blogging via Ant with the Blogger API

Hi,

It's an additional XML-RPC method call as follows because the BloggerAPI doesn't support it...

Name : addCategory


OK, one of us got confused ;-). I was trying to post an entry to a specific category via the API, not add a category. This is not supported I guess? Phil

Posting to categories not supported by Blogger API

That's right, posting to a specific category isn't supported by the Blogger API. It's supported by other XML-RPC APIs though, but they're lower on my priority list at the moment. ;-)

Re: Posting to categories not supported by Blogger API

Some 'blogs' (e.g. Journalspace, Livejournal and wordpress) support posting to a specific category by allowing a <category>xxx</category> element in the 'content', much like the <title>xxx</title> is currently.

Re: Blogging via Ant with the Blogger API

That sounds easy enough - do you want to raise a JIRA request with an example of what the content/body would look like?

Re: Posting to categories not supported by Blogger API

That sounds easy enough - do you want to raise a JIRA request with an example of what the content/body would look like?

Done

Re: Posting to categories not supported by Blogger API

Thanks Phil. :-)

Add a comment Send a TrackBack