[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Java Linux common packaging



Le sam, 27/03/2004 à 16:23 +0100, Nicolas Mailhot a écrit :

> I've added a few pages in the wiki over the last few days.
> 
> (http://java.debian.net/index.php/CommonJavaPackaging)

BTW if someone wants to play with xml dependency descriptors like the
ones declared in : 

http://java.debian.net/index.php/Classpath%20unit%20description

.. here is a proof-of-concept xslt that converts them into a java
classpath.

Usage :
1. write some bogus descriptors following the template in the wiki (the
more complex the better - we want to stress the infrastructure)
2. reference them into an index file, for example :
<?xml version="1.0"?>
<classesdb xmlns:xi="http://www.w3.org/2003/XInclude";>
 <xi:include href="foo-a.b.c.xml"/>
 <xi:include href="bar-d.e.f.xml"/>
</classesdb>
3. generate the classpath using your favorite xslt engine, for example
with xltproc :
xsltproc --xinclude --stringparam path foo pathtest.xsl index.xml

Warning ! The xsl is still very immature and feature-incomplete. The
following is not implemented yet :
- generating a classpath from more than one element
- smart version handling (ie if we ask for version x.y.z, generate
  foo.jar:foo-x.jar:foo-x.y.jar:foo-x.y.z.jar as classpath)
- virtual priority (ie have a separate policy file that specifies
implementation priorities for virtuals)
- blacklisting checking (ie do not generate a path with foo and bar is
foo declares it can not work with bar, do not use elements that conflict
with the selected java engine...)
- classpath sanitization (do not output a classelement twice in the
final path)
- non classpath-string mode (output file lists to create a directory of
jar links for application servers, ant, eclipse and everything that uses
jar directories)
... and probably a lot more I forgot

The following however should already work :
- recursive deps
- basic virtual handling (ie pathelement foo declaring it implements bar
virtual, and the classpath engine resolving foo when asked for bar)
- multi-extension handling (ie not everything is a jar file)
- config file handling (place config files before jar files so
foo.properties in /etc/ will be taken into account instead of hidden
foo.properties in foo.jar)
- user overrides (always check for files into ~/.java before sourcing
system-level ones)

Which is not too bad for a 100-line file. However I really feel the more
complete the policy we wan to implement, the more xslt+xpath will shine
- consolidating data in loosely written files in exactly why it was
written.

BTW xsltproc is blazingly fast here - I doubt a shell implementation
would be any faster. In fact I suspect it'll end up faster than anything
in shell - all the optimizations the Gnome folks did to process heavy
docbook documents seem to paying of nicely.

Regards,

-- 
Nicolas Mailhot
<?xml version="1.0"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
  xmlns:exsl="http://exslt.org/common";
  extension-element-prefixes="exsl">

  <xsl:output method="text" encoding="UTF-8"/>

  <xsl:key name="pathelems" match="/classesdb/pathelem" use="@name"/>
  <xsl:key name="virtuals" match="/classesdb/pathelem/implements/pathelem" use="@name"/>
  <xsl:param name="sysconfdir">/etc/java</xsl:param>
  <xsl:param name="usrconfdir">~/.java/etc</xsl:param>
  <xsl:param name="sysjardir">/usr/share/java</xsl:param>
  <xsl:param name="usrjardir">~/.java/lib</xsl:param>
  <xsl:param name="path" required="yes"/>

  <xsl:template match="/">
    <xsl:variable name="expanded">
     <classpath>
     <xsl:call-template name="findelem">
      <xsl:with-param name="pathname" select="$path"/>
     </xsl:call-template>
     </classpath>
    </xsl:variable>
    <xsl:variable name="classpath">
     <xsl:for-each select="exsl:node-set($expanded)/*">
      <xsl:apply-templates/>
     </xsl:for-each>
    </xsl:variable>
    <xsl:copy-of select="$classpath"/>
  </xsl:template>

  <xsl:template match="depends/pathelem" priority="1">
     <xsl:call-template name="findelem">
      <xsl:with-param name="pathname" select="@name"/>
     </xsl:call-template>
  </xsl:template>

  <xsl:template match="pathelem" priority="0">
    <xsl:apply-templates select="config" mode="full"/>
    <xsl:apply-templates select="classes" mode="full"/>
    <xsl:apply-templates select="depends/pathelem"/>
  </xsl:template>

  <xsl:template name="findelem">
    <xsl:param name="pathname" required="yes"/>
    <xsl:choose>
     <xsl:when test="count(key('pathelems',$pathname))>0">
      <xsl:apply-templates select="key('pathelems',$pathname)[1]"/>
     </xsl:when>
     <xsl:when test="count(key('virtuals',$pathname))>0">
       <xsl:apply-templates select="key('virtuals',$pathname)[1]/../.."/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:message>Could not find matching classpath element for <xsl:value-of select="$pathname"/></xsl:message>
     </xsl:otherwise>
   </xsl:choose>
  </xsl:template>

  <xsl:template match="config|classes" mode="full">
    <pathbit>
      <xsl:apply-templates select="." mode="prefix"/>
      <xsl:apply-templates select="." mode="version"/>
      <xsl:apply-templates select="." mode="root"/>
    </pathbit>
  </xsl:template>

  <xsl:template match="*[@dir and (self::config or self::classes)]" mode="prefix">
      <prefix><xsl:value-of select="@dir"/></prefix>
      <postfix>/</postfix>
  </xsl:template>

  <xsl:template match="classes[@libdir]" mode="prefix">
      <prefix><xsl:value-of select="@libdir"/></prefix>
      <postfix>/*</postfix>
  </xsl:template>

  <xsl:template match="*[@file and (self::config or self::classes)]" mode="prefix">
      <prefix><xsl:value-of select="@file"/></prefix>
      <xsl:apply-templates select="." mode="postfix"/>
  </xsl:template>

  <xsl:template match="*[@file and @ext and (self::config or self::classes)]" mode="postfix" priority="1">
       <postfix><xsl:value-of select="concat('.',@ext)"/></postfix>
  </xsl:template>

  <xsl:template match="config[@file]" mode="postfix" priority="0">
       <postfix>.properties</postfix>
  </xsl:template>

  <xsl:template match="classes[@file]" mode="postfix" priority="0">
       <postfix>.jar</postfix>
  </xsl:template>

  <xsl:template match="*[@version and (self::config or self::classes)]" mode="version" priority="1">
       <version><xsl:value-of select="@version"/></version>
  </xsl:template>

  <xsl:template match="config|classes" mode="version" priority="0">
       <version><xsl:value-of select="../@version"/></version>
  </xsl:template>

  <xsl:template match="config" mode="root">
       <sysroot><xsl:value-of select="$sysconfdir"/></sysroot>
       <usrroot><xsl:value-of select="$usrconfdir"/></usrroot>
  </xsl:template>

  <xsl:template match="classes" mode="root">
       <sysroot><xsl:value-of select="$sysjardir"/></sysroot>
       <usrroot><xsl:value-of select="$usrjardir"/></usrroot>
  </xsl:template>

  <xsl:template match="pathbit">

    <xsl:variable name="pathlet" select="concat(prefix,'-',version,postfix)"/>
    <xsl:choose>
     <xsl:when test="starts-with($pathlet,'/')">
      <xsl:value-of select="$pathlet"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="concat(usrroot,'/',$pathlet,':',sysroot,'/',$pathlet)"/>
     </xsl:otherwise>
   </xsl:choose>

   <xsl:if test="position() != last()">:</xsl:if>

  </xsl:template>

</xsl:stylesheet>

Attachment: signature.asc
Description: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=


Reply to: