<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Hacking JSpecView: Creating an HTML Test Harness</title>
    <link>http://depth-first.com/articles/2008/01/28/hacking-jspecview-creating-an-html-test-harness</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Hacking JSpecView: Creating an HTML Test Harness</title>
      <description>&lt;p&gt;&lt;a href="http://jspecview.sourceforge.net/"&gt;&lt;img src="http://depth-first.com/demo/20080123/jspecview.png" align="right"&gt;&lt;/img&gt;&lt;/a&gt;The &lt;a href="http://depth-first.com/articles/2008/01/23/hacking-jspecview-getting-organized-with-ant"&gt;previous article in this series&lt;/a&gt; discussed the construction of an Ant build environment for &lt;a href="http://jspecview.sourceforge.net/"&gt;JSpecView&lt;/a&gt;. This article will show how to use Ant to build an HTML harness to test the resulting Applet and jarfile.&lt;/p&gt;

&lt;h4&gt;Availability of Source Code&lt;/h4&gt;

&lt;p&gt;Robert Lancashire, the lead JSpecView developer, has kindly agreed to host the complete source code for this series of tutorials on the &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=161398&amp;amp;package_id=260592"&gt;JSpecView SourceForge project page&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Overview&lt;/h4&gt;

&lt;p&gt;Our goal for this session is to create an Ant task that will assemble a directory of HTML pages for testing the JSpecView applet. To do this, we'll add a new &lt;tt&gt;demo&lt;/tt&gt; task and some supporting files.&lt;/p&gt;

&lt;h4&gt;Editing the build.xml File&lt;/h4&gt;

&lt;p&gt;The main change we'll make is to add the &lt;tt&gt;demo&lt;/tt&gt; task itself:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;target&lt;/span&gt; &lt;span class="attribute"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;demo&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;depends&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;mkdir&lt;/span&gt; &lt;span class="attribute"&gt;dir&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;${demo}&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;copy&lt;/span&gt; &lt;span class="attribute"&gt;todir&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;${demo}&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
    &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;fileset&lt;/span&gt; &lt;span class="attribute"&gt;dir&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;${resources-html}&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;copy&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;copy&lt;/span&gt; &lt;span class="attribute"&gt;file&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;${build-lib}/${unix-name}-${version}.jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="attribute"&gt;tofile&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;${demo}/lib/${unix-name}.jar&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;target&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This task creates a &lt;strong&gt;demo&lt;/strong&gt; directory and copies into it the contents of a new &lt;strong&gt;resources/html&lt;/strong&gt; directory, along with the jarfile built with the &lt;tt&gt;jar&lt;/tt&gt; task.&lt;/p&gt;

&lt;p&gt;Other changes to the &lt;strong&gt;build.xml&lt;/strong&gt; file are necessary. In the interest of brevity, they have been omitted. Those interested should &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=161398&amp;package_id=260592"&gt;download the source package&lt;/a&gt; to be available shortly.&lt;/p&gt;

&lt;h4&gt;Creating the &lt;strong&gt;resources&lt;/strong&gt; Directory&lt;/h4&gt;

&lt;p&gt;Think of the &lt;strong&gt;resources&lt;/strong&gt; directory as a place to hold non-Java files that will get used by our Ant tasks. Our first addition to this directory will be a directory called &lt;/strong&gt;html&lt;/strong&gt;. Here, we'll create a new directory called &lt;strong&gt;demo1&lt;/strong&gt;. It will contain an HTML document with an embedded JSpecView applet (&lt;strong&gt;index.html&lt;/strong&gt;), along with a JCAMP-DX file (&lt;strong&gt;netanilineH.jdx&lt;/strong&gt;) and the excellent &lt;a href="http://depth-first.com/articles/2007/11/02/eolas-and-jactivating-working-around-a-workaround"&gt;JActivating&lt;/a&gt; JavaScript tool.&lt;/p&gt;

&lt;h4&gt;Using the &lt;tt&gt;demo&lt;/tt&gt; Task&lt;/h4&gt;

&lt;p&gt;We can run our new &lt;tt&gt;demo&lt;/tt&gt; task just like the others:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;tt&gt;
$ ant demo
Buildfile: build.xml

init:
    [mkdir] Created dir: /home/rich/devel/proj/jspecview/build
    [mkdir] Created dir: /home/rich/devel/proj/jspecview/build/classes
    [mkdir] Created dir: /home/rich/devel/proj/jspecview/build/lib

compile:
    [javac] Compiling 48 source files to /home/rich/devel/proj/jspecview/build/classes

jar:
      [jar] Building jar: /home/rich/devel/proj/jspecview/build/lib/jspecview-20080128.jar

demo:
    [mkdir] Created dir: /home/rich/devel/proj/jspecview/demo
     [copy] Copying 3 files to /home/rich/devel/proj/jspecview/demo
     [copy] Copying 1 file to /home/rich/devel/proj/jspecview/demo/lib

BUILD SUCCESSFUL
Total time: 3 seconds
&lt;/tt&gt;
&lt;/div&gt;

&lt;p&gt;If all went well, you should see a new &lt;strong&gt;demo&lt;/strong&gt; directory with the following structure:&lt;/p&gt;

&lt;p&gt;&lt;center&gt;&lt;img src="http://depth-first.com/demo/20080128/screen.png"&gt;&lt;/img&gt;&lt;/center&gt;&lt;/p&gt;

&lt;h4&gt;Viewing the Result&lt;/h4&gt;

&lt;p&gt;You can view the result online &lt;a href="http://depth-first.com/demo/20080128/demo/demo1/index.html"&gt;here&lt;/a&gt;. The applet loads and displays the JCAMP-DX file &lt;a href="http://depth-first.com/demo/20080128/demo/demo1/netanilineH.jdx"&gt;&lt;strong&gt;netanilineH.jdx&lt;/strong&gt;&lt;/a&gt;. Notice that the spectrum is interactive; zoom and display properties can be set by right-clicking in the applet Window.&lt;/p&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

&lt;p&gt;This tutorial has show how to build a simple HTML test harness for JSpecView. With this important step complete, we can begin to customize JSpecView itself. Future tutorials will show how.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Jan 2008 10:37:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:7918de44-3bdf-462d-8167-d13d1c2104fe</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2008/01/28/hacking-jspecview-creating-an-html-test-harness</link>
      <category>Tools</category>
      <category>java</category>
      <category>applet</category>
      <category>jspecview</category>
      <category>ant</category>
      <category>xydata</category>
    </item>
  </channel>
</rss>
