Bug 31520 - Extending JAR-Task for SPI
Summary: Extending JAR-Task for SPI
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: All All
: P3 enhancement with 4 votes (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
URL: http://java.sun.com/j2se/1.5.0/docs/g...
Depends on:
Reported: 2004-10-04 00:25 UTC by bernd
Modified: 2008-02-22 12:18 UTC (History)
0 users

first impl. (5.12 KB, patch)
2004-10-06 21:52 UTC, bernd
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description bernd 2004-10-04 00:25:39 UTC
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"/>
Comment 1 Steve Loughran 2004-10-04 09:37:06 UTC
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.
Comment 2 bernd 2004-10-04 20:46:41 UTC
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();
    return service;

  private void writeService(ZipOutputStream zOut)
     Iterator i = serviceList.iterator();
       ((Service) i.next()).write(zOut);

I will try to implement this.
Comment 3 Jose Alberto Fernandez 2004-10-05 10:48:35 UTC
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 
Comment 4 bernd 2004-10-06 21:52:17 UTC
Created attachment 12971 [details]
first impl.
Comment 5 Peter Reilly 2006-09-27 21:12:38 UTC
Committed a slightly modified version of this.
Thanks for the patch!