Skip to content

Commit

Permalink
Build: Commonize build files for XSL applications and libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Feb 24, 2022
1 parent c5dafd8 commit f020c87
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 5,762 deletions.
45 changes: 0 additions & 45 deletions build.properties

This file was deleted.

239 changes: 14 additions & 225 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,240 +7,29 @@
<property name="version" value="1.0"/>
<property name="copyright" value="Copyright (C) 2019-2022 xslet project"/>
<property name="license" value="MIT License"/>
<property name="prodtype" value="library"/>

<property file="build.properties"/>


<target name="setup"
description="Make directories and download modules used for build.">
<antcall target="setup:dirs"/>
<antcall target="setup:scss"/>
<antcall target="setup:js"/>
<antcall target="setup:deps"/>
</target>

<target name="setup:dirs">
<mkdir dir="${dir.src.xsl}/lib"/>
<mkdir dir="${dir.src.xsl}/ext"/>
<mkdir dir="${dir.src.scss}"/>
<mkdir dir="${dir.src.js}"/>
<mkdir dir="${dir.dist}"/>
<mkdir dir="${dir.test}/unit"/>
<mkdir dir="${dir.docs}/test"/>
<mkdir dir="${dir.docs}/api"/>
<mkdir dir="${dir.work.dl}"/>
<mkdir dir="${dir.work.lib}"/>
<mkdir dir="${dir.work.bin}"/>
<mkdir dir="${dir.deploy}"/>
</target>

<target name="setup:scss">
<touch file="${dir.src.scss}/xslutil.scss"/>
</target>

<target name="setup:js">
<copy todir="${dir.src.js}">
<fileset dir="${dir.res.js}"/>
</copy>
<exec executable="${npm.cmd}">
<arg line="${npm.arg}"/>
<arg line="install"/>
<arg line="--prefix ${dir.src.js}"/>
</exec>
</target>

<target name="setup:deps">
<!-- Dependencies for this project -->
<target name="setup:deps" depends="setup:deps:base">
<antcall target="setup:xsldoc"/>
<antcall target="setup:saxon"/>
<antcall target="setup:tomcat"/>
</target>

<target name="setup:xsldoc">
<property name="zip" location="${dir.work.dl}/${pkg.xsldoc}.zip"/>
<property name="unzip" location="${dir.xsldoc}/.."/>
<get src="${url.xsldoc.download}" dest="${zip}"/>
<unzip src="${zip}" dest="${unzip}"/>
</target>
<property name="dep.xsldoc.version" value="1.0.0"/>

<target name="setup:saxon">
<property name="zip" location="${dir.work.dl}/${pkg.saxon}.zip"/>
<property name="unzip" location="${dir.saxon}"/>
<get src="${url.saxon.download}" dest="${zip}"/>
<unzip src="${zip}" dest="${unzip}"/>
</target>

<target name="setup:tomcat">
<property name="zip" location="${dir.work.dl}/${pkg.tomcat}.zip"/>
<property name="unzip" location="${dir.work.bin}"/>
<get src="${url.tomcat.download}" dest="${zip}"/>
<target name="setup:xsldoc">
<property name="pkg" value="xsldoc-${dep.xsldoc.version}"/>
<property name="dir" value="${dir.work.xsl}/${pkg}"/>
<property name="url" value="https://github.com/xslet/xsldoc/archive/${dep.xsldoc.version}.zip"/>
<property name="zip" location="${dir.work.dl}/${pkg}.zip"/>
<property name="unzip" location="${dir}/.."/>
<get src="${url}" dest="${zip}"/>
<unzip src="${zip}" dest="${unzip}"/>
<chmod perm="ugo+rx" dir="${dir.tomcat}/bin" includes="**/*.sh"/>
</target>


<target name="build"
description="Execute `clean`, `merge` and `deploy` tasks.">
<antcall target="clean"/>
<antcall target="merge"/>
<!--
<antcall target="build:scss"/>
<antcall target="build:js"/>
-->
<antcall target="deploy"/>
</target>


<target name="clean"
description="Clean files in `dist` directory.">
<delete>
<fileset dir="${dir.dist}" includes="**/*"/>
<fileset dir="${dir.deploy}" includes="**/*"/>
<fileset dir="${dir.docs}/test" includes="**/*"/>
<fileset dir="${dir.docs}/api" includes="**/*"/>
</delete>
<exec executable="find" os="Mac OS X">
<arg line=". -name .DS_Store -delete"/>
</exec>
</target>


<target name="merge"
description="Merge XSL files into a distributable file.">
<delete>
<fileset dir="${dir.src.xsl}/ext" includes="**/*"/>
</delete>
<antcall target="merge:xsl-for-doc"/>
<antcall target="merge:xsl-for-dist"/>
<antcall target="merge:xsl-for-test"/>
</target>

<target name="merge:xsl-for-doc">
<path id="extjars">
<fileset dir="${dir.work.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<java classname="net.sf.saxon.Transform">
<arg line="-o:${dir.docs}" />
<arg line="-s:${dir.src.xsl}" />
<arg line="-xsl:${dir.res.xsl}/merge-for-doc.xsl" />
<arg line="-strip:all" />
<classpath refid="extjars" />
</java>
</target>

<target name="merge:xsl-for-dist">
<path id="extjars">
<fileset dir="${dir.work.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<java classname="net.sf.saxon.Transform">
<arg line="-o:${dir.dist}" />
<arg line="-s:${dir.src.xsl}" />
<arg line="-xsl:${dir.res.xsl}/merge-for-dist.xsl" />
<arg line="-strip:all" />
<classpath refid="extjars" />
</java>
</target>

<target name="merge:xsl-for-test">
<path id="extjars">
<fileset dir="${dir.work.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<java classname="net.sf.saxon.Transform">
<arg line="-o:${dir.test}/unit" />
<arg line="-s:${dir.src.xsl}" />
<arg line="-xsl:${dir.res.xsl}/merge-for-test.xsl" />
<arg line="-strip:all" />
<classpath refid="extjars" />
</java>
</target>

<target name="build:scss">
<property name="prefix" value="${dir.src.js}" />
<exec executable="${npm.cmd}">
<arg line="${npm.arg}" />
<arg line="run sass:build" />
<arg line="--prefix ${prefix}" />
</exec>
</target>

<target name="build:js">
<property name="prefix" value="${dir.src.js}" />
<exec executable="${npm.cmd}">
<arg line="${npm.arg}" />
<arg line="run js:build" />
<arg line="--prefix ${prefix}" />
</exec>
</target>


<target name="deploy"
description="Deploy distributable files and test files to Tomcat.">
<copy todir="${dir.docs}/test">
<fileset dir="${dir.test}"/>
</copy>
<copy todir="${dir.docs}/api/xsldoc">
<fileset dir="${dir.xsldoc}/dist"/>
</copy>
<copy todir="${dir.docs}/test/unit">
<fileset dir="${dir.res.doc}"/>
</copy>
<copy todir="${dir.deploy}">
<fileset dir="${dir.docs}"/>
</copy>
</target>


<target name="watch"
description="Watch source files updated, then deploy.">
<retry retrycount="1000000">
<antcall target="watch:wait-and-build"/>
</retry>
</target>

<target name="watch:wait-and-build">
<waitfor>
<not>
<uptodate targetfile="${dir.dist}/${product}">
<srcfiles dir="${dir.src}" includes="**/*"/>
<srcfiles dir="${dir.test}" includes="**/*"/>
</uptodate>
</not>
</waitfor>
<antcall target="build"/>
<touch file="${dir.dist}/${product}"/>
<fail/>
</target>


<target name="start"
description="Start tomcat.">
<condition property="cmd" value="startup.bat" else="startup.sh">
<os family="windows"/>
</condition>
<exec executable="${dir.tomcat}/bin/${cmd}"/>
</target>


<target name="stop"
description="Stop tomcat.">
<condition property="cmd" value="shutdown.bat" else="shutdown.sh">
<os family="windows"/>
</condition>
<exec executable="${dir.tomcat}/bin/${cmd}"/>
</target>


<condition property="npm.cmd" value="cmd" else="npm">
<os family="windows"/>
</condition>

<condition property="npm.arg" value="/c npm" else="">
<os family="windows"/>
</condition>
<import file="res/ant/build.targets.xml"/>
<import file="res/ant/build.dependencies.xml"/>
<import file="res/ant/build.directories.xml"/>

</project>
2 changes: 1 addition & 1 deletion dist/xslutil.xsl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/api/xsldoc/xslutil.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!-- xslutil.xsl 1.0 Copyright (C) 2019-2022 xslet project MIT License --><xsl:stylesheet xmlns:ut="https://github.com/xslet/2020/xslutil" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:param name="ut:apos">'</xsl:param><xsl:param name="ut:quot">"</xsl:param><xsl:param name="ut:true" select="string(true())"/><xsl:param name="ut:unknown_namespace">&#x86;-&#x87;</xsl:param><xsl:template name="ut:get_xsl_url"><xsl:param name="pi" select="/processing-instruction('xml-stylesheet')"/><xsl:variable name="QUOT">"</xsl:variable><xsl:variable name="APOS">'</xsl:variable><xsl:variable name="s1" select="substring-after($pi, 'href')"/><xsl:if test="normalize-space(substring-before($s1, '=')) = ''"><xsl:variable name="s2" select="substring-after($s1, '=')"/><xsl:choose><xsl:when test="substring($s2, 1, 1) = $QUOT"><xsl:value-of select="translate(substring-before(substring-after($s2, $QUOT), $QUOT), '\', '/')"/></xsl:when><xsl:when test="substring($s2, 1, 1) = $APOS"><xsl:value-of select="translate(substring-before(substring-after($s2, $APOS), $APOS), '\', '/')"/></xsl:when><xsl:otherwise><xsl:variable name="s3" select="normalize-space($s2)"/><xsl:choose><xsl:when test="substring($s3, 1, 1) = $QUOT"><xsl:value-of select="translate(substring-before(substring-after($s2, $QUOT), $QUOT), '\', '/')"/></xsl:when><xsl:when test="substring($s3, 1, 1) = $APOS"><xsl:value-of select="translate(substring-before(substring-after($s2, $APOS), $APOS), '\', '/')"/></xsl:when></xsl:choose></xsl:otherwise></xsl:choose></xsl:if></xsl:template><xsl:template name="ut:count"><xsl:param name="string"/><xsl:param name="target"/><xsl:choose><xsl:when test="string-length($string) = 0">0</xsl:when><xsl:when test="string-length($target) = 0">0</xsl:when><xsl:when test="starts-with($string, $target)"><xsl:variable name="_count"><xsl:variable name="_next_bgn" select="string-length($target) + 1"/><xsl:call-template name="ut:count"><xsl:with-param name="string" select="substring($string, $_next_bgn)"/><xsl:with-param name="target" select="$target"/></xsl:call-template></xsl:variable><xsl:value-of select="$_count + 1"/></xsl:when><xsl:otherwise><xsl:call-template name="ut:count"><xsl:with-param name="string" select="substring($string, 2)"/><xsl:with-param name="target" select="$target"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:get_namespace_uri"><xsl:param name="prefix"/><xsl:variable name="_ns" select="namespace::*[name() = $prefix]"/><xsl:choose><xsl:when test="string-length($_ns) &gt; 0"><xsl:value-of select="$_ns"/></xsl:when><xsl:otherwise><xsl:variable name="_ns2" select="namespace-uri(//*[name() = concat($prefix,':',local-name())])"/><xsl:choose><xsl:when test="string-length($_ns2) &gt; 0"><xsl:value-of select="$_ns2"/></xsl:when><xsl:when test="string-length($prefix) &gt; 0"><xsl:value-of select="$ut:unknown_namespace"/></xsl:when></xsl:choose></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:validate"><xsl:param name="string"/><xsl:param name="forbidden"/><xsl:param name="default"/><xsl:variable name="_s" select="translate($string, $forbidden, '')"/><xsl:choose><xsl:when test="string-length($_s) = string-length($string)"><xsl:value-of select="$string"/></xsl:when><xsl:otherwise><xsl:value-of select="$default"/></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:replace"><xsl:param name="string"/><xsl:param name="target"/><xsl:param name="replacement"/><xsl:variable name="_lenT" select="string-length($target)"/><xsl:choose><xsl:when test="$_lenT = 0"><xsl:value-of select="$string"/></xsl:when><xsl:when test="starts-with($string, $target)"><xsl:value-of select="$replacement"/><xsl:call-template name="ut:replace"><xsl:with-param name="string" select="substring($string, $_lenT + 1)"/><xsl:with-param name="target" select="$target"/><xsl:with-param name="replacement" select="$replacement"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:variable name="_before" select="substring-before($string, $target)"/><xsl:choose><xsl:when test="$_before = ''"><xsl:value-of select="$string"/></xsl:when><xsl:otherwise><xsl:variable name="_lenB" select="string-length($_before)"/><xsl:variable name="_posA" select="$_lenB + $_lenT + 1"/><xsl:value-of select="$_before"/><xsl:value-of select="$replacement"/><xsl:call-template name="ut:replace"><xsl:with-param name="string" select="substring($string, $_posA)"/><xsl:with-param name="target" select="$target"/><xsl:with-param name="replacement" select="$replacement"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:is_absolute_url"><xsl:param name="url"/><xsl:choose><xsl:when test="string-length($url) = 0"><xsl:value-of select="$ut:true"/></xsl:when><xsl:when test="contains($url, ':')"><xsl:value-of select="$ut:true"/></xsl:when><xsl:when test="starts-with($url, '/')"><xsl:value-of select="$ut:true"/></xsl:when></xsl:choose></xsl:template><xsl:template name="ut:ends_with"><xsl:param name="string"/><xsl:param name="suffix"/><xsl:variable name="_len1" select="string-length($suffix)"/><xsl:choose><xsl:when test="$_len1 = 0"><xsl:value-of select="$ut:true"/></xsl:when><xsl:otherwise><xsl:variable name="_len0" select="string-length($string)"/><xsl:variable name="_len2" select="$_len0 - $_len1"/><xsl:variable name="_ends" select="substring($string, $_len2 + 1)"/><xsl:if test="$_ends = $suffix"><xsl:value-of select="$ut:true"/></xsl:if></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:get_dir_from_url"><xsl:param name="url"/><xsl:choose><xsl:when test="not(contains($url, '/'))">.</xsl:when><xsl:otherwise><xsl:call-template name="ut:_get_dir_from_url_r"><xsl:with-param name="url" select="$url"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:_get_dir_from_url_r"><xsl:param name="url"/><xsl:value-of select="substring-before($url, '/')"/><xsl:variable name="suburl" select="substring-after($url, '/')"/><xsl:if test="string-length($suburl) &gt; 0"><xsl:variable name="subdir"><xsl:call-template name="ut:_get_dir_from_url_r"><xsl:with-param name="url" select="$suburl"/></xsl:call-template></xsl:variable><xsl:if test="string-length($subdir) &gt; 0"><xsl:value-of select="concat('/', $subdir)"/></xsl:if></xsl:if></xsl:template><xsl:template name="ut:repeat"><xsl:param name="string"/><xsl:param name="count"/><xsl:if test="$count &gt; 0"><xsl:value-of select="$string"/><xsl:call-template name="ut:repeat"><xsl:with-param name="string" select="$string"/><xsl:with-param name="count" select="$count - 1"/></xsl:call-template></xsl:if></xsl:template><xsl:template name="ut:trim_start"><xsl:param name="string"/><xsl:param name="target"/><xsl:variable name="_lenS" select="string-length($string)"/><xsl:variable name="_lenT" select="string-length($target)"/><xsl:choose><xsl:when test="$_lenS = 0"/><xsl:when test="$_lenT = 0"><xsl:variable name="_first" select="substring($string, 1, 1)"/><xsl:choose><xsl:when test="normalize-space($_first) = ''"><xsl:call-template name="ut:trim_start"><xsl:with-param name="string" select="substring($string, 2)"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><xsl:choose><xsl:when test="starts-with($string, $target)"><xsl:call-template name="ut:trim_start"><xsl:with-param name="string" select="substring($string, $_lenT + 1)"/><xsl:with-param name="target" select="$target"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:trim_end"><xsl:param name="string"/><xsl:param name="target"/><xsl:variable name="_lenS" select="string-length($string)"/><xsl:variable name="_lenT" select="string-length($target)"/><xsl:choose><xsl:when test="$_lenS = 0"/><xsl:when test="$_lenT = 0"><xsl:variable name="_last" select="substring($string, $_lenS, 1)"/><xsl:choose><xsl:when test="normalize-space($_last) = ''"><xsl:call-template name="ut:trim_end"><xsl:with-param name="string" select="substring($string, 1, $_lenS - 1)"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><xsl:choose><xsl:when test="substring($string, $_lenS - $_lenT + 1) = $target"><xsl:call-template name="ut:trim_end"><xsl:with-param name="string" select="substring($string, 1, $_lenS - $_lenT)"/><xsl:with-param name="target" select="$target"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="ut:trim"><xsl:param name="string"/><xsl:param name="target"/><xsl:variable name="_str"><xsl:call-template name="ut:trim_start"><xsl:with-param name="string" select="$string"/><xsl:with-param name="target" select="$target"/></xsl:call-template></xsl:variable><xsl:call-template name="ut:trim_end"><xsl:with-param name="string" select="$_str"/><xsl:with-param name="target" select="$target"/></xsl:call-template></xsl:template></xsl:stylesheet>
Loading

0 comments on commit f020c87

Please sign in to comment.