You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2006/09/26 23:15:13 UTC
svn commit: r450209 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW
contributors.xml docs/manual/CoreTasks/jar.html
src/main/org/apache/tools/ant/taskdefs/Jar.java
Author: peterreilly
Date: Tue Sep 26 14:15:12 2006
New Revision: 450209
URL: http://svn.apache.org/viewvc?view=rev&rev=450209
Log:
Bugzilla 31520
adding SPI to jar-task
This patch from bernd Dutkowski adds
a nested element <service> to the <jar> task
this creates the SPI files - see doc.
Modified:
ant/core/trunk/CONTRIBUTORS
ant/core/trunk/WHATSNEW
ant/core/trunk/contributors.xml
ant/core/trunk/docs/manual/CoreTasks/jar.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?view=diff&rev=450209&r1=450208&r2=450209
==============================================================================
Binary files - no diff available.
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=450209&r1=450208&r2=450209
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Sep 26 14:15:12 2006
@@ -34,6 +34,8 @@
* Add <matches> condition. Bugzilla report 28883.
+* Extending JAR-Task for SPI. Bugzilla report 31520.
+
Changes from Ant 1.7.0Beta1 to Ant 1.7.0Beta2
=============================================
Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?view=diff&rev=450209&r1=450208&r2=450209
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Tue Sep 26 14:15:12 2006
@@ -89,6 +89,10 @@
<last>Moussaud</last>
</name>
<name>
+ <first>Bernd</first>
+ <last>Dutkowski</last>
+ </name>
+ <name>
<first>Brad</first>
<last>Clark</last>
</name>
Modified: ant/core/trunk/docs/manual/CoreTasks/jar.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/jar.html?view=diff&rev=450209&r1=450208&r2=450209
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/jar.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/jar.html Tue Sep 26 14:15:12 2006
@@ -60,10 +60,10 @@
entry in the archive, Ant will not consider it newer.</p>
<p>The <code>whenmanifestonly</code> parameter controls what happens when no
-files, apart from the manifest file, match.
+files, apart from the manifest file, or nested services, match.
If <code>skip</code>, the JAR is not created and a warning is issued.
If <code>fail</code>, the JAR is not created and the build is halted with an error.
-If <code>create</code>, (default) an empty JAR file (only containing a manifest)
+If <code>create</code>, (default) an empty JAR file (only containing a manifest and services)
is created.</p>
<p>(The Jar task is a shortcut for specifying the manifest file of a JAR file.
@@ -82,7 +82,7 @@
fully-qualified name to exist within a single archive. This has been
documented as causing various problems for unsuspecting users. If you wish
to avoid this behavior you must set the <code>duplicate</code> attribute
-to a value other than its default, <code>"add"</code>.</b></p>
+to a value other than its default, <code>"add"</code>.</b></p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
@@ -278,7 +278,52 @@
<p>This task will not create any index entries for archives that are
empty or only contain files inside the META-INF directory.</p>
+<a name="service"><h4>service</h4></a>
+<p><em>since ant 1.7.0</em></p>
+
+<p>
+ The nested <code>server</code> element specifies a service.
+ Services are described by
+ <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider">http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider</a>.
+ The approach is to have providers JARs include files named by the service
+ provided, for example,
+ META-INF/services/javax.script.ScriptEngineFactory
+ which can include implementation class names, one per line (usually just one per JAR).
+
+ The name of the
+ service is set by the "type" attribute. The classname implementing
+ the service is the the "provider" attribute, or it one wants to
+ specify a number of classes that implement the service, by
+ "provider" nested elements.
+</p>
+<p>
+<table border="1" cellpadding="2" cellspacing="0">
+ <tr>
+ <td valign="top"><b>Attribute</b></td>
+ <td valign="top"><b>Description</b></td>
+ <td align="center" valign="top"><b>Required</b></td>
+ </tr>
+ <tr>
+ <td valign="top">type</td>
+ <td valign="top">The name of the service.</td>
+ <td valign="top" align="center">Yes</td>
+ </tr>
+ <tr>
+ <td valign="top">provider</td>
+ <td valign="top">
+ The classname of the class implemening the service.
+ </td>
+ <td valign="top" align="center">Yes, unless there is a nested
+ <code><provider></code> element.</td>
+ </tr>
+</table>
+ <p>
+ The provider classname is specified either by the "provider" attribute, or
+ by a nested <provider> element, which has a single "classname" attribute.
+ If a JAR file has more that one implementation of the service, a number of
+ nested <provider> elements may be used.
+ </p>
<h3>Examples</h3>
<pre> <jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"/></pre>
<p>jars all files in the <code>${build}/classes</code> directory into a file
@@ -336,6 +381,28 @@
Sealed: false</code></pre>
-
+<p>
+ The following shows how to create a jar file specifing a service
+ with an implementation of the JDK6 scripting interface:
+</p>
+<blockquote><pre><jar jarfile="pinky.jar">
+ <fileset dir="build/classes"/>
+ <service type="javax.script.ScriptEngineFactory"
+ provider="org.acme.PinkyLanguage"/>
+</jar>
+</pre></blockquote>
+<p>
+ The following shows how to create a jar file specifing a service
+ with two implementations of the JDK6 scripting interface:
+</p>
+<blockquote><pre>
+<jar jarfile="pinkyandbrain.jar">
+ <fileset dir="classes"/>
+ <service type="javax.script.ScriptEngineFactory">
+ <provider classname="org.acme.PinkyLanguage"/>
+ <provider classname="org.acme.BrainLanguage"/>
+ </service>
+</jar>
+</pre></blockquote>
</body>
</html>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?view=diff&rev=450209&r1=450208&r2=450209
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java Tue Sep 26 14:15:12 2006
@@ -48,6 +48,7 @@
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.ZipFileSet;
+import org.apache.tools.ant.types.spi.Service;
import org.apache.tools.zip.JarMarker;
import org.apache.tools.zip.ZipExtraField;
import org.apache.tools.zip.ZipOutputStream;
@@ -66,6 +67,11 @@
/** The manifest file name. */
private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
+ /**
+ * List of all known SPI Services
+ */
+ private List serviceList = new ArrayList();
+
/** merged manifests added through addConfiguredManifest */
private Manifest configuredManifest;
/** shadow of the above if upToDate check alters the value */
@@ -368,6 +374,36 @@
}
/**
+ * A nested SPI service element.
+ * @param service the nested element.
+ * @since Ant 1.7
+ */
+ public void addConfiguredService(Service service) {
+ // Check if the service is configured correctly
+ service.check();
+ serviceList.add(service);
+ }
+
+ /**
+ * Write SPI Information to JAR
+ */
+ private void writeServices(ZipOutputStream zOut) throws IOException {
+ Iterator serviceIterator;
+ Service service;
+
+ serviceIterator = serviceList.iterator();
+ while(serviceIterator.hasNext()){
+ service = (Service) serviceIterator.next();
+ //stolen from writeManifest
+ super.zipFile(service.getAsStream(), zOut,
+ "META-INF/service/" + service.getType(),
+ System.currentTimeMillis(), null,
+ ZipFileSet.DEFAULT_FILE_MODE);
+ }
+ }
+
+
+ /**
* Initialize the zip output stream.
* @param zOut the zip output stream
* @throws IOException on I/O errors
@@ -379,6 +415,7 @@
if (!skipWriting) {
Manifest jarManifest = createManifest();
writeManifest(zOut, jarManifest);
+ writeServices(zOut);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org