added some cleanup of code, and new junit targets to the build file

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@177 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
aaron 2009-03-24 21:16:12 +00:00
parent c2b2ed8e1d
commit c047b53d6b
2 changed files with 211 additions and 140 deletions

133
build.xml
View File

@ -2,60 +2,107 @@
<description>Compile and distribute the Sting toolkit</description> <description>Compile and distribute the Sting toolkit</description>
<!-- Set target based on STING_BUILD_TYPE environment variable --> <!-- Set target based on STING_BUILD_TYPE environment variable -->
<property environment="env" /> <property environment="env"/>
<condition property="target" value="playground" else="core"> <condition property="target" value="playground" else="core">
<equals arg1="${env.STING_BUILD_TYPE}" arg2="playground" casesensitive="false" /> <equals arg1="${env.STING_BUILD_TYPE}" arg2="playground" casesensitive="false"/>
</condition> </condition>
<condition property="target.is.playground" value="true"> <condition property="target.is.playground" value="true">
<equals arg1="${target}" arg2="playground" /> <equals arg1="${target}" arg2="playground"/>
</condition> </condition>
<!-- set global properties for this build --> <!-- set global properties for this build -->
<path id="thirdparty.dependencies"> <path id="thirdparty.dependencies">
<fileset dir="lib" includes="*.jar" /> <fileset dir="lib" includes="*.jar"/>
</path> </path>
<path id="source"> <path id="source">
<dirset dir="java/src"> <dirset dir="java/src">
<patternset> <patternset>
<include name="org/broadinstitute/sting/*" /> <include name="org/broadinstitute/sting/*"/>
<exclude name="**/playground/**" unless="target.is.playground" /> <exclude name="**/playground/**" unless="target.is.playground"/>
</patternset> </patternset>
</dirset> </dirset>
</path> </path>
<!-- ivy properties --> <!-- ivy properties -->
<property name="ivy.install.version" value="2.0.0" /> <property name="ivy.install.version" value="2.0.0"/>
<property name="ivy.home" value="${user.home}/.ant" /> <property name="ivy.home" value="${user.home}/.ant"/>
<property name="ivy.jar.dir" value="${ivy.home}/lib" /> <property name="ivy.jar.dir" value="${ivy.home}/lib"/>
<property name="ivy.jar.file" value="ivy-${ivy.install.version}.jar" /> <property name="ivy.jar.file" value="ivy-${ivy.install.version}.jar"/>
<property name="ivy.settings.dir" value="settings" /> <property name="ivy.settings.dir" value="settings"/>
<property file="${ivy.settings.dir}/ivysettings.properties" /> <property file="${ivy.settings.dir}/ivysettings.properties"/>
<target name="resolve" depends="init" <target name="resolve" depends="init"
description="locate and download library dependencies"> description="locate and download library dependencies">
<!-- retrieve ivy if necessary --> <!-- retrieve ivy if necessary -->
<mkdir dir="${ivy.jar.dir}" /> <mkdir dir="${ivy.jar.dir}"/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}" <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}"
dest="${ivy.jar.dir}/${ivy.jar.file}" dest="${ivy.jar.dir}/${ivy.jar.file}"
usetimestamp="true"/> usetimestamp="true"/>
<!-- initialize and load ivy --> <!-- initialize and load ivy -->
<taskdef resource="org/apache/ivy/ant/antlib.xml" <taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" uri="antlib:org.apache.ivy.ant"
classpath="${ivy.jar.dir}/${ivy.jar.file}" /> classpath="${ivy.jar.dir}/${ivy.jar.file}"/>
<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" /> <ivy:settings file="${ivy.settings.dir}/ivysettings.xml"/>
<!-- retrieve dependencies --> <!-- retrieve dependencies -->
<ivy:retrieve /> <ivy:retrieve/>
</target> </target>
<!-- where to put reports and tests-->
<property name="report" value="build/report"/>
<property name="test.classes" value="build/testclasses"/>
<property name="test.output" value="dist/test"/>
<property name="test.sources" value="java/test"/>
<property name="classes" value="classes"/>
<target name="test.compile" depends="compile" description="Compile test cases">
<echo message="Sting: Compiling test cases!"/>
<mkdir dir="${test.classes}"/>
<javac destdir="${test.classes}" debug="on" optimize="on">
<src path="${test.sources}"/>
<classpath>
<path refid="thirdparty.dependencies"/>
<pathelement location="build"/>
<pathelement location="lib/junit-4.4.jar"/>
</classpath>
</javac>
</target>
<!-- TEST -->
<target name="test" depends="test.compile">
<mkdir dir="${report}"/>
<echo message="Sting: Running test cases!"/>
<junit printsummary="yes" clonevm="yes" haltonfailure="yes">
<formatter type="plain"/>
<classpath>
<path refid="thirdparty.dependencies"/>
<pathelement location="build"/>
<pathelement location="${test.classes}"/>
<pathelement location="lib/junit-4.4.jar"/>
</classpath>
<batchtest fork="yes" todir="${report}">
<fileset dir="${test.classes}">
<include name="**/*.class"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="init"> <target name="init">
<!-- Create the time stamp --> <!-- Create the time stamp -->
<tstamp/> <tstamp/>
<echo message="Compiling module ${target}" /> <echo message="Compiling module ${target}"/>
<!-- Create the build directory structure used by compile --> <!-- Create the build directory structure used by compile -->
<mkdir dir="build" /> <mkdir dir="build"/>
</target> </target>
<target name="compile" depends="init,resolve" <target name="compile" depends="init,resolve"
@ -63,33 +110,33 @@
<!-- Compile the java code from ${src} into build --> <!-- Compile the java code from ${src} into build -->
<javac destdir="build" classpathref="thirdparty.dependencies" <javac destdir="build" classpathref="thirdparty.dependencies"
debug="true" debuglevel="lines,vars,source"> debug="true" debuglevel="lines,vars,source">
<src refid="source" /> <src refid="source"/>
</javac> </javac>
</target> </target>
<target name="dist" depends="compile" <target name="dist" depends="compile"
description="generate the distribution" > description="generate the distribution">
<mkdir dir="dist"/> <mkdir dir="dist"/>
<copy todir="dist"> <copy todir="dist">
<fileset dir="lib" includes="*.jar" /> <fileset dir="lib" includes="*.jar"/>
</copy> </copy>
<jar jarfile="dist/StingUtils.jar"> <jar jarfile="dist/StingUtils.jar">
<fileset dir="build" includes="**/utils/**/*.class" /> <fileset dir="build" includes="**/utils/**/*.class"/>
</jar> </jar>
<jar jarfile="dist/GenomeAnalysisTK.jar"> <jar jarfile="dist/GenomeAnalysisTK.jar">
<fileset dir="build" includes="**/gatk/**/*.class" /> <fileset dir="build" includes="**/gatk/**/*.class"/>
<manifest> <manifest>
<attribute name="Main-Class" value="org.broadinstitute.sting.gatk.GenomeAnalysisTK" /> <attribute name="Main-Class" value="org.broadinstitute.sting.gatk.GenomeAnalysisTK"/>
</manifest> </manifest>
</jar> </jar>
<jar jarfile="dist/FourBaseCaller.jar" whenmanifestonly="skip"> <jar jarfile="dist/FourBaseCaller.jar" whenmanifestonly="skip">
<fileset dir="build" includes="**/fourbasecaller/**/*.class" /> <fileset dir="build" includes="**/fourbasecaller/**/*.class"/>
<manifest> <manifest>
<attribute name="Main-Class" value="org.broadinstitute.sting.playground.fourbasecaller.FourBaseCaller" /> <attribute name="Main-Class" value="org.broadinstitute.sting.playground.fourbasecaller.FourBaseCaller"/>
</manifest> </manifest>
</jar> </jar>
@ -106,33 +153,33 @@
<jar jarfile="dist/Playground.jar" whenmanifestonly="skip"> <jar jarfile="dist/Playground.jar" whenmanifestonly="skip">
<fileset dir="build"> <fileset dir="build">
<include name="**/*.class" /> <include name="**/*.class"/>
<exclude name="**/utils/**" /> <exclude name="**/utils/**"/>
<exclude name="**/gatk/**" /> <exclude name="**/gatk/**"/>
<exclude name="**/fourbasecaller/**" /> <exclude name="**/fourbasecaller/**"/>
</fileset> </fileset>
</jar> </jar>
<pathconvert property="jar.classpath" pathsep=" "> <pathconvert property="jar.classpath" pathsep=" ">
<flattenmapper /> <flattenmapper/>
<fileset dir="dist" includes="*.jar" /> <fileset dir="dist" includes="*.jar"/>
</pathconvert> </pathconvert>
<jar jarfile="dist/StingUtils.jar" update="true"> <jar jarfile="dist/StingUtils.jar" update="true">
<manifest> <manifest>
<attribute name="Class-Path" value="${jar.classpath}" /> <attribute name="Class-Path" value="${jar.classpath}"/>
</manifest> </manifest>
</jar> </jar>
<jar jarfile="dist/GenomeAnalysisTK.jar" update="true"> <jar jarfile="dist/GenomeAnalysisTK.jar" update="true">
<manifest> <manifest>
<attribute name="Class-Path" value="${jar.classpath}" /> <attribute name="Class-Path" value="${jar.classpath}"/>
</manifest> </manifest>
</jar> </jar>
<jar jarfile="dist/FourBaseCaller.jar" update="true" whenmanifestonly="skip"> <jar jarfile="dist/FourBaseCaller.jar" update="true" whenmanifestonly="skip">
<manifest> <manifest>
<attribute name="Class-Path" value="${jar.classpath}" /> <attribute name="Class-Path" value="${jar.classpath}"/>
</manifest> </manifest>
</jar> </jar>
@ -144,21 +191,21 @@
<jar jarfile="dist/Playground.jar" update="true" whenmanifestonly="skip"> <jar jarfile="dist/Playground.jar" update="true" whenmanifestonly="skip">
<manifest> <manifest>
<attribute name="Class-Path" value="${jar.classpath}" /> <attribute name="Class-Path" value="${jar.classpath}"/>
</manifest> </manifest>
</jar> </jar>
</target> </target>
<target name="javadoc"> <target name="javadoc">
<mkdir dir="javadoc" /> <mkdir dir="javadoc"/>
<javadoc sourcepathref="${target}.srcdir" destdir="javadoc" /> <javadoc sourcepathref="${target}.srcdir" destdir="javadoc"/>
</target> </target>
<target name="clean" <target name="clean"
description="clean up" > description="clean up">
<delete dir="out" /> <delete dir="out"/>
<delete dir="build" /> <delete dir="build"/>
<delete dir="dist" /> <delete dir="dist"/>
<delete dir="lib" /> <delete dir="lib"/>
</target> </target>
</project> </project>

View File

@ -66,6 +66,7 @@ public class ArgumentParser {
true); true);
} }
/** /**
* addOptionalArg * addOptionalArg
* <p/> * <p/>
@ -77,6 +78,7 @@ public class ArgumentParser {
* @param fieldname the field to set when we've parsed this option * @param fieldname the field to set when we've parsed this option
*/ */
public void addOptionalArg(String name, String letterform, String description, String fieldname) { public void addOptionalArg(String name, String letterform, String description, String fieldname) {
// we always want the help option to be available // we always want the help option to be available
Option opt = OptionBuilder.withLongOpt(name).withArgName(name) Option opt = OptionBuilder.withLongOpt(name).withArgName(name)
.hasArg() .hasArg()
@ -98,9 +100,15 @@ public class ArgumentParser {
* @param opt the option * @param opt the option
*/ */
private void AddToOptionStorage(String name, String letterform, String fieldname, Option opt) { private void AddToOptionStorage(String name, String letterform, String fieldname, Option opt) {
// add to the option list // add to the option list
m_options.addOption(opt); m_options.addOption(opt);
// first check to see if we've already added an option with the same name
if (m_option_names.contains(letterform)) {
throw new IllegalArgumentException(letterform + " was already added as an option");
}
// add the object with it's name to the storage location // add the object with it's name to the storage location
try { try {
m_storageLocations.put(name, prog.getClass().getField(fieldname)); m_storageLocations.put(name, prog.getClass().getField(fieldname));
@ -159,6 +167,7 @@ public class ArgumentParser {
} }
/** /**
* addRequiredlArg * addRequiredlArg
* <p/> * <p/>
@ -170,6 +179,7 @@ public class ArgumentParser {
* @param fieldname what field it should be stuck into on the calling class * @param fieldname what field it should be stuck into on the calling class
*/ */
public void addRequiredlArgList(String name, String letterform, String description, String fieldname) { public void addRequiredlArgList(String name, String letterform, String description, String fieldname) {
// we always want the help option to be available // we always want the help option to be available
Option opt = OptionBuilder.isRequired() Option opt = OptionBuilder.isRequired()
.withLongOpt(name) .withLongOpt(name)
@ -193,11 +203,22 @@ public class ArgumentParser {
* @param fieldname what field it should be stuck into on the calling class * @param fieldname what field it should be stuck into on the calling class
*/ */
public void addOptionalFlag(String name, String letterform, String description, String fieldname) { public void addOptionalFlag(String name, String letterform, String description, String fieldname) {
// if they've passed a non-Boolean as a object, beat them
try {
if (!(prog.getClass().getField(fieldname).getType() == Boolean.class)) {
throw new IllegalArgumentException("Fields to addOptionalFlag must be of type Boolean");
}
} catch (NoSuchFieldException e) {
throw new IllegalArgumentException("Fields to addOptionalFlag must exist!");
}
// we always want the help option to be available // we always want the help option to be available
Option opt = OptionBuilder.withLongOpt(name) Option opt = OptionBuilder.withLongOpt(name)
.withDescription(description) .withDescription(description)
.create(letterform); .create(letterform);
// add it to the option // add it to the option
AddToOptionStorage(name, letterform, fieldname, opt); AddToOptionStorage(name, letterform, fieldname, opt);
@ -215,6 +236,16 @@ public class ArgumentParser {
* @param fieldname what field it should be stuck into on the calling class * @param fieldname what field it should be stuck into on the calling class
*/ */
public void addRequiredlFlag(String name, String letterform, String description, String fieldname) { public void addRequiredlFlag(String name, String letterform, String description, String fieldname) {
// if they've passed a non-Boolean as a object, beat them
try {
if (!(prog.getClass().getField(fieldname).getType() == Boolean.class)) {
throw new IllegalArgumentException("Fields to addRequiredlFlag must be of type Boolean");
}
} catch (NoSuchFieldException e) {
throw new IllegalArgumentException("Fields to addRequiredlFlag must exist!");
}
// we always want the help option to be available // we always want the help option to be available
Option opt = OptionBuilder.isRequired() Option opt = OptionBuilder.isRequired()
.withLongOpt(name) .withLongOpt(name)
@ -234,7 +265,7 @@ public class ArgumentParser {
* *
* @param args the command line arguments we recieved * @param args the command line arguments we recieved
*/ */
public void processArgs(String[] args) { public void processArgs(String[] args) throws ParseException {
CommandLineParser parser = new PosixParser(); CommandLineParser parser = new PosixParser();
try { try {
@ -254,8 +285,7 @@ public class ArgumentParser {
logger.fatal("processArgs: cannot convert field " + f.toString()); logger.fatal("processArgs: cannot convert field " + f.toString());
throw new RuntimeException("processArgs: Failed conversion " + e.getMessage()); throw new RuntimeException("processArgs: Failed conversion " + e.getMessage());
} }
} } else {
else {
Field f = m_storageLocations.get(opt.getLongOpt()); Field f = m_storageLocations.get(opt.getLongOpt());
try { try {
@ -268,15 +298,9 @@ public class ArgumentParser {
} }
} }
} }
}catch (UnrecognizedOptionException e) { } catch (UnrecognizedOptionException e) {
// we don't care about unknown exceptions right now // we don't care about unknown exceptions right now
logger.warn(e.getMessage()); logger.warn(e.getMessage());
} catch (ParseException e) {
// we didn't get all the required arguments,
// print out the help
e.printStackTrace();
this.printHelp();
System.exit(1);
} }
} }