As requested by Mark, I've broken out the code to pull out the protected subclass when available (and otherwise use the public version) into the GATKLiteUtils class. People should use this code instead of reimplementing all of the java reflection on their own.

This commit is contained in:
Eric Banks 2012-07-18 22:44:37 -04:00
parent d46ccec04e
commit e370030e6c
4 changed files with 91 additions and 36 deletions

View File

@ -51,7 +51,7 @@ import org.broadinstitute.sting.gatk.samples.SampleDBBuilder;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.utils.*;
import org.broadinstitute.sting.utils.baq.BAQ;
import org.broadinstitute.sting.utils.classloader.JVMUtils;
import org.broadinstitute.sting.utils.classloader.GATKLiteUtils;
import org.broadinstitute.sting.utils.codecs.vcf.VCFCodec;
import org.broadinstitute.sting.utils.codecs.vcf.VCFHeader;
import org.broadinstitute.sting.utils.collections.Pair;
@ -206,7 +206,7 @@ public class GenomeAnalysisEngine {
* Utility method to determine whether this is the lite version of the GATK
*/
public boolean isGATKLite() {
return JVMUtils.isGATKLite();
return GATKLiteUtils.isGATKLite();
}
/**

View File

@ -34,8 +34,7 @@ import org.broadinstitute.sting.gatk.filters.MappingQualityZeroFilter;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.utils.baq.BAQ;
import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.sting.utils.classloader.ProtectedPackageSource;
import org.broadinstitute.sting.utils.classloader.GATKLiteUtils;
import org.broadinstitute.sting.utils.collections.Pair;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.exceptions.UserException;
@ -179,27 +178,15 @@ public class BaseQualityScoreRecalibrator extends LocusWalker<Long, Long> implem
}
private RecalibrationEngine initializeRecalibrationEngine() {
List<Class<? extends RecalibrationEngine>> REclasses = new PluginManager<RecalibrationEngine>(RecalibrationEngine.class).getPlugins();
if ( REclasses.isEmpty() )
throw new ReviewedStingException("The RecalibrationEngine class is not found; repository must be corrupted");
Class c = null;
for ( Class<? extends RecalibrationEngine> REclass : REclasses ) {
if ( ProtectedPackageSource.class.isAssignableFrom(REclass) ) {
c = REclass;
break;
}
}
if ( c == null )
c = REclasses.get(0);
final Class recalibrationEngineClass = GATKLiteUtils.getProtectedClassIfAvailable(RecalibrationEngine.class);
try {
Constructor constructor = c.getDeclaredConstructor((Class[])null);
Constructor constructor = recalibrationEngineClass.getDeclaredConstructor((Class[])null);
constructor.setAccessible(true);
return (RecalibrationEngine)constructor.newInstance();
}
catch (Exception e) {
throw new ReviewedStingException("Unable to create RecalibrationEngine class instance " + c.getSimpleName());
throw new ReviewedStingException("Unable to create RecalibrationEngine class instance " + recalibrationEngineClass.getSimpleName());
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2010 The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.utils.classloader;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: ebanks
*
* A set of static utility methods for working with the full vs. Lite GATK build
*/
public class GATKLiteUtils {
/**
* Constructor access disallowed...static utility methods only!
*/
private GATKLiteUtils() { }
/**
* Utility method to determine whether this is the lite version of the GATK
*/
public static boolean isGATKLite() {
if ( isLiteVersion == null ) {
try {
Class.forName(DummyProtectedClassName);
isLiteVersion = false;
} catch ( ClassNotFoundException e) {
isLiteVersion = true;
}
}
return isLiteVersion;
}
private static final String DummyProtectedClassName = "org.broadinstitute.sting.gatk.DummyProtectedClass";
private static Boolean isLiteVersion = null;
/**
* Utility method to pull out a protected subclass if possible, otherwise it falls back to a public subclass.
* Important note: the protected classes MUST implement ProtectedPackageSource!
*
* @param interfaceClass the interface class which the target classes implement
*/
public static Class getProtectedClassIfAvailable(final Class interfaceClass) {
List<Class<? extends Object>> classes = new PluginManager<Object>(interfaceClass).getPlugins();
if ( classes.isEmpty() )
throw new ReviewedStingException("No classes implementing the interface class " + interfaceClass.getSimpleName() + " were found");
Class result = null;
for ( Class<? extends Object> c : classes ) {
if ( ProtectedPackageSource.class.isAssignableFrom(c) ) {
result = c;
break;
}
}
if ( result == null )
result = classes.get(0);
return result;
}
}

View File

@ -105,23 +105,6 @@ public class JVMUtils {
return allFields;
}
/**
* Utility method to determine whether this is the lite version of the GATK
*/
public static boolean isGATKLite() {
if ( isLiteVersion == null ) {
try {
Class.forName(DummyProtectedClassName);
isLiteVersion = false;
} catch ( ClassNotFoundException e) {
isLiteVersion = true;
}
}
return isLiteVersion;
}
private static final String DummyProtectedClassName = "org.broadinstitute.sting.gatk.DummyProtectedClass";
private static Boolean isLiteVersion = null;
/**
* Find the field with the given name in the class. Will inspect all fields, independent
* of access level.