SPI is well known and used but not supported by ANT. Maybe something like this: <jar ...> ... <service type="java.io.spi.CharCodec"> <provider class="sun.io.StandardCodec"/> </service> </jar>
We would certainly consider it, especially if you were to provide docs and unit tests alongside the code :) It'd be best if the code was like <manifest>; it could also act as a self contained task to create the relevant file outside the JAR itself. Some people like that.
I had al look at the ANT 1.6.2 Sources and tis is my Idea: package org.apache.tools.ant.taskdefs; class Service { private String type; private List providerList; setType(String type)... Provider createProvider()... //writing the File void write(ZipOutputStream zOut) { } } class Provider { private String clazz; setClass(String clazz)... } class Jar .. { private List serviceList = new LinkedList(); ... protected void initZipOutputStream(ZipOutputStream zOut) throws IOException, BuildException { if (!skipWriting) { Manifest jarManifest = createManifest(); writeManifest(zOut, jarManifest); writeService(zOut);//add this line } } public Service createService() { Service service = new Service(); serviceList.add(service); return service; } private void writeService(ZipOutputStream zOut) { Iterator i = serviceList.iterator(); while(i.hasNext()) { ((Service) i.next()).write(zOut); } } } I will try to implement this.
Do you really need to use "createService()" instead of "addConfiguredService(Service s)" or any other of the "add..." methods. The main difference between the two, is that "add..." would allow having polimorphic usage of services, while "create..." does not. If we eventually manage to do polimorphism, "add..." is a much better starting point.
Created attachment 12971 [details] first impl.
Committed a slightly modified version of this. Thanks for the patch!