You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2013/03/28 18:39:07 UTC

[Bug 54761] New: Using jar command to create a jar containing two separate implementations of a service doesn't work

https://issues.apache.org/bugzilla/show_bug.cgi?id=54761

            Bug ID: 54761
           Summary: Using jar command to create a jar containing two
                    separate implementations of a service doesn't work
           Product: Ant
           Version: 1.9.0
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
          Assignee: notifications@ant.apache.org
          Reporter: jburgess1024@gmail.com
    Classification: Unclassified

If you are using the jar task to create a jar that contains two implementations
of a service the two classes are concatenated.

So

<macrodef name="build-checker" >
<attribute name="scname" />
<attribute name="extra1" default=""/>
<sequential xmlns:ac="antlib:net.sf.antcontrib">
<jar jarfile="${dist.dir}/@{scname}.jar" >
   <fileset dir="build/@{scname}"/>
   <service type="com.riskdecisions.sanitycheck.SanityCheck">
      <provider classname="com.riskdecisions.sanitycheck.providers.@{scname}"
/>
      <provider classname="com.riskdecisions.sanitycheck.providers.@{extra1}"
/>
   </service>
</jar>
</sequential>
</macrodef>

when called as 
        <build-checker scname="BergChecker" extra1="CheckCluster"/>
results in a file com.riskdecisions.sanitycheck.SanityCheck in the services
folder containing
com.riskdecisions.sanitycheck.providers.BergCheckercom.riskdecisions.sanitycheck.providers.CheckCluster

There should be a new line between the two providers.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 54761] Using jar command to create a jar containing two separate implementations of a service doesn't work

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54761

John Burgess <jb...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from John Burgess <jb...@gmail.com> ---
The work around I have found is to use the zip task to add a new version of
com.riskdecisions.sanitycheck.SanityCheck to the jar.

After the jar command I added:

<mkdir dir="META-INF/services"/>
<echo file="META-INF/services/com.riskdecisions.sanitycheck.SanityCheck"
append="false">
com.riskdecisions.sanitycheck.providers.@{scname}
${line.separator}
com.riskdecisions.sanitycheck.providers.@{extra1}
</echo>
<zip destfile="${dist.dir}/@{scname}.jar" update="true">
     <fileset dir="${basedir}" includes="META-INF/services/*"/>
</zip>   
<delete dir="META-INF"/>

This solves the problem, but I don't think it should be difficult to fix and
would be much more convenient.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 54761] Using jar command to create a jar containing two separate implementations of a service doesn't work

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54761

Stefan Bodewig <bo...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #3 from Stefan Bodewig <bo...@apache.org> ---
maybe I'm jut repeating what Antoine says, but it seems to work as expected:

stefanb@brick:/tmp$ cat foo.xml
<project>
  <property name="dist.dir" location="."/>
  <mkdir dir="build/BergChecker"/>
  <macrodef name="build-checker" >
    <attribute name="scname" />
    <attribute name="extra1" default=""/>
    <sequential>
      <jar jarfile="${dist.dir}/@{scname}.jar" >
        <fileset dir="build/@{scname}"/>
        <service type="com.riskdecisions.sanitycheck.SanityCheck">
          <provider
classname="com.riskdecisions.sanitycheck.providers.@{scname}" />
          <provider
classname="com.riskdecisions.sanitycheck.providers.@{extra1}" />
        </service>
      </jar>
    </sequential>
  </macrodef>
  <build-checker scname="BergChecker" extra1="CheckCluster"/>
</project>
stefanb@brick:/tmp$ ant -f foo.xml 
Buildfile: /tmp/foo.xml
    [mkdir] Created dir: /tmp/build/BergChecker
      [jar] Building MANIFEST-only jar: /tmp/BergChecker.jar

BUILD SUCCESSFUL
Total time: 0 seconds
stefanb@brick:/tmp$ unzip BergChecker.jar 
Archive:  BergChecker.jar
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF    
  inflating: META-INF/services/com.riskdecisions.sanitycheck.SanityCheck  
stefanb@brick:/tmp$ cat
META-INF/services/com.riskdecisions.sanitycheck.SanityCheck 
com.riskdecisions.sanitycheck.providers.BergChecker
com.riskdecisions.sanitycheck.providers.CheckCluster

there even is an AntUnit test for that in
http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/antunit/taskdefs/jar-spi-test.xml
(test-providers)

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 54761] Using jar command to create a jar containing two separate implementations of a service doesn't work

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54761

--- Comment #2 from Antoine Levy-Lambert <an...@apache.org> ---
Hello John,

I disagree that the classes are concatenated in the service file.
The names of the 2 provider classes will be separated by a newline character
(\n).
The jar file specification
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Service_Provider
says that "The file should contain a newline-separated list of unique concrete
provider-class names. "
So Ant is creating service provider files where classnames are separated by new
lines. New lines only are not visible in some Windows editors such as notepad.

If the service provider classes are only recognized when the class names are
separated by \r\n instead of just \n, that would mean that the service provider
paragraph in the jar file documentation is not specific enough.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 54761] Using jar command to create a jar containing two separate implementations of a service doesn't work

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54761

Antoine Levy-Lambert <an...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.9.0                       |1.9.1

-- 
You are receiving this mail because:
You are the assignee for the bug.