maartenc commented on pull request #134:
URL: https://github.com/apache/ant/pull/134#issuecomment-671239026


   Hi @bodewig ,
   
   You are right, here is a bit more context of the problem.
   
   Our applications are installed like this:
   ```
   <some root dir>
       /Shared
           /org/apache/commons-io/commons-io-2.4.jar
           /org/apache/commons-lang/commons-lang-2.6.jar
           ...
       /ApplicationA
           main.jar
           lib1.jar
           lib2.jar
           ...
       /ApplicationB
           main.jar
           lib1.jar
           lib3.jar
       ...
   ```
   
   Our biggest application uses about 500 jars. To speed up classloading, we 
are adding an INDEX.LIST to main.jar.
   The INDEX.LIST spec says that the jar file paths in the INDEX.LIST should be 
relative to main.jar. So the INDEX.LIST should look like:
   
   ```
   JarIndex-Version: 1.0
   
   main.jar
   [...]
   
   lib1.jar
   [...]
   
   ../Shared/org/apache/commons-io/commons-io-2.4.jar
   [...]
   
   ../Shared/org/apache/commons-lang/commons-lang-2.6.jar
   [...]
   ```
   
   With the current Ant <jar> task, there are 2 possibilities to configure the 
jar file paths in the INDEX.LIST.
   1. if main.jar doesn't contain a Class-Path attribute (our use-case), all 
jar file paths are flattened.
   2. if main.jar does contain a Class-Path attribute, the jar file path is 
taken from that Class-Path attribute.
   
   Since we don't have a Class-Path attribute (which is intentionaly), we end 
up with a flatten path names in INDEX.LIST.
   
   A workaround could probably be to:
   1. add a Class-Path attribute to the MANIFEST.MF with the wanted mapping for 
INDEX.LIST
   2. generate the INDEX.LIST
   3. remove the Class-Path attribute from the MANIFEST.MF
   
   This is off course a suboptimal solution making the build script needlessly 
complex.
   
   The attached patch tries to address the issue by making it possible to 
specify a filename-mapper **inside** the <indexjars> element. If this mapper 
isn't specified, the default mapping (as specified above) is used. 
   
   ```
   <jar ...>
       <indexjars>
           <fileset dir="build/lib/**/*.jar"/>
           <firstmatchmapper>
               <globmapper from="${basedir}/build/lib/${application}/*" to="*" 
handledirsep="true" />
               <globmapper from="${basedir}/build/lib/Shared/*" 
to="../Shared/*" handledirsep="true"/>
           </firstmatchmapper>
       </indexjars>
   </jar>
   ```
   
   An alternative patch could be to add an extra mapper subelement to the <jar> 
task directly (and not inside the <indexjars> element), something like:
   
   ```
   <jar ...>
       <indexjars>
           <fileset dir="build/lib/**/*.jar"/>
       </indexjars>
       <indexjarsmapper>
           <firstmatchmapper>
               <globmapper from="${basedir}/build/lib/${application}/*" to="*" 
handledirsep="true" />
               <globmapper from="${basedir}/build/lib/Shared/*" 
to="../Shared/*" handledirsep="true"/>
           </firstmatchmapper>
       </indexjarsmapper>
   </jar>
   ```
   
   I think the first solutions results in a cleaner build.xml. But with perhaps 
a little bit more complex java code (and with a not 100% backwards compatible 
API change). But the second solution is also a possibility, I can create a new 
patch if you prefer that solution.
   
   Maarten


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org

Reply via email to