View | Details | Raw Unified | Return to bug 31520
Collapse All | Expand All

(-)src/main/org/apache/tools/ant/taskdefs/Jar.java (-1 / +46 lines)
Lines 43-48 Link Here
43
import java.util.zip.ZipFile;
43
import java.util.zip.ZipFile;
44
import org.apache.tools.ant.BuildException;
44
import org.apache.tools.ant.BuildException;
45
import org.apache.tools.ant.Project;
45
import org.apache.tools.ant.Project;
46
import org.apache.tools.ant.taskdefs.spi.Service;
46
import org.apache.tools.ant.types.EnumeratedAttribute;
47
import org.apache.tools.ant.types.EnumeratedAttribute;
47
import org.apache.tools.ant.types.FileSet;
48
import org.apache.tools.ant.types.FileSet;
48
import org.apache.tools.ant.types.Path;
49
import org.apache.tools.ant.types.Path;
Lines 335-340 Link Here
335
        if (!skipWriting) {
336
        if (!skipWriting) {
336
            Manifest jarManifest = createManifest();
337
            Manifest jarManifest = createManifest();
337
            writeManifest(zOut, jarManifest);
338
            writeManifest(zOut, jarManifest);
339
            writeService(zOut);
338
        }
340
        }
339
    }
341
    }
340
342
Lines 846-849 Link Here
846
            }
848
            }
847
        }
849
        }
848
    }
850
    }
849
}
851
    
852
    /**
853
     * ANT Jar-Task SPI extension
854
     * 
855
     * List of all known Services
856
     * 
857
     * @author Bernd 'Nexos' Dutkowski <bernd@dutkowski.net>
858
     * @see http://issues.apache.org/bugzilla/show_bug.cgi?id=31520
859
     */
860
    private List serviceList = new ArrayList();
861
862
    /**
863
     * ANT Jar-Task SPI extension
864
     * 
865
     * @author Bernd 'Nexos' Dutkowski <bernd@dutkowski.net>
866
     * @see http://issues.apache.org/bugzilla/show_bug.cgi?id=31520
867
     */
868
    public void addConfiguredService(Service service){
869
        serviceList.add(service);
870
    }
871
872
    /**
873
     * ANT Jar-Task SPI extension
874
     * 
875
     * Write SPI Information to JAR
876
     * 
877
     * @author Bernd 'Nexos' Dutkowski <bernd@dutkowski.net>
878
     * @see http://issues.apache.org/bugzilla/show_bug.cgi?id=31520
879
     */
880
    private void writeService(ZipOutputStream zOut) throws IOException{
881
        Iterator serviceIterator;
882
        Service service;
883
        
884
        serviceIterator = serviceList.iterator();
885
        while(serviceIterator.hasNext()){
886
           service = (Service) serviceIterator.next();
887
           //stolen from writeManifest
888
           super.zipFile(service.getAsStream(), zOut, 
889
                   "META-INF/service/" + service.getType(),
890
                   System.currentTimeMillis(), null,
891
                   ZipFileSet.DEFAULT_FILE_MODE);
892
        }
893
    }
894
}
(-)src/main/org/apache/tools/ant/taskdefs/spi/Provider.java (+19 lines)
Added Link Here
1
package org.apache.tools.ant.taskdefs.spi;
2
3
/**
4
 * ANT Jar-Task SPI extension
5
 * 
6
 * @author Bernd 'Nexos' Dutkowski <bernd@dutkowski.net>
7
 * @see http://issues.apache.org/bugzilla/show_bug.cgi?id=31520
8
 */
9
public class Provider{
10
    private String type;
11
    
12
    public String getType(){
13
        return type;
14
    }
15
    
16
    public void setType(String type){
17
        this.type = type;
18
    }
19
}
(-)src/main/org/apache/tools/ant/taskdefs/spi/Service.java (+58 lines)
Added Link Here
1
package org.apache.tools.ant.taskdefs.spi;
2
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.OutputStreamWriter;
8
import java.io.Writer;
9
import java.util.ArrayList;
10
import java.util.Iterator;
11
import java.util.List;
12
13
/**
14
 * ANT Jar-Task SPI extension
15
 * 
16
 * @author Bernd 'Nexos' Dutkowski <bernd@dutkowski.net>
17
 * @see http://issues.apache.org/bugzilla/show_bug.cgi?id=31520
18
 */
19
public class Service{
20
    private List providerList;
21
    private String type;
22
    
23
    public Service(){
24
        super();
25
        
26
        providerList = new ArrayList();
27
    }
28
    
29
    public void addConfiguredProvider(Provider provider){
30
        providerList.add(provider);
31
    }
32
    
33
    public String getType(){
34
        return type;
35
    }
36
    
37
    public void setType(String type){
38
        this.type = type;
39
    }
40
    
41
    public InputStream getAsStream() throws IOException{
42
        ByteArrayOutputStream arrayOut;
43
        Writer writer;
44
        Iterator providerIterator;
45
        Provider provider;
46
        
47
        arrayOut = new ByteArrayOutputStream();
48
        writer = new OutputStreamWriter(arrayOut, "UTF-8");
49
        providerIterator = providerList.iterator();
50
        while (providerIterator.hasNext()){
51
            provider = (Provider) providerIterator.next();
52
            writer.write(provider.getType());
53
            writer.write("\n");
54
        }
55
        writer.close();
56
        return new ByteArrayInputStream(arrayOut.toByteArray());
57
    }
58
}

Return to bug 31520