On Mon, Apr 7, 2008 at 10:31 AM, Xavier Hanin <[EMAIL PROTECTED]>
wrote:

> The problem I see with #2 is that now we
> > are adding a requirement for xalan (or equivalent) to be present when
> ivy
> > runs. This doesn't work e.g. for the situation where ivy itself is used
> to
> > download xalan :-)
>
> Or you can use something else than xslt, like some java code. It's not
> pretty, but we already do this frequently in Ivy: rewrite in Java what
> some
> libraries already do, simply because we don't want to hit the chicken and
> egg problem. If the language is simple, writing some java code to parse it
> and write the ant script can be pretty straightforward.
>

I just realized that this is not really a problem, because we can delay the
XSLT step until when we run "ant" (i.e., make that step part of the
build.xml we generate), and <xslt> is a "core" ant task.

> What other issues need to be addressed before this could happen?
>
> Mainly test and documentation. By test I mean some automatic test, based
> on
> junit, and using a repo packaged with Ivy sources (probably accessed with
> file: URLs), as we do for almost everything in Ivy. This is the only way
> to
> get something included in Ivy core, because once included it has to be
> maintained, and maintaining stuff without automatic tests is a pain.
>

Yes I agree unit tests should be a requirement.

Regarding security, I've made an initial version of the XSLT. See attached
files for (3) sample "builder XML" for TestNG, (2) the XSLT, and (3) sample
build.xml output.

There is a tradeoff between security and flexibility. I decided to allow a
handful of basic ant tasks like <move>, <copy>, <zip>, <unzip>, etc. but
otherwise everything is "controlled".

Let me know if you think I made the right tradeoffs here.

Thanks,
-Archie

-- 
Archie L. Cobbs
<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- $Id$ -->
<builder-module>

    <!-- Property definitions are allowed -->
    <property name="name" value="testng"/>
    <property name="version" value="5.7"/>
    <property name="zipname" value="${name}-${version}"/>

    <!--
        The <resource> tag specifies some file to download, where to unpack it,
        and its expected checksum.

        The type (zip, tar, etc.) is determined automatically from the
        suffix, but it can also be explicitly overridden via "type"
        attribute, which can be one of: "none" (i.e., don't unpack),
        "zip", "tar", "tar.gz" (alias "tgz"), or "tar.bz2"

        The "dest" attribute specifies a subdirectory for unpacking the archive.

        The "url" and "sha1" attributes are self-explanatory and both required.

        Nested tags are optional; they become children of the <unzip>, etc.
    -->
    <resource dest="archive" url="http://testng.org/${zipname}.zip";
      sha1="2ea19275dc17453306f8bb780fe6ef6e9af7756b">
        <include name="${zipname}/src/main/**/*"/>
        <include name="${zipname}/src/jdk15/**/*"/>
        <include name="${zipname}/javadocs/**/*"/>
        <include name="${zipname}/*.jar"/>
    </resource>

    <!--
        Instructions that are reponsible for putting each artifact in place,
        where "in place" means copying it to "artifacts/[type]s/[artifact].[ext]".

        The only tags allowed as children of <build> are:

            <copy> <jar> <mkdir> <move> <tar>
            <unjar> <untar> <unwar> <unzip>
            <war> <zip>
    -->
    <build>

        <!-- jar  -->
        <move file="archive/${zipname}/${zipname}-jdk15.jar" tofile="artifacts/jars/${name}.jar"/>

        <!-- source -->
        <zip destfile="artifacts/sources/${name}.zip">
            <fileset dir="archive/${zipname}/src/main">
                <include name="**/*.java"/>
            </fileset>
            <fileset dir="archive/${zipname}/src/jdk15">
                <include name="**/*.java"/>
            </fileset>
        </zip>

        <!-- javadoc -->
        <zip destfile="artifacts/javadocs/javadoc.zip">
            <fileset dir="archive/${zipname}/javadocs"/>
        </zip>

    </build>

</builder-module>

<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id$ -->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

    <xsl:output encoding="UTF-8" method="xml" indent="yes" media-type="text/xml"/>

    <xsl:template match="/builder-module">
        <xsl:comment> GENERATED FILE - DO NOT EDIT </xsl:comment>
        <xsl:comment> Generated by $Id$ </xsl:comment>
        <project name="builder-project" default="build">
            <xsl:apply-templates select="property"/>
            <target name="resources">
                <xsl:apply-templates select="resource"/>
            </target>
            <target name="build" depends="resources">
                <mkdir dir="artifacts/jars"/>
                <mkdir dir="artifacts/sources"/>
                <mkdir dir="artifacts/javadocs"/>
                <!-- ...add some other common artifact types here... -->
                <xsl:apply-templates select="build/*"/>
            </target>
        </project>
    </xsl:template>

    <!-- Properties -->
    <xsl:template match="/builder-module/property">
        <xsl:copy-of select="."/>
    </xsl:template>

    <!-- The allowed build actions -->
    <xsl:template match="/builder-module/build/copy"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/jar"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/mkdir"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/move"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/tar"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/unjar"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/untar"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/unwar"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/unzip"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/war"><xsl:copy-of select="."/></xsl:template>
    <xsl:template match="/builder-module/build/zip"><xsl:copy-of select="."/></xsl:template>

    <!-- Resource definitions -->
    <xsl:template match="/builder-module/resource">

        <!-- Determine type of archive (automatically or via "type" attribute) -->
        <xsl:variable name="type">
            <xsl:choose>
                <xsl:when test="@type">
                    <xsl:value-of select="@type"/>
                </xsl:when>
                <xsl:when test="substring(@url, string-length(@url) - 3) = '.zip'">zip</xsl:when>
                <xsl:when test="substring(@url, string-length(@url) - 3) = '.tar'">tar</xsl:when>
                <xsl:when test="substring(@url, string-length(@url) - 3) = '.tgz'">tar.gz</xsl:when>
                <xsl:when test="substring(@url, string-length(@url) - 6) = '.tar.gz'">tar.gz</xsl:when>
                <xsl:when test="substring(@url, string-length(@url) - 7) = '.tar.bz2'">tar.bz2</xsl:when>
                <xsl:otherwise>
                    <xsl:message terminate="yes">
                        <xsl:value-of select="concat('ERROR: cannot determine type of archive: ', @url, '&#10;')"/>
                        <xsl:value-of select="'Please set the &quot;type&quot; attribute to one of: none, zip, tar, tar.gz, or tar.bz2.&#10;'"/>
                    </xsl:message>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <!-- Download resource -->
        <xsl:variable name="getdir" select="concat('directory.', generate-id())"/>
        <xsl:variable name="fileprop" select="concat('filename.', generate-id())"/>
        <xsl:variable name="filename" select="concat('${', $fileprop, '}')"/>
        <xsl:variable name="filepath" select="concat($getdir, '/', $filename)"/>
        <basename property="{$fileprop}" file="[EMAIL PROTECTED]"/>
        <mkdir dir="{$getdir}"/>
        <get src="[EMAIL PROTECTED]" dest="{$filepath}" verbose="true" usetimestamp="true"/>

        <!-- Verify checksum -->
        <xsl:variable name="csumprop" select="concat('checksum.', generate-id())"/>
        <xsl:variable name="csumvalue" select="concat('${', $csumprop, '}')"/>
        <checksum file="{$filepath}" algorithm="SHA" verifyproperty="{$csumprop}" property="[EMAIL PROTECTED]"/>
        <fail message="checksum verification for {$filename} failed!">
            <condition>
                <isfalse value="{$csumvalue}"/>
            </condition>
        </fail>
        <echo message="successfully verified checksum of {$filename}"/>

        <!-- Unpack -->
        <mkdir dir="[EMAIL PROTECTED]"/>
        <xsl:choose>
            <xsl:when test="$type = 'none'">
                <move file="{$filepath}" todir="[EMAIL PROTECTED]"/>
            </xsl:when>
            <xsl:when test="$type = 'zip'">
                <unzip src="{$filepath}" dest="[EMAIL PROTECTED]">
                    <fileset dir=".">
                        <xsl:copy-of select="*"/>
                    </fileset>
                </unzip>
            </xsl:when>
            <xsl:when test="starts-with($type, 'tar')">
                <xsl:variable name="compression">
                    <xsl:choose>
                        <xsl:when test="$type = 'tar.gz'">gzip</xsl:when>
                        <xsl:when test="$type = 'tar.bz2'">bzip2</xsl:when>
                        <xsl:otherwise>none</xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                <untar src="{$filepath}" dest="[EMAIL PROTECTED]">
                    <fileset dir=".">
                        <xsl:copy-of select="*"/>
                    </fileset>
                </untar>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate="yes">ERROR: internal error: impossible case&#10;</xsl:message>
            </xsl:otherwise>
        </xsl:choose>

        <!-- Delete download directory -->
        <delete dir="{$getdir}"/>
    </xsl:template>

    <!-- Ignore anything unexpected -->
    <xsl:template match="@*|node()"/>
</xsl:transform>

<?xml version="1.0" encoding="UTF-8"?>
<!-- GENERATED FILE - DO NOT EDIT -->
<!-- Generated by $Id$ -->
<project name="builder-project" default="build">
  <property name="name" value="testng"/>
  <property name="version" value="5.7"/>
  <property name="zipname" value="${name}-${version}"/>
  <target name="resources">
    <basename property="filename.id2245134" file="file:///home/archie/home.svn/hogwash/oss/testng/5.7/src/sources/testng-5.7.zip"/>
    <mkdir dir="directory.id2245134"/>
    <get src="file:///home/archie/home.svn/hogwash/oss/testng/5.7/src/sources/testng-5.7.zip" dest="directory.id2245134/${filename.id2245134}" verbose="true" usetimestamp="true"/>
    <checksum file="directory.id2245134/${filename.id2245134}" algorithm="SHA" verifyproperty="checksum.id2245134" property="2ea19275dc17453306f8bb780fe6ef6e9af7756b"/>
    <fail message="checksum verification for ${filename.id2245134} failed!">
      <condition>
        <isfalse value="${checksum.id2245134}"/>
      </condition>
    </fail>
    <echo message="verified checksum of ${filename.id2245134}"/>
    <mkdir dir="archive"/>
    <unzip src="directory.id2245134/${filename.id2245134}" dest="archive">
      <fileset dir=".">
        <include name="${zipname}/src/main/**/*"/>
        <include name="${zipname}/src/jdk15/**/*"/>
        <include name="${zipname}/javadocs/**/*"/>
        <include name="${zipname}/*.jar"/>
      </fileset>
    </unzip>
    <delete dir="directory.id2245134"/>
  </target>
  <target name="build" depends="resources">
    <mkdir dir="artifacts/jars"/>
    <mkdir dir="artifacts/sources"/>
    <mkdir dir="artifacts/javadocs"/>
    <move file="archive/${zipname}/${zipname}-jdk15.jar" tofile="artifacts/jars/${name}.jar"/>
    <zip destfile="artifacts/sources/${name}.zip">
            <fileset dir="archive/${zipname}/src/main">
                <include name="**/*.java"/>
            </fileset>
            <fileset dir="archive/${zipname}/src/jdk15">
                <include name="**/*.java"/>
            </fileset>
        </zip>
    <zip destfile="artifacts/javadocs/javadoc.zip">
            <fileset dir="archive/${zipname}/javadocs"/>
        </zip>
  </target>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to