Bug 31520 - Extending JAR-Task for SPI
Extending JAR-Task for SPI
Status: RESOLVED FIXED
Product: Ant
Classification: Unclassified
Component: Core tasks
unspecified
All All
: P3 enhancement with 4 votes (vote)
: 1.7.0
Assigned To: Ant Notifications List
http://java.sun.com/j2se/1.5.0/docs/g...
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2004-10-04 00:25 UTC by bernd
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments
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"/>
  </service>
</jar>
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();
    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.
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 
point.
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!