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

293
build.xml
View File

@ -1,97 +1,144 @@
<project name="Sting" default="dist" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
<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 -->
<property environment="env" />
<condition property="target" value="playground" else="core">
<equals arg1="${env.STING_BUILD_TYPE}" arg2="playground" casesensitive="false" />
</condition>
<condition property="target.is.playground" value="true">
<equals arg1="${target}" arg2="playground" />
</condition>
<!-- Set target based on STING_BUILD_TYPE environment variable -->
<property environment="env"/>
<condition property="target" value="playground" else="core">
<equals arg1="${env.STING_BUILD_TYPE}" arg2="playground" casesensitive="false"/>
</condition>
<condition property="target.is.playground" value="true">
<equals arg1="${target}" arg2="playground"/>
</condition>
<!-- set global properties for this build -->
<path id="thirdparty.dependencies">
<fileset dir="lib" includes="*.jar" />
</path>
<!-- set global properties for this build -->
<path id="thirdparty.dependencies">
<fileset dir="lib" includes="*.jar"/>
</path>
<path id="source">
<dirset dir="java/src">
<patternset>
<include name="org/broadinstitute/sting/*" />
<exclude name="**/playground/**" unless="target.is.playground" />
</patternset>
</dirset>
</path>
<path id="source">
<dirset dir="java/src">
<patternset>
<include name="org/broadinstitute/sting/*"/>
<exclude name="**/playground/**" unless="target.is.playground"/>
</patternset>
</dirset>
</path>
<!-- ivy properties -->
<property name="ivy.install.version" value="2.0.0" />
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="ivy-${ivy.install.version}.jar" />
<property name="ivy.settings.dir" value="settings" />
<property file="${ivy.settings.dir}/ivysettings.properties" />
<!-- ivy properties -->
<property name="ivy.install.version" value="2.0.0"/>
<property name="ivy.home" value="${user.home}/.ant"/>
<property name="ivy.jar.dir" value="${ivy.home}/lib"/>
<property name="ivy.jar.file" value="ivy-${ivy.install.version}.jar"/>
<property name="ivy.settings.dir" value="settings"/>
<property file="${ivy.settings.dir}/ivysettings.properties"/>
<target name="resolve" depends="init"
description="locate and download library dependencies">
<!-- retrieve ivy if necessary -->
<mkdir dir="${ivy.jar.dir}" />
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}"
dest="${ivy.jar.dir}/${ivy.jar.file}"
usetimestamp="true"/>
<!-- initialize and load ivy -->
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant"
classpath="${ivy.jar.dir}/${ivy.jar.file}" />
<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
<!-- retrieve dependencies -->
<ivy:retrieve />
</target>
<target name="resolve" depends="init"
description="locate and download library dependencies">
<!-- retrieve ivy if necessary -->
<mkdir dir="${ivy.jar.dir}"/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}"
dest="${ivy.jar.dir}/${ivy.jar.file}"
usetimestamp="true"/>
<!-- initialize and load ivy -->
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant"
classpath="${ivy.jar.dir}/${ivy.jar.file}"/>
<ivy:settings file="${ivy.settings.dir}/ivysettings.xml"/>
<!-- retrieve dependencies -->
<ivy:retrieve/>
</target>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<echo message="Compiling module ${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"/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="build" />
</target>
<target name="compile" depends="init,resolve"
description="compile the source">
<!-- Compile the java code from ${src} into build -->
<javac destdir="build" classpathref="thirdparty.dependencies"
debug="true" debuglevel="lines,vars,source">
<src refid="source" />
</javac>
</target>
<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>
<target name="dist" depends="compile"
description="generate the distribution" >
<mkdir dir="dist"/>
<copy todir="dist">
<fileset dir="lib" includes="*.jar" />
</copy>
<!-- 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>
<jar jarfile="dist/StingUtils.jar">
<fileset dir="build" includes="**/utils/**/*.class" />
</jar>
<batchtest fork="yes" todir="${report}">
<fileset dir="${test.classes}">
<include name="**/*.class"/>
</fileset>
</batchtest>
</junit>
<jar jarfile="dist/GenomeAnalysisTK.jar">
<fileset dir="build" includes="**/gatk/**/*.class" />
<manifest>
<attribute name="Main-Class" value="org.broadinstitute.sting.gatk.GenomeAnalysisTK" />
</manifest>
</jar>
</target>
<jar jarfile="dist/FourBaseCaller.jar" whenmanifestonly="skip">
<fileset dir="build" includes="**/fourbasecaller/**/*.class" />
<manifest>
<attribute name="Main-Class" value="org.broadinstitute.sting.playground.fourbasecaller.FourBaseCaller" />
</manifest>
</jar>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<echo message="Compiling module ${target}"/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="build"/>
</target>
<target name="compile" depends="init,resolve"
description="compile the source">
<!-- Compile the java code from ${src} into build -->
<javac destdir="build" classpathref="thirdparty.dependencies"
debug="true" debuglevel="lines,vars,source">
<src refid="source"/>
</javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution">
<mkdir dir="dist"/>
<copy todir="dist">
<fileset dir="lib" includes="*.jar"/>
</copy>
<jar jarfile="dist/StingUtils.jar">
<fileset dir="build" includes="**/utils/**/*.class"/>
</jar>
<jar jarfile="dist/GenomeAnalysisTK.jar">
<fileset dir="build" includes="**/gatk/**/*.class"/>
<manifest>
<attribute name="Main-Class" value="org.broadinstitute.sting.gatk.GenomeAnalysisTK"/>
</manifest>
</jar>
<jar jarfile="dist/FourBaseCaller.jar" whenmanifestonly="skip">
<fileset dir="build" includes="**/fourbasecaller/**/*.class"/>
<manifest>
<attribute name="Main-Class" value="org.broadinstitute.sting.playground.fourbasecaller.FourBaseCaller"/>
</manifest>
</jar>
<jar jarfile="dist/FourBaseRecaller.jar" whenmanifestonly="skip">
<!--<fileset dir="build" includes="**/fourbasecaller/**/*.class" />-->
@ -104,37 +151,37 @@
</manifest>
</jar>
<jar jarfile="dist/Playground.jar" whenmanifestonly="skip">
<fileset dir="build">
<include name="**/*.class" />
<exclude name="**/utils/**" />
<exclude name="**/gatk/**" />
<exclude name="**/fourbasecaller/**" />
</fileset>
</jar>
<jar jarfile="dist/Playground.jar" whenmanifestonly="skip">
<fileset dir="build">
<include name="**/*.class"/>
<exclude name="**/utils/**"/>
<exclude name="**/gatk/**"/>
<exclude name="**/fourbasecaller/**"/>
</fileset>
</jar>
<pathconvert property="jar.classpath" pathsep=" ">
<flattenmapper />
<fileset dir="dist" includes="*.jar" />
</pathconvert>
<pathconvert property="jar.classpath" pathsep=" ">
<flattenmapper/>
<fileset dir="dist" includes="*.jar"/>
</pathconvert>
<jar jarfile="dist/StingUtils.jar" update="true">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
<jar jarfile="dist/StingUtils.jar" update="true">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
<jar jarfile="dist/GenomeAnalysisTK.jar" update="true">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
<jar jarfile="dist/GenomeAnalysisTK.jar" update="true">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
<jar jarfile="dist/FourBaseCaller.jar" update="true" whenmanifestonly="skip">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
<jar jarfile="dist/FourBaseCaller.jar" update="true" whenmanifestonly="skip">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
<jar jarfile="dist/FourBaseRecaller.jar" update="true" whenmanifestonly="skip">
<manifest>
@ -142,23 +189,23 @@
</manifest>
</jar>
<jar jarfile="dist/Playground.jar" update="true" whenmanifestonly="skip">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
</target>
<jar jarfile="dist/Playground.jar" update="true" whenmanifestonly="skip">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
</target>
<target name="javadoc">
<mkdir dir="javadoc" />
<javadoc sourcepathref="${target}.srcdir" destdir="javadoc" />
</target>
<target name="javadoc">
<mkdir dir="javadoc"/>
<javadoc sourcepathref="${target}.srcdir" destdir="javadoc"/>
</target>
<target name="clean"
description="clean up" >
<delete dir="out" />
<delete dir="build" />
<delete dir="dist" />
<delete dir="lib" />
</target>
<target name="clean"
description="clean up">
<delete dir="out"/>
<delete dir="build"/>
<delete dir="dist"/>
<delete dir="lib"/>
</target>
</project>

View File

@ -59,13 +59,14 @@ public class ArgumentParser {
// automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(100,
"java -Xmx4096m -jar dist/GenomeAnalysisTK.jar",
"",
m_options,
"",
true);
"java -Xmx4096m -jar dist/GenomeAnalysisTK.jar",
"",
m_options,
"",
true);
}
/**
* addOptionalArg
* <p/>
@ -77,6 +78,7 @@ public class ArgumentParser {
* @param fieldname the field to set when we've parsed this option
*/
public void addOptionalArg(String name, String letterform, String description, String fieldname) {
// we always want the help option to be available
Option opt = OptionBuilder.withLongOpt(name).withArgName(name)
.hasArg()
@ -98,9 +100,15 @@ public class ArgumentParser {
* @param opt the option
*/
private void AddToOptionStorage(String name, String letterform, String fieldname, Option opt) {
// add to the option list
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
try {
m_storageLocations.put(name, prog.getClass().getField(fieldname));
@ -159,6 +167,7 @@ public class ArgumentParser {
}
/**
* addRequiredlArg
* <p/>
@ -170,6 +179,7 @@ public class ArgumentParser {
* @param fieldname what field it should be stuck into on the calling class
*/
public void addRequiredlArgList(String name, String letterform, String description, String fieldname) {
// we always want the help option to be available
Option opt = OptionBuilder.isRequired()
.withLongOpt(name)
@ -193,11 +203,22 @@ public class ArgumentParser {
* @param fieldname what field it should be stuck into on the calling class
*/
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
Option opt = OptionBuilder.withLongOpt(name)
.withDescription(description)
.create(letterform);
// add it to the option
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
*/
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
Option opt = OptionBuilder.isRequired()
.withLongOpt(name)
@ -231,15 +262,15 @@ public class ArgumentParser {
* This function is called to validate all the arguments to the program.
* If a required Arg isn't found, we generate the help message, and
* exit the program
*
*
* @param args the command line arguments we recieved
*/
public void processArgs(String[] args) {
public void processArgs(String[] args) throws ParseException {
CommandLineParser parser = new PosixParser();
try {
Collection<Option> opts = m_options.getOptions();
CommandLine cmd = parser.parse(m_options, args);
// logger.info("We have " + opts.size() + " options");
@ -254,8 +285,7 @@ public class ArgumentParser {
logger.fatal("processArgs: cannot convert field " + f.toString());
throw new RuntimeException("processArgs: Failed conversion " + e.getMessage());
}
}
else {
} else {
Field f = m_storageLocations.get(opt.getLongOpt());
try {
@ -268,15 +298,9 @@ public class ArgumentParser {
}
}
}
}catch (UnrecognizedOptionException e) {
} catch (UnrecognizedOptionException e) {
// we don't care about unknown exceptions right now
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);
}
}