From 4514bc350f3a05cdb5bba94fe092c819cb29bb4d Mon Sep 17 00:00:00 2001 From: Matt Hanna Date: Fri, 7 Oct 2011 11:19:29 -0400 Subject: [PATCH] More reliable way of finding the Tribble jar. --- .../VCFJarClassLoadingUnitTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/public/java/test/org/broadinstitute/sting/utils/variantcontext/VCFJarClassLoadingUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/variantcontext/VCFJarClassLoadingUnitTest.java index 50eebe179..c99afb960 100644 --- a/public/java/test/org/broadinstitute/sting/utils/variantcontext/VCFJarClassLoadingUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/variantcontext/VCFJarClassLoadingUnitTest.java @@ -24,6 +24,7 @@ package org.broadinstitute.sting.utils.variantcontext; +import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.testng.annotations.Test; import java.io.File; @@ -39,7 +40,7 @@ public class VCFJarClassLoadingUnitTest { @Test public void testVCFJarClassLoading() throws ClassNotFoundException, MalformedURLException { URI vcfURI = new File("dist/vcf.jar").toURI(); - URI tribbleURI = new File("lib/tribble-24.jar").toURI(); + URI tribbleURI = getTribbleJarFile().toURI(); ClassLoader classLoader = new URLClassLoader(new URL[] {vcfURI.toURL(),tribbleURI.toURL()}, null); classLoader.loadClass("org.broadinstitute.sting.utils.variantcontext.VariantContext"); @@ -48,4 +49,21 @@ public class VCFJarClassLoadingUnitTest { classLoader.loadClass("org.broadinstitute.sting.utils.codecs.vcf.VCFWriter"); classLoader.loadClass("org.broadinstitute.sting.utils.codecs.vcf.StandardVCFWriter"); } + + /** + * A very unsafe way of determining the current location of the Tribble jar file. Assumes that + * the tribble jar (as opposed to the constituent tribble classes) is on the classpath. + * + * This method might or might not work when built via IntelliJ's debugger. + * + * @return The file representing the tribble jar. + */ + private File getTribbleJarFile() { + String[] classPath = System.getProperty("java.class.path").split(File.pathSeparator); + for(String classPathEntry: classPath) { + if(classPathEntry.contains("tribble")) + return new File(classPathEntry); + } + throw new ReviewedStingException("Unable to find Tribble jar file"); + } }