Cross-Browser.com

X Library Forums

You are not logged in.

Announcement

New user registration is currently disabled.

#1 December 18, 2009 1:36:21 am

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Ant Build Files for X

Ant macros for building X library files. In "build.xml" you can see how I'm using the macros.

build.xml


<?xml version="1.0"?>
<!--
  build.xml v1.0
  Copyright 2009-2010 Michael Foster (Cross-Browser.com)
  Distributed under the terms of the GNU LGPL
-->

<project name="x-library-ant-build" default="help" basedir=".">

  <import file="tools/x-library-ant-macros.xml"/>

                                   <!-- * -->

  <!-- Build all library files. -->
  <target name="all" depends="lib, app" description="Build all library files."/>

  <!-- Build all general-purpose library files. -->
  <target name="lib" depends="x" description="Build all general-purpose library files."/>

  <!-- Build all application-specific library files. -->
  <target name="app" depends="xpersistentdisplay-xlib, xfenster-xlib" description="Build all application-specific library files."/>

  <target name="help">
    <fail message="You must specify a target. Try 'ant -p'."/>
  </target>

                                   <!-- * -->

  <!--
    The "x.js" general-purpose library file contains some of the most used X functions.
  -->
  <target name="x" description="Build 'x.js'.">
    <x-initialize prj="x"/>
    <x-aggregate prj="x" options="-app -dep">
      xGetElementById, xGetElementsByTagName, xGetElementsByClassName,
      xMoveTo, xLeft, xTop, xPageX, xPageY, xScrollLeft, xScrollTop, xHasPoint,
      xResizeTo, xWidth, xHeight, xClientWidth, xClientHeight,
      xStyle, xOpacity, xGetComputedStyle, xCamelize,
      xDef, xStr, xNum, xLibrary,
      xEachE, xEachN, xOffset,
      xAddEventListener, xRemoveEventListener, xEvent, xStopPropagation, xPreventDefault
    </x-aggregate>
    <x-compress prj="x"/>
  </target>

  <!--
    As an example of building an application-specific library file, this task
    builds a library file for use by the xFenster demos. It also is an
    example of using x-preprocess to implement obfuscation.
  -->
  <target name="xfenster-xlib" description="Build 'examples/xfenster-xlib.js'.">
    <x-initialize prj="xfenster-xlib"/>
    <filelist id="xfenster-xag-files" dir="${basedir}/examples">
      <file name="xfenster-demo.php"/> 
    </filelist>
    <x-aggregate prj="xfenster-xlib" input="xfenster-xag-files"/>
    <x-preprocess prj="xfenster-xlib" input="obf-demo"/>
    <x-compress prj="xfenster-xlib" output="examples/xfenster-xlib.js"/>
  </target>

  <!--
    As an example of building an application-specific library file when the
    dependencies are known, this task builds a library file for use by the
    xPersistentDisplay demo.
  -->
  <target name="xpersistentdisplay-xlib" description="Build 'examples/xpersistentdisplay-xlib.js'.">
    <x-initialize prj="xpersistentdisplay-xlib"/>
    <x-aggregate prj="xpersistentdisplay-xlib" options="-app -dep">
      xGetElementById, xGetElementsByTagName, xGetElementsByClassName,
      xAddEventListener, xEachN, xCookie, xPersistentDisplay
    </x-aggregate>
    <x-compress prj="xpersistentdisplay-xlib" output="examples/xpersistentdisplay-xlib.js"/>
  </target>

                                   <!-- * -->

  <!--
    This is used as an example of using x-preprocess to implement obfuscation.
  -->
  <filelist id="obf-demo" dir="${basedir}" files="obf-demo.xpp"/>

</project>



x-library-ant-macros.xml


<?xml version="1.0"?>
<!--
  x-library-ant-macros.xml v1.1
  Copyright 2009-2011 Michael Foster (Cross-Browser.com)
  Distributed under the terms of the GNU LGPL
-->

<project name="x-library-ant-macros">

  <description>Ant macros for building X Library projects.</description>

  <!-- In your build script, "x.dir" must be defined, and these properties may be overridden. -->
  <property name="x.tmp.dir" value="tmp"/> <!-- Directory for intermediate files. -->
  <property name="x.xag.exe" value="${x.dir}/tools/xag.exe"/> <!-- Pathname of XAG executable file. -->
  <property name="x.xag.lib" value="${x.dir}/lib/"/> <!-- Directory containing X Library files. Requires a trailing slash. -->
  <property name="x.xpp.exe" value="${x.dir}/tools/xpp.exe"/> <!-- Pathnames of XPP  and YUICompressor executable files. -->
  <property name="x.cmp.jar" value="/Program Files/yuicompressor/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar"/>

  <!--
  <property name="x.tmp.dir" value="tmp"/>
  <property name="x.xag.exe" value="tools/xag"/>
  <property name="x.xag.lib" value="lib/"/>
  <property name="x.xpp.exe" value="tools/xpp"/>
  <property name="x.cmp.jar" value="/Program Files/yuicompressor/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar"/>
  -->

  <!-- Initialize - prepare to build a project.
    This macro creates project-specific properties, creates the tmp directory
    if not present, and deletes old tmp files for the current project if present.
  -->
  <macrodef name="x-initialize">
    <attribute name="prj" default="default"/>
    <sequential>
      <!-- Create project-specific file name properties. They must not be overridden. -->
      <property name="x.@{prj}.xag.out" value="${x.tmp.dir}/@{prj}.xago"/>
      <property name="x.@{prj}.xpp.out" value="${x.tmp.dir}/@{prj}.xppo"/>
      <echo message="Building @{prj} ..."/>
      <!-- Prepare the tmp directory. -->
      <mkdir dir="${x.tmp.dir}"/>
      <delete>
        <fileset dir="${x.tmp.dir}" includes="@{prj}.*"/>
      </delete>
    </sequential>
  </macrodef>

  <!-- Aggregate - create a custom X Library file.
    Prerequsite: x-initialize.
    This macro creates a XAG configuration file using the values of its attributes.
    An optional list of symbols can be provided as the contents of the x-aggregate
    element. This text is saved in a file and fed to XAG as another app file.
    The default XAG options are for building application-specific libraries with
    application code not included ("-app +dep"). When building general purpose
    libraries, use options="-app -dep".
  -->
  <macrodef name="x-aggregate">
    <attribute name="prj" default="default"/>
    <attribute name="input" default="empty-filelist"/> <!-- refid -->
    <attribute name="output" default="${x.@{prj}.xag.out}"/>
    <attribute name="options" default="-app +dep"/>
    <attribute name="libpath" default="${x.xag.lib}"/>
    <text name="symbols" optional="true"/>
    <sequential>
      <!-- Create project-specific file name properties. They must not be overridden. -->
      <property name="x.@{prj}.xag.cfg" value="${x.tmp.dir}/@{prj}.xag"/>
      <property name="x.@{prj}.xag.sym" value="${x.tmp.dir}/@{prj}.sym"/>
      <!-- Create config file. -->
      <pathconvert refid="@{input}" property="x.@{input}.xag.files" setonempty="true" pathsep="${line.separator}"/>
      <echo file="${x.@{prj}.xag.cfg}" append="false">
; @{prj}
options @{options}
output @{output}
libpath @{libpath}
appfiles
${x.@{prj}.xag.sym}
${x.@{input}.xag.files}</echo>
      <!-- Create symbols file. -->
      <echo file="${x.@{prj}.xag.sym}" append="false">@{symbols}</echo>
      <!-- Run XAG. -->
      <apply executable="${x.xag.exe}" relative="true" parallel="true" failonerror="true">
        <srcfile/>
        <filelist dir="." files="${x.@{prj}.xag.cfg}"/> 
      </apply>
    </sequential>
  </macrodef>

  <!-- Preprocess - preprocess the project with XPP.
    The input to this stage is the optional output from x-aggregate as well as
    an optional file-type resource collection.
  -->
  <macrodef name="x-preprocess">
    <attribute name="prj" default="default"/>
    <attribute name="input" default="empty-filelist"/> <!-- refid -->
    <attribute name="output" default="${x.@{prj}.xpp.out}"/>
    <sequential>
      <!-- If XAG output exists, use it as input. -->
      <condition property="x.@{prj}.xpp.xag" value="${x.@{prj}.xag.out}" else="">
        <available file="${x.@{prj}.xag.out}"/>
      </condition>
      <!-- Run XPP. -->
      <apply executable="${x.xpp.exe}" relative="true" parallel="true" failonerror="true">
        <!-- output -->
        <arg value="@{output}"/>
        <!-- input -->
        <srcfile/>
        <resources refid="@{input}"/>
        <arg value="${x.@{prj}.xpp.xag}"/>
      </apply>
    </sequential>
  </macrodef>

  <!-- Compress. - compress the project with YUICompressor.
    The input to this stage is either: the input attribute or the x-preprocess
    output or the x-aggregate output.
  -->
  <macrodef name="x-compress">
    <attribute name="prj" default="default"/>
    <attribute name="type" default="js"/> <!-- 'js' or 'css'. -->
    <attribute name="input" default=""/> <!-- filename -->
    <attribute name="output" default="@{prj}.@{type}"/>
    <attribute name="options" default=""/>
    <sequential>
      <echo message="Compressing to @{output}"/>
      <!-- If input is "" and XPP output exists, use it as input. -->
      <condition property="x.@{prj}.cmp.xpp" value="${x.@{prj}.xpp.out}" else="">
        <and>
          <equals arg1="@{input}" arg2=""/>
          <available file="${x.@{prj}.xpp.out}"/>
        </and>
      </condition>
      <!-- If input is "" and cmp.xpp is "" and XAG output exists, use it as input. -->
      <condition property="x.@{prj}.cmp.xag" value="${x.@{prj}.xag.out}" else="">
        <and>
          <equals arg1="@{input}" arg2=""/>
          <equals arg1="${x.@{prj}.cmp.xpp}" arg2=""/>
          <available file="${x.@{prj}.xag.out}"/>
        </and>
      </condition>
      <!-- Run YUICompressor. -->
      <apply executable="java" relative="true" parallel="true" failonerror="true">
        <arg value="-jar"/>
        <arg value="${x.cmp.jar}"/>
        <arg line="--type @{type} @{options} -o"/>
        <!-- output -->
        <arg value="@{output}"/>
        <!-- input -->
        <srcfile/>
        <filelist dir="." files="@{input}"/>
        <arg line="${x.@{prj}.cmp.xpp} ${x.@{prj}.cmp.xag}"/>
      </apply>
    </sequential>
  </macrodef>

  <!--
    This empty filelist is used as a default input attribute in the above macros.
  -->
  <filelist id="empty-filelist" files=""/>

<!-- Notes:

1. These macros can be ran separately, or chained into a 3 stage build process:
  - Resolve library dependencies and aggregate them into one file with XAG.
  - Preprocess the file with XPP.
  - Compress the file with YUICompressor.

2. You can pass the ID of any file-type resource collection (<resources>, <files>,
<filelist> or <fileset>) as the input attribute to x-aggregate or x-preprocess
However, <fileset> and <files> do not allow you to control the order in which
the files are included. Using <resources> (and it seems,  <filelist> also),
you can control the order in which the files are included.
    

v1.1, 24Jan2011: Added default values for 'prj' attributes.
-->
</project>

Last edited by MikeFoster (February 15, 2011 2:53:46 pm)

Offline

 

#2 December 18, 2009 10:20:21 am

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Re: Ant Build Files for X

These build files (after a little more tweaking and testing) will be included in the upcoming X release.

Offline

 

#3 January 12, 2010 3:52:21 pm

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Re: Ant Build Files for X

These files were part of the 4.19 release. I've made a few changes since then and have updated the post above with the latest versions of these files.

Offline

 

#4 January 24, 2010 5:43:21 pm

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Re: Ant Build Files for X

I made some improvements to the build files and have updated the post above.

Offline

 

#5 February 13, 2010 10:43:08 pm

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Re: Ant Build Files for X

Bug fix for x-compress - on linux, yuicompressor would throw an exception on an empty-string argument that was not the last argument.

Offline

 

#6 February 23, 2010 5:34:08 pm

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Re: Ant Build Files for X

Now at version 1.0.

Offline

 

#7 February 15, 2011 2:55:10 pm

MikeFoster
Administrator
From: Alabama, USA
Registered: April 27, 2007
Posts: 874
Website

Re: Ant Build Files for X

Now at version 1.1.

Offline

 

Board footer

Powered by PunBB 1.2.15
Copyright © 2002–2005 Rickard Andersson

Expand Restore Select Format Eval Load