package de.tobject.findbugs.tools;

import java.io.File;

import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

/**
 * Extract information (plugin id, version, etc.)
 * from the plugin's plugin.xml file,
 * and print the information as java properties.
 * This allows our Ant build.xml file to figure out
 * what the deployable plugin zip file should be called.
 */
public class PluginInfo {
	public static void main(String[] args) throws Exception {
		if (args.length != 1) {
			System.err.println("Usage: " + PluginInfo.class.getName() + " <plugin.xml file>");
			System.exit(1);
		}
		
		SAXReader reader = new SAXReader();
		Document document = reader.read(new File(args[0]));
		
		emitProperty(document, "plugin.id", "/plugin/@id");
		emitProperty(document, "plugin.version", "/plugin/@version");
	}

	private static void emitProperty(Document document, String propName, String xpath) {
		Node node = document.selectSingleNode(xpath);
		if (node == null)
			throw new RuntimeException("No node found for xpath " + xpath);
		System.out.println(propName + "=" + node.getText());
	}
}

@@ -49,16 +49,74 @@
 io.File;
+%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;
 %0A%0Aimport
@@ -471,16 +471,101 @@
 nInfo %7B%0A
+%09static final SimpleDateFormat eclipseDateFormat = new SimpleDateFormat(%22yyyyMMdd%22);%0A
 %09public 
@@ -902,16 +902,16 @@
 /@id%22);%0A
-
 %09%09emitPr
@@ -963,16 +963,75 @@
 version%22
+.replace(%22qualifier%22, eclipseDateFormat.format(new Date()))
 );%0A%09%7D%0A%0A%09

replace qualifier in version with yyyyMMdd